List of usage examples for javax.swing JPopupMenu JPopupMenu
public JPopupMenu()
JPopupMenu
without an "invoker". From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Brings up the <code>Personal Menu</code> on top of the specified * component at the specified location.//from w w w . j a v a 2s .c o m * * @param c The component that requested the pop-up menu. * @param p The point at which to display the menu, relative to the * <code>component</code>'s coordinates. */ void showPersonalMenu(Component c, Point p) { if (p == null) return; if (c == null) throw new IllegalArgumentException("No component."); personalMenu = new JPopupMenu(); personalMenu.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); List<JMenuItem> l = createMenuItem(false); Iterator<JMenuItem> i = l.iterator(); while (i.hasNext()) { personalMenu.add(i.next()); } personalMenu.show(c, p.x, p.y); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Brings up the <code>Available Scripts</code> on top of the specified * component at the specified location.//from w ww . j a v a 2 s. c o m * * @param c The component that requested the pop-pup menu. * @param p The point at which to display the menu, relative to the * <code>component</code>'s coordinates. */ void showAvailableScriptsMenu(Component c, Point p) { if (p == null) return; if (c == null) { c = scriptButton; } IconManager icons = IconManager.getInstance(); Collection<ScriptObject> scripts = model.getAvailableScripts(); if (CollectionUtils.isEmpty(scripts)) return; if (scriptsMenu == null) { scriptsMenu = new JPopupMenu(); JMenuItem refresh = new JMenuItem(icons.getIcon(IconManager.REFRESH)); refresh.setText("Reload Scripts"); refresh.setToolTipText("Reloads the existing scripts."); refresh.addMouseListener(new MouseAdapter() { /** * Launches the dialog when the user releases the mouse. * MouseAdapter#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { model.setAvailableScripts(null); scriptsMenu = null; controller.reloadAvailableScripts(e.getPoint()); } }); scriptsMenu.add(refresh); scriptsMenu.add(new JSeparator()); ScriptObject so; Map<String, JMenu> menus = new HashMap<String, JMenu>(); String path; Icon icon = icons.getIcon(IconManager.ANALYSIS); Icon largeIcon = icons.getIcon(IconManager.ANALYSIS_48); ActionListener listener = new ActionListener() { /** * Listens to the selection of a script. * @see ActionListener#actionPerformed(ActionEvent) */ public void actionPerformed(ActionEvent e) { ScriptMenuItem item = (ScriptMenuItem) e.getSource(); controller.handleScriptSelection(item.getScript()); } }; String name = ""; //loop twice to check if we need to add the first element String refString = null; int count = 0; Iterator<ScriptObject> i = scripts.iterator(); String sep; String[] values; String value; while (i.hasNext()) { so = i.next(); value = ""; path = so.getPath(); if (path != null) { sep = FilenameUtils.getPrefix(path); if (path.startsWith(sep)) path = path.substring(1, path.length()); values = UIUtilities.splitString(path); if (values != null && values.length > 0) value = values[0]; } if (refString == null) { refString = value; count++; } else if (refString.equals(value)) count++; } int index = 0; if (scripts.size() == count) index++; i = scripts.iterator(); List<JMenuItem> topMenus = new ArrayList<JMenuItem>(); JMenu ref = null; while (i.hasNext()) { so = i.next(); path = so.getPath(); if (path != null) { sep = FilenameUtils.getPrefix(path); if (path.startsWith(sep)) path = path.substring(1, path.length()); values = UIUtilities.splitString(path); if (values != null) { for (int j = index; j < values.length; j++) { value = values[j]; JMenu v; String text = name + value; if (menus.containsKey(text)) { v = menus.get(text); } else { value = value.replace(ScriptObject.PARAMETER_SEPARATOR, ScriptObject.PARAMETER_UI_SEPARATOR); v = new JMenu(value); } if (ref == null) topMenus.add(v); else ref.add(v); ref = v; name += values[j]; menus.put(name, v); } } } ScriptMenuItem item = new ScriptMenuItem(so); item.addActionListener(listener); if (ref != null) ref.add(item); else topMenus.add(item); name = ""; ref = null; if (so.getIcon() == null) { so.setIcon(icon); so.setIconLarge(largeIcon); } } Iterator<JMenuItem> j = topMenus.iterator(); while (j.hasNext()) { scriptsMenu.add(j.next()); } } scriptsMenu.show(c, p.x, p.y); }
From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java
/** * Creates the option menu.//from w w w . j a v a2 s . c o m * * @return See above. */ private JPopupMenu createOptionMenu() { if (optionMenu != null) return optionMenu; optionMenu = new JPopupMenu(); optionMenu.add(createButton("Download", DOWNLOAD)); optionMenu.add(createButton("View", VIEW)); return optionMenu; }
From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
public JPopupMenu getPopup() { JPopupMenu popup = new JPopupMenu(); JComponent[] menus = menuTree.getJMenus(); for (JComponent menu : menus) { popup.add(menu);//from w w w. j a v a 2 s . c o m } if (!tagSources.isEmpty() && lstSources.getSelectedIndices().length > 0) { JMenu menu = new JMenu(I18N.getString("orbisgis.org.orbisgis.core.ui.plugins.views.geocatalog.tag")); Iterator<String> tagsIterator = tagSources.keySet().iterator(); while (tagsIterator.hasNext()) { String tag = tagsIterator.next(); JCheckBoxMenuItem item; if (isSelectionTagged(tag)) { item = new JCheckBoxMenuItem(tag, true); RemoveTagActionListener removeTagAL = new RemoveTagActionListener(tag); item.addActionListener(removeTagAL); } else { item = new JCheckBoxMenuItem(tag, false); AddTagActionListener addTagAL = new AddTagActionListener(tag); item.addActionListener(addTagAL); } menu.add(item); } popup.addSeparator(); popup.add(menu); } return popup; }
From source file:org.orbisgis.sif.components.fstree.FileTree.java
/** * Fetch all selected items to make a pop-up menu * @return // www . j a v a 2 s . co m */ private JPopupMenu makePopupMenu() { JPopupMenu menu = new JPopupMenu(); TreePath[] paths = getSelectionPaths(); if (paths != null) { // Generic action on single TreeNode if (paths.length == 1) { Object component = paths[0].getLastPathComponent(); if (component instanceof AbstractTreeNode) { AbstractTreeNode aTreeNode = (AbstractTreeNode) component; if (aTreeNode.isEditable()) { JMenuItem editMenu = new JMenuItem(I18N.tr("Rename")); editMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onRenameItem")); editMenu.setActionCommand("rename"); menu.add(editMenu); } } } for (TreePath treePath : paths) { Object component = treePath.getLastPathComponent(); // All nodes if (component instanceof MutableTreeNode) { MutableTreeNode node = (MutableTreeNode) component; for (TreeNodeFileFactory fact : getFactories()) { fact.feedTreeNodePopupMenu(node, menu); } } // Specific nodes if (component instanceof PopupTreeNode) { PopupTreeNode treeNode = (PopupTreeNode) component; treeNode.feedPopupMenu(menu); } } } return menu; }
From source file:org.orbisgis.view.geocatalog.Catalog.java
/** * The user click on the source list control * * @param e The mouse event fired by the LI *//*from w w w . ja va2 s . c o m*/ public void onMouseActionOnSourceList(MouseEvent e) { //Manage selection of items before popping up the menu if (e.isPopupTrigger()) { //Right mouse button under linux and windows int itemUnderMouse = -1; //Item under the position of the mouse event //Find the Item under the position of the mouse cursor for (int i = 0; i < sourceListContent.getSize(); i++) { //If the coordinate of the cursor cover the cell bouding box if (sourceList.getCellBounds(i, i).contains(e.getPoint())) { itemUnderMouse = i; break; } } //Retrieve all selected items index int[] selectedItems = sourceList.getSelectedIndices(); //If there are a list item under the mouse if ((selectedItems != null) && (itemUnderMouse != -1)) { //If the item under the mouse was not previously selected if (!CollectionUtils.contains(selectedItems, itemUnderMouse)) { //Control must be pushed to add the list item to the selection if (e.isControlDown()) { sourceList.addSelectionInterval(itemUnderMouse, itemUnderMouse); } else { //Unselect the other items and select only the item under the mouse sourceList.setSelectionInterval(itemUnderMouse, itemUnderMouse); } } } else if (itemUnderMouse == -1) { //Unselect all items sourceList.clearSelection(); } //Selection are ready, now create the popup menu JPopupMenu popup = new JPopupMenu(); popupActions.copyEnabledActions(popup); if (popup.getComponentCount() > 0) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }
From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java
private void addDeviceContactShareButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_addDeviceContactShareButtonMousePressed final JFrame thisFrame = this; JPopupMenu menu = new JPopupMenu(); JMenuItem addDevice = new JMenuItem(bundle.getString("shareUserList.device")); addDevice.addActionListener(new ActionListener() { @Override//from w ww .ja v a2s.co m public void actionPerformed(ActionEvent e) { try { int selected = shareList.getSelectedIndex(); PanboxShare share = shareModel.getElementAt(selected); if (share instanceof DropboxPanboxShare) { DropboxAdapterFactory dbxFac = (DropboxAdapterFactory) CSPAdapterFactory .getInstance(StorageBackendType.DROPBOX); DropboxAPIIntegration api = (DropboxAPIIntegration) dbxFac.getAPIAdapter(); DropboxClientIntegration c = (DropboxClientIntegration) dbxFac.getClientAdapter(); if (!c.isClientRunning()) { int ret = JOptionPane.showConfirmDialog(client.getMainWindow(), bundle.getString("PanboxClientGUI.dropboxNotRunningError"), bundle.getString("client.warn"), JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) { return; } } if (!api.isOnline()) { int ret = JOptionPane.showConfirmDialog(client.getMainWindow(), bundle.getString("PanboxClientGUI.offlineError"), bundle.getString("client.warn"), JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) { return; } } } if (share != null) { AddDeviceToShareDialog dialog = new AddDeviceToShareDialog(thisFrame, deviceModel, share.getDevices()); dialog.setVisible(true); List<PanboxDevice> result = dialog.getResult(); if (result.isEmpty()) { logger.debug("PanboxClientGUI : addDevice.addActionListener : Operation aborted!"); return; } char[] password = PasswordEnterDialog.invoke(PermissionType.DEVICE); PanboxShare sharenew = null; try { client.showTrayMessage(bundle.getString("PleaseWait"), bundle.getString("tray.addDeviceToShare.waitMessage"), MessageType.INFO); client.getShareWatchService().removeShare(share); for (PanboxDevice dev : result) { DeviceShareParticipant dp = new DeviceShareParticipant(dev); sharenew = client.addPermissionToShare(share, dp, password); ((ShareParticipantListModel) usersList.getModel()).addElement(dp); } if (sharenew != null) { shareModel.setElementAt(sharenew, selected); } client.showTrayMessage(bundle.getString("tray.addDeviceToShare.finishTitle"), bundle.getString("tray.addDeviceToShare.finishMessage"), MessageType.INFO); } catch (ShareDoesNotExistException e1) { logger.error("Share not found!", e1); JOptionPane.showMessageDialog(client.getMainWindow(), bundle.getString("PanboxClient.shareNotFound"), bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE); } catch (ShareManagerException e1) { logger.error("Could not add device to share!", e1); JOptionPane.showMessageDialog(client.getMainWindow(), bundle.getString("PanboxClientGUI.errorWhileAddingDeviceToShare"), bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE); } catch (UnrecoverableKeyException e1) { logger.error("Unable to recover key!", e1); JOptionPane.showMessageDialog(client.getMainWindow(), bundle.getString("PanboxClient.unableToRecoverKeys"), bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE); } catch (ShareMetaDataException e1) { logger.error("Error in share metadata", e1); JOptionPane.showMessageDialog(client.getMainWindow(), bundle.getString("PanboxClientGUI.errorWhileAccessingShareMetadata"), bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE); } finally { Utils.eraseChars(password); PanboxShare tmp = (sharenew != null) ? sharenew : share; client.getShareWatchService().registerShare(tmp); // Also update share list for selected device if (device != null) { deviceShareList.setModel(client.getDeviceShares(device)); } } } } catch (OperationAbortedException ex) { System.out.println("Operation aborted!"); } } }); JMenuItem addContact = new JMenuItem(bundle.getString("shareUserList.contact")); addContact.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // check if user is share owner int selected = shareList.getSelectedIndex(); if ((selected != -1) && shareModel.getElementAt(selected).isOwner()) { boolean hasParticipants = (share.getContacts().size() != 0); PanboxShare share = shareModel.getElementAt(selected); if (share instanceof DropboxPanboxShare) { DropboxAdapterFactory dbxFac = (DropboxAdapterFactory) CSPAdapterFactory .getInstance(StorageBackendType.DROPBOX); DropboxAPIIntegration api = (DropboxAPIIntegration) dbxFac.getAPIAdapter(); DropboxClientIntegration c = (DropboxClientIntegration) dbxFac.getClientAdapter(); if (!c.isClientRunning()) { int ret = JOptionPane.showConfirmDialog(client.getMainWindow(), bundle.getString("PanboxClientGUI.dropboxNotRunningError"), bundle.getString("client.warn"), JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) { return; } } if (!api.isOnline()) { int ret = JOptionPane.showConfirmDialog(client.getMainWindow(), bundle.getString("PanboxClientGUI.offlineError"), bundle.getString("client.warn"), JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) { return; } } } // AddContactToShareWizard contactWizard; // try { // contactWizard = new AddContactToShareWizard(thisFrame, // client, share, contactModel); // } catch (Exception e2) { // e2.printStackTrace(); // return; // } // // contactWizard.setVisible(true); AddContactToShareDialog dialog = new AddContactToShareDialog(thisFrame, contactModel, share.getContacts()); dialog.setVisible(true); List<PanboxGUIContact> result; try { result = dialog.getResult(); } catch (OperationAbortedException e2) { logger.debug("PanboxClientGUI : addContact.addActionListener : Operation aborted!"); return; } if (result.isEmpty()) { logger.debug("PanboxClientGUI : addContact.addActionListener : Operation aborted!"); return; } char[] password = PasswordEnterDialog.invoke(PermissionType.USER); PanboxShare sharenew = null; try { client.showTrayMessage(bundle.getString("PleaseWait"), bundle.getString("tray.addContactToShare.waitMessage"), MessageType.INFO); ArrayList<PanboxGUIContact> reallyAdded = new ArrayList<PanboxGUIContact>(); client.getShareWatchService().removeShare(share); for (int i = 0; i < result.size(); i++) { // add permission for user ContactShareParticipant cp = new ContactShareParticipant(result.get(i)); if (Settings.getInstance().getExpertMode() && !cp.getContact().isVerified()) { int res = JOptionPane.showConfirmDialog(client.getMainWindow(), MessageFormat.format(bundle.getString( "PanboxClientGUI.addUnverifiedContactWarning.text"), cp.getName()), bundle.getString("PanboxClientGUI.addUnverifiedContactWarning.title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (res == JOptionPane.YES_OPTION) { sharenew = client.addPermissionToShare(share, cp, password); logger.info("Added unverified contact " + cp.getName() + " to share."); reallyAdded.add(result.get(i)); ((ShareParticipantListModel) usersList.getModel()).addElement(cp); } else if (res == JOptionPane.NO_OPTION) { logger.info("Skipped adding unverified contact " + cp.getName() + " to share."); continue; } } else { sharenew = client.addPermissionToShare(share, cp, password); reallyAdded.add(result.get(i)); ((ShareParticipantListModel) usersList.getModel()).addElement(cp); } } if (reallyAdded.size() > 0) { shareModel.setElementAt(sharenew, selected); handleCSPShareParticipantConfiguration(sharenew, hasParticipants, reallyAdded); } client.showTrayMessage(bundle.getString("tray.addContactToShare.finishTitle"), bundle.getString("tray.addContactToShare.finishMessage"), MessageType.INFO); } catch (ShareDoesNotExistException e1) { logger.error("Share not found!", e1); JOptionPane.showMessageDialog(client.getMainWindow(), bundle.getString("PanboxClient.shareNotFound"), bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE); } catch (ShareManagerException e1) { logger.error("Could not add contact to share!", e1); JOptionPane.showMessageDialog(client.getMainWindow(), bundle.getString("PanboxClientGUI.errorWhileAddingContactToShare"), bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE); } catch (UnrecoverableKeyException e1) { logger.error("Unable to recover key!", e1); JOptionPane.showMessageDialog(client.getMainWindow(), bundle.getString("PanboxClient.unableToRecoverKeys"), bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE); } catch (ShareMetaDataException e1) { logger.error("Error in share metadata", e1); JOptionPane.showMessageDialog(client.getMainWindow(), bundle.getString("PanboxClientGUI.errorWhileAccessingShareMetadata"), bundle.getString("client.error"), JOptionPane.ERROR_MESSAGE); } finally { Utils.eraseChars(password); PanboxShare tmp = (sharenew != null) ? sharenew : share; client.getShareWatchService().registerShare(tmp); } } } }); menu.add(addDevice); menu.add(addContact); menu.show(addDeviceContactShareButton, evt.getX(), evt.getY()); }
From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java
private void addDeviceButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_addDeviceButtonMousePressed JPopupMenu menu = new JPopupMenu(); JMenuItem bluetooth = new JMenuItem(bundle.getString("PanboxClientGui.bluetooth")); bluetooth.addActionListener(new AddDeviceBluetoothActionListener(client, this)); JMenuItem file = new JMenuItem(bundle.getString("PanboxClientGui.File")); file.addActionListener(new AddDeviceFileActionListener(client, this)); JMenuItem lan = new JMenuItem(bundle.getString("PanboxClientGui.lanandwlan")); lan.addActionListener(new AddDeviceNetworkActionListener(client, this)); menu.add(bluetooth);/* w w w.j a v a2 s . c om*/ menu.add(file); menu.add(lan); menu.show(addDeviceButton, evt.getX(), evt.getY()); }
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
void createUI() { photoTransferHandler = new PhotoCollectionTransferHandler(this); setTransferHandler(photoTransferHandler); setAutoscrolls(true);//from w w w .j a va 2 s . c om addMouseListener(this); addMouseMotionListener(this); // Create the popup menu popup = new JPopupMenu(); ImageIcon propsIcon = getIcon("view_properties.png"); editSelectionPropsAction = new EditSelectionPropsAction(this, "Properties...", propsIcon, "Edit properties of the selected photos", KeyEvent.VK_P); JMenuItem propsItem = new JMenuItem(editSelectionPropsAction); ImageIcon colorsIcon = getIcon("colors.png"); editSelectionColorsAction = new EditSelectionColorsAction(this, null, "Adjust colors...", colorsIcon, "Adjust colors of the selected photos", KeyEvent.VK_A); JMenuItem colorsItem = new JMenuItem(editSelectionColorsAction); ImageIcon showIcon = getIcon("show_new_window.png"); showSelectedPhotoAction = new ShowSelectedPhotoAction(this, "Show image", showIcon, "Show the selected phot(s)", KeyEvent.VK_S); JMenuItem showItem = new JMenuItem(showSelectedPhotoAction); showHistoryAction = new ShowPhotoHistoryAction(this, "Show history", null, "Show history of selected photo", KeyEvent.VK_H, null); resolveConflictsAction = new ResolvePhotoConflictsAction(this, "Resolve conflicts", null, "Resolve synchronization conflicts", KeyEvent.VK_R, null); JMenuItem rotateCW = new JMenuItem(ctrl.getActionAdapter("rotate_cw")); JMenuItem rotateCCW = new JMenuItem(ctrl.getActionAdapter("rotate_ccw")); JMenuItem rotate180deg = new JMenuItem(ctrl.getActionAdapter("rotate_180")); JMenuItem addToFolder = new JMenuItem("Add to folder..."); addToFolder.addActionListener(this); addToFolder.setActionCommand(PHOTO_ADD_TO_FOLDER_CMD); addToFolder.setIcon(getIcon("empty_icon.png")); ImageIcon exportIcon = getIcon("filesave.png"); exportSelectedAction = new ExportSelectedAction(this, "Export selected...", exportIcon, "Export the selected photos to from archive database to image files", KeyEvent.VK_E); JMenuItem exportSelected = new JMenuItem(exportSelectedAction); ImageIcon deleteSelectedIcon = getIcon("delete_image.png"); deleteSelectedAction = new DeletePhotoAction(this, "Delete", deleteSelectedIcon, "Delete selected photos including all of their instances", KeyEvent.VK_D); JMenuItem deleteSelected = new JMenuItem(deleteSelectedAction); starIcon = getIcon("star_normal_border.png"); rejectedIcon = getIcon("quality_unusable.png"); rawIcon = getIcon("raw_icon.png"); JMenuItem showHistory = new JMenuItem(showHistoryAction); JMenuItem resolveConflicts = new JMenuItem(resolveConflictsAction); AddTagAction addTagAction = new AddTagAction(ctrl, "Add tag...", null, "Add tag to image", KeyEvent.VK_T); JMenuItem addTag = new JMenuItem(addTagAction); popup.add(showItem); popup.add(propsItem); popup.add(colorsItem); popup.add(rotateCW); popup.add(rotateCCW); popup.add(rotate180deg); popup.add(addToFolder); popup.add(exportSelected); popup.add(deleteSelected); popup.add(showHistory); popup.add(resolveConflicts); popup.add(addTag); MouseListener popupListener = new PopupListener(); addMouseListener(popupListener); ImageIcon selectNextIcon = getIcon("next.png"); selectNextAction = new ChangeSelectionAction(this, ChangeSelectionAction.MOVE_FWD, "Next photo", selectNextIcon, "Move to next photo", KeyEvent.VK_N, KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); ImageIcon selectPrevIcon = getIcon("previous.png"); selectPrevAction = new ChangeSelectionAction(this, ChangeSelectionAction.MOVE_BACK, "Previous photo", selectPrevIcon, "Move to previous photo", KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); creatingThumbIcon = getIcon("creating_thumb.png"); }
From source file:org.photovault.swingui.tag.TagEditor2.java
/** * Show the autocomplete popup menu/* ww w. j ava 2 s . co m*/ */ private void showPopup() { log.debug("showPopup()"); if (nameField.isShowing()) { if (popup != null) { hidePopup(); } popup = new JPopupMenu(); popup.setFocusable(false); popup.add(suggestionList); suggestionList.setPreferredSize(null); Dimension prefSize = suggestionList.getPreferredSize(); System.err.println("popup pref height" + prefSize.getHeight()); prefSize = new Dimension(nameField.getWidth(), prefSize.height); suggestionList.setPreferredSize(prefSize); popup.show(nameField, 0, nameField.getHeight()); } }