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.Snippet147;
|
|
14 /*
|
|
15 * Combo example snippet: stop CR from going to the default button
|
|
16 *
|
|
17 * For a list of all SWT example snippets see
|
|
18 * http://www.eclipse.org/swt/snippets/
|
|
19 */
|
|
20 import org.eclipse.swt.SWT;
|
|
21 import org.eclipse.swt.events.SelectionAdapter;
|
|
22 import org.eclipse.swt.events.SelectionEvent;
|
|
23 import org.eclipse.swt.events.TraverseListener;
|
|
24 import org.eclipse.swt.layout.GridData;
|
|
25 import org.eclipse.swt.layout.GridLayout;
|
|
26 import org.eclipse.swt.widgets.Button;
|
|
27 import org.eclipse.swt.widgets.Combo;
|
|
28 import org.eclipse.swt.widgets.Display;
|
|
29 import org.eclipse.swt.widgets.Shell;
|
|
30 import java.lang.all;
|
|
31
|
|
32 import tango.io.Stdout;
|
|
33
|
|
34 void main(String[] args) {
|
|
35 Display display = new Display();
|
|
36 Shell shell = new Shell(display);
|
|
37 shell.setLayout(new GridLayout());
|
|
38 Combo combo = new Combo(shell, SWT.NONE);
|
|
39 combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
40 combo.setText("Here is some text");
|
|
41 combo.addSelectionListener(new class() SelectionAdapter{
|
|
42 public void widgetDefaultSelected(SelectionEvent e) {
|
|
43 Stdout("Combo default selected (overrides default button)\n");
|
|
44 }
|
|
45 });
|
|
46 combo.addTraverseListener(new class() TraverseListener{
|
|
47 public void keyTraversed(TraverseEvent e) {
|
|
48 if (e.detail == SWT.TRAVERSE_RETURN) {
|
|
49 e.doit = false;
|
|
50 e.detail = SWT.TRAVERSE_NONE;
|
|
51 }
|
|
52 }
|
|
53 });
|
|
54 Button button = new Button(shell, SWT.PUSH);
|
|
55 button.setText("Ok");
|
|
56 button.addSelectionListener(new class() SelectionAdapter{
|
|
57 public void widgetSelected(SelectionEvent e) {
|
|
58 Stdout("Button selected\n");
|
|
59 }
|
|
60 });
|
|
61 shell.setDefaultButton(button);
|
|
62 shell.pack();
|
|
63 shell.open();
|
|
64 while (!shell.isDisposed()) {
|
|
65 if (!display.readAndDispatch())
|
|
66 display.sleep();
|
|
67 }
|
|
68 display.dispose();
|
|
69 }
|
|
70
|