Changeset 117:8cdaac0dc743
- Timestamp:
- 07/12/08 14:09:06 (5 months ago)
- Files:
-
- snippets/busyindicator/Snippet130.d (modified) (6 diffs)
- snippets/busyindicator/Snippet130a.d (added)
- snippets/button/Snippet108.d (modified) (1 diff)
- snippets/button/Snippet162.d (added)
- snippets/button/Snippet169.d (modified) (1 diff)
- snippets/button/Snippet206.d (modified) (2 diffs)
- snippets/button/Snippet224.d (modified) (1 diff)
- snippets/button/Snippet293.d (modified) (2 diffs)
- snippets/button/Snippet294.d (modified) (2 diffs)
- snippets/caret/Snippet43.d (added)
- snippets/caret/Snippet74.d (added)
- snippets/ccombo/Snippet39.d (added)
- snippets/clipboard/Snippet122.d (added)
- snippets/clipboard/Snippet282.d (added)
- snippets/clipboard/Snippet94.d (added)
- snippets/color/Snippet208.d (added)
- snippets/dsss.conf (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
snippets/busyindicator/Snippet130.d
r113 r117 8 8 * Contributors: 9 9 * IBM Corporation - initial API and implementation 10 * D Port: 11 * Thomas Demmer <t_demmer AT web DOT de> 10 12 *******************************************************************************/ 11 13 module busyindicator.Snippet130; 12 14 /* 13 15 * BusyIndicator example snippet: display busy cursor during long running task … … 16 18 * http://www.eclipse.org/swt/snippets/ 17 19 */ 18 module busyindicator.Snippet130;19 20 20 import dwt.DWT; 21 21 import dwt.events.SelectionAdapter; … … 37 37 38 38 import tango.core.Thread; 39 import tango.io.Stdout; 39 40 import tango.util.Convert; 40 41 import tango.util.log.Trace; 42 41 43 42 44 void main(String[] args){ … … 52 54 Text text = new Text(shell, DWT.MULTI | DWT.BORDER | DWT.V_SCROLL); 53 55 text.setLayoutData(new GridData(GridData.FILL_BOTH)); 54 int[ 1] nextId;56 int[] nextId = new int[1]; 55 57 Button b = new Button(shell, DWT.PUSH); 56 58 b.setText("invoke long running job"); … … 61 63 bool done = false; 62 64 int id; 63 private void runThread(){ 64 id = nextId[0]++; 65 display.syncExec( dgRunnable( &printStart, text, id )); 66 for (int i = 0; i < 6; i++) { 65 public void run() { 66 Thread thread = new Thread({ 67 id = nextId[0]++; 68 display.syncExec(new class() Runnable { 69 public void run() { 70 if (text.isDisposed()) return; 71 text.append("\nStart long running task "~to!(char[])(id)); 72 } 73 }); // display.syncExec 74 /* 75 * This crashes when more than 1 thread gets created. THD 76 for (int i = 0; i < 100000; i++) { 77 if (display.isDisposed()) return; 78 Stdout.formatln("do task that takes a long time in a separate thread {}", id); 79 } 80 */ 81 // This runs fine 82 for (int i = 0; i < 6; i++) { 83 if (display.isDisposed()) return; 84 Trace.formatln("do task that takes a long time in a separate thread {} {}/6", id, i); 85 Thread.sleep(0.500); 86 } 87 67 88 if (display.isDisposed()) return; 68 Trace.formatln("do task that takes a long time in a separate thread {} {}/6", id, i); 69 Thread.sleep(0.500); 70 } 71 if (display.isDisposed()) return; 72 display.syncExec( dgRunnable( &printEnd , text, id )); // display.syncExec 73 done = true; 74 display.wake(); 75 } 76 public void run() { 77 Thread thread = new Thread( &runThread ); 89 display.syncExec(new class() Runnable { 90 public void run() { 91 if (text.isDisposed()) return; 92 text.append("\nCompleted long running task "~to!(char[])(id)); 93 } 94 }); // display.syncExec 95 done = true; 96 display.wake(); 97 }); // thread = ... 78 98 thread.start(); 79 99 … … 108 128 } 109 129 } 110 111 snippets/button/Snippet108.d
r114 r117 33 33 34 34 void main(String[] args){ 35 Snippet108.main(args);35 Snippet108.main(args); 36 36 } 37 37 38 38 public class Snippet108 { 39 39 40 public static void main (String [] args) { 41 Display display = new Display (); 42 Shell shell = new Shell (display); 43 Label label = new Label (shell, DWT.NONE); 44 label.setText ("Enter your name:"); 45 Text text = new Text (shell, DWT.BORDER); 46 text.setLayoutData (new RowData (100, DWT.DEFAULT)); 47 Button ok = new Button (shell, DWT.PUSH); 48 ok.setText ("OK"); 49 ok.addSelectionListener(new class() SelectionAdapter { 50 public void widgetSelected(SelectionEvent e) { 51 Stdout.formatln("OK"); 52 } 53 }); 54 Button cancel = new Button (shell, DWT.PUSH); 55 cancel.setText ("Cancel"); 56 cancel.addSelectionListener(new class() SelectionAdapter { 57 public void widgetSelected(SelectionEvent e) { 58 Stdout.formatln("Cancel"); 59 } 60 }); 61 shell.setDefaultButton (cancel); 62 shell.setLayout (new RowLayout ()); 63 shell.pack (); 64 shell.open (); 65 while (!shell.isDisposed ()) { 66 if (!display.readAndDispatch ()) display.sleep (); 40 public static void main (String [] args) { 41 Display display = new Display (); 42 Shell shell = new Shell (display); 43 Label label = new Label (shell, DWT.NONE); 44 label.setText ("Enter your name:"); 45 Text text = new Text (shell, DWT.BORDER); 46 text.setLayoutData (new RowData (100, DWT.DEFAULT)); 47 Button ok = new Button (shell, DWT.PUSH); 48 ok.setText ("OK"); 49 ok.addSelectionListener(new class() SelectionAdapter { 50 public void widgetSelected(SelectionEvent e) { 51 Stdout.formatln("OK"); 52 } 53 }); 54 Button cancel = new Button (shell, DWT.PUSH); 55 cancel.setText ("Cancel"); 56 cancel.addSelectionListener(new class() SelectionAdapter { 57 public void widgetSelected(SelectionEvent e) { 58 Stdout.formatln("Cancel"); 59 } 60 }); 61 shell.setDefaultButton (cancel); 62 shell.setLayout (new RowLayout ()); 63 shell.pack (); 64 shell.open (); 65 while (!shell.isDisposed ()) { 66 if (!display.readAndDispatch ()) display.sleep (); 67 } 68 display.dispose (); 67 69 } 68 display.dispose ();69 }70 70 } 71 snippets/button/Snippet169.d
r114 r117 35 35 36 36 void main(String[] args){ 37 Snippet169.main(args);37 Snippet169.main(args); 38 38 } 39 39 40 40 41 41 public class Snippet169 { 42 public static void main (String [] args) { 43 Display display = new Display (); 44 final Shell shell = new Shell (display); 45 shell.setLayout (new FillLayout ()); 46 Listener listener = new class() Listener { 47 public void handleEvent (Event e) { 48 Control [] children = shell.getChildren (); 49 for (int i=0; i<children.length; i++) { 50 Control child = children [i]; 51 if (e.widget !is child && cast(Button)child !is null && (child.getStyle () & DWT.TOGGLE) != 0) { 52 (cast(Button) child).setSelection (false); 53 } 54 } 55 (cast(Button) e.widget).setSelection (true); 56 } 57 }; 58 for (int i=0; i<20; i++) { 59 Button button = new Button (shell, DWT.TOGGLE); 60 button.setText ("B" ~to!(char[])(i)); 61 button.addListener (DWT.Selection, listener); 62 if (i == 0) button.setSelection (true); 42 public static void main (String [] args) { 43 Display display = new Display (); 44 final Shell shell = new Shell (display); 45 shell.setLayout (new FillLayout ()); 46 Listener listener = new class() Listener { 47 public void handleEvent (Event e) { 48 Control [] children = shell.getChildren (); 49 for (int i=0; i<children.length; i++) { 50 Control child = children [i]; 51 if (e.widget !is child && cast(Button)child !is null && (child.getStyle () & DWT.TOGGLE) != 0) { 52 (cast(Button) child).setSelection (false); 53 } 54 } 55 (cast(Button) e.widget).setSelection (true); 56 } 57 }; 58 for (int i=0; i<20; i++) { 59 Button button = new Button (shell, DWT.TOGGLE); 60 button.setText ("B" ~to!(char[])(i)); 61 button.addListener (DWT.Selection, listener); 62 if (i == 0) button.setSelection (true); 63 } 64 shell.pack (); 65 shell.open (); 66 while (!shell.isDisposed ()) { 67 if (!display.readAndDispatch ()) display.sleep (); 68 } 69 display.dispose (); 63 70 } 64 shell.pack ();65 shell.open ();66 while (!shell.isDisposed ()) {67 if (!display.readAndDispatch ()) display.sleep ();68 }69 display.dispose ();70 }71 71 } snippets/button/Snippet206.d
r114 r117 21 21 * @since 3.2 22 22 */ 23 /* Port OK */24 23 25 24 import dwt.DWT; … … 33 32 34 33 void main(String[] args){ 35 Snippet206.main(args);34 Snippet206.main(args); 36 35 } 37 36 38 37 public class Snippet206 { 39 public static void main(String[] args) { 40 Display display = new Display(); 41 Image image = display.getSystemImage(DWT.ICON_QUESTION); 42 Shell shell = new Shell(display); 43 shell.setLayout (new GridLayout()); 44 Button button = new Button(shell, DWT.PUSH); 45 button.setImage(image); 46 button.setText("Button"); 47 shell.setSize(300, 300); 48 shell.open(); 49 while (!shell.isDisposed ()) { 50 if (!display.readAndDispatch ()) display.sleep (); 38 public static void main(String[] args) { 39 Display display = new Display(); 40 Image image = display.getSystemImage(DWT.ICON_QUESTION); 41 Shell shell = new Shell(display); 42 shell.setLayout (new GridLayout()); 43 Button button = new Button(shell, DWT.PUSH); 44 button.setImage(image); 45 button.setText("Button"); 46 shell.setSize(300, 300); 47 shell.open(); 48 while (!shell.isDisposed ()) { 49 if (!display.readAndDispatch ()) display.sleep (); 50 } 51 display.dispose (); 51 52 } 52 display.dispose ();53 }54 53 } snippets/button/Snippet224.d
r114 r117 35 35 36 36 void main(String[] args){ 37 Snippet224.main(args);37 Snippet224.main(args); 38 38 } 39 39 40 40 41 41 public class Snippet224 { 42 public static void main (String [] args) { 43 Display display = new Display (); 44 Shell shell = new Shell (display); 45 shell.setLayout (new RowLayout (DWT.VERTICAL)); 46 for (int i=0; i<8; i++) { 47 Button button = new Button (shell, DWT.RADIO); 48 button.setText ("B" ~ to!(char[])(i)); 49 if (i == 0) button.setSelection (true); 42 public static void main (String [] args) { 43 Display display = new Display (); 44 Shell shell = new Shell (display); 45 shell.setLayout (new RowLayout (DWT.VERTICAL)); 46 for (int i=0; i<8; i++) { 47 Button button = new Button (shell, DWT.RADIO); 48 button.setText ("B" ~ to!(char[])(i)); 49 if (i == 0) button.setSelection (true); 50 } 51 Button button = new Button (shell, DWT.PUSH); 52 button.setText ("Set Selection to B4"); 53 button.addListener (DWT.Selection, new class() Listener{ 54 public void handleEvent (Event event) { 55 Control [] children = shell.getChildren (); 56 Button newButton = cast(Button) children [4]; 57 for (int i=0; i<children.length; i++) { 58 Control child = children [i]; 59 if ( cast(Button)child !is null && (child.getStyle () & DWT.RADIO) != 0) { 60 (cast(Button)child).setSelection (false); 61 } 62 } 63 newButton.setSelection (true); 64 } 65 }); 66 shell.pack (); 67 shell.open (); 68 while (!shell.isDisposed ()) { 69 if (!display.readAndDispatch ()) display.sleep (); 70 } 71 display.dispose (); 50 72 } 51 Button button = new Button (shell, DWT.PUSH);52 button.setText ("Set Selection to B4");53 button.addListener (DWT.Selection, new class() Listener{54 public void handleEvent (Event event) {55 Control [] children = shell.getChildren ();56 Button newButton = cast(Button) children [4];57 for (int i=0; i<children.length; i++) {58 Control child = children [i];59 if ( cast(Button)child !is null && (child.getStyle () & DWT.RADIO) != 0) {60 (cast(Button)child).setSelection (false);61 }62 }63 newButton.setSelection (true);64 }65 });66 shell.pack ();67 shell.open ();68 while (!shell.isDisposed ()) {69 if (!display.readAndDispatch ()) display.sleep ();70 }71 display.dispose ();72 }73 73 } snippets/button/Snippet293.d
r78 r117 11 11 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com 12 12 *******************************************************************************/ 13 module snippets.button.Snippet293;13 module button.Snippet293; 14 14 15 15 /* … … 26 26 27 27 void main() { 28 auto display = new Display(); 29 auto shell = new Shell(display); 30 shell.setLayout(new GridLayout()); 31 32 auto b1 = new Button (shell, DWT.CHECK); 33 b1.setText("State 1"); 34 b1.setSelection(true); 35 36 auto b2 = new Button (shell, DWT.CHECK); 37 b2.setText("State 2"); 38 b2.setSelection(false); 39 40 auto b3 = new Button (shell, DWT.CHECK); 41 b3.setText("State 3"); 42 b3.setSelection(true); 28 auto display = new Display(); 29 auto shell = new Shell(display); 30 shell.setLayout(new GridLayout()); 43 31 44 // This function does not appear in the api for swt 3.3 45 // b3.setGrayed(true); 46 47 shell.pack(); 48 shell.open(); 49 while (!shell.isDisposed()) { 50 if (!display.readAndDispatch()) 51 display.sleep(); 52 } 53 display.dispose(); 32 auto b1 = new Button (shell, DWT.CHECK); 33 b1.setText("State 1"); 34 b1.setSelection(true); 35 36 auto b2 = new Button (shell, DWT.CHECK); 37 b2.setText("State 2"); 38 b2.setSelection(false); 39 40 auto b3 = new Button (shell, DWT.CHECK); 41 b3.setText("State 3"); 42 b3.setSelection(true); 43 44 // This function does not appear in the api for swt 3.3 45 // b3.setGrayed(true); 46 47 shell.pack(); 48 shell.open(); 49 while (!shell.isDisposed()) { 50 if (!display.readAndDispatch()) 51 display.sleep(); 52 } 53 display.dispose(); 54 54 } snippets/button/Snippet294.d
r114 r117 28 28 29 29 void main(String[] args){ 30 Snippet294.main(args);30 Snippet294.main(args); 31 31 } 32 32 … … 42 42 public class Snippet294 { 43 43 44 static int[] circle(int r, int offsetX, int offsetY) { 45 int[] polygon = new int[8 * r + 4]; 46 // x^2 + y^2 = r^2 47 for (int i = 0; i < 2 * r + 1; i++) { 48 int x = i - r; 49 int y = cast(int)Math.sqrt(cast(real)(r*r - x*x)); 50 polygon[2*i] = offsetX + x; 51 polygon[2*i+1] = offsetY + y; 52 polygon[8*r - 2*i - 2] = offsetX + x; 53 polygon[8*r - 2*i - 1] = offsetY - y; 44 static int[] circle(int r, int offsetX, int offsetY) { 45 int[] polygon = new int[8 * r + 4]; 46 // x^2 + y^2 = r^2 47 for (int i = 0; i < 2 * r + 1; i++) { 48 int x = i - r; 49 int y = cast(int)Math.sqrt(cast(real)(r*r - x*x)); 50 polygon[2*i] = offsetX + x; 51 polygon[2*i+1] = offsetY + y; 52 polygon[8*r - 2*i - 2] = offsetX + x; 53 polygon[8*r - 2*i - 1] = offsetY - y; 54 } 55 return polygon; 54 56 } 55 return polygon;56 }57 57 58 public static void main(String[] args) {59 Display display = new Display();60 Shell shell = new Shell(display);61 shell.setText("Regions on a Control");62 shell.setLayout(new FillLayout());63 shell.setBackground(display.getSystemColor(DWT.COLOR_DARK_RED));58 public static void main(String[] args) { 59 Display display = new Display(); 60 Shell shell = new Shell(display); 61 shell.setText("Regions on a Control"); 62 shell.setLayout(new FillLayout()); 63 shell.setBackground(display.getSystemColor(DWT.COLOR_DARK_RED)); 64 64 65 Button b2 = new Button(shell, DWT.PUSH);66 b2.setText("Button with Regions");65 Button b2 = new Button(shell, DWT.PUSH); 66 b2.setText("Button with Regions"); 67 67 68 // define a region that looks like a circle with two holes in ot69 Region region = new Region();70 region.add(circle(67, 87, 77));71 region.subtract(circle(20, 87, 47));72 region.subtract(circle(20, 87, 113));68 // define a region that looks like a circle with two holes in ot 69 Region region = new Region(); 70 region.add(circle(67, 87, 77)); 71 region.subtract(circle(20, 87, 47)); 72 region.subtract(circle(20, 87, 113)); 73 73 74 // define the shape of the button using setRegion75 b2.setRegion(region);76 b2.setLocation(100,50);74 // define the shape of the button using setRegion 75 b2.setRegion(region); 76 b2.setLocation(100,50); 77 77 78 b2.addListener(DWT.Selection, new class() Listener {79 public void handleEvent(Event e) {80 shell.close();81 }82 });78 b2.addListener(DWT.Selection, new class() Listener { 79 public void handleEvent(Event e) { 80 shell.close(); 81 } 82 }); 83 83 84 shell.setSize(200,200);85 shell.open();84 shell.setSize(200,200); 85 shell.open(); 86 86 87 while (!shell.isDisposed()) { 88 if (!display.readAndDispatch()) 89 display.sleep(); 87 while (!shell.isDisposed()) { 88 if (!display.readAndDispatch()) 89 display.sleep(); 90 } 91 region.dispose(); 92 display.dispose(); 90 93 } 91 region.dispose();92 display.dispose();93 }94 94 } snippets/dsss.conf
r114 r117 18 18 19 19 [busyindicator/Snippet130.d] 20 [busyindicator/Snippet130a.d] 20 21 [button/Snippet108.d] 22 [button/Snippet162.d] 21 23 [button/Snippet169.d] 22 24 [button/Snippet206.d] … … 29 31 [canvas/Snippet275.d] 30 32 [canvas/Snippet290.d] 33 [caret/Snippet43.d] 34 [caret/Snippet74.d] 35 [ccombo/Snippet39.d] 36 [clipboard/Snippet94.d] 37 [clipboard/Snippet122.d] 38 [clipboard/Snippet282.d] 39 [color/Snippet208.d] 31 40 [control/Snippet25.d] 32 41 [control/Snippet62.d]
