use of org.xel.Nxt in project elastic-core-maven by OrdinaryDude.
the class DesktopSystemTray method createAndShowGUI.
void createAndShowGUI() {
if (!SystemTray.isSupported()) {
Logger.logInfoMessage("SystemTray is not supported");
return;
}
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
final PopupMenu popup = new PopupMenu();
imageIcon = new ImageIcon("html/www/img/nxt-icon-32x32.png", "tray icon");
trayIcon = new TrayIcon(imageIcon.getImage());
trayIcon.setImageAutoSize(true);
tray = SystemTray.getSystemTray();
MenuItem shutdown = new MenuItem("Shutdown");
openWalletInBrowser = new MenuItem("Open Wallet in Browser");
if (!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
openWalletInBrowser.setEnabled(false);
}
MenuItem showDesktopApplication = new MenuItem("Show Desktop Application");
MenuItem refreshDesktopApplication = new MenuItem("Refresh Wallet");
if (!Nxt.isDesktopApplicationEnabled()) {
showDesktopApplication.setEnabled(false);
refreshDesktopApplication.setEnabled(false);
}
viewLog = new MenuItem("View Log File");
if (!Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
viewLog.setEnabled(false);
}
MenuItem status = new MenuItem("Status");
popup.add(status);
popup.add(viewLog);
popup.addSeparator();
popup.add(openWalletInBrowser);
popup.add(showDesktopApplication);
popup.add(refreshDesktopApplication);
popup.addSeparator();
popup.add(shutdown);
trayIcon.setPopupMenu(popup);
trayIcon.setToolTip("Initializing");
try {
tray.add(trayIcon);
} catch (AWTException e) {
Logger.logInfoMessage("TrayIcon could not be added", e);
return;
}
trayIcon.addActionListener(e -> displayStatus());
openWalletInBrowser.addActionListener(e -> {
try {
Desktop.getDesktop().browse(dataProvider.getWallet());
} catch (IOException ex) {
Logger.logInfoMessage("Cannot open wallet in browser", ex);
}
});
showDesktopApplication.addActionListener(e -> {
try {
Class.forName("nxtdesktop.DesktopApplication").getMethod("launch").invoke(null);
} catch (ReflectiveOperationException exception) {
Logger.logInfoMessage("DesktopApplication failed to launch", exception);
}
});
refreshDesktopApplication.addActionListener(e -> {
try {
Class.forName("nxtdesktop.DesktopApplication").getMethod("refresh").invoke(null);
} catch (ReflectiveOperationException exception) {
Logger.logInfoMessage("DesktopApplication failed to refresh", exception);
}
});
viewLog.addActionListener(e -> {
try {
Desktop.getDesktop().open(dataProvider.getLogFile());
} catch (IOException ex) {
Logger.logInfoMessage("Cannot view log", ex);
}
});
status.addActionListener(e -> displayStatus());
shutdown.addActionListener(e -> {
if (JOptionPane.showConfirmDialog(null, "Sure you want to shutdown XEL?\n\nIf you do, this will stop forging, shufflers and account monitors.\n\n", "Shutdown", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
Logger.logInfoMessage("Shutdown requested by System Tray");
// Implicitly invokes shutdown using the shutdown hook
System.exit(0);
}
});
ActionListener statusUpdater = evt -> {
if (statusDialog == null || !statusDialog.isVisible()) {
return;
}
displayStatus();
};
new Timer(DELAY, statusUpdater).start();
}
Aggregations