use of jmri.jmrit.display.IndicatorTrackIcon in project JMRI by JMRI.
the class EditCircuitFrame method updateIconList.
protected void updateIconList(java.util.List<Positionable> icons) {
//if (log.isDebugEnabled()) log.debug(
int segments = 0;
int turnouts = 0;
if (icons != null) {
if (log.isDebugEnabled()) {
log.debug("updateIconList: icons.size()= {}", icons.size());
}
for (int i = 0; i < icons.size(); i++) {
Positionable pos = icons.get(i);
if (pos instanceof IndicatorTurnoutIcon) {
turnouts++;
} else if (pos instanceof IndicatorTrackIcon) {
segments++;
} else if (pos instanceof TurnoutIcon) {
turnouts++;
} else {
segments++;
}
}
}
_numTrackSeg.setText(String.valueOf(segments));
_numTurnouts.setText(String.valueOf(turnouts));
}
use of jmri.jmrit.display.IndicatorTrackIcon in project JMRI by JMRI.
the class IndicatorTrackIconXml method load.
/**
* Create a IndicatorTrackIcon, 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 p = (Editor) o;
IndicatorTrackIcon l = new IndicatorTrackIcon(p);
Element elem = element.getChild("iconmap");
if (elem != null) {
List<Element> status = elem.getChildren();
if (status.size() > 0) {
for (int i = 0; i < status.size(); i++) {
String msg = "IndicatorTrack \"" + l.getNameString() + "\" icon \"" + status.get(i).getName() + "\" ";
NamedIcon icon = loadIcon(l, status.get(i).getName(), elem, msg, p);
if (icon != null) {
l.setIcon(status.get(i).getName(), icon);
} else {
log.info(msg + " removed for url= " + status.get(i).getName());
return;
}
}
}
Attribute attr = elem.getAttribute("family");
if (attr != null) {
l.setFamily(attr.getValue());
}
}
Element name = element.getChild("occupancyblock");
if (name != null) {
l.setOccBlock(name.getText());
} else {
// only write sensor if no OBlock, don't write double sensing
name = element.getChild("occupancysensor");
if (name != null) {
l.setOccSensor(name.getText());
}
}
l.setShowTrain(false);
name = element.getChild("showTrainName");
if (name != null) {
if ("yes".equals(name.getText())) {
l.setShowTrain(true);
}
}
elem = element.getChild("paths");
if (elem != null) {
ArrayList<String> paths = new ArrayList<String>();
List<Element> pth = elem.getChildren();
for (int i = 0; i < pth.size(); i++) {
paths.add(pth.get(i).getText());
}
l.setPaths(paths);
}
l.displayState(l.getStatus());
l.updateSize();
p.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.TURNOUTS, element);
}
use of jmri.jmrit.display.IndicatorTrackIcon in project JMRI by JMRI.
the class CircuitBuilder method convertSeg.
private void convertSeg() {
IndicatorTrackIcon t = new IndicatorTrackIcon(_editor);
t.setOccBlockHandle(InstanceManager.getDefault(NamedBeanHandleManager.class).getNamedBeanHandle(_currentBlock.getSystemName(), _currentBlock));
t.setFamily(_trackPanel.getFamilyName());
HashMap<String, NamedIcon> iconMap = _trackPanel.getIconMap();
if (iconMap != null) {
Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
while (it.hasNext()) {
Entry<String, NamedIcon> entry = it.next();
if (log.isDebugEnabled()) {
log.debug("key= " + entry.getKey());
}
t.setIcon(entry.getKey(), new NamedIcon(entry.getValue()));
}
}
t.setLevel(Editor.TURNOUTS);
t.setScale(_oldIcon.getScale());
t.rotate(_oldIcon.getDegrees());
finishConvert(t);
}
use of jmri.jmrit.display.IndicatorTrackIcon in project JMRI by JMRI.
the class IndicatorTrackIconXml method store.
/**
* Default implementation for storing the contents of a IndicatorTrackIcon
*
* @param o Object to store, of type IndicatorTrackIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
IndicatorTrackIcon p = (IndicatorTrackIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("indicatortrackicon");
storeCommonAttributes(p, element);
NamedBeanHandle<OBlock> b = p.getNamedOccBlock();
if (b != null) {
element.addContent(storeNamedBean("occupancyblock", b));
}
NamedBeanHandle<Sensor> s = p.getNamedOccSensor();
if (b == null && s != null) {
// only write sensor if no OBlock, don't write double sensing
element.addContent(storeNamedBean("occupancysensor", s));
}
/*
s = p.getErrSensor();
if (s!=null) {
element.addContent(storeBean("errorsensor", s));
}
*/
Element elem = new Element("showTrainName");
String show = "no";
if (p.showTrain()) {
show = "yes";
}
elem.addContent(show);
element.addContent(elem);
HashMap<String, NamedIcon> iconMap = p.getIconMap();
Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
elem = new Element("iconmap");
String family = p.getFamily();
if (family != null) {
elem.setAttribute("family", family);
}
while (it.hasNext()) {
Entry<String, NamedIcon> entry = it.next();
elem.addContent(storeIcon(entry.getKey(), entry.getValue()));
}
element.addContent(elem);
elem = new Element("paths");
ArrayList<String> paths = p.getPaths();
if (paths != null) {
for (int i = 0; i < paths.size(); i++) {
Element e = new Element("path");
e.addContent(paths.get(i));
elem.addContent(e);
}
element.addContent(elem);
}
element.setAttribute("class", "jmri.jmrit.display.configurexml.IndicatorTrackIconXml");
return element;
}
Aggregations