示例#1
0
  private static void createAndShowGUI() {
    // Check the SystemTray support
    if (!SystemTray.isSupported()) {
      System.out.println("SystemTray is not supported");
      return;
    }
    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon = new TrayIcon(createImage("logo.gif", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    MenuItem aboutItem = new MenuItem("About");
    MenuItem exitItem = new MenuItem("Exit");

    // Add components to popup menu
    popup.add(aboutItem);
    popup.addSeparator();
    popup.add(exitItem);

    trayIcon.setPopupMenu(popup);
    trayIcon.setImageAutoSize(true);
    trayIcon.setToolTip("Geomar Wetterdaten");

    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      System.out.println("TrayIcon could not be added.");
      return;
    }

    trayIcon.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray");
          }
        });

    aboutItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                null,
                "Windgeschwindigkeit: "
                    + weather.getWindspeed()
                    + "m/s\n"
                    + "Windrichtung: "
                    + weather.getDirection()
                    + "° "
                    + weather.calcDir(weather.getDirection()));
          }
        });

    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tray.remove(trayIcon);
            System.exit(0);
          }
        });
  }
示例#2
0
文件: MacTray.java 项目: ufoe/desktop
  private void initIcon() throws InitializationException {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      throw new InitializationException("Unable to set look and feel for tray icon", e);
    }

    tray = SystemTray.getSystemTray();
    File defaultIconFile =
        new File(
            config.getResDir()
                + File.separator
                + Constants.TRAY_DIRNAME
                + File.separator
                + Constants.TRAY_FILENAME_DEFAULT);

    Image image = Toolkit.getDefaultToolkit().getImage(defaultIconFile.getAbsolutePath());

    icon = new TrayIcon(image, "Stacksync", menu);
    icon.setImageAutoSize(true);

    try {
      tray.add(icon);
    } catch (AWTException e) {
      throw new InitializationException("Unable to add tray icon.", e);
    }
  }
示例#3
0
  private MainPanel(final JFrame frame) {
    super();
    add(check);
    setPreferredSize(new Dimension(320, 240));

    if (!SystemTray.isSupported()) {
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      return;
    }
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowIconified(WindowEvent e) {
            if (check.isSelected()) {
              e.getWindow().dispose();
            }
          }
        });
    // or
    // frame.addWindowStateListener(new WindowStateListener() {
    //    @Override public void windowStateChanged(WindowEvent e) {
    //        if (check.isSelected() && e.getNewState() == Frame.ICONIFIED) {
    //            e.getWindow().dispose();
    //        }
    //    }
    // });

    final SystemTray tray = SystemTray.getSystemTray();
    Dimension d = tray.getTrayIconSize();
    BufferedImage image = makeBufferedImage(new StarIcon(), d.width, d.height);
    final PopupMenu popup = new PopupMenu();
    final TrayIcon icon = new TrayIcon(image, "TRAY", popup);

    MenuItem item1 = new MenuItem("OPEN");
    item1.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            frame.setVisible(true);
          }
        });
    MenuItem item2 = new MenuItem("EXIT");
    item2.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            tray.remove(icon);
            frame.dispose();
            // frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
          }
        });
    popup.add(item1);
    popup.add(item2);

    try {
      tray.add(icon);
    } catch (AWTException e) {
      e.printStackTrace();
    }
  }
  public void init() {
    final TrayIcon trayIcon;

    if (!SystemTray.isSupported()) {
      System.err.println("SystemTray is not supported");
      return;
    }

    SystemTray tray = SystemTray.getSystemTray();

    Image image =
        new ImageIcon(getClass().getResource("/threaded/ThreadedEshoServer/db_settings_32.png"))
            .getImage();

    // ‘ормирование меню
    PopupMenu popup = new PopupMenu();
    MenuItem exitItem = new MenuItem("Exit");
    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    popup.add(exitItem);

    trayIcon = new TrayIcon(image, "My server", popup);
    trayIcon.setImageAutoSize(true);
    trayIcon.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            trayIcon.displayMessage(
                "My server", "—ообщение по дабл клику", TrayIcon.MessageType.INFO);
          }
        });

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

    Timer timer =
        new Timer(
            10000,
            new ActionListener() {

              @Override
              public void actionPerformed(ActionEvent e) {
                // trayIcon.displayMessage("Your messages:",
                // "я вывел это сообщение", TrayIcon.MessageType.INFO);
              }
            });
    timer.start();
  }
示例#5
0
文件: Tray.java 项目: Tyf0n/musique
  public void install() {
    try {
      if (trayIcon == null && SystemTray.isSupported()) {
        SystemTray systemTray = SystemTray.getSystemTray();
        Dimension size = systemTray.getTrayIconSize();
        trayIcon = createTrayIcon(size);
        systemTray.add(trayIcon);

        JPopupMenu popup = new JPopupMenu();
        trayIcon.setJPopupMenu(popup);
        createPopup(popup);
      }
    } catch (AWTException e) {
      e.printStackTrace();
    }
  }
示例#6
0
  Timed() throws AWTException {
    // super("Trial by fire");
    setLayout(new FlowLayout());

    label.setFont(
        new Font(
            label.getFont().getName(), label.getFont().getStyle(), label.getFont().getSize() + 6));
    Container content = getContentPane();
    content.add(label, JLabel.CENTER);
    addMouseMotionListener(this);
    addMouseListener(this);

    javax.swing.Timer t = new javax.swing.Timer(1000, this);
    setUndecorated(true);
    com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.6f);

    // system tray
    mItem1.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    popup.add(mItem1);
    systray.add(tray);
    tray.setImageAutoSize(true);
    t.start();
  }
 public void setTray() {
   if (SystemTray.isSupported()) {
     Image icon =
         Toolkit.getDefaultToolkit().getImage("C:/.hack3rClient/sprites/cursors/icon.png");
     trayIcon = new TrayIcon(icon, "Vestige-x");
     trayIcon.setImageAutoSize(true);
     try {
       SystemTray tray = SystemTray.getSystemTray();
       tray.add(trayIcon);
       trayIcon.displayMessage(
           "Vestige-x", "Vestige-x has been launched!", TrayIcon.MessageType.INFO);
       PopupMenu menu = new PopupMenu();
       final MenuItem minimizeItem = new MenuItem("Hide Vestige-x");
       MenuItem BLANK = new MenuItem("-");
       MenuItem exitItem = new MenuItem("Quit");
       menu.add(minimizeItem);
       menu.add(BLANK);
       menu.add(exitItem);
       trayIcon.setPopupMenu(menu);
       ActionListener minimizeListener =
           new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               if (frame.isVisible()) {
                 frame.setVisible(false);
                 minimizeItem.setLabel("Show 1# Vestige-x.");
               } else {
                 frame.setVisible(true);
                 minimizeItem.setLabel("Hide 1# Vestige-x.");
               }
             }
           };
       minimizeItem.addActionListener(minimizeListener);
       ActionListener exitListener =
           new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               System.exit(0);
             }
           };
       exitItem.addActionListener(exitListener);
     } catch (AWTException e) {
       System.err.println(e);
     }
   }
 }
  private void setTrayIcon(Stage primaryStage)
      throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException,
          IllegalAccessException {

    if (!SystemTray.isSupported()) {
      return;
    }

    SystemTray sTray = SystemTray.getSystemTray();
    primaryStage.setOnCloseRequest(arg0 -> primaryStage.hide());
    JPopupMenu popup = buildSystemTrayJPopupMenu(primaryStage);
    URL url = System.class.getResource("/logo-invert_small.png");
    Image img = Toolkit.getDefaultToolkit().getImage(url);
    TrayIcon icon = new TrayIcon(img, "Qabel");

    icon.setImageAutoSize(true);
    trayIconListener(popup, icon);

    try {
      sTray.add(icon);
    } catch (AWTException e) {
      logger.error("failed to add tray icon: " + e.getMessage(), e);
    }
  }
示例#9
0
  public void restartApplication() {

    try {

      final String javaBin =
          System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaw";
      final File currentJar =
          new File(network.class.getProtectionDomain().getCodeSource().getLocation().toURI());

      System.out.println("javaBin " + javaBin);
      System.out.println("currentJar " + currentJar);
      System.out.println("currentJar.getPath() " + currentJar.getPath());

      /* is it a jar file? */
      // if(!currentJar.getName().endsWith(".jar")){return;}

      try {

        // xmining = 0;
        // systemx.shutdown();

      } catch (Exception e) {
        e.printStackTrace();
      }

      /* Build command: java -jar application.jar */
      final ArrayList<String> command = new ArrayList<String>();
      command.add(javaBin);
      command.add("-jar");
      command.add("-Xms256m");
      command.add("-Xmx1024m");
      command.add(currentJar.getPath());

      final ProcessBuilder builder = new ProcessBuilder(command);
      builder.start();

      // try{Thread.sleep(10000);} catch (InterruptedException e){}

      // close and exit
      SystemTray.getSystemTray().remove(network.icon);
      System.exit(0);

    } // try
    catch (Exception e) {
      JOptionPane.showMessageDialog(null, e.getCause());
    }
  } // ******************************
示例#10
0
  public void setTray() {
    boolean showTip = false;
    if (tray == null) {
      showTip = true;
      final Image image = Configuration.getImage(Configuration.Paths.Resources.ICON);
      tray = new TrayIcon(image, Configuration.NAME, null);
      tray.setImageAutoSize(true);
      tray.addMouseListener(
          new MouseListener() {
            public void mouseClicked(MouseEvent arg0) {}

            public void mouseEntered(MouseEvent arg0) {}

            public void mouseExited(MouseEvent arg0) {}

            public void mouseReleased(MouseEvent arg0) {}

            public void mousePressed(MouseEvent arg0) {
              SystemTray.getSystemTray().remove(tray);
              setVisible(true);
              lessCpu(false);
            }
          });
    }
    try {
      SystemTray.getSystemTray().add(tray);
      if (showTip) {
        tray.displayMessage(
            Configuration.NAME + " Hidden",
            "Bots are still running in the background.\nClick this icon to restore the window.",
            MessageType.INFO);
      }
    } catch (Exception ignored) {
      log.warning("Unable to hide window");
    }
    setVisible(false);
    lessCpu(true);
  }
示例#11
0
文件: Tray.java 项目: Tyf0n/musique
 public void uninstall() {
   if (SystemTray.isSupported()) {
     SystemTray.getSystemTray().remove(trayIcon);
     trayIcon = null;
   }
 }
示例#12
0
  public static void main(String[] args) {
    System.out.println(ResourceUsage.getStatus());
    final String ipAddress = Util.getIp();
    final Thread listener;
    final SocketListener socketListener = new SocketListener();
    listener = new Thread(socketListener);
    if (!SystemTray.isSupported()) {
      System.err.println("System tray is not supported.");
      return;
    }

    SystemTray systemTray = SystemTray.getSystemTray();

    Image image =
        Toolkit.getDefaultToolkit().getImage(ServiceDriver.class.getResource("pause.png"));

    final TrayIcon trayIcon = new TrayIcon(image);

    final PopupMenu trayPopupMenu = new PopupMenu();

    MenuItem startService = new MenuItem("Start Service");
    startService.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                null, "Service Started", "Surrogate Service", JOptionPane.INFORMATION_MESSAGE);
            try {
              listener.start();
              Image image =
                  Toolkit.getDefaultToolkit()
                      .getImage(ServiceDriver.class.getResource("cyber.gif"));
              trayIcon.setImage(image);
            } catch (Exception err) {
              Image image =
                  Toolkit.getDefaultToolkit()
                      .getImage(ServiceDriver.class.getResource("cyber.gif"));
              trayIcon.setImage(image);
              socketListener.resume();
            }
          }
        });
    trayPopupMenu.add(startService);

    MenuItem action = new MenuItem("Stop Service");
    action.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                null, "Service Stopped", "Surrogate Service", JOptionPane.INFORMATION_MESSAGE);
            try {
              socketListener.pause();
              Image image =
                  Toolkit.getDefaultToolkit()
                      .getImage(ServiceDriver.class.getResource("pause.png"));
              trayIcon.setImage(image);
            } catch (Exception e1) {
              System.err.println("Service has not stared yet");
            }
          }
        });
    trayPopupMenu.add(action);

    MenuItem close = new MenuItem("Close");
    close.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    trayPopupMenu.add(close);

    trayIcon.setPopupMenu(trayPopupMenu);

    trayIcon.addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseMoved(MouseEvent e) {
            trayIcon.setToolTip(Util.getStatus(ipAddress));
          }
        });
    trayIcon.setImageAutoSize(true);

    try {
      systemTray.add(trayIcon);
    } catch (AWTException awtException) {
      awtException.printStackTrace();
    }
  }
示例#13
0
  private static void createAndShowGUI() {
    // Check the SystemTray support
    if (!SystemTray.isSupported()) {
      System.out.println("SystemTray is not supported");
      return;
    }
    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon =
        new TrayIcon(ImageHelper.loadImage("/images/splash.jpg", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    MenuItem aboutItem = new MenuItem("About");
    CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
    CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
    Menu displayMenu = new Menu("Display");
    MenuItem errorItem = new MenuItem("Error");
    MenuItem warningItem = new MenuItem("Warning");
    MenuItem infoItem = new MenuItem("Info");
    MenuItem noneItem = new MenuItem("None");
    MenuItem exitItem = new MenuItem("Exit");

    // Add components to popup menu
    popup.add(aboutItem);
    popup.addSeparator();
    popup.add(cb1);
    popup.add(cb2);
    popup.addSeparator();
    popup.add(displayMenu);
    displayMenu.add(errorItem);
    displayMenu.add(warningItem);
    displayMenu.add(infoItem);
    displayMenu.add(noneItem);
    popup.add(exitItem);

    trayIcon.setPopupMenu(popup);

    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      System.out.println("TrayIcon could not be added.");
      return;
    }

    trayIcon.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray");
          }
        });

    aboutItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "This dialog box is run from the About menu item");
          }
        });

    cb1.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            int cb1Id = e.getStateChange();
            if (cb1Id == ItemEvent.SELECTED) {
              trayIcon.setImageAutoSize(true);
            } else {
              trayIcon.setImageAutoSize(false);
            }
          }
        });

    cb2.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            int cb2Id = e.getStateChange();
            if (cb2Id == ItemEvent.SELECTED) {
              trayIcon.setToolTip("Sun TrayIcon");
            } else {
              trayIcon.setToolTip(null);
            }
          }
        });

    ActionListener listener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            MenuItem item = (MenuItem) e.getSource();
            // TrayIcon.MessageType type = null;
            System.out.println(item.getLabel());
            if ("Error".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.ERROR;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an error message", TrayIcon.MessageType.ERROR);

            } else if ("Warning".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.WARNING;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is a warning message", TrayIcon.MessageType.WARNING);

            } else if ("Info".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.INFO;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO);

            } else if ("None".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.NONE;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an ordinary message", TrayIcon.MessageType.NONE);
            }
          }
        };

    errorItem.addActionListener(listener);
    warningItem.addActionListener(listener);
    infoItem.addActionListener(listener);
    noneItem.addActionListener(listener);

    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tray.remove(trayIcon);
            System.exit(0);
          }
        });
  }
示例#14
0
/**
 * Small widget clock to be on top right side of screen displays time and other essential
 * notifications always on top
 *
 * @author Pratik Anand <*****@*****.**>
 */
public final class Timed extends JDialog
    implements ActionListener, MouseMotionListener, MouseListener {

  String date;
  JButton jb = new JButton("Ninja");
  JLabel label = new JLabel(" " + new Date());
  DateFormat df = new SimpleDateFormat("HH:mm:ss");

  Point p_initial = null;

  // transparency
  /*
  DateFormat df=new  SimpleDateFormat("MM/dd/yyyy");
  Date today=Calendar.getInstance().getTime();
  date=df.format("today");
   */

  // system tray
  SystemTray systray = SystemTray.getSystemTray();
  final PopupMenu popup = new PopupMenu();
  final MenuItem mItem1 = new MenuItem("Exit");

  URL myurl = this.getClass().getResource("/images/wlan.png");
  Toolkit tk = this.getToolkit();
  Image image = tk.getImage(myurl);

  // Image image = Toolkit.getDefaultToolkit().getImage("src/images/wlan.png");
  TrayIcon tray = new TrayIcon(image, "Timed", popup);

  Timed() throws AWTException {
    // super("Trial by fire");
    setLayout(new FlowLayout());

    label.setFont(
        new Font(
            label.getFont().getName(), label.getFont().getStyle(), label.getFont().getSize() + 6));
    Container content = getContentPane();
    content.add(label, JLabel.CENTER);
    addMouseMotionListener(this);
    addMouseListener(this);

    javax.swing.Timer t = new javax.swing.Timer(1000, this);
    setUndecorated(true);
    com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.6f);

    // system tray
    mItem1.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    popup.add(mItem1);
    systray.add(tray);
    tray.setImageAutoSize(true);
    t.start();
  }

  @Override
  public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    // date = new Date().toString();
    // System.out.println(df.format(new Date()));

    date = df.format(new Date());

    label.setText(date);
    repaint();
  }

  @Override
  public void mouseDragged(MouseEvent e) {
    // TODO Auto-generated method stub
    Point p = e.getLocationOnScreen(); // global location of mouse pointer
    this.setLocation(new Point(-p_initial.x + p.x, -p_initial.y + p.y));
  }

  @Override
  public void mouseMoved(MouseEvent e) {
    // TODO Auto-generated method stub
  }

  public static void main(String args[]) throws AWTException {

    Timed tm = new Timed();
    tm.setSize(125, 23);
    // tm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // tm.setUndecorated(true);
    // tm.getRootPane().putClientProperty("Window.alpha", new Float(0.8f)); works on Mac OS X only
    tm.setAlwaysOnTop(true);
    tm.setVisible(true);
  }

  @Override
  public void mouseClicked(MouseEvent e) {
    // TODO Auto-generated method stub
  }

  @Override
  public void mouseEntered(MouseEvent e) {
    // TODO Auto-generated method stub
  }

  @Override
  public void mouseExited(MouseEvent e) {
    // TODO Auto-generated method stub
  }

  @Override
  public void mousePressed(MouseEvent e) {
    // TODO Auto-generated method stub
    p_initial = e.getPoint();
  }

  @Override
  public void mouseReleased(MouseEvent e) {
    // TODO Auto-generated method stub
    // this.setLocation(e.getX(), e.getY());
  }
}