use of jmri.jmrit.display.TurnoutIcon in project JMRI by JMRI.
the class CircuitBuilder method convertIcon.
/**
* Converts icon to IndicatorTrack
*/
private void convertIcon(Positionable pos) {
_oldIcon = (PositionableLabel) pos;
_editor.highlight(_oldIcon);
_editor.toFront();
_editor.repaint();
if (pos instanceof TurnoutIcon) {
makePaletteFrame("IndicatorTO");
_trackTOPanel = new IndicatorTOItemPanel(_convertFrame, "IndicatorTO", null, null, _editor);
ActionListener updateAction = new ActionListener() {
@Override
public void actionPerformed(ActionEvent a) {
convertTO();
}
};
_trackTOPanel.init(updateAction);
_convertDialog.add(_trackTOPanel);
} else {
makePaletteFrame("IndicatorTrack");
_trackPanel = new IndicatorItemPanel(_convertFrame, "IndicatorTrack", null, _editor);
ActionListener updateAction = new ActionListener() {
@Override
public void actionPerformed(ActionEvent a) {
convertSeg();
}
};
_trackPanel.init(updateAction);
_convertDialog.add(_trackPanel);
}
_convertDialog.pack();
_convertDialog.setVisible(true);
_editor.repaint();
}
use of jmri.jmrit.display.TurnoutIcon in project JMRI by JMRI.
the class TurnoutIconXml method load.
/**
* Create a PositionableLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@SuppressWarnings("null")
@Override
public void load(Element element, Object o) {
// create the objects
Editor p = (Editor) o;
TurnoutIcon l = new TurnoutIcon(p);
String name;
try {
name = element.getAttribute("turnout").getValue();
} catch (NullPointerException e) {
log.error("incorrect information for turnout; must use turnout name");
p.loadFailed();
return;
}
l.setTurnout(name);
Attribute a = element.getAttribute("tristate");
if ((a == null) || a.getValue().equals("true")) {
l.setTristate(true);
} else {
l.setTristate(false);
}
a = element.getAttribute("momentary");
if ((a != null) && a.getValue().equals("true")) {
l.setMomentary(true);
} else {
l.setMomentary(false);
}
a = element.getAttribute("directControl");
if ((a != null) && a.getValue().equals("true")) {
l.setDirectControl(true);
} else {
l.setDirectControl(false);
}
List<Element> states = element.getChildren();
if (states.size() > 0) {
if (log.isDebugEnabled()) {
log.debug("Main element has" + states.size() + " items");
}
// the element containing the icons
Element elem = element;
Element icons = element.getChild("icons");
if (icons != null) {
List<Element> s = icons.getChildren();
states = s;
// the element containing the icons
elem = icons;
if (log.isDebugEnabled()) {
log.debug("icons element has" + states.size() + " items");
}
}
for (int i = 0; i < states.size(); i++) {
String state = states.get(i).getName();
if (log.isDebugEnabled()) {
log.debug("setIcon for state \"" + state + "\" and " + _nameMap.get(state));
}
NamedIcon icon = loadIcon(l, state, elem, "TurnoutIcon \"" + name + "\": icon \"" + state + "\" ", p);
if (icon != null) {
l.setIcon(_nameMap.get(state), icon);
} else {
log.info("TurnoutIcon \"" + name + "\": icon \"" + state + "\" removed");
return;
}
}
log.debug(states.size() + " icons loaded for " + l.getNameString());
} else {
// case when everything was attributes
int rotation = 0;
try {
rotation = element.getAttribute("rotate").getIntValue();
} catch (org.jdom2.DataConversionException e) {
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
if (loadTurnoutIcon("thrown", rotation, l, element, name, p) == null) {
return;
}
if (loadTurnoutIcon("closed", rotation, l, element, name, p) == null) {
return;
}
if (loadTurnoutIcon("unknown", rotation, l, element, name, p) == null) {
return;
}
if (loadTurnoutIcon("inconsistent", rotation, l, element, name, p) == null) {
return;
}
}
Element elem = element.getChild("iconmaps");
if (elem != null) {
Attribute attr = elem.getAttribute("family");
if (attr != null) {
l.setFamily(attr.getValue());
}
}
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.TurnoutIcon 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.TurnoutIcon in project JMRI by JMRI.
the class TurnoutIconXml method store.
/**
* Default implementation for storing the contents of a TurnoutIcon
*
* @param o Object to store, of type TurnoutIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
TurnoutIcon p = (TurnoutIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("turnouticon");
element.setAttribute("turnout", p.getNamedTurnout().getName());
storeCommonAttributes(p, element);
element.setAttribute("tristate", p.getTristate() ? "true" : "false");
element.setAttribute("momentary", p.getMomentary() ? "true" : "false");
element.setAttribute("directControl", p.getDirectControl() ? "true" : "false");
Element elem = new Element("icons");
elem.addContent(storeIcon("closed", p.getIcon("TurnoutStateClosed")));
elem.addContent(storeIcon("thrown", p.getIcon("TurnoutStateThrown")));
elem.addContent(storeIcon("unknown", p.getIcon("BeanStateUnknown")));
elem.addContent(storeIcon("inconsistent", p.getIcon("BeanStateInconsistent")));
element.addContent(elem);
elem = new Element("iconmaps");
String family = p.getFamily();
if (family != null) {
elem.setAttribute("family", family);
}
element.addContent(elem);
element.setAttribute("class", "jmri.jmrit.display.configurexml.TurnoutIconXml");
return element;
}
Aggregations