Search in sources :

Example 1 with TrayIcon

use of java.awt.TrayIcon in project cryptomator by cryptomator.

the class ExitUtil method createTrayIcon.

private TrayIcon createTrayIcon(Runnable exitCommand) {
    final PopupMenu popup = new PopupMenu();
    final MenuItem showItem = new MenuItem(localization.getString("tray.menu.open"));
    showItem.addActionListener(this::restoreFromTray);
    popup.add(showItem);
    final MenuItem exitItem = new MenuItem(localization.getString("tray.menu.quit"));
    exitItem.addActionListener(e -> exitCommand.run());
    popup.add(exitItem);
    final Image image;
    if (SystemUtils.IS_OS_MAC_OSX && isMacMenuBarDarkMode()) {
        image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_white.png"));
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_black.png"));
    } else {
        image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon.png"));
    }
    return new TrayIcon(image, localization.getString("app.name"), popup);
}
Also used : TrayIcon(java.awt.TrayIcon) MenuItem(java.awt.MenuItem) Image(java.awt.Image) PopupMenu(java.awt.PopupMenu)

Example 2 with TrayIcon

use of java.awt.TrayIcon in project apjp by jvansteirteghem.

the class Main method main.

public static void main(final String[] args) {
    EventQueue.invokeLater(new Runnable() {

        public void run() {
            try {
                System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
                Security.addProvider(new IAIK());
                Properties properties = new Properties();
                properties.load(new FileInputStream("APJP_LOCAL.properties"));
                APJP.APJP_KEY = properties.getProperty("APJP_KEY", "");
                APJP.APJP_LOGGER_ID = "APJP";
                APJP.APJP_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_PROXY_SERVER";
                APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_PROXY_SERVER";
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTP_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTP_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTP_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_SERVER";
                APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL = new String[10];
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
                for (int i = 0; i < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
                    APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_URL", "");
                    for (int j = 0; j < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
                        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
                        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
                    }
                }
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_PROXY_SERVER";
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTPS_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTPS_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_SERVER";
                APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL = new String[10];
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
                for (int i = 0; i < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
                    APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_URL", "");
                    for (int j = 0; j < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
                        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
                        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
                    }
                }
                APJP.APJP_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTP_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTP_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_HTTP_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_HTTP_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTP_PROXY_SERVER_USERNAME", "");
                APJP.APJP_HTTP_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTP_PROXY_SERVER_PASSWORD", "");
                APJP.APJP_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTPS_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTPS_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_HTTPS_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_HTTPS_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTPS_PROXY_SERVER_USERNAME", "");
                APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTPS_PROXY_SERVER_PASSWORD", "");
                Authenticator.setDefault(new Authenticator() {

                    protected PasswordAuthentication getPasswordAuthentication() {
                        PasswordAuthentication passwordAuthentication = null;
                        if (this.getRequestorType() == Authenticator.RequestorType.PROXY) {
                            if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTP") == true) {
                                passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTP_PROXY_SERVER_USERNAME, APJP.APJP_HTTP_PROXY_SERVER_PASSWORD.toCharArray());
                            } else {
                                if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTPS") == true) {
                                    passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTPS_PROXY_SERVER_USERNAME, APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD.toCharArray());
                                }
                            }
                        }
                        return passwordAuthentication;
                    }
                });
                logger = Logger.getLogger(APJP.APJP_LOGGER_ID);
                final ProxyServer proxyServer = new ProxyServer();
                final JTextArea outputTextArea = new JTextArea();
                outputTextArea.setEditable(false);
                outputTextArea.setLineWrap(true);
                outputTextArea.setBackground(new Color(0, 0, 0));
                outputTextArea.setForeground(new Color(255, 255, 255));
                outputTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
                final JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
                final OutputStream outputStream = new OutputStream() {

                    public void write(final int b) throws IOException {
                        outputTextArea.append(new String(new char[] { (char) b }));
                    }

                    public void write(final byte[] b, final int off, final int len) throws IOException {
                        outputTextArea.append(new String(b, off, len));
                    }
                };
                final PrintStream printStream = new PrintStream(outputStream, true);
                System.setOut(printStream);
                final JButton startButton = new JButton();
                startButton.setText("Start");
                startButton.setPreferredSize(new Dimension(100, 30));
                startButton.addActionListener(new ActionListener() {

                    public void actionPerformed(final ActionEvent actionEvent) {
                        outputTextArea.setText("");
                        logger.log(1, "START_PROXY_SERVER");
                        try {
                            proxyServer.start();
                            logger.log(1, "START_PROXY_SERVER: OK");
                        } catch (Exception e) {
                            logger.log(1, "START_PROXY_SERVER: EXCEPTION", e);
                            logger.log(1, "START_PROXY_SERVER: NOT OK");
                        }
                        HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
                        logger.log(1, "TEST_HTTP_REQUESTS");
                        try {
                            httpRequests.test();
                            logger.log(1, "TEST_HTTP_REQUESTS: OK");
                        } catch (Exception e) {
                            logger.log(1, "TEST_HTTP_REQUESTS: EXCEPTION", e);
                            logger.log(1, "TEST_HTTP_REQUESTS: NOT OK");
                        }
                        HTTPSRequests httpsRequests = HTTPSRequests.getHTTPSRequests();
                        logger.log(1, "TEST_HTTPS_REQUESTS");
                        try {
                            httpsRequests.test();
                            logger.log(1, "TEST_HTTPS_REQUESTS: OK");
                        } catch (Exception e) {
                            logger.log(1, "TEST_HTTPS_REQUESTS: EXCEPTION", e);
                            logger.log(1, "TEST_HTTPS_REQUESTS: NOT OK");
                        }
                    }
                });
                final JButton stopButton = new JButton();
                stopButton.setText("Stop");
                stopButton.setPreferredSize(new Dimension(100, 30));
                stopButton.addActionListener(new ActionListener() {

                    public void actionPerformed(final ActionEvent actionEvent) {
                        outputTextArea.setText("");
                        logger.log(1, "STOP_PROXY_SERVER");
                        try {
                            proxyServer.stop();
                            logger.log(1, "STOP_PROXY_SERVER: OK");
                        } catch (Exception e) {
                            logger.log(1, "STOP_PROXY_SERVER: EXCEPTION", e);
                            logger.log(1, "STOP_PROXY_SERVER: NOT OK");
                        }
                    }
                });
                final Panel buttonPanel = new Panel();
                buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
                buttonPanel.add(startButton);
                buttonPanel.add(stopButton);
                final ImageIcon imageIcon = new ImageIcon("APJP_LOCAL.png");
                final JFrame frame = new JFrame();
                frame.setIconImage(imageIcon.getImage());
                frame.setSize(675, 375);
                frame.setResizable(false);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                frame.add(buttonPanel, BorderLayout.NORTH);
                frame.add(outputScrollPane, BorderLayout.CENTER);
                if (SystemTray.isSupported()) {
                    final TrayIcon trayIcon = new TrayIcon(imageIcon.getImage());
                    trayIcon.setImageAutoSize(true);
                    trayIcon.addActionListener(new ActionListener() {

                        public void actionPerformed(final ActionEvent actionEvent) {
                            frame.setVisible(!frame.isVisible());
                        }
                    });
                    SystemTray.getSystemTray().add(trayIcon);
                }
                frame.setVisible(true);
            } catch (Exception e) {
                logger.log(1, "EXCEPTION", e);
            }
        }
    });
}
Also used : ImageIcon(javax.swing.ImageIcon) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) OutputStream(java.io.OutputStream) JButton(javax.swing.JButton) HTTPRequests(APJP.HTTP11.HTTPRequests) Properties(java.util.Properties) Font(java.awt.Font) HTTPSRequests(APJP.HTTP11.HTTPSRequests) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) TrayIcon(java.awt.TrayIcon) IAIK(iaik.security.provider.IAIK) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication) JScrollPane(javax.swing.JScrollPane) PrintStream(java.io.PrintStream) Color(java.awt.Color) IOException(java.io.IOException) Dimension(java.awt.Dimension) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ProxyServer(APJP.ProxyServer) Panel(java.awt.Panel) ActionListener(java.awt.event.ActionListener)

Example 3 with TrayIcon

use of java.awt.TrayIcon in project jdk8u_jdk by JetBrains.

the class WTrayIconPeer method updateNativeImage.

// ***********************************************
// ***********************************************
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;
    boolean autosize = ((TrayIcon) target).isImageAutoSize();
    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();
            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)), (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);
            createNativeImage(bufImage);
            updateNativeIcon(!firstUpdate);
            if (firstUpdate)
                firstUpdate = false;
        } finally {
            gr.dispose();
        }
    }
}
Also used : TrayIcon(java.awt.TrayIcon) Graphics2D(java.awt.Graphics2D)

Example 4 with TrayIcon

use of java.awt.TrayIcon in project cryptomator by cryptomator.

the class ExitUtil method initTrayIconExitHandler.

private void initTrayIconExitHandler(Runnable exitCommand) {
    final TrayIcon trayIcon = createTrayIcon(exitCommand);
    try {
        // double clicking tray icon should open Cryptomator
        if (SystemUtils.IS_OS_WINDOWS) {
            trayIcon.addMouseListener(new TrayIconMouseListener());
        }
        SystemTray.getSystemTray().add(trayIcon);
        mainWindow.setOnCloseRequest((e) -> {
            if (Platform.isImplicitExit()) {
                exitCommand.run();
            } else {
                macFunctions.map(MacFunctions::uiState).ifPresent(JniException.ignore(MacApplicationUiState::transformToAgentApplication));
                mainWindow.close();
                this.showTrayNotification(trayIcon);
            }
        });
    } catch (SecurityException | AWTException ex) {
        // not working? then just go ahead and close the app
        mainWindow.setOnCloseRequest((ev) -> {
            exitCommand.run();
        });
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) Settings(org.cryptomator.ui.settings.Settings) PopupMenu(java.awt.PopupMenu) Inject(javax.inject.Inject) SwingUtilities(javax.swing.SwingUtilities) TrayIcon(java.awt.TrayIcon) MacFunctions(org.cryptomator.jni.MacFunctions) MouseAdapter(java.awt.event.MouseAdapter) MessageType(java.awt.TrayIcon.MessageType) Named(javax.inject.Named) SystemTray(java.awt.SystemTray) Localization(org.cryptomator.ui.settings.Localization) ScriptException(javax.script.ScriptException) Logger(org.slf4j.Logger) Image(java.awt.Image) SystemUtils(org.apache.commons.lang3.SystemUtils) ScriptEngineManager(javax.script.ScriptEngineManager) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) TimeUnit(java.util.concurrent.TimeUnit) Platform(javafx.application.Platform) MenuItem(java.awt.MenuItem) Stage(javafx.stage.Stage) AWTException(java.awt.AWTException) ScriptEngine(javax.script.ScriptEngine) Optional(java.util.Optional) JniException(org.cryptomator.jni.JniException) MacApplicationUiState(org.cryptomator.jni.MacApplicationUiState) Toolkit(java.awt.Toolkit) TrayIcon(java.awt.TrayIcon) AWTException(java.awt.AWTException)

Example 5 with TrayIcon

use of java.awt.TrayIcon in project screenbird by adamhub.

the class ScreenRecorder method createTray.

/**
     * Sets up the system tray for screenRecorder application
     */
private void createTray() {
    PopupMenu menu = new PopupMenu();
    MenuItem aboutItem = new MenuItem("About");
    aboutItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jfRecorderPanel, String.format("Screenbird%nBuild Version %s", RecorderPanel.resources.getString("BUILD")));
        }
    });
    menu.add(aboutItem);
    // Open the settings menu
    MenuItem settingsItem = new MenuItem("Preferences");
    settingsItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (jpRecorderPanel.isRecorderConfigSate())
                jpRecorderPanel.showSettingsForm();
        }
    });
    menu.add(settingsItem);
    // Hide or show the recorder 
    MenuItem messageItem = new MenuItem("Hide/Show");
    messageItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (jfRecorderPanel.getState() == JFrame.NORMAL) {
                jfRecorderPanel.setState(JFrame.ICONIFIED);
            } else {
                jfRecorderPanel.setState(JFrame.NORMAL);
            }
        }
    });
    menu.add(messageItem);
    MenuItem closeItem = new MenuItem("Quit/Exit");
    closeItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            destroy();
        }
    });
    menu.add(closeItem);
    // Loads the pastevid logo
    Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_16));
    if (!MediaUtil.osIsWindows()) {
        icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_24));
    }
    // Assigns the pastevid logo
    TrayIcon tray = new TrayIcon(icon, "Screenbird", menu);
    try {
        SystemTray.getSystemTray().add(tray);
    } catch (AWTException ex) {
        log(ex);
    }
}
Also used : ActionListener(java.awt.event.ActionListener) TrayIcon(java.awt.TrayIcon) ActionEvent(java.awt.event.ActionEvent) MenuItem(java.awt.MenuItem) Image(java.awt.Image) PopupMenu(java.awt.PopupMenu) AWTException(java.awt.AWTException)

Aggregations

TrayIcon (java.awt.TrayIcon)9 ActionEvent (java.awt.event.ActionEvent)5 Image (java.awt.Image)4 MenuItem (java.awt.MenuItem)4 PopupMenu (java.awt.PopupMenu)4 ActionListener (java.awt.event.ActionListener)4 AWTException (java.awt.AWTException)3 Dimension (java.awt.Dimension)2 SystemTray (java.awt.SystemTray)2 WindowEvent (java.awt.event.WindowEvent)2 IOException (java.io.IOException)2 ImageIcon (javax.swing.ImageIcon)2 JButton (javax.swing.JButton)2 JFrame (javax.swing.JFrame)2 HTTPRequests (APJP.HTTP11.HTTPRequests)1 HTTPSRequests (APJP.HTTP11.HTTPSRequests)1 ProxyServer (APJP.ProxyServer)1 IAIK (iaik.security.provider.IAIK)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1