Mercurial > projects > dwt-samples
comparison snippets/display/Snippet235.d @ 132:104f5ed240fc
More snippets from TomD, thanks!
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 29 Jul 2008 01:50:10 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
130:5c1906bfc206 | 132:104f5ed240fc |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2006 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 * D Port: | |
11 * Thomas Demmer <t_demmer AT web DOT de> | |
12 *******************************************************************************/ | |
13 module display.Snippet235; | |
14 /* | |
15 * example snippet: detect a system settings change | |
16 * | |
17 * For a list of all DWT example snippets see | |
18 * http://www.eclipse.org/swt/snippets/ | |
19 * | |
20 * @since 3.2 | |
21 */ | |
22 | |
23 import dwt.DWT; | |
24 import dwt.graphics.Color; | |
25 import dwt.layout.GridData; | |
26 import dwt.layout.GridLayout; | |
27 import dwt.widgets.Display; | |
28 import dwt.widgets.Event; | |
29 import dwt.widgets.Label; | |
30 import dwt.widgets.Listener; | |
31 import dwt.widgets.Shell; | |
32 import dwt.widgets.Table; | |
33 import dwt.widgets.TableColumn; | |
34 import dwt.widgets.TableItem; | |
35 | |
36 import dwt.dwthelper.utils; | |
37 | |
38 void main(String [] args) { | |
39 Display display = new Display(); | |
40 Shell shell = new Shell(display); | |
41 shell.setText("The DWT.Settings Event"); | |
42 shell.setLayout(new GridLayout()); | |
43 Label label = new Label(shell, DWT.WRAP); | |
44 label.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, true, false)); | |
45 label.setText("Change a system setting and the table below will be updated."); | |
46 final Table table = new Table(shell, DWT.BORDER); | |
47 table.setLayoutData(new GridData(DWT.FILL, DWT.FILL, true, true)); | |
48 TableColumn column = new TableColumn(table, DWT.NONE); | |
49 column = new TableColumn(table, DWT.NONE); | |
50 column.setWidth(150); | |
51 column = new TableColumn(table, DWT.NONE); | |
52 for (int i = 0; i < colorIds.length; i++) { | |
53 TableItem item = new TableItem(table, DWT.NONE); | |
54 Color color = display.getSystemColor(colorIds[i]); | |
55 item.setText(0, colorNames[i]); | |
56 item.setBackground(1, color); | |
57 item.setText(2, color.toString()); | |
58 } | |
59 TableColumn[] columns = table.getColumns(); | |
60 columns[0].pack(); | |
61 columns[2].pack(); | |
62 display.addListener(DWT.Settings, dgListener((Event event){ | |
63 for (int i = 0; i < colorIds.length; i++) { | |
64 Color color = display.getSystemColor(colorIds[i]); | |
65 TableItem item = table.getItem(i); | |
66 item.setBackground(1, color); | |
67 } | |
68 TableColumn[] columns = table.getColumns(); | |
69 columns[0].pack(); | |
70 columns[2].pack(); | |
71 })); | |
72 | |
73 shell.pack(); | |
74 shell.open(); | |
75 while (!shell.isDisposed()) { | |
76 if (!display.readAndDispatch()) | |
77 display.sleep(); | |
78 } | |
79 display.dispose(); | |
80 } | |
81 static int[] colorIds = | |
82 [ | |
83 DWT.COLOR_INFO_BACKGROUND, | |
84 DWT.COLOR_INFO_FOREGROUND, | |
85 DWT.COLOR_LIST_BACKGROUND, | |
86 DWT.COLOR_LIST_FOREGROUND, | |
87 DWT.COLOR_LIST_SELECTION, | |
88 DWT.COLOR_LIST_SELECTION_TEXT, | |
89 DWT.COLOR_TITLE_BACKGROUND, | |
90 DWT.COLOR_TITLE_BACKGROUND_GRADIENT, | |
91 DWT.COLOR_TITLE_FOREGROUND, | |
92 DWT.COLOR_TITLE_INACTIVE_BACKGROUND, | |
93 DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT, | |
94 DWT.COLOR_TITLE_INACTIVE_FOREGROUND, | |
95 DWT.COLOR_WIDGET_BACKGROUND, | |
96 DWT.COLOR_WIDGET_BORDER, | |
97 DWT.COLOR_WIDGET_DARK_SHADOW, | |
98 DWT.COLOR_WIDGET_FOREGROUND, | |
99 DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW, | |
100 DWT.COLOR_WIDGET_LIGHT_SHADOW, | |
101 DWT.COLOR_WIDGET_NORMAL_SHADOW, | |
102 ]; | |
103 static String [] colorNames = | |
104 [ | |
105 "DWT.COLOR_INFO_BACKGROUND", | |
106 "DWT.COLOR_INFO_FOREGROUND", | |
107 "DWT.COLOR_LIST_BACKGROUND", | |
108 "DWT.COLOR_LIST_FOREGROUND", | |
109 "DWT.COLOR_LIST_SELECTION", | |
110 "DWT.COLOR_LIST_SELECTION_TEXT", | |
111 "DWT.COLOR_TITLE_BACKGROUND", | |
112 "DWT.COLOR_TITLE_BACKGROUND_GRADIENT", | |
113 "DWT.COLOR_TITLE_FOREGROUND", | |
114 "DWT.COLOR_TITLE_INACTIVE_BACKGROUND", | |
115 "DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT", | |
116 "DWT.COLOR_TITLE_INACTIVE_FOREGROUND", | |
117 "DWT.COLOR_WIDGET_BACKGROUND", | |
118 "DWT.COLOR_WIDGET_BORDER", | |
119 "DWT.COLOR_WIDGET_DARK_SHADOW", | |
120 "DWT.COLOR_WIDGET_FOREGROUND", | |
121 "DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW", | |
122 "DWT.COLOR_WIDGET_LIGHT_SHADOW", | |
123 "DWT.COLOR_WIDGET_NORMAL_SHADOW", | |
124 ]; |