Search in sources :

Example 96 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class ControlPanelEditor method showPopUp.

/**
     * Create popup for a Positionable object Popup items common to all
     * positionable objects are done before and after the items that pertain
     * only to specific Positionable types.
     */
@Override
protected void showPopUp(Positionable p, MouseEvent event) {
    if (!((JComponent) p).isVisible()) {
        // component must be showing on the screen to determine its location
        return;
    }
    JPopupMenu popup = new JPopupMenu();
    PositionablePopupUtil util = p.getPopupUtility();
    if (p.isEditable()) {
        // items common to all
        if (p.doViemMenu()) {
            popup.add(p.getNameString());
            setPositionableMenu(p, popup);
            if (p.isPositionable()) {
                setShowCoordinatesMenu(p, popup);
                setShowAlignmentMenu(p, popup);
            }
            setDisplayLevelMenu(p, popup);
            setHiddenMenu(p, popup);
            popup.addSeparator();
            setCopyMenu(p, popup);
        }
        // items with defaults or using overrides
        boolean popupSet = false;
        //            popupSet |= p.setRotateOrthogonalMenu(popup);
        popupSet |= p.setRotateMenu(popup);
        popupSet |= p.setScaleMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        popupSet = p.setEditItemMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        if (p instanceof PositionableLabel) {
            PositionableLabel pl = (PositionableLabel) p;
            /*                if (pl.isIcon() && "javax.swing.JLabel".equals(pl.getClass().getSuperclass().getName()) ) {
                    popupSet |= setTextAttributes(pl, popup);       // only for plain icons
                }   Add backgrounds & text over icons later */
            if (!pl.isIcon()) {
                popupSet |= setTextAttributes(pl, popup);
                if (p instanceof MemoryIcon) {
                    popupSet |= p.setTextEditMenu(popup);
                }
            } else if (p instanceof SensorIcon) {
                popup.add(CoordinateEdit.getTextEditAction(p, "OverlayText"));
                if (pl.isText()) {
                    popupSet |= setTextAttributes(p, popup);
                }
            } else {
                popupSet = p.setTextEditMenu(popup);
            }
        } else if (p instanceof PositionableJPanel) {
            popupSet |= setTextAttributes(p, popup);
        }
        if (p instanceof LinkingObject) {
            ((LinkingObject) p).setLinkMenu(popup);
        }
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        p.setDisableControlMenu(popup);
        if (util != null) {
            util.setAdditionalEditPopUpMenu(popup);
        }
        // for Positionables with unique settings
        p.showPopUp(popup);
        if (p.doViemMenu()) {
            setShowTooltipMenu(p, popup);
            setRemoveMenu(p, popup);
        }
    } else {
        if (p instanceof LocoIcon) {
            setCopyMenu(p, popup);
        }
        p.showPopUp(popup);
        if (util != null) {
            util.setAdditionalViewPopUpMenu(popup);
        }
    }
    popup.show((Component) p, p.getWidth() / 2 + (int) ((getPaintScale() - 1.0) * p.getX()), p.getHeight() / 2 + (int) ((getPaintScale() - 1.0) * p.getY()));
    _currentSelection = null;
}
Also used : PositionablePopupUtil(jmri.jmrit.display.PositionablePopupUtil) SensorIcon(jmri.jmrit.display.SensorIcon) LinkingObject(jmri.jmrit.display.LinkingObject) LocoIcon(jmri.jmrit.display.LocoIcon) MemoryIcon(jmri.jmrit.display.MemoryIcon) PositionableLabel(jmri.jmrit.display.PositionableLabel) JPopupMenu(javax.swing.JPopupMenu) PositionableJPanel(jmri.jmrit.display.PositionableJPanel)

Example 97 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class TrackSegment method showBezierPopUp.

/**
     * Display popup menu for information and editing.
     */
protected void showBezierPopUp(MouseEvent e, int hitPointType) {
    int bezierControlPointIndex = hitPointType - BEZIER_CONTROL_POINT_OFFSET_MIN;
    if (popup != null) {
        popup.removeAll();
    } else {
        popup = new JPopupMenu();
    }
    JMenuItem jmi = popup.add(rb.getString("BezierControlPoint") + " #" + bezierControlPointIndex);
    jmi.setEnabled(false);
    popup.add(new JSeparator(JSeparator.HORIZONTAL));
    if (bezierControlPoints.size() < BEZIER_CONTROL_POINT_OFFSET_MAX - BEZIER_CONTROL_POINT_OFFSET_MIN) {
        popup.add(new AbstractAction(rb.getString("AddBezierControlPointAfter")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                addBezierControlPointAfter(bezierControlPointIndex);
            }
        });
        popup.add(new AbstractAction(rb.getString("AddBezierControlPointBefore")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                addBezierControlPointBefore(bezierControlPointIndex);
            }
        });
    }
    if (bezierControlPoints.size() > 2) {
        popup.add(new AbstractAction(rb.getString("DeleteBezierControlPoint") + " #" + bezierControlPointIndex) {

            @Override
            public void actionPerformed(ActionEvent e) {
                deleteBezierControlPoint(bezierControlPointIndex);
            }
        });
    }
    popup.show(e.getComponent(), e.getX(), e.getY());
}
Also used : ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator)

Example 98 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class PanelEditor method showMultiSelectPopUp.

protected void showMultiSelectPopUp(final MouseEvent event, Positionable p) {
    JPopupMenu popup = new JPopupMenu();
    // changed "edit" to "copy"
    JMenuItem copy = new JMenuItem(Bundle.getMessage("ButtonCopy"));
    if (p.isPositionable()) {
        setShowAlignmentMenu(p, popup);
    }
    copy.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            _multiItemCopyGroup = new ArrayList<Positionable>();
            // must make a copy or pasteItem() will hang
            if (_selectionGroup != null) {
                for (Positionable comp : _selectionGroup) {
                    _multiItemCopyGroup.add(comp);
                }
            }
        }
    });
    // adding Lock Position for all
    setMultiItemsPositionableMenu(popup);
    // selected items
    setRemoveMenu(p, popup);
    //showAddItemPopUp(event, popup); // no need to Add when group selected
    popup.add(copy);
    popup.show(event.getComponent(), event.getX(), event.getY());
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) Positionable(jmri.jmrit.display.Positionable) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 99 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class PanelEditor method pasteItemPopUp.

protected void pasteItemPopUp(final MouseEvent event) {
    if (!isEditable()) {
        return;
    }
    if (_multiItemCopyGroup == null) {
        return;
    }
    JPopupMenu popup = new JPopupMenu();
    JMenuItem edit = new JMenuItem("Paste");
    edit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            pasteItem(event);
        }
    });
    setBackgroundMenu(popup);
    showAddItemPopUp(event, popup);
    popup.add(edit);
    popup.show(event.getComponent(), event.getX(), event.getY());
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 100 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class PanelEditor method backgroundPopUp.

protected void backgroundPopUp(MouseEvent event) {
    if (!isEditable()) {
        return;
    }
    JPopupMenu popup = new JPopupMenu();
    setBackgroundMenu(popup);
    showAddItemPopUp(event, popup);
    popup.show(event.getComponent(), event.getX(), event.getY());
}
Also used : JPopupMenu(javax.swing.JPopupMenu)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)128 JMenuItem (javax.swing.JMenuItem)56 ActionEvent (java.awt.event.ActionEvent)34 ActionListener (java.awt.event.ActionListener)20 JMenu (javax.swing.JMenu)19 Component (java.awt.Component)17 JButton (javax.swing.JButton)16 JScrollPane (javax.swing.JScrollPane)15 AbstractAction (javax.swing.AbstractAction)14 JLabel (javax.swing.JLabel)14 MouseEvent (java.awt.event.MouseEvent)13 Point (java.awt.Point)11 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)11 JSeparator (javax.swing.JSeparator)11 JPanel (javax.swing.JPanel)10 JTable (javax.swing.JTable)10 Dimension (java.awt.Dimension)7 ArrayList (java.util.ArrayList)7 JTextArea (javax.swing.JTextArea)7 JCheckBox (javax.swing.JCheckBox)6