Example usage for javax.swing JPopupMenu add

List of usage examples for javax.swing JPopupMenu add

Introduction

In this page you can find the example usage for javax.swing JPopupMenu add.

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Appends a new menu item to the end of the menu which dispatches the specified Action object.

Usage

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/*www. j  a v  a2 s.c  o  m*/
            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());
                            }/*from w  ww .j  a v a 2  s  .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 ww  .j  ava 2  s.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.
 * /*ww  w .  ja  v a 2s. 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.ja v a2s.  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;//from  w  w w  . j  a  v a 2 s.c o 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  ww  w  .  j a v a2s.  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());
    }
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void selectionReportGroup(DBBrowserNode selectedNode, MouseEvent e) {
    if (e.getClickCount() == 2) {
        return;/*www. j av  a2s.c  o  m*/
    }
    ImportReportAction importAction = new ImportReportAction();
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem(importAction);
    popupMenu.add(menuItem);
    JMenuItem menuItem2 = new JMenuItem(new AddFolderAction(this, selectedNode, DBObject.FOLDER_REPORT));
    popupMenu.add(menuItem2);
    JMenuItem menuItem3 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject()));
    popupMenu.add(menuItem3);
    JMenuItem menuItem4 = new JMenuItem(new PublishBulkReportAction());
    popupMenu.add(menuItem4);
    JMenuItem menuItem5 = new JMenuItem(
            new DownloadBulkReportAction(FileReportPersistence.getReportsAbsolutePath()));
    popupMenu.add(menuItem5);

    popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void selectionReport(DBBrowserNode selectedNode, MouseEvent e, boolean pressed) {
    OpenReportAction openAction = new OpenReportAction();
    openAction.setReportName(selectedNode.getDBObject().getName());
    openAction.setReportPath(selectedNode.getDBObject().getAbsolutePath());

    if (e.getClickCount() == 2) {
        if (pressed) {
            openAction.actionPerformed(new ActionEvent(e.getSource(), e.getID(), ""));
        }/*from  w w w .  jav  a2s . c om*/
    } else {
        JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(openAction);
        popupMenu.add(menuItem);

        DeleteReportAction deleteAction = new DeleteReportAction(instance, selectedNode);
        JMenuItem menuItem2 = new JMenuItem(deleteAction);
        popupMenu.add(menuItem2);

        RenameReportAction renameAction = new RenameReportAction(instance, selectedNode);
        JMenuItem menuItem3 = new JMenuItem(renameAction);
        popupMenu.add(menuItem3);

        ExportReportAction exportAction = new ExportReportAction(instance, selectedNode);
        JMenuItem menuItem4 = new JMenuItem(exportAction);
        popupMenu.add(menuItem4);

        Report report = FormLoader.getInstance().load(selectedNode.getDBObject().getAbsolutePath(), false);
        JMenu runMenu = new JMenu(I18NSupport.getString("export"));
        Globals.setTreeReportAbsolutePath(selectedNode.getDBObject().getAbsolutePath());
        runMenu.add(new JMenuItem(new ExportToHtmlAction(report)));
        runMenu.add(new JMenuItem(new ExportToExcelAction(report)));
        runMenu.add(new JMenuItem(new ExportToPdfAction(report)));
        runMenu.add(new JMenuItem(new ExportToDocxAction(report)));
        runMenu.add(new JMenuItem(new ExportToRtfAction(report)));
        runMenu.add(new JMenuItem(new ExportToCsvAction(report)));
        runMenu.add(new JMenuItem(new ExportToTsvAction(report)));
        runMenu.add(new JMenuItem(new ExportToXmlAction(report)));
        runMenu.add(new JMenuItem(new ExportToTxtAction(report)));
        popupMenu.add(runMenu);

        PublishReportAction publishAction = new PublishReportAction(
                selectedNode.getDBObject().getAbsolutePath());
        JMenuItem menuItem5 = new JMenuItem(publishAction);
        popupMenu.add(menuItem5);

        JMenuItem menuItem6 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject()));
        popupMenu.add(menuItem6);

        JMenuItem menuItem7 = new JMenuItem(new AddToFavoritesAction(selectedNode.getDBObject()));
        popupMenu.add(menuItem7);

        popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
    }
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void selectionChartGroup(DBBrowserNode selectedNode, MouseEvent e) {
    if (e.getClickCount() == 2) {
        return;//from  ww w. j  ava  2  s  .  c  o m
    }
    JPopupMenu popupMenu = new JPopupMenu();
    ImportChartAction importAction = new ImportChartAction();
    JMenuItem menuItem = new JMenuItem(importAction);
    popupMenu.add(menuItem);
    JMenuItem menuItem2 = new JMenuItem(new AddFolderAction(this, selectedNode, DBObject.FOLDER_CHART));
    popupMenu.add(menuItem2);
    JMenuItem menuItem3 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject()));
    popupMenu.add(menuItem3);
    JMenuItem menuItem4 = new JMenuItem(new PublishBulkChartAction());
    popupMenu.add(menuItem4);
    JMenuItem menuItem5 = new JMenuItem(
            new DownloadBulkChartAction(FileReportPersistence.getChartsAbsolutePath()));
    popupMenu.add(menuItem5);

    popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
}