1 #!/usr/bin/env dub
2 /+
3 dub.sdl:
4     name "snippet235"
5     dependency "dwt" path="../../../../../../"
6     libs \
7       "atk-1.0" \
8       "cairo" \
9       "dl" \
10       "fontconfig" \
11       "gdk-x11-2.0" \
12       "gdk_pixbuf-2.0" \
13       "glib-2.0" \
14       "gmodule-2.0" \
15       "gnomeui-2" \
16       "gnomevfs-2" \
17       "gobject-2.0" \
18       "gthread-2.0" \
19       "gtk-x11-2.0" \
20       "pango-1.0" \
21       "pangocairo-1.0" \
22       "X11" \
23       "Xcomposite" \
24       "Xcursor" \
25       "Xdamage" \
26       "Xext" \
27       "Xfixes" \
28       "Xi" \
29       "Xinerama" \
30       "Xrandr" \
31       "Xrender" \
32       "Xtst" \
33       platform="linux"
34 +/
35 
36 /*******************************************************************************
37  * Copyright (c) 2000, 2006 IBM Corporation and others.
38  * All rights reserved. This program and the accompanying materials
39  * are made available under the terms of the Eclipse Public License v1.0
40  * which accompanies this distribution, and is available at
41  * http://www.eclipse.org/legal/epl-v10.html
42  *
43  * Contributors:
44  *     IBM Corporation - initial API and implementation
45  * D Port:
46  *     Thomas Demmer <t_demmer AT web DOT de>
47  *******************************************************************************/
48 module org.eclipse.swt.snippets.Snippet235;
49 /* 
50  * example snippet: detect a system settings change
51  *
52  * For a list of all SWT example snippets see
53  * http://www.eclipse.org/swt/snippets/
54  * 
55  * @since 3.2
56  */
57 
58 import org.eclipse.swt.SWT;
59 import org.eclipse.swt.graphics.Color;
60 import org.eclipse.swt.layout.GridData;
61 import org.eclipse.swt.layout.GridLayout;
62 import org.eclipse.swt.widgets.Display;
63 import org.eclipse.swt.widgets.Event;
64 import org.eclipse.swt.widgets.Label;
65 import org.eclipse.swt.widgets.Listener;
66 import org.eclipse.swt.widgets.Shell;
67 import org.eclipse.swt.widgets.Table;
68 import org.eclipse.swt.widgets.TableColumn;
69 import org.eclipse.swt.widgets.TableItem;
70 
71 import java.lang.all;
72 
73 void main() {
74     Display display = new Display();
75     Shell shell = new Shell(display);
76     shell.setText("The SWT.Settings Event");
77     shell.setLayout(new GridLayout());
78     Label label = new Label(shell, SWT.WRAP);
79     label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
80     label.setText("Change a system setting and the table below will be updated.");
81     Table table = new Table(shell, SWT.BORDER);
82     table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
83     TableColumn column = new TableColumn(table, SWT.NONE);
84     column = new TableColumn(table, SWT.NONE);
85     column.setWidth(150);
86     column = new TableColumn(table, SWT.NONE);
87     for (int i = 0; i < colorIds.length; i++) {
88         TableItem item = new TableItem(table, SWT.NONE);
89         Color color = display.getSystemColor(colorIds[i]);
90         item.setText(0, colorNames[i]);
91         item.setBackground(1, color);
92         item.setText(2, color.toString());
93     }
94     TableColumn[] columns = table.getColumns();
95     columns[0].pack();
96     columns[2].pack();
97     display.addListener(SWT.Settings, dgListener((Event event){
98         for (int i = 0; i < colorIds.length; i++) {
99             Color color = display.getSystemColor(colorIds[i]);
100             TableItem item = table.getItem(i);
101             item.setBackground(1, color);
102         }
103         TableColumn[] columns = table.getColumns();
104         columns[0].pack();
105         columns[2].pack();
106     }));
107 
108     shell.pack();
109     shell.open();
110     while (!shell.isDisposed()) {
111         if (!display.readAndDispatch())
112             display.sleep();
113     }
114     display.dispose();
115 }
116 const int[19] colorIds = 
117     [ 
118     SWT.COLOR_INFO_BACKGROUND, 
119     SWT.COLOR_INFO_FOREGROUND, 
120     SWT.COLOR_LIST_BACKGROUND,
121     SWT.COLOR_LIST_FOREGROUND,
122     SWT.COLOR_LIST_SELECTION,
123     SWT.COLOR_LIST_SELECTION_TEXT,
124     SWT.COLOR_TITLE_BACKGROUND,
125     SWT.COLOR_TITLE_BACKGROUND_GRADIENT,
126     SWT.COLOR_TITLE_FOREGROUND,
127     SWT.COLOR_TITLE_INACTIVE_BACKGROUND,
128     SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT,
129     SWT.COLOR_TITLE_INACTIVE_FOREGROUND,
130     SWT.COLOR_WIDGET_BACKGROUND,
131     SWT.COLOR_WIDGET_BORDER,
132     SWT.COLOR_WIDGET_DARK_SHADOW,
133     SWT.COLOR_WIDGET_FOREGROUND,
134     SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW,
135     SWT.COLOR_WIDGET_LIGHT_SHADOW,
136     SWT.COLOR_WIDGET_NORMAL_SHADOW,
137     ];
138 const String[19] colorNames = 
139     [
140     "SWT.COLOR_INFO_BACKGROUND",
141     "SWT.COLOR_INFO_FOREGROUND", 
142     "SWT.COLOR_LIST_BACKGROUND",
143     "SWT.COLOR_LIST_FOREGROUND",
144     "SWT.COLOR_LIST_SELECTION",
145     "SWT.COLOR_LIST_SELECTION_TEXT",
146     "SWT.COLOR_TITLE_BACKGROUND",
147     "SWT.COLOR_TITLE_BACKGROUND_GRADIENT",
148     "SWT.COLOR_TITLE_FOREGROUND",
149     "SWT.COLOR_TITLE_INACTIVE_BACKGROUND",
150     "SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT",
151     "SWT.COLOR_TITLE_INACTIVE_FOREGROUND",
152     "SWT.COLOR_WIDGET_BACKGROUND",
153     "SWT.COLOR_WIDGET_BORDER",
154     "SWT.COLOR_WIDGET_DARK_SHADOW",
155     "SWT.COLOR_WIDGET_FOREGROUND",
156     "SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW",
157     "SWT.COLOR_WIDGET_LIGHT_SHADOW",
158     "SWT.COLOR_WIDGET_NORMAL_SHADOW",
159     ];