Search in sources :

Example 31 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class AddSignalMastPanel method checkSignalHeadUse.

boolean checkSignalHeadUse() {
    for (int i = 0; i < headList.size(); i++) {
        JmriBeanComboBox head = headList.get(i);
        NamedBean h = headList.get(i).getSelectedBean();
        for (int j = i; j < headList.size(); j++) {
            JmriBeanComboBox head2check = headList.get(j);
            if ((head2check != head) && (head2check.getSelectedBean() == h)) {
                if (!duplicateHeadAssigned(headList.get(i).getSelectedDisplayName())) {
                    return false;
                }
            }
        }
        if (includeUsed.isSelected()) {
            String isUsed = SignalHeadSignalMast.isHeadUsed((SignalHead) h);
            if ((isUsed != null) && (!headAssignedElseWhere(h.getDisplayName(), isUsed))) {
                return false;
            }
        }
    }
    return true;
}
Also used : JmriBeanComboBox(jmri.util.swing.JmriBeanComboBox) NamedBean(jmri.NamedBean)

Example 32 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class Editor method vetoableChange.

@Override
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException {
    NamedBean nb = (NamedBean) evt.getOldValue();
    if ("CanDelete".equals(evt.getPropertyName())) {
        //IN18N
        StringBuilder message = new StringBuilder();
        //IN18N
        message.append(Bundle.getMessage("VetoInUseEditorHeader", getName()));
        message.append("<br>");
        boolean found = false;
        int count = 0;
        for (Positionable p : _contents) {
            if (nb.equals(p.getNamedBean())) {
                found = true;
                count++;
            }
        }
        if (found) {
            message.append(Bundle.getMessage("VetoFoundInPanel", count));
            message.append("<br>");
            //IN18N
            message.append(Bundle.getMessage("VetoReferencesWillBeRemoved"));
            message.append("<br>");
            throw new java.beans.PropertyVetoException(message.toString(), evt);
        }
    } else if ("DoDelete".equals(evt.getPropertyName())) {
        //IN18N
        ArrayList<Positionable> toDelete = new ArrayList<Positionable>();
        for (Positionable p : _contents) {
            if (nb.equals(p.getNamedBean())) {
                toDelete.add(p);
            }
        }
        for (Positionable p : toDelete) {
            removeFromContents(p);
            _targetPanel.repaint();
        }
    }
}
Also used : NamedBean(jmri.NamedBean) ArrayList(java.util.ArrayList) Point(java.awt.Point)

Example 33 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class TransitCreationTool method createTransit.

public Transit createTransit() throws JmriException {
    TransitManager tm = InstanceManager.getDefault(jmri.TransitManager.class);
    String transitName = "From " + list.get(0).getDisplayName() + " to " + list.get(list.size() - 1).getDisplayName();
    Transit t = tm.createNewTransit(transitName);
    if (t == null) {
        log.error("Unable to create transit " + transitName);
        throw new JmriException(Bundle.getMessage("TCTErrorUnableToCreate", transitName));
    }
    if (list.get(0) instanceof SignalMast) {
        jmri.SignalMastLogicManager smlm = InstanceManager.getDefault(jmri.SignalMastLogicManager.class);
        for (int i = 1; i <= list.size() - 1; i++) {
            jmri.SignalMastLogic sml = smlm.getSignalMastLogic((SignalMast) list.get(i - 1));
            Section sec = sml.getAssociatedSection((SignalMast) list.get(i));
            //In theory sec being null would already have been tested when the signal was added.
            if (sec == null) {
                String error = Bundle.getMessage("TCTErrorMastPairsNoSection", list.get(i - 1).getDisplayName(), list.get(i).getDisplayName());
                log.error(error);
                tm.deregister(t);
                t.dispose();
                cancelTransitCreate();
                throw new JmriException(error);
            }
            t.addTransitSection(new jmri.TransitSection(sec, i, Section.FORWARD));
        }
    }
    //Once created clear the list for a fresh start.
    list = new ArrayList<NamedBean>();
    return t;
}
Also used : NamedBean(jmri.NamedBean) JmriException(jmri.JmriException) Transit(jmri.Transit) Section(jmri.Section) TransitManager(jmri.TransitManager) SignalMast(jmri.SignalMast)

Example 34 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class SignalMastItemPanel method getIconMap.

private void getIconMap(int row) {
    if (row < 0) {
        _currentIconMap = null;
        _family = null;
        return;
    }
    NamedBean bean = _model.getBeanAt(row);
    if (bean == null) {
        if (log.isDebugEnabled()) {
            log.debug("getIconMap: NamedBean is null at row " + row);
        }
        _currentIconMap = null;
        _family = null;
        return;
    }
    try {
        _mast = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(bean.getDisplayName());
    } catch (IllegalArgumentException ex) {
        log.error("getIconMap: No SignalMast called " + bean.getDisplayName());
        _currentIconMap = null;
        return;
    }
    _family = _mast.getSignalSystem().getSystemName();
    _currentIconMap = new HashMap<String, NamedIcon>();
    SignalAppearanceMap appMap = _mast.getAppearanceMap();
    Enumeration<String> e = _mast.getAppearanceMap().getAspects();
    while (e.hasMoreElements()) {
        String aspect = e.nextElement();
        String s = appMap.getImageLink(aspect, _family);
        if (s != null && !s.equals("")) {
            if (!s.contains("preference:")) {
                s = s.substring(s.indexOf("resources"));
            }
            NamedIcon n = new NamedIcon(s, s);
            _currentIconMap.put(aspect, n);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("getIconMap: for " + _family + " size= " + _currentIconMap.size());
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) NamedBean(jmri.NamedBean) SignalAppearanceMap(jmri.SignalAppearanceMap)

Example 35 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class Warrant method setStoppingSignal.

private void setStoppingSignal(int idx) {
    BlockOrder blkOrder = getBlockOrderAt(idx);
    NamedBean signal = blkOrder.getSignal();
    if (_protectSignal != null) {
        if (_protectSignal.equals(signal)) {
            // Must be the route coming back to the same block
            if (_idxProtectSignal < idx && idx >= 0) {
                _idxProtectSignal = idx;
            }
            return;
        } else {
            if (_idxProtectSignal <= _idxCurrentOrder && !_waitForSignal) {
                _protectSignal.removePropertyChangeListener(this);
            } else {
                return;
            }
        }
    }
    NamedBean prevSignal = _protectSignal;
    if (signal != null) {
        _protectSignal = signal;
        _idxProtectSignal = idx;
        _protectSignal.addPropertyChangeListener(this);
    }
    if (log.isDebugEnabled()) {
        String msg = "Signal at block \"{}\" Warrant \"{}\"";
        if (_protectSignal != null) {
            msg = msg + " sets _protectSignal= \"{}\"";
        }
        if (prevSignal != null) {
            msg = msg + ", removes signal= \"{}\"";
        }
        log.debug(msg, blkOrder.getBlock().getDisplayName(), getDisplayName(), (signal == null ? "" : _protectSignal.getDisplayName()), (prevSignal == null ? "" : prevSignal.getDisplayName()));
    }
}
Also used : NamedBean(jmri.NamedBean)

Aggregations

NamedBean (jmri.NamedBean)104 ArrayList (java.util.ArrayList)18 JTextField (javax.swing.JTextField)12 JmriException (jmri.JmriException)12 SignalMast (jmri.SignalMast)12 JTable (javax.swing.JTable)11 Manager (jmri.Manager)9 Sensor (jmri.Sensor)9 JButton (javax.swing.JButton)8 InstanceManager (jmri.InstanceManager)8 JComboBox (javax.swing.JComboBox)7 MouseEvent (java.awt.event.MouseEvent)6 Hashtable (java.util.Hashtable)6 SignalHead (jmri.SignalHead)6 Turnout (jmri.Turnout)6 OBlock (jmri.jmrit.logix.OBlock)5 File (java.io.File)4 JLabel (javax.swing.JLabel)4 TableCellEditor (javax.swing.table.TableCellEditor)4 TableCellRenderer (javax.swing.table.TableCellRenderer)4