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"));
}
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);
}
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());
}
}
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);
}
}
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();
}
Aggregations