use of jmri.Reporter in project JMRI by JMRI.
the class Location method setReporter.
/*
* set the jmri.Reporter object associated with this location.
*
* @param reader jmri.Reporter object.
*/
protected void setReporter(Reporter r) {
Reporter old = _reader;
_reader = r;
if (old != r) {
setDirtyAndFirePropertyChange("reporterChange", old, r);
}
}
use of jmri.Reporter in project JMRI by JMRI.
the class EcosReporterManager method createNewReporter.
@Override
public Reporter createNewReporter(String systemName, String userName) {
Reporter r = new EcosReporter(systemName, userName);
register(r);
return r;
}
use of jmri.Reporter in project JMRI by JMRI.
the class AbstractReporterManager method getNextValidAddress.
@Override
public String getNextValidAddress(String curAddress, String prefix) {
//If the hardware address past does not already exist then this can
//be considered the next valid address.
Reporter r = getBySystemName(prefix + typeLetter() + curAddress);
if (r == null) {
return curAddress;
}
// This bit deals with handling the curAddress, and how to get the next address.
int iName = 0;
try {
iName = Integer.parseInt(curAddress);
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " Hardware Address to a number");
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
return null;
}
//Check to determine if the systemName is in use, return null if it is,
//otherwise return the next valid address.
r = getBySystemName(prefix + typeLetter() + iName);
if (r != null) {
for (int x = 1; x < 10; x++) {
iName++;
r = getBySystemName(prefix + typeLetter() + iName);
if (r == null) {
return Integer.toString(iName);
}
}
return null;
} else {
return Integer.toString(iName);
}
}
use of jmri.Reporter in project JMRI by JMRI.
the class DefaultRailComTest method testHasBeenSeen.
@Test
public void testHasBeenSeen() throws InterruptedException {
RailCom r = new DefaultRailCom("ID0413276BC1");
Reporter rep = new AbstractReporter("IR1") {
@Override
public int getState() {
return state;
}
@Override
public void setState(int s) {
state = s;
}
int state = 0;
};
Date timeBefore = Calendar.getInstance().getTime();
Thread.sleep(5);
r.setWhereLastSeen(rep);
Thread.sleep(5);
Date timeAfter = Calendar.getInstance().getTime();
Assert.assertEquals("Where last seen is 'IR1'", rep, r.getWhereLastSeen());
Assert.assertNotNull("When last seen is not null", r.getWhenLastSeen());
Assert.assertEquals("Status is SEEN", RailCom.SEEN, r.getState());
Assert.assertTrue("Time when last seen is later than 'timeBefore'", r.getWhenLastSeen().after(timeBefore));
Assert.assertTrue("Time when last seen is earlier than 'timeAfter'", r.getWhenLastSeen().before(timeAfter));
r.setWhereLastSeen(null);
Assert.assertNull("After setWhereLastSeen(null), Reporter where seen is null", r.getWhereLastSeen());
Assert.assertNull("After setWhereLastSeen(null), Date when seen is null", r.getWhenLastSeen());
Assert.assertEquals("After setWhereLastSeen(null), RailCom status is UNSEEN", RailCom.UNSEEN, r.getState());
}
use of jmri.Reporter in project JMRI by JMRI.
the class IconEditorWindowTest method testReporterEditor.
public void testReporterEditor() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
Editor.JFrameItem iconEditorFrame = _editor.getIconFrame("Reporter");
IconAdder iconEditor = iconEditorFrame.getEditor();
Assert.assertNotNull(iconEditor);
iconEditor._sysNametext.setText("IR0");
iconEditor.addToTable();
ReporterIcon icon = _editor.addReporter();
Assert.assertNotNull(icon);
Reporter reporter = icon.getReporter();
Assert.assertNotNull(reporter);
int x = 30;
int y = 10;
icon.setLocation(x, y);
_panel.repaint();
java.awt.Point location = new java.awt.Point(x + icon.getSize().width / 2, y + icon.getSize().height / 2);
getHelper().enterClickAndLeave(new MouseEventData(this, // component
_panel, // number clicks
1, // modifiers
EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
false, // sleeptime
10, // position
EventDataConstants.CUSTOM, location));
TestHelper.disposeWindow(iconEditorFrame, this);
}
Aggregations