28
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2004 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.Snippet115;
|
|
14
|
|
15 /*
|
|
16 * Composite example snippet: force radio behavior on two different composites
|
|
17 *
|
|
18 * For a list of all SWT example snippets see
|
|
19 * http://www.eclipse.org/swt/snippets/
|
|
20 */
|
|
21 import org.eclipse.swt.SWT;
|
|
22 import org.eclipse.swt.widgets.Button;
|
|
23 import org.eclipse.swt.widgets.Composite;
|
|
24 import org.eclipse.swt.widgets.Control;
|
|
25 import org.eclipse.swt.widgets.Display;
|
|
26 import org.eclipse.swt.widgets.Event;
|
|
27 import org.eclipse.swt.widgets.Listener;
|
|
28 import org.eclipse.swt.widgets.Shell;
|
|
29 import org.eclipse.swt.layout.RowLayout;
|
|
30
|
|
31 import java.lang.all;
|
|
32 import tango.util.Convert;
|
|
33
|
|
34 void main (String [] args) {
|
|
35 Display display = new Display ();
|
|
36 Shell shell = new Shell (display);
|
|
37 shell.setLayout (new RowLayout (SWT.VERTICAL));
|
|
38 Composite c1 = new Composite (shell, SWT.BORDER | DWT.NO_RADIO_GROUP);
|
|
39 c1.setLayout (new RowLayout ());
|
|
40 Composite c2 = new Composite (shell, SWT.BORDER | DWT.NO_RADIO_GROUP);
|
|
41 c2.setLayout (new RowLayout ());
|
|
42 Composite [] composites = [c1, c2];
|
|
43 Listener radioGroup = new class() Listener{
|
|
44 public void handleEvent (Event event) {
|
|
45 for (int i=0; i<composites.length; i++) {
|
|
46 Composite composite = composites [i];
|
|
47 Control [] children = composite.getChildren ();
|
|
48 for (int j=0; j<children.length; j++) {
|
|
49 Control child = children [j];
|
|
50 if (cast(Button)child !is null) {
|
|
51 Button button = cast(Button) child;
|
|
52 if ((button.getStyle () & SWT.RADIO) != 0) button.setSelection (false);
|
|
53 }
|
|
54 }
|
|
55 }
|
|
56 Button button = cast(Button) event.widget;
|
|
57 button.setSelection (true);
|
|
58 }
|
|
59 };
|
|
60 for (int i=0; i<4; i++) {
|
|
61 Button button = new Button (c1, SWT.RADIO);
|
|
62 button.setText ("Button " ~ to!(char[])(i));
|
|
63 button.addListener (SWT.Selection, radioGroup);
|
|
64 }
|
|
65 for (int i=0; i<4; i++) {
|
|
66 Button button = new Button (c2, SWT.RADIO);
|
|
67 button.setText ("Button " ~to!(char[])(i + 4));
|
|
68 button.addListener (SWT.Selection, radioGroup);
|
|
69 }
|
|
70 shell.pack ();
|
|
71 shell.open ();
|
|
72 while (!shell.isDisposed()) {
|
|
73 if (!display.readAndDispatch ()) display.sleep ();
|
|
74 }
|
|
75 display.dispose ();
|
|
76 }
|