use of jmri.jmrit.operations.trains.TrainIcon in project JMRI by JMRI.
the class OperationsTrainsGuiTest method testTrainIconAttributes.
// test TrainIcon attributes
@Test
public void testTrainIconAttributes() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
Train train1 = new Train("TESTTRAINID", "TESTNAME");
Assert.assertEquals("Train Id", "TESTTRAINID", train1.getId());
Assert.assertEquals("Train Name", "TESTNAME", train1.getName());
Assert.assertEquals("Train toString", "TESTNAME", train1.toString());
jmri.jmrit.display.panelEditor.PanelEditor editor = new jmri.jmrit.display.panelEditor.PanelEditor("Test Panel");
Assert.assertNotNull("New editor", editor);
TrainIcon trainicon1 = editor.addTrainIcon("TestName");
trainicon1.setTrain(train1);
Assert.assertEquals("TrainIcon set train", "TESTNAME", trainicon1.getTrain().getName());
// test color change
String[] colors = TrainIcon.getLocoColors();
for (int i = 0; i < colors.length; i++) {
trainicon1.setLocoColor(colors[i]);
}
editor.getTargetFrame().dispose();
}
use of jmri.jmrit.operations.trains.TrainIcon in project JMRI by JMRI.
the class TrainIconXml method store.
/**
* Default implementation for storing the contents of a TrainIcon
*
* @param o Object to store, of type TrainIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
TrainIcon p = (TrainIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element(Xml.TRAINICON);
element.setAttribute(Xml.TRAIN, p.getTrain().getId());
element.setAttribute(Xml.TRAIN_NAME, p.getTrain().getName());
storeCommonAttributes(p, element);
// include contents
if (p.getUnRotatedText() != null) {
element.setAttribute(Xml.TEXT, p.getUnRotatedText());
}
storeTextInfo(p, element);
element.setAttribute(Xml.ICON, Xml.YES);
element.setAttribute(Xml.DOCK_X, "" + p.getDockX());
element.setAttribute(Xml.DOCK_Y, "" + p.getDockY());
// element.setAttribute("iconId", p.getIconId());
element.addContent(storeIcon(Xml.ICON, (NamedIcon) p.getIcon()));
RosterEntry entry = p.getRosterEntry();
if (entry != null) {
element.setAttribute(Xml.ROSTERENTRY, entry.getId());
}
element.setAttribute(Xml.CLASS, this.getClass().getName());
return element;
}
use of jmri.jmrit.operations.trains.TrainIcon in project JMRI by JMRI.
the class Editor method addTrainIcon.
public TrainIcon addTrainIcon(String name) {
TrainIcon l = new TrainIcon(this);
putLocoIcon(l, name);
return l;
}