Package java.awt

Examples of java.awt.SystemTray


      return;
    }

    // NOTE: The SystemTray must be created get before the TrayIconHandler is created.
    //       Otherwise a UnsatisfiedLinkError will raise on linux systems
    SystemTray tray = SystemTray.getSystemTray();
    Image icon = loadImageFromClasspath("net/sf/regain/ui/desktop/regain_icon_16.gif");

    PopupMenu menu = new PopupMenu();
    MenuItem item;

    item = new MenuItem(localizer.msg("search", "Search"));
    item.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent evt) {
        DesktopToolkit.openPageInBrowser("searchinput.jsp");
      }
    });
    menu.add(item);

    item = new MenuItem(localizer.msg("status", "Status"));
    item.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent evt) {
        DesktopToolkit.openPageInBrowser("status.jsp");
      }
    });
    menu.add(item);

    item = new MenuItem(localizer.msg("config", "Preferences"));
    item.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent evt) {
        DesktopToolkit.openPageInBrowser("config.jsp");
      }
    });
    menu.add(item);

    menu.addSeparator();

    item = new MenuItem(localizer.msg("exit", "Exit"));
    item.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent evt) {
        Main.quit();
      }
    });
    menu.add(item);

    trayIcon = new TrayIcon(icon, "regain", menu);
    trayIcon.setImageAutoSize(true);
    trayIcon.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent evt) {
        DesktopToolkit.openPageInBrowser("searchinput.jsp");
      }
    });

    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      System.err.println("TrayIcon could not be added.");
    }
  }
View Full Code Here


    // System.out.println("hello world. short test");
  }

  private static void startTray()
  {
    SystemTray tray = SystemTray.getSystemTray();
    int w = 80;
    int[] pix = new int[w*w];
    for (int i=0; i< w*w; i++ )
      pix [i]=(int)(Math.random ()*255);
    ImageProducer producer = new MemoryImageSource ( w,w,pix,0,w );
    Image  image = Toolkit.getDefaultToolkit().createImage(producer);
    TrayIcon trayIcon = new TrayIcon(image);
    trayIcon.setImageAutoSize(true);
    startWindow();
    try
    {
      tray.add(trayIcon);
      System.out.println("installed tray");
    }
    catch (AWTException e)
    {
      // TODO Auto-generated catch block
View Full Code Here

    if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(isEnabled));

    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        final SystemTray tray = SystemTray.getSystemTray();

        moduleData.addValue(KEY_TRAYICON_ENABLED, isEnabled);
        isTrayIconEnabled = isEnabled;

        if (isEnabled) {
          if (isModuleEnabled && !HelperArray.contains(tray.getTrayIcons(), trayIcon)) {
            createLayout();

            try {
              tray.add(trayIcon);
            } catch (AWTException ex) {
              log.error("TrayIcon could not be added", ex); //$NON-NLS-1$
            }
          }
        } else {
          tray.remove(trayIcon);
        }
      }

    });
View Full Code Here

    MenuItem exitItem = new MenuItem("Exit");
    popup.add(openItem);
    popup.add(exitItem);

    final TrayIcon trayIcon = new TrayIcon(IconHelper.getProductLogoImage(), "double click here to open Dot Project Client", popup);
    final SystemTray tray = SystemTray.getSystemTray();
    trayIcon.setImageAutoSize(true);

    trayIcon.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        frm.setVisible(true);
        frm.setExtendedState(JFrame.MAXIMIZED_BOTH);
        tray.remove(trayIcon);
      }
    });
    ActionListener exitListener = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("Exiting...");
        tray.remove(trayIcon);
        System.exit(0);
      }
    };
    exitItem.addActionListener(exitListener);
    ActionListener openListener = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        frm.setVisible(true);
        frm.setExtendedState(JFrame.MAXIMIZED_BOTH);
        tray.remove(trayIcon);
      }
    };
    openItem.addActionListener(openListener);
   
    frm.addWindowListener(new WindowAdapter() {
      @Override
      public void windowIconified(WindowEvent e) {

        try {
          tray.add(trayIcon);
          frm.setVisible(false);
          trayIcon.displayMessage("Dot Project", "You can access Dot Project by double clicking this icon", TrayIcon.MessageType.INFO);
        } catch (AWTException ex) {
          System.err.println("TrayIcon could not be added.");
        }
View Full Code Here

      }
    });
   
    //TrayIcon
    if (SystemTray.isSupported()) {
      SystemTray tray = SystemTray.getSystemTray();
      trayIcon.setImageAutoSize(true);
     
      trayIcon.addActionListener(new ActionListener() {
       
        @Override
        public void actionPerformed(ActionEvent e) {
          if(mainFrame.getState() == Frame.ICONIFIED)
            mainFrame.setState(Frame.NORMAL);
          if(mainFrame.isVisible() == false)
            mainFrame.setVisible(true);
          mainFrame.toFront();
        }
       
      });
     
      //TrayPopupMenu Actions
      MenuItem show = new MenuItem("AlMaGe - Gehaltsabrechnung");
      show.addActionListener(new ActionListener() {
       
        @Override
        public void actionPerformed(ActionEvent e) {
          if(mainFrame.getState() == Frame.ICONIFIED)
            mainFrame.setState(Frame.NORMAL);
          if(mainFrame.isVisible() == false)
            mainFrame.setVisible(true);
          mainFrame.toFront();           
        }
      });

      MenuItem exit = new MenuItem("Programm beenden");
      exit.addActionListener(new ActionListener() {
       
        @Override
        public void actionPerformed(ActionEvent e) {
          if(JOptionPane
              .showOptionDialog(
                  mainFrame,
                  "<html>M�chten Sie das Programm wirklich beenden?</html>",   
                  "Programm beenden",
                  JOptionPane.YES_NO_CANCEL_OPTION,
                  JOptionPane.QUESTION_MESSAGE,
                  null, null, null) == 0){
            if(SystemTray.isSupported()){
              SystemTray.getSystemTray().remove(trayIcon);
            }
            System.exit(0);
          }
        }
      });

     
      trayPopMenu.add(show);
      trayPopMenu.addSeparator();
      trayPopMenu.add(exit);
     
      trayIcon.setPopupMenu(trayPopMenu);
     
      tray.add(trayIcon);
    }
   
    //Window Preferences
    mainFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(GehaltTreeTable.class.getResource("/images/icons/32X32/tray.png")));
    mainFrame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
View Full Code Here

                //-- remove trayicon from system tray --//
                this.removeSystemTray();
            }
            //-- add trayicon to system tray --//
            try {
                final SystemTray tray = SystemTray.getSystemTray();
                tray.add(_trayicon);
            } catch (Exception ex) {
            }
        }
    }
View Full Code Here

    }

    private void removeSystemTray() {
        //-- remove trayicon from system tray --//
        try {
            final SystemTray tray = SystemTray.getSystemTray();
            tray.remove(_trayicon);
        } catch (Exception ex) {
            // nothing to do
        }
    }
View Full Code Here

  public void attachServe(Method stop, String[] contextPath) {
    s = stop;
    if (SystemTray.isSupported() == false)
      return;
    SystemTray st = SystemTray.getSystemTray();
    PopupMenu popup = new PopupMenu();
    popup.setFont(new Font("Arial", Font.PLAIN, 12));
    //System.err.printf("%s%n", Arrays.toString(java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() .getAvailableFontFamilyNames()));
    MenuItem mi;
    if (Desktop.isDesktopSupported()) {
      for (String cp : contextPath) {
        popup.add(mi = new MenuItem(getResource("label_open") + cp));
        mi.setActionCommand("!" + cp);
        mi.addActionListener(this);
      }
    }
    popup.addSeparator();
    popup.add(mi = new MenuItem(getResource("label_stop")));
    mi.setActionCommand("stop");
    mi.addActionListener(this);
    popup.add(mi = new MenuItem(getResource("label_exit")));
    mi.setActionCommand("exit");
    mi.addActionListener(this);
    //java.net.URL u;
    // TODO icon can be customizable
    ti = new TrayIcon(Toolkit.getDefaultToolkit().getImage(
        getClass().getClassLoader().getResource("rogatkin/resource/tjws.gif")), "TJWS"+getResource("title_control_panel"), popup);
    //javax.swing.JOptionPane.showMessageDialog(null, String.format("Created sys tray icon with image%s%n",u));
    ti.setImageAutoSize(true);

    try {
      st.add(ti);
    } catch (AWTException e) {

    }
    new Timer("Splash closer", true).schedule(new TimerTask() {
      @Override
View Full Code Here

    }
  }
 
  public SysTray(final MainFrame mainFrame)
  {
    final SystemTray tray = SystemTray.getSystemTray();
    final JPopupMenu popup = new JPopupMenu();
    ImageIcon icon = new ImageIcon(
            MainFrame.class.getResource("/images/flag-16.png"));
    final TrayIcon trayIcon = new TrayIcon(icon.getImage(),
            Constants.PROJECT_NAME);
   
    trayIcon.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        restoreFrame(mainFrame);
      }
    });
    trayIcon.addMouseListener(new MouseAdapter()
    {
      public void mouseReleased(MouseEvent e)
      {
        if (e.isPopupTrigger())
        {
          // popup.
          popup.setLocation(e.getX(), e.getY());
          popup.setInvoker(popup);
          popup.setVisible(true);
        }
      }
    });
   
    JMenuItem item = new JMenuItem("Restore", new ImageIcon(
            MainFrame.class.getResource("/images/flag-16.png")));
    item.setFont(new Font(null, Font.BOLD, 12));
    item.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        restoreFrame(mainFrame);
      }
    });
    popup.add(item);
   
    final JMenu servicePop = new JMenu("Services");
    final List<Pair<JMenuItem, String>> serviceMemus = new LinkedList<Pair<JMenuItem, String>>();
    String[] all = new String[] { "GAE", "C4", "SPAC" };
    for (int i = 0; i < all.length; i++)
    {
      final String handlerName = all[i];
      final JMenuItem serviceItem = new JMenuItem(all[i]);
      serviceItem.setFont(new Font(null, Font.BOLD, 12));
      serviceItem.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          String choice = handlerName;
          if (handlerName.equalsIgnoreCase("SPAC"))
          {
            choice = "Auto";
            SPAC.spacEnbale = true;
          }else{
            SPAC.spacEnbale = false;
          }
          SnovaConfiguration.getInstance().setProxyService(choice);
          SnovaConfiguration.getInstance().save();
          updateProxyServiceMenus(serviceMemus);
        }
      });
      serviceMemus.add(new Pair<JMenuItem, String>(serviceItem,
              handlerName));
      updateProxyServiceMenus(serviceMemus);
      servicePop.add(serviceItem);
    }
    popup.add(servicePop);
    // item = new MenuItem("View Log");
    // item.setFont(new Font(null, Font.BOLD, 12));
    // item.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // try {
    // Desktop.getDesktop().browse(AppData.getLogHome().toURI());
    // } catch (IOException ex) {
    // Logger.getLogger(SysTray.class.getName()).log(Level.SEVERE, null,
    // ex);
    // }
    // }
    // });
    // popup.add(item);
   
    item = new JMenuItem("Exit", new ImageIcon(
            MainFrame.class.getResource("/images/exit.png")));
   
    item.setFont(new Font(null, Font.BOLD, 12));
    item.addActionListener(new ActionListener()
    {
     
      public void actionPerformed(ActionEvent e)
      {
        System.exit(1);
      }
    });
    popup.add(item);
    try
    {
      tray.add(trayIcon);
    }
    catch (Exception e)
    {
      // TODO: handle exception
    }
View Full Code Here

 
  private void createTrayIcon() {
    if (log.isTraceEnabled()) log.trace(HelperLog.methodStart());

    if (SystemTray.isSupported()) {
      final SystemTray tray = SystemTray.getSystemTray();

      try {
        tray.add(trayIcon);
      } catch (AWTException ex) {
        log.error("TrayIcon could not be added", ex); //$NON-NLS-1$
        controller.exit(61);
      }
    } else {
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.