Search in sources :

Example 66 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SingleTurnoutSignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    List<Element> l = shared.getChildren("turnoutname");
    if (l.size() == 0) {
        l = shared.getChildren("turnout");
    }
    NamedBeanHandle<Turnout> lit = loadTurnout(l.get(0));
    int off = loadAppearance(shared.getChildren("appearance"), "closed");
    int on = loadAppearance(shared.getChildren("appearance"), "thrown");
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    SignalHead h;
    if (uname == null) {
        h = new SingleTurnoutSignalHead(sys, lit, on, off);
    } else {
        h = new SingleTurnoutSignalHead(sys, uname, lit, on, off);
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : SingleTurnoutSignalHead(jmri.implementation.SingleTurnoutSignalHead) Element(org.jdom2.Element) SingleTurnoutSignalHead(jmri.implementation.SingleTurnoutSignalHead) SignalHead(jmri.SignalHead) Turnout(jmri.Turnout)

Example 67 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SE8cSignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    List<Element> l = shared.getChildren("turnoutname");
    if (l.size() == 0) {
        // older form
        l = shared.getChildren("turnout");
    }
    NamedBeanHandle<Turnout> low = loadTurnout(l.get(0));
    NamedBeanHandle<Turnout> high = loadTurnout(l.get(1));
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    SignalHead h;
    if (uname == null) {
        h = new SE8cSignalHead(sys, low, high);
    } else {
        h = new SE8cSignalHead(sys, low, high, uname);
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SE8cSignalHead(jmri.implementation.SE8cSignalHead) Turnout(jmri.Turnout) SE8cSignalHead(jmri.implementation.SE8cSignalHead)

Example 68 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class VirtualSignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    SignalHead h;
    if (uname == null) {
        h = new VirtualSignalHead(sys);
    } else {
        h = new VirtualSignalHead(sys, uname);
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : SignalHead(jmri.SignalHead) VirtualSignalHead(jmri.implementation.VirtualSignalHead) VirtualSignalHead(jmri.implementation.VirtualSignalHead)

Example 69 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class Maintenance method getTypeAndNames.

/**
     * Find type of element and its names from a name that may be a user name or
     * a system name. (Maybe this can be done at a generic manager level, but
     * there seem to be two kinds of implementation of Managers and I don't know
     * which is the preferred kind or why they need to be different.)
     * <p>
     * Searches each Manager for a reference to the "name".
     *
     * @param name string (name base) to look for
     * @return 4 element String: {Type, userName, sysName, numListeners}
     */
static String[] getTypeAndNames(String name) {
    // N11N
    String userName = name.trim();
    String sysName = userName;
    // String sysName = userName.toUpperCase();
    boolean found = false;
    if (log.isDebugEnabled()) {
        log.debug("getTypeAndNames for \"" + name + "\"");
    }
    jmri.SensorManager sensorManager = InstanceManager.sensorManagerInstance();
    Sensor sen = sensorManager.getBySystemName(sysName);
    if (sen != null) {
        userName = sen.getUserName();
        found = true;
    } else {
        sen = sensorManager.getBySystemName(userName.toUpperCase());
        if (sen != null) {
            sysName = sen.getSystemName();
            userName = sen.getUserName();
            found = true;
        } else {
            sen = sensorManager.getByUserName(userName);
            if (sen != null) {
                sysName = sen.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Sensor", userName, sysName, // NOI18N
        Integer.toString(sen.getNumPropertyChangeListeners()) });
    }
    jmri.TurnoutManager turnoutManager = InstanceManager.turnoutManagerInstance();
    Turnout t = turnoutManager.getBySystemName(sysName);
    if (t != null) {
        userName = t.getUserName();
        found = true;
    } else {
        t = turnoutManager.getBySystemName(userName.toUpperCase());
        if (t != null) {
            sysName = t.getSystemName();
            userName = t.getUserName();
            found = true;
        } else {
            t = turnoutManager.getByUserName(userName);
            if (t != null) {
                sysName = t.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Turnout", userName, sysName, // NOI18N
        Integer.toString(t.getNumPropertyChangeListeners()) });
    }
    jmri.LightManager lightManager = InstanceManager.lightManagerInstance();
    Light l = lightManager.getBySystemName(sysName);
    if (l != null) {
        userName = l.getUserName();
        found = true;
    } else {
        l = lightManager.getBySystemName(userName.toUpperCase());
        if (l != null) {
            sysName = l.getSystemName();
            userName = l.getUserName();
            found = true;
        } else {
            l = lightManager.getByUserName(userName);
            if (l != null) {
                sysName = l.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Light", userName, sysName, // NOI18N
        Integer.toString(l.getNumPropertyChangeListeners()) });
    }
    jmri.SignalHeadManager signalManager = InstanceManager.getDefault(jmri.SignalHeadManager.class);
    SignalHead sh = signalManager.getBySystemName(sysName);
    if (sh != null) {
        userName = sh.getUserName();
        found = true;
    } else {
        sh = signalManager.getBySystemName(userName.toUpperCase());
        if (sh != null) {
            sysName = sh.getSystemName();
            userName = sh.getUserName();
            found = true;
        } else {
            sh = signalManager.getByUserName(userName);
            if (sh != null) {
                sysName = sh.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "SignalHead", userName, sysName, // NOI18N
        Integer.toString(sh.getNumPropertyChangeListeners()) });
    }
    jmri.ConditionalManager cm = InstanceManager.getDefault(jmri.ConditionalManager.class);
    Conditional c = cm.getBySystemName(sysName);
    if (c != null) {
        userName = c.getUserName();
        found = true;
    } else {
        c = cm.getBySystemName(userName.toUpperCase());
        if (c != null) {
            sysName = c.getSystemName();
            userName = c.getUserName();
            found = true;
        } else {
            c = cm.getByUserName(userName);
            if (c != null) {
                sysName = c.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Conditional", userName, sysName, // NOI18N
        Integer.toString(c.getNumPropertyChangeListeners()) });
    }
    jmri.BlockManager blockManager = InstanceManager.getDefault(jmri.BlockManager.class);
    jmri.Block b = blockManager.getBySystemName(sysName);
    if (b != null) {
        userName = b.getUserName();
        found = true;
    } else {
        b = blockManager.getBySystemName(userName.toUpperCase());
        if (b != null) {
            sysName = b.getSystemName();
            userName = b.getUserName();
            found = true;
        } else {
            b = blockManager.getByUserName(userName);
            if (b != null) {
                sysName = b.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Block", userName, sysName, // NOI18N
        Integer.toString(b.getNumPropertyChangeListeners()) });
    }
    jmri.SectionManager sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
    jmri.Section sec = sectionManager.getBySystemName(sysName);
    if (sec != null) {
        userName = sec.getUserName();
        found = true;
    } else {
        sec = sectionManager.getBySystemName(userName.toUpperCase());
        if (sec != null) {
            sysName = sec.getSystemName();
            userName = sec.getUserName();
            found = true;
        } else {
            sec = sectionManager.getByUserName(userName);
            if (sec != null) {
                sysName = sec.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Block", userName, sysName, // NOI18N
        Integer.toString(sec.getNumPropertyChangeListeners()) });
    }
    log.warn(" No type found for " + userName + " (" + sysName + ").");
    jmri.jmrit.logix.OBlockManager oBlockManager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    jmri.jmrit.logix.OBlock blk = oBlockManager.getBySystemName(sysName);
    if (sec != null) {
        userName = blk.getUserName();
        found = true;
    } else {
        blk = oBlockManager.getBySystemName(userName.toUpperCase());
        if (blk != null) {
            sysName = blk.getSystemName();
            userName = blk.getUserName();
            found = true;
        } else {
            blk = oBlockManager.getByUserName(userName);
            if (blk != null) {
                sysName = blk.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "OBlock", userName, sysName, // NOI18N
        Integer.toString(blk.getNumPropertyChangeListeners()) });
    }
    log.warn(" No type found for " + userName + " (" + sysName + ").");
    return (new String[] { "", userName, sysName, "0" });
}
Also used : SignalHead(jmri.SignalHead) Conditional(jmri.Conditional) Block(jmri.Block) Light(jmri.Light) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 70 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class TransitTableAction method validateSignal.

private boolean validateSignal(String sName, boolean when) {
    // check if anything entered
    if (sName.length() < 1) {
        // no sensor entered
        JOptionPane.showMessageDialog(addEditActionFrame, (rbx.getString("NoSignalError")), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    // get the signalMast or signalHead corresponding to this name
    SignalMast sm = null;
    SignalHead sh = null;
    sm = InstanceManager.getDefault(SignalMastManager.class).getSignalMast(sName);
    if (sm == null) {
        sh = InstanceManager.getDefault(SignalHeadManager.class).getSignalHead(sName);
    }
    if (sm == null && sh == null) {
        // There is no signal corresponding to this name
        JOptionPane.showMessageDialog(addEditActionFrame, (rbx.getString("SignalEntryError")), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    return true;
}
Also used : SignalMast(jmri.SignalMast) SignalHead(jmri.SignalHead)

Aggregations

SignalHead (jmri.SignalHead)73 Turnout (jmri.Turnout)20 Element (org.jdom2.Element)13 SignalMast (jmri.SignalMast)12 Sensor (jmri.Sensor)11 JsonException (jmri.server.json.JsonException)8 Test (org.junit.Test)7 NamedBean (jmri.NamedBean)6 DoubleTurnoutSignalHead (jmri.implementation.DoubleTurnoutSignalHead)6 QuadOutputSignalHead (jmri.implementation.QuadOutputSignalHead)6 SingleTurnoutSignalHead (jmri.implementation.SingleTurnoutSignalHead)6 TripleOutputSignalHead (jmri.implementation.TripleOutputSignalHead)6 TripleTurnoutSignalHead (jmri.implementation.TripleTurnoutSignalHead)6 SignalHeadManager (jmri.SignalHeadManager)5 DccSignalHead (jmri.implementation.DccSignalHead)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 JmriException (jmri.JmriException)4 Light (jmri.Light)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 ActionEvent (java.awt.event.ActionEvent)3