Mercurial > projects > dwt-samples
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet235.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * D Port: + * Thomas Demmer <t_demmer AT web DOT de> + *******************************************************************************/ +module display.Snippet235; +/* + * example snippet: detect a system settings change + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.2 + */ + +import dwt.DWT; +import dwt.graphics.Color; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Label; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.widgets.Table; +import dwt.widgets.TableColumn; +import dwt.widgets.TableItem; + +import dwt.dwthelper.utils; + +void main(String [] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setText("The DWT.Settings Event"); + shell.setLayout(new GridLayout()); + Label label = new Label(shell, DWT.WRAP); + label.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, true, false)); + label.setText("Change a system setting and the table below will be updated."); + final Table table = new Table(shell, DWT.BORDER); + table.setLayoutData(new GridData(DWT.FILL, DWT.FILL, true, true)); + TableColumn column = new TableColumn(table, DWT.NONE); + column = new TableColumn(table, DWT.NONE); + column.setWidth(150); + column = new TableColumn(table, DWT.NONE); + for (int i = 0; i < colorIds.length; i++) { + TableItem item = new TableItem(table, DWT.NONE); + Color color = display.getSystemColor(colorIds[i]); + item.setText(0, colorNames[i]); + item.setBackground(1, color); + item.setText(2, color.toString()); + } + TableColumn[] columns = table.getColumns(); + columns[0].pack(); + columns[2].pack(); + display.addListener(DWT.Settings, dgListener((Event event){ + for (int i = 0; i < colorIds.length; i++) { + Color color = display.getSystemColor(colorIds[i]); + TableItem item = table.getItem(i); + item.setBackground(1, color); + } + TableColumn[] columns = table.getColumns(); + columns[0].pack(); + columns[2].pack(); + })); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} +static int[] colorIds = + [ + DWT.COLOR_INFO_BACKGROUND, + DWT.COLOR_INFO_FOREGROUND, + DWT.COLOR_LIST_BACKGROUND, + DWT.COLOR_LIST_FOREGROUND, + DWT.COLOR_LIST_SELECTION, + DWT.COLOR_LIST_SELECTION_TEXT, + DWT.COLOR_TITLE_BACKGROUND, + DWT.COLOR_TITLE_BACKGROUND_GRADIENT, + DWT.COLOR_TITLE_FOREGROUND, + DWT.COLOR_TITLE_INACTIVE_BACKGROUND, + DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT, + DWT.COLOR_TITLE_INACTIVE_FOREGROUND, + DWT.COLOR_WIDGET_BACKGROUND, + DWT.COLOR_WIDGET_BORDER, + DWT.COLOR_WIDGET_DARK_SHADOW, + DWT.COLOR_WIDGET_FOREGROUND, + DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW, + DWT.COLOR_WIDGET_LIGHT_SHADOW, + DWT.COLOR_WIDGET_NORMAL_SHADOW, + ]; +static String [] colorNames = + [ + "DWT.COLOR_INFO_BACKGROUND", + "DWT.COLOR_INFO_FOREGROUND", + "DWT.COLOR_LIST_BACKGROUND", + "DWT.COLOR_LIST_FOREGROUND", + "DWT.COLOR_LIST_SELECTION", + "DWT.COLOR_LIST_SELECTION_TEXT", + "DWT.COLOR_TITLE_BACKGROUND", + "DWT.COLOR_TITLE_BACKGROUND_GRADIENT", + "DWT.COLOR_TITLE_FOREGROUND", + "DWT.COLOR_TITLE_INACTIVE_BACKGROUND", + "DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT", + "DWT.COLOR_TITLE_INACTIVE_FOREGROUND", + "DWT.COLOR_WIDGET_BACKGROUND", + "DWT.COLOR_WIDGET_BORDER", + "DWT.COLOR_WIDGET_DARK_SHADOW", + "DWT.COLOR_WIDGET_FOREGROUND", + "DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW", + "DWT.COLOR_WIDGET_LIGHT_SHADOW", + "DWT.COLOR_WIDGET_NORMAL_SHADOW", + ];