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;
|
|
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 is null) {
|
|
45 Stdout.formatln ("The system tray is not available");
|
|
46 } else {
|
|
47 item = new TrayItem (tray, SWT.NONE);
|
|
48 item.setToolTipText("SWT TrayItem");
|
|
49 item.addListener (SWT.Show, new class() Listener {
|
|
50 public void handleEvent (Event event) {
|
|
51 Stdout.formatln("show");
|
|
52 }
|
|
53 });
|
|
54 item.addListener (SWT.Hide, new class() Listener {
|
|
55 public void handleEvent (Event event) {
|
|
56 Stdout.formatln("hide");
|
|
57 }
|
|
58 });
|
|
59 item.addListener (SWT.Selection, new class() Listener {
|
|
60 public void handleEvent (Event event) {
|
|
61 Stdout.formatln("selection");
|
|
62 }
|
|
63 });
|
|
64 item.addListener (SWT.DefaultSelection, new class() Listener {
|
|
65 public void handleEvent (Event event) {
|
|
66 Stdout.formatln("default selection");
|
|
67 }
|
|
68 });
|
|
69 menu = new Menu (shell, SWT.POP_UP);
|
|
70 for (int i = 0; i < 8; i++) {
|
|
71 MenuItem mi = new MenuItem (menu, SWT.PUSH);
|
|
72 mi.setText ( Format( "Item{}", i ));
|
|
73 mi.addListener (SWT.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 (SWT.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
|