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