Package java.awt

Examples of java.awt.SystemTray


                }
                AccessController.doPrivileged(new PrivilegedAction() {
                        public Object run() {
                            if (!GraphicsEnvironment.isHeadless() && SystemTray.isSupported())
                            {
                                SystemTray systemTray = SystemTray.getSystemTray();
                                TrayIcon[] trayIconsToDispose = systemTray.getTrayIcons();
                                for (TrayIcon ti : trayIconsToDispose) {
                                    systemTray.remove(ti);
                                }
                            }
                            return null;
                        }
                    });
View Full Code Here


        System.out.println("Starting monitor...");
    }

    private static void addSystemTrayIcon() throws AWTException, MalformedURLException {
        SystemTray tray = SystemTray.getSystemTray();

        URL moviepng = NotificationMonitor.class.getClassLoader().getResource("movie.png");
        Image image = Toolkit.getDefaultToolkit().getImage(moviepng);

        ActionListener exitListener = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("Exiting monitor...");
                System.exit(0);
            }
        };

        PopupMenu popup = new PopupMenu();
        MenuItem defaultItem = new MenuItem("Exit");
        defaultItem.addActionListener(exitListener);
        popup.add(defaultItem);

        trayIcon = new TrayIcon(image, "Notification Monitor", popup);
        trayIcon.setImageAutoSize(true);
        tray.add(trayIcon);


    }
View Full Code Here

                }
                AccessController.doPrivileged(new PrivilegedAction() {
                        public Object run() {
                            if (!GraphicsEnvironment.isHeadless() && SystemTray.isSupported())
                            {
                                SystemTray systemTray = SystemTray.getSystemTray();
                                TrayIcon[] trayIconsToDispose = systemTray.getTrayIcons();
                                for (TrayIcon ti : trayIconsToDispose) {
                                    systemTray.remove(ti);
                                }
                            }
                            return null;
                        }
                    });
View Full Code Here

    private void enableSystemTray() {

        if (SystemTray.isSupported()) {

            SystemTray tray = SystemTray.getSystemTray();
            MouseListener mouseListener = getMouseListener();

            log.info("Creating listeners");

            final ActionListener exitListener = getExitListener();
            final WindowListener settingsWindowListener = getSettingsWindowListener();
            final WindowListener notificationWindowListener = getNotificationWindowListener();
            final ActionListener settingsListener = getSettingsListener(settingsWindowListener);
            final ActionListener showNotificationsListener = getShowNotificationListener(notificationWindowListener);
            final ActionListener configListener = this.getConfigurationListener();

            log.info("Creating popup and tray icon ");

            PopupMenu popup = new PopupMenu();
            MenuItem exitItem = new MenuItem("Exit");
            exitItem.addActionListener(exitListener);
            MenuItem settingsItem = new MenuItem("Connection Settings");
            settingsItem.addActionListener(settingsListener);
            MenuItem configsItem = new MenuItem("Configurations");
            configsItem.addActionListener(configListener);
            MenuItem notifyItem = new MenuItem("Show notifications");
            notifyItem.addActionListener(showNotificationsListener);

            popup.add(settingsItem);
            popup.add(configsItem);
            popup.add(notifyItem);
            popup.addSeparator();
            popup.add(exitItem);

            trayIcon = new TrayIcon(opengrokImage, "OpenGrok Agent Client", popup);

            final ActionListener actionListener = getAgentActionListener();

            if (agent == null || !agent.isConnected()) {
                trayIcon.setImage(noConnectionImage);
            } else {
                agent.setActionListener(actionListener);
            }

            trayIcon.setImageAutoSize(true);
            trayIcon.addActionListener(actionListener);
            trayIcon.addMouseListener(mouseListener);

            try {
                tray.add(trayIcon);
            } catch (AWTException e) {
                log.log(Level.WARNING, "TrayIcon could not be added.", e);
            }
            log.info("Created, ready for action");
View Full Code Here

        if (SystemTray.isSupported()) {
            // allow proper shutdown
            System.setProperty("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES","false");


            SystemTray tray = SystemTray.getSystemTray();

            // create menu
            PopupMenu popup = new PopupMenu();


            //MenuItem mainPage = createMenuItem("Start Page", "http://"+getServerName()+":"+getServerPort()+"/");
            //popup.add(mainPage);

            popup.addSeparator();


            // launch browser action
            MenuItem admin = createMenuItem("Administration","http://"+getServerName()+":"+getServerPort()+"/");
            popup.add(admin);

            // admin links

            for(final Map.Entry<String,String> linkEntry : adminLinks.entrySet()) {
                MenuItem entry = createMenuItem(linkEntry.getKey(),linkEntry.getValue());
                popup.add(entry);
            }

            // shutdown action
            MenuItem shutdown = new MenuItem("Shutdown");
            try {
                Class.forName("org.apache.catalina.mbeans.MBeanUtils");
                ActionListener stopListener = new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        performServerShutdown();
                    }
                };
                shutdown.addActionListener(stopListener);
            } catch (ClassNotFoundException e) {
                shutdown.setEnabled(false);
            }
            popup.add(shutdown);

            popup.addSeparator();

            for(final Map.Entry<String,String> linkEntry : demoLinks.entrySet()) {
                boolean containsEntry = false;
                for(int i = 0; i < popup.getItemCount(); i++) {
                    MenuItem item = popup.getItem(i);
                    if(item.getLabel().equals(linkEntry.getKey())) {
                        containsEntry = true;
                        break;
                    }
                }

                if(!containsEntry) {
                    MenuItem entry = createMenuItem(linkEntry.getKey(),linkEntry.getValue());
                    popup.add(entry);
                }
            }

            popup.addSeparator();

            MenuItem about = new MenuItem("About");
            about.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    TaskDialogs.inform(null,
                            "About Apache Marmotta \n",
                            "(c)2013 The Apache Software Foundation \n" +
                            "Visit http://marmotta.incubator.apache.org for further details");
                }
            });
            popup.add(about);

            MenuItem issues = createMenuItem("Issues Reports", "https://issues.apache.org/jira/browse/MARMOTTA");
            popup.add(issues);

            MenuItem homepage = createMenuItem("Project Homepage", "http://marmotta.incubator.apache.org");
            popup.add(homepage);


            // load icon image
            try {
                Image image = ImageIO.read(SystrayListener.class.getResource("systray.png"));
                icon = new TrayIcon(image,"Apache Marmotta",popup);
                icon.setImageAutoSize(true);
                tray.add(icon);

            } catch (IOException e) {
                log.error("SYSTRAY: could not load the logo for system tray",e);
            } catch (AWTException e) {
                log.error("SYSTRAY: tray icon could not be added");
View Full Code Here

        if (SystemTray.isSupported()) {
            // allow proper shutdown
            System.setProperty("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES","false");


            SystemTray tray = SystemTray.getSystemTray();

            // create menu
            PopupMenu popup = new PopupMenu();


            //MenuItem mainPage = createMenuItem("Start Page", "http://"+getServerName()+":"+getServerPort()+"/");
            //popup.add(mainPage);
            //popup.addSeparator();


            // launch browser action
            MenuItem admin = createMenuItem("Administration","http://"+getServerName()+":"+getServerPort()+"/");
            popup.add(admin);

            // admin links

            for(final Map.Entry<String,String> linkEntry : adminLinks.entrySet()) {
                MenuItem entry = createMenuItem(linkEntry.getKey(),linkEntry.getValue());
                popup.add(entry);
            }

            // shutdown action
            MenuItem shutdown = new MenuItem("Shutdown");
            try {
                Class.forName("org.apache.catalina.mbeans.MBeanUtils");
                ActionListener stopListener = new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        performServerShutdown();
                    }
                };
                shutdown.addActionListener(stopListener);
            } catch (ClassNotFoundException e) {
                shutdown.setEnabled(false);
            }
            popup.add(shutdown);

           
            if (!demoLinks.isEmpty()) {
                popup.addSeparator();
            }
            for(final Map.Entry<String,String> linkEntry : demoLinks.entrySet()) {
                boolean containsEntry = false;
                for(int i = 0; i < popup.getItemCount(); i++) {
                    MenuItem item = popup.getItem(i);
                    if(item.getLabel().equals(linkEntry.getKey())) {
                        containsEntry = true;
                        break;
                    }
                }

                if(!containsEntry) {
                    MenuItem entry = createMenuItem(linkEntry.getKey(),linkEntry.getValue());
                    popup.add(entry);
                }
            }

            popup.addSeparator();
            MenuItem about = new MenuItem("About");
            about.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    MessageDialog.show("Apache Marmotta",
                            "About Apache Marmotta \n",
                            "(c)2014 The Apache Software Foundation \n" +
                            "Visit http://marmotta.apache.org for further details");
                }
            });
            popup.add(about);

            MenuItem issues = createMenuItem("Issues Reports", "https://issues.apache.org/jira/browse/MARMOTTA");
            popup.add(issues);

            MenuItem homepage = createMenuItem("Project Homepage", "http://marmotta.apache.org");
            popup.add(homepage);


            // load icon image
            try {
                Image image = ImageIO.read(SystrayListener.class.getResource("systray.png"));
                icon = new TrayIcon(image,"Apache Marmotta",popup);
                icon.setImageAutoSize(true);
                tray.add(icon);

            } catch (IOException e) {
                log.error("SYSTRAY: could not load the logo for system tray",e);
            } catch (AWTException e) {
                log.error("SYSTRAY: tray icon could not be added");
View Full Code Here

        this.workingDir = working;

        normal = createImage("/record_icon_small.png");
        on = createImage("/record_icon_on_small.png");

        SystemTray tray = SystemTray.getSystemTray();
        if (!SystemTray.isSupported()) {
            throw new RuntimeException("Tray Not Supported");
        }
        trayIcon = new TrayIcon(normal, "Couch Audio Recorder");
        final PopupMenu popup = createMenu();

        trayIcon.setPopupMenu(popup);
        try {
            tray.add(trayIcon);
            //registerEvents();
        } catch (AWTException e) {

        }
View Full Code Here

        }
    }

    private static void trySystemTrayIntegration() throws Exception {
        if (SystemTray.isSupported()) {
            SystemTray tray = SystemTray.getSystemTray();
            TrayIcon trayIcon = new TrayIcon(Utils.getImage("/assets/image/Icon.png"));

            trayIcon.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    if (e.getButton() == MouseEvent.BUTTON3) {
                        TRAY_MENU.setInvoker(TRAY_MENU);
                        TRAY_MENU.setLocation(e.getX(), e.getY());
                        TRAY_MENU.setVisible(true);
                    }
                }
            });
            trayIcon.setToolTip("ATLauncher");
            trayIcon.setImageAutoSize(true);

            tray.add(trayIcon);
        }
    }
View Full Code Here

   */
  private void createTrayIcon()
  {
    // TODO: Add checks to ensure the system tray is available (although this will always run under Windows)
   
    SystemTray sysTray = SystemTray.getSystemTray();
    Image iconImage = Toolkit.getDefaultToolkit().getImage("icon.png");
   
    ExitActionListener exitListener = new ExitActionListener(ogThread, cfa635Thread);
   
    PopupMenu popupMenu = new PopupMenu();
    MenuItem exitItem = new MenuItem("Exit");
    exitItem.addActionListener(exitListener);
    popupMenu.add(exitItem);
   
    TrayIcon trayIcon = new TrayIcon(iconImage, "LFSLCD", popupMenu);
    trayIcon.setImageAutoSize(true);
   
    try {
      sysTray.add(trayIcon);
    }
    catch (AWTException e) {
      log.fatal("Can't add the tray icon", e);
      System.exit(1);
    }
View Full Code Here

  {
    // Do nothing if there is no system tray support
    if (!SystemTray.isSupported()) return;
   
    // Initialize the system tray with the icon
    SystemTray tray = SystemTray.getSystemTray();
    Image image = Toolkit.getDefaultToolkit().getImage("icon.gif");
   
    // Create the popup menu
    PopupMenu popup = new PopupMenu();
    MenuItem restoreItem = new MenuItem("Restore");
    MenuItem exitItem = new MenuItem("Exit");
   
    // Treat the "Exit" option as closing the window
    ActionListener exitListener = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        app.new WindowExitAdapter().windowClosing(null);
        System.exit(0);
      }
    };
   
    // Treat the "Restore" option as a deiconification
    ActionListener restoreListener = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        app.new WindowRestoreAdapter().windowDeiconified(null);
      }
    };
   
    restoreItem.addActionListener(restoreListener);
    exitItem.addActionListener(exitListener);
   
    popup.add(restoreItem);
    popup.add(exitItem);
   
    trayIcon = new TrayIcon(image, "StreamTracker", popup);
   
    trayIcon.setImageAutoSize(true);
   
    trayIcon.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent arg0) {
        app.new WindowRestoreAdapter().windowDeiconified(null);
      }
    });
   
    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      System.out.println("Could not be added");
    }
  }
View Full Code Here

TOP

Related Classes of java.awt.SystemTray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.