Search in sources :

Example 1 with SignalHeadSignalMast

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

the class SignalHeadSignalMastXml method store.

/**
     * Default implementation for storing the contents of a
     * DefaultSignalMastManager
     *
     * @param o Object to store, of type TripleTurnoutSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SignalHeadSignalMast p = (SignalHeadSignalMast) o;
    Element e = new Element("signalmast");
    e.setAttribute("class", this.getClass().getName());
    e.addContent(new Element("systemName").addContent(p.getSystemName()));
    storeCommon(p, e);
    Element unlit = new Element("unlit");
    if (p.allowUnLit()) {
        unlit.setAttribute("allowed", "yes");
    } else {
        unlit.setAttribute("allowed", "no");
    }
    e.addContent(unlit);
    List<String> disabledAspects = p.getDisabledAspects();
    if (disabledAspects != null) {
        Element el = new Element("disabledAspects");
        for (String aspect : disabledAspects) {
            Element ele = new Element("disabledAspect");
            ele.addContent(aspect);
            el.addContent(ele);
        }
        if (disabledAspects.size() != 0) {
            e.addContent(el);
        }
    }
    return e;
}
Also used : Element(org.jdom2.Element) SignalHeadSignalMast(jmri.implementation.SignalHeadSignalMast)

Example 2 with SignalHeadSignalMast

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

the class SignalHeadSignalMastXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    SignalMast m;
    String sys = getSystemName(shared);
    try {
        m = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(sys);
    } catch (Exception e) {
        log.error("An error occured while trying to create the signal '" + sys + "' " + e.toString());
        return false;
    }
    if (getUserName(shared) != null) {
        m.setUserName(getUserName(shared));
    }
    loadCommon(m, shared);
    if (shared.getChild("unlit") != null) {
        Element unlit = shared.getChild("unlit");
        if (unlit.getAttribute("allowed") != null) {
            if (unlit.getAttribute("allowed").getValue().equals("no")) {
                m.setAllowUnLit(false);
            } else {
                m.setAllowUnLit(true);
            }
        }
    }
    Element e = shared.getChild("disabledAspects");
    if (e != null) {
        List<Element> list = e.getChildren("disabledAspect");
        for (Element aspect : list) {
            ((SignalHeadSignalMast) m).setAspectDisabled(aspect.getText());
        }
    }
    return true;
}
Also used : Element(org.jdom2.Element) SignalMast(jmri.SignalMast) SignalHeadSignalMast(jmri.implementation.SignalHeadSignalMast) SignalHeadSignalMast(jmri.implementation.SignalHeadSignalMast)

Example 3 with SignalHeadSignalMast

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

the class AddSignalMastPanel method okPressed.

/**
     * Store user input for a signal mast definition in new or existing mast object.
     * <p>
     * Invoked from Apply/Create button.
     *
     * @param e the event heard
     */
void okPressed(ActionEvent e) {
    String mastname = mastNames.get(mastBox.getSelectedIndex()).getName();
    // N11N
    String user = userName.getText().trim();
    if (user.equals("")) {
        int i = JOptionPane.showConfirmDialog(null, "No Username has been defined, this may cause issues when editing the mast later.\nAre you sure that you want to continue?", "No UserName Given", JOptionPane.YES_NO_OPTION);
        if (i != 0) {
            return;
        }
    }
    // create new mast
    if (mast == null) {
        if (!checkUserName(userName.getText())) {
            return;
        }
        if (Bundle.getMessage("HeadCtlMast").equals(signalMastDriver.getSelectedItem())) {
            if (!checkSignalHeadUse()) {
                return;
            }
            StringBuilder build = new StringBuilder();
            build.append("IF$shsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4));
            for (JmriBeanComboBox head : headList) {
                if (head != null && head.getSelectedDisplayName() != null)
                    build.append("(" + StringUtil.parenQuote(head.getSelectedDisplayName()) + ")");
            }
            String name = build.toString();
            log.debug("add signal: " + name);
            SignalMast m = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name);
            if (m != null) {
                JOptionPane.showMessageDialog(null, java.text.MessageFormat.format(Bundle.getMessage("DuplicateMast"), new Object[] { m.getDisplayName() }), Bundle.getMessage("DuplicateMastTitle"), JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            try {
                m = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(name);
            } catch (IllegalArgumentException ex) {
                // user input no good
                handleCreateException(name);
                // without creating
                return;
            }
            if (!user.equals("")) {
                m.setUserName(user);
            }
            for (String aspect : disabledAspects.keySet()) {
                if (disabledAspects.get(aspect).isSelected()) {
                    ((SignalHeadSignalMast) m).setAspectDisabled(aspect);
                } else {
                    ((SignalHeadSignalMast) m).setAspectEnabled(aspect);
                }
            }
            m.setAllowUnLit(allowUnLit.isSelected());
        } else if (Bundle.getMessage("TurnCtlMast").equals(signalMastDriver.getSelectedItem())) {
            String name = "IF$tsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
            name += "($" + (paddedNumber.format(TurnoutSignalMast.getLastRef() + 1)) + ")";
            TurnoutSignalMast turnMast = new TurnoutSignalMast(name);
            for (String aspect : turnoutAspect.keySet()) {
                turnoutAspect.get(aspect).setReference(name + ":" + aspect);
                turnoutMastPanel.add(turnoutAspect.get(aspect).getPanel());
                if (turnoutAspect.get(aspect).isAspectDisabled()) {
                    turnMast.setAspectDisabled(aspect);
                } else {
                    turnMast.setAspectEnabled(aspect);
                    turnMast.setTurnout(aspect, turnoutAspect.get(aspect).getTurnoutName(), turnoutAspect.get(aspect).getTurnoutState());
                }
            }
            turnMast.resetPreviousStates(resetPreviousState.isSelected());
            if (!user.equals("")) {
                turnMast.setUserName(user);
            }
            InstanceManager.getDefault(jmri.SignalMastManager.class).register(turnMast);
            turnMast.setAllowUnLit(allowUnLit.isSelected());
            if (allowUnLit.isSelected()) {
                turnMast.setUnLitTurnout(turnoutUnLitBox.getDisplayName(), turnoutStateValues[turnoutUnLitState.getSelectedIndex()]);
            }
        } else if (Bundle.getMessage("VirtualMast").equals(signalMastDriver.getSelectedItem())) {
            String name = "IF$vsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
            name += "($" + (paddedNumber.format(VirtualSignalMast.getLastRef() + 1)) + ")";
            VirtualSignalMast virtMast = new VirtualSignalMast(name);
            if (!user.equals("")) {
                virtMast.setUserName(user);
            }
            InstanceManager.getDefault(jmri.SignalMastManager.class).register(virtMast);
            for (String aspect : disabledAspects.keySet()) {
                if (disabledAspects.get(aspect).isSelected()) {
                    virtMast.setAspectDisabled(aspect);
                } else {
                    virtMast.setAspectEnabled(aspect);
                }
            }
            virtMast.setAllowUnLit(allowUnLit.isSelected());
        } else if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
            if (!validateDCCAddress()) {
                return;
            }
            String systemNameText = ConnectionNameFromSystemName.getPrefixFromName((String) systemPrefixBox.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";
            }
            if (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem())) {
                systemNameText = systemNameText + "F$lncpsm:";
            } else {
                systemNameText = systemNameText + "F$dsm:";
            }
            String name = systemNameText + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
            name += "(" + dccAspectAddressField.getText() + ")";
            DccSignalMast dccMast;
            if (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem())) {
                dccMast = new jmri.jmrix.loconet.LNCPSignalMast(name);
            } else {
                dccMast = new DccSignalMast(name);
            }
            for (String aspect : dccAspect.keySet()) {
                // update mast from aspect subpanel panel
                dccMastPanel.add(dccAspect.get(aspect).getPanel());
                if (dccAspect.get(aspect).isAspectDisabled()) {
                    dccMast.setAspectDisabled(aspect);
                } else {
                    dccMast.setAspectEnabled(aspect);
                    dccMast.setOutputForAppearance(aspect, dccAspect.get(aspect).getAspectId());
                }
            }
            if (!user.equals("")) {
                dccMast.setUserName(user);
            }
            dccMast.setAllowUnLit(allowUnLit.isSelected());
            if (allowUnLit.isSelected()) {
                dccMast.setUnlitId(Integer.parseInt(unLitAspectField.getText()));
            }
            InstanceManager.getDefault(jmri.SignalMastManager.class).register(dccMast);
        } else if (Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem())) {
            // Create was pressed for new mast, check all boxes are filled
            if (turnoutBox1.getDisplayName().isEmpty() || (bitNum > 1 && turnoutBox2.getDisplayName().isEmpty()) || (bitNum > 2 && turnoutBox3.getDisplayName().isEmpty()) || (bitNum > 3 && turnoutBox4.getDisplayName().equals("")) || (bitNum > 4 && turnoutBox5.getDisplayName().equals("")) || (bitNum > 5 && turnoutBox6.getDisplayName().equals(""))) {
                // radd extra OR in order to set MAXMATRIXBITS > 6
                //error dialog
                JOptionPane.showMessageDialog(null, Bundle.getMessage("MatrixOutputEmpty", mastname), Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
                log.error("Empty output on panel");
                return;
            }
            //create new MatrixMast with props from panel
            String name = "IF$xsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
            name += "($" + (paddedNumber.format(MatrixSignalMast.getLastRef() + 1));
            // for the number of t = "turnout-outputs", add option for direct packets
            name += ")" + "-" + bitNum + "t";
            MatrixSignalMast matrixMast = new MatrixSignalMast(name);
            // store number of columns in aspect - outputs matrix in mast
            matrixMast.setBitNum(bitNum);
            //store outputs from turnoutBoxes; method in line 976
            // store choice from turnoutBox1
            matrixMast.setOutput("output1", turnoutBox1.getDisplayName());
            // write mast name to output1 bean comment
            setMatrixReference(turnoutBox1, name + ":output1");
            if (bitNum > 1) {
                // store choice from turnoutBox2
                matrixMast.setOutput("output2", turnoutBox2.getDisplayName());
                // write mast name to output2 bean comment
                setMatrixReference(turnoutBox2, name + ":output2");
                if (bitNum > 2) {
                    // store choice from turnoutBox3
                    matrixMast.setOutput("output3", turnoutBox3.getDisplayName());
                    // write mast name to output3 bean comment
                    setMatrixReference(turnoutBox3, name + ":output3");
                    if (bitNum > 3) {
                        // store choice from turnoutBox4
                        matrixMast.setOutput("output4", turnoutBox4.getDisplayName());
                        // write mast name to output4 bean comment
                        setMatrixReference(turnoutBox4, name + ":output4");
                        if (bitNum > 4) {
                            // store choice from turnoutBox5
                            matrixMast.setOutput("output5", turnoutBox5.getDisplayName());
                            // write mast name to output5 bean comment
                            setMatrixReference(turnoutBox5, name + ":output5");
                            if (bitNum > 5) {
                                // store choice from turnoutBox6
                                matrixMast.setOutput("output6", turnoutBox6.getDisplayName());
                                // write mast name to output6 bean comment
                                setMatrixReference(turnoutBox6, name + ":output6");
                            // repeat in order to set MAXMATRIXBITS > 6
                            }
                        }
                    }
                }
            }
            for (String aspect : matrixAspect.keySet()) {
                // store matrix in mast per aspect, compare with line 991
                // read from aspect panel to mast
                matrixMastPanel.add(matrixAspect.get(aspect).getPanel());
                if (matrixAspect.get(aspect).isAspectDisabled()) {
                    // don't store bits when this aspect is disabled
                    matrixMast.setAspectDisabled(aspect);
                } else {
                    matrixMast.setAspectEnabled(aspect);
                    // return as char[]
                    matrixMast.setBitsForAspect(aspect, matrixAspect.get(aspect).trimAspectBits());
                }
            }
            // read from panel, not displayed?
            matrixMast.resetPreviousStates(resetPreviousState.isSelected());
            matrixMast.setAllowUnLit(allowUnLit.isSelected());
            if (allowUnLit.isSelected()) {
                // copy bits from UnLitPanel var unLitPanelBits
                try {
                    // same as line 1046,
                    matrixMast.setUnLitBits(trimUnLitBits());
                } catch (Exception ex) {
                    log.error("failed to read and copy unLitPanelBits");
                }
            }
            if (!user.equals("")) {
                matrixMast.setUserName(user);
            }
            // store bitNum pref
            prefs.addComboBoxLastSelection(matrixBitNumSelectionCombo, (String) columnChoice.getSelectedItem());
            InstanceManager.getDefault(jmri.SignalMastManager.class).register(matrixMast);
        }
        prefs.addComboBoxLastSelection(systemSelectionCombo, (String) sigSysBox.getSelectedItem());
        prefs.addComboBoxLastSelection(driverSelectionCombo, (String) signalMastDriver.getSelectedItem());
        prefs.addComboBoxLastSelection(mastSelectionCombo + ":" + ((String) sigSysBox.getSelectedItem()), (String) mastBox.getSelectedItem());
        refreshHeadComboBox();
    } else {
        // Edit mode, mast was already available
        if (Bundle.getMessage("HeadCtlMast").equals(signalMastDriver.getSelectedItem())) {
            SignalHeadSignalMast headMast = (SignalHeadSignalMast) mast;
            for (String aspect : disabledAspects.keySet()) {
                if (disabledAspects.get(aspect).isSelected()) {
                    headMast.setAspectDisabled(aspect);
                } else {
                    headMast.setAspectEnabled(aspect);
                }
            }
            headMast.setAllowUnLit(allowUnLit.isSelected());
        } else if (Bundle.getMessage("TurnCtlMast").equals(signalMastDriver.getSelectedItem())) {
            String name = "IF$tsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
            TurnoutSignalMast turnMast = (TurnoutSignalMast) mast;
            for (String aspect : turnoutAspect.keySet()) {
                turnoutAspect.get(aspect).setReference(name + ":" + aspect);
                turnMast.setTurnout(aspect, turnoutAspect.get(aspect).getTurnoutName(), turnoutAspect.get(aspect).getTurnoutState());
                turnoutMastPanel.add(turnoutAspect.get(aspect).getPanel());
                if (turnoutAspect.get(aspect).isAspectDisabled()) {
                    turnMast.setAspectDisabled(aspect);
                } else {
                    turnMast.setAspectEnabled(aspect);
                }
            }
            turnMast.resetPreviousStates(resetPreviousState.isSelected());
            turnMast.setAllowUnLit(allowUnLit.isSelected());
            if (allowUnLit.isSelected()) {
                turnMast.setUnLitTurnout(turnoutUnLitBox.getDisplayName(), turnoutStateValues[turnoutUnLitState.getSelectedIndex()]);
            }
        } else if (Bundle.getMessage("VirtualMast").equals(signalMastDriver.getSelectedItem())) {
            VirtualSignalMast virtMast = (VirtualSignalMast) mast;
            for (String aspect : disabledAspects.keySet()) {
                if (disabledAspects.get(aspect).isSelected()) {
                    virtMast.setAspectDisabled(aspect);
                } else {
                    virtMast.setAspectEnabled(aspect);
                }
            }
            virtMast.setAllowUnLit(allowUnLit.isSelected());
        } else if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
            DccSignalMast dccMast = (DccSignalMast) mast;
            for (String aspect : dccAspect.keySet()) {
                dccMastPanel.add(dccAspect.get(aspect).getPanel());
                if (dccAspect.get(aspect).isAspectDisabled()) {
                    dccMast.setAspectDisabled(aspect);
                } else {
                    dccMast.setAspectEnabled(aspect);
                    dccMast.setOutputForAppearance(aspect, dccAspect.get(aspect).getAspectId());
                }
            }
            dccMast.setAllowUnLit(allowUnLit.isSelected());
            if (allowUnLit.isSelected()) {
                dccMast.setUnlitId(Integer.parseInt(unLitAspectField.getText()));
            }
        } else if (Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem())) {
            // Apply was pressed, store existing MatrixMast
            MatrixSignalMast matrixMast = (MatrixSignalMast) mast;
            // store number of columns in aspect - outputs matrix in mast
            matrixMast.setBitNum(bitNum);
            //store outputs from turnoutBoxes; method in line 865
            // store choice from turnoutBox1
            matrixMast.setOutput("output1", turnoutBox1.getDisplayName());
            // write mast name to output1 bean comment
            setMatrixReference(turnoutBox1, matrixMast.getSystemName() + ":output1");
            if (bitNum > 1) {
                // store choice from turnoutBox2
                matrixMast.setOutput("output2", turnoutBox2.getDisplayName());
                // write mast name to output2 bean comment
                setMatrixReference(turnoutBox2, matrixMast.getSystemName() + ":output2");
                if (bitNum > 2) {
                    // store choice from turnoutBox3
                    matrixMast.setOutput("output3", turnoutBox3.getDisplayName());
                    // write mast name to output3 bean comment
                    setMatrixReference(turnoutBox3, matrixMast.getSystemName() + ":output3");
                    if (bitNum > 3) {
                        // store choice from turnoutBox4
                        matrixMast.setOutput("output4", turnoutBox4.getDisplayName());
                        // write mast name to output4 bean comment
                        setMatrixReference(turnoutBox4, matrixMast.getSystemName() + ":output4");
                        if (bitNum > 4) {
                            // store choice from turnoutBox5
                            matrixMast.setOutput("output5", turnoutBox5.getDisplayName());
                            // write mast name to output5 bean comment
                            setMatrixReference(turnoutBox5, matrixMast.getSystemName() + ":output5");
                            if (bitNum > 4) {
                                // store choice from turnoutBox6
                                matrixMast.setOutput("output6", turnoutBox6.getDisplayName());
                                // write mast name to output6 bean comment
                                setMatrixReference(turnoutBox6, matrixMast.getSystemName() + ":output6");
                            // nest if in order to set MAXMATRIXBITS > 6
                            }
                        }
                    }
                }
            }
            for (String aspect : matrixAspect.keySet()) {
                // store matrix in mast, compare with line 881
                // from matrixMastPanel hashtable to matrixMast
                // update from aspect panel to mast
                matrixMastPanel.add(matrixAspect.get(aspect).getPanel());
                if (matrixAspect.get(aspect).isAspectDisabled()) {
                    // don't store bits when this aspect is disabled
                    matrixMast.setAspectDisabled(aspect);
                } else {
                    matrixMast.setAspectEnabled(aspect);
                    // return as char[]
                    matrixMast.setBitsForAspect(aspect, matrixAspect.get(aspect).trimAspectBits());
                }
            }
            matrixMast.resetPreviousStates(resetPreviousState.isSelected());
            matrixMast.setAllowUnLit(allowUnLit.isSelected());
            if (allowUnLit.isSelected()) {
                try {
                    // same as line 929
                    matrixMast.setUnLitBits(trimUnLitBits());
                } catch (Exception ex) {
                    log.error("failed to read and copy unLitPanelBits");
                }
            }
        }
    }
    // close and dispose JPanel
    clearPanel();
}
Also used : TurnoutSignalMast(jmri.implementation.TurnoutSignalMast) VirtualSignalMast(jmri.implementation.VirtualSignalMast) MatrixSignalMast(jmri.implementation.MatrixSignalMast) URISyntaxException(java.net.URISyntaxException) JmriBeanComboBox(jmri.util.swing.JmriBeanComboBox) DccSignalMast(jmri.implementation.DccSignalMast) SignalMast(jmri.SignalMast) VirtualSignalMast(jmri.implementation.VirtualSignalMast) DccSignalMast(jmri.implementation.DccSignalMast) TurnoutSignalMast(jmri.implementation.TurnoutSignalMast) MatrixSignalMast(jmri.implementation.MatrixSignalMast) SignalHeadSignalMast(jmri.implementation.SignalHeadSignalMast) SignalHeadSignalMast(jmri.implementation.SignalHeadSignalMast)

Aggregations

SignalHeadSignalMast (jmri.implementation.SignalHeadSignalMast)3 SignalMast (jmri.SignalMast)2 Element (org.jdom2.Element)2 URISyntaxException (java.net.URISyntaxException)1 DccSignalMast (jmri.implementation.DccSignalMast)1 MatrixSignalMast (jmri.implementation.MatrixSignalMast)1 TurnoutSignalMast (jmri.implementation.TurnoutSignalMast)1 VirtualSignalMast (jmri.implementation.VirtualSignalMast)1 JmriBeanComboBox (jmri.util.swing.JmriBeanComboBox)1