use of javax.swing.JMenuItem in project JMRI by JMRI.
the class RosterGroupsPanel method defaultMenu.
private JPopupMenu defaultMenu(int menu) {
JPopupMenu pm = new JPopupMenu();
MenuActionListener ml = new MenuActionListener();
JMenuItem mi = new JMenuItem(Bundle.getMessage("Exportddd"));
mi.addActionListener(ml);
mi.setActionCommand("export");
pm.add(mi);
mi = new JMenuItem(Bundle.getMessage("Importddd"));
mi.addActionListener(ml);
mi.setActionCommand("import");
pm.add(mi);
if (menu == GROUPS_MENU) {
pm.addSeparator();
// key is in jmri.NamedBeanBundle
mi = new JMenuItem(Bundle.getMessage("Renameddd"));
mi.addActionListener(ml);
mi.setActionCommand("rename");
pm.add(mi);
mi = new JMenuItem(Bundle.getMessage("Duplicateddd"));
mi.addActionListener(ml);
mi.setActionCommand("duplicate");
pm.add(mi);
mi = new JMenuItem(Bundle.getMessage("ButtonDelete"));
mi.addActionListener(ml);
mi.setActionCommand("delete");
pm.add(mi);
}
return pm;
}
use of javax.swing.JMenuItem in project JMRI by JMRI.
the class ControlPanel method initGUI.
/**
* Create, initialize and place GUI components.
*/
private void initGUI() {
mainPanel = new JPanel();
this.setContentPane(mainPanel);
mainPanel.setLayout(new BorderLayout());
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
speedControlPanel = new JPanel();
speedControlPanel.setLayout(new BoxLayout(speedControlPanel, BoxLayout.X_AXIS));
speedControlPanel.setOpaque(false);
mainPanel.add(speedControlPanel, BorderLayout.CENTER);
sliderPanel = new JPanel();
sliderPanel.setLayout(new GridBagLayout());
sliderPanel.setOpaque(false);
speedSlider = new JSlider(0, intSpeedSteps);
speedSlider.setOpaque(false);
speedSlider.setValue(0);
speedSlider.setFocusable(false);
// add mouse-wheel support
speedSlider.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() > 0) {
for (int i = 0; i < e.getScrollAmount(); i++) {
decelerate1();
}
} else {
for (int i = 0; i < e.getScrollAmount(); i++) {
accelerate1();
}
}
}
});
speedSliderContinuous = new JSlider(-intSpeedSteps, intSpeedSteps);
speedSliderContinuous.setValue(0);
speedSliderContinuous.setOpaque(false);
speedSliderContinuous.setFocusable(false);
// add mouse-wheel support
speedSliderContinuous.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() > 0) {
for (int i = 0; i < e.getScrollAmount(); i++) {
decelerate1();
}
} else {
for (int i = 0; i < e.getScrollAmount(); i++) {
accelerate1();
}
}
}
});
speedSpinner = new JSpinner();
speedSpinnerModel = new SpinnerNumberModel(0, 0, intSpeedSteps, 1);
speedSpinner.setModel(speedSpinnerModel);
speedSpinner.setFocusable(false);
SpeedStep128Button = new JRadioButton(Bundle.getMessage("Button128SS"));
SpeedStep28Button = new JRadioButton(Bundle.getMessage("Button28SS"));
SpeedStep27Button = new JRadioButton(Bundle.getMessage("Button27SS"));
SpeedStep14Button = new JRadioButton(Bundle.getMessage("Button14SS"));
forwardButton = new JRadioButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
forwardButton.setBorderPainted(false);
forwardButton.setContentAreaFilled(false);
forwardButton.setText(null);
forwardButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-red.png")));
forwardButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-green.png")));
forwardButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
forwardButton.setToolTipText(Bundle.getMessage("ButtonForward"));
} else {
forwardButton.setText(Bundle.getMessage("ButtonForward"));
}
reverseButton = new JRadioButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
reverseButton.setBorderPainted(false);
reverseButton.setContentAreaFilled(false);
reverseButton.setText(null);
reverseButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-red.png")));
reverseButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-green.png")));
reverseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
reverseButton.setToolTipText(Bundle.getMessage("ButtonReverse"));
} else {
reverseButton.setText(Bundle.getMessage("ButtonReverse"));
}
propertiesPopup = new JPopupMenu();
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.ipadx = 0;
constraints.ipady = 0;
Insets insets = new Insets(2, 2, 2, 2);
constraints.insets = insets;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 0;
sliderPanel.add(speedSlider, constraints);
//this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
speedControlPanel.add(sliderPanel);
speedSlider.setOrientation(JSlider.VERTICAL);
speedSlider.setMajorTickSpacing(maxSpeed / 2);
java.util.Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<Integer, JLabel>();
labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
speedSlider.setLabelTable(labelTable);
speedSlider.setPaintTicks(true);
speedSlider.setPaintLabels(true);
// remove old actions
speedSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
boolean doIt = false;
if (!speedSlider.getValueIsAdjusting()) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
} else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis();
}
if (doIt) {
float newSpeed = (speedSlider.getValue() / (intSpeedSteps * 1.0f));
if (log.isDebugEnabled()) {
log.debug("stateChanged: slider pos: " + speedSlider.getValue() + " speed: " + newSpeed);
}
if (sliderPanel.isVisible() && throttle != null) {
throttle.setSpeedSetting(newSpeed);
}
if (speedSpinner != null) {
speedSpinnerModel.setValue(Integer.valueOf(speedSlider.getValue()));
}
if (speedSliderContinuous != null) {
if (forwardButton.isSelected()) {
speedSliderContinuous.setValue(((Integer) speedSlider.getValue()).intValue());
} else {
speedSliderContinuous.setValue(-((Integer) speedSlider.getValue()).intValue());
}
}
}
}
}
});
speedSliderContinuousPanel = new JPanel();
speedSliderContinuousPanel.setLayout(new GridBagLayout());
constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.ipadx = 0;
constraints.ipady = 0;
insets = new Insets(2, 2, 2, 2);
constraints.insets = insets;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 0;
speedSliderContinuousPanel.add(speedSliderContinuous, constraints);
//this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
speedControlPanel.add(speedSliderContinuousPanel);
speedSliderContinuous.setOrientation(JSlider.VERTICAL);
speedSliderContinuous.setMajorTickSpacing(maxSpeed / 2);
labelTable = new java.util.Hashtable<Integer, JLabel>();
labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
labelTable.put(Integer.valueOf(-maxSpeed / 2), new JLabel("-50%"));
labelTable.put(Integer.valueOf(-maxSpeed), new JLabel("-100%"));
speedSliderContinuous.setLabelTable(labelTable);
speedSliderContinuous.setPaintTicks(true);
speedSliderContinuous.setPaintLabels(true);
// remove old actions
speedSliderContinuous.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
boolean doIt = false;
if (!speedSliderContinuous.getValueIsAdjusting()) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
} else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis();
}
if (doIt) {
float newSpeed = (java.lang.Math.abs(speedSliderContinuous.getValue()) / (intSpeedSteps * 1.0f));
boolean newDir = (speedSliderContinuous.getValue() >= 0);
if (log.isDebugEnabled()) {
log.debug("stateChanged: slider pos: " + speedSliderContinuous.getValue() + " speed: " + newSpeed + " dir: " + newDir);
}
if (speedSliderContinuousPanel.isVisible() && throttle != null) {
throttle.setSpeedSetting(newSpeed);
if ((newSpeed > 0) && (newDir != forwardButton.isSelected())) {
throttle.setIsForward(newDir);
}
}
if (speedSpinner != null) {
speedSpinnerModel.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
}
if (speedSlider != null) {
speedSlider.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
}
}
}
}
});
spinnerPanel = new JPanel();
spinnerPanel.setLayout(new GridBagLayout());
spinnerPanel.add(speedSpinner, constraints);
speedControlPanel.add(spinnerPanel);
// remove old actions
speedSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
//if (!speedSpinner.getValueIsAdjusting())
//{
float newSpeed = ((Integer) speedSpinner.getValue()).floatValue() / (intSpeedSteps * 1.0f);
if (log.isDebugEnabled()) {
log.debug("stateChanged: spinner pos: " + speedSpinner.getValue() + " speed: " + newSpeed);
}
if (throttle != null) {
if (spinnerPanel.isVisible()) {
throttle.setSpeedSetting(newSpeed);
}
speedSlider.setValue(((Integer) speedSpinner.getValue()).intValue());
if (speedSliderContinuous != null) {
if (forwardButton.isSelected()) {
speedSliderContinuous.setValue(((Integer) speedSpinner.getValue()).intValue());
} else {
speedSliderContinuous.setValue(-((Integer) speedSpinner.getValue()).intValue());
}
}
} else {
log.warn("no throttle object in stateChanged, ignoring change of speed to " + newSpeed);
}
//}
}
}
});
ButtonGroup speedStepButtons = new ButtonGroup();
speedStepButtons.add(SpeedStep128Button);
speedStepButtons.add(SpeedStep28Button);
speedStepButtons.add(SpeedStep27Button);
speedStepButtons.add(SpeedStep14Button);
constraints.fill = GridBagConstraints.NONE;
constraints.gridy = 1;
spinnerPanel.add(SpeedStep128Button, constraints);
constraints.gridy = 2;
spinnerPanel.add(SpeedStep28Button, constraints);
constraints.gridy = 3;
spinnerPanel.add(SpeedStep27Button, constraints);
constraints.gridy = 4;
spinnerPanel.add(SpeedStep14Button, constraints);
SpeedStep14Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode14);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode14);
}
});
SpeedStep27Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode27);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode27);
}
});
SpeedStep28Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode28);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode28);
}
});
SpeedStep128Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode128);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode128);
}
});
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
ButtonGroup directionButtons = new ButtonGroup();
directionButtons.add(forwardButton);
directionButtons.add(reverseButton);
constraints.fill = GridBagConstraints.NONE;
constraints.gridy = 1;
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 3;
}
buttonPanel.add(forwardButton, constraints);
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 1;
} else {
constraints.gridy = 2;
}
buttonPanel.add(reverseButton, constraints);
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 2;
}
forwardButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
throttle.setIsForward(true);
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(java.lang.Math.abs(speedSliderContinuous.getValue()));
}
}
});
reverseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
throttle.setIsForward(false);
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(-java.lang.Math.abs(speedSliderContinuous.getValue()));
}
}
});
stopButton = new JButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
stopButton.setBorderPainted(false);
stopButton.setContentAreaFilled(false);
stopButton.setText(null);
stopButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop.png")));
stopButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop24.png")));
stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
stopButton.setToolTipText(Bundle.getMessage("ButtonEStop"));
} else {
stopButton.setText(Bundle.getMessage("ButtonEStop"));
}
constraints.gridy = 4;
constraints.fill = GridBagConstraints.HORIZONTAL;
buttonPanel.add(stopButton, constraints);
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stop();
}
});
stopButton.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
stop();
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
idleButton = new JButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
idleButton.setBorderPainted(false);
idleButton.setContentAreaFilled(false);
idleButton.setText(null);
idleButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop.png")));
idleButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop24.png")));
idleButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
idleButton.setToolTipText(Bundle.getMessage("ButtonIdle"));
} else {
idleButton.setText(Bundle.getMessage("ButtonIdle"));
}
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridy = 1;
} else {
constraints.gridy = 3;
}
buttonPanel.add(idleButton, constraints);
idleButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
speedSlider.setValue(0);
if (speedSpinner != null) {
speedSpinner.setValue(Integer.valueOf(0));
}
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(Integer.valueOf(0));
}
throttle.setSpeedSetting(0);
}
});
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
changeOrientation();
}
});
JMenuItem propertiesItem = new JMenuItem(Bundle.getMessage("ControlPanelProperties"));
propertiesItem.addActionListener(this);
propertiesPopup.add(propertiesItem);
// Add a mouse listener all components to trigger the popup menu.
MouseInputAdapter popupListener = new PopupListener(propertiesPopup, this);
MouseInputAdapterInstaller.installMouseInputAdapterOnAllComponents(popupListener, this);
// Install the Key bindings on all Components
KeyListenerInstaller.installKeyListenerOnAllComponents(new ControlPadKeyListener(), this);
// set by default which speed selection method is on top
setSpeedController(_displaySlider);
}
use of javax.swing.JMenuItem in project JMRI by JMRI.
the class AppsLaunchFrame method debugMenu.
protected void debugMenu(JMenuBar menuBar, WindowInterface wi, AppsLaunchPane pane) {
JMenu d = new DebugMenu(pane);
// also add some tentative items from jmrix
d.add(new JSeparator());
d.add(new jmri.jmrix.pricom.PricomMenu());
d.add(new JSeparator());
d.add(new jmri.jmrix.jinput.treecontrol.TreeAction());
d.add(new jmri.jmrix.libusb.UsbViewAction());
d.add(new JSeparator());
try {
d.add(new RunJythonScript(Bundle.getMessage("MenuRailDriverThrottle"), new File(FileUtil.findURL("jython/RailDriver.py").toURI())));
} catch (URISyntaxException | NullPointerException ex) {
log.error("Unable to load RailDriver Throttle", ex);
JMenuItem i = new JMenuItem(Bundle.getMessage("MenuRailDriverThrottle"));
i.setEnabled(false);
d.add(i);
}
// also add some tentative items from webserver
d.add(new JSeparator());
d.add(new WebServerAction());
d.add(new JSeparator());
d.add(new WiThrottleCreationAction());
menuBar.add(d);
}
use of javax.swing.JMenuItem in project JMRI by JMRI.
the class LogixTableAction method setMenuBar.
/**
* Insert 2 table specific menus.
* <p>
* Accounts 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 new menus 2 places earlier
* unless the table is part of the ListedTableFrame, which adds the Help menu later on.
* @param f the JFrame of this table
*/
@Override
public void setMenuBar(BeanTableFrame f) {
loadSelectionMode();
JMenu menu = new JMenu(Bundle.getMessage("MenuOptions"));
menu.setMnemonic(KeyEvent.VK_O);
javax.swing.JMenuBar menuBar = f.getJMenuBar();
// 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;
}
}
}
ButtonGroup enableButtonGroup = new ButtonGroup();
JRadioButtonMenuItem r = new JRadioButtonMenuItem(rbx.getString("EnableAll"));
r.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
enableAll(true);
}
});
enableButtonGroup.add(r);
r.setSelected(true);
menu.add(r);
r = new JRadioButtonMenuItem(rbx.getString("DisableAll"));
r.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
enableAll(false);
}
});
enableButtonGroup.add(r);
menu.add(r);
menu.addSeparator();
ButtonGroup modeButtonGroup = new ButtonGroup();
r = new JRadioButtonMenuItem(rbx.getString("UseMultiPick"));
r.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
setSelectionMode(SelectionMode.USEMULTI);
}
});
modeButtonGroup.add(r);
menu.add(r);
r.setSelected(_selectionMode == SelectionMode.USEMULTI);
r = new JRadioButtonMenuItem(rbx.getString("UseSinglePick"));
r.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
setSelectionMode(SelectionMode.USESINGLE);
}
});
modeButtonGroup.add(r);
menu.add(r);
r.setSelected(_selectionMode == SelectionMode.USESINGLE);
r = new JRadioButtonMenuItem(rbx.getString("UseComboNameBoxes"));
r.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
setSelectionMode(SelectionMode.USECOMBO);
}
});
modeButtonGroup.add(r);
menu.add(r);
r.setSelected(_selectionMode == SelectionMode.USECOMBO);
menuBar.add(menu, pos + offset);
menu = new JMenu(Bundle.getMessage("MenuTools"));
menu.setMnemonic(KeyEvent.VK_T);
JMenuItem item = new JMenuItem(rbx.getString("OpenPickListTables"));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
OpenPickListTable();
}
});
menu.add(item);
item = new JMenuItem(rbx.getString("FindOrphans"));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
findOrphansPressed(e);
}
});
menu.add(item);
item = new JMenuItem(rbx.getString("EmptyConditionals"));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
findEmptyPressed(e);
}
});
menu.add(item);
item = new JMenuItem(rbx.getString("CrossReference"));
item.addActionListener(new ActionListener() {
BeanTableFrame parent;
@Override
public void actionPerformed(ActionEvent e) {
new RefDialog(parent);
}
ActionListener init(BeanTableFrame f) {
parent = f;
return this;
}
}.init(f));
menu.add(item);
item = new JMenuItem(rbx.getString("DisplayWhereUsed"));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
makeWhereUsedWindow();
}
});
menu.add(item);
// add this menu to the right of the previous
menuBar.add(menu, pos + offset + 1);
}
use of javax.swing.JMenuItem in project JMRI by JMRI.
the class ListedTableFrame method buildMenus.
void buildMenus(final TabbedTableItem item) {
JMenuBar menuBar = new JMenuBar();
ResourceBundle rb = ResourceBundle.getBundle("apps.AppsBundle");
JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
menuBar.add(fileMenu);
JMenuItem newItem = new JMenuItem(Bundle.getMessage("MenuNewWindow"));
fileMenu.add(newItem);
newItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
actionList.openNewTableWindow(list.getSelectedIndex());
}
});
fileMenu.add(new jmri.configurexml.SaveMenu());
JMenuItem printItem = new JMenuItem(rb.getString("PrintTable"));
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}");
if (item.getStandardTableModel()) {
item.getDataTable().print(JTable.PrintMode.FIT_WIDTH, null, footerFormat);
} else {
item.getAAClass().print(JTable.PrintMode.FIT_WIDTH, null, footerFormat);
}
} catch (java.awt.print.PrinterException e1) {
log.warn("error printing: " + e1, e1);
} catch (NullPointerException ex) {
log.error("Trying to print returned a NPE error");
}
}
});
JMenu viewMenu = new JMenu(Bundle.getMessage("MenuView"));
menuBar.add(viewMenu);
for (int i = 0; i < TabbedTableItemListArrayArray.size(); i++) {
final TabbedTableItemListArray itemList = TabbedTableItemListArrayArray.get(i);
JMenuItem viewItem = new JMenuItem(itemList.getItemString());
viewMenu.add(viewItem);
viewItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
gotoListItem(itemList.getClassAsString());
}
});
}
this.setJMenuBar(menuBar);
try {
item.getAAClass().setMenuBar(this);
this.addHelpMenu(item.getAAClass().helpTarget(), true);
} catch (Exception ex) {
log.error("Error when trying to set menu bar for " + item.getClassAsString() + "\n" + ex);
}
this.revalidate();
}
Aggregations