Search in sources :

Example 86 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class CatalogTreeIndexTest method testGetParameter.

public void testGetParameter() {
    NamedBean n = new CatalogTreeIndex("sys", "usr") {

        @Override
        public int getState() {
            return 0;
        }

        @Override
        public void setState(int i) {
        }
    };
    n.setProperty("foo", "bar");
    Assert.assertEquals("bar", n.getProperty("foo"));
}
Also used : NamedBean(jmri.NamedBean)

Example 87 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class EntryExitPairs method automaticallyDiscoverEntryExitPairs.

/**
     * Discover all possible valid source and destination Signal Mast Logic pairs
     * on all Layout Editor panels.
     *
     * @param editor The Layout Editor panel
     * @param interlockType Integer value representing the type of interlocking, one of
     *                      SETUPTURNOUTSONLY, SETUPSIGNALMASTLOGIC or FULLINTERLOCK
     * @throws JmriException when an error occurs during discovery
     */
public void automaticallyDiscoverEntryExitPairs(LayoutEditor editor, int interlockType) throws JmriException {
    //This is almost a duplicate of that in the DefaultSignalMastLogicManager
    runWhenStabilised = false;
    jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class);
    if (!lbm.isAdvancedRoutingEnabled()) {
        throw new JmriException("advanced routing not enabled");
    }
    if (!lbm.routingStablised()) {
        runWhenStabilised = true;
        toUseWhenStable = editor;
        interlockTypeToUseWhenStable = interlockType;
        log.debug("Layout block routing has not yet stabilised, discovery will happen once it has");
        return;
    }
    Hashtable<NamedBean, ArrayList<NamedBean>> validPaths = lbm.getLayoutBlockConnectivityTools().discoverValidBeanPairs(editor, Sensor.class, LayoutBlockConnectivityTools.SENSORTOSENSOR);
    Enumeration<NamedBean> en = validPaths.keys();
    EntryExitPairs eep = this;
    while (en.hasMoreElements()) {
        NamedBean key = en.nextElement();
        ArrayList<NamedBean> validDestMast = validPaths.get(key);
        if (validDestMast.size() > 0) {
            eep.addNXSourcePoint(key, editor);
            for (int i = 0; i < validDestMast.size(); i++) {
                if (!eep.isDestinationValid(key, validDestMast.get(i), editor)) {
                    eep.addNXDestination(key, validDestMast.get(i), editor);
                    eep.setEntryExitType(key, editor, validDestMast.get(i), interlockType);
                }
            }
        }
    }
    firePropertyChange("autoGenerateComplete", null, null);
}
Also used : NamedBean(jmri.NamedBean) ArrayList(java.util.ArrayList) JmriException(jmri.JmriException)

Example 88 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class VSDecoderManager method registerBeanListener.

protected void registerBeanListener(Manager beanManager, String sysName) {
    NamedBean b = beanManager.getBeanBySystemName(sysName);
    if (b == null) {
        log.debug("No bean by name " + sysName);
        return;
    }
    jmri.NamedBeanHandle<NamedBean> h = nbhm.getNamedBeanHandle(sysName, b);
    if (h == null) {
        log.debug("no handle for bean " + b.getDisplayName());
        return;
    }
    // Make sure we aren't already registered.
    java.beans.PropertyChangeListener[] ll = b.getPropertyChangeListenersByReference(h.getName());
    if (ll.length == 0) {
        b.addPropertyChangeListener(this, h.getName(), vsd_property_change_name);
        log.debug("Added listener to bean " + b.getDisplayName() + " type " + b.getClass().getName());
    }
}
Also used : NamedBean(jmri.NamedBean) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 89 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class AbstractManager method propertyChange.

/**
     * The PropertyChangeListener interface in this class is intended to keep
     * track of user name changes to individual NamedBeans. It is not completely
     * implemented yet. In particular, listeners are not added to newly
     * registered objects.
     *
     * @param e the event
     */
@Override
@OverridingMethodsMustInvokeSuper
public void propertyChange(PropertyChangeEvent e) {
    if (e.getPropertyName().equals("UserName")) {
        // previous user name
        String old = (String) e.getOldValue();
        // current user name
        String now = (String) e.getNewValue();
        NamedBean t = (NamedBean) e.getSource();
        if (old != null) {
            // remove old name for this bean
            _tuser.remove(old);
        }
        if (now != null) {
            // was there previously a bean with the new name?
            if (_tuser.get(now) != null && _tuser.get(now) != t) {
                // If so, clear. Note that this is not a "move" operation
                _tuser.get(now).setUserName(null);
            }
            // put new name for this bean
            _tuser.put(now, t);
        }
        //called DisplayListName, as DisplayName might get used at some point by a NamedBean
        //IN18N
        firePropertyChange("DisplayListName", old, now);
    }
}
Also used : NamedBean(jmri.NamedBean) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper)

Example 90 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class MultiSensorIcon method updateItem.

void updateItem() {
    HashMap<String, NamedIcon> iconMap = _itemPanel.getIconMap();
    ArrayList<NamedBean> selections = _itemPanel.getTableSelections();
    int[] positions = _itemPanel.getPositions();
    if (selections == null || selections.size() < positions.length) {
        JOptionPane.showMessageDialog(_paletteFrame, Bundle.getMessage("NeedPosition", positions.length), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    if (iconMap != null) {
        setInactiveIcon(new NamedIcon(iconMap.get("SensorStateInactive")));
        setInconsistentIcon(new NamedIcon(iconMap.get("BeanStateInconsistent")));
        setUnknownIcon(new NamedIcon(iconMap.get("BeanStateUnknown")));
    } else {
        return;
    }
    entries = new ArrayList<>(selections.size());
    for (int i = 0; i < selections.size(); i++) {
        addEntry(selections.get(i).getDisplayName(), new NamedIcon(iconMap.get(MultiSensorItemPanel.getPositionName(i))));
    }
    _iconFamily = _itemPanel.getFamilyName();
    _itemPanel.clearSelections();
    setUpDown(_itemPanel.getUpDown());
    //        jmri.jmrit.catalog.ImageIndexEditor.checkImageIndex();
    _paletteFrame.dispose();
    _paletteFrame = null;
    _itemPanel.dispose();
    _itemPanel = null;
    invalidate();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) 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