Search in sources :

Example 21 with Reporter

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);
    }
}
Also used : Reporter(jmri.Reporter)

Example 22 with Reporter

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);
    }
}
Also used : Reporter(jmri.Reporter)

Example 23 with Reporter

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());
}
Also used : RailCom(jmri.RailCom) Reporter(jmri.Reporter) Date(java.util.Date) Test(org.junit.Test)

Example 24 with Reporter

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);
}
Also used : Reporter(jmri.Reporter) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor)

Example 25 with Reporter

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;
}
Also used : Reporter(jmri.Reporter)

Aggregations

Reporter (jmri.Reporter)55 Test (org.junit.Test)18 ReporterManager (jmri.ReporterManager)10 Block (jmri.Block)6 Element (org.jdom2.Element)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IOException (java.io.IOException)4 BlockManager (jmri.BlockManager)4 JsonException (jmri.server.json.JsonException)4 Date (java.util.Date)3 JmriException (jmri.JmriException)3 Sensor (jmri.Sensor)3 OBlock (jmri.jmrit.logix.OBlock)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ParseException (java.text.ParseException)2 PhysicalLocationReporter (jmri.PhysicalLocationReporter)2 Location (jmri.jmrit.operations.locations.Location)2 JsonMockConnection (jmri.server.json.JsonMockConnection)2 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)1