28
|
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.Snippet247;
|
|
14
|
|
15 /*
|
|
16 * Control example snippet: allow a multi-line text to process the default button
|
|
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.events.SelectionAdapter;
|
|
23 import org.eclipse.swt.events.SelectionEvent;
|
|
24 import org.eclipse.swt.events.SelectionListener;
|
|
25 import org.eclipse.swt.events.TraverseEvent;
|
|
26 import org.eclipse.swt.events.TraverseListener;
|
|
27 import org.eclipse.swt.widgets.Button;
|
|
28 import org.eclipse.swt.widgets.Display;
|
|
29 import org.eclipse.swt.widgets.Shell;
|
|
30 import org.eclipse.swt.widgets.Text;
|
|
31 import org.eclipse.swt.layout.RowLayout;
|
|
32
|
|
33 import java.lang.all;
|
|
34
|
|
35 import tango.io.Stdout;
|
|
36
|
|
37 void main (String [] args) {
|
|
38 Display display = new Display ();
|
|
39 Shell shell = new Shell (display);
|
|
40 shell.setLayout(new RowLayout());
|
|
41 Text text = new Text(shell, SWT.MULTI | DWT.BORDER);
|
|
42 String modifier = SWT.MOD1 == DWT.CTRL ? "Ctrl" : "Command";
|
|
43 text.setText("Hit " ~ modifier ~ "+Return\nto see\nthe default button\nrun");
|
|
44 text.addTraverseListener(new class() TraverseListener{
|
|
45 public void keyTraversed(TraverseEvent e) {
|
|
46 switch (e.detail) {
|
|
47 case SWT.TRAVERSE_RETURN:
|
|
48 if ((e.stateMask & SWT.MOD1) != 0) e.doit = true;
|
|
49 default:
|
|
50 }
|
|
51 }
|
|
52 });
|
|
53 Button button = new Button (shell, SWT.PUSH);
|
|
54 button.pack();
|
|
55 button.setText("OK");
|
|
56 button.addSelectionListener(new class() SelectionAdapter{
|
|
57 public void widgetSelected(SelectionEvent e) {
|
|
58 Stdout("OK selected\n");
|
|
59 Stdout.flush();
|
|
60 }
|
|
61 });
|
|
62 shell.setDefaultButton(button);
|
|
63 shell.pack ();
|
|
64 shell.open();
|
|
65 while (!shell.isDisposed ()) {
|
|
66 if (!display.readAndDispatch ()) display.sleep ();
|
|
67 }
|
|
68 display.dispose ();
|
|
69 }
|