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

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

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

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

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

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

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

    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tray.remove(trayIcon);
            System.exit(0);
          }
        });
  }
Пример #2
0
 @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 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();
  }
 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);
     }
   }
 }
Пример #5
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);
    }
  }
  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
  /** 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 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);
  }