Mercurial > projects > dwt-samples
comparison dwtsnippets/tray/Snippet143.d @ 24:5681fc54f1c1
Added Tray-Snippet143
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 02 Mar 2008 18:52:39 +0100 |
parents | |
children | 6fb20f548c46 |
comparison
equal
deleted
inserted
replaced
23:073094250126 | 24:5681fc54f1c1 |
---|---|
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 dwt.snippets.tray.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 DWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.0 | |
22 */ | |
23 import dwt.DWT; | |
24 import dwt.graphics.Image; | |
25 import dwt.widgets.Shell; | |
26 import dwt.widgets.Display; | |
27 import dwt.widgets.Menu; | |
28 import dwt.widgets.MenuItem; | |
29 import dwt.widgets.Tray; | |
30 import dwt.widgets.TrayItem; | |
31 import dwt.widgets.Listener; | |
32 import dwt.widgets.Event; | |
33 import tango.io.Stdout; | |
34 import tango.text.convert.Format; | |
35 | |
36 TrayItem item; | |
37 Menu menu; | |
38 | |
39 public static void main(char[][] args) { | |
40 Display display = new Display (); | |
41 Shell shell = new Shell (display); | |
42 Image image = new Image (display, 16, 16); | |
43 final Tray tray = display.getSystemTray (); | |
44 if (tray == null) { | |
45 Stdout.formatln ("The system tray is not available"); | |
46 } else { | |
47 item = new TrayItem (tray, DWT.NONE); | |
48 item.setToolTipText("DWT TrayItem"); | |
49 item.addListener (DWT.Show, new class() Listener { | |
50 public void handleEvent (Event event) { | |
51 Stdout.formatln("show"); | |
52 } | |
53 }); | |
54 item.addListener (DWT.Hide, new class() Listener { | |
55 public void handleEvent (Event event) { | |
56 Stdout.formatln("hide"); | |
57 } | |
58 }); | |
59 item.addListener (DWT.Selection, new class() Listener { | |
60 public void handleEvent (Event event) { | |
61 Stdout.formatln("selection"); | |
62 } | |
63 }); | |
64 item.addListener (DWT.DefaultSelection, new class() Listener { | |
65 public void handleEvent (Event event) { | |
66 Stdout.formatln("default selection"); | |
67 } | |
68 }); | |
69 menu = new Menu (shell, DWT.POP_UP); | |
70 for (int i = 0; i < 8; i++) { | |
71 MenuItem mi = new MenuItem (menu, DWT.PUSH); | |
72 mi.setText ( Format( "Item{}", i )); | |
73 mi.addListener (DWT.Selection, new class() Listener { | |
74 public void handleEvent (Event event) { | |
75 Stdout.formatln("selection {}", event.widget); | |
76 } | |
77 }); | |
78 if (i == 0) menu.setDefaultItem(mi); | |
79 } | |
80 item.addListener (DWT.MenuDetect, new class() Listener { | |
81 public void handleEvent (Event event) { | |
82 menu.setVisible (true); | |
83 } | |
84 }); | |
85 item.setImage (image); | |
86 } | |
87 shell.setBounds(50, 50, 300, 200); | |
88 shell.open (); | |
89 while (!shell.isDisposed ()) { | |
90 if (!display.readAndDispatch ()) display.sleep (); | |
91 } | |
92 image.dispose (); | |
93 display.dispose (); | |
94 } | |
95 |