Example usage for javax.swing JPopupMenu JPopupMenu

List of usage examples for javax.swing JPopupMenu JPopupMenu

Introduction

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

Prototype

public JPopupMenu() 

Source Link

Document

Constructs a JPopupMenu without an "invoker".

Usage

From source file:org.zaproxy.zap.extension.openapi.ImportFromUrlDialog.java

public JTextField addContextMenu(final JTextField field) {
    JPopupMenu jPopupMenu = new JPopupMenu();
    String actionName = Constant.messages.getString(MESSAGE_PREFIX + "pasteaction");
    @SuppressWarnings("serial")
    Action pasteAction = new AbstractAction(actionName) {

        public void actionPerformed(ActionEvent e) {
            field.paste();/*from ww  w .  jav a2  s  . c o m*/
        }
    };
    JMenuItem paste = new JMenuItem(pasteAction);
    jPopupMenu.add(paste);
    field.setComponentPopupMenu(jPopupMenu);
    return field;
}

From source file:org.zaproxy.zap.extension.tlsdebug.TlsDebugPanel.java

protected JPopupMenu getOutputAreaPopupMenu() {
    if (outputAreaPopup == null) {
        outputAreaPopup = new JPopupMenu();

        JMenuItem menuItem = new JMenuItem(Constant.messages.getString("tlsdebug.label.clear"));
        menuItem.addActionListener(new ActionListener() {
            @Override// w  ww .ja v  a 2s . co m
            public void actionPerformed(ActionEvent e) {
                outputArea.setText("");
            }
        });
        outputAreaPopup.add(menuItem);
    }

    return outputAreaPopup;
}

From source file:org.zaproxy.zap.extension.zest.ZestZapUtils.java

private static JPopupMenu getPopupMenu() {
    if (popupMenu == null) {
        popupMenu = new JPopupMenu() {

            private static final long serialVersionUID = 1L;

            @Override/*from w ww  . j  a  va 2 s .  com*/
            public void show(Component invoker, int x, int y) {
                View.getSingleton().getPopupMenu().show(invoker, x, y);
            }
        };
    }
    return popupMenu;
}

From source file:pcgen.gui2.CharacterTabs.java

public CharacterTabs(PCGenFrame frame) {
    this.frame = frame;
    this.characters = new ArrayList<>();
    this.infoTabbedPane = new InfoTabbedPane();
    this.listenerMap = new HashMap<>();
    this.popupMenu = new JPopupMenu();
    initComponents();/*w  w w .  j  a va  2 s.  c o  m*/
}

From source file:picocash.components.mode.buttons.ModeButton.java

private void init() {
    setLayout(new MigLayout("fill"));
    add(iconLabel);/*from  www .  j  av  a 2s .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 v a 2s  .  c  o  m
    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 JPopupMenu initMessageDetailPopupMenu() {
    JPopupMenu jPopupMenu = new JPopupMenu();
    jPopupMenu.add(new CopySelectedText(otrosApplication, logDetailTextArea));
    jPopupMenu.add(new CopyStyledMessageDetailAction(otrosApplication, dateFormat,
            selectedMessageColorizersContainer, selectedMessageFormattersContainer));
    return jPopupMenu;
}

From source file:pl.otros.vfs.browser.VfsBrowser.java

License:asdf

private JPopupMenu addPopupMenu(JList list, String... actions) {
    JPopupMenu favoritesPopupMenu = new JPopupMenu();
    for (String action : actions) {
        favoritesPopupMenu.add(list.getActionMap().get(action));
    }// w  w  w  .  j av a2 s.c  om
    list.addKeyListener(new PopupListener(favoritesPopupMenu));
    list.addMouseListener(new PopupListener(favoritesPopupMenu));
    return favoritesPopupMenu;
}

From source file:plugin.notes.gui.JIcon.java

/**
 *  This method is called from within the constructor to initialize the form.
 *  WARNING: Do NOT modify this code. The content of this method is always
 *  regenerated by the Form Editor.//from  w ww.j  a va  2 s.  c o  m
 */
private void initComponents() {

    contextMenu = new JPopupMenu();
    JMenuItem launchMI = new JMenuItem();
    JMenuItem deleteMI = new JMenuItem();
    button = new JButton();
    label = new JLabel();

    launchMI.setText("Launch File (enter)");
    launchMI.addActionListener(this::launchMIActionPerformed);

    contextMenu.add(launchMI);
    deleteMI.setText("Delete File (del)");
    deleteMI.addActionListener(this::deleteMIActionPerformed);

    contextMenu.add(deleteMI);

    setLayout(new BorderLayout());

    setBackground((Color) UIManager.getDefaults().get("Panel.background"));
    setBorder(new LineBorder(new Color(0, 0, 0)));
    button.setBackground((Color) UIManager.getDefaults().get("Button.background"));
    button.setBorder(null);
    button.addActionListener(this::buttonActionPerformed);

    button.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent evt) {
            buttonFocusGained(evt);
        }

        @Override
        public void focusLost(FocusEvent evt) {
            buttonFocusLost(evt);
        }
    });

    button.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent evt) {
            buttonKeyReleased(evt);
        }
    });

    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            buttonMouseClicked(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            buttonMouseReleased(evt);
        }
    });

    add(button, BorderLayout.NORTH);

    label.setBackground(new Color(204, 204, 204));
    add(label, BorderLayout.CENTER);
}

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//  w ww  .  j av  a  2 s.  co  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());
    }
}