use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class SetTrainIconPositionFrame method placeTestIcons.
// place test markers on panel
private void placeTestIcons() {
removeIcons();
if (locationBox.getSelectedItem() == null) {
return;
}
Editor editor = PanelMenu.instance().getEditorByName(Setup.getPanelName());
if (editor == null) {
JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("LoadPanel"), new Object[] { Setup.getPanelName() }), Bundle.getMessage("PanelNotFound"), JOptionPane.ERROR_MESSAGE);
return;
}
Location l = (Location) locationBox.getSelectedItem();
if (l != null) {
// East icon
if ((Setup.getTrainDirection() & Setup.EAST) == Setup.EAST) {
_tIonEast = editor.addTrainIcon(Bundle.getMessage("East"));
_tIonEast.getTooltip().setText(l.getName());
_tIonEast.getTooltip().setBackgroundColor(Color.white);
_tIonEast.setLocoColor(Setup.getTrainIconColorEast());
_tIonEast.setLocation((Integer) spinTrainIconEastX.getValue(), (Integer) spinTrainIconEastY.getValue());
addIconListener(_tIonEast);
}
// West icon
if ((Setup.getTrainDirection() & Setup.WEST) == Setup.WEST) {
_tIonWest = editor.addTrainIcon(Bundle.getMessage("West"));
_tIonWest.getTooltip().setText(l.getName());
_tIonWest.getTooltip().setBackgroundColor(Color.white);
_tIonWest.setLocoColor(Setup.getTrainIconColorWest());
_tIonWest.setLocation((Integer) spinTrainIconWestX.getValue(), (Integer) spinTrainIconWestY.getValue());
addIconListener(_tIonWest);
}
// North icon
if ((Setup.getTrainDirection() & Setup.NORTH) == Setup.NORTH) {
_tIonNorth = editor.addTrainIcon(Bundle.getMessage("North"));
_tIonNorth.getTooltip().setText(l.getName());
_tIonNorth.getTooltip().setBackgroundColor(Color.white);
_tIonNorth.setLocoColor(Setup.getTrainIconColorNorth());
_tIonNorth.setLocation((Integer) spinTrainIconNorthX.getValue(), (Integer) spinTrainIconNorthY.getValue());
addIconListener(_tIonNorth);
}
// South icon
if ((Setup.getTrainDirection() & Setup.SOUTH) == Setup.SOUTH) {
_tIonSouth = editor.addTrainIcon(Bundle.getMessage("South"));
_tIonSouth.getTooltip().setText(l.getName());
_tIonSouth.getTooltip().setBackgroundColor(Color.white);
_tIonSouth.setLocoColor(Setup.getTrainIconColorSouth());
_tIonSouth.setLocation((Integer) spinTrainIconSouthX.getValue(), (Integer) spinTrainIconSouthY.getValue());
addIconListener(_tIonSouth);
}
}
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class SetTrainIconRouteFrame method placeTestIcons.
// place test markers on panel
private void placeTestIcons() {
Editor editor = PanelMenu.instance().getEditorByName(Setup.getPanelName());
if (editor == null) {
JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("LoadPanel"), new Object[] { Setup.getPanelName() }), Bundle.getMessage("PanelNotFound"), JOptionPane.ERROR_MESSAGE);
} else {
if (_tIon != null) {
_tIon.remove();
}
// icon
_tIon = editor.addTrainIcon(_rl.getName());
_tIon.getTooltip().setText(_route.getName());
_tIon.getTooltip().setBackgroundColor(Color.white);
_tIon.setLocation(_rl.getTrainIconX(), _rl.getTrainIconY());
setTrainIconNameAndColor();
addIconListener(_tIon);
}
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class JsonUtilHttpService method getPanels.
public JsonNode getPanels(Locale locale, String format) {
ArrayNode root = mapper.createArrayNode();
// list loaded Panels (ControlPanelEditor, PanelEditor, LayoutEditor, SwitchboardEditor)
// list ControlPanelEditors
Editor.getEditors(ControlPanelEditor.class).stream().map((editor) -> this.getPanel(locale, editor, format)).filter((panel) -> (panel != null)).forEach((panel) -> {
root.add(panel);
});
// list LayoutEditors and PanelEditors
Editor.getEditors(PanelEditor.class).stream().map((editor) -> this.getPanel(locale, editor, format)).filter((panel) -> (panel != null)).forEach((panel) -> {
root.add(panel);
});
// list SwitchboardEditors
Editor.getEditors(SwitchboardEditor.class).stream().map((editor) -> this.getPanel(locale, editor, format)).filter((panel) -> (panel != null)).forEach((panel) -> {
root.add(panel);
});
return root;
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class SignalHeadIconXml method load.
/**
* Create a PositionableLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o an Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor ed = (Editor) o;
SignalHeadIcon l = new SignalHeadIcon(ed);
String name;
Attribute attr = element.getAttribute("signalhead");
if (attr == null) {
log.error("incorrect information for signal head; must use signalhead name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
}
SignalHead sh = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(name);
if (sh != null) {
l.setSignalHead(name);
} else {
log.error("SignalHead named '" + attr.getValue() + "' not found.");
// ed.loadFailed();
return;
}
int rotation = 0;
try {
attr = element.getAttribute("rotate");
rotation = attr.getIntValue();
} catch (org.jdom2.DataConversionException e) {
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
List<Element> aspects = element.getChildren();
if (aspects.size() > 0) {
Element icons = element.getChild("icons");
Element elem = element;
if (icons != null) {
List<Element> c = icons.getChildren();
aspects = c;
elem = icons;
}
for (int i = 0; i < aspects.size(); i++) {
String aspect = aspects.get(i).getName();
NamedIcon icon = loadIcon(l, aspect, elem, "SignalHead \"" + name + "\": icon \"" + aspect + "\" ", ed);
if (icon != null) {
l.setIcon(_nameMap.get(aspect), icon);
} else {
log.info("SignalHead \"" + name + "\": icon \"" + aspect + "\" removed");
}
}
log.debug(aspects.size() + " icons loaded for " + l.getNameString());
} else {
// old style as attributes - somewhere around pre 2.5.4
NamedIcon icon = loadSignalIcon("red", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateRed"), icon);
}
icon = loadSignalIcon("yellow", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateYellow"), icon);
}
icon = loadSignalIcon("green", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateGreen"), icon);
}
icon = loadSignalIcon("lunar", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateLunar"), icon);
}
icon = loadSignalIcon("held", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateHeld"), icon);
}
icon = loadSignalIcon("dark", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateDark"), icon);
}
icon = loadSignalIcon("flashred", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateFlashingRed"), icon);
}
icon = loadSignalIcon("flashyellow", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateFlashingYellow"), icon);
}
icon = loadSignalIcon("flashgreen", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateFlashingGreen"), icon);
}
icon = loadSignalIcon("flashlunar", rotation, l, element, name, ed);
if (icon != null) {
l.setIcon(rbean.getString("SignalHeadStateFlashingLunar"), icon);
}
}
Element elem = element.getChild("iconmaps");
if (elem != null) {
attr = elem.getAttribute("family");
if (attr != null) {
l.setFamily(attr.getValue());
}
}
try {
attr = element.getAttribute("clickmode");
if (attr != null) {
l.setClickMode(attr.getIntValue());
}
} catch (org.jdom2.DataConversionException e) {
log.error("Failed on clickmode attribute: " + e);
}
try {
attr = element.getAttribute("litmode");
if (attr != null) {
l.setLitMode(attr.getBooleanValue());
}
} catch (org.jdom2.DataConversionException e) {
log.error("Failed on litmode attribute: " + e);
}
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.SIGNALS, element);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class SignalMastIconXml method load.
/**
* Create a SignalMastIcon, then add
*
* @param element Top level Element to unpack.
* @param o an Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor ed = (Editor) o;
SignalMastIcon l = new SignalMastIcon(ed);
String name;
Attribute attr;
/*
* We need to set the rotation and scaling first, prior to setting the
* signalmast, otherwise we end up in a situation where by the icons do
* not get rotated or scaled correctly.
**/
try {
int rotation = 0;
double scale = 1.0;
// former attribute name.
attr = element.getAttribute("rotation");
if (attr != null) {
rotation = attr.getIntValue();
}
attr = element.getAttribute("degrees");
if (attr != null) {
rotation = attr.getIntValue();
}
l.rotate(rotation);
attr = element.getAttribute("scale");
String text = "Error attr null";
if (attr != null) {
scale = attr.getDoubleValue();
text = attr.getValue();
}
l.setScale(scale);
if (log.isDebugEnabled()) {
log.debug("Load SignalMast rotation= " + rotation + " scale= " + scale + " attr text= " + text);
}
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert rotation or scale attribute");
}
attr = element.getAttribute("signalmast");
if (attr == null) {
log.error("incorrect information for signal mast; must use signalmast name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
if (log.isDebugEnabled()) {
log.debug("Load SignalMast " + name);
}
}
SignalMast sh = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name);
if (sh != null) {
l.setSignalMast(name);
} else {
log.error("SignalMast named '" + attr.getValue() + "' not found.");
ed.loadFailed();
// return;
}
attr = element.getAttribute("imageset");
if (attr != null) {
l.useIconSet(attr.getValue());
}
attr = element.getAttribute("imageset");
if (attr != null) {
l.useIconSet(attr.getValue());
}
try {
attr = element.getAttribute("clickmode");
if (attr != null) {
l.setClickMode(attr.getIntValue());
}
} catch (org.jdom2.DataConversionException e) {
log.error("Failed on clickmode attribute: " + e);
}
try {
attr = element.getAttribute("litmode");
if (attr != null) {
l.setLitMode(attr.getBooleanValue());
}
} catch (org.jdom2.DataConversionException e) {
log.error("Failed on litmode attribute: " + e);
}
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.SIGNALS, element);
}
Aggregations