If the system doesn't support systray SystemTray.getSystemTray() will failed
This commit is contained in:
@@ -52,8 +52,7 @@ public class GuiSwing extends JFrame implements Gui {
|
|||||||
WORKING, SETTINGS
|
WORKING, SETTINGS
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final SystemTray TRAY = SystemTray.getSystemTray();
|
private SystemTray sysTray;
|
||||||
|
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private Working activityWorking;
|
private Working activityWorking;
|
||||||
private Settings activitySettings;
|
private Settings activitySettings;
|
||||||
@@ -81,6 +80,13 @@ public class GuiSwing extends JFrame implements Gui {
|
|||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
sysTray = SystemTray.getSystemTray();
|
||||||
|
}
|
||||||
|
catch (UnsupportedOperationException e) {
|
||||||
|
sysTray = null;
|
||||||
|
}
|
||||||
|
|
||||||
URL iconUrl = getClass().getResource("/icon.png");
|
URL iconUrl = getClass().getResource("/icon.png");
|
||||||
if (iconUrl != null) {
|
if (iconUrl != null) {
|
||||||
ImageIcon img = new ImageIcon(iconUrl);
|
ImageIcon img = new ImageIcon(iconUrl);
|
||||||
@@ -214,14 +220,14 @@ public class GuiSwing extends JFrame implements Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hideToTray() {
|
public void hideToTray() {
|
||||||
if (SystemTray.isSupported() == false) {
|
if (sysTray == null || SystemTray.isSupported() == false) {
|
||||||
System.out.println("GuiSwing::hideToTray SystemTray not supported!");
|
System.out.println("GuiSwing::hideToTray SystemTray not supported!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
trayIcon = getTrayIcon();
|
trayIcon = getTrayIcon();
|
||||||
TRAY.add(trayIcon);
|
sysTray.add(trayIcon);
|
||||||
}
|
}
|
||||||
catch (AWTException e) {
|
catch (AWTException e) {
|
||||||
System.out.println("GuiSwing::hideToTray an error occured while trying to add system tray icon (exception: " + e + ")");
|
System.out.println("GuiSwing::hideToTray an error occured while trying to add system tray icon (exception: " + e + ")");
|
||||||
@@ -233,8 +239,10 @@ public class GuiSwing extends JFrame implements Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void restoreFromTray() {
|
public void restoreFromTray() {
|
||||||
TRAY.remove(trayIcon);
|
if (sysTray != null && SystemTray.isSupported()) {
|
||||||
setVisible(true);
|
sysTray.remove(trayIcon);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrayIcon getTrayIcon() {
|
public TrayIcon getTrayIcon() {
|
||||||
|
|||||||
Reference in New Issue
Block a user