Search in sources :

Example 36 with JCheckBoxMenuItem

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

the class WindowMenu method menuSelected.

@Override
public void menuSelected(MenuEvent e) {
    String windowName;
    framesList = JmriJFrame.getFrameList();
    removeAll();
    add(new AbstractAction(Bundle.getMessage("MenuItemMinimize")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            // the next line works on Java 2, but not 1.1.8
            if (parentFrame != null) {
                parentFrame.setState(Frame.ICONIFIED);
            }
        }
    });
    add(new JSeparator());
    int framesNumber = framesList.size();
    for (int i = 0; i < framesNumber; i++) {
        JmriJFrame iFrame = framesList.get(i);
        windowName = iFrame.getTitle();
        if (windowName.equals("")) {
            windowName = "Untitled";
        }
        JCheckBoxMenuItem newItem = new JCheckBoxMenuItem(new AbstractAction(windowName) {

            @Override
            public void actionPerformed(ActionEvent e) {
                JMenuItem selectedItem = (JMenuItem) e.getSource();
                // Since different windows can have the same name, look for the position of the selected menu item
                int itemCount = getItemCount();
                // Skip possible other items at the top of the menu (for example, "Minimize")
                int firstItem = itemCount - framesList.size();
                for (int i = firstItem; i < itemCount; i++) {
                    if (selectedItem == getItem(i)) {
                        i -= firstItem;
                        // Retrieve the corresponding window
                        if (i < framesList.size()) {
                            // "i" should always be < framesList.size(), but it's better to make sure
                            framesList.get(i).setVisible(true);
                            framesList.get(i).setExtendedState(Frame.NORMAL);
                            return;
                        }
                    }
                }
            }
        });
        if (iFrame == parentFrame) {
            newItem.setState(true);
        }
        add(newItem);
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JSeparator(javax.swing.JSeparator) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 37 with JCheckBoxMenuItem

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

the class PositionableLabel method setDisableControlMenu.

@Override
public boolean setDisableControlMenu(JPopupMenu popup) {
    if (_control) {
        disableItem = new JCheckBoxMenuItem(Bundle.getMessage("Disable"));
        disableItem.setSelected(!_controlling);
        popup.add(disableItem);
        disableItem.addActionListener((java.awt.event.ActionEvent e) -> {
            setControlling(!disableItem.isSelected());
        });
        return true;
    }
    return false;
}
Also used : ActionEvent(java.awt.event.ActionEvent) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 38 with JCheckBoxMenuItem

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

the class PanelMenu method addEditorPanel.

/**
     * Add an Editor panel to Show Panels sub menu
     *
     * @param panel the panel to add to the menu
     */
public void addEditorPanel(final Editor panel) {
    // If this is the first panel, remove the 'No Panels' menu item
    if (panelsList.isEmpty()) {
        panelsSubMenu.remove(noPanelsItem);
    }
    panelsList.add(panel);
    ActionListener a = (ActionEvent e) -> {
        if (panel instanceof LayoutEditor) {
            panel.setVisible(true);
            panel.repaint();
        } else {
            panel.getTargetFrame().setVisible(true);
        }
        updateEditorPanel(panel);
    };
    JCheckBoxMenuItem r = new JCheckBoxMenuItem(panel.getTitle());
    r.addActionListener(a);
    panelsSubMenu.add(r);
    updateEditorPanel(panel);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 39 with JCheckBoxMenuItem

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

the class PanelMenu method renameEditorPanel.

/**
     * Rename an Editor type panel in Show Panels sub menu
     *
     * @param panel the panel to rename
     */
public void renameEditorPanel(Editor panel) {
    if (panelsList.isEmpty()) {
        return;
    }
    for (int i = 0; i < panelsList.size(); i++) {
        Object o = panelsList.get(i);
        if (o == panel) {
            JCheckBoxMenuItem r = (JCheckBoxMenuItem) panelsSubMenu.getItem(i);
            r.setText(panel.getTitle());
            return;
        }
    }
}
Also used : JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 40 with JCheckBoxMenuItem

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

the class PortalIcon method setPositionableMenu.

private void setPositionableMenu(JPopupMenu popup) {
    JCheckBoxMenuItem lockItem = new JCheckBoxMenuItem(Bundle.getMessage("LockPosition"));
    lockItem.setSelected(!isPositionable());
    lockItem.addActionListener(new ActionListener() {

        Positionable comp;

        JCheckBoxMenuItem checkBox;

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

        ActionListener init(Positionable pos, JCheckBoxMenuItem cb) {
            comp = pos;
            checkBox = cb;
            return this;
        }
    }.init(this, lockItem));
    JMenuItem jmi = popup.add(lockItem);
    jmi.setEnabled(false);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Positionable(jmri.jmrit.display.Positionable) JMenuItem(javax.swing.JMenuItem) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Aggregations

JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)48 ActionEvent (java.awt.event.ActionEvent)21 JMenuItem (javax.swing.JMenuItem)21 ActionListener (java.awt.event.ActionListener)18 JMenu (javax.swing.JMenu)17 JPopupMenu (javax.swing.JPopupMenu)12 AbstractAction (javax.swing.AbstractAction)8 JMenuBar (javax.swing.JMenuBar)6 JSeparator (javax.swing.JSeparator)5 JSpinner (javax.swing.JSpinner)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 PropertyChangeListener (java.beans.PropertyChangeListener)4 JTableHeader (javax.swing.table.JTableHeader)4 TableColumn (javax.swing.table.TableColumn)4 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)3 Component (java.awt.Component)2 ItemEvent (java.awt.event.ItemEvent)2 HashMap (java.util.HashMap)2 Action (javax.swing.Action)2 ButtonGroup (javax.swing.ButtonGroup)2