|
@@ -23,11 +23,19 @@
|
23
|
23
|
package uk.org.ownage.dmdirc.plugins.plugins.systray;
|
24
|
24
|
|
25
|
25
|
import java.awt.AWTException;
|
|
26
|
+import java.awt.MenuItem;
|
|
27
|
+import java.awt.PopupMenu;
|
26
|
28
|
import java.awt.SystemTray;
|
27
|
29
|
import java.awt.TrayIcon;
|
|
30
|
+import java.awt.event.ActionEvent;
|
|
31
|
+import java.awt.event.ActionListener;
|
|
32
|
+import java.awt.event.MouseEvent;
|
|
33
|
+import java.awt.event.MouseListener;
|
|
34
|
+import java.net.URL;
|
28
|
35
|
|
29
|
36
|
import javax.swing.ImageIcon;
|
30
|
37
|
|
|
38
|
+import uk.org.ownage.dmdirc.Main;
|
31
|
39
|
import uk.org.ownage.dmdirc.plugins.Plugin;
|
32
|
40
|
import uk.org.ownage.dmdirc.ui.MainFrame;
|
33
|
41
|
|
|
@@ -36,7 +44,7 @@ import uk.org.ownage.dmdirc.ui.MainFrame;
|
36
|
44
|
* notifications to be disabled.
|
37
|
45
|
* @author chris
|
38
|
46
|
*/
|
39
|
|
-public class SystrayPlugin implements Plugin {
|
|
47
|
+public class SystrayPlugin implements Plugin, ActionListener, MouseListener {
|
40
|
48
|
|
41
|
49
|
/** Is this plugin active? */
|
42
|
50
|
private boolean isActive = false;
|
|
@@ -44,6 +52,22 @@ public class SystrayPlugin implements Plugin {
|
44
|
52
|
/** The tray icon we're currently using. */
|
45
|
53
|
private TrayIcon icon;
|
46
|
54
|
|
|
55
|
+ /** The menu to use for the tray icon. */
|
|
56
|
+ private final PopupMenu menu;
|
|
57
|
+
|
|
58
|
+ /** Creates a new system tray plugin. */
|
|
59
|
+ public SystrayPlugin() {
|
|
60
|
+ final MenuItem show = new MenuItem("Show/hide");
|
|
61
|
+ final MenuItem quit = new MenuItem("Quit");
|
|
62
|
+
|
|
63
|
+ menu = new PopupMenu();
|
|
64
|
+ menu.add(show);
|
|
65
|
+ menu.add(quit);
|
|
66
|
+
|
|
67
|
+ show.addActionListener(this);
|
|
68
|
+ quit.addActionListener(this);
|
|
69
|
+ }
|
|
70
|
+
|
47
|
71
|
/**
|
48
|
72
|
* Sends a notification via the system tray icon.
|
49
|
73
|
* @param title The title of the notification
|
|
@@ -61,21 +85,28 @@ public class SystrayPlugin implements Plugin {
|
61
|
85
|
*/
|
62
|
86
|
public void notify(final String title, final String message) {
|
63
|
87
|
notify(title, message, TrayIcon.MessageType.NONE);
|
64
|
|
- }
|
|
88
|
+ }
|
65
|
89
|
|
66
|
|
- /** {@inheritDoc}. */
|
|
90
|
+ /** {@inheritDoc} */
|
|
91
|
+ public void actionPerformed(final ActionEvent e) {
|
|
92
|
+ if (e.getActionCommand().equals("Show/hide")) {
|
|
93
|
+ MainFrame.getMainFrame().setVisible(!MainFrame.getMainFrame().isVisible());
|
|
94
|
+ } else if (e.getActionCommand().equals("Quit")) {
|
|
95
|
+ Main.quit();
|
|
96
|
+ }
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ /** {@inheritDoc} */
|
67
|
100
|
public boolean onLoad() {
|
68
|
101
|
if (SystemTray.isSupported()) {
|
69
|
|
- final SystemTray tray = SystemTray.getSystemTray();
|
70
|
|
-
|
71
|
|
- final ImageIcon image = MainFrame.getMainFrame().getIcon();
|
72
|
|
-
|
73
|
|
- icon = new TrayIcon(image.getImage());
|
74
|
|
-
|
75
|
|
- icon.setImageAutoSize(false);
|
|
102
|
+ final ClassLoader cldr = this.getClass().getClassLoader();
|
|
103
|
+ final URL imageURL = cldr.getResource("uk/org/ownage/dmdirc/res/logo.png");
|
|
104
|
+ icon = new TrayIcon(new ImageIcon(imageURL).getImage(), "DMDirc", menu);
|
|
105
|
+ icon.setImageAutoSize(true);
|
|
106
|
+ icon.addMouseListener(this);
|
76
|
107
|
|
77
|
108
|
try {
|
78
|
|
- tray.add(icon);
|
|
109
|
+ SystemTray.getSystemTray().add(icon);
|
79
|
110
|
} catch (AWTException ex) {
|
80
|
111
|
return false;
|
81
|
112
|
}
|
|
@@ -88,50 +119,82 @@ public class SystrayPlugin implements Plugin {
|
88
|
119
|
return true;
|
89
|
120
|
}
|
90
|
121
|
|
91
|
|
- /** {@inheritDoc}. */
|
|
122
|
+ /** {@inheritDoc} */
|
92
|
123
|
public void onUnload() {
|
93
|
124
|
}
|
94
|
125
|
|
95
|
|
- /** {@inheritDoc}. */
|
|
126
|
+ /** {@inheritDoc} */
|
96
|
127
|
public void onActivate() {
|
97
|
128
|
isActive = true;
|
98
|
129
|
}
|
99
|
130
|
|
100
|
|
- /** {@inheritDoc}. */
|
|
131
|
+ /** {@inheritDoc} */
|
101
|
132
|
public boolean isActive() {
|
102
|
133
|
return isActive;
|
103
|
134
|
}
|
104
|
135
|
|
105
|
136
|
/** {@inheritDoc}. */
|
106
|
137
|
public void onDeactivate() {
|
|
138
|
+ SystemTray.getSystemTray().remove(icon);
|
107
|
139
|
isActive = false;
|
108
|
|
- final SystemTray tray = SystemTray.getSystemTray();
|
109
|
|
-
|
110
|
|
- tray.remove(icon);
|
111
|
140
|
}
|
112
|
141
|
|
113
|
|
- /** {@inheritDoc}. */
|
|
142
|
+ /** {@inheritDoc} */
|
114
|
143
|
public boolean isConfigurable() {
|
115
|
144
|
return false;
|
116
|
145
|
}
|
117
|
146
|
|
118
|
|
- /** {@inheritDoc}. */
|
|
147
|
+ /** {@inheritDoc} */
|
119
|
148
|
public void showConfig() {
|
120
|
149
|
}
|
121
|
150
|
|
122
|
|
- /** {@inheritDoc}. */
|
|
151
|
+ /** {@inheritDoc} */
|
123
|
152
|
public int getVersion() {
|
124
|
153
|
return 0;
|
125
|
154
|
}
|
126
|
155
|
|
127
|
|
- /** {@inheritDoc}. */
|
|
156
|
+ /** {@inheritDoc} */
|
128
|
157
|
public String getAuthor() {
|
129
|
158
|
return "Chris 'MD87' Smith - chris@dmdirc.com";
|
130
|
159
|
}
|
131
|
160
|
|
132
|
|
- /** {@inheritDoc}. */
|
|
161
|
+ /** {@inheritDoc} */
|
133
|
162
|
public String getDescription() {
|
134
|
163
|
return "Adds a system tray icon";
|
135
|
164
|
}
|
136
|
165
|
|
|
166
|
+ /** {@inheritDoc} */
|
|
167
|
+ public void mouseClicked(final MouseEvent e) {
|
|
168
|
+ if (e.getButton() == MouseEvent.BUTTON1) {
|
|
169
|
+ if (MainFrame.getMainFrame().isVisible()) {
|
|
170
|
+ // TODO: Uncomment the code below, with an appropriate replacement
|
|
171
|
+ // for requestFocus() that does something more than flash.
|
|
172
|
+
|
|
173
|
+ //if (MainFrame.getMainFrame().isActive()) {
|
|
174
|
+ MainFrame.getMainFrame().setVisible(false);
|
|
175
|
+ //} else {
|
|
176
|
+ // MainFrame.getMainFrame().requestFocus();
|
|
177
|
+ //}
|
|
178
|
+ } else {
|
|
179
|
+ MainFrame.getMainFrame().setVisible(true);
|
|
180
|
+ }
|
|
181
|
+ }
|
|
182
|
+ }
|
|
183
|
+
|
|
184
|
+ /** {@inheritDoc} */
|
|
185
|
+ public void mousePressed(final MouseEvent e) {
|
|
186
|
+ }
|
|
187
|
+
|
|
188
|
+ /** {@inheritDoc} */
|
|
189
|
+ public void mouseReleased(final MouseEvent e) {
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ /** {@inheritDoc} */
|
|
193
|
+ public void mouseEntered(final MouseEvent e) {
|
|
194
|
+ }
|
|
195
|
+
|
|
196
|
+ /** {@inheritDoc} */
|
|
197
|
+ public void mouseExited(final MouseEvent e) {
|
|
198
|
+ }
|
|
199
|
+
|
137
|
200
|
}
|