use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class ReporterIconXml 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) {
Editor ed = (Editor) o;
ReporterIcon l = new ReporterIcon(ed);
loadTextInfo(l, element);
l.setReporter(jmri.InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(element.getAttribute("reporter").getValue()));
l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.REPORTERS, element);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class PositionableRectangleXml method load.
/**
* Create a PositionableShape, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor ed = (Editor) o;
PositionableRectangle ps = new PositionableRectangle(ed);
Element elem = element.getChild("size");
ps.setWidth(getInt(elem, "width"));
ps.setHeight(getInt(elem, "height"));
ed.putItem(ps);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(ps, Editor.MARKERS, element);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class LocoLabelXml method load.
/**
* Create a PositionableShape, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor ed = (Editor) o;
LocoLabel ll = new LocoLabel(ed);
Element elem = element.getChild("size");
ll.setWidth(getInt(elem, "width"));
ll.setHeight(getInt(elem, "height"));
if (elem != null && elem.getAttribute("systemName") != null) {
String name = elem.getAttribute("systemName").getValue();
OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
OBlock block = manager.getBySystemName(name);
ll.setBlock(block);
if (elem.getAttribute("trainName") != null && block != null) {
block.setValue(elem.getAttribute("trainName").getValue());
}
} else {
// don't put into editor's content list without
return;
}
ed.putItem(ll);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(ll, Editor.MARKERS, element);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class Train method createTrainIcon.
public void createTrainIcon(RouteLocation rl) {
if (_trainIcon != null && _trainIcon.isActive()) {
_trainIcon.remove();
}
// if there's a panel specified, get it and place icon
if (!Setup.getPanelName().equals(Setup.NONE)) {
Editor editor = PanelMenu.instance().getEditorByName(Setup.getPanelName());
if (editor != null) {
_trainIcon = editor.addTrainIcon(getIconName());
_trainIcon.setTrain(this);
if (getIconName().length() > 9) {
_trainIcon.setFont(jmri.util.FontUtil.deriveFont(_trainIcon.getFont(), 8.f));
}
if (rl != null) {
_trainIcon.setLocation(rl.getTrainIconX(), rl.getTrainIconY());
}
// add throttle if there's a throttle manager
if (jmri.InstanceManager.getNullableDefault(jmri.ThrottleManager.class) != null) {
// add throttle if JMRI loco roster entry exist
RosterEntry entry = null;
if (getLeadEngine() != null) {
// first try and find a match based on loco road number
List<RosterEntry> entries = Roster.getDefault().matchingList(null, getLeadEngine().getNumber(), null, null, null, null, null);
if (entries.size() > 0) {
entry = entries.get(0);
}
if (entry == null) {
// now try finding a match based on DCC address
entries = Roster.getDefault().matchingList(null, null, getLeadEngine().getNumber(), null, null, null, null);
if (entries.size() > 0) {
entry = entries.get(0);
}
}
}
if (entry != null) {
_trainIcon.setRosterEntry(entry);
if (getLeadEngine().getConsist() != null) {
_trainIcon.setConsistNumber(getLeadEngine().getConsist().getConsistNumber());
}
} else {
log.debug("Loco roster entry not found for train (" + getName() + ")");
}
}
}
}
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class BlockContentsIconXml method load.
/**
* Load, starting with the BlockContentsIcon element, then all the
* value-icon pairs
*
* @param element Top level Element to unpack.
* @param o an Editor as an Object
*/
@Override
public void load(Element element, Object o) {
Editor ed = null;
BlockContentsIcon l;
if (o instanceof LayoutEditor) {
ed = (LayoutEditor) o;
l = new jmri.jmrit.display.layoutEditor.BlockContentsIcon(" ", (LayoutEditor) ed);
} else if (o instanceof jmri.jmrit.display.Editor) {
ed = (Editor) o;
l = new BlockContentsIcon("", ed);
} else {
log.error("Unrecognizable class - " + o.getClass().getName());
return;
}
String name;
Attribute attr = element.getAttribute("blockcontents");
if (attr == null) {
log.error("incorrect information for a block contents; must use block name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
}
loadTextInfo(l, element);
Block m = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
if (m != null) {
l.setBlock(name);
} else {
log.error("Block named '" + attr.getValue() + "' not found.");
ed.loadFailed();
}
Attribute a = element.getAttribute("selectable");
if (a != null && a.getValue().equals("yes")) {
l.setSelectable(true);
} else {
l.setSelectable(false);
}
// get the icon pairs
List<Element> items = element.getChildren("blockstate");
for (int i = 0; i < items.size(); i++) {
// get the class, hence the adapter object to do loading
Element item = items.get(i);
String iconName = item.getAttribute("icon").getValue();
NamedIcon icon = NamedIcon.getIconByName(iconName);
if (icon == null) {
icon = ed.loadFailed("Memory " + name, iconName);
if (icon == null) {
log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
}
}
if (icon != null) {
String keyValue = item.getAttribute("value").getValue();
l.addKeyAndIcon(icon, keyValue);
}
}
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.MEMORIES, element);
int x = 0;
int y = 0;
try {
x = element.getAttribute("x").getIntValue();
y = element.getAttribute("y").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert positional attribute");
}
l.setOriginalLocation(x, y);
l.displayState();
}
Aggregations