Mercurial > projects > dwt2
comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet258.d @ 28:69b1fa94a4a8
Added SWT snippets
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 22 Mar 2009 15:17:04 +0100 |
parents | |
children | 4e5843b771cc |
comparison
equal
deleted
inserted
replaced
27:1bf55a6eb092 | 28:69b1fa94a4a8 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2007 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 * Port to the D programming language: | |
11 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com | |
12 *******************************************************************************/ | |
13 | |
14 module org.eclipse.swt.snippets.Snippet258; | |
15 | |
16 /* | |
17 * Create a search text control | |
18 * | |
19 * For a list of all SWT example snippets see | |
20 * http://www.eclipse.org/swt/snippets/ | |
21 * | |
22 * @since 3.3 | |
23 */ | |
24 import org.eclipse.swt.SWT; | |
25 import java.io.ByteArrayInputStream; | |
26 import org.eclipse.swt.events.SelectionAdapter; | |
27 import org.eclipse.swt.events.SelectionEvent; | |
28 import org.eclipse.swt.graphics.Image; | |
29 import org.eclipse.swt.graphics.ImageData; | |
30 import org.eclipse.swt.layout.GridLayout; | |
31 import org.eclipse.swt.layout.GridData; | |
32 import org.eclipse.swt.widgets.Display; | |
33 import org.eclipse.swt.widgets.Shell; | |
34 import org.eclipse.swt.widgets.Text; | |
35 import org.eclipse.swt.widgets.ToolBar; | |
36 import org.eclipse.swt.widgets.ToolItem; | |
37 | |
38 import tango.io.Stdout; | |
39 | |
40 void main() { | |
41 auto display = new Display(); | |
42 auto shell = new Shell(display); | |
43 shell.setLayout(new GridLayout(2, false)); | |
44 | |
45 auto text = new Text(shell, SWT.SEARCH | DWT.CANCEL); | |
46 Image image = null; | |
47 if ((text.getStyle() & SWT.CANCEL) == 0) { | |
48 image = new Image (display, new ImageData(new ByteArrayInputStream( cast(byte[]) import("links_obj.gif" )))); | |
49 auto toolBar = new ToolBar (shell, SWT.FLAT); | |
50 auto item = new ToolItem (toolBar, SWT.PUSH); | |
51 item.setImage (image); | |
52 item.addSelectionListener(new class SelectionAdapter { | |
53 public void widgetSelected(SelectionEvent e) { | |
54 text.setText(""); | |
55 Stdout("Search cancelled").newline; | |
56 } | |
57 }); | |
58 } | |
59 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
60 text.setText("Search text"); | |
61 text.addSelectionListener(new class SelectionAdapter { | |
62 public void widgetDefaultSelected(SelectionEvent e) { | |
63 if (e.detail == SWT.CANCEL) { | |
64 Stdout("Search cancelled").newline; | |
65 } else { | |
66 Stdout("Searching for: ")(text.getText())("...").newline; | |
67 } | |
68 } | |
69 }); | |
70 | |
71 shell.pack(); | |
72 shell.open(); | |
73 while (!shell.isDisposed()) { | |
74 if (!display.readAndDispatch()) display.sleep(); | |
75 } | |
76 if (image !is null) image.dispose(); | |
77 display.dispose(); | |
78 } |