Search in sources :

Example 1 with Nxt

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();
}
Also used : Generator(org.xel.Generator) ActionListener(java.awt.event.ActionListener) Constants(org.xel.Constants) Date(java.util.Date) Convert(org.xel.util.Convert) Collection(java.util.Collection) Logger(org.xel.util.Logger) IOException(java.io.IOException) API(org.xel.http.API) java.awt(java.awt) Block(org.xel.Block) Paths(java.nio.file.Paths) Locale(java.util.Locale) Peers(org.xel.peer.Peers) Db(org.xel.Db) Nxt(org.xel.Nxt) DateFormat(java.text.DateFormat) javax.swing(javax.swing) ActionListener(java.awt.event.ActionListener) IOException(java.io.IOException)

Aggregations

java.awt (java.awt)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 Paths (java.nio.file.Paths)1 DateFormat (java.text.DateFormat)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Locale (java.util.Locale)1 javax.swing (javax.swing)1 Block (org.xel.Block)1 Constants (org.xel.Constants)1 Db (org.xel.Db)1 Generator (org.xel.Generator)1 Nxt (org.xel.Nxt)1 API (org.xel.http.API)1 Peers (org.xel.peer.Peers)1 Convert (org.xel.util.Convert)1 Logger (org.xel.util.Logger)1