28
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2005 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.Snippet169;
|
|
14
|
|
15 /*
|
|
16 * Make a toggle button have radio behavior
|
|
17 *
|
|
18 * For a list of all SWT example snippets see
|
|
19 * http://www.eclipse.org/swt/snippets/
|
|
20 *
|
|
21 * Port OK.
|
|
22 */
|
|
23
|
|
24 import org.eclipse.swt.SWT;
|
|
25 import org.eclipse.swt.widgets.Button;
|
|
26 import org.eclipse.swt.widgets.Control;
|
|
27 import org.eclipse.swt.widgets.Display;
|
|
28 import org.eclipse.swt.widgets.Event;
|
|
29 import org.eclipse.swt.widgets.Shell;
|
|
30 import org.eclipse.swt.widgets.Listener;
|
|
31 import org.eclipse.swt.layout.FillLayout;
|
|
32
|
|
33 import java.lang.all;
|
112
|
34 version(Tango){
|
|
35 import tango.util.Convert;
|
|
36 } else { // Phobos
|
|
37 import std.conv;
|
|
38 }
|
28
|
39
|
|
40 void main(String[] args){
|
|
41 Snippet169.main(args);
|
|
42 }
|
|
43
|
|
44
|
|
45 public class Snippet169 {
|
|
46 public static void main (String [] args) {
|
|
47 Display display = new Display ();
|
112
|
48 Shell shell = new Shell (display);
|
28
|
49 shell.setLayout (new FillLayout ());
|
|
50 Listener listener = new class() Listener {
|
|
51 public void handleEvent (Event e) {
|
|
52 Control [] children = shell.getChildren ();
|
|
53 for (int i=0; i<children.length; i++) {
|
|
54 Control child = children [i];
|
|
55 if (e.widget !is child && cast(Button)child !is null && (child.getStyle () & SWT.TOGGLE) != 0) {
|
|
56 (cast(Button) child).setSelection (false);
|
|
57 }
|
|
58 }
|
|
59 (cast(Button) e.widget).setSelection (true);
|
|
60 }
|
|
61 };
|
|
62 for (int i=0; i<20; i++) {
|
|
63 Button button = new Button (shell, SWT.TOGGLE);
|
112
|
64 button.setText ("B" ~to!(String)(i));
|
28
|
65 button.addListener (SWT.Selection, listener);
|
|
66 if (i == 0) button.setSelection (true);
|
|
67 }
|
|
68 shell.pack ();
|
|
69 shell.open ();
|
|
70 while (!shell.isDisposed ()) {
|
|
71 if (!display.readAndDispatch ()) display.sleep ();
|
|
72 }
|
|
73 display.dispose ();
|
|
74 }
|
|
75 }
|