# HG changeset patch # User Frank Benoit # Date 1217289010 -7200 # Node ID 104f5ed240fca86fb803f00775db9abb09f8a0be # Parent 5c1906bfc2069526a39ee6d5a190ed78ceadb1ec More snippets from TomD, thanks! diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet146.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet146.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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 + *******************************************************************************/ +module display.Snippet146; + +/* + * UI Automation (for testing tools) snippet: post key events + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Shell; +import dwt.widgets.Text; + +import dwt.dwthelper.utils; + +import tango.core.Thread; +import tango.text.Unicode; + +void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + Text text = new Text(shell, DWT.BORDER); + text.setSize(text.computeSize(150, DWT.DEFAULT)); + shell.pack(); + shell.open(); + Thread thread = new Thread({ + String string = "Love the method."; + String lstring; + lstring. length = string.length; + toLower(string, lstring); + for (int i = 0; i < string.length; i++) { + char ch = string.charAt(i); + bool shift = isUpper(ch); + ch = lstring.charAt(i); + if (shift) { + Event event = new Event(); + event.type = DWT.KeyDown; + event.keyCode = DWT.SHIFT; + display.post(event); + } + Event event = new Event(); + event.type = DWT.KeyDown; + event.character = ch; + display.post(event); + try { + Thread.sleep(10/1000.); + } catch (InterruptedException e) {} + event.type = DWT.KeyUp; + display.post(event); + try { + Thread.sleep(100/1000.0); + } catch (InterruptedException e) {} + if (shift) { + event = new Event(); + event.type = DWT.KeyUp; + event.keyCode = DWT.SHIFT; + display.post(event); + } + } + }); + thread.start(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); +} + diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet16.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet16.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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 + *******************************************************************************/ +module display.Snippet16; + +/* + * Display example snippet: create one repeating timer (every 500 ms) + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; +import dwt.dwthelper.Runnable; + +import tango.io.Stdout; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + final int time = 500; + Runnable timer; + timer = dgRunnable( { + Point point = display.getCursorLocation (); + Rectangle rect = shell.getBounds (); + if (rect.contains (point)) { + Stdout("In\n"); + } else { + Stdout("Out\n"); + } + Stdout.flush(); + display.timerExec (time, timer); + }); + display.timerExec (time, timer); + shell.setSize (200, 200); + shell.open (); + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet235.d --- /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 + *******************************************************************************/ +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", + ]; diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet268.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet268.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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 + *******************************************************************************/ +module display.Snippet268; + +/* + * UI Automation (for testing tools) snippet: post mouse wheel events to a styled text + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + +import dwt.custom.StyledText; +import dwt.graphics.Point; +import dwt.layout.FillLayout; + +import tango.io.Stdout; +import tango.util.Convert; +import tango.core.Thread; + +void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + StyledText styledText = new StyledText(shell, DWT.V_SCROLL); + String multiLineString = ""; + for (int i = 0; i < 200; i++) { + multiLineString ~= "This is line number " ~ to!(String)(i) ~ + " in the multi-line string.\n"; + } + styledText.setText(multiLineString); + shell.setSize(styledText.computeSize(DWT.DEFAULT, 400)); + shell.open(); + styledText.addListener(DWT.MouseWheel, dgListener( (Event e){ + Stdout.formatln("Mouse Wheel event \n"); //" + e); + Stdout.flush(); + })); + final Point pt = display.map(shell, null, 50, 50); + Thread thread = new Thread({ + Event event; + for (int i = 0; i < 50; i++) { + event = new Event(); + event.type = DWT.MouseWheel; + event.detail = DWT.SCROLL_LINE; + event.x = pt.x; + event.y = pt.y; + event.count = -2; + display.post(event); + try { + Thread.sleep(400/1000); + } catch (InterruptedException e) {} + } + Stdout("Thread done\n").flush(); + }); + + thread.start(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); +} diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet276.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet276.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 + *******************************************************************************/ +module display.Snippet276; + +/* + * Display snippet: map from control-relative to display-relative coordinates + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.Point; + +import dwt.widgets.Control; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Label; +import dwt.widgets.Listener; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; +import tango.io.Stdout; + +void main (String[] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setBounds (200, 200, 400, 400); + Label label = new Label (shell, DWT.NONE); + label.setText ("click in shell to print display-relative coordinate"); + Listener listener = dgListener( (Event event) { + Point point = new Point (event.x, event.y); + Stdout(display.map (cast(Control)event.widget, null, point)).newline().flush(); + }); + shell.addListener (DWT.MouseDown, listener); + label.addListener (DWT.MouseDown, listener); + label.pack (); + shell.open (); + while (!shell.isDisposed ()){ + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet42.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet42.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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 + *******************************************************************************/ +module display.Snippet42; + +/* + * Display example snippet: get the bounds and client area of a display + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.widgets.Display; + +import dwt.dwthelper.utils; + +import tango.io.Stdout; +void main (String [] args) { + Display display = new Display (); + Stdout.formatln("Display Bounds= {} Display ClientArea= {}" + ,display.getBounds(),display.getClientArea()); + display.dispose (); +} diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet60.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet60.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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 + *******************************************************************************/ +module display.Snippet60; + +/* + * Display example snippet: create two one shot timers (5000 ms, 2000 ms) + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.widgets.Display; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; +import dwt.dwthelper.Runnable; + +import tango.io.Stdout; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setSize (200, 200); + shell.open (); + display.timerExec (5000, dgRunnable({ + Stdout("5000\n").flush(); + })); + display.timerExec (2000, dgRunnable({ + Stdout("2000\n").flush(); + })); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet68.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet68.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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 + *******************************************************************************/ +module display.Snippet68; + +/* + * Display example snippet: stop a repeating timer when a button is pressed + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.Color; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Label; +import dwt.widgets.Listener; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; +import dwt.dwthelper.Runnable; + +import dwt.layout.RowData; +import dwt.layout.RowLayout; + +void main (String [] args) { + Display display = new Display (); + final Color red = display.getSystemColor (DWT.COLOR_RED); + final Color blue = display.getSystemColor (DWT.COLOR_BLUE); + Shell shell = new Shell (display); + shell.setLayout (new RowLayout ()); + Button button = new Button (shell, DWT.PUSH); + button.setText ("Stop Timer"); + final Label label = new Label (shell, DWT.BORDER); + label.setBackground (red); + final int time = 500; + Runnable timer; + timer = dgRunnable({ + if (label.isDisposed ()) return; + Color color = label.getBackground ().opEquals (red) ? blue : red; + label.setBackground (color); + display.timerExec (time, timer); + }); + display.timerExec (time, timer); + button.addListener (DWT.Selection, dgListener( (Event event) { + display.timerExec (-1, timer); + })); + button.pack (); + label.setLayoutData (new RowData (button.getSize ())); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 5c1906bfc206 -r 104f5ed240fc snippets/display/Snippet7.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/display/Snippet7.d Tue Jul 29 01:50:10 2008 +0200 @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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 + *******************************************************************************/ +module display.Snippet7; + +/* + * example snippet: create a table (lazy) + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.layout.FillLayout; +import dwt.graphics.GC; +import dwt.graphics.Image; +import dwt.widgets.Display; +import dwt.widgets.Item; +import dwt.widgets.Shell; +import dwt.widgets.Table; +import dwt.widgets.TableItem; + +import dwt.dwthelper.Runnable; +import dwt.dwthelper.utils; + +import tango.core.Thread; +import tango.util.Convert; + +void main (String [] args) { + Display display = new Display (); + Image image = new Image (display, 16, 16); + GC gc = new GC (image); + gc.setBackground (display.getSystemColor (DWT.COLOR_RED)); + gc.fillRectangle (image.getBounds ()); + gc.dispose (); + + Shell shell = new Shell (display); + shell.setText ("Lazy Table"); + shell.setLayout (new FillLayout ()); + Table table = new Table (shell, DWT.BORDER | DWT.MULTI); + table.setSize (200, 200); + Thread thread = new Thread({ + for(int i=0; i< 20000; i++){ + if (table.isDisposed ()) return; + + int [] index = [i]; + display.syncExec (new class() Runnable{ + public void run () { + if (table.isDisposed ()) return; + TableItem item = new TableItem (table, DWT.NONE); + item.setText ("Table Item " ~ to!(String)(index [0])); + item.setImage (image); + } + }); + } + }); + + thread.start (); + shell.setSize (200, 200); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + image.dispose (); + display.dispose (); +} diff -r 5c1906bfc206 -r 104f5ed240fc snippets/dsss.conf --- a/snippets/dsss.conf Sat Jul 26 14:35:04 2008 +0200 +++ b/snippets/dsss.conf Tue Jul 29 01:50:10 2008 +0200 @@ -14,7 +14,6 @@ buildflags+= -L/rc:..\dwt } - [busyindicator/Snippet130.d] [busyindicator/Snippet130a.d] [button/Snippet108.d] @@ -67,6 +66,15 @@ [datetime/Snippet251.d] [directorydialog/Snippet33.d] [display/Snippet142.d] +[display/Snippet146.d] +[display/Snippet16.d] +[display/Snippet235.d] +[display/Snippet268.d] +[display/Snippet276.d] +[display/Snippet42.d] +[display/Snippet60.d] +[display/Snippet68.d] +[display/Snippet7.d] [expandbar/Snippet223.d] [filedialog/Snippet72.d] [gc/Snippet10.d]