use of javax.swing.AbstractAction 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());
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class Editor method setShowTooltipMenu.
/**
* Add a checkbox to display a tooltip for the Positionable item and if
* showable, provide a dialog menu to edit it.
*
* @param p the item to set the menu for
* @param popup the menu to add for p
*/
public void setShowTooltipMenu(Positionable p, JPopupMenu popup) {
if (p.getDisplayLevel() == BKG) {
return;
}
JMenu edit = new JMenu(Bundle.getMessage("EditTooltip"));
JCheckBoxMenuItem showTooltipItem = new JCheckBoxMenuItem(Bundle.getMessage("ShowTooltip"));
showTooltipItem.setSelected(p.showTooltip());
showTooltipItem.addActionListener(new ActionListener() {
Positionable comp;
JCheckBoxMenuItem checkBox;
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
comp.setShowTooltip(checkBox.isSelected());
}
ActionListener init(Positionable pos, JCheckBoxMenuItem cb) {
comp = pos;
checkBox = cb;
return this;
}
}.init(p, showTooltipItem));
edit.add(showTooltipItem);
edit.add(CoordinateEdit.getTooltipEditAction(p));
jmri.NamedBean bean = p.getNamedBean();
if (bean != null) {
edit.add(new AbstractAction(Bundle.getMessage("SetSysNameTooltip")) {
Positionable comp;
jmri.NamedBean bean;
@Override
public void actionPerformed(ActionEvent e) {
ToolTip tip = comp.getTooltip();
if (tip != null) {
String uName = bean.getUserName();
String sName = bean.getSystemName();
if (uName != null && uName.length() > 0) {
sName = uName + "(" + sName + ")";
}
tip.setText(sName);
}
}
AbstractAction init(Positionable pos, jmri.NamedBean b) {
comp = pos;
bean = b;
return this;
}
}.init(p, bean));
}
popup.add(edit);
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class SensorIcon method setEditIconMenu.
@Override
public boolean setEditIconMenu(JPopupMenu popup) {
String txt = java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameSensor"));
popup.add(new AbstractAction(txt) {
@Override
public void actionPerformed(ActionEvent e) {
edit();
}
});
return true;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class SensorIcon method showPopUp.
/**
* Pop-up just displays the sensor name.
*
* @param popup the menu to display
* @return always true
*/
@Override
public boolean showPopUp(JPopupMenu popup) {
if (isEditable()) {
if (isIcon()) {
popup.add(new AbstractAction(Bundle.getMessage("ChangeToText")) {
@Override
public void actionPerformed(ActionEvent e) {
changeLayoutSensorType();
}
});
} else {
popup.add(new AbstractAction(Bundle.getMessage("ChangeToIcon")) {
@Override
public void actionPerformed(ActionEvent e) {
changeLayoutSensorType();
}
});
}
popup.add(momentaryItem);
momentaryItem.setSelected(getMomentary());
momentaryItem.addActionListener((java.awt.event.ActionEvent e) -> {
setMomentary(momentaryItem.isSelected());
});
} else if (getPopupUtility() != null) {
getPopupUtility().setAdditionalViewPopUpMenu(popup);
}
return true;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class MemoryIcon method showPopUp.
@Override
public boolean showPopUp(JPopupMenu popup) {
if (isEditable() && selectable) {
popup.add(new JSeparator());
java.util.Iterator<String> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
//String value = ((NamedIcon)map.get(key)).getName();
popup.add(new AbstractAction(key) {
@Override
public void actionPerformed(ActionEvent e) {
String key = e.getActionCommand();
setValue(key);
}
});
}
return true;
}
// end of selectable
if (re != null) {
popup.add(new AbstractAction(Bundle.getMessage("OpenThrottle")) {
@Override
public void actionPerformed(ActionEvent e) {
ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
tf.toFront();
tf.getAddressPanel().setRosterEntry(re);
}
});
//don't like the idea of refering specifically to the layout block manager for this, but it has to be done if we are to allow the panel editor to also assign trains to block, when used with a layouteditor
if ((InstanceManager.getDefault(jmri.SectionManager.class).getSystemNameList().size()) > 0 && jmri.InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getBlockWithMemoryAssigned(getMemory()) != null) {
final jmri.jmrit.dispatcher.DispatcherFrame df = jmri.InstanceManager.getNullableDefault(jmri.jmrit.dispatcher.DispatcherFrame.class);
if (df != null) {
final jmri.jmrit.dispatcher.ActiveTrain at = df.getActiveTrainForRoster(re);
if (at != null) {
popup.add(new AbstractAction(Bundle.getMessage("MenuTerminateTrain")) {
@Override
public void actionPerformed(ActionEvent e) {
df.terminateActiveTrain(at);
}
});
popup.add(new AbstractAction(Bundle.getMessage("MenuAllocateExtra")) {
@Override
public void actionPerformed(ActionEvent e) {
//Just brings up the standard allocate extra frame, this could be expanded in the future
//As a point and click operation.
df.allocateExtraSection(e, at);
}
});
if (at.getStatus() == jmri.jmrit.dispatcher.ActiveTrain.DONE) {
popup.add(new AbstractAction(Bundle.getMessage("MenuRestartTrain")) {
@Override
public void actionPerformed(ActionEvent e) {
at.allocateAFresh();
}
});
}
} else {
popup.add(new AbstractAction(Bundle.getMessage("MenuNewTrain")) {
@Override
public void actionPerformed(ActionEvent e) {
if (!df.getNewTrainActive()) {
df.getActiveTrainFrame().initiateTrain(e, re, jmri.InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getBlockWithMemoryAssigned(getMemory()).getBlock());
df.setNewTrainActive(true);
} else {
df.getActiveTrainFrame().showActivateFrame(re);
}
}
});
}
}
}
return true;
}
return false;
}
Aggregations