Search in sources :

Example 16 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SignalGroupTableAction method editPressed.

/**
     * Respond to the Edit button in the Signal Group Table
     * after creating the Add/Edit pane with AddPressed supplying _SystemName.
     * Hides the editable _systemName field on the Add Group pane and displays the value as a label instead.
     * @param e Event from origin, null if invoked by clicking the Edit button in a Signal Group Table row
     */
void editPressed(ActionEvent e) {
    // identify the Signal Group with this name if it already exists
    // is already filled in from the Signal Group table by addPressed()
    String sName = _systemName.getText().toUpperCase();
    SignalGroup g = jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class).getBySystemName(sName);
    if (g == null) {
        // Signal Group does not exist, so cannot be edited
        return;
    }
    g.addPropertyChangeListener(this);
    // Signal Group was found, make its system name not changeable
    curSignalGroup = g;
    log.debug("curSignalGroup was set");
    jmri.SignalMast sm = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(g.getSignalMastName());
    if (sm != null) {
        java.util.Vector<String> aspects = sm.getValidAspects();
        _mastAspectsList = new ArrayList<SignalMastAspect>(aspects.size());
        for (int i = 0; i < aspects.size(); i++) {
            _mastAspectsList.add(new SignalMastAspect(aspects.get(i)));
        }
    } else {
        // false indicates Can't find mast (but quoted name stands for a head) TODO
        log.error("Failed to get signal mast {}", g.getSignalMastName());
    }
    fixedSystemName.setText(sName);
    fixedSystemName.setVisible(true);
    _systemName.setVisible(false);
    mainSignalComboBox.setSelectedBean(g.getSignalMast());
    _userName.setText(g.getUserName());
    int setRow = 0;
    for (int i = _signalHeadsList.size() - 1; i >= 0; i--) {
        SignalGroupSignalHead sgsh = _signalHeadsList.get(i);
        SignalHead sigBean = sgsh.getBean();
        if (g.isHeadIncluded(sigBean)) {
            sgsh.setIncluded(true);
            sgsh.setOnState(g.getHeadOnState(sigBean));
            sgsh.setOffState(g.getHeadOffState(sigBean));
            setRow = i;
        } else {
            sgsh.setIncluded(false);
        }
    }
    _SignalGroupHeadScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _SignalGroupHeadModel.fireTableDataChanged();
    for (int i = 0; i < _mastAspectsList.size(); i++) {
        SignalMastAspect _aspect = _mastAspectsList.get(i);
        String asp = _aspect.getAspect();
        if (g.isSignalMastAspectIncluded(asp)) {
            _aspect.setIncluded(true);
            setRow = i;
        } else {
            _aspect.setIncluded(false);
        }
    }
    _SignalAppearanceScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _AspectModel.fireTableDataChanged();
    initializeIncludedList();
    // to fire reminder to save work
    SignalGroupDirty = true;
    updateButton.setVisible(true);
    fixedSystemName.setVisible(true);
    _systemName.setVisible(false);
    addFrame.setTitle(Bundle.getMessage("EditSignalGroup"));
    // to block opening another edit session
    inEditMode = true;
}
Also used : SignalGroup(jmri.SignalGroup) SignalHead(jmri.SignalHead) SignalMast(jmri.SignalMast)

Example 17 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SignalHeadTableAction method handleMergSignalDriverOkPressed.

@SuppressWarnings("fallthrough")
@SuppressFBWarnings(value = "SF_SWITCH_FALLTHROUGH")
void handleMergSignalDriverOkPressed() {
    SignalHead s;
    // Adding Merg Signal Driver.
    Turnout t3 = null;
    Turnout t2 = null;
    Turnout t1 = null;
    NamedBeanHandle<Turnout> nbt1 = null;
    NamedBeanHandle<Turnout> nbt2 = null;
    NamedBeanHandle<Turnout> nbt3 = null;
    if (checkBeforeCreating(systemName.getText())) {
        switch(ukSignalAspectsFromBox(msaBox)) {
            case 4:
                t3 = getTurnoutFromPanel(to5, (Bundle.getMessage("OutputComment", Bundle.getMessage("BeanNameSignalHead"), systemName.getText(), Bundle.getMessage("InputNum", "3"))));
                if (t3 == null) {
                    addTurnoutMessage(v5Border.getTitle(), to5.getDisplayName());
                    log.warn("skipping creation of signal " + systemName.getText() + " due to error");
                    return;
                } else {
                    nbt3 = nbhm.getNamedBeanHandle(to5.getDisplayName(), t3);
                }
            // fall through
            case 3:
                t2 = getTurnoutFromPanel(to4, (Bundle.getMessage("OutputComment", Bundle.getMessage("BeanNameSignalHead"), systemName.getText(), Bundle.getMessage("InputNum", "2"))));
                if (t2 == null) {
                    addTurnoutMessage(v4Border.getTitle(), to4.getDisplayName());
                    log.warn("skipping creation of signal " + systemName.getText() + " due to error");
                    return;
                } else {
                    nbt2 = nbhm.getNamedBeanHandle(to4.getDisplayName(), t2);
                }
            // fall through
            case 2:
                t1 = getTurnoutFromPanel(to3, (Bundle.getMessage("OutputComment", Bundle.getMessage("BeanNameSignalHead"), systemName.getText(), Bundle.getMessage("InputNum", "1"))));
                if (t1 == null) {
                    addTurnoutMessage(v3Border.getTitle(), to3.getDisplayName());
                    log.warn("skipping creation of signal " + systemName.getText() + " due to error");
                    return;
                } else {
                    nbt1 = nbhm.getNamedBeanHandle(to3.getDisplayName(), t1);
                }
            default:
                break;
        }
        boolean home;
        if (ukSignalTypeFromBox(mstBox).equals("Distant")) {
            home = false;
        } else {
            home = true;
        }
        s = new jmri.implementation.MergSD2SignalHead(systemName.getText(), ukSignalAspectsFromBox(msaBox), nbt1, nbt2, nbt3, false, home);
        s.setUserName(userName.getText());
        InstanceManager.getDefault(jmri.SignalHeadManager.class).register(s);
    }
}
Also used : QuadOutputSignalHead(jmri.implementation.QuadOutputSignalHead) DccSignalHead(jmri.implementation.DccSignalHead) DoubleTurnoutSignalHead(jmri.implementation.DoubleTurnoutSignalHead) TripleTurnoutSignalHead(jmri.implementation.TripleTurnoutSignalHead) SignalHead(jmri.SignalHead) SingleTurnoutSignalHead(jmri.implementation.SingleTurnoutSignalHead) TripleOutputSignalHead(jmri.implementation.TripleOutputSignalHead) Turnout(jmri.Turnout) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 18 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SignalGroupTableAction method setHeadInformation.

/**
     * Check all available Single Output Signal Heads against the list of signal head items registered with the group.
     * Updates the list, which is stored in the field _includedSignalHeadsList.
     * @param g Signal Group object
     * @return The number of Signal Heads included in the group
     */
int setHeadInformation(SignalGroup g) {
    for (int i = 0; i < g.getNumHeadItems(); i++) {
        SignalHead sig = g.getHeadItemBeanByIndex(i);
        boolean valid = false;
        for (int x = 0; x < _includedSignalHeadsList.size(); x++) {
            SignalGroupSignalHead sh = _includedSignalHeadsList.get(x);
            if (sig == sh.getBean()) {
                valid = true;
                break;
            }
        }
        if (!valid) {
            g.deleteSignalHead(sig);
        }
    }
    for (int i = 0; i < _includedSignalHeadsList.size(); i++) {
        SignalGroupSignalHead s = _includedSignalHeadsList.get(i);
        SignalHead sig = s.getBean();
        if (!g.isHeadIncluded(sig)) {
            g.addSignalHead(sig);
            g.setHeadOnState(sig, s.getOnStateInt());
            g.setHeadOffState(sig, s.getOffStateInt());
        }
    }
    return _includedSignalHeadsList.size();
}
Also used : SignalHead(jmri.SignalHead)

Example 19 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SignalGroupTableAction method propertyChange.

@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
    if (e.getPropertyName().equals("UpdateCondition")) {
        for (int i = _signalHeadsList.size() - 1; i >= 0; i--) {
            SignalGroupSignalHead signalHead = _signalHeadsList.get(i);
            SignalHead sigBean = signalHead.getBean();
            if (curSignalGroup.isHeadIncluded(sigBean)) {
                signalHead.setIncluded(true);
                signalHead.setOnState(curSignalGroup.getHeadOnState(sigBean));
                signalHead.setOffState(curSignalGroup.getHeadOffState(sigBean));
            } else {
                signalHead.setIncluded(false);
            }
        }
    }
}
Also used : SignalHead(jmri.SignalHead)

Example 20 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class IconAdder method makeIconMap.

void makeIconMap(NamedBean bean) {
    if (bean != null && _type != null && _type.equals("SignalHead")) {
        _order = new ArrayList<>();
        _iconMap = new HashMap<>(12);
        int k = 0;
        ArrayList<CatalogTreeLeaf> list = _defaultIcons.getLeaves();
        String[] states = ((SignalHead) bean).getValidStateNames();
        for (int i = 0; i < list.size(); i++) {
            CatalogTreeLeaf leaf = list.get(i);
            String name = leaf.getName();
            try {
                name = Bundle.getMessage(leaf.getName());
            } catch (java.util.MissingResourceException mre) {
            }
            if (log.isDebugEnabled()) {
                log.debug("makeIconMap: leafName= " + leaf.getName() + ", name= " + name);
            }
            for (String state : states) {
                if (name.equals(state) || leaf.getName().equals(Bundle.getMessage("SignalHeadStateDark")) || leaf.getName().equals(Bundle.getMessage("SignalHeadStateHeld"))) {
                    String path = leaf.getPath();
                    this.setIcon(k++, leaf.getName(), new NamedIcon(path, path));
                    break;
                }
            }
        }
    } else {
        makeIcons(_defaultIcons);
    }
    if (log.isDebugEnabled()) {
        log.debug("makeIconMap: _iconMap.size()= " + _iconMap.size());
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) 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