Search in sources :

Example 46 with AbstractAction

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

the class CatalogPanel method showPopUp.

/**
     * Return the icon selected in the preview panel Save this code in case
     * there is a need to use an alternative icon changing method rather than
     * DnD.
     *
     * public NamedIcon getSelectedIcon() { if (_selectedImage != null) { JLabel
     * l = (JLabel)_selectedImage.getComponent(0); // deselect
     * //setSelectionBackground(_currentBackground); Save for use as alternative
     * to DnD. _selectedImage = null; return (NamedIcon)l.getIcon(); } return
     * null; }
     */
private void showPopUp(MouseEvent e, NamedIcon icon) {
    if (log.isDebugEnabled()) {
        log.debug("showPopUp {}", icon.toString());
    }
    JPopupMenu popup = new JPopupMenu();
    popup.add(new JMenuItem(icon.getName()));
    popup.add(new JMenuItem(icon.getURL()));
    popup.add(new javax.swing.JPopupMenu.Separator());
    popup.add(new AbstractAction(Bundle.getMessage("RenameIcon")) {

        NamedIcon icon;

        @Override
        public void actionPerformed(ActionEvent e) {
            rename(icon);
        }

        AbstractAction init(NamedIcon i) {
            icon = i;
            return this;
        }
    }.init(icon));
    popup.add(new javax.swing.JPopupMenu.Separator());
    popup.add(new AbstractAction(Bundle.getMessage("DeleteIcon")) {

        NamedIcon icon;

        @Override
        public void actionPerformed(ActionEvent e) {
            delete(icon);
        }

        AbstractAction init(NamedIcon i) {
            icon = i;
            return this;
        }
    }.init(icon));
    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)

Example 47 with AbstractAction

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

the class Editor method setShowTooltipMenu.

/**
     * Add a checkbox to display a tooltip for the Positionable item and if
     * showable, provide a dialog menu to edit it.
     *
     * @param p     the item to set the menu for
     * @param popup the menu to add for p
     */
public void setShowTooltipMenu(Positionable p, JPopupMenu popup) {
    if (p.getDisplayLevel() == BKG) {
        return;
    }
    JMenu edit = new JMenu(Bundle.getMessage("EditTooltip"));
    JCheckBoxMenuItem showTooltipItem = new JCheckBoxMenuItem(Bundle.getMessage("ShowTooltip"));
    showTooltipItem.setSelected(p.showTooltip());
    showTooltipItem.addActionListener(new ActionListener() {

        Positionable comp;

        JCheckBoxMenuItem checkBox;

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            comp.setShowTooltip(checkBox.isSelected());
        }

        ActionListener init(Positionable pos, JCheckBoxMenuItem cb) {
            comp = pos;
            checkBox = cb;
            return this;
        }
    }.init(p, showTooltipItem));
    edit.add(showTooltipItem);
    edit.add(CoordinateEdit.getTooltipEditAction(p));
    jmri.NamedBean bean = p.getNamedBean();
    if (bean != null) {
        edit.add(new AbstractAction(Bundle.getMessage("SetSysNameTooltip")) {

            Positionable comp;

            jmri.NamedBean bean;

            @Override
            public void actionPerformed(ActionEvent e) {
                ToolTip tip = comp.getTooltip();
                if (tip != null) {
                    String uName = bean.getUserName();
                    String sName = bean.getSystemName();
                    if (uName != null && uName.length() > 0) {
                        sName = uName + "(" + sName + ")";
                    }
                    tip.setText(sName);
                }
            }

            AbstractAction init(Positionable pos, jmri.NamedBean b) {
                comp = pos;
                bean = b;
                return this;
            }
        }.init(p, bean));
    }
    popup.add(edit);
}
Also used : NamedBean(jmri.NamedBean) ActionListener(java.awt.event.ActionListener) NamedBean(jmri.NamedBean) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 48 with AbstractAction

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

the class SensorIcon method setEditIconMenu.

@Override
public boolean setEditIconMenu(JPopupMenu popup) {
    String txt = java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameSensor"));
    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 49 with AbstractAction

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

the class SensorIcon method showPopUp.

/**
     * Pop-up just displays the sensor name.
     *
     * @param popup the menu to display
     * @return always true
     */
@Override
public boolean showPopUp(JPopupMenu popup) {
    if (isEditable()) {
        if (isIcon()) {
            popup.add(new AbstractAction(Bundle.getMessage("ChangeToText")) {

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

                @Override
                public void actionPerformed(ActionEvent e) {
                    changeLayoutSensorType();
                }
            });
        }
        popup.add(momentaryItem);
        momentaryItem.setSelected(getMomentary());
        momentaryItem.addActionListener((java.awt.event.ActionEvent e) -> {
            setMomentary(momentaryItem.isSelected());
        });
    } else if (getPopupUtility() != null) {
        getPopupUtility().setAdditionalViewPopUpMenu(popup);
    }
    return true;
}
Also used : ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 50 with AbstractAction

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

the class MemoryIcon method showPopUp.

@Override
public boolean showPopUp(JPopupMenu popup) {
    if (isEditable() && selectable) {
        popup.add(new JSeparator());
        java.util.Iterator<String> iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            //String value = ((NamedIcon)map.get(key)).getName();
            popup.add(new AbstractAction(key) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String key = e.getActionCommand();
                    setValue(key);
                }
            });
        }
        return true;
    }
    // end of selectable
    if (re != null) {
        popup.add(new AbstractAction(Bundle.getMessage("OpenThrottle")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
                tf.toFront();
                tf.getAddressPanel().setRosterEntry(re);
            }
        });
        //don't like the idea of refering specifically to the layout block manager for this, but it has to be done if we are to allow the panel editor to also assign trains to block, when used with a layouteditor
        if ((InstanceManager.getDefault(jmri.SectionManager.class).getSystemNameList().size()) > 0 && jmri.InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getBlockWithMemoryAssigned(getMemory()) != null) {
            final jmri.jmrit.dispatcher.DispatcherFrame df = jmri.InstanceManager.getNullableDefault(jmri.jmrit.dispatcher.DispatcherFrame.class);
            if (df != null) {
                final jmri.jmrit.dispatcher.ActiveTrain at = df.getActiveTrainForRoster(re);
                if (at != null) {
                    popup.add(new AbstractAction(Bundle.getMessage("MenuTerminateTrain")) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            df.terminateActiveTrain(at);
                        }
                    });
                    popup.add(new AbstractAction(Bundle.getMessage("MenuAllocateExtra")) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            //Just brings up the standard allocate extra frame, this could be expanded in the future 
                            //As a point and click operation.
                            df.allocateExtraSection(e, at);
                        }
                    });
                    if (at.getStatus() == jmri.jmrit.dispatcher.ActiveTrain.DONE) {
                        popup.add(new AbstractAction(Bundle.getMessage("MenuRestartTrain")) {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                at.allocateAFresh();
                            }
                        });
                    }
                } else {
                    popup.add(new AbstractAction(Bundle.getMessage("MenuNewTrain")) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (!df.getNewTrainActive()) {
                                df.getActiveTrainFrame().initiateTrain(e, re, jmri.InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getBlockWithMemoryAssigned(getMemory()).getBlock());
                                df.setNewTrainActive(true);
                            } else {
                                df.getActiveTrainFrame().showActivateFrame(re);
                            }
                        }
                    });
                }
            }
        }
        return true;
    }
    return false;
}
Also used : ActionEvent(java.awt.event.ActionEvent) JSeparator(javax.swing.JSeparator) ThrottleFrame(jmri.jmrit.throttle.ThrottleFrame) AbstractAction(javax.swing.AbstractAction)

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