0
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtexamples.controlexample.TableTab;
|
|
14
|
|
15
|
|
16
|
|
17 import dwt.DWT;
|
|
18 import dwt.events.DisposeEvent;
|
|
19 import dwt.events.DisposeListener;
|
|
20 import dwt.events.SelectionAdapter;
|
|
21 import dwt.events.SelectionEvent;
|
|
22 import dwt.events.SelectionListener;
|
|
23 import dwt.graphics.Color;
|
|
24 import dwt.graphics.Font;
|
|
25 import dwt.graphics.FontData;
|
|
26 import dwt.graphics.Image;
|
|
27 import dwt.graphics.Point;
|
|
28 import dwt.graphics.RGB;
|
|
29 import dwt.layout.GridData;
|
|
30 import dwt.layout.GridLayout;
|
|
31 import dwt.widgets.Button;
|
|
32 import dwt.widgets.Event;
|
|
33 import dwt.widgets.Group;
|
|
34 import dwt.widgets.Item;
|
|
35 import dwt.widgets.Menu;
|
|
36 import dwt.widgets.MenuItem;
|
|
37 import dwt.widgets.Table;
|
|
38 import dwt.widgets.TableColumn;
|
|
39 import dwt.widgets.TableItem;
|
|
40 import dwt.widgets.Widget;
|
|
41
|
|
42 import dwtexamples.controlexample.Tab;
|
|
43 import dwtexamples.controlexample.ControlExample;
|
|
44 import dwtexamples.controlexample.ScrollableTab;
|
|
45 import tango.text.convert.Format;
|
|
46 import tango.util.Convert;
|
|
47 import tango.core.Exception;
|
|
48
|
|
49 class TableTab : ScrollableTab {
|
|
50 /* Example widgets and groups that contain them */
|
|
51 Table table1;
|
|
52 Group tableGroup;
|
|
53
|
|
54 /* Size widgets added to the "Size" group */
|
|
55 Button packColumnsButton;
|
|
56
|
|
57 /* Style widgets added to the "Style" group */
|
|
58 Button checkButton, fullSelectionButton, hideSelectionButton;
|
|
59
|
|
60 /* Other widgets added to the "Other" group */
|
|
61 Button multipleColumns, moveableColumns, resizableColumns, headerVisibleButton, sortIndicatorButton, headerImagesButton, linesVisibleButton, subImagesButton;
|
|
62
|
|
63 /* Controls and resources added to the "Colors and Fonts" group */
|
|
64 static const int ITEM_FOREGROUND_COLOR = 3;
|
|
65 static const int ITEM_BACKGROUND_COLOR = 4;
|
|
66 static const int ITEM_FONT = 5;
|
|
67 static const int CELL_FOREGROUND_COLOR = 6;
|
|
68 static const int CELL_BACKGROUND_COLOR = 7;
|
|
69 static const int CELL_FONT = 8;
|
|
70 Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor;
|
|
71 Font itemFont, cellFont;
|
|
72
|
|
73 static char[] [] columnTitles;
|
|
74 static char[][][] tableData;
|
|
75
|
|
76 Point menuMouseCoords;
|
|
77
|
|
78 /**
|
|
79 * Creates the Tab within a given instance of ControlExample.
|
|
80 */
|
|
81 this(ControlExample instance) {
|
|
82 super(instance);
|
|
83 if( columnTitles.length is 0 ){
|
|
84 columnTitles = [
|
|
85 ControlExample.getResourceString("TableTitle_0"),
|
|
86 ControlExample.getResourceString("TableTitle_1"),
|
|
87 ControlExample.getResourceString("TableTitle_2"),
|
|
88 ControlExample.getResourceString("TableTitle_3")];
|
|
89 }
|
|
90 if( tableData.length is 0 ){
|
|
91 tableData = [
|
|
92 [ ControlExample.getResourceString("TableLine0_0"),
|
|
93 ControlExample.getResourceString("TableLine0_1"),
|
|
94 ControlExample.getResourceString("TableLine0_2"),
|
|
95 ControlExample.getResourceString("TableLine0_3") ],
|
|
96 [ ControlExample.getResourceString("TableLine1_0"),
|
|
97 ControlExample.getResourceString("TableLine1_1"),
|
|
98 ControlExample.getResourceString("TableLine1_2"),
|
|
99 ControlExample.getResourceString("TableLine1_3") ],
|
|
100 [ ControlExample.getResourceString("TableLine2_0"),
|
|
101 ControlExample.getResourceString("TableLine2_1"),
|
|
102 ControlExample.getResourceString("TableLine2_2"),
|
|
103 ControlExample.getResourceString("TableLine2_3") ]];
|
|
104 }
|
|
105 }
|
|
106
|
|
107 /**
|
|
108 * Creates the "Colors and Fonts" group.
|
|
109 */
|
|
110 void createColorAndFontGroup () {
|
|
111 super.createColorAndFontGroup();
|
|
112
|
|
113 TableItem item = new TableItem(colorAndFontTable, DWT.None);
|
|
114 item.setText(ControlExample.getResourceString ("Item_Foreground_Color"));
|
|
115 item = new TableItem(colorAndFontTable, DWT.None);
|
|
116 item.setText(ControlExample.getResourceString ("Item_Background_Color"));
|
|
117 item = new TableItem(colorAndFontTable, DWT.None);
|
|
118 item.setText(ControlExample.getResourceString ("Item_Font"));
|
|
119 item = new TableItem(colorAndFontTable, DWT.None);
|
|
120 item.setText(ControlExample.getResourceString ("Cell_Foreground_Color"));
|
|
121 item = new TableItem(colorAndFontTable, DWT.None);
|
|
122 item.setText(ControlExample.getResourceString ("Cell_Background_Color"));
|
|
123 item = new TableItem(colorAndFontTable, DWT.None);
|
|
124 item.setText(ControlExample.getResourceString ("Cell_Font"));
|
|
125
|
|
126 shell.addDisposeListener(new class() DisposeListener {
|
|
127 public void widgetDisposed(DisposeEvent event) {
|
|
128 if (itemBackgroundColor !is null) itemBackgroundColor.dispose();
|
|
129 if (itemForegroundColor !is null) itemForegroundColor.dispose();
|
|
130 if (itemFont !is null) itemFont.dispose();
|
|
131 if (cellBackgroundColor !is null) cellBackgroundColor.dispose();
|
|
132 if (cellForegroundColor !is null) cellForegroundColor.dispose();
|
|
133 if (cellFont !is null) cellFont.dispose();
|
|
134 itemBackgroundColor = null;
|
|
135 itemForegroundColor = null;
|
|
136 itemFont = null;
|
|
137 cellBackgroundColor = null;
|
|
138 cellForegroundColor = null;
|
|
139 cellFont = null;
|
|
140 }
|
|
141 });
|
|
142 }
|
|
143
|
|
144 void changeFontOrColor(int index) {
|
|
145 switch (index) {
|
|
146 case ITEM_FOREGROUND_COLOR: {
|
|
147 Color oldColor = itemForegroundColor;
|
|
148 if (oldColor is null) oldColor = table1.getItem (0).getForeground ();
|
|
149 colorDialog.setRGB(oldColor.getRGB());
|
|
150 RGB rgb = colorDialog.open();
|
|
151 if (rgb is null) return;
|
|
152 oldColor = itemForegroundColor;
|
|
153 itemForegroundColor = new Color (display, rgb);
|
|
154 setItemForeground ();
|
|
155 if (oldColor !is null) oldColor.dispose ();
|
|
156 }
|
|
157 break;
|
|
158 case ITEM_BACKGROUND_COLOR: {
|
|
159 Color oldColor = itemBackgroundColor;
|
|
160 if (oldColor is null) oldColor = table1.getItem (0).getBackground ();
|
|
161 colorDialog.setRGB(oldColor.getRGB());
|
|
162 RGB rgb = colorDialog.open();
|
|
163 if (rgb is null) return;
|
|
164 oldColor = itemBackgroundColor;
|
|
165 itemBackgroundColor = new Color (display, rgb);
|
|
166 setItemBackground ();
|
|
167 if (oldColor !is null) oldColor.dispose ();
|
|
168 }
|
|
169 break;
|
|
170 case ITEM_FONT: {
|
|
171 Font oldFont = itemFont;
|
|
172 if (oldFont is null) oldFont = table1.getItem (0).getFont ();
|
|
173 fontDialog.setFontList(oldFont.getFontData());
|
|
174 FontData fontData = fontDialog.open ();
|
|
175 if (fontData is null) return;
|
|
176 oldFont = itemFont;
|
|
177 itemFont = new Font (display, fontData);
|
|
178 setItemFont ();
|
|
179 setExampleWidgetSize ();
|
|
180 if (oldFont !is null) oldFont.dispose ();
|
|
181 }
|
|
182 break;
|
|
183 case CELL_FOREGROUND_COLOR: {
|
|
184 Color oldColor = cellForegroundColor;
|
|
185 if (oldColor is null) oldColor = table1.getItem (0).getForeground (1);
|
|
186 colorDialog.setRGB(oldColor.getRGB());
|
|
187 RGB rgb = colorDialog.open();
|
|
188 if (rgb is null) return;
|
|
189 oldColor = cellForegroundColor;
|
|
190 cellForegroundColor = new Color (display, rgb);
|
|
191 setCellForeground ();
|
|
192 if (oldColor !is null) oldColor.dispose ();
|
|
193 }
|
|
194 break;
|
|
195 case CELL_BACKGROUND_COLOR: {
|
|
196 Color oldColor = cellBackgroundColor;
|
|
197 if (oldColor is null) oldColor = table1.getItem (0).getBackground (1);
|
|
198 colorDialog.setRGB(oldColor.getRGB());
|
|
199 RGB rgb = colorDialog.open();
|
|
200 if (rgb is null) return;
|
|
201 oldColor = cellBackgroundColor;
|
|
202 cellBackgroundColor = new Color (display, rgb);
|
|
203 setCellBackground ();
|
|
204 if (oldColor !is null) oldColor.dispose ();
|
|
205 }
|
|
206 break;
|
|
207 case CELL_FONT: {
|
|
208 Font oldFont = cellFont;
|
|
209 if (oldFont is null) oldFont = table1.getItem (0).getFont (1);
|
|
210 fontDialog.setFontList(oldFont.getFontData());
|
|
211 FontData fontData = fontDialog.open ();
|
|
212 if (fontData is null) return;
|
|
213 oldFont = cellFont;
|
|
214 cellFont = new Font (display, fontData);
|
|
215 setCellFont ();
|
|
216 setExampleWidgetSize ();
|
|
217 if (oldFont !is null) oldFont.dispose ();
|
|
218 }
|
|
219 break;
|
|
220 default:
|
|
221 super.changeFontOrColor(index);
|
|
222 }
|
|
223 }
|
|
224
|
|
225 /**
|
|
226 * Creates the "Other" group.
|
|
227 */
|
|
228 void createOtherGroup () {
|
|
229 super.createOtherGroup ();
|
|
230
|
|
231 /* Create display controls specific to this example */
|
|
232 linesVisibleButton = new Button (otherGroup, DWT.CHECK);
|
|
233 linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible"));
|
|
234 multipleColumns = new Button (otherGroup, DWT.CHECK);
|
|
235 multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns"));
|
|
236 multipleColumns.setSelection(true);
|
|
237 headerVisibleButton = new Button (otherGroup, DWT.CHECK);
|
|
238 headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible"));
|
|
239 sortIndicatorButton = new Button (otherGroup, DWT.CHECK);
|
|
240 sortIndicatorButton.setText (ControlExample.getResourceString("Sort_Indicator"));
|
|
241 moveableColumns = new Button (otherGroup, DWT.CHECK);
|
|
242 moveableColumns.setText (ControlExample.getResourceString("Moveable_Columns"));
|
|
243 resizableColumns = new Button (otherGroup, DWT.CHECK);
|
|
244 resizableColumns.setText (ControlExample.getResourceString("Resizable_Columns"));
|
|
245 headerImagesButton = new Button (otherGroup, DWT.CHECK);
|
|
246 headerImagesButton.setText (ControlExample.getResourceString("Header_Images"));
|
|
247 subImagesButton = new Button (otherGroup, DWT.CHECK);
|
|
248 subImagesButton.setText (ControlExample.getResourceString("Sub_Images"));
|
|
249
|
|
250 /* Add the listeners */
|
|
251 linesVisibleButton.addSelectionListener (new class() SelectionAdapter {
|
|
252 public void widgetSelected (SelectionEvent event) {
|
|
253 setWidgetLinesVisible ();
|
|
254 }
|
|
255 });
|
|
256 multipleColumns.addSelectionListener (new class() SelectionAdapter {
|
|
257 public void widgetSelected (SelectionEvent event) {
|
|
258 recreateExampleWidgets ();
|
|
259 }
|
|
260 });
|
|
261 headerVisibleButton.addSelectionListener (new class() SelectionAdapter {
|
|
262 public void widgetSelected (SelectionEvent event) {
|
|
263 setWidgetHeaderVisible ();
|
|
264 }
|
|
265 });
|
|
266 sortIndicatorButton.addSelectionListener (new class() SelectionAdapter {
|
|
267 public void widgetSelected (SelectionEvent event) {
|
|
268 setWidgetSortIndicator ();
|
|
269 }
|
|
270 });
|
|
271 moveableColumns.addSelectionListener (new class() SelectionAdapter {
|
|
272 public void widgetSelected (SelectionEvent event) {
|
|
273 setColumnsMoveable ();
|
|
274 }
|
|
275 });
|
|
276 resizableColumns.addSelectionListener (new class() SelectionAdapter {
|
|
277 public void widgetSelected (SelectionEvent event) {
|
|
278 setColumnsResizable ();
|
|
279 }
|
|
280 });
|
|
281 headerImagesButton.addSelectionListener (new class() SelectionAdapter {
|
|
282 public void widgetSelected (SelectionEvent event) {
|
|
283 recreateExampleWidgets ();
|
|
284 }
|
|
285 });
|
|
286 subImagesButton.addSelectionListener (new class() SelectionAdapter {
|
|
287 public void widgetSelected (SelectionEvent event) {
|
|
288 recreateExampleWidgets ();
|
|
289 }
|
|
290 });
|
|
291 }
|
|
292
|
|
293 /**
|
|
294 * Creates the "Example" group.
|
|
295 */
|
|
296 void createExampleGroup () {
|
|
297 super.createExampleGroup ();
|
|
298
|
|
299 /* Create a group for the table */
|
|
300 tableGroup = new Group (exampleGroup, DWT.NONE);
|
|
301 tableGroup.setLayout (new GridLayout ());
|
|
302 tableGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
|
|
303 tableGroup.setText ("Table");
|
|
304 }
|
|
305
|
|
306 /**
|
|
307 * Creates the "Example" widgets.
|
|
308 */
|
|
309 void createExampleWidgets () {
|
|
310 /* Compute the widget style */
|
|
311 int style = getDefaultStyle();
|
|
312 if (singleButton.getSelection ()) style |= DWT.SINGLE;
|
|
313 if (multiButton.getSelection ()) style |= DWT.MULTI;
|
|
314 if (verticalButton.getSelection ()) style |= DWT.V_SCROLL;
|
|
315 if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL;
|
|
316 if (checkButton.getSelection ()) style |= DWT.CHECK;
|
|
317 if (fullSelectionButton.getSelection ()) style |= DWT.FULL_SELECTION;
|
|
318 if (hideSelectionButton.getSelection ()) style |= DWT.HIDE_SELECTION;
|
|
319 if (borderButton.getSelection ()) style |= DWT.BORDER;
|
|
320
|
|
321 /* Create the table widget */
|
|
322 table1 = new Table (tableGroup, style);
|
|
323
|
|
324 /* Fill the table with data */
|
|
325 bool multiColumn = multipleColumns.getSelection();
|
|
326 if (multiColumn) {
|
|
327 for (int i = 0; i < columnTitles.length; i++) {
|
|
328 TableColumn tableColumn = new TableColumn(table1, DWT.NONE);
|
|
329 tableColumn.setText(columnTitles[i]);
|
|
330 tableColumn.setToolTipText( Format( ControlExample.getResourceString("Tooltip"), columnTitles[i] ));
|
|
331 if (headerImagesButton.getSelection()) tableColumn.setImage(instance.images [i % 3]);
|
|
332 }
|
|
333 table1.setSortColumn(table1.getColumn(0));
|
|
334 }
|
|
335 for (int i=0; i<16; i++) {
|
|
336 TableItem item = new TableItem (table1, DWT.NONE);
|
|
337 if (multiColumn && subImagesButton.getSelection()) {
|
|
338 for (int j = 0; j < columnTitles.length; j++) {
|
|
339 item.setImage(j, instance.images [i % 3]);
|
|
340 }
|
|
341 } else {
|
|
342 item.setImage(instance.images [i % 3]);
|
|
343 }
|
|
344 setItemText (item, i, ControlExample.getResourceString("Index") ~ to!(char[])(i));
|
|
345 }
|
|
346 packColumns();
|
|
347 }
|
|
348
|
|
349 void setItemText(TableItem item, int i, char[] node) {
|
|
350 int index = i % 3;
|
|
351 if (multipleColumns.getSelection()) {
|
|
352 tableData [index][0] = node;
|
|
353 item.setText (tableData [index]);
|
|
354 } else {
|
|
355 item.setText (node);
|
|
356 }
|
|
357 }
|
|
358
|
|
359 /**
|
|
360 * Creates the "Size" group. The "Size" group contains
|
|
361 * controls that allow the user to change the size of
|
|
362 * the example widgets.
|
|
363 */
|
|
364 void createSizeGroup () {
|
|
365 super.createSizeGroup();
|
|
366
|
|
367 packColumnsButton = new Button (sizeGroup, DWT.PUSH);
|
|
368 packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns"));
|
|
369 packColumnsButton.addSelectionListener(new class() SelectionAdapter {
|
|
370 public void widgetSelected (SelectionEvent event) {
|
|
371 packColumns ();
|
|
372 setExampleWidgetSize ();
|
|
373 }
|
|
374 });
|
|
375 }
|
|
376
|
|
377 /**
|
|
378 * Creates the "Style" group.
|
|
379 */
|
|
380 void createStyleGroup () {
|
|
381 super.createStyleGroup ();
|
|
382
|
|
383 /* Create the extra widgets */
|
|
384 checkButton = new Button (styleGroup, DWT.CHECK);
|
|
385 checkButton.setText ("DWT.CHECK");
|
|
386 fullSelectionButton = new Button (styleGroup, DWT.CHECK);
|
|
387 fullSelectionButton.setText ("DWT.FULL_SELECTION");
|
|
388 hideSelectionButton = new Button (styleGroup, DWT.CHECK);
|
|
389 hideSelectionButton.setText ("DWT.HIDE_SELECTION");
|
|
390 }
|
|
391
|
|
392 /**
|
|
393 * Gets the "Example" widget children's items, if any.
|
|
394 *
|
|
395 * @return an array containing the example widget children's items
|
|
396 */
|
|
397 Item [] getExampleWidgetItems () {
|
|
398 Item [] columns = table1.getColumns();
|
|
399 Item [] items = table1.getItems();
|
|
400 Item [] allItems = new Item [columns.length + items.length];
|
|
401 System.arraycopy(columns, 0, allItems, 0, columns.length);
|
|
402 System.arraycopy(items, 0, allItems, columns.length, items.length);
|
|
403 return allItems;
|
|
404 }
|
|
405
|
|
406 /**
|
|
407 * Gets the "Example" widget children.
|
|
408 */
|
|
409 Widget [] getExampleWidgets () {
|
|
410 return [ cast(Widget) table1 ];
|
|
411 }
|
|
412
|
|
413 /**
|
|
414 * Returns a list of set/get API method names (without the set/get prefix)
|
|
415 * that can be used to set/get values in the example control(s).
|
|
416 */
|
|
417 char[][] getMethodNames() {
|
|
418 return ["ColumnOrder", "ItemCount", "Selection", "SelectionIndex", "ToolTipText", "TopIndex"];
|
|
419 }
|
|
420
|
|
421 char[] setMethodName(char[] methodRoot) {
|
|
422 /* Override to handle special case of int getSelectionIndex()/setSelection(int) */
|
|
423 return (methodRoot == "SelectionIndex" ) ? "setSelection" : "set" ~ methodRoot;
|
|
424 }
|
|
425
|
|
426 void packColumns () {
|
|
427 int columnCount = table1.getColumnCount();
|
|
428 for (int i = 0; i < columnCount; i++) {
|
|
429 TableColumn tableColumn = table1.getColumn(i);
|
|
430 tableColumn.pack();
|
|
431 }
|
|
432 }
|
|
433
|
|
434 //PORTING_LEFT
|
|
435 /+
|
|
436 Object[] parameterForType(char[] typeName, char[] value, Widget widget) {
|
|
437 if (value.length is 0 ) return [new TableItem[0]]; // bug in Table?
|
|
438 if (typeName.equals("org.eclipse.swt.widgets.TableItem")) {
|
|
439 TableItem item = findItem(value, ((Table) widget).getItems());
|
|
440 if (item !is null) return new Object[] {item};
|
|
441 }
|
|
442 if (typeName.equals("[Lorg.eclipse.swt.widgets.TableItem;")) {
|
|
443 char[][] values = split(value, ',');
|
|
444 TableItem[] items = new TableItem[values.length];
|
|
445 for (int i = 0; i < values.length; i++) {
|
|
446 items[i] = findItem(values[i], ((Table) widget).getItems());
|
|
447 }
|
|
448 return new Object[] {items};
|
|
449 }
|
|
450 return super.parameterForType(typeName, value, widget);
|
|
451 }
|
|
452 +/
|
|
453 TableItem findItem(char[] value, TableItem[] items) {
|
|
454 for (int i = 0; i < items.length; i++) {
|
|
455 TableItem item = items[i];
|
|
456 if (item.getText() == value ) return item;
|
|
457 }
|
|
458 return null;
|
|
459 }
|
|
460
|
|
461 /**
|
|
462 * Gets the text for the tab folder item.
|
|
463 */
|
|
464 char[] getTabText () {
|
|
465 return "Table";
|
|
466 }
|
|
467
|
|
468 /**
|
|
469 * Sets the foreground color, background color, and font
|
|
470 * of the "Example" widgets to their default settings.
|
|
471 * Also sets foreground and background color of TableItem [0]
|
|
472 * to default settings.
|
|
473 */
|
|
474 void resetColorsAndFonts () {
|
|
475 super.resetColorsAndFonts ();
|
|
476 Color oldColor = itemForegroundColor;
|
|
477 itemForegroundColor = null;
|
|
478 setItemForeground ();
|
|
479 if (oldColor !is null) oldColor.dispose();
|
|
480 oldColor = itemBackgroundColor;
|
|
481 itemBackgroundColor = null;
|
|
482 setItemBackground ();
|
|
483 if (oldColor !is null) oldColor.dispose();
|
|
484 Font oldFont = font;
|
|
485 itemFont = null;
|
|
486 setItemFont ();
|
|
487 if (oldFont !is null) oldFont.dispose();
|
|
488 oldColor = cellForegroundColor;
|
|
489 cellForegroundColor = null;
|
|
490 setCellForeground ();
|
|
491 if (oldColor !is null) oldColor.dispose();
|
|
492 oldColor = cellBackgroundColor;
|
|
493 cellBackgroundColor = null;
|
|
494 setCellBackground ();
|
|
495 if (oldColor !is null) oldColor.dispose();
|
|
496 oldFont = font;
|
|
497 cellFont = null;
|
|
498 setCellFont ();
|
|
499 if (oldFont !is null) oldFont.dispose();
|
|
500 }
|
|
501
|
|
502 /**
|
|
503 * Sets the background color of the Row 0 TableItem in column 1.
|
|
504 */
|
|
505 void setCellBackground () {
|
|
506 if (!instance.startup) {
|
|
507 table1.getItem (0).setBackground (1, cellBackgroundColor);
|
|
508 }
|
|
509 /* Set the background color item's image to match the background color of the cell. */
|
|
510 Color color = cellBackgroundColor;
|
|
511 if (color is null) color = table1.getItem (0).getBackground (1);
|
|
512 TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR);
|
|
513 Image oldImage = item.getImage();
|
|
514 if (oldImage !is null) oldImage.dispose();
|
|
515 item.setImage (colorImage(color));
|
|
516 }
|
|
517
|
|
518 /**
|
|
519 * Sets the foreground color of the Row 0 TableItem in column 1.
|
|
520 */
|
|
521 void setCellForeground () {
|
|
522 if (!instance.startup) {
|
|
523 table1.getItem (0).setForeground (1, cellForegroundColor);
|
|
524 }
|
|
525 /* Set the foreground color item's image to match the foreground color of the cell. */
|
|
526 Color color = cellForegroundColor;
|
|
527 if (color is null) color = table1.getItem (0).getForeground (1);
|
|
528 TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR);
|
|
529 Image oldImage = item.getImage();
|
|
530 if (oldImage !is null) oldImage.dispose();
|
|
531 item.setImage (colorImage(color));
|
|
532 }
|
|
533
|
|
534 /**
|
|
535 * Sets the font of the Row 0 TableItem in column 1.
|
|
536 */
|
|
537 void setCellFont () {
|
|
538 if (!instance.startup) {
|
|
539 table1.getItem (0).setFont (1, cellFont);
|
|
540 }
|
|
541 /* Set the font item's image to match the font of the item. */
|
|
542 Font ft = cellFont;
|
|
543 if (ft is null) ft = table1.getItem (0).getFont (1);
|
|
544 TableItem item = colorAndFontTable.getItem(CELL_FONT);
|
|
545 Image oldImage = item.getImage();
|
|
546 if (oldImage !is null) oldImage.dispose();
|
|
547 item.setImage (fontImage(ft));
|
|
548 item.setFont(ft);
|
|
549 colorAndFontTable.layout ();
|
|
550 }
|
|
551
|
|
552 /**
|
|
553 * Sets the background color of TableItem [0].
|
|
554 */
|
|
555 void setItemBackground () {
|
|
556 if (!instance.startup) {
|
|
557 table1.getItem (0).setBackground (itemBackgroundColor);
|
|
558 }
|
|
559 /* Set the background color item's image to match the background color of the item. */
|
|
560 Color color = itemBackgroundColor;
|
|
561 if (color is null) color = table1.getItem (0).getBackground ();
|
|
562 TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR);
|
|
563 Image oldImage = item.getImage();
|
|
564 if (oldImage !is null) oldImage.dispose();
|
|
565 item.setImage (colorImage(color));
|
|
566 }
|
|
567
|
|
568 /**
|
|
569 * Sets the foreground color of TableItem [0].
|
|
570 */
|
|
571 void setItemForeground () {
|
|
572 if (!instance.startup) {
|
|
573 table1.getItem (0).setForeground (itemForegroundColor);
|
|
574 }
|
|
575 /* Set the foreground color item's image to match the foreground color of the item. */
|
|
576 Color color = itemForegroundColor;
|
|
577 if (color is null) color = table1.getItem (0).getForeground ();
|
|
578 TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR);
|
|
579 Image oldImage = item.getImage();
|
|
580 if (oldImage !is null) oldImage.dispose();
|
|
581 item.setImage (colorImage(color));
|
|
582 }
|
|
583
|
|
584 /**
|
|
585 * Sets the font of TableItem 0.
|
|
586 */
|
|
587 void setItemFont () {
|
|
588 if (!instance.startup) {
|
|
589 table1.getItem (0).setFont (itemFont);
|
|
590 }
|
|
591 /* Set the font item's image to match the font of the item. */
|
|
592 Font ft = itemFont;
|
|
593 if (ft is null) ft = table1.getItem (0).getFont ();
|
|
594 TableItem item = colorAndFontTable.getItem(ITEM_FONT);
|
|
595 Image oldImage = item.getImage();
|
|
596 if (oldImage !is null) oldImage.dispose();
|
|
597 item.setImage (fontImage(ft));
|
|
598 item.setFont(ft);
|
|
599 colorAndFontTable.layout ();
|
|
600 }
|
|
601
|
|
602 /**
|
|
603 * Sets the moveable columns state of the "Example" widgets.
|
|
604 */
|
|
605 void setColumnsMoveable () {
|
|
606 bool selection = moveableColumns.getSelection();
|
|
607 TableColumn[] columns = table1.getColumns();
|
|
608 for (int i = 0; i < columns.length; i++) {
|
|
609 columns[i].setMoveable(selection);
|
|
610 }
|
|
611 }
|
|
612
|
|
613 /**
|
|
614 * Sets the resizable columns state of the "Example" widgets.
|
|
615 */
|
|
616 void setColumnsResizable () {
|
|
617 bool selection = resizableColumns.getSelection();
|
|
618 TableColumn[] columns = table1.getColumns();
|
|
619 for (int i = 0; i < columns.length; i++) {
|
|
620 columns[i].setResizable(selection);
|
|
621 }
|
|
622 }
|
|
623
|
|
624 /**
|
|
625 * Sets the state of the "Example" widgets.
|
|
626 */
|
|
627 void setExampleWidgetState () {
|
|
628 setItemBackground ();
|
|
629 setItemForeground ();
|
|
630 setItemFont ();
|
|
631 setCellBackground ();
|
|
632 setCellForeground ();
|
|
633 setCellFont ();
|
|
634 if (!instance.startup) {
|
|
635 setColumnsMoveable ();
|
|
636 setColumnsResizable ();
|
|
637 setWidgetHeaderVisible ();
|
|
638 setWidgetSortIndicator ();
|
|
639 setWidgetLinesVisible ();
|
|
640 }
|
|
641 super.setExampleWidgetState ();
|
|
642 checkButton.setSelection ((table1.getStyle () & DWT.CHECK) !is 0);
|
|
643 fullSelectionButton.setSelection ((table1.getStyle () & DWT.FULL_SELECTION) !is 0);
|
|
644 hideSelectionButton.setSelection ((table1.getStyle () & DWT.HIDE_SELECTION) !is 0);
|
|
645 try {
|
|
646 TableColumn column = table1.getColumn(0);
|
|
647 moveableColumns.setSelection (column.getMoveable());
|
|
648 resizableColumns.setSelection (column.getResizable());
|
|
649 } catch (IllegalArgumentException ex) {}
|
|
650 headerVisibleButton.setSelection (table1.getHeaderVisible());
|
|
651 linesVisibleButton.setSelection (table1.getLinesVisible());
|
|
652 }
|
|
653
|
|
654 /**
|
|
655 * Sets the header visible state of the "Example" widgets.
|
|
656 */
|
|
657 void setWidgetHeaderVisible () {
|
|
658 table1.setHeaderVisible (headerVisibleButton.getSelection ());
|
|
659 }
|
|
660
|
|
661 /**
|
|
662 * Sets the sort indicator state of the "Example" widgets.
|
|
663 */
|
|
664 void setWidgetSortIndicator () {
|
|
665 if (sortIndicatorButton.getSelection ()) {
|
|
666 /* Reset to known state: 'down' on column 0. */
|
|
667 table1.setSortDirection (DWT.DOWN);
|
|
668 TableColumn [] columns = table1.getColumns();
|
|
669 for (int i = 0; i < columns.length; i++) {
|
|
670 TableColumn column = columns[i];
|
|
671 if (i is 0) table1.setSortColumn(column);
|
|
672 SelectionListener listener = new class() SelectionAdapter {
|
|
673 public void widgetSelected(SelectionEvent e) {
|
|
674 int sortDirection = DWT.DOWN;
|
|
675 if (e.widget is table1.getSortColumn()) {
|
|
676 /* If the sort column hasn't changed, cycle down -> up -> none. */
|
|
677 switch (table1.getSortDirection ()) {
|
|
678 case DWT.DOWN: sortDirection = DWT.UP; break;
|
|
679 case DWT.UP: sortDirection = DWT.NONE; break;
|
|
680 }
|
|
681 } else {
|
|
682 table1.setSortColumn(cast(TableColumn)e.widget);
|
|
683 }
|
|
684 table1.setSortDirection (sortDirection);
|
|
685 }
|
|
686 };
|
|
687 column.addSelectionListener(listener);
|
|
688 column.setData("SortListener", cast(Object)listener); //$NON-NLS-1$
|
|
689 }
|
|
690 } else {
|
|
691 table1.setSortDirection (DWT.NONE);
|
|
692 TableColumn [] columns = table1.getColumns();
|
|
693 for (int i = 0; i < columns.length; i++) {
|
|
694 SelectionListener listener = cast(SelectionListener)columns[i].getData("SortListener"); //$NON-NLS-1$
|
|
695 if (listener !is null) columns[i].removeSelectionListener(listener);
|
|
696 }
|
|
697 }
|
|
698 }
|
|
699
|
|
700 /**
|
|
701 * Sets the lines visible state of the "Example" widgets.
|
|
702 */
|
|
703 void setWidgetLinesVisible () {
|
|
704 table1.setLinesVisible (linesVisibleButton.getSelection ());
|
|
705 }
|
|
706
|
|
707 protected void specialPopupMenuItems(Menu menu, Event event) {
|
|
708 MenuItem item = new MenuItem(menu, DWT.PUSH);
|
|
709 item.setText("getItem(Point) on mouse coordinates");
|
|
710 menuMouseCoords = table1.toControl(new Point(event.x, event.y));
|
|
711 item.addSelectionListener(new class() SelectionAdapter {
|
|
712 public void widgetSelected(SelectionEvent e) {
|
|
713 eventConsole.append ("getItem(Point(" ~ menuMouseCoords.toString() ~ ")) returned: " ~ ((table1.getItem(menuMouseCoords))).toString);
|
|
714 eventConsole.append ("\n");
|
|
715 };
|
|
716 });
|
|
717 }
|
|
718 }
|