comparison snippets/button/Snippet169.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, 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 button.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 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.Shell;
30 import dwt.widgets.Listener;
31 import dwt.layout.FillLayout;
32
33 import dwt.dwthelper.utils;
34 import tango.util.Convert;
35
36 void main(String[] args){
37 Snippet169.main(args);
38 }
39
40
41 public class Snippet169 {
42 public static void main (String [] args) {
43 Display display = new Display ();
44 final Shell shell = new Shell (display);
45 shell.setLayout (new FillLayout ());
46 Listener listener = new class() Listener {
47 public void handleEvent (Event e) {
48 Control [] children = shell.getChildren ();
49 for (int i=0; i<children.length; i++) {
50 Control child = children [i];
51 if (e.widget !is child && cast(Button)child !is null && (child.getStyle () & DWT.TOGGLE) != 0) {
52 (cast(Button) child).setSelection (false);
53 }
54 }
55 (cast(Button) e.widget).setSelection (true);
56 }
57 };
58 for (int i=0; i<20; i++) {
59 Button button = new Button (shell, DWT.TOGGLE);
60 button.setText ("B" ~to!(char[])(i));
61 button.addListener (DWT.Selection, listener);
62 if (i == 0) button.setSelection (true);
63 }
64 shell.pack ();
65 shell.open ();
66 while (!shell.isDisposed ()) {
67 if (!display.readAndDispatch ()) display.sleep ();
68 }
69 display.dispose ();
70 }
71 }