Search in sources :

Example 76 with JMenuItem

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

the class BeanTableDataModel method showPopup.

/*{
     return "Bean";
     }*/
protected void showPopup(MouseEvent e) {
    JTable source = (JTable) e.getSource();
    int row = source.rowAtPoint(e.getPoint());
    int column = source.columnAtPoint(e.getPoint());
    if (!source.isRowSelected(row)) {
        source.changeSelection(row, column, false, false);
    }
    final int rowindex = source.convertRowIndexToModel(row);
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem(Bundle.getMessage("CopyName"));
    menuItem.addActionListener((ActionEvent e1) -> {
        copyName(rowindex, 0);
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("Rename"));
    menuItem.addActionListener((ActionEvent e1) -> {
        renameBean(rowindex, 0);
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("Clear"));
    menuItem.addActionListener((ActionEvent e1) -> {
        removeName(rowindex, 0);
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("Move"));
    menuItem.addActionListener((ActionEvent e1) -> {
        moveBean(rowindex, 0);
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("ButtonDelete"));
    menuItem.addActionListener((ActionEvent e1) -> {
        deleteBean(rowindex, 0);
    });
    popupMenu.add(menuItem);
    popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
Also used : ActionEvent(java.awt.event.ActionEvent) JTable(javax.swing.JTable) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 77 with JMenuItem

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

the class AudioTablePanel method getPrintItem.

public JMenuItem getPrintItem() {
    ResourceBundle rbapps = ResourceBundle.getBundle("apps.AppsBundle");
    JMenuItem printItem = new JMenuItem(rbapps.getString("PrintTable"));
    printItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                MessageFormat footerFormat = new MessageFormat("Page {0,number}");
                listenerDataTable.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat("Listener Table"), footerFormat);
                bufferDataTable.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat("Buffer Table"), footerFormat);
                sourceDataTable.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat("Source Table"), footerFormat);
            } catch (java.awt.print.PrinterException e1) {
                log.warn("error printing: " + e1, e1);
            }
        }
    });
    return printItem;
}
Also used : ActionListener(java.awt.event.ActionListener) MessageFormat(java.text.MessageFormat) ActionEvent(java.awt.event.ActionEvent) ResourceBundle(java.util.ResourceBundle) JMenuItem(javax.swing.JMenuItem)

Example 78 with JMenuItem

use of javax.swing.JMenuItem 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 79 with JMenuItem

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

the class Editor method makeAddIconFrame.

protected JFrameItem makeAddIconFrame(String name, boolean add, boolean table, IconAdder editor) {
    log.debug("makeAddIconFrame for {}, add= {}, table= ", name, add, table);
    String txt;
    String BundleName;
    JFrameItem frame = new JFrameItem(name, editor);
    // use NamedBeanBundle property for basic beans like "Turnout" I18N
    if ("Sensor".equals(name)) {
        BundleName = "BeanNameSensor";
    } else if ("SignalHead".equals(name)) {
        BundleName = "BeanNameSignalHead";
    } else if ("SignalMast".equals(name)) {
        BundleName = "BeanNameSignalMast";
    } else if ("Memory".equals(name)) {
        BundleName = "BeanNameMemory";
    } else if ("Reporter".equals(name)) {
        BundleName = "BeanNameReporter";
    } else if ("Light".equals(name)) {
        BundleName = "BeanNameLight";
    } else if ("Turnout".equals(name)) {
        // called by RightTurnout and LeftTurnout objects in TurnoutIcon.java edit() method
        BundleName = "BeanNameTurnout";
    } else if ("Block".equals(name)) {
        BundleName = "BeanNameBlock";
    } else {
        BundleName = name;
    }
    if (editor != null) {
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
        if (add) {
            txt = java.text.MessageFormat.format(Bundle.getMessage("addItemToPanel"), Bundle.getMessage(BundleName));
        } else {
            txt = java.text.MessageFormat.format(Bundle.getMessage("editItemInPanel"), Bundle.getMessage(BundleName));
        }
        p.add(new JLabel(txt));
        if (table) {
            txt = java.text.MessageFormat.format(Bundle.getMessage("TableSelect"), Bundle.getMessage(BundleName), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
        } else {
            if ("MultiSensor".equals(name)) {
                txt = java.text.MessageFormat.format(Bundle.getMessage("SelectMultiSensor", Bundle.getMessage("ButtonAddIcon")), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
            } else {
                txt = java.text.MessageFormat.format(Bundle.getMessage("IconSelect"), Bundle.getMessage(BundleName), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
            }
        }
        p.add(new JLabel(txt));
        // add a bit of space on pane above icons
        p.add(new JLabel("    "));
        frame.getContentPane().add(p, BorderLayout.NORTH);
        frame.getContentPane().add(editor);
        JMenuBar menuBar = new JMenuBar();
        JMenu findIcon = new JMenu(Bundle.getMessage("findIconMenu"));
        menuBar.add(findIcon);
        JMenuItem editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
        editItem.addActionListener(new ActionListener() {

            Editor editor;

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

            ActionListener init(Editor ed) {
                editor = ed;
                return this;
            }
        }.init(this));
        findIcon.add(editItem);
        findIcon.addSeparator();
        JMenuItem searchItem = new JMenuItem(Bundle.getMessage("searchFSMenu"));
        searchItem.addActionListener(new ActionListener() {

            IconAdder ea;

            @Override
            public void actionPerformed(ActionEvent e) {
                jmri.jmrit.catalog.DirectorySearcher.instance().searchFS();
                ea.addDirectoryToCatalog();
            }

            ActionListener init(IconAdder ed) {
                ea = ed;
                return this;
            }
        }.init(editor));
        findIcon.add(searchItem);
        frame.setJMenuBar(menuBar);
        editor.setParent(frame);
        // when this window closes, check for saving
        if (add) {
            frame.addWindowListener(new java.awt.event.WindowAdapter() {

                @Override
                public void windowClosing(java.awt.event.WindowEvent e) {
                    setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
                    if (log.isDebugEnabled()) {
                        log.debug("windowClosing: HIDE {}", toString());
                    }
                }
            });
        }
    } else {
        //NOI18N
        log.error("No icon editor specified for {}", name);
    }
    if (add) {
        txt = java.text.MessageFormat.format(Bundle.getMessage("AddItem"), Bundle.getMessage(BundleName));
        _iconEditorFrame.put(name, frame);
    } else {
        txt = java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage(BundleName));
    }
    frame.setTitle(txt + " (" + getTitle() + ")");
    frame.pack();
    return frame;
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) ActionListener(java.awt.event.ActionListener) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenuItem(javax.swing.JMenuItem) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 80 with JMenuItem

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

the class PositionablePopupUtil method propertyUtil.

public void propertyUtil(JPopupMenu popup) {
    JMenuItem edit = new JMenuItem("Properties");
    edit.addActionListener((ActionEvent e) -> {
        _propertiesUtil.display();
    });
    popup.add(edit);
}
Also used : ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem)

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