10
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006, 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
|
|
11 * Port to the D programming language:
|
|
12 * Frank Benoit <benoit@tionex.de>
|
|
13 *******************************************************************************/
|
|
14
|
|
15 module dwtx.jface.viewers.ViewerCell;
|
|
16
|
|
17 import dwtx.jface.viewers.ViewerRow;
|
|
18
|
|
19 import dwt.graphics.Color;
|
|
20 import dwt.graphics.Font;
|
|
21 import dwt.graphics.Image;
|
|
22 import dwt.graphics.Rectangle;
|
|
23 import dwt.widgets.Control;
|
|
24 import dwt.widgets.Item;
|
|
25 import dwt.widgets.Widget;
|
|
26
|
|
27 import dwt.dwthelper.utils;
|
|
28
|
|
29 /**
|
|
30 * The ViewerCell is the JFace representation of a cell entry in a ViewerRow.
|
|
31 *
|
|
32 * @since 3.3
|
|
33 *
|
|
34 */
|
|
35 public class ViewerCell {
|
|
36 private int columnIndex;
|
|
37
|
|
38 private ViewerRow row;
|
|
39
|
|
40 private Object element;
|
|
41
|
|
42 /**
|
|
43 * Constant denoting the cell above current one (value is 1).
|
|
44 */
|
|
45 public static int ABOVE = 1;
|
|
46
|
|
47 /**
|
|
48 * Constant denoting the cell below current one (value is 2).
|
|
49 */
|
|
50 public static int BELOW = 1 << 1;
|
|
51
|
|
52 /**
|
|
53 * Constant denoting the cell to the left of the current one (value is 4).
|
|
54 */
|
|
55 public static int LEFT = 1 << 2;
|
|
56
|
|
57 /**
|
|
58 * Constant denoting the cell to the right of the current one (value is 8).
|
|
59 */
|
|
60 public static int RIGHT = 1 << 3;
|
|
61
|
|
62 /**
|
|
63 * Create a new instance of the receiver on the row.
|
|
64 *
|
|
65 * @param row
|
|
66 * @param columnIndex
|
|
67 */
|
|
68 this(ViewerRow row, int columnIndex, Object element) {
|
|
69 this.row = row;
|
|
70 this.columnIndex = columnIndex;
|
|
71 this.element = element;
|
|
72 }
|
|
73
|
|
74 /**
|
|
75 * Get the index of the cell.
|
|
76 *
|
|
77 * @return the index
|
|
78 */
|
|
79 public int getColumnIndex() {
|
|
80 return columnIndex;
|
|
81 }
|
|
82
|
|
83 /**
|
|
84 * Get the bounds of the cell.
|
|
85 *
|
|
86 * @return {@link Rectangle}
|
|
87 */
|
|
88 public Rectangle getBounds() {
|
|
89 return row.getBounds(columnIndex);
|
|
90 }
|
|
91
|
|
92 /**
|
|
93 * Get the element this row represents.
|
|
94 *
|
|
95 * @return {@link Object}
|
|
96 */
|
|
97 public Object getElement() {
|
|
98 if (element !is null) {
|
|
99 return element;
|
|
100 }
|
|
101 return row.getElement();
|
|
102 }
|
|
103
|
|
104 /**
|
|
105 * Return the text for the cell.
|
|
106 *
|
|
107 * @return {@link String}
|
|
108 */
|
|
109 public String getText() {
|
|
110 return row.getText(columnIndex);
|
|
111 }
|
|
112
|
|
113 /**
|
|
114 * Return the Image for the cell.
|
|
115 *
|
|
116 * @return {@link Image} or <code>null</code>
|
|
117 */
|
|
118 public Image getImage() {
|
|
119 return row.getImage(columnIndex);
|
|
120 }
|
|
121
|
|
122 /**
|
|
123 * Set the background color of the cell.
|
|
124 *
|
|
125 * @param background
|
|
126 */
|
|
127 public void setBackground(Color background) {
|
|
128 row.setBackground(columnIndex, background);
|
|
129
|
|
130 }
|
|
131
|
|
132 /**
|
|
133 * Set the foreground color of the cell.
|
|
134 *
|
|
135 * @param foreground
|
|
136 */
|
|
137 public void setForeground(Color foreground) {
|
|
138 row.setForeground(columnIndex, foreground);
|
|
139
|
|
140 }
|
|
141
|
|
142 /**
|
|
143 * Set the font of the cell.
|
|
144 *
|
|
145 * @param font
|
|
146 */
|
|
147 public void setFont(Font font) {
|
|
148 row.setFont(columnIndex, font);
|
|
149
|
|
150 }
|
|
151
|
|
152 /**
|
|
153 * Set the text for the cell.
|
|
154 *
|
|
155 * @param text
|
|
156 */
|
|
157 public void setText(String text) {
|
|
158 row.setText(columnIndex, text);
|
|
159
|
|
160 }
|
|
161
|
|
162 /**
|
|
163 * Set the Image for the cell.
|
|
164 *
|
|
165 * @param image
|
|
166 */
|
|
167 public void setImage(Image image) {
|
|
168 row.setImage(columnIndex, image);
|
|
169
|
|
170 }
|
|
171
|
|
172 /**
|
|
173 * Set the columnIndex.
|
|
174 *
|
|
175 * @param column
|
|
176 */
|
|
177 void setColumn(int column) {
|
|
178 columnIndex = column;
|
|
179
|
|
180 }
|
|
181
|
|
182 /**
|
|
183 * Set the row to rowItem and the columnIndex to column.
|
|
184 *
|
|
185 * @param rowItem
|
|
186 * @param column
|
|
187 */
|
|
188 void update(ViewerRow rowItem, int column, Object element) {
|
|
189 row = rowItem;
|
|
190 columnIndex = column;
|
|
191 this.element = element;
|
|
192 }
|
|
193
|
|
194 /**
|
|
195 * Return the item for the receiver.
|
|
196 *
|
|
197 * @return {@link Item}
|
|
198 */
|
|
199 public Widget getItem() {
|
|
200 return row.getItem();
|
|
201 }
|
|
202
|
|
203 /**
|
|
204 * Get the control for this cell.
|
|
205 *
|
|
206 * @return {@link Control}
|
|
207 */
|
|
208 public Control getControl() {
|
|
209 return row.getControl();
|
|
210 }
|
|
211
|
|
212 /**
|
|
213 * Returns the specified neighbor of this cell, or <code>null</code> if no
|
|
214 * neighbor exists in the given direction. Direction constants can be
|
|
215 * combined by bitwise OR; for example, this method will return the cell to
|
|
216 * the upper-left of the current cell by passing {@link #ABOVE} |
|
|
217 * {@link #LEFT}. If <code>sameLevel</code> is <code>true</code>, only
|
|
218 * cells in sibling rows (under the same parent) will be considered.
|
|
219 *
|
|
220 * @param directionMask
|
|
221 * the direction mask used to identify the requested neighbor
|
|
222 * cell
|
|
223 * @param sameLevel
|
|
224 * if <code>true</code>, only consider cells from sibling rows
|
|
225 * @return the requested neighbor cell, or <code>null</code> if not found
|
|
226 */
|
|
227 public ViewerCell getNeighbor(int directionMask, bool sameLevel) {
|
|
228 ViewerRow row;
|
|
229 int columnIndex;
|
|
230
|
|
231 if ((directionMask & ABOVE) is ABOVE) {
|
|
232 row = this.row.getNeighbor(ViewerRow.ABOVE, sameLevel);
|
|
233 } else if ((directionMask & BELOW) is BELOW) {
|
|
234 row = this.row.getNeighbor(ViewerRow.BELOW, sameLevel);
|
|
235 } else {
|
|
236 row = this.row;
|
|
237 }
|
|
238
|
|
239 if (row !is null) {
|
|
240 if ((directionMask & LEFT) is LEFT) {
|
|
241 columnIndex = getColumnIndex() - 1;
|
|
242 } else if ((directionMask & RIGHT) is RIGHT) {
|
|
243 columnIndex = getColumnIndex() + 1;
|
|
244 } else {
|
|
245 columnIndex = getColumnIndex();
|
|
246 }
|
|
247
|
|
248 if (columnIndex >= 0 && columnIndex < row.getColumnCount()) {
|
|
249 return row.getCell(columnIndex);
|
|
250 }
|
|
251 }
|
|
252
|
|
253 return null;
|
|
254 }
|
|
255
|
|
256 /**
|
|
257 * @return the row
|
|
258 */
|
|
259 public ViewerRow getViewerRow() {
|
|
260 return row;
|
|
261 }
|
|
262
|
|
263 /* (non-Javadoc)
|
|
264 * @see java.lang.Object#hashCode()
|
|
265 */
|
|
266 public override hash_t toHash() {
|
|
267 const int prime = 31;
|
|
268 int result = 1;
|
|
269 result = prime * result + columnIndex;
|
|
270 result = prime * result + ((row is null) ? 0 : row.toHash());
|
|
271 return result;
|
|
272 }
|
|
273
|
|
274 /* (non-Javadoc)
|
|
275 * @see java.lang.Object#equals(java.lang.Object)
|
|
276 */
|
|
277 public override int opEquals(Object obj) {
|
|
278 if (this is obj)
|
|
279 return true;
|
|
280 if (obj is null)
|
|
281 return false;
|
|
282 if (this.classinfo !is obj.classinfo )
|
|
283 return false;
|
|
284 ViewerCell other = cast(ViewerCell) obj;
|
|
285 if (columnIndex !is other.columnIndex)
|
|
286 return false;
|
|
287 if (row is null) {
|
|
288 if (other.row !is null)
|
|
289 return false;
|
|
290 } else if (!row.opEquals(other.row))
|
|
291 return false;
|
|
292 return true;
|
|
293 }
|
|
294 }
|