Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet235.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 4e5843b771cc |
children | 536e43f63c81 |
rev | line source |
---|---|
28 | 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 org.eclipse.swt.snippets.Snippet235; | |
14 /* | |
15 * example snippet: detect a system settings change | |
16 * | |
17 * For a list of all SWT example snippets see | |
18 * http://www.eclipse.org/swt/snippets/ | |
19 * | |
20 * @since 3.2 | |
21 */ | |
22 | |
23 import org.eclipse.swt.SWT; | |
24 import org.eclipse.swt.graphics.Color; | |
25 import org.eclipse.swt.layout.GridData; | |
26 import org.eclipse.swt.layout.GridLayout; | |
27 import org.eclipse.swt.widgets.Display; | |
28 import org.eclipse.swt.widgets.Event; | |
29 import org.eclipse.swt.widgets.Label; | |
30 import org.eclipse.swt.widgets.Listener; | |
31 import org.eclipse.swt.widgets.Shell; | |
32 import org.eclipse.swt.widgets.Table; | |
33 import org.eclipse.swt.widgets.TableColumn; | |
34 import org.eclipse.swt.widgets.TableItem; | |
35 | |
36 import java.lang.all; | |
37 | |
38 void main(String [] args) { | |
39 Display display = new Display(); | |
40 Shell shell = new Shell(display); | |
41 shell.setText("The SWT.Settings Event"); | |
42 shell.setLayout(new GridLayout()); | |
43 Label label = new Label(shell, SWT.WRAP); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
44 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
28 | 45 label.setText("Change a system setting and the table below will be updated."); |
112 | 46 Table table = new Table(shell, SWT.BORDER); |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
47 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
28 | 48 TableColumn column = new TableColumn(table, SWT.NONE); |
49 column = new TableColumn(table, SWT.NONE); | |
50 column.setWidth(150); | |
51 column = new TableColumn(table, SWT.NONE); | |
52 for (int i = 0; i < colorIds.length; i++) { | |
53 TableItem item = new TableItem(table, SWT.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(SWT.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 SWT.COLOR_INFO_BACKGROUND, | |
84 SWT.COLOR_INFO_FOREGROUND, | |
85 SWT.COLOR_LIST_BACKGROUND, | |
86 SWT.COLOR_LIST_FOREGROUND, | |
87 SWT.COLOR_LIST_SELECTION, | |
88 SWT.COLOR_LIST_SELECTION_TEXT, | |
89 SWT.COLOR_TITLE_BACKGROUND, | |
90 SWT.COLOR_TITLE_BACKGROUND_GRADIENT, | |
91 SWT.COLOR_TITLE_FOREGROUND, | |
92 SWT.COLOR_TITLE_INACTIVE_BACKGROUND, | |
93 SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT, | |
94 SWT.COLOR_TITLE_INACTIVE_FOREGROUND, | |
95 SWT.COLOR_WIDGET_BACKGROUND, | |
96 SWT.COLOR_WIDGET_BORDER, | |
97 SWT.COLOR_WIDGET_DARK_SHADOW, | |
98 SWT.COLOR_WIDGET_FOREGROUND, | |
99 SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW, | |
100 SWT.COLOR_WIDGET_LIGHT_SHADOW, | |
101 SWT.COLOR_WIDGET_NORMAL_SHADOW, | |
102 ]; | |
103 static String [] colorNames = | |
104 [ | |
105 "SWT.COLOR_INFO_BACKGROUND", | |
106 "SWT.COLOR_INFO_FOREGROUND", | |
107 "SWT.COLOR_LIST_BACKGROUND", | |
108 "SWT.COLOR_LIST_FOREGROUND", | |
109 "SWT.COLOR_LIST_SELECTION", | |
110 "SWT.COLOR_LIST_SELECTION_TEXT", | |
111 "SWT.COLOR_TITLE_BACKGROUND", | |
112 "SWT.COLOR_TITLE_BACKGROUND_GRADIENT", | |
113 "SWT.COLOR_TITLE_FOREGROUND", | |
114 "SWT.COLOR_TITLE_INACTIVE_BACKGROUND", | |
115 "SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT", | |
116 "SWT.COLOR_TITLE_INACTIVE_FOREGROUND", | |
117 "SWT.COLOR_WIDGET_BACKGROUND", | |
118 "SWT.COLOR_WIDGET_BORDER", | |
119 "SWT.COLOR_WIDGET_DARK_SHADOW", | |
120 "SWT.COLOR_WIDGET_FOREGROUND", | |
121 "SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW", | |
122 "SWT.COLOR_WIDGET_LIGHT_SHADOW", | |
123 "SWT.COLOR_WIDGET_NORMAL_SHADOW", | |
124 ]; |