Search in sources :

Example 41 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class AbstractProxyManager method provideNamedBean.

/**
     * Locate via user name, then system name if needed. If that fails, create a
     * new NamedBean: If the name is a valid system name, it will be used for
     * the new NamedBean. Otherwise, the makeSystemName method will attempt to
     * turn it into a valid system name. Subclasses use this to create provider methods such as 
     * getSensor or getTurnout via casts.
     *
     * @param name the user name or system name of the bean
     * @return an existing or new NamedBean
     */
protected NamedBean provideNamedBean(String name) throws IllegalArgumentException {
    // make sure internal present
    initInternal();
    NamedBean t = getNamedBean(name);
    if (t != null) {
        return t;
    }
    // Doesn't exist. If the systemName was specified, find that system
    int index = matchTentative(name);
    if (index >= 0) {
        return makeBean(index, name, null);
    }
    log.debug("provideNamedBean did not find manager for name " + name + ", defer to default");
    return makeBean(0, getMgr(0).makeSystemName(name), null);
}
Also used : NamedBean(jmri.NamedBean)

Example 42 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class DefaultIdTagManager method getTagsForReporter.

@Override
public List<IdTag> getTagsForReporter(Reporter reporter, long threshold) {
    List<IdTag> out = new ArrayList<>();
    Date lastWhenLastSeen = new Date(0);
    // and record the time most recently seen
    for (NamedBean n : _tsys.values()) {
        IdTag t = (IdTag) n;
        if (t.getWhereLastSeen() == reporter) {
            out.add(t);
            if (t.getWhenLastSeen().after(lastWhenLastSeen)) {
                lastWhenLastSeen = t.getWhenLastSeen();
            }
        }
    }
    if (out.size() > 0) {
        // Calculate the threshold time based on the most recently seen tag
        Date thresholdTime = new Date(lastWhenLastSeen.getTime() - threshold);
        // Now remove from the list all tags seen prior to the threshold time
        for (IdTag t : out) {
            if (t.getWhenLastSeen().before(thresholdTime)) {
                out.remove(t);
            }
        }
    }
    return out;
}
Also used : NamedBean(jmri.NamedBean) ArrayList(java.util.ArrayList) DefaultIdTag(jmri.implementation.DefaultIdTag) IdTag(jmri.IdTag) Date(java.util.Date)

Example 43 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class NamedBeanTest method testGetBeanParameter.

public void testGetBeanParameter() {
    NamedBean n = createInstance();
    n.setProperty("foo", "bar");
    Assert.assertEquals("bar", n.getProperty("foo"));
}
Also used : NamedBean(jmri.NamedBean)

Example 44 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class NamedBeanTest method testGetSetNullBeanParameter.

public void testGetSetNullBeanParameter() {
    NamedBean n = createInstance();
    n.setProperty("foo", "bar");
    Assert.assertEquals("bar", n.getProperty("foo"));
    n.setProperty("foo", null);
    Assert.assertEquals(null, n.getProperty("foo"));
}
Also used : NamedBean(jmri.NamedBean)

Example 45 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class NamedBeanTest method testDispose.

public void testDispose() {
    NamedBean n = createInstance();
    n.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent p) {
        }
    });
    n.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent p) {
        }
    });
    Assert.assertEquals("start length", 2, n.getNumPropertyChangeListeners());
    n.dispose();
    Assert.assertEquals("end length", 0, n.getNumPropertyChangeListeners());
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) NamedBean(jmri.NamedBean) PropertyChangeListener(java.beans.PropertyChangeListener)

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