Search in sources :

Example 66 with AbstractAction

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

the class SignalHeadIcon method setEditIconMenu.

@Override
public boolean setEditIconMenu(JPopupMenu popup) {
    String txt = java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameSignalHead"));
    popup.add(new AbstractAction(txt) {

        @Override
        public void actionPerformed(ActionEvent e) {
            edit();
        }
    });
    return true;
}
Also used : ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 67 with AbstractAction

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

the class SignalMastIcon method showPopUp.

/**
     * Pop-up just displays the name
     */
@Override
public boolean showPopUp(JPopupMenu popup) {
    if (isEditable()) {
        JMenu clickMenu = new JMenu(Bundle.getMessage("WhenClicked"));
        ButtonGroup clickButtonGroup = new ButtonGroup();
        JRadioButtonMenuItem r;
        r = new JRadioButtonMenuItem(Bundle.getMessage("ChangeAspect"));
        r.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setClickMode(0);
            }
        });
        clickButtonGroup.add(r);
        if (clickMode == 0) {
            r.setSelected(true);
        } else {
            r.setSelected(false);
        }
        clickMenu.add(r);
        r = new JRadioButtonMenuItem(Bundle.getMessage("AlternateLit"));
        r.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setClickMode(1);
            }
        });
        clickButtonGroup.add(r);
        if (clickMode == 1) {
            r.setSelected(true);
        } else {
            r.setSelected(false);
        }
        clickMenu.add(r);
        r = new JRadioButtonMenuItem(Bundle.getMessage("AlternateHeld"));
        r.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setClickMode(2);
            }
        });
        clickButtonGroup.add(r);
        if (clickMode == 2) {
            r.setSelected(true);
        } else {
            r.setSelected(false);
        }
        clickMenu.add(r);
        popup.add(clickMenu);
        // add menu to select handling of lit parameter
        JMenu litMenu = new JMenu(Bundle.getMessage("WhenNotLit"));
        litButtonGroup = new ButtonGroup();
        r = new JRadioButtonMenuItem(Bundle.getMessage("ShowAppearance"));
        r.setIconTextGap(10);
        r.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setLitMode(false);
                displayState(mastState());
            }
        });
        litButtonGroup.add(r);
        if (!litMode) {
            r.setSelected(true);
        } else {
            r.setSelected(false);
        }
        litMenu.add(r);
        r = new JRadioButtonMenuItem(Bundle.getMessage("ShowDarkIcon"));
        r.setIconTextGap(10);
        r.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setLitMode(true);
                displayState(mastState());
            }
        });
        litButtonGroup.add(r);
        if (litMode) {
            r.setSelected(true);
        } else {
            r.setSelected(false);
        }
        litMenu.add(r);
        popup.add(litMenu);
        java.util.Enumeration<String> en = getSignalMast().getSignalSystem().getImageTypeList();
        if (en.hasMoreElements()) {
            JMenu iconSetMenu = new JMenu(Bundle.getMessage("SignalMastIconSet"));
            ButtonGroup iconTypeGroup = new ButtonGroup();
            setImageTypeList(iconTypeGroup, iconSetMenu, "default");
            while (en.hasMoreElements()) {
                setImageTypeList(iconTypeGroup, iconSetMenu, en.nextElement());
            }
            popup.add(iconSetMenu);
        }
        popup.add(new jmri.jmrit.signalling.SignallingSourceAction(Bundle.getMessage("SignalMastLogic"), getSignalMast()));
        JMenu aspect = new JMenu(Bundle.getMessage("ChangeAspect"));
        final java.util.Vector<String> aspects = getSignalMast().getValidAspects();
        for (int i = 0; i < aspects.size(); i++) {
            final int index = i;
            aspect.add(new AbstractAction(aspects.elementAt(index)) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    getSignalMast().setAspect(aspects.elementAt(index));
                }
            });
        }
        popup.add(aspect);
        addTransitPopup(popup);
    } else {
        final java.util.Vector<String> aspects = getSignalMast().getValidAspects();
        for (int i = 0; i < aspects.size(); i++) {
            final int index = i;
            popup.add(new AbstractAction(aspects.elementAt(index)) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    getSignalMast().setAspect(aspects.elementAt(index));
                }
            });
        }
    }
    return true;
}
Also used : ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu)

Example 68 with AbstractAction

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

the class SignalHeadIcon method setEditItemMenu.

@Override
public boolean setEditItemMenu(JPopupMenu popup) {
    String txt = java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameSignalHead"));
    popup.add(new AbstractAction(txt) {

        @Override
        public void actionPerformed(ActionEvent e) {
            editItem();
        }
    });
    return true;
}
Also used : ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 69 with AbstractAction

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

the class LayoutTurnout method showPopUp.

/**
     * Display popup menu for information and editing
     */
protected void showPopUp(MouseEvent e) {
    if (popup != null) {
        popup.removeAll();
    } else {
        popup = new JPopupMenu();
    }
    if (layoutEditor.isEditable()) {
        JMenuItem jmi = null;
        switch(getTurnoutType()) {
            case RH_TURNOUT:
                jmi = popup.add(Bundle.getMessage("RightTurnout"));
                break;
            case LH_TURNOUT:
                jmi = popup.add(Bundle.getMessage("LeftTurnout"));
                break;
            case WYE_TURNOUT:
                jmi = popup.add(rb.getString("WYETurnout"));
                break;
            case DOUBLE_XOVER:
                jmi = popup.add(rb.getString("DoubleCrossOver"));
                break;
            case RH_XOVER:
                jmi = popup.add(Bundle.getMessage("RightCrossOver"));
                break;
            case LH_XOVER:
                jmi = popup.add(Bundle.getMessage("LeftCrossOver"));
                break;
            default:
                break;
        }
        jmi.setEnabled(false);
        jmi = popup.add(ident);
        jmi.setEnabled(false);
        if (getTurnout() == null) {
            jmi = popup.add(rb.getString("NoTurnout"));
        } else {
            jmi = popup.add(Bundle.getMessage("BeanNameTurnout") + ": " + turnoutName);
        }
        jmi.setEnabled(false);
        if (blockName.equals("")) {
            jmi = popup.add(rb.getString("NoBlock"));
        } else {
            jmi = popup.add(Bundle.getMessage("BeanNameBlock") + ": " + getLayoutBlock().getID());
        }
        jmi.setEnabled(false);
        if ((type == DOUBLE_XOVER) || (type == RH_XOVER) || (type == LH_XOVER)) {
            // check if extra blocks have been entered
            if (blockB != null) {
                jmi = popup.add(Bundle.getMessage("Block_ID", 2) + ": " + blockBName);
                jmi.setEnabled(false);
            }
            if (blockC != null) {
                jmi = popup.add(Bundle.getMessage("Block_ID", 3) + ": " + blockCName);
                jmi.setEnabled(false);
            }
            if (blockD != null) {
                jmi = popup.add(Bundle.getMessage("Block_ID", 4) + ": " + blockDName);
                jmi.setEnabled(false);
            }
        }
        if (hidden) {
            jmi = popup.add(rb.getString("Hidden"));
        } else {
            jmi = popup.add(rb.getString("NotHidden"));
        }
        jmi.setEnabled(false);
        popup.add(new JSeparator(JSeparator.HORIZONTAL));
        // Rotate if there are no track connections
        if ((connectA == null) && (connectB == null) && (connectC == null) && (connectD == null)) {
            JMenuItem rotateItem = new JMenuItem(rb.getString("Rotate") + "...");
            popup.add(rotateItem);
            rotateItem.addActionListener((ActionEvent event) -> {
                boolean entering = true;
                boolean error = false;
                String newAngle = "";
                while (entering) {
                    // prompt for rotation angle
                    error = false;
                    newAngle = JOptionPane.showInputDialog(layoutEditor, rb.getString("EnterRotation") + " :");
                    if (newAngle.length() < 1) {
                        // cancelled
                        return;
                    }
                    double rot = 0.0;
                    try {
                        rot = Double.parseDouble(newAngle);
                    } catch (Exception e1) {
                        JOptionPane.showMessageDialog(layoutEditor, rb.getString("Error3") + " " + e1, Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                        error = true;
                        newAngle = "";
                    }
                    if (!error) {
                        entering = false;
                        if (rot != 0.0) {
                            rotateCoords(rot);
                            layoutEditor.redrawPanel();
                        }
                    }
                }
            });
        }
        if (disableItem == null) {
            disableItem = new JCheckBoxMenuItem(Bundle.getMessage("Disabled"));
        }
        disableItem.setSelected(disabled);
        popup.add(disableItem);
        disableItem.addActionListener((java.awt.event.ActionEvent e2) -> {
            disabled = disableItem.isSelected();
        });
        if (disableWhenOccupiedItem == null) {
            disableWhenOccupiedItem = new JCheckBoxMenuItem(rb.getString("DisabledWhenOccupied"));
        }
        disableWhenOccupiedItem.setSelected(disableWhenOccupied);
        popup.add(disableWhenOccupiedItem);
        disableWhenOccupiedItem.addActionListener((java.awt.event.ActionEvent e3) -> {
            disableWhenOccupied = disableWhenOccupiedItem.isSelected();
        });
        popup.add(new AbstractAction(rb.getString("UseSizeAsDefault")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                setUpDefaultSize();
            }
        });
        popup.add(new AbstractAction(Bundle.getMessage("ButtonEdit")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                editLayoutTurnout();
            }
        });
        popup.add(new AbstractAction(Bundle.getMessage("ButtonDelete")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (layoutEditor.removeLayoutTurnout(instance)) {
                    // Returned true if user did not cancel
                    remove();
                    dispose();
                }
            }
        });
        if (getTurnout() != null) {
            popup.add(new AbstractAction(rb.getString("SetSignals")) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (tools == null) {
                        tools = new LayoutEditorTools(layoutEditor);
                    }
                    if ((getTurnoutType() == DOUBLE_XOVER) || (getTurnoutType() == RH_XOVER) || (getTurnoutType() == LH_XOVER)) {
                        tools.setSignalsAtXoverTurnoutFromMenu(instance, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    } else if (linkType == NO_LINK) {
                        tools.setSignalsAtTurnoutFromMenu(instance, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    } else if (linkType == THROAT_TO_THROAT) {
                        tools.setThroatToThroatFromMenu(instance, linkedTurnoutName, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    } else if (linkType == FIRST_3_WAY) {
                        tools.set3WayFromMenu(turnoutName, linkedTurnoutName, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    } else if (linkType == SECOND_3_WAY) {
                        tools.set3WayFromMenu(linkedTurnoutName, turnoutName, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    }
                }
            });
        }
        if (!blockName.equals("")) {
            final String[] boundaryBetween = getBlockBoundaries();
            boolean blockBoundaries = false;
            for (int i = 0; i < 4; i++) {
                if (boundaryBetween[i] != null) {
                    blockBoundaries = true;
                }
            }
            if (InstanceManager.getDefault(LayoutBlockManager.class).isAdvancedRoutingEnabled()) {
                if (blockBName.equals("") && blockCName.equals("") && blockDName.equals("")) {
                    popup.add(new AbstractAction(rb.getString("ViewBlockRouting")) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            AbstractAction routeTableAction = new LayoutBlockRouteTableAction("ViewRouting", getLayoutBlock());
                            routeTableAction.actionPerformed(e);
                        }
                    });
                } else {
                    JMenu viewRouting = new JMenu(rb.getString("ViewBlockRouting"));
                    viewRouting.add(new AbstractAction(blockName) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockName, getLayoutBlock());
                            routeTableAction.actionPerformed(e);
                        }
                    });
                    if (!blockBName.equals("") && !blockBName.equals(blockName)) {
                        viewRouting.add(new AbstractAction(blockBName) {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockBName, getLayoutBlockB());
                                routeTableAction.actionPerformed(e);
                            }
                        });
                    }
                    if (!blockCName.equals("") && !blockCName.equals(blockName) && !blockCName.equals(blockBName)) {
                        viewRouting.add(new AbstractAction(blockCName) {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockCName, getLayoutBlockC());
                                routeTableAction.actionPerformed(e);
                            }
                        });
                    }
                    if (!blockDName.equals("") && !blockDName.equals(blockName) && !blockDName.equals(blockBName) && !blockDName.equals(blockCName)) {
                        viewRouting.add(new AbstractAction(blockDName) {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockDName, getLayoutBlockD());
                                routeTableAction.actionPerformed(e);
                            }
                        });
                    }
                    popup.add(viewRouting);
                }
            }
            if (blockBoundaries) {
                popup.add(new AbstractAction(rb.getString("SetSignalMasts")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (tools == null) {
                            tools = new LayoutEditorTools(layoutEditor);
                        }
                        tools.setSignalMastsAtTurnoutFromMenu(instance, boundaryBetween);
                    }
                });
                popup.add(new AbstractAction(rb.getString("SetSensors")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (tools == null) {
                            tools = new LayoutEditorTools(layoutEditor);
                        }
                        tools.setSensorsAtTurnoutFromMenu(instance, boundaryBetween, layoutEditor.sensorIconEditor, layoutEditor.sensorFrame);
                    }
                });
            }
        }
        setAdditionalEditPopUpMenu(popup);
        layoutEditor.setShowAlignmentMenu(popup);
        popup.show(e.getComponent(), e.getX(), e.getY());
    } else if (!viewAdditionalMenu.isEmpty()) {
        setAdditionalViewPopUpMenu(popup);
        popup.show(e.getComponent(), e.getX(), e.getY());
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) LayoutBlockRouteTableAction(jmri.jmrit.display.layoutEditor.blockRoutingTable.LayoutBlockRouteTableAction) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu)

Example 70 with AbstractAction

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

the class LevelXing method showPopUp.

/**
     * Display popup menu for information and editing
     */
protected void showPopUp(MouseEvent e) {
    if (popup != null) {
        popup.removeAll();
    } else {
        popup = new JPopupMenu();
    }
    if (layoutEditor.isEditable()) {
        JMenuItem jmi = popup.add(rb.getString("LevelCrossing"));
        jmi.setEnabled(false);
        jmi = popup.add(ident);
        jmi.setEnabled(false);
        boolean blockACAssigned = false;
        boolean blockBDAssigned = false;
        if ((blockNameAC == null) || (blockNameAC.equals(""))) {
            jmi = popup.add(Bundle.getMessage("NoBlockX", 1));
        } else {
            jmi = popup.add(Bundle.getMessage("Block_ID", 1) + ": " + getLayoutBlockAC().getID());
            blockACAssigned = true;
        }
        jmi.setEnabled(false);
        if ((blockNameBD == null) || (blockNameBD.equals(""))) {
            jmi = popup.add(Bundle.getMessage("NoBlockX", 2));
        } else {
            jmi = popup.add(Bundle.getMessage("Block_ID", 2) + ": " + getLayoutBlockBD().getID());
            blockBDAssigned = true;
        }
        jmi.setEnabled(false);
        if (hidden) {
            jmi = popup.add(rb.getString("Hidden"));
        } else {
            jmi = popup.add(rb.getString("NotHidden"));
        }
        jmi.setEnabled(false);
        popup.add(new JSeparator(JSeparator.HORIZONTAL));
        popup.add(new AbstractAction(Bundle.getMessage("ButtonEdit")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                editLevelXing(instance);
            }
        });
        popup.add(new AbstractAction(Bundle.getMessage("ButtonDelete")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (layoutEditor.removeLevelXing(instance)) {
                    // Returned true if user did not cancel
                    remove();
                    dispose();
                }
            }
        });
        if (blockACAssigned && blockBDAssigned) {
            popup.add(new AbstractAction(rb.getString("SetSignals")) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (tools == null) {
                        tools = new LayoutEditorTools(layoutEditor);
                    }
                    // bring up signals at level crossing tool dialog
                    tools.setSignalsAtLevelXingFromMenu(instance, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                }
            });
        }
        final String[] boundaryBetween = getBlockBoundaries();
        boolean blockBoundaries = false;
        if (jmri.InstanceManager.getDefault(LayoutBlockManager.class).isAdvancedRoutingEnabled()) {
            if (blockACAssigned && !blockBDAssigned) {
                popup.add(new AbstractAction(rb.getString("ViewBlockRouting")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        AbstractAction routeTableAction = new LayoutBlockRouteTableAction("ViewRouting", getLayoutBlockAC());
                        routeTableAction.actionPerformed(e);
                    }
                });
            } else if (!blockACAssigned && blockBDAssigned) {
                popup.add(new AbstractAction(rb.getString("ViewBlockRouting")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        AbstractAction routeTableAction = new LayoutBlockRouteTableAction("ViewRouting", getLayoutBlockBD());
                        routeTableAction.actionPerformed(e);
                    }
                });
            } else if (blockACAssigned && blockBDAssigned) {
                JMenu viewRouting = new JMenu(rb.getString("ViewBlockRouting"));
                viewRouting.add(new AbstractAction(blockNameAC) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockNameAC, getLayoutBlockAC());
                        routeTableAction.actionPerformed(e);
                    }
                });
                viewRouting.add(new AbstractAction(blockNameBD) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockNameBD, getLayoutBlockBD());
                        routeTableAction.actionPerformed(e);
                    }
                });
                popup.add(viewRouting);
            }
        }
        for (int i = 0; i < 4; i++) {
            if (boundaryBetween[i] != null) {
                blockBoundaries = true;
            }
        }
        if (blockBoundaries) {
            popup.add(new AbstractAction(rb.getString("SetSignalMasts")) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (tools == null) {
                        tools = new LayoutEditorTools(layoutEditor);
                    }
                    tools.setSignalMastsAtLevelXingFromMenu(instance, boundaryBetween, layoutEditor.signalFrame);
                }
            });
            popup.add(new AbstractAction(rb.getString("SetSensors")) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (tools == null) {
                        tools = new LayoutEditorTools(layoutEditor);
                    }
                    tools.setSensorsAtLevelXingFromMenu(instance, boundaryBetween, layoutEditor.sensorIconEditor, layoutEditor.sensorFrame);
                }
            });
        }
        layoutEditor.setShowAlignmentMenu(popup);
        popup.show(e.getComponent(), e.getX(), e.getY());
    } else if (!viewAdditionalMenu.isEmpty()) {
        setAdditionalViewPopUpMenu(popup);
        popup.show(e.getComponent(), e.getX(), e.getY());
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) LayoutBlockRouteTableAction(jmri.jmrit.display.layoutEditor.blockRoutingTable.LayoutBlockRouteTableAction) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu)

Aggregations

AbstractAction (javax.swing.AbstractAction)174 ActionEvent (java.awt.event.ActionEvent)162 Action (javax.swing.Action)42 InputMap (javax.swing.InputMap)34 JButton (javax.swing.JButton)33 JMenu (javax.swing.JMenu)30 JPanel (javax.swing.JPanel)30 ActionListener (java.awt.event.ActionListener)24 JMenuItem (javax.swing.JMenuItem)24 ActionMap (javax.swing.ActionMap)23 JScrollPane (javax.swing.JScrollPane)16 JPopupMenu (javax.swing.JPopupMenu)15 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)14 BorderLayout (java.awt.BorderLayout)14 BoxLayout (javax.swing.BoxLayout)12 JSeparator (javax.swing.JSeparator)12 JDialog (javax.swing.JDialog)11 WindowEvent (java.awt.event.WindowEvent)9 JMenuBar (javax.swing.JMenuBar)9 JTextField (javax.swing.JTextField)9