Search in sources :

Example 1 with DccSignalHead

use of jmri.implementation.DccSignalHead in project JMRI by JMRI.

the class DccSignalHeadXml method store.

/**
     * Default implementation for storing the contents of a LsDecSignalHead
     *
     * @param o Object to store, of type LsDecSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    DccSignalHead p = (DccSignalHead) o;
    Element element = new Element("signalhead");
    element.setAttribute("class", this.getClass().getName());
    element.addContent(new Element("systemName").addContent(p.getSystemName()));
    storeCommon(p, element);
    if (p.useAddressOffSet()) {
        element.addContent(new Element("useAddressOffSet").addContent("yes"));
    } else {
        element.addContent(new Element("useAddressOffSet").addContent("no"));
    }
    for (int i = 0; i < p.getValidStates().length; i++) {
        String aspect = p.getValidStateNames()[i];
        //String address = p.getOutputForAppearance(i);
        Element el = new Element("aspect");
        el.setAttribute("defines", aspect);
        el.addContent(new Element("number").addContent(Integer.toString(p.getOutputForAppearance(p.getValidStates()[i]))));
        element.addContent(el);
    }
    return element;
}
Also used : Element(org.jdom2.Element) DccSignalHead(jmri.implementation.DccSignalHead)

Example 2 with DccSignalHead

use of jmri.implementation.DccSignalHead in project JMRI by JMRI.

the class SignalHeadTableAction method updatePressed.

@SuppressWarnings("fallthrough")
@SuppressFBWarnings(value = "SF_SWITCH_FALLTHROUGH")
void updatePressed(ActionEvent e) {
    String nam = eUserName.getText();
    // check if user name changed
    String uname = curS.getUserName();
    // TODO: not sure this if statement is right. I think (uname != null && !uname.equals(nam))
    if (!((uname != null) && (uname.equals(nam)))) {
        if (checkUserName(nam)) {
            curS.setUserName(nam);
        } else {
            return;
        }
    }
    // update according to class of signal head
    if (className.equals("jmri.implementation.QuadOutputSignalHead")) {
        Turnout t1 = updateTurnoutFromPanel(eto1, "SignalHead:" + eSysNameLabel.getText() + ":Green", ((QuadOutputSignalHead) curS).getGreen().getBean(), ev1Border.getTitle());
        if (t1 == null) {
            return;
        } else {
            ((QuadOutputSignalHead) curS).setGreen(nbhm.getNamedBeanHandle(eto1.getDisplayName(), t1));
        }
        Turnout t2 = updateTurnoutFromPanel(eto2, "SignalHead:" + eSysNameLabel.getText() + ":Yellow", ((QuadOutputSignalHead) curS).getYellow().getBean(), ev2Border.getTitle());
        if (t2 == null) {
            return;
        } else {
            ((QuadOutputSignalHead) curS).setYellow(nbhm.getNamedBeanHandle(eto2.getDisplayName(), t2));
        }
        Turnout t3 = updateTurnoutFromPanel(eto3, "SignalHead:" + eSysNameLabel.getText() + ":Red", ((QuadOutputSignalHead) curS).getRed().getBean(), ev3Border.getTitle());
        if (t3 == null) {
            return;
        } else {
            ((QuadOutputSignalHead) curS).setRed(nbhm.getNamedBeanHandle(eto3.getDisplayName(), t3));
        }
        Turnout t4 = updateTurnoutFromPanel(eto4, "SignalHead:" + eSysNameLabel.getText() + ":Lunar", ((QuadOutputSignalHead) curS).getLunar().getBean(), ev4Border.getTitle());
        if (t4 == null) {
            return;
        } else {
            ((QuadOutputSignalHead) curS).setLunar(nbhm.getNamedBeanHandle(eto4.getDisplayName(), t4));
        }
    } else if (className.equals("jmri.implementation.TripleTurnoutSignalHead")) {
        Turnout t1 = updateTurnoutFromPanel(eto1, "SignalHead:" + eSysNameLabel.getText() + ":Green", ((TripleTurnoutSignalHead) curS).getGreen().getBean(), ev1Border.getTitle());
        if (t1 == null) {
            return;
        } else {
            ((TripleTurnoutSignalHead) curS).setGreen(nbhm.getNamedBeanHandle(eto1.getDisplayName(), t1));
        }
        Turnout t2 = updateTurnoutFromPanel(eto2, "SignalHead:" + eSysNameLabel.getText() + ":Yellow", ((TripleTurnoutSignalHead) curS).getYellow().getBean(), ev2Border.getTitle());
        if (t2 == null) {
            return;
        } else {
            ((TripleTurnoutSignalHead) curS).setYellow(nbhm.getNamedBeanHandle(eto2.getDisplayName(), t2));
        }
        Turnout t3 = updateTurnoutFromPanel(eto3, "SignalHead:" + eSysNameLabel.getText() + ":Red", ((TripleTurnoutSignalHead) curS).getRed().getBean(), ev3Border.getTitle());
        if (t3 == null) {
            return;
        } else {
            ((TripleTurnoutSignalHead) curS).setRed(nbhm.getNamedBeanHandle(eto3.getDisplayName(), t3));
        }
    } else if (className.equals("jmri.implementation.TripleOutputSignalHead")) {
        Turnout t1 = updateTurnoutFromPanel(eto1, "SignalHead:" + eSysNameLabel.getText() + ":Green", ((TripleOutputSignalHead) curS).getGreen().getBean(), ev1Border.getTitle());
        if (t1 == null) {
            return;
        } else {
            ((TripleOutputSignalHead) curS).setGreen(nbhm.getNamedBeanHandle(eto1.getDisplayName(), t1));
        }
        Turnout t2 = updateTurnoutFromPanel(eto2, "SignalHead:" + eSysNameLabel.getText() + ":Blue", ((TripleOutputSignalHead) curS).getBlue().getBean(), ev2Border.getTitle());
        if (t2 == null) {
            return;
        } else {
            ((TripleOutputSignalHead) curS).setBlue(nbhm.getNamedBeanHandle(eto2.getDisplayName(), t2));
        }
        Turnout t3 = updateTurnoutFromPanel(eto3, "SignalHead:" + eSysNameLabel.getText() + ":Red", ((TripleOutputSignalHead) curS).getRed().getBean(), ev3Border.getTitle());
        if (t3 == null) {
            return;
        } else {
            ((TripleOutputSignalHead) curS).setRed(nbhm.getNamedBeanHandle(eto3.getDisplayName(), t3));
        }
    } else if (className.equals("jmri.implementation.DoubleTurnoutSignalHead")) {
        Turnout t1 = updateTurnoutFromPanel(eto1, "SignalHead:" + eSysNameLabel.getText() + ":Green", ((DoubleTurnoutSignalHead) curS).getGreen().getBean(), ev1Border.getTitle());
        Turnout t2 = updateTurnoutFromPanel(eto2, "SignalHead:" + eSysNameLabel.getText() + ":Red", ((DoubleTurnoutSignalHead) curS).getRed().getBean(), ev2Border.getTitle());
        if (t1 == null) {
            return;
        } else {
            ((DoubleTurnoutSignalHead) curS).setGreen(nbhm.getNamedBeanHandle(eto1.getDisplayName(), t1));
        }
        if (t2 == null) {
            return;
        } else {
            ((DoubleTurnoutSignalHead) curS).setRed(nbhm.getNamedBeanHandle(eto2.getDisplayName(), t2));
        }
    } else if (className.equals("jmri.implementation.SingleTurnoutSignalHead")) {
        Turnout t1 = updateTurnoutFromPanel(eto1, "SignalHead:" + eSysNameLabel.getText() + ":" + (String) es2aBox.getSelectedItem() + ":" + (String) es3aBox.getSelectedItem(), ((SingleTurnoutSignalHead) curS).getOutput().getBean(), ev1Border.getTitle());
        if (t1 == null) {
            noTurnoutMessage(ev1Border.getTitle(), eto1.getDisplayName());
            return;
        }
        ((SingleTurnoutSignalHead) curS).setOutput(nbhm.getNamedBeanHandle(eto1.getDisplayName(), t1));
        ((SingleTurnoutSignalHead) curS).setOnAppearance(signalStateFromBox(es2aBox));
        ((SingleTurnoutSignalHead) curS).setOffAppearance(signalStateFromBox(es3aBox));
    } else if (className.equals("jmri.implementation.LsDecSignalHead")) {
        Turnout t1 = updateTurnoutFromPanel(eto1, "SignalHead:" + eSysNameLabel.getText() + ":Green", ((jmri.implementation.LsDecSignalHead) curS).getGreen().getBean(), ev1Border.getTitle());
        if (t1 == null) {
            return;
        } else {
            ((jmri.implementation.LsDecSignalHead) curS).setGreen(nbhm.getNamedBeanHandle(eto1.getDisplayName(), t1));
            ((jmri.implementation.LsDecSignalHead) curS).setGreenState(turnoutStateFromBox(es1Box));
        }
        Turnout t2 = updateTurnoutFromPanel(eto2, "SignalHead:" + eSysNameLabel.getText() + ":Yellow", ((jmri.implementation.LsDecSignalHead) curS).getYellow().getBean(), ev2Border.getTitle());
        if (t2 == null) {
            return;
        } else {
            ((jmri.implementation.LsDecSignalHead) curS).setYellow(nbhm.getNamedBeanHandle(eto2.getDisplayName(), t2));
            ((jmri.implementation.LsDecSignalHead) curS).setYellowState(turnoutStateFromBox(es2Box));
        }
        Turnout t3 = updateTurnoutFromPanel(eto3, "SignalHead:" + eSysNameLabel.getText() + ":Red", ((jmri.implementation.LsDecSignalHead) curS).getRed().getBean(), ev3Border.getTitle());
        if (t3 == null) {
            return;
        } else {
            ((jmri.implementation.LsDecSignalHead) curS).setRed(nbhm.getNamedBeanHandle(eto3.getDisplayName(), t3));
            ((jmri.implementation.LsDecSignalHead) curS).setRedState(turnoutStateFromBox(es3Box));
        }
        Turnout t4 = updateTurnoutFromPanel(eto4, "SignalHead:" + eSysNameLabel.getText() + ":FlashGreen", ((jmri.implementation.LsDecSignalHead) curS).getFlashGreen().getBean(), ev4Border.getTitle());
        if (t4 == null) {
            return;
        } else {
            ((jmri.implementation.LsDecSignalHead) curS).setFlashGreen(nbhm.getNamedBeanHandle(eto4.getDisplayName(), t4));
            ((jmri.implementation.LsDecSignalHead) curS).setFlashGreenState(turnoutStateFromBox(es4Box));
        }
        Turnout t5 = updateTurnoutFromPanel(eto5, "SignalHead:" + eSysNameLabel.getText() + ":FlashYellow", ((jmri.implementation.LsDecSignalHead) curS).getFlashYellow().getBean(), ev5Border.getTitle());
        if (t5 == null) {
            return;
        } else {
            ((jmri.implementation.LsDecSignalHead) curS).setFlashYellow(nbhm.getNamedBeanHandle(eto5.getDisplayName(), t5));
            ((jmri.implementation.LsDecSignalHead) curS).setFlashYellowState(turnoutStateFromBox(es5Box));
        }
        Turnout t6 = updateTurnoutFromPanel(eto6, "SignalHead:" + eSysNameLabel.getText() + ":FlashRed", ((jmri.implementation.LsDecSignalHead) curS).getFlashRed().getBean(), ev6Border.getTitle());
        if (t6 == null) {
            return;
        } else {
            ((jmri.implementation.LsDecSignalHead) curS).setFlashRed(nbhm.getNamedBeanHandle(eto6.getDisplayName(), t6));
            ((jmri.implementation.LsDecSignalHead) curS).setFlashRedState(turnoutStateFromBox(es6Box));
        }
        Turnout t7 = updateTurnoutFromPanel(eto7, "SignalHead:" + eSysNameLabel.getText() + ":Dark", ((jmri.implementation.LsDecSignalHead) curS).getDark().getBean(), ev7Border.getTitle());
        if (t7 == null) {
            return;
        } else {
            ((jmri.implementation.LsDecSignalHead) curS).setDark(nbhm.getNamedBeanHandle(eto7.getDisplayName(), t7));
            ((jmri.implementation.LsDecSignalHead) curS).setDarkState(turnoutStateFromBox(es7Box));
        }
    } else if (className.equals("jmri.implementation.SE8cSignalHead")) {
        handleSE8cUpdatePressed();
    } else if (className.equals("jmri.jmrix.grapevine.SerialSignalHead")) {
    /*String nam = eUserName.getText();
             // check if user name changed
             if (!((curS.getUserName()!=null) && (curS.getUserName().equals(nam)))) {
             if(checkUserName(nam))
             curS.setUserName(nam);
             }*/
    } else if (className.equals("jmri.jmrix.acela.AcelaSignalHead")) {
        /*String nam = eUserName.getText();
             // check if user name changed
             if (!((curS.getUserName()!=null) && (curS.getUserName().equals(nam)))) {
             if(checkUserName(nam))
             curS.setUserName(nam);

             }*/
        AcelaNode tNode = AcelaAddress.getNodeFromSystemName(curS.getSystemName(), jmri.InstanceManager.getDefault(jmri.jmrix.acela.AcelaSystemConnectionMemo.class));
        if (tNode == null) {
            // node does not exist, ignore call
            log.error("Can't find new Acela Signal with name '{}'", curS.getSystemName());
            return;
        }
        int headnumber = Integer.parseInt(curS.getSystemName().substring(2, curS.getSystemName().length()));
        tNode.setOutputSignalHeadTypeString(headnumber, estBox.getSelectedItem().toString());
    //          setSignalheadTypeInBox(estBox, tNode.getOutputSignalHeadType(headnumber), signalheadTypeValues);
    //          ((jmri.AcelaSignalHead)curS).setDarkState(signalheadTypeFromBox(estBox));
    } else if (className.equals("jmri.implementation.MergSD2SignalHead")) {
        switch(ukSignalAspectsFromBox(emsaBox)) {
            case 4:
                Turnout t3 = updateTurnoutFromPanel(eto5, (Bundle.getMessage("OutputComment", Bundle.getMessage("BeanNameSignalHead"), eSysNameLabel.getText(), Bundle.getMessage("InputNum", "3"))), ((jmri.implementation.MergSD2SignalHead) curS).getInput3().getBean(), ev5Border.getTitle());
                if (t3 == null) {
                    return;
                } else {
                    ((jmri.implementation.MergSD2SignalHead) curS).setInput3(nbhm.getNamedBeanHandle(eto5.getDisplayName(), t3));
                }
            // fall through
            case 3:
                Turnout t2 = updateTurnoutFromPanel(eto4, (Bundle.getMessage("OutputComment", Bundle.getMessage("BeanNameSignalHead"), eSysNameLabel.getText(), Bundle.getMessage("InputNum", "2"))), ((jmri.implementation.MergSD2SignalHead) curS).getInput2().getBean(), ev4Border.getTitle());
                if (t2 == null) {
                    return;
                } else {
                    ((jmri.implementation.MergSD2SignalHead) curS).setInput2(nbhm.getNamedBeanHandle(eto4.getDisplayName(), t2));
                }
            // fall through
            case 2:
                Turnout t1 = updateTurnoutFromPanel(eto3, (Bundle.getMessage("OutputComment", Bundle.getMessage("BeanNameSignalHead"), eSysNameLabel.getText(), Bundle.getMessage("InputNum", "1"))), ((jmri.implementation.MergSD2SignalHead) curS).getInput1().getBean(), ev3Border.getTitle());
                if (t1 == null) {
                    return;
                } else {
                    ((jmri.implementation.MergSD2SignalHead) curS).setInput1(nbhm.getNamedBeanHandle(eto3.getDisplayName(), t1));
                }
                ((jmri.implementation.MergSD2SignalHead) curS).setAspects(ukSignalAspectsFromBox(emsaBox));
                if (ukSignalTypeFromBox(emstBox).equals("Distant")) {
                    ((jmri.implementation.MergSD2SignalHead) curS).setHome(false);
                } else {
                    ((jmri.implementation.MergSD2SignalHead) curS).setHome(true);
                }
            default:
                break;
        }
    //Need to add the code here for update!
    } else if (className.equals("jmri.implementation.DccSignalHead")) {
        for (int i = 0; i < dccAspectEdt.length; i++) {
            int number = (Integer) dccAspectEdt[i].getValue();
            try {
                ((DccSignalHead) curS).setOutputForAppearance(((DccSignalHead) curS).getValidStates()[i], number);
            } catch (Exception ex) {
                //in theory JSpinner should already have caught a number conversion error.
                log.error(ex.toString());
            }
        }
        ((DccSignalHead) curS).useAddressOffSet(dccOffSetAddressEdt.isSelected());
    } else {
        log.error("Internal error - cannot update signal of type " + className);
    }
    // successful
    editFrame.setVisible(false);
    editingHead = false;
}
Also used : AcelaNode(jmri.jmrix.acela.AcelaNode) TripleOutputSignalHead(jmri.implementation.TripleOutputSignalHead) SingleTurnoutSignalHead(jmri.implementation.SingleTurnoutSignalHead) QuadOutputSignalHead(jmri.implementation.QuadOutputSignalHead) Turnout(jmri.Turnout) DccSignalHead(jmri.implementation.DccSignalHead) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with DccSignalHead

use of jmri.implementation.DccSignalHead in project JMRI by JMRI.

the class SignalHeadTableAction method handleDCCOkPressed.

void handleDCCOkPressed() {
    DccSignalHead s;
    String systemNameText = ConnectionNameFromSystemName.getPrefixFromName((String) prefixBox.getSelectedItem());
    //if we return a null string then we will set it to use internal, thus picking up the default command station at a later date.
    if (systemNameText.equals("\0")) {
        systemNameText = "I";
    }
    systemNameText = systemNameText + "H$" + systemName.getText();
    if (checkBeforeCreating(systemNameText)) {
        s = new jmri.implementation.DccSignalHead(systemNameText);
        s.setUserName(userName.getText());
        log.debug("dccAspect Length = {}", dccAspect.length);
        for (int i = 0; i < DccSignalHead.getDefaultValidStates().length; i++) {
            // no need to check DCC ID input when using JSpinner
            log.debug("i = {}", i);
            int number = (Integer) dccAspect[i].getValue();
            try {
                s.setOutputForAppearance(s.getValidStates()[i], number);
            } catch (RuntimeException ex) {
                log.warn("error setting \"{}\" output for appearance \"{}\"", systemNameText, number);
            }
        }
        InstanceManager.getDefault(jmri.SignalHeadManager.class).register(s);
        s.useAddressOffSet(dccOffSetAddress.isSelected());
    }
}
Also used : DccSignalHead(jmri.implementation.DccSignalHead) DccSignalHead(jmri.implementation.DccSignalHead)

Example 4 with DccSignalHead

use of jmri.implementation.DccSignalHead in project JMRI by JMRI.

the class DccSignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    DccSignalHead h;
    if (uname == null) {
        h = new DccSignalHead(sys);
    } else {
        h = new DccSignalHead(sys, uname);
    }
    loadCommon(h, shared);
    if (shared.getChild("useAddressOffSet") != null) {
        if (shared.getChild("useAddressOffSet").getText().equals("yes")) {
            h.useAddressOffSet(true);
        }
    }
    List<Element> list = shared.getChildren("aspect");
    for (Element e : list) {
        String aspect = e.getAttribute("defines").getValue();
        int number = -1;
        try {
            String value = e.getChild("number").getValue();
            number = Integer.parseInt(value);
        } catch (Exception ex) {
            log.error("failed to convert DCC number");
        }
        int indexOfAspect = -1;
        for (int i = 0; i < h.getValidStates().length; i++) {
            if (h.getValidStateNames()[i].equals(aspect)) {
                indexOfAspect = i;
                break;
            }
        }
        if (indexOfAspect != -1) {
            h.setOutputForAppearance(h.getValidStates()[indexOfAspect], number);
        }
    }
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : Element(org.jdom2.Element) DccSignalHead(jmri.implementation.DccSignalHead)

Aggregations

DccSignalHead (jmri.implementation.DccSignalHead)4 Element (org.jdom2.Element)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Turnout (jmri.Turnout)1 QuadOutputSignalHead (jmri.implementation.QuadOutputSignalHead)1 SingleTurnoutSignalHead (jmri.implementation.SingleTurnoutSignalHead)1 TripleOutputSignalHead (jmri.implementation.TripleOutputSignalHead)1 AcelaNode (jmri.jmrix.acela.AcelaNode)1