Search in sources :

Example 1 with Light

use of jmri.Light in project JMRI by JMRI.

the class AbstractLightManagerConfigXML method store.

/**
     * Default implementation for storing the contents of a LightManager
     *
     * @param o Object to store, of type LightManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element lights = new Element("lights");
    setStoreElementClass(lights);
    LightManager tm = (LightManager) o;
    if (tm != null) {
        java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
        // don't return an element if there are not lights to include
        if (!iter.hasNext()) {
            return null;
        }
        // store the lights
        while (iter.hasNext()) {
            String sname = iter.next();
            if (sname == null) {
                log.error("System name null during store");
                break;
            }
            log.debug("system name is " + sname);
            Light lgt = tm.getBySystemName(sname);
            Element elem = new Element("light");
            elem.addContent(new Element("systemName").addContent(sname));
            // store common parts
            storeCommon(lgt, elem);
            // write variable intensity attributes
            elem.setAttribute("minIntensity", "" + lgt.getMinIntensity());
            elem.setAttribute("maxIntensity", "" + lgt.getMaxIntensity());
            // write transition attribute
            elem.setAttribute("transitionTime", "" + lgt.getTransitionTime());
            // save child lightcontrol entries
            ArrayList<LightControl> lcList = lgt.getLightControlList();
            Element lcElem = null;
            for (int i = 0; i < lcList.size(); i++) {
                LightControl lc = lcList.get(i);
                if (lc != null) {
                    lcElem = new Element("lightcontrol");
                    int type = lc.getControlType();
                    lcElem.setAttribute("controlType", "" + type);
                    if (type == Light.SENSOR_CONTROL) {
                        lcElem.setAttribute("controlSensor", lc.getControlSensorName());
                        lcElem.setAttribute("sensorSense", "" + lc.getControlSensorSense());
                    } else if (type == Light.FAST_CLOCK_CONTROL) {
                        lcElem.setAttribute("fastClockOnHour", "" + lc.getFastClockOnHour());
                        lcElem.setAttribute("fastClockOnMin", "" + lc.getFastClockOnMin());
                        lcElem.setAttribute("fastClockOffHour", "" + lc.getFastClockOffHour());
                        lcElem.setAttribute("fastClockOffMin", "" + lc.getFastClockOffMin());
                    } else if (type == Light.TURNOUT_STATUS_CONTROL) {
                        lcElem.setAttribute("controlTurnout", lc.getControlTurnoutName());
                        lcElem.setAttribute("turnoutState", "" + lc.getControlTurnoutState());
                    } else if (type == Light.TIMED_ON_CONTROL) {
                        lcElem.setAttribute("timedControlSensor", lc.getControlTimedOnSensorName());
                        lcElem.setAttribute("duration", "" + lc.getTimedOnDuration());
                    }
                    if (type == Light.TWO_SENSOR_CONTROL) {
                        lcElem.setAttribute("controlSensor", lc.getControlSensorName());
                        lcElem.setAttribute("controlSensor2", lc.getControlSensor2Name());
                        lcElem.setAttribute("sensorSense", "" + lc.getControlSensorSense());
                    }
                    elem.addContent(lcElem);
                }
            }
            lights.addContent(elem);
        }
    }
    return lights;
}
Also used : Light(jmri.Light) Element(org.jdom2.Element) LightManager(jmri.LightManager) LightControl(jmri.implementation.LightControl)

Example 2 with Light

use of jmri.Light in project JMRI by JMRI.

the class JsonLightHttpService method doGet.

@Override
public JsonNode doGet(String type, String name, Locale locale) throws JsonException {
    ObjectNode root = mapper.createObjectNode();
    root.put(TYPE, LIGHT);
    Light light = InstanceManager.lightManagerInstance().getLight(name);
    ObjectNode data = this.getNamedBean(light, name, type, locale);
    root.put(DATA, data);
    if (light != null) {
        switch(light.getState()) {
            case Light.ON:
                data.put(STATE, ON);
                break;
            case Light.OFF:
                data.put(STATE, OFF);
                break;
            case Light.INCONSISTENT:
                data.put(STATE, INCONSISTENT);
                break;
            case Light.UNKNOWN:
            default:
                data.put(STATE, UNKNOWN);
                break;
        }
    }
    return root;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Light(jmri.Light)

Example 3 with Light

use of jmri.Light in project JMRI by JMRI.

the class JsonLightHttpService method doPost.

@Override
public JsonNode doPost(String type, String name, JsonNode data, Locale locale) throws JsonException {
    Light light = InstanceManager.lightManagerInstance().getLight(name);
    if (light == null) {
        throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", LIGHT, name));
    }
    if (data.path(USERNAME).isTextual()) {
        light.setUserName(data.path(USERNAME).asText());
    }
    if (data.path(COMMENT).isTextual()) {
        light.setComment(data.path(COMMENT).asText());
    }
    int state = data.path(STATE).asInt(UNKNOWN);
    switch(state) {
        case ON:
            light.setState(Light.ON);
            break;
        case OFF:
            light.setState(Light.OFF);
            break;
        case UNKNOWN:
            // leave state alone in this case
            break;
        default:
            throw new JsonException(400, Bundle.getMessage(locale, "ErrorUnknownState", LIGHT, state));
    }
    return this.doGet(type, name, locale);
}
Also used : JsonException(jmri.server.json.JsonException) Light(jmri.Light)

Example 4 with Light

use of jmri.Light in project JMRI by JMRI.

the class LightTableActionTest method testAddAndInvoke.

/**
     * Check graphic state presentation.
     * @since 4.7.4
     */
@Test
public void testAddAndInvoke() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    // show table
    a.actionPerformed(null);
    // create 2 lights and see if they exist
    Light il1 = InstanceManager.lightManagerInstance().provideLight("IL1");
    Light il2 = InstanceManager.lightManagerInstance().provideLight("IL2");
    il1.setState(Light.ON);
    il1.setState(Light.OFF);
    // set graphic state column display preference to false, read by createModel()
    InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(false);
    LightTableAction _lTable;
    _lTable = new LightTableAction();
    Assert.assertNotNull("found LightTable frame", _lTable);
    // set to true, use icons
    InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(true);
    LightTableAction _l1Table;
    _l1Table = new LightTableAction();
    Assert.assertNotNull("found LightTable1 frame", _l1Table);
    _l1Table.addPressed(null);
    JFrame af = JFrameOperator.waitJFrame(Bundle.getMessage("TitleAddLight"), true, true);
    Assert.assertNotNull("found Add frame", af);
    //        // wait 1 sec (nothing to see)
    //        Runnable waiter = new Runnable() {
    //            @Override
    //            public synchronized void run() {
    //                try {
    //                    this.wait(1000);
    //                } catch (InterruptedException ex) {
    //                    log.error("Waiter interrupted.");
    //                }
    //            }
    //        };
    //        waiter.run();
    // close AddPane
    _l1Table.cancelPressed(null);
    // TODO Add more Light Add pane tests in new LightTableWindowTest? see TurnoutEtc
    // clean up
    af.dispose();
    _lTable.dispose();
    _l1Table.dispose();
}
Also used : GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) JFrame(javax.swing.JFrame) Light(jmri.Light) Test(org.junit.Test)

Example 5 with Light

use of jmri.Light in project JMRI by JMRI.

the class LogixTableActionTest method setUp.

// The minimal setup for log4J
@Override
protected void setUp() throws Exception {
    apps.tests.Log4JFixture.setUp();
    super.setUp();
    JUnitUtil.resetInstanceManager();
    JUnitUtil.initDefaultUserMessagePreferences();
    JUnitUtil.initInternalTurnoutManager();
    JUnitUtil.initInternalLightManager();
    JUnitUtil.initInternalSensorManager();
    JUnitUtil.initInternalSignalHeadManager();
    _logixTable = new LogixTableAction() {

        // skip dialog box if in edit mode, just assume OK pressed
        @Override
        boolean checkEditConditional() {
            return inEditConditionalMode;
        }
    };
    // test has begun
    assertNotNull("LogixTableAction is null!", _logixTable);
    _logixTable._suppressReminder = true;
    Logix x1 = new jmri.implementation.DefaultLogix("IX01");
    assertNotNull("Logix x1 is null!", x1);
    InstanceManager.getDefault(jmri.LogixManager.class).register(x1);
    for (int i = 0; i < 10; i++) {
        Sensor s = InstanceManager.sensorManagerInstance().newSensor("IS" + i, "Sensor" + i);
        assertNotNull(i + "th Sensor is null!", s);
        Turnout t = InstanceManager.turnoutManagerInstance().newTurnout("IT" + i, "Turnout" + i);
        assertNotNull(i + "th Turnout is null!", t);
        Light l = InstanceManager.lightManagerInstance().newLight("IL" + (i), "Light" + i);
        assertNotNull(i + "th Light is null!", l);
        Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional("IX01C" + i, "Conditional " + i);
        assertNotNull(i + "th Conditional is null!", c);
        Memory m = InstanceManager.memoryManagerInstance().provideMemory("IMemory" + i);
        assertNotNull(i + "th Memory is null!", m);
        SignalHead sh = new jmri.implementation.VirtualSignalHead("SignalHead" + i);
        assertNotNull(i + "th SignalHead is null!", sh);
        InstanceManager.getDefault(jmri.SignalHeadManager.class).register(sh);
        Route r = new jmri.implementation.DefaultRoute("Route" + i);
        assertNotNull(i + "th Route is null!", r);
        InstanceManager.getDefault(jmri.RouteManager.class).register(r);
    }
}
Also used : Memory(jmri.Memory) SignalHead(jmri.SignalHead) Conditional(jmri.Conditional) Logix(jmri.Logix) Light(jmri.Light) Turnout(jmri.Turnout) Route(jmri.Route) Sensor(jmri.Sensor)

Aggregations

Light (jmri.Light)69 LightManager (jmri.LightManager)16 Test (org.junit.Test)16 Turnout (jmri.Turnout)10 Sensor (jmri.Sensor)9 JsonException (jmri.server.json.JsonException)7 IOException (java.io.IOException)5 JmriException (jmri.JmriException)5 SignalHead (jmri.SignalHead)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Conditional (jmri.Conditional)4 NamedBean (jmri.NamedBean)3 Route (jmri.Route)3 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 File (java.io.File)2 JButton (javax.swing.JButton)2 Logix (jmri.Logix)2 Memory (jmri.Memory)2