comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet153.d @ 28:69b1fa94a4a8

Added SWT snippets
author Frank Benoit <benoit@tionex.de>
date Sun, 22 Mar 2009 15:17:04 +0100
parents
children 9f4c18c268b2
comparison
equal deleted inserted replaced
27:1bf55a6eb092 28:69b1fa94a4a8
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 * Port to the D programming language:
11 * Bill Baxter <bill@billbaxter.com>
12 *******************************************************************************/
13 module org.eclipse.swt.snippets.Snippet153;
14
15 /*
16 * ToolBar example snippet: update a status line when the pointer enters a ToolItem
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.MouseEvent;
23 import org.eclipse.swt.events.MouseMoveListener;
24 import org.eclipse.swt.graphics.Point;
25 import org.eclipse.swt.widgets.Display;
26 import org.eclipse.swt.widgets.Shell;
27 import org.eclipse.swt.widgets.ToolBar;
28 import org.eclipse.swt.widgets.ToolItem;
29 import org.eclipse.swt.widgets.Label;
30
31 static char[] statusText = "";
32 void main() {
33 Display display = new Display();
34 Shell shell = new Shell(display);
35 shell.setBounds(10, 10, 200, 200);
36 ToolBar bar = new ToolBar(shell, SWT.BORDER);
37 bar.setBounds(10, 10, 150, 50);
38 Label statusLine = new Label(shell, SWT.BORDER);
39 statusLine.setBounds(10, 90, 150, 30);
40 (new ToolItem(bar, SWT.NONE)).setText("item 1");
41 (new ToolItem(bar, SWT.NONE)).setText("item 2");
42 (new ToolItem(bar, SWT.NONE)).setText("item 3");
43 bar.addMouseMoveListener(new class MouseMoveListener {
44 void mouseMove(MouseEvent e) {
45 ToolItem item = bar.getItem(new Point(e.x, e.y));
46 char[] name = "";
47 if (item !is null) {
48 name = item.getText();
49 }
50 if (statusText != name) {
51 statusLine.setText(name);
52 statusText = name;
53 }
54 }
55 });
56 shell.open();
57 while (!shell.isDisposed()) {
58 if (!display.readAndDispatch()) display.sleep();
59 }
60 display.dispose();
61 }
62