Search in sources :

Example 41 with JMenuBar

use of javax.swing.JMenuBar in project Gargoyle by callakrsos.

the class DesignerFx method createFxMenuBar.

//	private JMenuBar createMenuBar() {
//		JMenuBar menuBar = new JMenuBar();
//		JMenu menu = new JMenu("Language");
//		ButtonGroup group = new ButtonGroup();
//
//		LanguageVersion[] languageVersions = getSupportedLanguageVersions();
//		for (int i = 0; i < languageVersions.length; i++) {
//			LanguageVersion languageVersion = languageVersions[i];
//			MenuItem button = new MenuItem(languageVersion.getShortName());
//			languageVersionMenuItems[i] = button;
//			group.add(button);
//			menu.add(button);
//		}
//		languageVersionMenuItems[DEFAULT_LANGUAGE_VERSION_SELECTION_INDEX].setSelected(true);
//		menuBar.add(menu);
//
//		JMenu actionsMenu = new JMenu("Actions");
//		JMenuItem copyXMLItem = new JMenuItem("Copy xml to clipboard");
//		copyXMLItem.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				copyXmlToClipboard();
//			}
//		});
//		actionsMenu.add(copyXMLItem);
//		JMenuItem createRuleXMLItem = new JMenuItem("Create rule XML");
//		createRuleXMLItem.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				createRuleXML();
//			}
//		});
//		actionsMenu.add(createRuleXMLItem);
//		menuBar.add(actionsMenu);
//
//		return menuBar;
//	}
private MenuBar createFxMenuBar() {
    MenuBar menuBar = new MenuBar();
    Menu menu = new Menu("Language");
    ToggleGroup group = new ToggleGroup();
    LanguageVersion[] languageVersions = getSupportedLanguageVersions();
    for (int i = 0; i < languageVersions.length; i++) {
        LanguageVersion languageVersion = languageVersions[i];
        //			JRadioButtonMenuItem button = new JRadioButtonMenuItem(languageVersion.getShortName());
        RadioMenuItem button = new RadioMenuItem(languageVersion.getShortName());
        button.setToggleGroup(group);
        languageVersionMenuItems[i] = button;
        //			group.add(button);
        menu.getItems().add(button);
    }
    //		languageVersionMenuItems[DEFAULT_LANGUAGE_VERSION_SELECTION_INDEX].setSelected(true);
    languageVersionMenuItems[getDefaultLanguageVersionSelectionIndex()].setSelected(true);
    menuBar.getMenus().add(menu);
    Menu actionsMenu = new Menu("Actions");
    MenuItem copyXMLItem = new MenuItem("Copy xml to clipboard");
    copyXMLItem.setOnAction(e -> copyXmlToClipboard());
    actionsMenu.getItems().add(copyXMLItem);
    MenuItem createRuleXMLItem = new MenuItem("Create rule XML");
    createRuleXMLItem.setOnAction(e -> createRuleXML());
    actionsMenu.getItems().add(createRuleXMLItem);
    menuBar.getMenus().add(actionsMenu);
    return menuBar;
}
Also used : ToggleGroup(javafx.scene.control.ToggleGroup) JMenuBar(javax.swing.JMenuBar) MenuBar(javafx.scene.control.MenuBar) LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) MenuItem(javafx.scene.control.MenuItem) RadioMenuItem(javafx.scene.control.RadioMenuItem) Menu(javafx.scene.control.Menu) RadioMenuItem(javafx.scene.control.RadioMenuItem)

Example 42 with JMenuBar

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

the class SectionTableAction method setMenuBar.

/**
     * Insert 2 table specific menus.
     * Account for the Window and Help menus, which are already added to the menu bar
     * as part of the creation of the JFrame, by adding the menus 2 places earlier
     * unless the table is part of the ListedTableFrame, that adds the Help menu later on.
     * @param f the JFrame of this table
     */
@Override
public void setMenuBar(BeanTableFrame f) {
    frame = f;
    JMenuBar menuBar = f.getJMenuBar();
    // count the number of menus to insert the TableMenu before 'Window' and 'Help'
    int pos = menuBar.getMenuCount() - 1;
    int offset = 1;
    log.debug("setMenuBar number of menu items = " + pos);
    for (int i = 0; i <= pos; i++) {
        if (menuBar.getComponent(i) instanceof JMenu) {
            if (((JMenu) menuBar.getComponent(i)).getText().equals(Bundle.getMessage("MenuHelp"))) {
                // correct for use as part of ListedTableAction where the Help Menu is not yet present
                offset = -1;
            }
        }
    }
    JMenu toolsMenu = new JMenu(Bundle.getMessage("MenuTools"));
    menuBar.add(toolsMenu, pos + offset);
    JMenuItem validate = new JMenuItem(rbx.getString("ValidateAllSections") + "...");
    toolsMenu.add(validate);
    validate.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (sectionManager != null) {
                initializeLayoutEditor(false);
                int n = sectionManager.validateAllSections(frame, panel);
                if (n > 0) {
                    JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(rbx.getString("Message14"), new Object[] { "" + n }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                } else if (n == -2) {
                    JOptionPane.showMessageDialog(frame, rbx.getString("Message16"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                } else if (n == 0) {
                    JOptionPane.showMessageDialog(frame, rbx.getString("Message15"), rbx.getString("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
                }
            }
        }
    });
    JMenuItem setDirSensors = new JMenuItem(rbx.getString("SetupDirectionSensors") + "...");
    toolsMenu.add(setDirSensors);
    setDirSensors.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (sectionManager != null) {
                if (initializeLayoutEditor(true)) {
                    int n = sectionManager.setupDirectionSensors(panel);
                    if (n > 0) {
                        JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(rbx.getString("Message27"), new Object[] { "" + n }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                    } else if (n == -2) {
                        JOptionPane.showMessageDialog(frame, rbx.getString("Message30"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                    } else if (n == 0) {
                        JOptionPane.showMessageDialog(frame, rbx.getString("Message28"), rbx.getString("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
                    }
                }
            }
        }
    });
    JMenuItem removeDirSensors = new JMenuItem(rbx.getString("RemoveDirectionSensors") + "...");
    toolsMenu.add(removeDirSensors);
    removeDirSensors.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (sectionManager != null) {
                if (initializeLayoutEditor(true)) {
                    int n = sectionManager.removeDirectionSensorsFromSSL(panel);
                    if (n > 0) {
                        JOptionPane.showMessageDialog(frame, java.text.MessageFormat.format(rbx.getString("Message33"), new Object[] { "" + n }), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                    } else if (n == -2) {
                        JOptionPane.showMessageDialog(frame, rbx.getString("Message32"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                    } else if (n == 0) {
                        JOptionPane.showMessageDialog(frame, rbx.getString("Message31"), rbx.getString("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
                    }
                }
            }
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) EntryPoint(jmri.EntryPoint) JMenu(javax.swing.JMenu)

Example 43 with JMenuBar

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

the class SensorTableAction method setMenuBar.

/**
     * Insert a table specific Defaults menu.
     * Account for the Window and Help menus, which are already added to the menu bar
     * as part of the creation of the JFrame, by adding the Tools menu 2 places earlier
     * unless the table is part of the ListedTableFrame, that adds the Help menu later on.
     * @param f the JFrame of this table
     */
@Override
public void setMenuBar(BeanTableFrame f) {
    // needed for anonymous ActionListener class
    final jmri.util.JmriJFrame finalF = f;
    JMenuBar menuBar = f.getJMenuBar();
    // check for menu
    boolean menuAbsent = true;
    for (int m = 0; m < menuBar.getMenuCount(); ++m) {
        String name = menuBar.getMenu(m).getAccessibleContext().getAccessibleName();
        if (name.equals(Bundle.getMessage("MenuDefaults"))) {
            // using first menu for check, should be identical to next JMenu Bundle
            menuAbsent = false;
            break;
        }
    }
    if (menuAbsent) {
        // create it
        JMenu optionsMenu = new JMenu(Bundle.getMessage("MenuDefaults"));
        JMenuItem item = new JMenuItem(Bundle.getMessage("GlobalDebounce"));
        optionsMenu.add(item);
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setDefaultDebounce(finalF);
            }
        });
        item = new JMenuItem(Bundle.getMessage("InitialSensorState"));
        optionsMenu.add(item);
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setDefaultState(finalF);
            }
        });
        // count the number of menus to insert the TableMenus before 'Window' and 'Help'
        int pos = menuBar.getMenuCount() - 1;
        int offset = 1;
        log.debug("setMenuBar number of menu items = " + pos);
        for (int i = 0; i <= pos; i++) {
            if (menuBar.getComponent(i) instanceof JMenu) {
                if (((JMenu) menuBar.getComponent(i)).getText().equals(Bundle.getMessage("MenuHelp"))) {
                    // correct for use as part of ListedTableAction where the Help Menu is not yet present
                    offset = -1;
                }
            }
        }
        menuBar.add(optionsMenu, pos + offset);
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JmriJFrame(jmri.util.JmriJFrame) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 44 with JMenuBar

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

the class TableFrames method initComponents.

@Override
public void initComponents() {
    setTitle(Bundle.getMessage("TitleOBlocks"));
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    fileMenu.add(new jmri.configurexml.SaveMenu());
    JMenuItem printItem = new JMenuItem(Bundle.getMessage("PrintOBlockTable"));
    fileMenu.add(printItem);
    printItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                // MessageFormat headerFormat = new MessageFormat(getTitle());  // not used below
                MessageFormat footerFormat = new MessageFormat(getTitle() + " page {0,number}");
                _oBlockTable.print(JTable.PrintMode.FIT_WIDTH, null, footerFormat);
            } catch (java.awt.print.PrinterException e1) {
                log.warn("error printing: " + e1, e1);
            }
        }
    });
    printItem = new JMenuItem(Bundle.getMessage("PrintPortalTable"));
    fileMenu.add(printItem);
    printItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                // MessageFormat headerFormat = new MessageFormat(getTitle());  // not used below
                MessageFormat footerFormat = new MessageFormat(getTitle() + " page {0,number}");
                _portalTable.print(JTable.PrintMode.FIT_WIDTH, null, footerFormat);
            } catch (java.awt.print.PrinterException e1) {
                log.warn("error printing: " + e1, e1);
            }
        }
    });
    printItem = new JMenuItem(Bundle.getMessage("PrintSignalTable"));
    fileMenu.add(printItem);
    printItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                // MessageFormat headerFormat = new MessageFormat(getTitle());  // not used below
                MessageFormat footerFormat = new MessageFormat(getTitle() + " page {0,number}");
                _signalTable.print(JTable.PrintMode.FIT_WIDTH, null, footerFormat);
            } catch (java.awt.print.PrinterException e1) {
                log.warn("error printing: " + e1, e1);
            }
        }
    });
    printItem = new JMenuItem(Bundle.getMessage("PrintXRef"));
    fileMenu.add(printItem);
    printItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                // MessageFormat headerFormat = new MessageFormat(getTitle());  // not used below
                MessageFormat footerFormat = new MessageFormat(getTitle() + " page {0,number}");
                _blockPortalTable.print(JTable.PrintMode.FIT_WIDTH, null, footerFormat);
            } catch (java.awt.print.PrinterException e1) {
                log.warn("error printing: " + e1, e1);
            }
        }
    });
    menuBar.add(fileMenu);
    JMenu editMenu = new JMenu(Bundle.getMessage("MenuEdit"));
    editMenu.setMnemonic(KeyEvent.VK_E);
    TransferActionListener actionListener = new TransferActionListener();
    JMenuItem menuItem = new JMenuItem(Bundle.getMessage("MenuItemCut"));
    menuItem.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME));
    menuItem.addActionListener(actionListener);
    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.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME));
    menuItem.addActionListener(actionListener);
    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.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME));
    menuItem.addActionListener(actionListener);
    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);
    menuBar.add(editMenu);
    JMenu optionMenu = new JMenu(Bundle.getMessage("MenuOptions"));
    _showWarnItem = new JMenuItem(Bundle.getMessage("SuppressWarning"));
    _showWarnItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            String cmd = event.getActionCommand();
            setShowWarnings(cmd);
        }
    });
    optionMenu.add(_showWarnItem);
    setShowWarnings("ShowWarning");
    menuBar.add(optionMenu);
    _openMenu = new JMenu(Bundle.getMessage("OpenMenu"));
    // replaces the last item with appropriate
    updateOpenMenu();
    menuBar.add(_openMenu);
    setJMenuBar(menuBar);
    addHelpMenu("package.jmri.jmrit.logix.OBlockTable", true);
    _desktop = new JDesktopPane();
    _desktop.putClientProperty("JDesktopPane.dragMode", "outline");
    _desktop.setPreferredSize(new Dimension(1100, 550));
    setContentPane(_desktop);
    _blockTableFrame = makeBlockFrame();
    _blockTableFrame.setVisible(true);
    _desktop.add(_blockTableFrame);
    _portalTableFrame = makePortalFrame();
    _portalTableFrame.setVisible(true);
    _desktop.add(_portalTableFrame);
    _signalTableFrame = makeSignalFrame();
    _signalTableFrame.setVisible(true);
    _desktop.add(_signalTableFrame);
    _blockPortalXRefFrame = makeBlockPortalFrame();
    _blockPortalXRefFrame.setVisible(false);
    _desktop.add(_blockPortalXRefFrame);
    setLocation(10, 30);
    setVisible(true);
    pack();
    errorCheck();
}
Also used : JDesktopPane(javax.swing.JDesktopPane) MessageFormat(java.text.MessageFormat) ActionEvent(java.awt.event.ActionEvent) TransferActionListener(jmri.util.com.sun.TransferActionListener) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) TransferActionListener(jmri.util.com.sun.TransferActionListener) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 45 with JMenuBar

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

the class ImageIndexEditor method init.

private void init(Editor editor) {
    JMenuBar menuBar = new JMenuBar();
    JMenu findIcon = new JMenu(Bundle.getMessage("MenuFile"));
    menuBar.add(findIcon);
    JMenuItem storeItem = new JMenuItem(Bundle.getMessage("MIStoreImageIndex"));
    findIcon.add(storeItem);
    storeItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            storeImageIndex();
        }
    });
    findIcon.addSeparator();
    JMenuItem openItem = new JMenuItem(Bundle.getMessage("openDirMenu"));
    openItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DirectorySearcher.instance().openDirectory();
        }
    });
    findIcon.add(openItem);
    JMenuItem searchItem = new JMenuItem(Bundle.getMessage("searchFSMenu"));
    searchItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jmri.jmrit.catalog.DirectorySearcher.instance().searchFS();
        }
    });
    findIcon.add(searchItem);
    JMenu editMenu = new JMenu(Bundle.getMessage("EditIndexMenu"));
    menuBar.add(editMenu);
    JMenuItem addItem = new JMenuItem(Bundle.getMessage("addNode"));
    addItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addNode();
        }
    });
    editMenu.add(addItem);
    JMenuItem renameItem = new JMenuItem(Bundle.getMessage("renameNode"));
    renameItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            renameNode();
        }
    });
    editMenu.add(renameItem);
    JMenuItem deleteItem = new JMenuItem(Bundle.getMessage("deleteNode"));
    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteNode();
        }
    });
    editMenu.add(deleteItem);
    setJMenuBar(menuBar);
    addHelpMenu("package.jmri.jmrit.catalog.ImageIndex", true);
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    JPanel labelPanel = new JPanel();
    labelPanel.add(new JLabel(Bundle.getMessage("dragIconsInstr"), SwingConstants.LEFT));
    mainPanel.add(labelPanel);
    JPanel catalogsPanel = new JPanel();
    catalogsPanel.setLayout(new BoxLayout(catalogsPanel, BoxLayout.X_AXIS));
    catalogsPanel.add(makeCatalogPanel());
    catalogsPanel.add(new JSeparator(SwingConstants.VERTICAL));
    catalogsPanel.add(makeIndexPanel());
    mainPanel.add(catalogsPanel);
    getContentPane().add(mainPanel);
    addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            DirectorySearcher.instance().close();
        }
    });
    setLocation(10, 200);
    pack();
    setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JSeparator(javax.swing.JSeparator) ActionListener(java.awt.event.ActionListener) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

JMenuBar (javax.swing.JMenuBar)119 JMenu (javax.swing.JMenu)83 JMenuItem (javax.swing.JMenuItem)45 ActionEvent (java.awt.event.ActionEvent)36 ActionListener (java.awt.event.ActionListener)30 JPanel (javax.swing.JPanel)28 BoxLayout (javax.swing.BoxLayout)25 Dimension (java.awt.Dimension)23 JFrame (javax.swing.JFrame)17 JScrollPane (javax.swing.JScrollPane)15 JLabel (javax.swing.JLabel)14 JButton (javax.swing.JButton)13 JmriJFrame (jmri.util.JmriJFrame)12 GridBagLayout (java.awt.GridBagLayout)11 BorderLayout (java.awt.BorderLayout)10 JSeparator (javax.swing.JSeparator)10 AbstractAction (javax.swing.AbstractAction)9 FlowLayout (java.awt.FlowLayout)6 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)6 JPopupMenu (javax.swing.JPopupMenu)6