Search in sources :

Example 76 with JMenuBar

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

the class AudioTableAction method setMenuBar.

@Override
public void setMenuBar(BeanTableFrame f) {
    JMenuBar menuBar = f.getJMenuBar();
    ResourceBundle rbapps = ResourceBundle.getBundle("apps.AppsBundle");
    MenuElement[] subElements;
    JMenu fileMenu = null;
    for (int i = 0; i < menuBar.getMenuCount(); i++) {
        if (menuBar.getComponent(i) instanceof JMenu) {
            if (((JMenu) menuBar.getComponent(i)).getText().equals(Bundle.getMessage("MenuFile"))) {
                fileMenu = menuBar.getMenu(i);
            }
        }
    }
    if (fileMenu == null) {
        return;
    }
    subElements = fileMenu.getSubElements();
    for (MenuElement subElement : subElements) {
        MenuElement[] popsubElements = subElement.getSubElements();
        for (MenuElement popsubElement : popsubElements) {
            if (popsubElement instanceof JMenuItem) {
                if (((JMenuItem) popsubElement).getText().equals(rbapps.getString("PrintTable"))) {
                    JMenuItem printMenu = (JMenuItem) popsubElement;
                    fileMenu.remove(printMenu);
                    break;
                }
            }
        }
    }
    fileMenu.add(atp.getPrintItem());
}
Also used : ResourceBundle(java.util.ResourceBundle) JMenuItem(javax.swing.JMenuItem) MenuElement(javax.swing.MenuElement) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 77 with JMenuBar

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

the class SignalMastLogicTableAction method setMenuBar.

/**
     * Insert a table specific Tools 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();
    // 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 pathMenu = new JMenu(Bundle.getMessage("MenuTools"));
    menuBar.add(pathMenu, pos + offset);
    JMenuItem item = new JMenuItem(Bundle.getMessage("MenuItemAutoGen"));
    pathMenu.add(item);
    item.addActionListener(new ActionListener() {

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

        @Override
        public void actionPerformed(ActionEvent e) {
            ((jmri.managers.DefaultSignalMastLogicManager) InstanceManager.getDefault(jmri.SignalMastLogicManager.class)).generateSection();
            JOptionPane.showMessageDialog(null, Bundle.getMessage("SectionGenerationComplete"));
        }
    });
}
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 78 with JMenuBar

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

the class SignalMastTableAction method setMenuBar.

/**
     * Insert a table specific Tools 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) {
    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 pathMenu = new JMenu(Bundle.getMessage("MenuTools"));
    menuBar.add(pathMenu, pos + offset);
    JMenuItem item = new JMenuItem(Bundle.getMessage("MenuItemRepeaters"));
    pathMenu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jmri.jmrit.beantable.signalmast.SignalMastRepeaterJFrame frame = new jmri.jmrit.beantable.signalmast.SignalMastRepeaterJFrame();
            frame.setVisible(true);
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) ActionListener(java.awt.event.ActionListener) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 79 with JMenuBar

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

the class SwitchboardEditor method makeFrame.

/**
     * Create sequence of panels, etc. for layout: JFrame contains its
     * ContentPane which contains a JPanel with BoxLayout (p1) which contains a
     * JScollPane (js) which contains the targetPane.
     *
     * @param name name for the Switchboard
     */
public JmriJFrame makeFrame(String name) {
    JmriJFrame targetFrame = new JmriJFrame(name);
    targetFrame.setVisible(true);
    JMenuBar menuBar = new JMenuBar();
    JMenu editMenu = new JMenu(Bundle.getMessage("MenuEdit"));
    menuBar.add(editMenu);
    editMenu.add(new AbstractAction(Bundle.getMessage("OpenEditor")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(true);
        }
    });
    targetFrame.setJMenuBar(menuBar);
    targetFrame.addHelpMenu("package.jmri.jmrit.display.SwitchboardEditor", true);
    return targetFrame;
}
Also used : JmriJFrame(jmri.util.JmriJFrame) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 80 with JMenuBar

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

the class WarrantTableFrame method initComponents.

/**
     * By default, Swing components should be created an installed in this
     * method, rather than in the ctor itself.
     */
@Override
public void initComponents() throws Exception {
    //Casts at getTableCellEditorComponent() now fails with 3.0 ??
    JTable table = new JTable(_model);
    ComboBoxCellEditor comboEd;
    TableRowSorter<WarrantTableModel> sorter = new TableRowSorter<>(_model);
    comboEd = new ComboBoxCellEditor(new JComboBox<>());
    table.setRowSorter(sorter);
    // Use XTableColumnModel so we can control which columns are visible
    XTableColumnModel tcm = new XTableColumnModel();
    table.setColumnModel(tcm);
    table.getTableHeader().setReorderingAllowed(true);
    table.createDefaultColumnsFromModel();
    _model.addHeaderListener(table);
    table.setDefaultRenderer(Boolean.class, new ButtonRenderer());
    table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
    table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
    JComboBox<String> box = new JComboBox<>(controls);
    box.setFont(new Font(null, Font.PLAIN, 12));
    table.getColumnModel().getColumn(WarrantTableModel.CONTROL_COLUMN).setCellEditor(new DefaultCellEditor(box));
    table.getColumnModel().getColumn(WarrantTableModel.ROUTE_COLUMN).setCellEditor(comboEd);
    table.getColumnModel().getColumn(WarrantTableModel.ALLOCATE_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.ALLOCATE_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.DEALLOC_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.DEALLOC_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.SET_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.SET_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.AUTO_RUN_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.AUTO_RUN_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.MANUAL_RUN_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.MANUAL_RUN_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.EDIT_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.EDIT_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.DELETE_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.DELETE_COLUMN).setCellRenderer(new ButtonRenderer());
    //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (int i = 0; i < _model.getColumnCount(); i++) {
        int width = _model.getPreferredWidth(i);
        table.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    tcm.setColumnVisible(tcm.getColumnByModelIndex(WarrantTableModel.MANUAL_RUN_COLUMN), false);
    _rowHeight = box.getPreferredSize().height;
    table.setRowHeight(_rowHeight);
    table.setDragEnabled(true);
    table.setTransferHandler(new jmri.util.DnDTableExportHandler());
    _tablePane = new JScrollPane(table);
    JPanel tablePanel = new JPanel();
    tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.Y_AXIS));
    tablePanel.add(Box.createVerticalGlue());
    JLabel title = new JLabel(Bundle.getMessage("ShowWarrants"));
    tablePanel.add(title);
    tablePanel.add(_tablePane);
    JPanel bottom = new JPanel();
    JPanel panel = new JPanel();
    JButton nxButton = new JButton(Bundle.getMessage("CreateNXWarrant"));
    nxButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            nxAction();
        }
    });
    panel.add(nxButton);
    panel.add(Box.createGlue());
    panel.add(new JLabel("status"));
    _status.addMouseListener(this);
    _status.setBackground(Color.white);
    _status.setFont(_status.getFont().deriveFont(Font.BOLD));
    _status.setEditable(false);
    setStatusText(BLANK.substring(0, 90), null, false);
    panel.add(_status);
    JButton haltAllButton = new JButton(Bundle.getMessage("HaltAllTrains"));
    haltAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            haltAllAction();
        }
    });
    haltAllButton.setForeground(Color.RED);
    panel.add(Box.createGlue());
    panel.add(haltAllButton);
    ///
    bottom.add(panel);
    tablePanel.add(bottom);
    addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            dispose();
        }
    });
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    fileMenu.add(new jmri.configurexml.SaveMenu());
    menuBar.add(fileMenu);
    JMenu warrantMenu = new JMenu(Bundle.getMessage("MenuWarrant"));
    warrantMenu.add(new AbstractAction(Bundle.getMessage("ConcatWarrants")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            concatMenuAction();
        }
    });
    warrantMenu.add(new jmri.jmrit.logix.WarrantTableAction("CreateWarrant"));
    warrantMenu.add(WarrantTableAction._trackerTable);
    warrantMenu.add(new AbstractAction(Bundle.getMessage("CreateNXWarrant")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            nxAction();
        }
    });
    warrantMenu.add(WarrantTableAction.makeLogMenu());
    menuBar.add(warrantMenu);
    setJMenuBar(menuBar);
    addHelpMenu("package.jmri.jmrit.logix.WarrantTable", true);
    getContentPane().add(tablePanel);
    //        setLocation(50,0);
    pack();
}
Also used : JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) Font(java.awt.Font) AbstractAction(javax.swing.AbstractAction) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) XTableColumnModel(jmri.util.swing.XTableColumnModel) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ButtonRenderer(jmri.util.table.ButtonRenderer) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

JMenuBar (javax.swing.JMenuBar)108 JMenu (javax.swing.JMenu)77 JMenuItem (javax.swing.JMenuItem)42 ActionEvent (java.awt.event.ActionEvent)36 ActionListener (java.awt.event.ActionListener)30 JPanel (javax.swing.JPanel)27 BoxLayout (javax.swing.BoxLayout)25 Dimension (java.awt.Dimension)23 JFrame (javax.swing.JFrame)17 JLabel (javax.swing.JLabel)14 JScrollPane (javax.swing.JScrollPane)14 JButton (javax.swing.JButton)13 JmriJFrame (jmri.util.JmriJFrame)12 GridBagLayout (java.awt.GridBagLayout)10 JSeparator (javax.swing.JSeparator)10 AbstractAction (javax.swing.AbstractAction)9 BorderLayout (java.awt.BorderLayout)6 FlowLayout (java.awt.FlowLayout)6 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)6 DecoderFile (jmri.jmrit.decoderdefn.DecoderFile)6