use of javax.swing.JMenuItem in project JMRI by JMRI.
the class TurnoutTableAction method setMenuBar.
/**
* Insert a table specific Operations 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 Operations 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("TurnoutAutomationMenu"))) {
// using first menu for check, should be identical to next JMenu Bundle
menuAbsent = false;
break;
}
}
if (menuAbsent) {
// create it
// 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 opsMenu = new JMenu(Bundle.getMessage("TurnoutAutomationMenu"));
JMenuItem item = new JMenuItem(Bundle.getMessage("TurnoutAutomationMenuItemEdit"));
opsMenu.add(item);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new TurnoutOperationFrame(finalF);
}
});
menuBar.add(opsMenu, pos + offset);
JMenu speedMenu = new JMenu(Bundle.getMessage("SpeedsMenu"));
item = new JMenuItem(Bundle.getMessage("SpeedsMenuItemDefaults"));
speedMenu.add(item);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setDefaultSpeeds(finalF);
}
});
// add this menu to the right of the previous
menuBar.add(speedMenu, pos + offset + 1);
}
}
use of javax.swing.JMenuItem in project JMRI by JMRI.
the class Editor method setDisplayLevelMenu.
/**
* Display display 'z' level of the Positionable item and provide a dialog
* menu item to edit it.
*
* @param p The item
* @param popup the menu to add entries to
*/
public void setDisplayLevelMenu(Positionable p, JPopupMenu popup) {
JMenu edit = new JMenu(Bundle.getMessage("EditLevel"));
JMenuItem jmi = edit.add(Bundle.getMessage("Level") + " = " + p.getDisplayLevel());
jmi.setEnabled(false);
edit.add(CoordinateEdit.getLevelEditAction(p));
popup.add(edit);
}
use of javax.swing.JMenuItem in project JMRI by JMRI.
the class ControlPanelEditor method setCopyMenu.
/**
* Add an action to copy the Positionable item and the group to which is may
* belong.
*/
public void setCopyMenu(Positionable p, JPopupMenu popup) {
JMenuItem edit = new JMenuItem(Bundle.getMessage("MenuItemDuplicate"));
edit.addActionListener(new ActionListener() {
Positionable comp;
@Override
public void actionPerformed(ActionEvent e) {
copyItem(comp);
}
ActionListener init(Positionable pos) {
comp = pos;
return this;
}
}.init(p));
popup.add(edit);
}
use of javax.swing.JMenuItem in project JMRI by JMRI.
the class CircuitBuilder method makeCircuitMenu.
private void makeCircuitMenu() {
_circuitMenu.removeAll();
JMenuItem circuitItem = new JMenuItem(Bundle.getMessage("newCircuitItem"));
_circuitMenu.add(circuitItem);
circuitItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
newCircuit();
}
});
JMenuItem editCircuitItem = new JMenuItem(Bundle.getMessage("editCircuitItem"));
_circuitMenu.add(editCircuitItem);
JMenuItem editPortalsItem = new JMenuItem(Bundle.getMessage("editPortalsItem"));
_circuitMenu.add(editPortalsItem);
JMenuItem editCircuitPathsItem = new JMenuItem(Bundle.getMessage("editCircuitPathsItem"));
_circuitMenu.add(editCircuitPathsItem);
JMenuItem editDirectionItem = new JMenuItem(Bundle.getMessage("editDirectionItem"));
_circuitMenu.add(editDirectionItem);
if (_circuitMap.size() > 0) {
editCircuitItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
editCircuit("editCircuitItem");
}
});
editPortalsItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
editPortals("editPortalsItem");
}
});
editCircuitPathsItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
editCircuitPaths("editCircuitPathsItem");
}
});
editDirectionItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
editPortalDirection("editDirectionItem");
}
});
// delay error detection until ControlPanelEditor is fully loaded
JMenuItem mi = new JMenuItem(Bundle.getMessage("circuitErrorsItem"));
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
checkCircuits();
}
});
_circuitMenu.add(mi);
} else {
editCircuitItem.add(new JMenuItem(Bundle.getMessage("noCircuitsItem")));
editPortalsItem.add(new JMenuItem(Bundle.getMessage("noCircuitsItem")));
editCircuitPathsItem.add(new JMenuItem(Bundle.getMessage("noCircuitsItem")));
editDirectionItem.add(new JMenuItem(Bundle.getMessage("noCircuitsItem")));
}
}
use of javax.swing.JMenuItem in project JMRI by JMRI.
the class PanelEditor method init.
@Override
protected void init(String name) {
Runnable r = new Runnable() {
@Override
public void run() {
try {
// Build resource catalog and load CatalogTree.xml now
jmri.jmrit.catalog.CatalogPanel catalog = new jmri.jmrit.catalog.CatalogPanel();
catalog.createNewBranch("IFJAR", "Program Directory", "resources");
} catch (Exception ex) {
log.error("Error in trying to setup preferences " + ex.toString());
}
}
};
Thread thr = new Thread(r);
thr.start();
java.awt.Container contentPane = this.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// common items
JPanel common = new JPanel();
common.setLayout(new FlowLayout());
common.add(new JLabel(" x:"));
common.add(nextX);
common.add(new JLabel(" y:"));
common.add(nextY);
contentPane.add(common);
setAllEditable(true);
setShowHidden(true);
super.setTargetPanel(null, makeFrame(name));
super.setTargetPanelSize(400, 300);
super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("SansSerif", Font.PLAIN, 12), Color.black, new Color(215, 225, 255), Color.black));
// set scrollbar initial state
setScroll(SCROLL_BOTH);
// add menu - not using PanelMenu, because it now
// has other stuff in it?
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
menuBar.add(fileMenu);
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("editIndexMenu"));
editItem.addActionListener(new ActionListener() {
PanelEditor panelEd;
@Override
public void actionPerformed(ActionEvent e) {
ImageIndexEditor ii = ImageIndexEditor.instance(panelEd);
ii.pack();
ii.setVisible(true);
}
ActionListener init(PanelEditor pe) {
panelEd = pe;
return this;
}
}.init(this));
fileMenu.add(editItem);
editItem = new JMenuItem(Bundle.getMessage("CPEView"));
fileMenu.add(editItem);
editItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
changeView("jmri.jmrit.display.controlPanelEditor.ControlPanelEditor");
}
});
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);
}
}
});
setJMenuBar(menuBar);
addHelpMenu("package.jmri.jmrit.display.PanelEditor", true);
// allow naming the panel
{
JPanel namep = new JPanel();
namep.setLayout(new FlowLayout());
JButton b = new JButton(Bundle.getMessage("ButtonSetName"));
b.addActionListener(new ActionListener() {
PanelEditor editor;
@Override
public void actionPerformed(ActionEvent e) {
// prompt for name
String newName = JOptionPane.showInputDialog(null, Bundle.getMessage("PromptNewName"));
if (newName == null) {
// cancelled
return;
}
if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(newName)) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("CanNotRename"), Bundle.getMessage("PanelExist"), JOptionPane.ERROR_MESSAGE);
return;
}
if (getTargetPanel().getTopLevelAncestor() != null) {
((JFrame) getTargetPanel().getTopLevelAncestor()).setTitle(newName);
}
editor.setTitle();
jmri.jmrit.display.PanelMenu.instance().renameEditorPanel(editor);
}
ActionListener init(PanelEditor e) {
editor = e;
return this;
}
}.init(this));
namep.add(b);
this.getContentPane().add(namep);
}
// add a text label
{
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(labelAdd);
labelAdd.setEnabled(false);
labelAdd.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
panel.add(nextLabel);
labelAdd.addActionListener(new ActionListener() {
PanelEditor editor;
@Override
public void actionPerformed(ActionEvent a) {
editor.addLabel(nextLabel.getText());
}
ActionListener init(PanelEditor e) {
editor = e;
return this;
}
}.init(this));
nextLabel.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent a) {
if (nextLabel.getText().equals("")) {
labelAdd.setEnabled(false);
labelAdd.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
} else {
labelAdd.setEnabled(true);
labelAdd.setToolTipText(null);
}
}
});
this.getContentPane().add(panel);
}
// Selection of the type of entity for the icon to represent is done from a combobox
_addIconBox = new JComboBox<ComboBoxItem>();
_addIconBox.setMinimumSize(new Dimension(75, 75));
_addIconBox.setMaximumSize(new Dimension(200, 200));
_addIconBox.addItem(new ComboBoxItem("RightTurnout"));
_addIconBox.addItem(new ComboBoxItem("LeftTurnout"));
_addIconBox.addItem(new ComboBoxItem("SlipTOEditor"));
// NOI18N
_addIconBox.addItem(new ComboBoxItem("Sensor"));
_addIconBox.addItem(new ComboBoxItem("SignalHead"));
_addIconBox.addItem(new ComboBoxItem("SignalMast"));
_addIconBox.addItem(new ComboBoxItem("Memory"));
_addIconBox.addItem(new ComboBoxItem("BlockLabel"));
_addIconBox.addItem(new ComboBoxItem("Reporter"));
_addIconBox.addItem(new ComboBoxItem("Light"));
_addIconBox.addItem(new ComboBoxItem("Background"));
_addIconBox.addItem(new ComboBoxItem("MultiSensor"));
_addIconBox.addItem(new ComboBoxItem("RPSreporter"));
_addIconBox.addItem(new ComboBoxItem("FastClock"));
_addIconBox.addItem(new ComboBoxItem("Icon"));
_addIconBox.setSelectedIndex(-1);
// must be AFTER no selection is set
_addIconBox.addItemListener(this);
JPanel p1 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(new JLabel(Bundle.getMessage("selectTypeIcon")));
p1.add(p2);
p1.add(_addIconBox);
contentPane.add(p1);
// edit, position, control controls
{
// edit mode item
contentPane.add(editableBox);
editableBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllEditable(editableBox.isSelected());
hiddenCheckBoxListener();
}
});
editableBox.setSelected(isEditable());
// positionable item
contentPane.add(positionableBox);
positionableBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllPositionable(positionableBox.isSelected());
}
});
positionableBox.setSelected(allPositionable());
// controlable item
contentPane.add(controllingBox);
controllingBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllControlling(controllingBox.isSelected());
}
});
controllingBox.setSelected(allControlling());
// hidden item
contentPane.add(hiddenBox);
hiddenCheckBoxListener();
hiddenBox.setSelected(showHidden());
/*
contentPane.add(showCoordinatesBox);
showCoordinatesBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setShowCoordinates(showCoordinatesBox.isSelected());
}
});
showCoordinatesBox.setSelected(showCoordinates());
*/
contentPane.add(showTooltipBox);
showTooltipBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setAllShowTooltip(showTooltipBox.isSelected());
}
});
showTooltipBox.setSelected(showTooltip());
contentPane.add(menuBox);
menuBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setPanelMenuVisible(menuBox.isSelected());
}
});
menuBox.setSelected(true);
// Show/Hide Scroll Bars
JPanel scrollPanel = new JPanel();
scrollPanel.setLayout(new FlowLayout());
scrollableLabel.setLabelFor(scrollableComboBox);
scrollPanel.add(scrollableLabel);
scrollPanel.add(scrollableComboBox);
contentPane.add(scrollPanel);
scrollableComboBox.addItem(Bundle.getMessage("ScrollNone"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollBoth"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollHorizontal"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollVertical"));
scrollableComboBox.setSelectedIndex(SCROLL_BOTH);
scrollableComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setScroll(scrollableComboBox.getSelectedIndex());
}
});
}
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(this);
}
// when this window closes, set contents of target uneditable
addWindowListener(new java.awt.event.WindowAdapter() {
HashMap<String, JFrameItem> iconAdderFrames;
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
Iterator<JFrameItem> iter = iconAdderFrames.values().iterator();
while (iter.hasNext()) {
JFrameItem frame = iter.next();
frame.dispose();
}
}
WindowAdapter init(HashMap<String, JFrameItem> f) {
iconAdderFrames = f;
return this;
}
}.init(_iconEditorFrame));
// and don't destroy the window
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
// move this editor panel off the panel's position
getTargetFrame().setLocationRelativeTo(this);
getTargetFrame().pack();
getTargetFrame().setVisible(true);
log.debug("PanelEditor ctor done.");
}
Aggregations