java类java.awt.PopupMenu的实例源码

WTrayIconPeer.java 文件源码 项目:openjdk-jdk7u-jdk 阅读 28 收藏 0 点赞 0 评论 0
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
ContextMenu.java 文件源码 项目:ArduBlock 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Returns the right click context menu for the specified JComponent.  If there is 
 * none, returns null.
 * @param o JComponent object seeking context menu
 * @return the right click context menu for the specified JComponent.  If there is 
 * none, returns null.
 */
public static PopupMenu getContextMenuFor(Object o) {
    if (o instanceof RenderableBlock) {
        if (((RenderableBlock) o).hasComment()) {
            if (!removeCommentMenuInit) {
                initRemoveCommentMenu();
            }
            activeComponent = o;
            return removeCommentMenu;
        } else {
            if (!addCommentMenuInit) {
                initAddCommentMenu();
            }
            activeComponent = o;
            return addCommentMenu;
        }
    } else if (o instanceof BlockCanvas) {
        if (!canvasMenuInit) {
            initCanvasMenu();
        }
        activeComponent = o;
        return canvasMenu;
    }
    return null;
}
StaveActionHandler.java 文件源码 项目:jmg 阅读 17 收藏 0 点赞 0 评论 0
StaveActionHandler(Stave stave) {
theApp = stave;

      noteContextMenu = new PopupMenu();

      editNote = new MenuItem("Edit Note");
      editNote.addActionListener(this);
      noteContextMenu.add(editNote );       

      repeatNote = new MenuItem("Repeat Note");
      repeatNote.addActionListener(this);
      noteContextMenu.add(repeatNote );         

      makeRest = new MenuItem("Change to Rest");
      makeRest.addActionListener(this);
      noteContextMenu.add(makeRest);       

      deleteNote = new MenuItem("Delete Note");
      deleteNote.addActionListener(this);
      noteContextMenu.add(deleteNote );       

      theApp.add(noteContextMenu);
  }
WTrayIconPeer.java 文件源码 项目:openjdk-icedtea7 阅读 36 收藏 0 点赞 0 评论 0
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
SysTrayIcon.java 文件源码 项目:oceano 阅读 21 收藏 0 点赞 0 评论 0
public SysTrayIcon(JDesktopAgent frame, String tooltip) {
    Translate translate = Translate.getTranslate();
    if (SystemTray.isSupported()) {
        Image image = Toolkit.getDefaultToolkit().getImage("icon.png");

        PopupMenu popup = new PopupMenu();
        popup.add(new RestoreMenuItem(frame, translate.backgroundRestore()));
        popup.addSeparator();
        popup.add(new AboutMenuItem(translate.about()));
        popup.addSeparator();
        popup.add(new ExitMenuItem(translate.exit()));

        TrayIcon trayIcon = new TrayIcon(image, tooltip, popup);
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new IconListener(frame));

        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException e) {
            new SysTrayForm(frame).setVisible(true);
        }
    } else {
        new SysTrayForm(frame).setVisible(true);
    }

}
TrayIconDefinition.java 文件源码 项目:mkRemote 阅读 20 收藏 0 点赞 0 评论 0
public TrayIcon buildTrayIcon() throws IOException {
    PopupMenu popup = new PopupMenu();
    for (MenuItemDefinition mid : menuItems) {
        if (mid instanceof SeperatorMenuItem) {
            popup.addSeparator();
        } else {
            MenuItem item = new MenuItem();
            item.setLabel(mid.getText());
            item.addActionListener(mid);
            popup.add(item);
        }
    }

    TrayIcon ti = new TrayIcon(getImage(imageName), tooltip, popup);
    ti.setImageAutoSize(true);
    return ti;
}
SubsonicController.java 文件源码 项目:madsonic-server-5.0 阅读 18 收藏 0 点赞 0 评论 0
private void createComponents() {
    PopupMenu menu = new PopupMenu();
    menu.add(createMenuItem(openAction));
    menu.add(createMenuItem(controlPanelAction));
    menu.addSeparator();
    menu.add(createMenuItem(quitAction));

    URL url = getClass().getResource("/images/madsonic-21.png");
    Image image = Toolkit.getDefaultToolkit().createImage(url);
    TrayIcon trayIcon = new TrayIcon(image, "Madsonic Music Streamer", menu);
    trayIcon.setImageAutoSize(false);

    try {
        SystemTray.getSystemTray().add(trayIcon);
    } catch (Throwable x) {
        System.err.println("Failed to add tray icon.");
    }
}
JfxTrayIcon.java 文件源码 项目:rapfx 阅读 20 收藏 0 点赞 0 评论 0
public JfxTrayIcon() {
    if (!SystemTray.isSupported()) {
        log.warn("system tray not supported!");
        this.tray = null;
    } else {
        this.tray = SystemTray.getSystemTray();
        this.menu = new PopupMenu();
        this.exit = new MenuItem("Exit");
        this.menu.add(exit);
        this.exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                hide(); // important, otherwise AWT keeps application alive!
                Platform.exit();
            }
        });
    }
}
Main.java 文件源码 项目:languagetool 阅读 21 收藏 0 点赞 0 评论 0
private PopupMenu makePopupMenu() {
  PopupMenu popup = new PopupMenu();
  ActionListener rmbListener = new TrayActionRMBListener();
  // Enable or disable embedded HTTP server:
  enableHttpServerItem = new CheckboxMenuItem(Tools.getLabel(messages.getString("tray_menu_enable_server")));
  enableHttpServerItem.setState(httpServer != null && httpServer.isRunning());
  enableHttpServerItem.addItemListener(new TrayActionItemListener());
  popup.add(enableHttpServerItem);
  // Check clipboard text:
  MenuItem checkClipboardItem =
          new MenuItem(Tools.getLabel(messages.getString("guiMenuCheckClipboard")));
  checkClipboardItem.addActionListener(rmbListener);
  popup.add(checkClipboardItem);
  // Open main window:
  MenuItem restoreItem = new MenuItem(Tools.getLabel(messages.getString("guiMenuShowMainWindow")));
  restoreItem.addActionListener(rmbListener);
  popup.add(restoreItem);
  // Exit:
  MenuItem exitItem = new MenuItem(Tools.getLabel(messages.getString("guiMenuQuit")));
  exitItem.addActionListener(rmbListener);
  popup.add(exitItem);
  return popup;
}
Main.java 文件源码 项目:languagetool 阅读 19 收藏 0 点赞 0 评论 0
private void hideToTray() {
  if (!isInTray) {
    SystemTray tray = SystemTray.getSystemTray();
    String iconPath = tray.getTrayIconSize().height > 16 ? TRAY_ICON : TRAY_SMALL_ICON;
    URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(iconPath);
    Image img = Toolkit.getDefaultToolkit().getImage(iconUrl);
    PopupMenu popup = makePopupMenu();
    try {
      trayIcon = new TrayIcon(img, TRAY_TOOLTIP, popup);
      trayIcon.addMouseListener(new TrayActionListener());
      setTrayIcon();
      tray.add(trayIcon);
    } catch (AWTException e1) {
      Tools.showError(e1);
    }
  }
  isInTray = true;
  frame.setVisible(false);
}


问题


面经


文章

微信
公众号

扫码关注公众号