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.Snippet24;
|
|
14
|
|
15 /*
|
|
16 * example snippet: detect CR in a text or combo control (default selection)
|
|
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.Combo;
|
|
23 import org.eclipse.swt.widgets.Display;
|
|
24 import org.eclipse.swt.widgets.Event;
|
|
25 import org.eclipse.swt.widgets.Listener;
|
|
26 import org.eclipse.swt.widgets.Shell;
|
|
27 import org.eclipse.swt.widgets.Text;
|
|
28 import org.eclipse.swt.layout.RowLayout;
|
|
29
|
|
30 import java.lang.all;
|
|
31 import tango.io.Stdout;
|
|
32
|
|
33 void main (String [] args) {
|
|
34 Display display = new Display ();
|
|
35 Shell shell = new Shell (display);
|
|
36 shell.setLayout (new RowLayout ());
|
|
37 Combo combo = new Combo (shell, SWT.NONE);
|
|
38 combo.setItems (["A-1", "B-1", "C-1"]);
|
|
39 Text text = new Text (shell, SWT.SINGLE | DWT.BORDER);
|
|
40 text.setText ("some text");
|
|
41 combo.addListener (SWT.DefaultSelection, new class() Listener{
|
|
42 public void handleEvent (Event e) {
|
|
43 Stdout(e.widget.toString() ~ " - Default Selection\n");
|
|
44 }
|
|
45 });
|
|
46 text.addListener (SWT.DefaultSelection, new class() Listener{
|
|
47 public void handleEvent (Event e) {
|
|
48 Stdout(e.widget.toString() ~ " - Default Selection\n");
|
|
49 }
|
|
50 });
|
|
51 shell.pack ();
|
|
52 shell.open ();
|
|
53 while (!shell.isDisposed()) {
|
|
54 if (!display.readAndDispatch ()) display.sleep ();
|
|
55 }
|
|
56 display.dispose ();
|
|
57 }
|