# HG changeset patch # User Jesse Phillips # Date 1204485094 28800 # Node ID 580d6cc14afd772a5ebb94d5ffef2710e7ac856e # Parent ff27e8ad465c2ca0347dee87225b2e55de333015 Added tree and table snippets. Cleaned up .hgignore. diff -r ff27e8ad465c -r 580d6cc14afd .hgignore --- a/.hgignore Sun Mar 02 18:57:50 2008 +0100 +++ b/.hgignore Sun Mar 02 11:11:34 2008 -0800 @@ -4,6 +4,7 @@ *.swp *.map *.exe +*.bak syntax: regexp ^build.sh$ @@ -11,24 +12,12 @@ ^dsss.last ^dsss_imports ^dwtexamples/simple$ -^dwtexamples/helloworld/HelloWorld1$ -^dwtexamples/helloworld/HelloWorld2$ -^dwtexamples/helloworld/HelloWorld3$ -^dwtexamples/helloworld/HelloWorld4$ -^dwtexamples/helloworld/HelloWorld5$ +^dwtexamples/helloworld/HelloWorld[0-9]$ ^dwtexamples/addressbook/AddressBook$ ^dwtexamples/controlexample/ControlExample$ ^dwtexamples/controlexample/CustomControlExample$ -^dwtsnippets/styledtext/Snippet163$ -^dwtsnippets/styledtext/Snippet189$ -^dwtsnippets/text/Snippet258$ -^dwtsnippets/tooltips/Snippet41$ -^dwtsnippets/tray/Snippet143$ -^dwtsnippets/combo/Snippet26$ -^dwtsnippets/composite/Snippet9$ +^dwtsnippets/.*/Snippet[0-9]*$ -^user/nascent_test1$ -^user/nascent_test2$ ^user/torhu_synctest$ ^user/doob_test1/draw$ ^user/drawingboard/DrawingBoard$ diff -r ff27e8ad465c -r 580d6cc14afd dsss.conf --- a/dsss.conf Sun Mar 02 18:57:50 2008 +0100 +++ b/dsss.conf Sun Mar 02 11:11:34 2008 -0800 @@ -35,9 +35,13 @@ [dwtsnippets/expandbar/Snippet223.d] [dwtsnippets/styledtext/Snippet163.d] [dwtsnippets/styledtext/Snippet189.d] +[dwtsnippets/table/Snippet38.d] +[dwtsnippets/table/Snippet144.d] [dwtsnippets/text/Snippet258.d] [dwtsnippets/tooltips/Snippet41.d] [dwtsnippets/tray/Snippet143.d] +[dwtsnippets/tree/Snippet8.d] +[dwtsnippets/tree/Snippet15.d] [user/drawingboard/DrawingBoard.d] [user/torhu_synctest.d] diff -r ff27e8ad465c -r 580d6cc14afd dwtsnippets/table/Snippet144.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtsnippets/table/Snippet144.d Sun Mar 02 11:11:34 2008 -0800 @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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: + * Jesse Phillips gmail.com + *******************************************************************************/ +module dwtsnippets.table.Snippet144; + +/* + * Virtual Table example snippet: create a table with 1,000,000 items (lazy) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +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.widgets.Table; +import dwt.widgets.TableItem; +import dwt.layout.RowLayout; +import dwt.layout.RowData; + +import tango.io.Stdout; +import tango.time.StopWatch; +import tango.util.Convert; + +const int COUNT = 1000000; + +void main() { + auto display = new Display (); + auto shell = new Shell (display); + shell.setLayout (new RowLayout (DWT.VERTICAL)); + auto table = new Table (shell, DWT.VIRTUAL | DWT.BORDER); + table.addListener (DWT.SetData, new class Listener { + public void handleEvent (Event event) { + auto item = cast(TableItem) event.item; + auto index = table.indexOf (item); + item.setText ("Item " ~ to!(char[])(index)); + Stdout(item.getText ()).newline; + } + }); + table.setLayoutData (new RowData (200, 200)); + auto button = new Button (shell, DWT.PUSH); + button.setText ("Add Items"); + auto label = new Label(shell, DWT.NONE); + button.addListener (DWT.Selection, new class Listener { + public void handleEvent (Event event) { + StopWatch elapsed; + elapsed.start; + table.setItemCount (COUNT); + auto t = elapsed.stop; + label.setText ("Items: " ~ to!(char[])(COUNT) ~ + ", Time: " ~ to!(char[])(t) ~ " (ms)"); + shell.layout (); + } + }); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r ff27e8ad465c -r 580d6cc14afd dwtsnippets/table/Snippet38.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtsnippets/table/Snippet38.d Sun Mar 02 11:11:34 2008 -0800 @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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: + * Jesse Phillips gmail.com + *******************************************************************************/ +module dwtsnippets.table.Snippet38; + +/* + * Table example snippet: create a table (columns, headers, lines) + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Table; +import dwt.widgets.TableColumn; +import dwt.widgets.TableItem; + +import tango.util.Convert; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + auto table = new Table (shell, DWT.MULTI | DWT.BORDER | DWT.FULL_SELECTION); + table.setLinesVisible (true); + table.setHeaderVisible (true); + char[][] titles = [" ", "C", "!", "Description", "Resource", "In Folder", "Location"]; + foreach (title; titles) { + auto column = new TableColumn (table, DWT.NONE); + column.setText (title); + } + int count = 128; + for (int i=0; i gmail.com + *******************************************************************************/ +module dwtsnippets.tree.Snippet15; + +/* + * Tree example snippet: create a tree + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; + +import tango.util.Convert; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + shell.setLayout(new FillLayout()); + auto tree = new Tree (shell, DWT.BORDER); + for (int i=0; i<4; i++) { + auto iItem = new TreeItem (tree, 0); + iItem.setText ("TreeItem (0) -" ~ to!(char[])(i)); + for (int j=0; j<4; j++) { + TreeItem jItem = new TreeItem (iItem, 0); + jItem.setText ("TreeItem (1) -" ~ to!(char[])(j)); + for (int k=0; k<4; k++) { + TreeItem kItem = new TreeItem (jItem, 0); + kItem.setText ("TreeItem (2) -" ~ to!(char[])(k)); + for (int l=0; l<4; l++) { + TreeItem lItem = new TreeItem (kItem, 0); + lItem.setText ("TreeItem (3) -" ~ to!(char[])(l)); + } + } + } + } + shell.setSize (200, 200); + shell.open (); + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r ff27e8ad465c -r 580d6cc14afd dwtsnippets/tree/Snippet8.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtsnippets/tree/Snippet8.d Sun Mar 02 11:11:34 2008 -0800 @@ -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: + * Jesse Phillips gmail.com + *******************************************************************************/ +module dwtsnippets.tree.Snippet8; + +/* + * Tree example snippet: create a tree (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.Point; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; + +import tango.math.Math; +import tango.io.FilePath; +import tango.io.FileRoots; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + shell.setText ("Lazy Tree"); + shell.setLayout (new FillLayout ()); + auto tree = new Tree (shell, DWT.BORDER); + auto roots = FileRoots.list(); + foreach (file; roots) { + auto root = new TreeItem (tree, 0); + root.setText (file); + root.setData (new FilePath(file)); + new TreeItem (root, 0); + } + tree.addListener (DWT.Expand, new class Listener { + public void handleEvent (Event event) { + auto root = cast(TreeItem) event.item; + auto items = root.getItems (); + foreach(item; items) { + if (item.getData () !is null) return; + item.dispose (); + } + auto file = cast(FilePath) root.getData (); + auto files = file.toList(); + if (files is null) return; + foreach (f; files) { + TreeItem item = new TreeItem (root, 0); + item.setText (f.toString()); + item.setData (f); + if (f.isFolder()) { + new TreeItem (item, 0); + } + } + } + }); + auto size = tree.computeSize (300, DWT.DEFAULT); + auto width = Math.max (300, size.x); + auto height = Math.max (300, size.y); + shell.setSize (shell.computeSize (width, height)); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +}