Search in sources :

Example 1 with MatrixSignalMast

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

the class MatrixSignalMastXml method store.

/**
     * Default implementation for storing the contents of a
     * MatrixSignalMastManager
     *
     * @param o Object to store, of type MatrixSignalMast
     * @return e Element containing the complete info
     */
@Override
public Element store(Object o) {
    // from mast p to XML
    MatrixSignalMast p = (MatrixSignalMast) o;
    Element e = new Element("matrixsignalmast");
    e.setAttribute("class", this.getClass().getName());
    // include content
    e.addContent(new Element("systemName").addContent(p.getSystemName()));
    // username, comment & properties
    storeCommon(p, e);
    // mast properties:
    Element unlit = new Element("unlit");
    if (p.allowUnLit()) {
        unlit.setAttribute("allowed", "yes");
        unlit.addContent(new Element("bitString").addContent(p.getUnLitChars()));
    } else {
        unlit.setAttribute("allowed", "no");
    }
    e.addContent(unlit);
    List<String> outputs = p.getOutputs();
    // convert char[] to xml-storable simple String
    // max. 5 outputs (either: turnouts (bean names) [or ToDo: DCC addresses (numbers)]
    // spotted by FindBugs as to never be null (check on creation of MatrixMast)
    Element outps = new Element("outputs");
    int i = 1;
    for (String _output : outputs) {
        String key = ("output" + i);
        Element outp = new Element("output");
        outp.setAttribute("matrixCol", key);
        // get name (Turnout)
        outp.addContent(p.getOutputName(i));
        outps.addContent(outp);
        i++;
    }
    if (outputs.size() != 0) {
        e.addContent(outps);
    }
    // string of max. 6 chars "001010" describing matrix row per aspect
    SignalAppearanceMap appMap = p.getAppearanceMap();
    if (appMap != null) {
        Element bss = new Element("bitStrings");
        java.util.Enumeration<String> aspects = appMap.getAspects();
        while (aspects.hasMoreElements()) {
            String key = aspects.nextElement();
            Element bs = new Element("bitString");
            bs.setAttribute("aspect", key);
            bs.addContent(p.getBitstring(key));
            bss.addContent(bs);
        }
        e.addContent(bss);
    }
    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) SignalAppearanceMap(jmri.SignalAppearanceMap) MatrixSignalMast(jmri.implementation.MatrixSignalMast)

Example 2 with MatrixSignalMast

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

the class AddSignalMastPanel method copyFromAnotherMatrixMastAspect.

// todo: validate entries, ie check & warn for duplicates
/*    static boolean validateMatrixAspectBits(String strAspect) {
        int aspect = -1;
        try {
            aspect = Integer.parseInt(strAspect.trim());
        } catch (java.lang.NumberFormatException e) {
            JOptionPane.showMessageDialog(null, Bundle.getMessage("AspectMastBitsWarning"));
            return false;
        }

        if (aspect < 0 || aspect > 31) {
            JOptionPane.showMessageDialog(null, Bundle.getMessage("AspectMastBitsOutOfRange"));
            log.error("invalid aspect " + aspect);
            return false;
        }
        return true;
    }

    boolean validateAspectBits() {
        if (aspectBitsField.getText().equals("")) {
            JOptionPane.showMessageDialog(null, Bundle.getMessage("MatrixMastBitsBlank"));
            return false;
        }
        int address = -1;
        try {
            address = Integer.parseInt(dccAspectAddressField.getText().trim());
        } catch (java.lang.NumberFormatException e) {
            JOptionPane.showMessageDialog(null, Bundle.getMessage("DCCMastAddressNumber"));
            return false;
        }

        if (address < NmraPacket.accIdLowLimit || address > NmraPacket.accIdAltHighLimit) {
            JOptionPane.showMessageDialog(null, Bundle.getMessage("DCCMastAddressOutOfRange"));
            log.error("invalid address " + address);
            return false;
        }
        if (DccSignalMast.isDCCAddressUsed(address) != null) {
            String msg = Bundle.getMessage("DCCMastAddressAssigned", new Object[]{dccAspectAddressField.getText(),
             DccSignalMast.isDCCAddressUsed(address)});
            JOptionPane.showMessageDialog(null, msg);
            return false;
        }
        return true;
    }*/
void copyFromAnotherMatrixMastAspect(String strMast) {
    MatrixSignalMast mast = (MatrixSignalMast) InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(strMast);
    if (bitNum != mast.getBitNum()) {
        int i = JOptionPane.showConfirmDialog(null, Bundle.getMessage("MatrixColWarning", mast.getBitNum(), bitNum), Bundle.getMessage("MatrixColWarningTitle"), JOptionPane.YES_NO_OPTION);
        if (i != 0) {
            return;
        }
    }
    // cf. line 405 loading an existing mast for edit
    for (String key : matrixAspect.keySet()) {
        // select the right checkboxes
        // load aspectpanel from hashmap
        MatrixAspectPanel matrixPanel = matrixAspect.get(key);
        // sets a disabled aspect
        matrixPanel.setAspectDisabled(mast.isAspectDisabled(key));
        if (!mast.isAspectDisabled(key)) {
            // same as loading an existing MatrixMast
            char[] mastBits = mast.getBitsForAspect(key);
            // store as 6 character array in panel
            char[] panelAspectBits = Arrays.copyOf(mastBits, MAXMATRIXBITS);
            matrixPanel.updateAspectBits(panelAspectBits);
            matrixPanel.setAspectBoxes(panelAspectBits);
        // sets boxes 1 - MAXMATRIXBITS on aspect sub panel from values in hashmap char[] like: 1001
        }
    }
}
Also used : MatrixSignalMast(jmri.implementation.MatrixSignalMast)

Example 3 with MatrixSignalMast

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

the class AddSignalMastPanel method copyFromMastSelection.

JComboBox<String> copyFromMastSelection() {
    JComboBox<String> mastSelect = new JComboBox<String>();
    List<String> names = InstanceManager.getDefault(jmri.SignalMastManager.class).getSystemNameList();
    for (String name : names) {
        if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
            if ((InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name) instanceof DccSignalMast) && InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name).getSignalSystem().getSystemName().equals(sigsysname) && !InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName().equals(userName.getText())) {
                // don't copy yourself
                mastSelect.addItem(InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName());
            }
        } else if ((Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem()))) {
            if ((InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name) instanceof MatrixSignalMast) && InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name).getSignalSystem().getSystemName().equals(sigsysname) && !InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName().equals(userName.getText())) {
                // don't copy yourself
                mastSelect.addItem(InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName());
            }
        }
    }
    if (mastSelect.getItemCount() == 0) {
        mastSelect.setEnabled(false);
    } else {
        mastSelect.insertItemAt("", 0);
        mastSelect.setSelectedIndex(0);
        mastSelect.addActionListener(new ActionListener() {

            // e.getSource() cast from mastSelect source
            @SuppressWarnings("unchecked")
            @Override
            public void actionPerformed(ActionEvent e) {
                JComboBox<String> eb = (JComboBox<String>) e.getSource();
                String sourceMast = (String) eb.getSelectedItem();
                if (sourceMast != null && !sourceMast.equals("")) {
                    if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
                        copyFromAnotherDCCMastAspect(sourceMast);
                    } else if ((Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem()))) {
                        copyFromAnotherMatrixMastAspect(sourceMast);
                    }
                }
            }
        });
    }
    return mastSelect;
}
Also used : JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DccSignalMast(jmri.implementation.DccSignalMast) MatrixSignalMast(jmri.implementation.MatrixSignalMast)

Example 4 with MatrixSignalMast

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

the class MatrixSignalMastXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // from XML to mast m
    MatrixSignalMast m;
    String sys = getSystemName(shared);
    try {
        m = new jmri.implementation.MatrixSignalMast(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));
    }
    // username & comment
    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);
                String bits = unlit.getChild("bitString").getText();
                m.setUnLitBits(bits);
            }
        }
    }
    // multiple
    Element outps = shared.getChild("outputs");
    if (outps != null) {
        // singular
        List<Element> list = outps.getChildren("output");
        int i = 0;
        for (Element outp : list) {
            // count outputs
            i++;
        }
        // set char[] size before creating outputs
        m.setBitNum(i);
        for (Element outp : list) {
            String outputname = outp.getAttribute("matrixCol").getValue();
            String turnoutname = outp.getText();
            m.setOutput(outputname, turnoutname);
        }
    }
    // multiple
    Element bss = shared.getChild("bitStrings");
    if (bss != null) {
        // singular
        List<Element> list = bss.getChildren("bitString");
        for (Element bs : list) {
            // OK if value is null
            m.setBitstring(bs.getAttribute("aspect").getValue(), bs.getText());
        }
    }
    // multiple
    Element disabled = shared.getChild("disabledAspects");
    if (disabled != null) {
        // singular
        List<Element> list = disabled.getChildren("disabledAspect");
        for (Element asp : list) {
            m.setAspectDisabled(asp.getText());
        }
    }
    InstanceManager.getDefault(jmri.SignalMastManager.class).register(m);
    return true;
}
Also used : Element(org.jdom2.Element) MatrixSignalMast(jmri.implementation.MatrixSignalMast) MatrixSignalMast(jmri.implementation.MatrixSignalMast)

Example 5 with MatrixSignalMast

use of jmri.implementation.MatrixSignalMast 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

MatrixSignalMast (jmri.implementation.MatrixSignalMast)5 DccSignalMast (jmri.implementation.DccSignalMast)2 Element (org.jdom2.Element)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 URISyntaxException (java.net.URISyntaxException)1 JComboBox (javax.swing.JComboBox)1 SignalAppearanceMap (jmri.SignalAppearanceMap)1 SignalMast (jmri.SignalMast)1 SignalHeadSignalMast (jmri.implementation.SignalHeadSignalMast)1 TurnoutSignalMast (jmri.implementation.TurnoutSignalMast)1 VirtualSignalMast (jmri.implementation.VirtualSignalMast)1 JmriBeanComboBox (jmri.util.swing.JmriBeanComboBox)1