Search in sources :

Example 6 with NamedBeanHandle

use of jmri.NamedBeanHandle in project JMRI by JMRI.

the class TripleTurnoutSignalHeadTest method testCTor.

@Test
public void testCTor() {
    Turnout it = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT1");
    NamedBeanHandle<Turnout> green = new NamedBeanHandle<>("green handle", it);
    Turnout it2 = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT3");
    NamedBeanHandle<Turnout> red = new NamedBeanHandle<>("red handle", it2);
    Turnout it3 = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT2");
    NamedBeanHandle<Turnout> yellow = new NamedBeanHandle<>("yellow handle", it3);
    TripleTurnoutSignalHead t = new TripleTurnoutSignalHead("Test Head", green, red, yellow);
    Assert.assertNotNull("exists", t);
}
Also used : Turnout(jmri.Turnout) NamedBeanHandle(jmri.NamedBeanHandle) Test(org.junit.Test)

Example 7 with NamedBeanHandle

use of jmri.NamedBeanHandle in project JMRI by JMRI.

the class QuadOutputSignalHeadTest method testCTor.

@Test
public void testCTor() {
    Turnout it = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT1");
    NamedBeanHandle<Turnout> green = new NamedBeanHandle<>("green handle", it);
    Turnout it2 = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT3");
    NamedBeanHandle<Turnout> red = new NamedBeanHandle<>("red handle", it2);
    Turnout it3 = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT2");
    NamedBeanHandle<Turnout> yellow = new NamedBeanHandle<>("yellow handle", it3);
    Turnout it4 = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT4");
    NamedBeanHandle<Turnout> lunar = new NamedBeanHandle<>("lunar handle", it4);
    QuadOutputSignalHead t = new QuadOutputSignalHead("Test Head", green, red, yellow, lunar);
    Assert.assertNotNull("exists", t);
}
Also used : Turnout(jmri.Turnout) NamedBeanHandle(jmri.NamedBeanHandle) Test(org.junit.Test)

Example 8 with NamedBeanHandle

use of jmri.NamedBeanHandle in project JMRI by JMRI.

the class SignalHeadTableActionTest method testAddAndInvoke.

@Test
public void testAddAndInvoke() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    // add a few signals and see if they exist
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(new DoubleTurnoutSignalHead("IH2", "double example 1-2", new NamedBeanHandle<>("IT1", InstanceManager.turnoutManagerInstance().provideTurnout("IT1")), new NamedBeanHandle<>("IT2", InstanceManager.turnoutManagerInstance().provideTurnout("IT2"))));
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(new QuadOutputSignalHead("IH4", "quad example 11-14", new NamedBeanHandle<>("IT11", InstanceManager.turnoutManagerInstance().provideTurnout("IT11")), new NamedBeanHandle<>("IT12", InstanceManager.turnoutManagerInstance().provideTurnout("IT12")), new NamedBeanHandle<>("IT13", InstanceManager.turnoutManagerInstance().provideTurnout("IT13")), new NamedBeanHandle<>("IT14", InstanceManager.turnoutManagerInstance().provideTurnout("IT14"))));
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(new SE8cSignalHead(new NamedBeanHandle<>("IT1", InstanceManager.turnoutManagerInstance().provideTurnout("IT21")), new NamedBeanHandle<>("IT2", InstanceManager.turnoutManagerInstance().provideTurnout("IT22")), "SE8c from handles"));
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(new SE8cSignalHead(31, "SE8c from number"));
    new SignalHeadTableAction().actionPerformed(null);
    JFrame f = JFrameOperator.waitJFrame(Bundle.getMessage("TitleSignalTable"), true, true);
    Assert.assertNotNull("found frame", f);
    f.dispose();
}
Also used : QuadOutputSignalHead(jmri.implementation.QuadOutputSignalHead) JFrame(javax.swing.JFrame) DoubleTurnoutSignalHead(jmri.implementation.DoubleTurnoutSignalHead) SE8cSignalHead(jmri.implementation.SE8cSignalHead) NamedBeanHandle(jmri.NamedBeanHandle) Test(org.junit.Test)

Example 9 with NamedBeanHandle

use of jmri.NamedBeanHandle in project JMRI by JMRI.

the class RouteController method propertyChange.

/**
     * This is on the aligned sensor, not the route itself.
     *
     */
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals("KnownState")) {
        Sensor s = (Sensor) evt.getSource();
        Enumeration<NamedBeanHandle<Sensor>> en = indication.keys();
        while (en.hasMoreElements()) {
            NamedBeanHandle<Sensor> namedSensor = en.nextElement();
            if (namedSensor.getBean() == s) {
                Route r = indication.get(namedSensor);
                String message = "PRA" + s.getKnownState() + r.getSystemName();
                for (ControllerInterface listener : listeners) {
                    listener.sendPacketToDevice(message);
                }
                return;
            }
        }
    }
}
Also used : NamedBeanHandle(jmri.NamedBeanHandle) Route(jmri.Route) Sensor(jmri.Sensor)

Example 10 with NamedBeanHandle

use of jmri.NamedBeanHandle in project JMRI by JMRI.

the class SignalMastLogicTest method testSetup.

@Test
public void testSetup() {
    jmri.NamedBeanHandleManager nbhm = jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class);
    // provide 2 turnouts:
    Turnout it1 = InstanceManager.turnoutManagerInstance().provideTurnout("IT1");
    Turnout it2 = InstanceManager.turnoutManagerInstance().provideTurnout("IT2");
    // provide 2 sensors:
    Sensor is1 = InstanceManager.sensorManagerInstance().provideSensor("IS1");
    Sensor is2 = InstanceManager.sensorManagerInstance().provideSensor("IS2");
    // provide 3 virtual signal masts:
    SignalMast sm1 = new jmri.implementation.VirtualSignalMast("IF$vsm:AAR-1946:CPL($0002)");
    Assert.assertNotNull("SignalMast is null!", sm1);
    SignalMast sm2 = new jmri.implementation.VirtualSignalMast("IF$vsm:AAR-1946:CPL($0002)");
    Assert.assertNotNull("SignalMast is null!", sm2);
    SignalMast sm3 = new jmri.implementation.VirtualSignalMast("IF$vsm:AAR-1946:CPL($0002)");
    Assert.assertNotNull("SignalMast is null!", sm3);
    // provide a signal mast logic:
    SignalMastLogic sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).newSignalMastLogic(sm1);
    sml.setDestinationMast(sm2);
    Assert.assertNotNull("SignalMastLogic is null!", sml);
    sml.allowAutoMaticSignalMastGeneration(false, sm2);
    // add a control sensor
    // Active
    sml.addSensor("IS1", 1, sm2);
    // check config
    Assert.assertEquals("IS1 included", true, sml.isSensorIncluded(is1, sm2));
    Assert.assertEquals("IS2 not included", false, sml.isSensorIncluded(is2, sm2));
    Assert.assertEquals("IS1 state", 1, sml.getSensorState(is1, sm2));
    // add 1 control turnout
    Hashtable<NamedBeanHandle<Turnout>, Integer> hashTurnouts = new Hashtable<NamedBeanHandle<Turnout>, Integer>();
    NamedBeanHandle<Turnout> namedTurnout1 = nbhm.getNamedBeanHandle("IT1", it1);
    // 1 = Closed
    hashTurnouts.put(namedTurnout1, 1);
    sml.setTurnouts(hashTurnouts, sm2);
    // check config
    Assert.assertTrue("IT1 included", sml.isTurnoutIncluded(it1, sm2));
    Assert.assertFalse("IT2 before", sml.isTurnoutIncluded(it2, sm2));
    // add another control turnout
    NamedBeanHandle<Turnout> namedTurnout2 = nbhm.getNamedBeanHandle("IT2", it2);
    // 2 = Thrown
    hashTurnouts.put(namedTurnout2, 2);
    sml.setTurnouts(hashTurnouts, sm2);
    Assert.assertEquals("IT2 after", true, sml.isTurnoutIncluded(it2, sm2));
    Assert.assertEquals("IT1 state", 1, sml.getTurnoutState(it1, sm2));
    // add a control signal mast
    Hashtable<SignalMast, String> hashSignalMast = new Hashtable<SignalMast, String>();
    hashSignalMast.put(sm3, "Stop");
    sml.setMasts(hashSignalMast, sm2);
    // check config
    Assert.assertEquals("SM3 included", true, sml.isSignalMastIncluded(sm3, sm2));
    Assert.assertEquals("SM3 aspect before", "Stop", sml.getSignalMastState(sm3, sm2));
    // set aspect to Proceed
    hashSignalMast.put(sm3, "Proceed");
    sml.setMasts(hashSignalMast, sm2);
    Assert.assertEquals("SM3 aspect after", "Proceed", sml.getSignalMastState(sm3, sm2));
    // set comment
    sml.setComment("SMLTest", sm2);
    Assert.assertEquals("comment", "SMLTest", sml.getComment(sm2));
    sml.initialise(sm2);
    // set SML disabled
    sml.setDisabled(sm2);
    Assert.assertEquals("disabled", false, sml.isEnabled(sm2));
    // change source mast and check
    sml.replaceSourceMast(sm1, sm3);
    Assert.assertFalse("sourcemast", sml.getSourceMast() == sm1);
    Assert.assertTrue("sourcemast", sml.getSourceMast() == sm3);
    // clean up
    sml.dispose();
}
Also used : Hashtable(java.util.Hashtable) SignalMastLogic(jmri.SignalMastLogic) SignalMast(jmri.SignalMast) Turnout(jmri.Turnout) NamedBeanHandle(jmri.NamedBeanHandle) Sensor(jmri.Sensor) Test(org.junit.Test)

Aggregations

NamedBeanHandle (jmri.NamedBeanHandle)12 Turnout (jmri.Turnout)9 Test (org.junit.Test)8 Sensor (jmri.Sensor)4 SignalMast (jmri.SignalMast)4 Hashtable (java.util.Hashtable)3 Block (jmri.Block)3 SignalMastLogic (jmri.SignalMastLogic)3 SignalMastLogicManager (jmri.SignalMastLogicManager)2 Element (org.jdom2.Element)2 JFrame (javax.swing.JFrame)1 Route (jmri.Route)1 Section (jmri.Section)1 SignalMastManager (jmri.SignalMastManager)1 DoubleTurnoutSignalHead (jmri.implementation.DoubleTurnoutSignalHead)1 QuadOutputSignalHead (jmri.implementation.QuadOutputSignalHead)1 SE8cSignalHead (jmri.implementation.SE8cSignalHead)1 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)1