Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet115.d @ 44:ed96ea2a2764
First swt win snippets are buiding with d2+phobos
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 25 Mar 2009 18:31:01 +0100 |
parents | 4e5843b771cc |
children | 536e43f63c81 |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * D Port: | |
11 * Thomas Demmer <t_demmer AT web DOT de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet115; | |
14 | |
15 /* | |
16 * Composite example snippet: force radio behavior on two different composites | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 import org.eclipse.swt.SWT; | |
22 import org.eclipse.swt.widgets.Button; | |
23 import org.eclipse.swt.widgets.Composite; | |
24 import org.eclipse.swt.widgets.Control; | |
25 import org.eclipse.swt.widgets.Display; | |
26 import org.eclipse.swt.widgets.Event; | |
27 import org.eclipse.swt.widgets.Listener; | |
28 import org.eclipse.swt.widgets.Shell; | |
29 import org.eclipse.swt.layout.RowLayout; | |
30 | |
31 import java.lang.all; | |
32 | |
33 void main (String [] args) { | |
34 Display display = new Display (); | |
35 Shell shell = new Shell (display); | |
36 shell.setLayout (new RowLayout (SWT.VERTICAL)); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
37 Composite c1 = new Composite (shell, SWT.BORDER | SWT.NO_RADIO_GROUP); |
28 | 38 c1.setLayout (new RowLayout ()); |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
39 Composite c2 = new Composite (shell, SWT.BORDER | SWT.NO_RADIO_GROUP); |
28 | 40 c2.setLayout (new RowLayout ()); |
41 Composite [] composites = [c1, c2]; | |
42 Listener radioGroup = new class() Listener{ | |
43 public void handleEvent (Event event) { | |
44 for (int i=0; i<composites.length; i++) { | |
45 Composite composite = composites [i]; | |
46 Control [] children = composite.getChildren (); | |
47 for (int j=0; j<children.length; j++) { | |
48 Control child = children [j]; | |
49 if (cast(Button)child !is null) { | |
50 Button button = cast(Button) child; | |
51 if ((button.getStyle () & SWT.RADIO) != 0) button.setSelection (false); | |
52 } | |
53 } | |
54 } | |
55 Button button = cast(Button) event.widget; | |
56 button.setSelection (true); | |
57 } | |
58 }; | |
59 for (int i=0; i<4; i++) { | |
60 Button button = new Button (c1, SWT.RADIO); | |
44
ed96ea2a2764
First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
61 button.setText (Format("Button {}",i)); |
28 | 62 button.addListener (SWT.Selection, radioGroup); |
63 } | |
64 for (int i=0; i<4; i++) { | |
65 Button button = new Button (c2, SWT.RADIO); | |
44
ed96ea2a2764
First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
66 button.setText (Format("Button {}",(i + 4))); |
28 | 67 button.addListener (SWT.Selection, radioGroup); |
68 } | |
69 shell.pack (); | |
70 shell.open (); | |
71 while (!shell.isDisposed()) { | |
72 if (!display.readAndDispatch ()) display.sleep (); | |
73 } | |
74 display.dispose (); | |
75 } |