comparison snippets/button/Snippet224.d @ 114:0de3dab4d6e1

Add buttons snippets. Thanks TomD.
author Frank Benoit <benoit@tionex.de>
date Fri, 11 Jul 2008 21:10:38 +0200
parents
children 8cdaac0dc743
comparison
equal deleted inserted replaced
113:7194dba256b8 114:0de3dab4d6e1
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 button.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 dwt.DWT;
25 import dwt.widgets.Button;
26 import dwt.widgets.Control;
27 import dwt.widgets.Display;
28 import dwt.widgets.Event;
29 import dwt.widgets.Listener;
30 import dwt.widgets.Shell;
31 import dwt.layout.RowLayout;
32
33 import dwt.dwthelper.utils;
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 (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 ();
72 }
73 }