Example usage for javax.swing JPopupMenu show

List of usage examples for javax.swing JPopupMenu show

Introduction

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

Prototype

public void show(Component invoker, int x, int y) 

Source Link

Document

Displays the popup menu at the position x,y in the coordinate space of the component invoker.

Usage

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

public MirthTreeTable(String prefix, Set<String> defaultVisibleColumns) {
    customHiddenColumnMap = new HashMap<String, Set<String>>();

    this.prefix = prefix;
    this.defaultVisibleColumns = defaultVisibleColumns;

    columnOrderMap = new HashMap<String, Integer>();
    sortOrderColumn = -1;/*from   w  ww .  j  av a 2s  .c o m*/
    sortOrder = null;

    if (StringUtils.isNotEmpty(prefix)) {
        try {
            userPreferences = Preferences.userNodeForPackage(Mirth.class);
            String columns = userPreferences.get(prefix + "ColumnOrderMap", "");

            if (StringUtils.isNotEmpty(columns)) {
                columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns,
                        Map.class);
            }
        } catch (Exception e) {
        }

        try {
            String order = userPreferences.get(prefix + "SortOrder", "");

            if (StringUtils.isNotEmpty(order)) {
                sortOrder = ObjectXMLSerializer.getInstance().deserialize(order, SortOrder.class);
                sortOrderColumn = userPreferences.getInt(prefix + "SortOrderColumn", -1);
            }
        } catch (Exception e) {
        }
    }

    addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            boolean isAccelerated = (((e.getModifiers()
                    & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0)
                    || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0));
            if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) {
                PlatformUI.MIRTH_FRAME.doContextSensitiveSave();
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }
    });

    /*
     * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping
     * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can
     * override it.
     */
    putClientProperty("terminateEditOnFocusLost", Boolean.FALSE);

    JTableHeader header = getTableHeader();
    header.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            saveColumnOrder();
        }
    });
    header.setDefaultRenderer(new SortableHeaderCellRenderer(header.getDefaultRenderer()));

    final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon());

    columnControlButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu columnMenu = getColumnMenu();
            Dimension buttonSize = columnControlButton.getSize();
            int xPos = columnControlButton.getComponentOrientation().isLeftToRight()
                    ? buttonSize.width - columnMenu.getPreferredSize().width
                    : 0;
            columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight());
        }

    });

    setColumnControl(columnControlButton);
}

From source file:de.tbuchloh.kiskis.gui.treeview.TreeView.java

/**
 * @param treeContext/*from w w w .  j ava2  s.c o m*/
 */
public TreeView(final JPopupMenu treeContext) {
    final GroupNode root = new GroupNode();
    root.setModelNode(new Group());
    _treeModel = new DefaultTreeModel(root);
    setModel(_treeModel);

    this.setEditable(true);
    this.setCellRenderer(new SpecialNodeCellRenderer());
    this.setCellEditor(new NameCellEditor());
    this.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                LOG.debug("Context Menu invoked!"); //$NON-NLS-1$
                treeContext.show(TreeView.this, e.getX(), e.getY());
            }
        }
    });
    setDragEnabled(true);
    setAutoscrolls(true);
}

From source file:canreg.client.gui.analysis.FrequenciesByYearInternalFrame.java

private void columnTableMousePressed(java.awt.event.MouseEvent evt) {
    if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
        JTable target = (JTable) evt.getSource();
        int columnNumber = target.getSelectedColumn();

        JPopupMenu jpm = new JPopupMenu("" + columnNumber);
        jpm.add(java.util.ResourceBundle
                .getBundle("canreg/client/gui/analysis/resources/FrequenciesByYearInternalFrame")
                .getString("COLUMN ")
                + tableColumnModel.getColumn(tableColumnModel.getColumnIndexAtX(evt.getX())).getHeaderValue());
        jpm.show(target, evt.getX(), evt.getY());
    }/*from w w  w .j  a  v a  2  s. c o m*/
}

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * Build the popup menu to switch between typeAnimation.
 * works only when statistic has observations 
 * Called by MouseListener   //www.  ja v a2  s. co m
 * Event wird nur bearbeitet, wenn die Simulation angehalten ist
 * Im anderen Fall kann der Viewer (inbes. Applet) ueberlastet sein
 * @param event      MouseEvent
 */
private void checkPopupMenu(MouseEvent event) {
    //System.out.println("StatisticGrafic.checkPopupMenu");
    ViewerPanel viewer = this.statistic.getModel().getViewer();
    if (viewer != null && viewer.getSimulationThread() != null && !viewer.getSimulationThread().isWorking()) {
        // Event wird nur bearbeitet, wenn die Simulation angehalten ist
        // Im anderen Fall kann der Viewer (inbes. Applet) ueberlastet sein
        if (event.isPopupTrigger() && this.statistic.hasValue()) {
            JPopupMenu popup = new JPopupMenu();
            JMenuItem mi = new JMenuItem(StatisticGrafic.TEXT_POPUP_MENU[0]);
            mi.addActionListener(this);
            popup.add(mi);
            mi = new JMenuItem(StatisticGrafic.TEXT_POPUP_MENU[1]);
            mi.addActionListener(this);
            popup.add(mi);
            popup.show(event.getComponent(), event.getX(), event.getY());
        }
    }
}

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper method to add a contextual menu on a text component that will allow for Copy & Select All text actions.
 *///from  w  ww .jav  a 2 s . c om
protected void addCopyMenu(final JTextComponent component) {
    Preconditions.checkNotNull(component);

    if (!component.isEditable()) {
        component.setCursor(new Cursor(Cursor.TEXT_CURSOR));
    }

    final JPopupMenu contextMenu = new JPopupMenu();
    JMenuItem copy = new JMenuItem(component.getActionMap().get(DefaultEditorKit.copyAction));
    copy.setText(i18n.getString(I18n.TEXT_COPY_ID));
    contextMenu.add(copy);
    contextMenu.addSeparator();

    JMenuItem selectAll = new JMenuItem(component.getActionMap().get(DefaultEditorKit.selectAllAction));
    selectAll.setText(i18n.getString(I18n.TEXT_SELECT_ALL_ID));
    contextMenu.add(selectAll);

    component.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                contextMenu.show(component, e.getX(), e.getY());
            }
        }
    });
}

From source file:com.univocity.app.swing.DataAnalysisWindow.java

private void addPopupMenuToTable(DaoTable daoTable, boolean isSourceTable) {
    String engineName = isSourceTable ? config.getSourceEngineName() : config.getDestinationEngineName();

    if (engineName == null) {
        return;/*from   www  .  j a v  a 2 s .  c  o m*/
    }

    final JTable table = daoTable.getDataTable();
    final JPopupMenu menu = new JPopupMenu();
    menu.add(newJMenuItem("Disable updates", daoTable, engineName, false, false));
    menu.add(newJMenuItem("Enable updates", daoTable, engineName, true, false));
    menu.add(new JSeparator());
    menu.add(newJMenuItem("Disable updates on all rows", daoTable, engineName, false, true));
    menu.add(newJMenuItem("Enable updates on all rows", daoTable, engineName, true, true));

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                int rowNumber = table.rowAtPoint(e.getPoint());
                if (rowNumber != -1) {
                    table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber);
                    menu.show(table, e.getX(), e.getY());
                }
            }
        };
    });
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

protected void displaySeriesPopup(final JFreeChart chart, final String label, final int series,
        final ColorButton button) {
    JPopupMenu p = new JPopupMenu();
    JMenuItem color = new JMenuItem("Color...");
    p.add(color);//from  w w  w  .  java  2 s.com
    color.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            displayColorPicker(chart, label, series, button);
        }
    });

    JMenuItem remove = new JMenuItem("Remove");
    p.add(remove);
    remove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            removeSeries(chart, series);
        }
    });

    p.show(button, 4, 4);
}

From source file:org.fhaes.jsea.JSEAFrame.java

/**
 * Show popup menu/*from  www.  j a  v a 2  s.  co  m*/
 * 
 * @param component
 * @param popup
 */
private static void addPopup(Component component, final JPopupMenu popup) {

    component.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {

            if (e.isPopupTrigger()) {
                showMenu(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {

            if (e.isPopupTrigger()) {
                showMenu(e);
            }
        }

        private void showMenu(MouseEvent e) {

            popup.show(e.getComponent(), e.getX(), e.getY());
        }
    });
}

From source file:edu.ku.brc.af.ui.forms.ResultSetController.java

/**
 * Creates the UI for the controller./*from ww w .j  a  v  a 2s .  co m*/
 * @param addNewBtn indicates it should include the "Add" (New Object) button
 * @param addDelBtn indicates it should include Delete button
 * @param objTitle the title of a single object in the controller (used for building tooltips)
 */
protected void buildRecordNavBar(final boolean addNewBtn, final boolean addDelBtn, final boolean addSearchBtn,
        final String objTitle) {
    String colDef = "p,2dlu,p,2dlu,max(50dlu;p):grow,2dlu,p,2dlu,p" + (addNewBtn ? ",12px,p" : "")
            + (addDelBtn ? ",2dlu,p" : "") + (addSearchBtn ? ",2dlu,p" : "");

    Insets insets = new Insets(1, 1, 1, 1);
    DefaultFormBuilder rowBuilder = new DefaultFormBuilder(new FormLayout(colDef, "p"));

    firstBtn = UIHelper.createIconBtn("FirstRec", null, null);
    prevBtn = UIHelper.createIconBtn("PrevRec", null, null);
    btnsHash.put(CommandType.Previous, prevBtn);
    btnsHash.put(CommandType.First, firstBtn);

    recDisp = createLabel("  ");
    recDisp.setHorizontalAlignment(SwingConstants.CENTER);
    recDisp.setOpaque(true);
    recDisp.setBackground(Color.WHITE);
    recDisp.setBorder(enabledBorder);
    recDisp.setFont(recDisp.getFont().deriveFont(recDisp.getFont().getSize2D() - 2));

    MouseListener mouseListener = new MouseAdapter() {
        private boolean showIfPopupTrigger(MouseEvent mouseEvent) {
            if (mouseEvent.isPopupTrigger()) {
                JPopupMenu popupMenu = createPopupMenu();
                if (popupMenu != null && popupMenu.getComponentCount() > 0) {
                    popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                    return true;
                }
            }
            return false;
        }

        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            showIfPopupTrigger(mouseEvent);
        }

        @Override
        public void mouseReleased(MouseEvent mouseEvent) {
            showIfPopupTrigger(mouseEvent);
        }

        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
         */
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                if (numRecords == 1) {
                    UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString("OnlyOneRrecordInCon"));
                } else {
                    showGotoRecDlg();
                }
            }
        }
    };
    recDisp.addMouseListener(mouseListener);

    nextBtn = UIHelper.createIconBtn("NextRec", null, null);
    lastBtn = UIHelper.createIconBtn("LastRec", null, null);
    btnsHash.put(CommandType.Next, nextBtn);
    btnsHash.put(CommandType.Last, lastBtn);

    firstBtn.setToolTipText(createTooltip("GotoFirstRecordTT", objTitle));
    prevBtn.setToolTipText(createTooltip("GotoPreviousRecordTT", objTitle));
    nextBtn.setToolTipText(createTooltip("GotoNextRecordTT", objTitle));
    lastBtn.setToolTipText(createTooltip("GotoLastRecordTT", objTitle));

    firstBtn.setOpaque(false);
    prevBtn.setOpaque(false);
    nextBtn.setOpaque(false);
    lastBtn.setOpaque(false);

    CellConstraints cc = new CellConstraints();
    rowBuilder.add(firstBtn, cc.xy(1, 1));
    rowBuilder.add(prevBtn, cc.xy(3, 1));
    rowBuilder.add(recDisp, cc.xy(5, 1));
    rowBuilder.add(nextBtn, cc.xy(7, 1));
    rowBuilder.add(lastBtn, cc.xy(9, 1));
    int col = 11;

    if (addNewBtn) {
        if (false) {
            newRecBtn = new JButton("+") {
                public void setEnabled(boolean enable) {
                    //log.debug("newRecBtn - RS: "+ formValidator.getName() + " " + newRecBtn.hashCode() + " "+enable+"  isNewObj: "+isNewObj);
                    if (formValidator != null && formValidator.getName() != null
                            && formValidator.getName().equals("Collection Object")) {
                        int x = 0;
                        x++;
                        if (enable) {
                            int y = 0;
                            y++;
                        }
                    }
                    if (enable) {
                        int x = 0;
                        x++;
                    }
                    super.setEnabled(enable);
                }
            };
            setControlSize(newRecBtn);

            ActionListener l = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    for (ResultSetControllerListener rscl : listeners) {
                        rscl.newRecordAdded();
                    }
                }
            };
            newRecBtn.addActionListener(l);

        } else {
            newRecBtn = UIHelper.createIconBtn("NewRecord", null, new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    for (ResultSetControllerListener rscl : listeners) {
                        rscl.newRecordAdded();
                    }
                }
            });
        }

        newRecBtn.setToolTipText(createTooltip("NewRecordTT", objTitle));
        newRecBtn.setEnabled(true);
        newRecBtn.setMargin(insets);
        btnsHash.put(CommandType.NewItem, newRecBtn);

        if (doLayoutBtns) {
            rowBuilder.add(newRecBtn, cc.xy(col, 1));
            col += 2;
        }
    }

    if (addDelBtn) {
        if (false) {
            delRecBtn = new JButton("-") {
                public void setEnabled(boolean enable) {
                    //log.debug("delRecBtn - RS: "+formValidator.getName() + " " + hashCode() + " "+enable);
                    if (formValidator != null && formValidator.getName() != null
                            && formValidator.getName().equals("Permit")) {
                        int x = 0;
                        x++;
                    }
                    if (!enable) {
                        int x = 0;
                        x++;
                    }
                    super.setEnabled(enable);
                }
            };
        } else {
            delRecBtn = UIHelper.createIconBtn("DeleteRecord", null, null);
        }
        delRecBtn.setToolTipText(createTooltip("DeleteRecordTT", objTitle));
        delRecBtn.setMargin(insets);
        btnsHash.put(CommandType.DelItem, delRecBtn);

        if (doLayoutBtns) {
            rowBuilder.add(delRecBtn, cc.xy(col, 1));
            col += 2;
        }
    }

    if (addSearchBtn) {
        searchRecBtn = UIHelper.createIconBtn("Search", IconManager.IconSize.Std16, null, null);
        searchRecBtn.setToolTipText(createTooltip("SearchForRecordTT", objTitle));
        searchRecBtn.setMargin(insets);

        if (doLayoutBtns) {
            rowBuilder.add(searchRecBtn, cc.xy(col, 1));
            col += 2;
        }
    }

    firstBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            firstRecord();
        }
    });
    prevBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            prevRecord();
        }
    });
    nextBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            nextRecord();
        }
    });
    lastBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            lastRecord();
        }
    });

    // Make sure it gets centered
    rowBuilder.getPanel().setOpaque(false);
    DefaultFormBuilder outerCenteredPanel = new DefaultFormBuilder(new FormLayout("c:p:g", "p"));
    outerCenteredPanel.add(rowBuilder.getPanel(), cc.xy(1, 1));
    panel = outerCenteredPanel.getPanel();
    panel.setOpaque(false);
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

protected void displayAddPopup(JButton src) {
    JPopupMenu p = new JPopupMenu();

    Map<String, List<Series<?>>> series = sampler.getCategories();

    for (Map.Entry<String, List<Series<?>>> e1 : series.entrySet()) {
        JMenu sm = new JMenu(e1.getKey());
        for (final Series<?> s : e1.getValue()) {
            if (!enabled.contains(s.getKey())) {
                JMenuItem mi = new JMenuItem(s.getLabel());

                mi.addActionListener(new ActionListener() {
                    @Override//from  ww w . j a va 2s .c o  m
                    public void actionPerformed(ActionEvent e) {
                        enable(s);
                    }
                });
                sm.add(mi);
            }
        }
        p.add(sm);
    }

    p.show(src, 4, 4);
}