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