Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet247.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 4e5843b771cc |
children | 536e43f63c81 |
rev | line source |
---|---|
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 | |
112 | 35 version(Tango){ |
36 import tango.io.Stdout; | |
37 } else { // Phobos | |
38 import std.stdio; | |
39 } | |
28 | 40 |
41 void main (String [] args) { | |
42 Display display = new Display (); | |
43 Shell shell = new Shell (display); | |
44 shell.setLayout(new RowLayout()); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
45 Text text = new Text(shell, SWT.MULTI | SWT.BORDER); |
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
46 String modifier = SWT.MOD1 == SWT.CTRL ? "Ctrl" : "Command"; |
28 | 47 text.setText("Hit " ~ modifier ~ "+Return\nto see\nthe default button\nrun"); |
48 text.addTraverseListener(new class() TraverseListener{ | |
49 public void keyTraversed(TraverseEvent e) { | |
50 switch (e.detail) { | |
51 case SWT.TRAVERSE_RETURN: | |
52 if ((e.stateMask & SWT.MOD1) != 0) e.doit = true; | |
53 default: | |
54 } | |
55 } | |
56 }); | |
57 Button button = new Button (shell, SWT.PUSH); | |
58 button.pack(); | |
59 button.setText("OK"); | |
60 button.addSelectionListener(new class() SelectionAdapter{ | |
61 public void widgetSelected(SelectionEvent e) { | |
112 | 62 version(Tango){ |
63 Stdout("OK selected\n"); | |
64 Stdout.flush(); | |
65 } else { | |
66 writeln("OK selected"); | |
67 } | |
28 | 68 } |
69 }); | |
70 shell.setDefaultButton(button); | |
71 shell.pack (); | |
72 shell.open(); | |
73 while (!shell.isDisposed ()) { | |
74 if (!display.readAndDispatch ()) display.sleep (); | |
75 } | |
76 display.dispose (); | |
77 } |