Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet143.d @ 125:c43718956f21 default tip
Updated the snippets status.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 11 Aug 2011 19:55:14 +0200 |
parents | 536e43f63c81 |
children |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2005 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 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet143; | |
14 | |
15 /* | |
16 * Tray example snippet: place an icon with a popup menu on the system tray | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.0 | |
22 */ | |
23 import org.eclipse.swt.SWT; | |
24 import org.eclipse.swt.graphics.Image; | |
25 import org.eclipse.swt.widgets.Shell; | |
26 import org.eclipse.swt.widgets.Display; | |
27 import org.eclipse.swt.widgets.Menu; | |
28 import org.eclipse.swt.widgets.MenuItem; | |
29 import org.eclipse.swt.widgets.Tray; | |
30 import org.eclipse.swt.widgets.TrayItem; | |
31 import org.eclipse.swt.widgets.Listener; | |
32 import org.eclipse.swt.widgets.Event; | |
112 | 33 import java.lang.all; |
34 version(Tango){ | |
35 import tango.io.Stdout; | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
36 void writeln(in char[] line) { |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
37 Stdout(line)("\n").flush(); |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
38 } |
112 | 39 } else { // Phobos |
40 import std.stdio; | |
41 } | |
28 | 42 |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
43 void main() { |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
44 TrayItem item; |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
45 Menu menu; |
28 | 46 |
47 Display display = new Display (); | |
48 Shell shell = new Shell (display); | |
49 Image image = new Image (display, 16, 16); | |
112 | 50 Tray tray = display.getSystemTray (); |
28 | 51 if (tray is null) { |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
52 writeln("The system tray is not available"); |
28 | 53 } else { |
54 item = new TrayItem (tray, SWT.NONE); | |
55 item.setToolTipText("SWT TrayItem"); | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
56 item.addListener (SWT.Show, new class Listener { |
28 | 57 public void handleEvent (Event event) { |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
58 writeln("show"); |
28 | 59 } |
60 }); | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
61 item.addListener (SWT.Hide, new class Listener { |
28 | 62 public void handleEvent (Event event) { |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
63 writeln("hide"); |
28 | 64 } |
65 }); | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
66 item.addListener (SWT.Selection, new class Listener { |
28 | 67 public void handleEvent (Event event) { |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
68 writeln("selection"); |
28 | 69 } |
70 }); | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
71 item.addListener (SWT.DefaultSelection, new class Listener { |
28 | 72 public void handleEvent (Event event) { |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
73 writeln("default selection"); |
28 | 74 } |
75 }); | |
76 menu = new Menu (shell, SWT.POP_UP); | |
77 for (int i = 0; i < 8; i++) { | |
78 MenuItem mi = new MenuItem (menu, SWT.PUSH); | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
79 mi.setText ( Format( "Item{}", i )); |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
80 mi.addListener (SWT.Selection, new class Listener { |
28 | 81 public void handleEvent (Event event) { |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
82 writeln ( Format( "selection {}", event.widget ) ); |
28 | 83 } |
84 }); | |
85 if (i == 0) menu.setDefaultItem(mi); | |
86 } | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
87 item.addListener (SWT.MenuDetect, new class Listener { |
28 | 88 public void handleEvent (Event event) { |
89 menu.setVisible (true); | |
90 } | |
91 }); | |
92 item.setImage (image); | |
93 } | |
94 shell.setBounds(50, 50, 300, 200); | |
95 shell.open (); | |
96 while (!shell.isDisposed ()) { | |
97 if (!display.readAndDispatch ()) display.sleep (); | |
98 } | |
99 image.dispose (); | |
100 display.dispose (); | |
101 } | |
102 |