List of usage examples for javax.swing JPopupMenu show
public void show(Component invoker, int x, int y)
From source file:org.openestate.tool.helloworld.HelloWorldObjectViewPanel.java
@Override protected void doShowActions(Component component, int x, int y) { JPopupMenu popup = new JPopupMenu(); popup.add(createDefaultCopyAction(currentObject != null && currentObject.id > 0 && HelloWorldPlugin.isUserAllowedTo(HelloWorldPermission.OBJECTS_EDIT))); popup.add(createDefaultRemoveAction(currentObject != null && currentObject.id > 0 && mayRemoveObject)); boolean addonItemAdded = false; for (ObjectViewExtension addon : addons) { JMenuItem[] items = addon.createActionMenuItems(currentObject); if (ArrayUtils.isEmpty(items)) continue; for (JMenuItem item : items) { if (!addonItemAdded) { addonItemAdded = true;// w ww.j ava 2 s .c o m popup.addSeparator(); } popup.add(item); } } popup.show(component, x, y); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.util.FileImportComponent.java
/** Initializes the components. */ private void initComponents() { actionMenuButton = new JButton(); actionMenuButton.setVisible(false);/*from w w w . j a v a 2 s . co m*/ actionMenuButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { JPopupMenu popup = createActionMenu(); popup.show(actionMenuButton, 0, actionMenuButton.getHeight()); } }); adapter = new MouseAdapter() { /** * Views the image. * @see MouseListener#mousePressed(MouseEvent) */ public void mousePressed(MouseEvent e) { if (e.getClickCount() == 1) { launchFullViewer(); } } }; setLayout(new FlowLayout(FlowLayout.LEFT)); busyLabel = new JXBusyLabel(SIZE); busyLabel.setVisible(false); busyLabel.setBusy(false); cancelButton = new JButton("Cancel"); cancelButton.setForeground(UIUtilities.HYPERLINK_COLOR); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { cancelLoading(); } }); cancelButton.setVisible(true); namePane = new JPanel(); namePane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); IconManager icons = IconManager.getInstance(); Icon icon; if (getFile().isFile()) icon = icons.getIcon(IconManager.IMAGE); else icon = icons.getIcon(IconManager.DIRECTORY); imageLabel = new ThumbnailLabel(icon); imageLabel.addPropertyChangeListener(this); imageLabels = new ArrayList<ThumbnailLabel>(); ThumbnailLabel label; for (int i = 0; i < MAX_THUMBNAILS; i++) { label = new ThumbnailLabel(); if (i == MAX_THUMBNAILS - 1) { Font f = label.getFont(); label.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2)); } label.setVisible(false); label.addPropertyChangeListener(this); imageLabels.add(label); } fileNameLabel = new JLabel(getFile().getName()); namePane.add(imageLabel); Iterator<ThumbnailLabel> j = imageLabels.iterator(); while (j.hasNext()) { namePane.add(j.next()); } namePane.add(Box.createHorizontalStrut(4)); namePane.add(fileNameLabel); namePane.add(Box.createHorizontalStrut(10)); resultLabel = new JLabel(); statusLabel = new StatusLabel(importable.getFile()); statusLabel.addPropertyChangeListener(this); image = null; refButton = cancelButton; refLabel = busyLabel; }
From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java
/** * Creates the menus corresponding to the passed id and brings it on screen. * //from ww w. j ava2s . co m * @param menuID The id of the menu. One out of the following constants: * {@link ImViewer#COLOR_PICKER_MENU}, * {@link ImViewer#CATEGORY_MENU}. * @param source The component that requested the popup menu. * @param location The point at which to display the menu, relative to the * <code>component</code>'s coordinates. */ void showMenu(int menuID, Component source, Point location) { switch (menuID) { case ImViewer.COLOR_PICKER_MENU: List<ChannelData> data = model.getChannelData(); ChannelData d; JPopupMenu menu = new JPopupMenu(); ChannelColorMenuItem item; Iterator<ChannelData> i = data.iterator(); int index; while (i.hasNext()) { d = i.next(); index = d.getIndex(); item = new ChannelColorMenuItem(d.getChannelLabeling(), model.getChannelColor(index), index); menu.add(item); item.addPropertyChangeListener(controller); } menu.show(source, location.x, location.y); } }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java
/** * Creates and displays the menu /*from w ww .j a v a 2 s.c o m*/ * @param src The invoker. * @param p The location where to show the menu. */ private void displayMenu(Component src, Point p) { JPopupMenu menu = new JPopupMenu(); ButtonGroup group = new ButtonGroup(); JCheckBoxMenuItem item = createMenuItem(SHOW_ALL); group.add(item); menu.add(item); item = createMenuItem(ADDED_BY_ME); group.add(item); menu.add(item); item = createMenuItem(ADDED_BY_OTHERS); group.add(item); menu.add(item); menu.show(src, p.x, p.y); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java
/** * Creates or recycles the view menu./* ww w .jav a 2 s . c o m*/ * * @param source The source of the mouse event. * @param p The location of the mouse pressed. */ private void showViewMenu(Component source, Point p) { JPopupMenu menu = new JPopupMenu(); IconManager icons = IconManager.getInstance(); JMenuItem item = new JMenuItem(icons.getIcon(IconManager.VIEWER)); item.setText("View..."); item.setActionCommand("" + EditorControl.VIEW_IMAGE); item.addActionListener(controller); menu.add(item); item = new JMenuItem(icons.getIcon(IconManager.VIEWER_IJ)); item.setText("View in ImageJ..."); item.setActionCommand("" + EditorControl.VIEW_IMAGE_IN_IJ); item.addActionListener(controller); menu.add(item); menu.show(source, p.x, p.y); }
From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
public Catalog() { menuTree = new org.orbisgis.core.ui.pluginSystem.menu.MenuTree(); lstSources = new OGList(); lstSources.addMouseListener(new MouseAdapter() { @Override/*from w w w. j av a 2 s . c o m*/ public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } private void showPopup(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { int path = -1; for (int i = 0; i < listModel.getSize(); i++) { if (lstSources.getCellBounds(i, i).contains(e.getPoint())) { path = i; break; } } int[] selectionPaths = lstSources.getSelectedIndices(); if ((selectionPaths != null) && (path != -1)) { if (!CollectionUtils.contains(selectionPaths, path)) { if (e.isControlDown()) { lstSources.addSelectionInterval(path, path); } else { lstSources.setSelectionInterval(path, path); } } } else if (path == -1) { lstSources.clearSelection(); } else { } } if (e.isPopupTrigger()) { JPopupMenu popup = getPopup(); if (popup != null) { popup.show(e.getComponent(), e.getX(), e.getY()); } } } }); listModel = new SourceListModel(); lstSources.setModel(listModel); this.setLayout(new BorderLayout()); this.add(new JScrollPane(lstSources), BorderLayout.CENTER); this.add(getNorthPanel(), BorderLayout.NORTH); SourceListRenderer cellRenderer = new SourceListRenderer(this); cellRenderer.setRenderers(new SourceRenderer[0]); lstSources.setCellRenderer(cellRenderer); dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(lstSources, DnDConstants.ACTION_COPY_OR_MOVE, this); editingSources = new HashMap<String, EditableSource>(); //Init the file drop system FileDrop fileDrop = new FileDrop(this, new FileDrop.Listener() { @Override public void filesDropped(java.io.File[] files) { DataManager dm = (DataManager) Services.getService(DataManager.class); SourceManager sourceManager = dm.getSourceManager(); for (File file : files) { // For each file, we ensure that we have a driver // that can be used to read it. If we don't, we don't // open the file. if (OrbisConfiguration.isFileEligible(file)) { try { String name = sourceManager .getUniqueName(FilenameUtils.removeExtension(file.getName())); sourceManager.register(name, file); } catch (SourceAlreadyExistsException e) { ErrorMessages.error(ErrorMessages.SourceAlreadyRegistered + ": ", e); } } } } }); }
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 .j a v a2 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// w w w . j a v a 2 s. 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);/*from ww w . j ava 2 s.c om*/ menu.add(file); menu.add(lan); menu.show(addDeviceButton, evt.getX(), evt.getY()); }
From source file:org.rdv.ui.ChannelListPanel.java
private void handlePopup(MouseEvent e) { TreePath treePath = tree.getPathForLocation(e.getX(), e.getY()); if (treePath == null) { return;//w w w . j a v a 2 s . com } // select only the node under the mouse if it is not already selected if (!tree.isPathSelected(treePath)) { tree.setSelectionPath(treePath); } JPopupMenu popup = null; Object o = treePath.getLastPathComponent(); if (o == treeModel.getRoot()) { popup = getRootPopup(); } else { popup = getChannelPopup(); } if (popup != null && popup.getComponentCount() > 0) { popup.show(tree, e.getX(), e.getY()); } }