1 12 13 package org.eclipse.jface.viewers; 14 15 import org.eclipse.swt.graphics.Color; 16 import org.eclipse.swt.graphics.Font; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.graphics.Rectangle; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Item; 21 import org.eclipse.swt.widgets.Widget; 22 23 29 public class ViewerCell { 30 private int columnIndex; 31 32 private ViewerRow row; 33 34 private Object element; 35 36 39 public static int ABOVE = 1; 40 41 44 public static int BELOW = 1 << 1; 45 46 49 public static int LEFT = 1 << 2; 50 51 54 public static int RIGHT = 1 << 3; 55 56 62 ViewerCell(ViewerRow row, int columnIndex, Object element) { 63 this.row = row; 64 this.columnIndex = columnIndex; 65 this.element = element; 66 } 67 68 73 public int getColumnIndex() { 74 return columnIndex; 75 } 76 77 82 public Rectangle getBounds() { 83 return row.getBounds(columnIndex); 84 } 85 86 91 public Object getElement() { 92 if (element!=null) { 93 return element; 94 } 95 return row.getElement(); 96 } 97 98 103 public String getText() { 104 return row.getText(columnIndex); 105 } 106 107 112 public Image getImage() { 113 return row.getImage(columnIndex); 114 } 115 116 121 public void setBackground(Color background) { 122 row.setBackground(columnIndex, background); 123 124 } 125 126 131 public void setForeground(Color foreground) { 132 row.setForeground(columnIndex, foreground); 133 134 } 135 136 141 public void setFont(Font font) { 142 row.setFont(columnIndex, font); 143 144 } 145 146 151 public void setText(String text) { 152 row.setText(columnIndex, text); 153 154 } 155 156 161 public void setImage(Image image) { 162 row.setImage(columnIndex, image); 163 164 } 165 166 171 void setColumn(int column) { 172 columnIndex = column; 173 174 } 175 176 182 void update(ViewerRow rowItem, int column, Object element) { 183 row = rowItem; 184 columnIndex = column; 185 this.element = element; 186 } 187 188 193 public Widget getItem() { 194 return row.getItem(); 195 } 196 197 202 public Control getControl() { 203 return row.getControl(); 204 } 205 206 221 public ViewerCell getNeighbor(int directionMask, boolean sameLevel) { 222 ViewerRow row; 223 int columnIndex; 224 225 if ((directionMask & ABOVE) == ABOVE) { 226 row = this.row.getNeighbor(ViewerRow.ABOVE, sameLevel); 227 } else if ((directionMask & BELOW) == BELOW) { 228 row = this.row.getNeighbor(ViewerRow.BELOW, sameLevel); 229 } else { 230 row = this.row; 231 } 232 233 if (row != null) { 234 if ((directionMask & LEFT) == LEFT) { 235 columnIndex = getColumnIndex() - 1; 236 } else if ((directionMask & RIGHT) == RIGHT) { 237 columnIndex = getColumnIndex() + 1; 238 } else { 239 columnIndex = getColumnIndex(); 240 } 241 242 if (columnIndex >= 0 && columnIndex < row.getColumnCount()) { 243 return row.getCell(columnIndex); 244 } 245 } 246 247 return null; 248 } 249 250 253 public ViewerRow getViewerRow() { 254 return row; 255 } 256 257 260 public int hashCode() { 261 final int prime = 31; 262 int result = 1; 263 result = prime * result + columnIndex; 264 result = prime * result + ((row == null) ? 0 : row.hashCode()); 265 return result; 266 } 267 268 271 public boolean equals(Object obj) { 272 if (this == obj) 273 return true; 274 if (obj == null) 275 return false; 276 if (getClass() != obj.getClass()) 277 return false; 278 final ViewerCell other = (ViewerCell) obj; 279 if (columnIndex != other.columnIndex) 280 return false; 281 if (row == null) { 282 if (other.row != null) 283 return false; 284 } else if (!row.equals(other.row)) 285 return false; 286 return true; 287 } 288 } 289 | Popular Tags |