comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet224.d @ 28:69b1fa94a4a8

Added SWT snippets
author Frank Benoit <benoit@tionex.de>
date Sun, 22 Mar 2009 15:17:04 +0100
parents
children 9f4c18c268b2
comparison
equal deleted inserted replaced
27:1bf55a6eb092 28:69b1fa94a4a8
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;
34 import tango.util.Convert;
35
36 void main(String[] args){
37 Snippet224.main(args);
38 }
39
40
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 (SWT.VERTICAL));
46 for (int i=0; i<8; i++) {
47 Button button = new Button (shell, SWT.RADIO);
48 button.setText ("B" ~ to!(char[])(i));
49 if (i == 0) button.setSelection (true);
50 }
51 Button button = new Button (shell, SWT.PUSH);
52 button.setText ("Set Selection to B4");
53 button.addListener (SWT.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 () & SWT.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 }