Esempio n. 1
0
  /**
   * Shows "call via" menu allowing user to selected from multiple providers.
   *
   * @param context the android context
   * @param v the View that will contain the popup menu.
   * @param destination target callee name.
   */
  private static void showCallViaMenu(final Context context, View v, final String destination) {
    PopupMenu popup = new PopupMenu(context, v);

    Menu menu = popup.getMenu();

    Iterator<ProtocolProviderService> registeredProviders =
        AccountUtils.getRegisteredProviders().iterator();

    while (registeredProviders.hasNext()) {
      final ProtocolProviderService provider = registeredProviders.next();
      String accountAddress = provider.getAccountID().getAccountAddress();

      MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, accountAddress);

      menuItem.setOnMenuItemClickListener(
          new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
              createCall(context, destination, provider);

              return false;
            }
          });
    }

    popup.show();
  }
Esempio n. 2
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() );
    }
Esempio n. 3
0
  public void showAtts() {
    if (ds == null) return;
    if (attTable == null) {
      // global attributes
      attTable =
          new BeanTableSorted(
              AttributeBean.class, (PreferencesExt) prefs.node("AttributeBeans"), false);
      PopupMenu varPopup = new ucar.nc2.ui.widget.PopupMenu(attTable.getJTable(), "Options");
      varPopup.addAction(
          "Show Attribute",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              AttributeBean bean = (AttributeBean) attTable.getSelectedBean();
              if (bean != null) {
                infoTA.setText(bean.att.toString());
                infoTA.gotoTop();
                infoWindow.show();
              }
            }
          });
      attWindow =
          new IndependentWindow("Global Attributes", BAMutil.getImage("netcdfUI"), attTable);
      attWindow.setBounds(
          (Rectangle) prefs.getBean("AttWindowBounds", new Rectangle(300, 100, 500, 800)));
    }

    List<AttributeBean> attlist = new ArrayList<AttributeBean>();
    for (Attribute att : ds.getGlobalAttributes()) {
      attlist.add(new AttributeBean(att));
    }
    attTable.setBeans(attlist);
    attWindow.show();
  }
Esempio n. 4
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();
    }
  }
Esempio n. 5
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);
          }
        });
  }
Esempio n. 6
0
  private void showPopupMenu(View v) {
    PopupMenu popupMenu = new PopupMenu(this, v);
    popupMenu.inflate(R.menu.popupmenu_currency);

    popupMenu.setOnMenuItemClickListener(
        new PopupMenu.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
              case R.id.$:
                editTextCurrency.setText("$");
                return true;
              case R.id.€:
                editTextCurrency.setText("€");
                return true;
              case R.id.₴:
                editTextCurrency.setText("₴");
                return true;
              default:
                return false;
            }
          }
        });
    popupMenu.show();
  }
Esempio n. 7
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()));
 }
  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();
  }
  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;
 }
Esempio n. 11
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();
  }
Esempio n. 12
0
  /** 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);
    }
  }
 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);
     }
   }
 }
Esempio 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);
 }
Esempio 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);
     }
   }
 }
Esempio n. 16
0
  private void createContextMenu() {
    contextMenu = new PopupMenu();

    MenuItem mnuRefresh =
        new MenuItem(
            "Refresh",
            SlacIcons.INSTANCE.refreshIcon(),
            new Scheduler.ScheduledCommand() {
              @Override
              public void execute() {
                refreshRecords(null);
              }
            });
    contextMenu.addItem(mnuRefresh);

    contextMenu.addSeparator();

    MenuItem mnuAdd =
        new MenuItem(
            "Add",
            SlacIcons.INSTANCE.addIcon(),
            new Scheduler.ScheduledCommand() {
              @Override
              public void execute() {
                addRecord(null);
              }
            });
    contextMenu.addItem(mnuAdd);

    MenuItem mnuRemove =
        new MenuItem(
            "Remove",
            SlacIcons.INSTANCE.removeIcon(),
            new Scheduler.ScheduledCommand() {
              @Override
              public void execute() {
                removeRecord(null);
              }
            });
    contextMenu.addItem(mnuRemove);
  }
Esempio n. 17
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);
   }
 }
  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();
  }
Esempio n. 19
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");
  }
Esempio n. 20
0
  // Overridden Methods
  void showItemMenu(View v, String name, ArrayList<SimpleMenuItem> menuItems) {
    PopupMenu popupMenu = new PopupMenu(v11.this, v);
    popupMenu.getMenu().clear();

    for (int i = 0; i < menuItems.size(); i++)
      popupMenu
          .getMenu()
          .add(
              0, menuItems.get(i).getItemId(),
              0, menuItems.get(i).getTitle());

    popupMenu.getMenu().findItem(R.id.status).setVisible(syncers.get(name) != null);

    popupMenu.setOnMenuItemClickListener(v11.this);
    popupMenu.show();
  }
Esempio n. 21
0
 private void packParentMenu() {
   if (getParent() instanceof PopupMenu) {
     PopupMenu menu = (PopupMenu) getParent();
     menu.pack();
   }
 }
Esempio n. 22
0
 void addPopupItem(String s) {
   MenuItem mi = new MenuItem(s);
   mi.addActionListener(this);
   pm.add(mi);
 }
Esempio n. 23
0
    NestedTable(int level) {
      this.level = level;
      myPrefs = (PreferencesExt) prefs.node("NestedTable" + level);

      table = new BeanTableSorted(VariableBean.class, myPrefs, false);

      JTable jtable = table.getJTable();
      PopupMenu csPopup = new PopupMenu(jtable, "Options");
      csPopup.addAction(
          "Show Declaration",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showDeclaration(table, false);
            }
          });
      csPopup.addAction(
          "Show NcML",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showDeclaration(table, true);
            }
          });
      csPopup.addAction(
          "NCdump Data",
          "Dump",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              dumpData(table);
            }
          });
      if (level == 0) {
        csPopup.addAction(
            "Data Table",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                dataTable(table);
              }
            });
      }

      // get selected variable, see if its a structure
      table.addListSelectionListener(
          new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
              Variable v = getCurrentVariable(table);
              if ((v != null) && (v instanceof Structure)) {
                hideNestedTable(NestedTable.this.level + 2);
                setNestedTable(NestedTable.this.level + 1, (Structure) v);

              } else {
                hideNestedTable(NestedTable.this.level + 1);
              }
              if (eventsOK) datasetTree.setSelected(v);
            }
          });

      // layout
      if (currentComponent == null) {
        currentComponent = table;
        tablePanel.add(currentComponent, BorderLayout.CENTER);
        isShowing = true;

      } else {
        split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, currentComponent, table);
        splitPos = myPrefs.getInt("splitPos" + level, 500);
        if (splitPos > 0) split.setDividerLocation(splitPos);

        show();
      }
    }
Esempio n. 24
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();
    }
  }
 /** Shows the popup menu */
 protected void showMenu(Component comp, int x, int y) {
   if (activeEditor) popupMenu.show(comp, x, y);
 }
Esempio n. 26
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);
          }
        });
  }
Esempio n. 27
0
  private void initMenu(String initialMessage) {
    // Create
    menu = new PopupMenu();

    // Status
    itemStatus = new MenuItem(initialMessage);
    itemStatus.setEnabled(false);

    menu.add(itemStatus);

    // Profile and folders
    menu.addSeparator();

    Profile profile = config.getProfile();

    final Folder folder = profile.getFolder();
    if (folder != null && folder.isActive() && folder.getLocalFile() != null) {

      MenuItem itemFolder = new MenuItem(folder.getLocalFile().getName());

      itemFolder.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
              fireTrayEvent(
                  new TrayEvent(
                      TrayEvent.EventType.OPEN_FOLDER, folder.getLocalFile().getAbsolutePath()));
            }
          });

      menu.add(itemFolder);
    }

    menu.addSeparator();

    // Preferences
    // itemPreferences = new MenuItem("Preferencias ...");
    // itemPreferences.addActionListener(new ActionListener() {

    //    @Override
    //    public void actionPerformed(ActionEvent ae) {
    //        fireTrayEvent(new TrayEvent(TrayEvent.EventType.PREFERENCES));
    //    }
    // });

    // menu.add(itemPreferences);

    // menu.addSeparator();
    itemWebsite = new MenuItem(resourceBundle.getString("tray_stacksync_website"));
    itemWebsite.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent ae) {
            fireTrayEvent(new TrayEvent(TrayEvent.EventType.WEBSITE));
          }
        });
    menu.add(itemWebsite);

    itemWebsite2 = new MenuItem(resourceBundle.getString("tray_ast_website"));
    itemWebsite2.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent ae) {
            fireTrayEvent(new TrayEvent(TrayEvent.EventType.WEBSITE2));
          }
        });
    menu.add(itemWebsite2);

    menu.addSeparator();

    // Quit
    itemQuit = new MenuItem(resourceBundle.getString("tray_exit"));
    itemQuit.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent ae) {
            fireTrayEvent(new TrayEvent(TrayEvent.EventType.QUIT));
          }
        });

    menu.add(itemQuit);
  }