diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet258.d	Sun Mar 22 15:17:04 2009 +0100
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ *******************************************************************************/
+
+module org.eclipse.swt.snippets.Snippet258;
+
+/*
+ * Create a search text control
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ *
+ * @since 3.3
+ */
+import org.eclipse.swt.SWT;
+import java.io.ByteArrayInputStream;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+
+import tango.io.Stdout;
+
+void main() {
+    auto display = new Display();
+    auto shell = new Shell(display);
+    shell.setLayout(new GridLayout(2, false));
+
+    auto text = new Text(shell, SWT.SEARCH | DWT.CANCEL);
+    Image image = null;
+    if ((text.getStyle() & SWT.CANCEL) == 0) {
+        image = new Image (display, new ImageData(new ByteArrayInputStream( cast(byte[]) import("links_obj.gif" ))));
+        auto toolBar = new ToolBar (shell, SWT.FLAT);
+        auto item = new ToolItem (toolBar, SWT.PUSH);
+        item.setImage (image);
+        item.addSelectionListener(new class SelectionAdapter {
+            public void widgetSelected(SelectionEvent e) {
+                text.setText("");
+                Stdout("Search cancelled").newline;
+            }
+        });
+    }
+    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+    text.setText("Search text");
+    text.addSelectionListener(new class SelectionAdapter {
+        public void widgetDefaultSelected(SelectionEvent e) {
+            if (e.detail == SWT.CANCEL) {
+                Stdout("Search cancelled").newline;
+            } else {
+                Stdout("Searching for: ")(text.getText())("...").newline;
+            }
+        }
+    });
+
+    shell.pack();
+    shell.open();
+    while (!shell.isDisposed()) {
+        if (!display.readAndDispatch()) display.sleep();
+    }
+    if (image !is null) image.dispose();
+    display.dispose();
+}