use of jmri.SignalMast in project JMRI by JMRI.
the class JsonSignalMastHttpService method doGet.
@Override
public JsonNode doGet(String type, String name, Locale locale) throws JsonException {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, SIGNAL_MAST);
SignalMast signalMast = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name);
ObjectNode data = this.getNamedBean(signalMast, name, type, locale);
root.put(DATA, data);
if (signalMast != null) {
String aspect = signalMast.getAspect();
if (aspect == null) {
//if null, set aspect to "Unknown"
aspect = ASPECT_UNKNOWN;
}
data.put(ASPECT, aspect);
data.put(LIT, signalMast.getLit());
data.put(TOKEN_HELD, signalMast.getHeld());
//state is appearance, plus flags for held and dark statii
if ((signalMast.getHeld()) && (signalMast.getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.HELD) != null)) {
data.put(STATE, ASPECT_HELD);
} else if ((!signalMast.getLit()) && (signalMast.getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.DARK) != null)) {
data.put(STATE, ASPECT_DARK);
} else {
data.put(STATE, aspect);
}
}
return root;
}
use of jmri.SignalMast in project JMRI by JMRI.
the class JsonSignalMastHttpService method doPost.
@Override
public JsonNode doPost(String type, String name, JsonNode data, Locale locale) throws JsonException {
SignalMast signalMast = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name);
this.postNamedBean(signalMast, data, name, type, locale);
if (signalMast != null) {
if (data.path(STATE).isTextual()) {
String aspect = data.path(STATE).asText();
if (aspect.equals("Held")) {
signalMast.setHeld(true);
} else if (signalMast.getValidAspects().contains(aspect)) {
if (signalMast.getHeld()) {
signalMast.setHeld(false);
}
if (signalMast.getAspect() == null || !signalMast.getAspect().equals(aspect)) {
signalMast.setAspect(aspect);
}
} else {
throw new JsonException(400, Bundle.getMessage(locale, "ErrorUnknownState", SIGNAL_MAST, aspect));
}
}
}
return this.doGet(type, name, locale);
}
use of jmri.SignalMast in project JMRI by JMRI.
the class BlockManagerXmlTest method testBlockAndSignalMastTest.
public void testBlockAndSignalMastTest() throws Exception {
JUnitUtil.resetInstanceManager();
JUnitUtil.initConfigureManager();
JUnitUtil.initInternalTurnoutManager();
JUnitUtil.initInternalLightManager();
JUnitUtil.initInternalSensorManager();
JUnitUtil.initMemoryManager();
JUnitUtil.initLayoutBlockManager();
// load file
InstanceManager.getDefault(ConfigureManager.class).load(new java.io.File("java/test/jmri/configurexml/loadref/BlockAndSignalMastTest.xml"));
// in loadref because comparison not working right
Assert.assertNotNull(InstanceManager.getDefault(jmri.BlockManager.class).getBlock("IB1"));
SignalMast m1 = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0001)");
Assert.assertNotNull(m1);
SignalMast m2 = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0002)");
Assert.assertNotNull(m2);
SignalMast m3 = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0003)");
Assert.assertNotNull(m3);
SignalMast m4 = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0004)");
Assert.assertNotNull(m4);
SignalMast m5 = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0005)");
Assert.assertNotNull(m5);
SignalMast m6 = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0006)");
Assert.assertNotNull(m6);
SignalMast m7 = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0007)");
Assert.assertNotNull(m7);
// allow listeners to process, but keep it quick by looking for desired result
for (int i = 0; i < 25; i++) {
JUnitUtil.releaseThread(this);
if (m1.getAspect().equals("Advance Approach") && m2.getAspect().equals("Clear") && m3.getAspect().equals("Clear") && m4.getAspect().equals("Clear") && m5.getAspect().equals("Approach") && m6.getAspect().equals("Stop") && m7.getAspect().equals("Stop")) {
break;
}
}
JUnitUtil.releaseThread(this);
// check for expected mast state
Assert.assertEquals("Signal 1", "Advance Approach", InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0001)").getAspect());
Assert.assertEquals("Signal 2", "Clear", InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0002)").getAspect());
Assert.assertEquals("Signal 3", "Clear", InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0003)").getAspect());
Assert.assertEquals("Signal 4", "Clear", InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0004)").getAspect());
Assert.assertEquals("Signal 5", "Approach", InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0005)").getAspect());
Assert.assertEquals("Signal 6", "Stop", InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0006)").getAspect());
Assert.assertEquals("Signal 7", "Stop", InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0007)").getAspect());
}
use of jmri.SignalMast in project JMRI by JMRI.
the class SignalHeadSignalMastTest method testOneSearchLightViaManager.
@Test
public void testOneSearchLightViaManager() {
SignalMast s = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast("IF$shsm:basic:one-searchlight:IH2");
s.setAspect("Clear");
Assert.assertEquals("check green", SignalHead.GREEN, InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead("IH2").getAppearance());
s.setAspect("Approach");
Assert.assertEquals("check yellow", SignalHead.YELLOW, InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead("IH2").getAppearance());
}
use of jmri.SignalMast in project JMRI by JMRI.
the class SignalMastIconTest method testShowText.
public void testShowText() {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
// this one is for Layout editor, which for now
// is still in text form.
JFrame jf = new JFrame("SignalMast Icon Text Test");
jf.getContentPane().setLayout(new java.awt.FlowLayout());
SignalMastIcon to = new SignalMastIcon(panel);
to.setShowAutoText(true);
jf.getContentPane().add(new JLabel("Should say Approach: "));
jf.getContentPane().add(to);
// reset instance manager & create test heads
jmri.util.JUnitUtil.resetInstanceManager();
InstanceManager.getDefault(jmri.SignalHeadManager.class).register(new DefaultSignalHead("IH1") {
@Override
protected void updateOutput() {
}
});
InstanceManager.getDefault(jmri.SignalHeadManager.class).register(new DefaultSignalHead("IH2") {
@Override
protected void updateOutput() {
}
});
InstanceManager.getDefault(jmri.SignalHeadManager.class).register(new DefaultSignalHead("IH3") {
@Override
protected void updateOutput() {
}
});
SignalMast s = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast("IF$shsm:basic:one-searchlight:IH1");
to.setSignalMast(s.getSystemName());
s.setAspect("Clear");
s.setAspect("Approach");
jf.pack();
jf.setVisible(true);
// close
jf.dispose();
}
Aggregations