Search in sources :

Example 81 with JMenuItem

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

the class ControlPanelEditor method makeFileMenu.

private void makeFileMenu() {
    _fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    _menuBar.add(_fileMenu, 0);
    _fileMenu.add(new jmri.jmrit.display.NewPanelAction(Bundle.getMessage("MenuItemNew")));
    _fileMenu.add(new jmri.configurexml.StoreXmlUserAction(Bundle.getMessage("MenuItemStore")));
    JMenuItem storeIndexItem = new JMenuItem(Bundle.getMessage("MIStoreImageIndex"));
    _fileMenu.add(storeIndexItem);
    storeIndexItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            jmri.jmrit.catalog.ImageIndexEditor.storeImageIndex();
        }
    });
    JMenuItem editItem = new JMenuItem(Bundle.getMessage("renamePanelMenu", "..."));
    PositionableJComponent z = new PositionableJComponent(this);
    z.setScale(getPaintScale());
    editItem.addActionListener(CoordinateEdit.getNameEditAction(z));
    _fileMenu.add(editItem);
    editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
    _fileMenu.add(editItem);
    editItem.addActionListener(new ActionListener() {

        ControlPanelEditor panelEd;

        @Override
        public void actionPerformed(ActionEvent e) {
            ImageIndexEditor ii = ImageIndexEditor.instance(panelEd);
            ii.pack();
            ii.setVisible(true);
        }

        ActionListener init(ControlPanelEditor pe) {
            panelEd = pe;
            return this;
        }
    }.init(this));
    editItem = new JMenuItem(Bundle.getMessage("PEView"));
    _fileMenu.add(editItem);
    editItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            changeView("jmri.jmrit.display.panelEditor.PanelEditor");
            if (_itemPalette != null) {
                _itemPalette.dispose();
            }
        }
    });
    _fileMenu.addSeparator();
    JMenuItem deleteItem = new JMenuItem(Bundle.getMessage("DeletePanel"));
    _fileMenu.add(deleteItem);
    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            if (deletePanel()) {
                dispose(true);
            }
        }
    });
    _fileMenu.addSeparator();
    editItem = new JMenuItem(Bundle.getMessage("CloseEditor"));
    _fileMenu.add(editItem);
    editItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            setAllEditable(false);
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) PositionableJComponent(jmri.jmrit.display.PositionableJComponent) ActionListener(java.awt.event.ActionListener) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 82 with JMenuItem

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

the class ControlPanelEditor method makeEditMenu.

/**
     * Create an Edit menu to support cut/copy/paste. An incredible hack to get
     * some semblance of CCP between panels. The hack works for one of two
     * problems. 1. Invoking a copy to the system clipboard causes a delayed
     * repaint placed on the EventQueue whenever ScrollBars are invoked. This
     * repaint ends with a null pointer exception at
     * javax.swing.plaf.basic.BasicScrollPaneUI.paint(BasicScrollPaneUI.java:90)
     * This error occurs regardless of the method used to put the copy in the
     * clipboard - JDK 1.2 style or 1.4 TransferHandler Fixed! Get the plaf glue
     * (BasicScrollPaneUI) and call installUI(_panelScrollPane) See
     * copyToClipboard() below, line 527 (something the Java code should have
     * done) No scrollbars - no problem. Hack does not fix this problem. 2. The
     * clipboard provides a shallow copy of what was placed there. For things
     * that have an icon Map (ArrayLists) the Tranferable data is shallow. The
     * Hack to work around this is: Place a reference to the panel copying to
     * the clipboard in the clipboard and let the pasting panel callback to the
     * copying panel to get the data. See public ArrayList<Positionable>
     * getClipGroup() {} below.
     */
protected void makeEditMenu() {
    _editMenu = new JMenu(Bundle.getMessage("ButtonEdit"));
    _menuBar.add(_editMenu, 0);
    _editMenu.setMnemonic(KeyEvent.VK_E);
    /*
         Tutorial recommended method not satisfactory.
         TransferActionListener actionListener = new TransferActionListener();
         JMenuItem menuItem = new JMenuItem("Cut");
         menuItem.setActionCommand((String)TransferHandler.getCutAction().getValue(Action.NAME));
         menuItem.addActionListener(actionListener);
         menuItem.setAccelerator(
         KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
         menuItem.setMnemonic(KeyEvent.VK_T);
         _editMenu.add(menuItem);

         menuItem = new JMenuItem("Copy");
         menuItem.setActionCommand((String)TransferHandler.getCopyAction().getValue(Action.NAME));
         menuItem.addActionListener(actionListener);
         menuItem.setAccelerator(
         KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
         menuItem.setMnemonic(KeyEvent.VK_C);
         _editMenu.add(menuItem);

         menuItem = new JMenuItem("Paste");
         menuItem.setActionCommand((String)TransferHandler.getPasteAction().getValue(Action.NAME));
         menuItem.addActionListener(actionListener);
         menuItem.setAccelerator(
         KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
         menuItem.setMnemonic(KeyEvent.VK_P);
         _editMenu.add(menuItem);
         */
    JMenuItem menuItem = new JMenuItem(Bundle.getMessage("MenuItemCut"));
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            copyToClipboard();
            removeSelections(null);
        }
    });
    if (SystemType.isMacOSX()) {
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.META_MASK));
    } else {
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
    }
    menuItem.setMnemonic(KeyEvent.VK_T);
    _editMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("MenuItemCopy"));
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            copyToClipboard();
        }
    });
    if (SystemType.isMacOSX()) {
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.META_MASK));
    } else {
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    }
    menuItem.setMnemonic(KeyEvent.VK_C);
    _editMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("MenuItemPaste"));
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            pasteFromClipboard();
        }
    });
    if (SystemType.isMacOSX()) {
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.META_MASK));
    } else {
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
    }
    menuItem.setMnemonic(KeyEvent.VK_P);
    _editMenu.add(menuItem);
    _editMenu.add(makeSelectTypeMenu());
    _editMenu.add(makeSelectLevelMenu());
    menuItem = new JMenuItem(Bundle.getMessage("SelectAll"));
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _selectionGroup = _contents;
            _targetPanel.repaint();
        }
    });
    if (SystemType.isMacOSX()) {
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.META_MASK));
    } else {
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    }
    _editMenu.add(menuItem);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 83 with JMenuItem

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

the class JynstrumentPopupMenu method initMenu.

private void initMenu() {
    // Quit option
    JMenuItem quitMenuItem = new JMenuItem(jythonBundle.getString("JynstrumentPopupMenuQuit"));
    quitMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jynstrument.exit();
            jynstrument = null;
        }
    });
    add(quitMenuItem);
    // Edit option
    /*  JMenuItem editMenuItem = new JMenuItem(jythonBundle.getString("JynstrumentPopupMenuEdit"));
         editMenuItem.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
         //   if (!java.awt.Desktop.isDesktopSupported()) //TODO: Need Java 6
         //        return;
         log.debug("Not implemented");
         } 
         } );
         editMenuItem.setEnabled(false);
         add(editMenuItem);    
         // Reload option
         JMenuItem reloadMenuItem = new JMenuItem(jythonBundle.getString("JynstrumentPopupMenuReload"));
         reloadMenuItem.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
         log.debug("Not implemented"); // TODO
         } 
         } );
         reloadMenuItem.setEnabled(false);
         add(reloadMenuItem);*/
    // Debug option
    add(new jmri.jmrit.jython.JythonWindow(jythonBundle.getString("JynstrumentPopupMenuDebug")));
    // A separator to differentiate Jynstrument private menu items
    addSeparator();
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem)

Example 84 with JMenuItem

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

the class SwitchboardEditor method makeFileMenu.

private void makeFileMenu() {
    _fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    _menuBar.add(_fileMenu, 0);
    _fileMenu.add(new jmri.jmrit.display.NewPanelAction(Bundle.getMessage("MenuItemNew")));
    _fileMenu.add(new jmri.configurexml.StoreXmlUserAction(Bundle.getMessage("MenuItemStore")));
    JMenuItem storeIndexItem = new JMenuItem(Bundle.getMessage("MIStoreImageIndex"));
    _fileMenu.add(storeIndexItem);
    storeIndexItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            jmri.jmrit.catalog.ImageIndexEditor.storeImageIndex();
        }
    });
    JMenuItem editItem = new JMenuItem(Bundle.getMessage("renamePanelMenu", "..."));
    PositionableJComponent z = new PositionableJComponent(this);
    z.setScale(getPaintScale());
    editItem.addActionListener(CoordinateEdit.getNameEditAction(z));
    _fileMenu.add(editItem);
    _fileMenu.addSeparator();
    JMenuItem deleteItem = new JMenuItem(Bundle.getMessage("DeletePanel"));
    _fileMenu.add(deleteItem);
    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            if (deletePanel()) {
                dispose(true);
            }
        }
    });
    _fileMenu.addSeparator();
    editItem = new JMenuItem(Bundle.getMessage("CloseEditor"));
    _fileMenu.add(editItem);
    editItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            setAllEditable(false);
            // hide Editor pane
            setVisible(false);
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) PositionableJComponent(jmri.jmrit.display.PositionableJComponent)

Example 85 with JMenuItem

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

the class YardmasterFrame method initComponents.

private void initComponents(Location location) {
    super.initComponents();
    if (location != null) {
        // build menu
        JMenuBar menuBar = new JMenuBar();
        JMenu toolMenu = new JMenu(Bundle.getMessage("MenuTools"));
        toolMenu.add(new YardmasterByTrackAction(location));
        JMenuItem print = toolMenu.add(new PrintSwitchListAction(Bundle.getMessage("MenuItemPrint"), location, false));
        JMenuItem preview = toolMenu.add(new PrintSwitchListAction(Bundle.getMessage("MenuItemPreview"), location, true));
        menuBar.add(toolMenu);
        setJMenuBar(menuBar);
        // add tool tip if in consolidation mode: "Disabled when switch list is in consolidation mode"
        if (!Setup.isSwitchListRealTime()) {
            print.setToolTipText(Bundle.getMessage("TipDisabled"));
            preview.setToolTipText(Bundle.getMessage("TipDisabled"));
        }
        setTitle(Bundle.getMessage("Yardmaster") + " (" + location.getName() + ")");
    }
    // NOI18N
    addHelpMenu("package.jmri.jmrit.operations.Operations_Locations", true);
    initMinimumSize(new Dimension(Control.panelWidth500, Control.panelHeight500));
}
Also used : PrintSwitchListAction(jmri.jmrit.operations.locations.tools.PrintSwitchListAction) Dimension(java.awt.Dimension) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

JMenuItem (javax.swing.JMenuItem)1130 ActionEvent (java.awt.event.ActionEvent)559 ActionListener (java.awt.event.ActionListener)464 JMenu (javax.swing.JMenu)369 JPopupMenu (javax.swing.JPopupMenu)225 JMenuBar (javax.swing.JMenuBar)103 AbstractAction (javax.swing.AbstractAction)90 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)76 ArrayList (java.util.ArrayList)71 JPanel (javax.swing.JPanel)70 Point (java.awt.Point)65 JSeparator (javax.swing.JSeparator)63 File (java.io.File)61 JLabel (javax.swing.JLabel)61 BorderLayout (java.awt.BorderLayout)57 JButton (javax.swing.JButton)54 Component (java.awt.Component)53 ButtonGroup (javax.swing.ButtonGroup)50 Dimension (java.awt.Dimension)46 MouseEvent (java.awt.event.MouseEvent)45