1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
import java.awt.*;
import java.awt.event.MouseListener;
public class DefaultCellAttribute
//implements CellAttribute ,CellSpan {
implements CellAttribute ,CellSpan ,ColoredCell ,CellFont {
protected int rowSize;
protected int columnSize;
protected int[][][] span; // CellSpan
protected Color[][] foreground; // ColoredCell
protected Color[][] background; //
protected Font[][] font; // CellFont
public DefaultCellAttribute() {
this(1,1);
}
/** {@docRoot} Définition des attributs des cellules pour interfaces */
public DefaultCellAttribute(int numRows, int numColumns) {
setSize(new Dimension(numColumns, numRows));
}
protected void initValue() {
for(int i=0; i<span.length;i++) {
for(int j=0; j<span[i].length; j++) {
span[i][j][CellSpan.COLUMN] = 1;
span[i][j][CellSpan.ROW] = 1;
}
}
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* retourne les coordonnées*/
public int[] getSpan(int row, int column) {
if (isOutOfBounds(row, column)) {
int[] ret_code = {1,1};
return ret_code;
}
return span[row][column];
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* modifie les coordonnées*/
public void setSpan(int[] span, int row, int column) {
if (isOutOfBounds(row, column)) return;
this.span[row][column] = span;
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* retourne visibilité de la cellule*/
public boolean isVisible(int row, int column) {
if (isOutOfBounds(row, column)) return false;
if ((span[row][column][CellSpan.COLUMN] < 1)
||(span[row][column][CellSpan.ROW] < 1)) return false;
return true;
}
/** {@docRoot}
* fusion de deux cellules*/
public void combine(int[] rows, int[] columns) {
if (isOutOfBounds(rows, columns)) return;
int rowSpan = rows.length;
int columnSpan = columns.length;
int startRow = rows[0];
int startColumn = columns[0];
for (int i=0;i<rowSpan;i++) {
for (int j=0;j<columnSpan;j++) {
if ((span[startRow +i][startColumn +j][CellSpan.COLUMN] != 1)
||(span[startRow +i][startColumn +j][CellSpan.ROW] != 1)) {
return ;
}
}
}
for (int i=0,ii=0;i<rowSpan;i++,ii--) {
for (int j=0,jj=0;j<columnSpan;j++,jj--) {
span[startRow +i][startColumn +j][CellSpan.COLUMN] = jj;
span[startRow +i][startColumn +j][CellSpan.ROW] = ii;
}
}
span[startRow][startColumn][CellSpan.COLUMN] = columnSpan;
span[startRow][startColumn][CellSpan.ROW] = rowSpan;
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* retourne couleur premier plan */
public Color getForeground(int row, int column) {
if (isOutOfBounds(row, column)) return null;
return foreground[row][column];
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* modifie couleur arrière plan 1 cellule */
public void setForeground(Color color, int row, int column) {
if (isOutOfBounds(row, column)) return;
foreground[row][column] = color;
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* modifie couleur arrière plan plusieurs cellules */
public void setForeground(Color color, int[] rows, int[] columns) {
if (isOutOfBounds(rows, columns)){ return;}
setValues(foreground, color, rows, columns);
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* retourne couleur arrière plan */
public Color getBackground(int row, int column) {
if (isOutOfBounds(row, column)) return null;
return background[row][column];
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* modifie couleur arrière plan 1cellule*/
public void setBackground(Color color, int row, int column) {
if (isOutOfBounds(row, column)) return;
background[row][column] = color;
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* modifie couleur arrière plan plusieurs cellules */
public void setBackground(Color color, int[] rows, int[] columns) {
if (isOutOfBounds(rows, columns)) return;
setValues(background, color, rows, columns);
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* retourne la police de la cellule*/
public Font getFont(int row, int column) {
if (isOutOfBounds(row, column)) return null;
return font[row][column];
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* modifie la police de la cellule*/
public void setFont(Font font, int row, int column) {
if (isOutOfBounds(row, column)) return;
this.font[row][column] = font;
}
/** {@docRoot} Définition des attributs Zone sélectionnée
* retourne la police de la cellule*/
public void setFont(Font font, int[] rows, int[] columns) {
if (isOutOfBounds(rows, columns)) return;
setValues(this.font, font, rows, columns);
}
/** {@docRoot} Retourne dimension selection */
public Dimension getSize() {
return new Dimension(rowSize, columnSize);
}
/** {@docRoot} Modifie dimension selection */
public void setSize(Dimension size) {
columnSize = size.width;
rowSize = size.height;
span = new int[rowSize][columnSize][2]; // 2: COLUMN,ROW
foreground = new Color[rowSize][columnSize];
background = new Color[rowSize][columnSize];
font = new Font[rowSize][columnSize];
initValue();
}
/** {@docRoot} Retourne en dehors de la selection 1 cellule */
protected boolean isOutOfBounds(int row, int column) {
if ((row < 0)||(rowSize <= row)
||(column < 0)||(columnSize <= column)) {
return true;
}
return false;
}
/** {@docRoot} Retourne en dehors de la selection plusieurs cellules */
protected boolean isOutOfBounds(int[] rows, int[] columns) {
for (int i=0;i<rows.length;i++) {
if ((rows[i] < 0)||(rowSize <= rows[i])) return true;
}
for (int i=0;i<columns.length;i++) {
if ((columns[i] < 0)||(columnSize <= columns[i])) return true;
}
return false;
}
/** {@docRoot} Modifs des valeurs */
protected void setValues(Object[][] target, Object value,
int[] rows, int[] columns) {
for (int i=0;i<rows.length;i++) {
int row = rows[i];
for (int j=0;j<columns.length;j++) {
int column = columns[j];
target[row][column] = value; }
}
}
} |