use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class WindowMenu method menuSelected.
@Override
public void menuSelected(MenuEvent e) {
String windowName;
framesList = JmriJFrame.getFrameList();
removeAll();
add(new AbstractAction(Bundle.getMessage("MenuItemMinimize")) {
@Override
public void actionPerformed(ActionEvent e) {
// the next line works on Java 2, but not 1.1.8
if (parentFrame != null) {
parentFrame.setState(Frame.ICONIFIED);
}
}
});
add(new JSeparator());
int framesNumber = framesList.size();
for (int i = 0; i < framesNumber; i++) {
JmriJFrame iFrame = framesList.get(i);
windowName = iFrame.getTitle();
if (windowName.equals("")) {
windowName = "Untitled";
}
JCheckBoxMenuItem newItem = new JCheckBoxMenuItem(new AbstractAction(windowName) {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem selectedItem = (JMenuItem) e.getSource();
// Since different windows can have the same name, look for the position of the selected menu item
int itemCount = getItemCount();
// Skip possible other items at the top of the menu (for example, "Minimize")
int firstItem = itemCount - framesList.size();
for (int i = firstItem; i < itemCount; i++) {
if (selectedItem == getItem(i)) {
i -= firstItem;
// Retrieve the corresponding window
if (i < framesList.size()) {
// "i" should always be < framesList.size(), but it's better to make sure
framesList.get(i).setVisible(true);
framesList.get(i).setExtendedState(Frame.NORMAL);
return;
}
}
}
}
});
if (iFrame == parentFrame) {
newItem.setState(true);
}
add(newItem);
}
}
use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class PositionableLabel method setDisableControlMenu.
@Override
public boolean setDisableControlMenu(JPopupMenu popup) {
if (_control) {
disableItem = new JCheckBoxMenuItem(Bundle.getMessage("Disable"));
disableItem.setSelected(!_controlling);
popup.add(disableItem);
disableItem.addActionListener((java.awt.event.ActionEvent e) -> {
setControlling(!disableItem.isSelected());
});
return true;
}
return false;
}
use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class PanelMenu method addEditorPanel.
/**
* Add an Editor panel to Show Panels sub menu
*
* @param panel the panel to add to the menu
*/
public void addEditorPanel(final Editor panel) {
// If this is the first panel, remove the 'No Panels' menu item
if (panelsList.isEmpty()) {
panelsSubMenu.remove(noPanelsItem);
}
panelsList.add(panel);
ActionListener a = (ActionEvent e) -> {
if (panel instanceof LayoutEditor) {
panel.setVisible(true);
panel.repaint();
} else {
panel.getTargetFrame().setVisible(true);
}
updateEditorPanel(panel);
};
JCheckBoxMenuItem r = new JCheckBoxMenuItem(panel.getTitle());
r.addActionListener(a);
panelsSubMenu.add(r);
updateEditorPanel(panel);
}
use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class PanelMenu method renameEditorPanel.
/**
* Rename an Editor type panel in Show Panels sub menu
*
* @param panel the panel to rename
*/
public void renameEditorPanel(Editor panel) {
if (panelsList.isEmpty()) {
return;
}
for (int i = 0; i < panelsList.size(); i++) {
Object o = panelsList.get(i);
if (o == panel) {
JCheckBoxMenuItem r = (JCheckBoxMenuItem) panelsSubMenu.getItem(i);
r.setText(panel.getTitle());
return;
}
}
}
use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class PortalIcon method setPositionableMenu.
private void setPositionableMenu(JPopupMenu popup) {
JCheckBoxMenuItem lockItem = new JCheckBoxMenuItem(Bundle.getMessage("LockPosition"));
lockItem.setSelected(!isPositionable());
lockItem.addActionListener(new ActionListener() {
Positionable comp;
JCheckBoxMenuItem checkBox;
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
comp.setPositionable(!checkBox.isSelected());
}
ActionListener init(Positionable pos, JCheckBoxMenuItem cb) {
comp = pos;
checkBox = cb;
return this;
}
}.init(this, lockItem));
JMenuItem jmi = popup.add(lockItem);
jmi.setEnabled(false);
}
Aggregations