コード例 #1
0
ファイル: TrayIconDemo.java プロジェクト: Invice/Wetter
  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
ファイル: FriendList.java プロジェクト: Fsig/Underground-IM
  /** Constructor. */
  public FriendList() {
    this.setIconImage(Constants.icon);
    this.setTitle("Underground IM");
    this.setSize(300, 400);
    this.setLocationRelativeTo(null);
    this.setResizable(true);
    this.setJMenuBar(menuBar.getMenuBar());

    // Friend List
    friendListData =
        new DefaultTableModel(new Object[0][0], new String[] {"Status", "Friends"}) {
          private static final long serialVersionUID = -3666163903937562582L;

          @Override
          public boolean isCellEditable(int a, int b) {
            return false;
          }
        };

    friendList = new JTable(friendListData);
    friendList.setBounds(0, 0, getWidth() - 15, getHeight() - 60);
    friendList.setFont(new Font("Arial", Font.PLAIN, 12));
    friendList.getColumnModel().getColumn(0).setCellRenderer(new ImageRenderer());

    friendListContainer =
        new JScrollPane(
            friendList,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    friendListContainer.setBounds(0, 0, getWidth() - 15, getHeight() - 90);

    // Add components
    this.add(friendListContainer);

    popupMenu = new PopupMenu(null, friendList);

    TrayIcon trayIcon = null;
    if (SystemTray.isSupported()) {
      this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      SystemTray tray = SystemTray.getSystemTray();
      Image image = Constants.iconTray;

      ActionListener listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {}
          };

      trayIcon = new TrayIcon(image, "Underground IM", popupMenu.getTrayMenu());
      trayIcon.addActionListener(listener);

      try {
        tray.add(trayIcon);
      } catch (AWTException e) {
        System.err.println(e);
      }
    } else {
      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
  }
コード例 #3
0
ファイル: FullTray.java プロジェクト: SolaKun/FYoung4j
    public void actionPerformed(ActionEvent e) {
      trayIcon.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              System.out.println("Message Clicked");
            }
          });
      trayIcon.displayMessage(title, message, messageType);
    }
コード例 #4
0
  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
ファイル: SysTray.java プロジェクト: vlpolyansky/LostFilmNews
  public static void main(String[] args) throws Exception {

    TrayIcon icon = new TrayIcon(getImage(), "This is a Java Tray Icon", createPopupMenu());

    icon.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            JOptionPane.showMessageDialog(null, "Bring Java to the Desktop app");
          }
        });

    SystemTray.getSystemTray().add(icon);

    while (true) {

      Thread.sleep(10000);

      icon.displayMessage("Warning", "Click me! =)", TrayIcon.MessageType.WARNING);
    }
  }
コード例 #6
0
  private void initTray() throws Exception {
    tray = SystemTray.getSystemTray();

    PopupMenu m = new PopupMenu();
    Font f = new Font("Tahoma", 0, 11);
    m.setFont(f);

    MenuItem mi = new MenuItem(Language.getLocalizedString(getClass(), "menuopen"));
    mi.setFont(f);
    mi.setFont(
        new Font(
            mi.getFont().getName(), mi.getFont().getStyle() | Font.BOLD, mi.getFont().getSize()));
    mi.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            openUI();
          }
        });
    m.add(mi);

    m.addSeparator();

    mi = new MenuItem(Language.getLocalizedString(getClass(), "menuunload"));
    mi.setFont(f);
    mi.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            unloadUI();
          }
        });
    m.add(mi);

    m.addSeparator();

    mi = new MenuItem(Language.getLocalizedString(getClass(), "menuexit"));
    mi.setFont(f);
    mi.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            shutdown();
          }
        });
    m.add(mi);

    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new PopupFixQueue(m));

    int[] imageSizes = {16, 24, 32, 48, 64, 128};
    for (int size : imageSizes) {
      if (size - tray.getTrayIconSize().getWidth() < 0) {
        continue;
      } else {
        ti =
            new TrayIcon(
                Toolkit.getDefaultToolkit()
                    .getImage(rl.getResource("gfx/icons/alliance" + size + ".png")),
                "Alliance",
                m);
        break;
      }
    }

    ti.setImageAutoSize(true);

    ti.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            openUI();
          }
        });

    tray.add(ti);

    ti.addActionListener(
        new ActionListener() {

          private long lastClickAt;

          @Override
          public void actionPerformed(ActionEvent e) {
            if (System.currentTimeMillis() - lastClickAt < 1000) {
              openUI();
            }
            lastClickAt = System.currentTimeMillis();
          }
        });

    // Update tooltip periodically with current transfer rates
    Thread t =
        new Thread(
            new Runnable() {

              @Override
              public void run() {
                try {
                  while (true) {
                    ti.setToolTip(
                        "Alliance v"
                            + Version.VERSION
                            + " build "
                            + Version.BUILD_NUMBER
                            + "\nDownload: "
                            + core.getNetworkManager().getBandwidthIn().getCPSHumanReadable()
                            + "\nUpload: "
                            + core.getNetworkManager().getBandwidthOut().getCPSHumanReadable()
                            + "\nOnline: "
                            + core.getFriendManager().getNFriendsConnected()
                            + "/"
                            + core.getFriendManager().getNFriends()
                            + " ("
                            + TextUtils.formatByteSize(
                                core.getFriendManager().getTotalBytesShared())
                            + ")");
                    Thread.sleep(5000);
                  }
                } catch (InterruptedException e) {
                } catch (NullPointerException e) {
                }
              }
            });
    t.setDaemon(true);
    t.start();
  }
コード例 #7
0
ファイル: ScreenSnapper.java プロジェクト: Codeusa/sleeksnap
  /** Initialize the tray menu */
  private void initializeTray() {
    // Add uploaders from the list we loaded earlier
    final PopupMenu tray = new PopupMenu();
    // Add the action menu
    tray.add(new ActionMenuItem(Language.getString("cropupload"), ScreenshotAction.CROP));
    tray.add(new ActionMenuItem(Language.getString("fullupload"), ScreenshotAction.FULL));

    if (Platform.isWindows() || Platform.isLinux()) {
      tray.add(new ActionMenuItem(Language.getString("activeupload"), ScreenshotAction.ACTIVE));
    }

    tray.addSeparator();

    tray.add(new ActionMenuItem(Language.getString("clipboardupload"), ScreenshotAction.CLIPBOARD));
    tray.add(new ActionMenuItem(Language.getString("fileupload"), ScreenshotAction.FILE));

    tray.addSeparator();

    final MenuItem settings = new MenuItem(Language.getString("options"));
    settings.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            if (!openSettings()) {
              icon.displayMessage(
                  Language.getString("error"),
                  Language.getString("optionsOpenError"),
                  TrayIcon.MessageType.ERROR);
            }
          }
        });
    tray.add(settings);

    final MenuItem exit = new MenuItem(Language.getString("exit"));
    exit.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            shutdown();
          }
        });
    tray.add(exit);

    icon =
        new TrayIcon(
            Toolkit.getDefaultToolkit().getImage(Resources.ICON),
            Application.NAME + " v" + Version.getVersionString());
    icon.setPopupMenu(tray);
    icon.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            if (lastUrl != null) {
              try {
                Util.openURL(new URL(lastUrl));
              } catch (final Exception e1) {
                showException(e1, "Unable to open URL");
              }
            }
          }
        });
    try {
      SystemTray.getSystemTray().add(icon);
    } catch (final AWTException e1) {
      this.showException(e1);
    }
  }
コード例 #8
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);
          }
        });
  }
コード例 #9
0
  private static void createAndShowGUI() {
    if (!SystemTray.isSupported()) {
      Logger.getLogger(StartAgentGUI.class.getName()).log(Level.SEVERE, "SYSTRAY_NOT_SUPPORTED");
      agent.exitProcess();
      return;
    }

    trayIcon =
        new TrayIcon(
            TrayProcess.createImage(AgentConstants.ICON16_PATH, AgentConstants.ICON_DESCRIPTION),
            AgentConstants.APP_PUBLIC_NAME);
    final SystemTray tray = SystemTray.getSystemTray();
    final AgentPopUpMenu popUpMenu = new AgentPopUpMenu(tray, trayIcon, agent, deviceService);

    MOUSE_HOOK = new JNIMouseHook(popUpMenu);
    trayIcon.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
              popUpMenu.setLocation(e.getX(), e.getY());
              popUpMenu.setInvoker(popUpMenu);
              popUpMenu.setVisible(true);
            }
          }
        });

    popUpMenu.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e instanceof MouseClickOutsideComponentEvent) {
              popUpMenu.setVisible(false);
            }
          }
        });

    popUpMenu.addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals(VISIBLE_PROPERTY)) {
              if (evt.getNewValue().equals(Boolean.TRUE)) {
                if (!MOUSE_HOOK.isIsHooked()) {
                  MOUSE_HOOK.setMouseHook();
                }
              } else if (MOUSE_HOOK.isIsHooked()) {
                MOUSE_HOOK.unsetMouseHook();
              }
            }
          }
        });

    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      Logger.getLogger(StartAgentGUI.class.getName()).log(Level.SEVERE, "TRAY_ICON_LOAD_ERROR", e);
      return;
    }
    trayIcon.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                null,
                LocalizedLogger.getLocalizedMessage("APPLICATION_INFO", AgentConstants.VERSION));
          }
        });
  }
コード例 #10
0
  private void init() {
    final TrayIcon trayIcon;
    if (SystemTray.isSupported()) {

      String path = System.getProperty("user.dir");
      // log.info(path);
      SystemTray tray = SystemTray.getSystemTray();

      MouseListener mouseListener =
          new MouseListener() {

            public void mouseClicked(MouseEvent e) {
              System.out.println("Tray Icon - Mouse clicked!");
            }

            public void mouseEntered(MouseEvent e) {
              System.out.println("Tray Icon - Mouse entered!");
            }

            public void mouseExited(MouseEvent e) {
              System.out.println("Tray Icon - Mouse exited!");
            }

            public void mousePressed(MouseEvent e) {
              System.out.println("Tray Icon - Mouse pressed!");
            }

            public void mouseReleased(MouseEvent e) {
              System.out.println("Tray Icon - Mouse released!");
            }
          };

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

      ActionListener testListener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              System.out.println("Just test...");
              System.exit(0);
            }
          };

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

      MenuItem defaultItem2 = new MenuItem("test");
      defaultItem.addActionListener(testListener);
      popup.add(defaultItem2);

      Image image =
          Toolkit.getDefaultToolkit()
              .getImage(this.getClass().getClassLoader().getResource("ico.gif"));
      trayIcon = new TrayIcon(image, "chimera", popup);

      ActionListener actionListener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              trayIcon.displayMessage(
                  "Action Event", "An Action Event Has Been Peformed!", TrayIcon.MessageType.INFO);
            }
          };

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

      //    Depending on which Mustang build you have, you may need to uncomment
      //    out the following code to check for an AWTException when you add
      //    an image to the system tray.

      //    try {
      try {
        tray.add(trayIcon);
      } catch (AWTException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      //    } catch (AWTException e) {
      //        System.err.println("TrayIcon could not be added.");
      //    }

      trayIcon.displayMessage("chimera", "", TrayIcon.MessageType.INFO);

    } else {
      System.err.println("System tray is currently not supported.");
    }
  }