List of usage examples for javax.swing JPopupMenu show
public void show(Component invoker, int x, int y)
From source file:picocash.components.mode.buttons.ModeButton.java
private void init() { setLayout(new MigLayout("fill")); add(iconLabel);//from ww w.j a va2 s . c om add(nameLabel, "push"); add(minimizeLabel); minimizeLabel.setIcon(PicocashIcons.getSystemIcon("minimize-dark")); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { JPopupMenu popupMenu = new JPopupMenu(); fillPopupMenu(popupMenu); Dimension dimension = getSize(); popupMenu.setSize(dimension.width, popupMenu.getHeight()); popupMenu.show((Component) arg0.getSource(), -1, dimension.height + 3); } }); }
From source file:pl.kotcrab.arget.gui.ContactsPanel.java
public ContactsPanel(final Profile profile, MainWindowCallback callback) { this.profile = profile; setLayout(new BorderLayout()); table = new JTable(new ContactsTableModel(profile.contacts)); table.setDefaultRenderer(ContactInfo.class, new ContactsTableEditor(table, callback)); table.setDefaultEditor(ContactInfo.class, new ContactsTableEditor(table, callback)); table.setShowGrid(false);//from ww w .j a va 2 s.com table.setTableHeader(null); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setRowHeight(40); final JPopupMenu popupMenu = new JPopupMenu(); { JMenuItem menuModify = new JMenuItem("Modify"); JMenuItem menuDelete = new JMenuItem("Delete"); popupMenu.add(menuModify); popupMenu.add(menuDelete); menuModify.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String key = Base64.encodeBase64String(profile.rsa.getPublicKey().getEncoded()); new CreateContactDialog(MainWindow.instance, key, (ContactInfo) table.getValueAt(table.getSelectedRow(), 0)); ProfileIO.saveProfile(profile); updateContactsTable(); } }); menuDelete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ContactInfo contact = (ContactInfo) table.getValueAt(table.getSelectedRow(), 0); if (contact.status == ContactStatus.CONNECTED_SESSION) { JOptionPane.showMessageDialog(MainWindow.instance, "This contact cannot be deleted because session is open.", "Error", JOptionPane.ERROR_MESSAGE); return; } int result = JOptionPane.showConfirmDialog(MainWindow.instance, "Are you sure you want to delete '" + contact.name + "'?", "Warning", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.NO_OPTION || result == JOptionPane.CLOSED_OPTION) return; profile.contacts.remove(contact); ProfileIO.saveProfile(profile); updateContactsTable(); } }); } table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), table); int rowNumber = table.rowAtPoint(p); table.editCellAt(rowNumber, 0); table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); JScrollPane tableScrollPane = new JScrollPane(table); tableScrollPane.setBorder(new EmptyBorder(0, 0, 0, 0)); add(tableScrollPane, BorderLayout.CENTER); }
From source file:pl.otros.logview.gui.LogViewPanel.java
private void showMessageFormatterOrColorizerPopupMenu(MouseEvent e, String menuTitle, PluginableElementsContainer<? extends PluginableElement> selectedPluginableElementsContainer, PluginableElementsContainer<? extends PluginableElement> pluginableElementsContainer) { final JPopupMenu popupMenu = new JPopupMenu(menuTitle); popupMenu.add(new JLabel(menuTitle)); ArrayList<PluginableElement> elements = new ArrayList<PluginableElement>( pluginableElementsContainer.getElements()); Collections.sort(elements, new PluginableElementNameComparator()); for (final PluginableElement pluginableElement : elements) { addMessageFormatterOrColorizerToMenu(popupMenu, pluginableElement, selectedPluginableElementsContainer); }//from w ww. jav a2s. c o m popupMenu.show(e.getComponent(), e.getX(), e.getY()); }
From source file:pt.lsts.neptus.console.plugins.ImageLayers.java
@Override public void mouseClicked(MouseEvent event, StateRenderer2D source) { if (event.getButton() == MouseEvent.BUTTON3) { JPopupMenu popup = new JPopupMenu(); popup.add("Add layer from file").addActionListener(new ActionListener() { @Override//from w w w . j a v a 2 s .c om public void actionPerformed(ActionEvent e) { JFileChooser chooser = GuiUtils.getFileChooser(lastDir, I18n.text("Neptus image layers"), "layer"); int op = chooser.showOpenDialog(getConsole()); if (op != JFileChooser.APPROVE_OPTION) return; lastDir = chooser.getSelectedFile().getParent(); Future<ImageLayer> il = addLayer(chooser.getSelectedFile()); try { il.get(); } catch (Exception ex) { GuiUtils.errorMessage(getConsole(), ex); } } }); if (!layers.isEmpty()) { JMenu menu = new JMenu("Remove"); JMenu menu2 = new JMenu("Opacity"); for (final ImageLayer l : layers) { menu.add(l.getName()).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { layers.remove(l); layerFiles = StringUtils.join(layers, ","); rebuildControls(); } }); menu2.add(l.getName() + "(" + l.getTransparency() + ")") .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(getConsole(), "Enter opacity (1 for opaque, 0 for invisible)", l.getTransparency()); if (s == null) return; try { double val = Double.parseDouble(s); if (val < 0) throw new Exception("Value must be greater or equal to 0"); if (val > 1) throw new Exception("Value must be less or equal to 1"); l.setTransparency(val); } catch (Exception ex) { GuiUtils.errorMessage(getConsole(), ex); } } }); } popup.add(menu); popup.add(menu2); } popup.show(source, event.getX(), event.getY()); } }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
@Override public void mouseClicked(MouseEvent event, final StateRenderer2D source) { if (event.getButton() == MouseEvent.BUTTON3) { final LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType(); JPopupMenu popup = new JPopupMenu(); for (String type : positions.keySet()) { JMenu menu = new JMenu(type + "s"); for (final AssetPosition p : positions.get(type)) { if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection) continue; Color c = cmap.getColor(1 - (p.getAge() / (7200000.0))); String htmlColor = String.format("#%02X%02X%02X", c.getRed(), c.getGreen(), c.getBlue()); menu.add("<html><b>" + p.getAssetName() + "</b> <font color=" + htmlColor + ">" + getAge(p) + "</font>").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { source.focusLocation(p.getLoc()); }// w ww. ja v a2s .c o m }); } popup.add(menu); } popup.addSeparator(); popup.add("Settings").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PluginUtils.editPluginProperties(SituationAwareness.this, true); } }); popup.add("Fetch asset properties").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // for (AssetTrack track : assets.values()) { // track.setColor(new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255))); // } fetchAssetProperties(); } }); popup.add("Select location sources").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); for (ILocationProvider l : localizers) { JCheckBox check = new JCheckBox(l.getName()); check.setSelected(true); p.add(check); check.setSelected(updateMethodNames.contains(l.getName())); } int op = JOptionPane.showConfirmDialog(getConsole(), p, "Location update sources", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (op == JOptionPane.CANCEL_OPTION) return; Vector<String> methods = new Vector<String>(); for (int i = 0; i < p.getComponentCount(); i++) { if (p.getComponent(i) instanceof JCheckBox) { JCheckBox sel = (JCheckBox) p.getComponent(i); if (sel.isSelected()) methods.add(sel.getText()); } } updateMethods = StringUtils.join(methods, ", "); propertiesChanged(); } }); popup.add("Select hidden positions types").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); for (String type : positions.keySet()) { JCheckBox check = new JCheckBox(type); check.setSelected(true); p.add(check); check.setSelected(hiddenPosTypes.contains(type)); } int op = JOptionPane.showConfirmDialog(getConsole(), p, "Position types to be hidden", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (op == JOptionPane.CANCEL_OPTION) return; Vector<String> types = new Vector<String>(); for (int i = 0; i < p.getComponentCount(); i++) { if (p.getComponent(i) instanceof JCheckBox) { JCheckBox sel = (JCheckBox) p.getComponent(i); if (sel.isSelected()) types.add(sel.getText()); } } hiddenTypes = StringUtils.join(types, ", "); propertiesChanged(); } }); popup.addSeparator(); popup.add("Decision Support").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dialogDecisionSupport == null) { dialogDecisionSupport = new JDialog(getConsole()); dialogDecisionSupport.setModal(false); dialogDecisionSupport.setAlwaysOnTop(true); dialogDecisionSupport.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); } ArrayList<AssetPosition> tags = new ArrayList<AssetPosition>(); LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType(); Vector<AssetPosition> spots = positions.get("SPOT Tag"); Vector<AssetPosition> argos = positions.get("Argos Tag"); if (spots != null) tags.addAll(spots); if (argos != null) tags.addAll(argos); if (!assets.containsKey(getConsole().getMainSystem())) { GuiUtils.errorMessage(getConsole(), "Decision Support", "UUV asset position is unknown"); return; } supportTable.setAssets(assets.get(getConsole().getMainSystem()).getLatest(), tags); JXTable table = new JXTable(supportTable); dialogDecisionSupport.setContentPane(new JScrollPane(table)); dialogDecisionSupport.invalidate(); dialogDecisionSupport.validate(); dialogDecisionSupport.setSize(600, 300); dialogDecisionSupport.setTitle("Decision Support Table"); dialogDecisionSupport.setVisible(true); dialogDecisionSupport.toFront(); GuiUtils.centerOnScreen(dialogDecisionSupport); } }); popup.show(source, event.getX(), event.getY()); } super.mouseClicked(event, source); }
From source file:pt.lsts.neptus.plugins.sunfish.IridiumComms.java
@Override public void mouseClicked(MouseEvent event, StateRenderer2D source) { if (event.getButton() != MouseEvent.BUTTON3) { super.mouseClicked(event, source); return;/* w w w . j a v a 2s . c o m*/ } final LocationType loc = source.getRealWorldLocation(event.getPoint()); loc.convertToAbsoluteLatLonDepth(); JPopupMenu popup = new JPopupMenu(); if (IridiumManager.getManager().isActive()) { popup.add(I18n.text("Deactivate Polling")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { IridiumManager.getManager().stop(); } }); } else { popup.add(I18n.text("Activate Polling")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { IridiumManager.getManager().start(); } }); } popup.add(I18n.text("Select Iridium gateway")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { IridiumManager.getManager().selectMessenger(getConsole()); } }); popup.addSeparator(); popup.add(I18n.textf("Send %vehicle a command via Iridium", getMainVehicleId())) .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sendIridiumCommand(); } }); popup.add(I18n.textf("Command %vehicle a plan via Iridium", getMainVehicleId())) .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { commandPlanExecution(); } }); popup.add(I18n.textf("Subscribe to iridium device updates", getMainVehicleId())) .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ActivateSubscription activate = new ActivateSubscription(); activate.setDestination(0xFF); activate.setSource(ImcMsgManager.getManager().getLocalId().intValue()); try { IridiumManager.getManager().send(activate); getConsole().post(Notification.success("Iridium message sent", "1 Iridium messages were sent using " + IridiumManager.getManager().getCurrentMessenger().getName())); } catch (Exception ex) { GuiUtils.errorMessage(getConsole(), ex); } } }); popup.add(I18n.textf("Unsubscribe to iridium device updates", getMainVehicleId())) .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DeactivateSubscription deactivate = new DeactivateSubscription(); deactivate.setDestination(0xFF); deactivate.setSource(ImcMsgManager.getManager().getLocalId().intValue()); try { IridiumManager.getManager().send(deactivate); } catch (Exception ex) { GuiUtils.errorMessage(getConsole(), ex); } } }); popup.add("Set this as actual wave glider target").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setWaveGliderTargetPosition(loc); } }); popup.add("Set this as desired wave glider target").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setWaveGliderDesiredPosition(loc); } }); popup.addSeparator(); popup.add(I18n.text("Send a text note")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sendTextNote(); } }); popup.add("Add virtual drifter").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VirtualDrifter d = new VirtualDrifter(loc, 0, 0.1); PropertiesEditor.editProperties(d, true); drifters.add(d); update(); } }); popup.show(source, event.getX(), event.getY()); }
From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerUtil.java
/** * Creates a {@link MouseListener} to open the selected log folder in MRA. * /*from w ww . jav a2 s . c o m*/ * @param worker * @param logFolderList * @return */ static MouseAdapter createOpenLogInMRAMouseListener(LogsDownloaderWorker worker, LogFolderInfoList logFolderList) { return new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { // Test if log can be opened in MRA, and open it final String baseFxPath = worker.getDirBaseToStoreFiles() + "/" + worker.getLogLabel() + "/" + logFolderList.getSelectedValue() + "/"; File logFolder = new File(baseFxPath); LogValidity isLogOkForOpening = LogUtils.isValidLSFSource(logFolder); JPopupMenu popup = new JPopupMenu(); JMenuItem jm = popup.add(I18n.text("Open this log in MRA")); if (isLogOkForOpening == LogValidity.VALID) { File log = LogUtils.getValidLogFileFromLogFolder(logFolder); jm.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Thread t = new Thread( LogsDownloaderWorker.class.getSimpleName() + " :: MRA Openner") { public void run() { JFrame mra = new NeptusMRA(); mra.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); ((NeptusMRA) mra).getMraFilesHandler().openLog(log); }; }; t.setDaemon(true); t.start(); } }); } else { jm.setEnabled(false); } popup.show((Component) e.getSource(), e.getX(), e.getY()); } } }; }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionDataSource(MouseEvent e) { if (e.getClickCount() == 2) { return;/*from w w w. j a v a 2s . c o m*/ } AddDataSourceAction addDSAction = new AddDataSourceAction(); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(addDSAction); popupMenu.add(menuItem); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionQueryGroup(DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;//ww w. j a v a2s . co m } ImportQueryAction importAction = new ImportQueryAction(); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(importAction); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem(new AddFolderAction(this, selectedNode, DBObject.FOLDER_QUERY)); popupMenu.add(menuItem2); JMenuItem menuItem3 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject())); popupMenu.add(menuItem3); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionQuery(DBBrowserNode selectedNode, MouseEvent e, boolean pressed) { OpenQueryAction openAction = new OpenQueryAction(); openAction.setQueryName(selectedNode.getDBObject().getName()); openAction.setQueryPath(selectedNode.getDBObject().getAbsolutePath()); if (e.getClickCount() == 2) { if (pressed) { openAction.actionPerformed(new ActionEvent(e.getSource(), e.getID(), "")); }//from w ww . j a va 2 s . c om } else { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(openAction); popupMenu.add(menuItem); NewReportFromQueryAction newReportQAction = new NewReportFromQueryAction(); newReportQAction.setQueryName(selectedNode.getDBObject().getName()); newReportQAction.setQueryPath(selectedNode.getDBObject().getAbsolutePath()); JMenuItem menuItem3 = new JMenuItem(newReportQAction); popupMenu.add(menuItem3); NewChartFromQueryAction newChartQAction = new NewChartFromQueryAction(); newChartQAction.setQueryName(selectedNode.getDBObject().getName()); newChartQAction.setQueryPath(selectedNode.getDBObject().getAbsolutePath()); JMenuItem menuItem6 = new JMenuItem(newChartQAction); popupMenu.add(menuItem6); DeleteQueryAction deleteAction = new DeleteQueryAction(instance, selectedNode); JMenuItem menuItem2 = new JMenuItem(deleteAction);// popupMenu.add(menuItem2); RenameQueryAction renameAction = new RenameQueryAction(instance, selectedNode); JMenuItem menuItem4 = new JMenuItem(renameAction); popupMenu.add(menuItem4); ExportQueryAction exportAction = new ExportQueryAction(instance, selectedNode); JMenuItem menuItem5 = new JMenuItem(exportAction); popupMenu.add(menuItem5); JMenuItem menuItem7 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject())); popupMenu.add(menuItem7); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); } }