Exemplo n.º 1
0
  protected PopupMenu getNetTunnelMenu(NetTunnel tunnel) {
    PopupMenu menu = new PopupMenu();
    PopupMenuListener pml = new NetTunnelPopupListener(tunnel, controller);

    String[] items = {
      "Track roadusers arrived",
      "Track trip waiting time",
      "Track waiting (receive) queue",
      "Track send queue"
    };
    MenuItem item;

    for (int i = 0; i < items.length; i++) {
      item = new MenuItem(items[i]);
      item.addActionListener(pml);
      menu.add(item);
    }

    menu.add(new MenuItem("-"));

    item = new MenuItem("Properties...", new MenuShortcut(KeyEvent.VK_ENTER));
    item.addActionListener(pml);
    menu.add(item);

    return menu;
  }
Exemplo n.º 2
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);
          }
        });
  }
Exemplo n.º 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();
    }
  }
Exemplo n.º 4
0
private void MenuPopup (MouseEvent ev, CGNode node)
    {
	if (!node.IsConcept())
	    return;

	String menuname = (String)menumap.get (node.GetType(true));
	if (menuname == null)
	    return;
	Hashtable templates = (Hashtable)menus.get (menuname);
	if (templates == null)
	    return;

	if( popup != null )
	  remove( popup );

	popup = new PopupMenu( menuname );
	
        Enumeration e = templates.keys();
        while (e.hasMoreElements()) {
            String key = (String)e.nextElement();
	    MenuItem mi = new MenuItem( key );
	    mi.setActionCommand( key );
	    mi.addActionListener( this );
	    popup.add( mi );
        }
        curnode = node;

	this.add( popup );

	popup.show( this, ev.getX(), ev.getY() );
    }
Exemplo n.º 5
0
    /** 初始化 1 设置页面 2 创建控件 3 页面添加控件 */
    void init() {
      // 布局
      this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
      this.setBackground(Color.LIGHT_GRAY);

      // 菜单按键
      bt0_HomePanel = new Button("主控制");
      bt1_SettingPanel = new Button("设置");
      bt2_DrawwingPanel = new Button("绘图");
      bt3_InternetPanel = new Button("网路");
      bt4_OtherPanel = new Button("其他");

      // 给bt4添加菜单,其他功能用弹出菜单
      popupmenu = new PopupMenu("popupmenu");
      mi_0 = new MenuItem("其他功能1");
      mi_1 = new MenuItem("其他功能2");
      mi_2 = new MenuItem("其他功能3");
      popupmenu.add(mi_0);
      popupmenu.add(mi_1);
      popupmenu.add(mi_2);
      bt4_OtherPanel.add(popupmenu);

      // 添加到Panel菜单条
      this.add(bt0_HomePanel);
      this.add(bt1_SettingPanel);
      this.add(bt2_DrawwingPanel);
      this.add(bt3_InternetPanel);
      this.add(bt4_OtherPanel);
    }
Exemplo n.º 6
0
 @PostConstruct
 public void createMenuItems() {
   popupMenu.add(menuItem("Options", injector.getInstance(ShowOptions.class)));
   pluginsMenu.addTo(popupMenu);
   popupMenu.add(menuItem("About", injector.getInstance(ShowAboutWindow.class)));
   popupMenu.addSeparator();
   popupMenu.add(menuItem("Close", new Exit()));
 }
Exemplo n.º 7
0
  protected PopupMenu getRoadMenu(Road r) {
    PopupMenu menu = new PopupMenu();
    PopupMenuListener pml = new RoadPopupListener(r, controller);

    MenuItem item = new MenuItem("Properties...", new MenuShortcut(KeyEvent.VK_ENTER));
    item.addActionListener(pml);
    menu.add(item);

    return menu;
  }
Exemplo n.º 8
0
  protected PopupMenu getDrivelaneMenu(Drivelane l) {
    PopupMenu menu = new PopupMenu();
    PopupMenuListener pml = new LanePopupListener(l, controller);

    MenuItem item = new MenuItem("Properties...", new MenuShortcut(KeyEvent.VK_ENTER));
    item.addActionListener(pml);
    menu.add(item);

    return menu;
  }
  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();
  }
Exemplo n.º 10
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();
  }
Exemplo n.º 11
0
  public WPopupMenuPeer(PopupMenu target) {
    this.target = target;
    MenuContainer parent = null;
    boolean isTrayIconPopup = false;
    isTrayIconPopup = AWTAccessor.getPopupMenuAccessor().isTrayIconPopup(target);
    if (isTrayIconPopup) {
      parent = AWTAccessor.getMenuComponentAccessor().getParent(target);
    } else {
      parent = target.getParent();
    }

    if (parent instanceof Component) {
      WComponentPeer parentPeer = (WComponentPeer) WToolkit.targetToPeer(parent);
      if (parentPeer == null) {
        // because the menu isn't a component (sigh) we first have to wait
        // for a failure to map the peer which should only happen for a
        // lightweight container, then find the actual native parent from
        // that component.
        parent = WToolkit.getNativeContainer((Component) parent);
        parentPeer = (WComponentPeer) WToolkit.targetToPeer(parent);
      }
      createMenu(parentPeer);
      // fix for 5088782: check if menu object is created successfully
      checkMenuCreation();
    } else {
      throw new IllegalArgumentException("illegal popup menu container class");
    }
  }
 protected final MenuItem createMenuItem(String _key, String _header, ActionListener _al) {
   MenuItem mi = new MenuItem(res.getString("TabbedEditor." + _key));
   mi.setActionCommand(_key);
   mi.addActionListener(_al);
   popupMenu.add(mi);
   return mi;
 }
 void installPopupMenu(String name, Program pgm) {
   Hashtable h = pgm.getMenus();
   if (h == null) return;
   String[] commands = (String[]) h.get(name);
   if (commands == null) return;
   PopupMenu popup = Menus.getPopupMenu();
   if (popup == null) return;
   popup.removeAll();
   for (int i = 0; i < commands.length; i++) {
     if (commands[i].equals("-")) popup.addSeparator();
     else {
       MenuItem mi = new MenuItem(commands[i]);
       mi.addActionListener(this);
       popup.add(mi);
     }
   }
 }
Exemplo n.º 14
0
 public void actionPerformed(ActionEvent e) {
   String command = e.getActionCommand();
   if (command == null) return;
   if (command.equals(moreLabel)) {
     Point bloc = moreButton.getLocation();
     pm.show(this, bloc.x, bloc.y);
   } else if (command.equals("Convert to RGB")) IJ.doCommand("Stack to RGB");
   else IJ.doCommand(command);
 }
Exemplo n.º 15
0
 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);
     }
   }
 }
Exemplo n.º 16
0
  private static PopupMenu createPopupMenu() throws HeadlessException {

    PopupMenu menu = new PopupMenu();

    MenuItem exit = new MenuItem("Exit");

    exit.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            System.exit(0);
          }
        });

    menu.add(exit);

    return menu;
  }
Exemplo n.º 17
0
  public Tray() {

    if (SystemTray.isSupported()) {

      EventHandler EH = new EventHandler();

      SystemTray Tray = SystemTray.getSystemTray();
      Toolkit tk = Toolkit.getDefaultToolkit();
      Image img =
          tk.getImage(
              System.getProperty("user.dir")
                  + fileSeparator
                  + "res"
                  + fileSeparator
                  + "notica.png");

      PopupMenu menu = new PopupMenu();
      MenuItem action = new MenuItem("Nueva Nota");
      MenuItem Close = new MenuItem("Cerrar");

      action.addActionListener(EH.addNote());
      Close.addActionListener(EH.Cerrar());

      menu.add(action);
      menu.add(Close);

      TrayIcon ti = new TrayIcon(img, "Knote 1.0", menu);
      ti.setImageAutoSize(true);

      try {
        Tray.add(ti);

      } catch (AWTException ex) {
        ex.printStackTrace();
        System.out.println("Error AWTException " + ex.getMessage());
      }

    } else {
      System.out.println("System Tray is not supported");
      return;
    }
  }
Exemplo n.º 18
0
  protected PopupMenu getJunctionMenu(Junction junction) {
    PopupMenu menu = new PopupMenu();
    PopupMenuListener pml = new JunctionPopupListener(junction, controller);

    String[] items = {"Track roadusers that crossed", "Track junction waiting time"};
    MenuItem item;

    for (int i = 0; i < items.length; i++) {
      item = new MenuItem(items[i]);
      item.addActionListener(pml);
      menu.add(item);
    }

    menu.add(new MenuItem("-"));

    item = new MenuItem("Properties...", new MenuShortcut(KeyEvent.VK_ENTER));
    item.addActionListener(pml);
    menu.add(item);

    return menu;
  }
Exemplo n.º 19
0
 protected void handlePopupMenu(MouseEvent e) {
   if (disablePopupMenu) return;
   if (IJ.debugMode) IJ.log("show popup: " + (e.isPopupTrigger() ? "true" : "false"));
   int x = e.getX();
   int y = e.getY();
   Roi roi = imp.getRoi();
   if (roi != null
       && (roi.getType() == Roi.POLYGON
           || roi.getType() == Roi.POLYLINE
           || roi.getType() == Roi.ANGLE)
       && roi.getState() == roi.CONSTRUCTING) {
     roi.handleMouseUp(x, y); // simulate double-click to finalize
     roi.handleMouseUp(x, y); // polygon or polyline selection
     return;
   }
   PopupMenu popup = Menus.getPopupMenu();
   if (popup != null) {
     add(popup);
     if (IJ.isMacOSX()) IJ.wait(10);
     popup.show(this, x, y);
   }
 }
Exemplo n.º 20
0
  protected PopupMenu getEdgeNodeMenu(EdgeNode edge) {
    PopupMenu menu = new PopupMenu();
    PopupMenuListener pml = new EdgeNodePopupListener(edge, controller);

    String[] items = {
      "Track waiting queue length", "Track roadusers arrived", "Track trip waiting time"
    };
    MenuItem item;

    for (int i = 0; i < items.length; i++) {
      item = new MenuItem(items[i]);
      item.addActionListener(pml);
      menu.add(item);
    }

    menu.add(new MenuItem("-"));

    item = new MenuItem("Properties...", new MenuShortcut(KeyEvent.VK_ENTER));
    item.addActionListener(pml);
    menu.add(item);

    return menu;
  }
  public TabbedEditor(org.colos.ejs.osejs.Osejs _ejs, String _type, String _header) {
    ejs = _ejs;
    defaultType = _type;
    defaultHeader = _header;
    defaultString = new String(res.getString(defaultHeader + ".Page"));

    MyActionListener al = new MyActionListener();

    popupMenu = new PopupMenu();
    customMenuItems(al); // Creates the top menu items
    // common menu items
    copyPage = createMenuItem("copyPage", defaultHeader, al);
    upPage = createMenuItem("upPage", defaultHeader, al);
    dnPage = createMenuItem("dnPage", defaultHeader, al);
    renamePage = createMenuItem("renamePage", defaultHeader, al);
    popupMenu.addSeparator();
    togglePage = createMenuItem("togglePage", defaultHeader, al);
    removePage = createMenuItem("removePage", defaultHeader, al);

    JPanel firstPanel = createFirstPanel();

    tabbedPanel = new JTabbedPane();
    tabbedPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    tabbedPanel.add(popupMenu);
    // tabbedPanel.setPreferredSize (res.getDimension("TabbedEditor.PreferredSize"));
    tabbedPanel.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mousePressed(java.awt.event.MouseEvent evt) {
            if (OSPRuntime.isPopupTrigger(evt)) // SwingUtilities.isRightMouseButton(evt))
            showMenu(evt.getComponent(), evt.getX(), evt.getY());
          }
        });
    cardLayout = new CardLayout();
    finalPanel = new JPanel(cardLayout);
    finalPanel.add(tabbedPanel, "TabbedPanel");
    finalPanel.add(firstPanel, "FirstPanel");
    setFont(finalPanel.getFont());

    Font font = InterfaceUtils.font(null, res.getString("Editor.TitleFont"));
    addPageMI.setFont(font);
    copyPage.setFont(font);
    upPage.setFont(font);
    dnPage.setFont(font);
    togglePage.setFont(font);
    removePage.setFont(font);
    renamePage.setFont(font);
    myFont = font.deriveFont(Font.PLAIN);
    showFirstPage();
  }
Exemplo n.º 22
0
  void setUpWindowsNotifications() throws AWTException {
    Image image = null;

    URL url = getClass().getResource("/SyncropIcon.png");
    // url=getClass().getClassLoader().getResource("SyncropIcon.png");
    // url=ClassLoader.getSystemResource("SyncropIcon.png");

    image =
        new ImageIcon(url, "Syncrop icon").getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH);
    logger.log(image + "");
    trayIcon = new TrayIcon(image, "Syncrop");
    help.addActionListener(this);
    about.addActionListener(this);
    update.addActionListener(this);
    exit.addActionListener(this);

    popup.add(help);
    popup.add(about);
    popup.add(update);
    popup.add(exit);

    trayIcon.setPopupMenu(popup);
    notificationsTray.add(trayIcon);
  }
Exemplo n.º 23
0
  /** Executes the specified command */
  public void run() {
    if (popup != null) {
      popup.show(popupComponent, popupX, popupY);
      popup = null;
      return;
    }

    if (cmd == null) return;

    switch (cmd.commandType) {
        // Open an UrlConnection
      case CommandInfo.COMMAND_TYPE_GET:
        try {
          cmd.commandURL.openConnection();

          BufferedReader in =
              new BufferedReader(new InputStreamReader(cmd.commandURL.openStream()));
          String strLine;
          Debug.println("Server responded:");
          while ((strLine = in.readLine()) != null) {
            Debug.println(strLine);
          }
          in.close();
        } catch (IOException e) {
        }
        break;
        // Open a port
      case CommandInfo.COMMAND_TYPE_OPEN:
        try {
          Socket sockServerConnection = new Socket(cmd.commandHost, (int) cmd.commandPort);
          BufferedReader in =
              new BufferedReader(new InputStreamReader(sockServerConnection.getInputStream()));
          String strLine;
          Debug.println("Server responded:");
          while ((strLine = in.readLine()) != null) {
            Debug.println(strLine);
          }
          in.close();
          sockServerConnection.close();
        } catch (IOException e) {
        }
        break;
    }
    cmd = null;
    Debug.println("Action terminated");
  }
Exemplo n.º 24
0
    MyMenuBar(MyFrame frame) {
      this.frame = frame;
      MyTime myTime = new MyTime();
      font = new Font(myTime.time, fontKind, fontSize);
      fontColor = Color.BLACK;

      popup = new PopupMenu();

      Menu mn = new Menu("���j���[");
      Menu mn1 = new Menu("�v���p�e�B");
      Menu mnf = new Menu("�t�H���g");
      Menu mnbg = new Menu("�w�i");

      mn1.add(mnf);
      mn1.add(mnbg);

      Menu mnfk = new Menu("�t�H���g�̎��");
      Menu mnfs = new Menu("�t�H���g�T�C�Y");
      Menu mnfc = new Menu("�����F");

      mnf.add(mnfk);
      mnf.add(mnfs);
      mnf.add(mnfc);

      MenuItem mifk1 = new MenuItem("�W��");
      MenuItem mifk2 = new MenuItem("����");
      MenuItem mifk3 = new MenuItem("�C�^���b�N");
      mnfk.add(mifk1);
      mnfk.add(mifk2);
      mnfk.add(mifk3);

      MenuItem mifs1 = new MenuItem("25");
      MenuItem mifs2 = new MenuItem("50");
      MenuItem mifs3 = new MenuItem("75");
      mnfs.add(mifs1);
      mnfs.add(mifs2);
      mnfs.add(mifs3);

      MenuItem mifc1 = new MenuItem("��");
      MenuItem mifc2 = new MenuItem("��");
      mnfc.add(mifc1);
      mnfc.add(mifc2);

      MenuItem mibg1 = new MenuItem("��");
      MenuItem mibg2 = new MenuItem("��");
      MenuItem mibg3 = new MenuItem("��");
      mnbg.add(mibg1);
      mnbg.add(mibg2);
      mnbg.add(mibg3);

      mn.add(mn1);
      popup.add(mn);

      addMouseListener((MouseListener) new MouseAdapter(this, frame));
      addMouseMotionListener((MouseMotionListener) new MouseAdapter(this.frame));

      add(popup);

      mifk1.addActionListener(new ActionAdapter());
      mifk2.addActionListener(new ActionAdapter());
      mifk3.addActionListener(new ActionAdapter());

      mifs1.addActionListener(new ActionAdapter());
      mifs2.addActionListener(new ActionAdapter());
      mifs3.addActionListener(new ActionAdapter());

      mifc1.addActionListener(new ActionAdapter());
      mifc2.addActionListener(new ActionAdapter());

      mibg1.addActionListener(new ActionAdapter());
      mibg2.addActionListener(new ActionAdapter());
      mibg3.addActionListener(new ActionAdapter());
    }
Exemplo n.º 25
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);
          }
        });
  }
Exemplo n.º 26
0
  /** 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);
    }
  }
  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();
  }
Exemplo n.º 28
0
  private void init(final SettingsUI settingsUI) throws AWTException {
    SystemTray tray = SystemTray.getSystemTray();

    PopupMenu popup = new PopupMenu();

    final CheckboxMenuItem ftpItem = new CheckboxMenuItem(" Ftp ");
    final CheckboxMenuItem picasawebItem = new CheckboxMenuItem(" Picasaweb ");

    ftpItem.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            Settings.getInstance().setPicasawebMode(false);
            Settings.getInstance().save();
            start();
          }
        });
    popup.add(ftpItem);

    picasawebItem.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            Settings.getInstance().setPicasawebMode(true);
            Settings.getInstance().save();
            start();
          }
        });
    popup.add(picasawebItem);

    checkMenuItem(picasawebItem, ftpItem, Settings.getInstance().isPicasawebMode());

    MenuItem settingsItem = new MenuItem(" Settings ");
    settingsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            settingsUI.open(mousePoint);
          }
        });
    popup.add(settingsItem);

    MenuItem exitItem = new MenuItem(" Exit ");
    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Exiting...");
            System.exit(0);
          }
        });
    popup.add(exitItem);

    URL imgURL = getClass().getClassLoader().getResource("icon.png");
    final TrayIcon trayIcon = new TrayIcon(new ImageIcon(imgURL).getImage(), "Screenshot", popup);

    trayIcon.setImageAutoSize(true);
    trayIcon.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            checkMenuItem(picasawebItem, ftpItem, Settings.getInstance().isPicasawebMode());
          }

          public void mouseClicked(MouseEvent e) {
            mousePoint = e.getPoint();
            if (e.getButton() == BUTTON1) {
              start();
            }
          }
        });

    tray.add(trayIcon);
  }
Exemplo n.º 29
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();
    }
  }
Exemplo n.º 30
0
  /** @throws AWTException */
  public SysTray() {

    if (SystemTray.isSupported()) {
      LOG.fine("O sistema possui suporte a ícone de bandeja.");

      SystemTray sys = SystemTray.getSystemTray();

      // cria o menu popup
      PopupMenu popup = new PopupMenu();

      MenuItem miExibe = new MenuItem("Exibir Painel");
      miExibe.setActionCommand("exibir");
      miExibe.addActionListener(this);
      popup.add(miExibe);

      popup.addSeparator();

      MenuItem miConf = new MenuItem("Configurar Serviços");
      miConf.setActionCommand("configurar");
      miConf.addActionListener(this);
      popup.add(miConf);

      MenuItem miConfLay = new MenuItem("Configurar Layout");
      miConfLay.setActionCommand("layout");
      miConfLay.addActionListener(this);
      popup.add(miConfLay);

      popup.addSeparator();

      MenuItem miSobre = new MenuItem("Sobre");
      miSobre.setActionCommand("sobre");
      miSobre.addActionListener(this);
      popup.add(miSobre);

      popup.addSeparator();

      MenuItem miSair = new MenuItem("Sair");
      miSair.setActionCommand("sair");
      miSair.addActionListener(this);
      popup.add(miSair);

      // constroi o system tray
      TrayIcon trayIcon = new TrayIcon(ImagesTable.SGA_ICON.getImage(), "Painel SGA", popup);

      // Ajusta ao tamanho do respectivo Sistema Operacional automaticamente
      trayIcon.setImageAutoSize(true);

      // adiciona imagem do system tray
      try {
        sys.add(trayIcon);
        LOG.fine("Ícone de bandeja exibido com sucesso.");
      } catch (AWTException e) {
        Mensagem.showMensagem(
            "Falha ao adicionar o Ícone na bandeja.\nDetalhe: " + e.getMessage(), "Erro", 0);
        System.exit(1);
      }
    } else {
      Mensagem.showMensagem("Seu sistema não suporta Ícone de bandeja.", "Erro", 0);
      System.exit(1);
    }
  }