List of usage examples for javax.swing JPopupMenu addSeparator
public void addSeparator()
From source file:processing.app.EditorTab.java
private void configurePopupMenu(final SketchTextArea textarea) { JPopupMenu menu = textarea.getPopupMenu(); menu.addSeparator(); JMenuItem item = editor.createToolMenuItem("cc.arduino.packages.formatter.AStyle"); if (item == null) { throw new NullPointerException("Tool cc.arduino.packages.formatter.AStyle unavailable"); }//w w w .j a v a 2 s . co m item.setName("menuToolsAutoFormat"); menu.add(item); item = new JMenuItem(tr("Comment/Uncomment"), '/'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCommentUncomment(); } }); menu.add(item); item = new JMenuItem(tr("Increase Indent"), ']'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleIndentOutdent(true); } }); menu.add(item); item = new JMenuItem(tr("Decrease Indent"), '['); item.setName("menuDecreaseIndent"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleIndentOutdent(false); } }); menu.add(item); item = new JMenuItem(tr("Copy for Forum")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleDiscourseCopy(); } }); menu.add(item); item = new JMenuItem(tr("Copy as HTML")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleHTMLCopy(); } }); menu.add(item); final JMenuItem referenceItem = new JMenuItem(tr("Find in Reference")); referenceItem.addActionListener(editor::handleFindReference); menu.add(referenceItem); final JMenuItem openURLItem = new JMenuItem(tr("Open URL")); openURLItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Base.openURL(e.getActionCommand()); } }); menu.add(openURLItem); menu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { String referenceFile = editor.base.getPdeKeywords().getReference(getCurrentKeyword()); referenceItem.setEnabled(referenceFile != null); int offset = textarea.getCaretPosition(); org.fife.ui.rsyntaxtextarea.Token token = RSyntaxUtilities.getTokenAtOffset(textarea, offset); if (token != null && token.isHyperlink()) { openURLItem.setEnabled(true); openURLItem.setActionCommand(token.getLexeme()); } else { openURLItem.setEnabled(false); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); }
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 . j av a 2s.c om }); } 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;/*from www .j a va 2 s.c om*/ } 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()); }