Search in sources :

Example 71 with Block

use of jmri.Block in project JMRI by JMRI.

the class OPathTest method testSetBlockToNull.

@Test
public void testSetBlockToNull() {
    Block b1 = new Block("IB1");
    OPath op = new OPath(b1, "name");
    op.setBlock(null);
    Assert.assertEquals("block", null, op.getBlock());
}
Also used : Block(jmri.Block) Test(org.junit.Test)

Example 72 with Block

use of jmri.Block in project JMRI by JMRI.

the class OPathTest method testSetBlockNonNull.

@Test
public void testSetBlockNonNull() {
    Block b1 = new Block("IB1");
    Block b2 = new Block("IB2");
    OPath op = new OPath(b1, "name");
    op.setBlock(b2);
    Assert.assertEquals("block", b2, op.getBlock());
}
Also used : Block(jmri.Block) Test(org.junit.Test)

Example 73 with Block

use of jmri.Block in project JMRI by JMRI.

the class OPathTest method testCtor.

@Test
public void testCtor() {
    Block b = new Block("IB1");
    OPath op = new OPath(b, "name");
    Assert.assertEquals("name", "name", op.getName());
    Assert.assertEquals("block", b, op.getBlock());
}
Also used : Block(jmri.Block) Test(org.junit.Test)

Example 74 with Block

use of jmri.Block in project JMRI by JMRI.

the class JsonBlockHttpService method doGet.

@Override
public JsonNode doGet(String type, String name, Locale locale) throws JsonException {
    ObjectNode root = mapper.createObjectNode();
    root.put(TYPE, BLOCK);
    ObjectNode data = root.putObject(DATA);
    Block block = InstanceManager.getDefault(BlockManager.class).getBlock(name);
    if (block == null) {
        throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", BLOCK, name));
    }
    data.put(NAME, block.getSystemName());
    data.put(USERNAME, block.getUserName());
    data.put(COMMENT, block.getComment());
    if (block.getValue() == null) {
        data.putNull(VALUE);
    } else {
        data.put(VALUE, block.getValue().toString());
    }
    return root;
}
Also used : JsonException(jmri.server.json.JsonException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BlockManager(jmri.BlockManager) Block(jmri.Block)

Example 75 with Block

use of jmri.Block in project JMRI by JMRI.

the class JsonBlockSocketService method onMessage.

@Override
public void onMessage(String type, JsonNode data, Locale locale) throws IOException, JmriException, JsonException {
    this.locale = locale;
    String name = data.path(NAME).asText();
    if (data.path(METHOD).asText().equals(PUT)) {
        this.connection.sendMessage(this.service.doPut(type, name, data, locale));
    } else {
        this.connection.sendMessage(this.service.doPost(type, name, data, locale));
    }
    if (!this.blocks.containsKey(name)) {
        Block block = InstanceManager.getDefault(BlockManager.class).getBlock(name);
        if (block != null) {
            BlockListener listener = new BlockListener(block);
            block.addPropertyChangeListener(listener);
            this.blocks.put(name, listener);
        }
    }
}
Also used : BlockManager(jmri.BlockManager) Block(jmri.Block)

Aggregations

Block (jmri.Block)84 ArrayList (java.util.ArrayList)19 EntryPoint (jmri.EntryPoint)16 Sensor (jmri.Sensor)10 Element (org.jdom2.Element)9 BlockManager (jmri.BlockManager)8 SignalMast (jmri.SignalMast)8 Turnout (jmri.Turnout)8 Test (org.junit.Test)7 Path (jmri.Path)6 Reporter (jmri.Reporter)6 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 Section (jmri.Section)5 Hashtable (java.util.Hashtable)4 NamedBean (jmri.NamedBean)4 SignalHead (jmri.SignalHead)4 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3