Search in sources :

Example 11 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class JsonUtil method getPanel.

public static ObjectNode getPanel(Locale locale, Editor editor, String format) {
    if (editor.getAllowInFrameServlet()) {
        String title = ((JmriJFrame) editor.getTargetPanel().getTopLevelAncestor()).getTitle();
        if (!title.isEmpty() && !Arrays.asList(WebServerPreferences.getDefault().getDisallowedFrames()).contains(title)) {
            String type = PANEL;
            String name = "Panel";
            if (editor instanceof ControlPanelEditor) {
                type = CONTROL_PANEL;
                name = "ControlPanel";
            } else if (editor instanceof LayoutEditor) {
                type = LAYOUT_PANEL;
                name = "Layout";
            }
            ObjectNode root = mapper.createObjectNode();
            root.put(TYPE, PANEL);
            ObjectNode data = root.putObject(DATA);
            // NOI18N
            data.put(NAME, name + "/" + title.replaceAll(" ", "%20").replaceAll("#", "%23"));
            // NOI18N
            data.put(URL, "/panel/" + data.path(NAME).asText() + "?format=" + format);
            data.put(USERNAME, title);
            data.put(TYPE, type);
            return root;
        }
    }
    return null;
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JmriJFrame(jmri.util.JmriJFrame) TrainCommon.splitString(jmri.jmrit.operations.trains.TrainCommon.splitString)

Example 12 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class NXFrameTest method testNXWarrant.

// For types from DialogFinder().findAll(..)
@SuppressWarnings("unchecked")
public void testNXWarrant() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    // load and display
    File f = new File("java/test/jmri/jmrit/logix/valid/NXWarrantTest.xml");
    InstanceManager.getDefault(ConfigureManager.class).load(f);
    _OBlockMgr = InstanceManager.getDefault(OBlockManager.class);
    _sensorMgr = InstanceManager.getDefault(SensorManager.class);
    OBlock block = _OBlockMgr.getBySystemName("OB0");
    NXFrame nxFrame = NXFrame.getDefault();
    nxFrame.init();
    nxFrame.setVisible(true);
    nxFrame.setThrottleIncrement(0.075f);
    nxFrame.setTimeInterval(1000);
    nxFrame.setThrottleFactor(0.75f);
    flushAWT();
    pressButton(nxFrame, Bundle.getMessage("ButtonCancel"));
    // wait to calm down after cancel
    flushAWT();
    flushAWT();
    // after cancel, try again
    nxFrame = NXFrame.getDefault();
    nxFrame.init();
    nxFrame.setVisible(true);
    nxFrame._maxSpeedBox.setText("0.30");
    nxFrame._origin.blockBox.setText("OB0");
    nxFrame._destination.blockBox.setText("OB10");
    pressButton(nxFrame, Bundle.getMessage("ButtonRunNX"));
    confirmJOptionPane(null, Bundle.getMessage("WarningTitle"), Bundle.getMessage("NoLoco"), "OK");
    nxFrame.setAddress("666");
    nxFrame.setTrainName("Nick");
    flushAWT();
    pressButton(nxFrame, Bundle.getMessage("ButtonRunNX"));
    DialogFinder finder = new DialogFinder(Bundle.getMessage("DialogTitle"));
    java.awt.Container pickDia = (java.awt.Container) finder.find();
    Assert.assertNotNull("PickRoute Dialog not found", pickDia);
    pressButton(pickDia, Bundle.getMessage("ButtonReview"));
    confirmJOptionPane(null, Bundle.getMessage("WarningTitle"), Bundle.getMessage("SelectRoute"), "OK");
    List<JRadioButton> list = getRadioButtons(pickDia);
    Assert.assertNotNull("Route RadioButtons not found", list);
    Assert.assertEquals("Number of RadioButton Routes", 4, list.size());
    getHelper().enterClickAndLeave(new MouseEventData(this, list.get(3)));
    pressButton(pickDia, Bundle.getMessage("ButtonReview"));
    getHelper().enterClickAndLeave(new MouseEventData(this, list.get(1)));
    pressButton(pickDia, Bundle.getMessage("ButtonReview"));
    nxFrame.setThrottleIncrement(0.05f);
    pressButton(pickDia, Bundle.getMessage("ButtonSelect"));
    //pause for NXFrame to make commands
    flushAWT();
    WarrantTableFrame tableFrame = WarrantTableFrame.getDefault();
    Assert.assertNotNull("tableFrame", tableFrame);
    WarrantTableModel model = tableFrame.getModel();
    Assert.assertNotNull("tableFrame model", model);
    JUnitUtil.waitFor(() -> {
        return model.getRowCount() > 0;
    }, "NXWarrant loaded into table");
    Warrant warrant = tableFrame.getModel().getWarrantAt(0);
    Assert.assertNotNull("warrant", warrant);
    Assert.assertNotNull("warrant.getBlockOrders(", warrant.getBlockOrders());
    List<BlockOrder> orders = warrant.getBlockOrders();
    if (orders.size() != 7) {
        System.out.println();
        System.out.println(warrant.getSystemName() + " " + warrant.getUserName());
        for (BlockOrder bo : orders) {
            System.out.println(bo.toString());
        }
        List<ThrottleSetting> commands = warrant.getThrottleCommands();
        for (ThrottleSetting ts : commands) {
            System.out.println(ts.toString());
        }
    }
    Assert.assertEquals("Num Blocks in Route", 7, warrant.getBlockOrders().size());
    Assert.assertTrue("Num Comands", warrant.getThrottleCommands().size() > 5);
    String name = block.getDisplayName();
    jmri.util.JUnitUtil.waitFor(() -> {
        return warrant.getRunningMessage().equals(Bundle.getMessage("waitForDelayStart", warrant.getTrainName(), name));
    }, "Waiting message");
    Sensor sensor0 = _sensorMgr.getBySystemName("IS0");
    Assert.assertNotNull("Senor IS0 not found", sensor0);
    jmri.util.ThreadingUtil.runOnLayout(() -> {
        try {
            sensor0.setState(Sensor.ACTIVE);
        } catch (jmri.JmriException e) {
            Assert.fail("Unexpected Exception: " + e);
        }
    });
    jmri.util.JUnitUtil.releaseThread(this);
    Assert.assertEquals("Start Block Active", (OBlock.ALLOCATED | OBlock.OCCUPIED | OBlock.RUNNING), block.getState());
    JUnitUtil.waitFor(() -> {
        return Bundle.getMessage("Halted", name, "0").equals(warrant.getRunningMessage());
    }, "Warrant processed sensor change");
    Assert.assertEquals("Halted/Resume message", warrant.getRunningMessage(), Bundle.getMessage("Halted", block.getDisplayName(), "0"));
    jmri.util.ThreadingUtil.runOnGUI(() -> {
        warrant.controlRunTrain(Warrant.RESUME);
    });
    jmri.util.JUnitUtil.waitFor(() -> {
        String m = warrant.getRunningMessage();
        return m.endsWith("Cmd #7.");
    }, "Train starts to move at 7th command");
    // OBlock sensor names
    String[] route = { "OB0", "OB1", "OB2", "OB3", "OB7", "OB5", "OB10" };
    block = _OBlockMgr.getOBlock("OB10");
    // runtimes() in next line runs the train, then checks location
    Assert.assertEquals("Train in last block", block.getSensor().getDisplayName(), runtimes(route).getDisplayName());
    flushAWT();
    // let calm down before running abort
    flushAWT();
    jmri.util.ThreadingUtil.runOnGUI(() -> {
        warrant.controlRunTrain(Warrant.ABORT);
    });
    flushAWT();
    // passed test - cleanup.  Do it here so failure leaves traces.
    TestHelper.disposeWindow(tableFrame, this);
    ControlPanelEditor panel = (ControlPanelEditor) jmri.util.JmriJFrame.getFrame("NXWarrantTest");
    // disposing this way allows test to be rerun (i.e. reload panel file) multiple times
    panel.dispose(true);
    //        TestHelper.disposeWindow(panel, this);
    // Dialog has popped up, so handle that. First, locate it.
    //        List<JDialog> dialogList = new DialogFinder(null).findAll(panel);
    //       TestHelper.disposeWindow(dialogList.get(0), this);
    // confirm one message logged
    jmri.util.JUnitAppender.assertWarnMessage("RosterSpeedProfile not found. Using default ThrottleFactor 0.75");
}
Also used : JRadioButton(javax.swing.JRadioButton) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) ConfigureManager(jmri.ConfigureManager) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) SensorManager(jmri.SensorManager) File(java.io.File) Sensor(jmri.Sensor)

Example 13 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class LearnWarrantTest method testLearnWarrant.

//    TurnoutManager _turnoutMgr;
// For types from DialogFinder().findAll(..)
@SuppressWarnings("unchecked")
public void testLearnWarrant() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    // load and display
    File f = new File("java/test/jmri/jmrit/logix/valid/LearnWarrantTest.xml");
    /* This layout designed so that the block and path will define a unique
         * route from origin to destination.  i.e. the review and select route
         * never needs to be displayed.  All possible EastBound Routes:
         * OB1/Main - OB5/main (default)    Route {OB1, OB2, OB3, OB4, OB5}
         * OB1/WestSiding - OB5/Main        Route {OB1, OB6, OB3, OB4, OB5}
         * OB1/Main - OB5/EastSiding        Route {OB1, OB2, OB3, OB7, OB5}
         * OB1/WestSiding - OB5/EastSiding  Route {OB1, OB6, OB3, OB7, OB5}
         * OB1/Main - OB7/EastSiding        Route {OB1, OB2, OB3, OB7}
         * OB1/WestSiding - OB7/EastSiding  Route {OB1, OB6, OB3, OB7}
         * OB1/Main - OB6/EastSiding        Route {OB1, OB6}
         * OB1/WestSiding - OB6/EastSiding  Route {OB1, OB6}
        */
    InstanceManager.getDefault(ConfigureManager.class).load(f);
    //        ControlPanelEditor panel = (ControlPanelEditor)null;
    _OBlockMgr = InstanceManager.getDefault(OBlockManager.class);
    _sensorMgr = InstanceManager.getDefault(SensorManager.class);
    Warrant w = new Warrant("IW00", "Learning");
    WarrantFrame frame = new WarrantFrame(w, true);
    frame._origin.blockBox.setText("OB1");
    frame._destination.blockBox.setText("OB5");
    String[] route = { "OB1", "OB2", "OB3", "OB4", "OB5" };
    pressButton(frame, Bundle.getMessage("Calculate"));
    flushAWT();
    JUnitUtil.waitFor(() -> {
        return (frame.getOrders() != null);
    }, "Found orders");
    List<BlockOrder> orders = frame.getOrders();
    Assert.assertEquals("5 BlockOrders", 5, orders.size());
    frame.setAddress("99");
    flushAWT();
    pressButton(frame, Bundle.getMessage("Start"));
    // dismiss warning "starting block not occupied
    confirmJOptionPane(frame, Bundle.getMessage("WarningTitle"), "OK");
    //        confirmJOptionPane(frame, Bundle.getMessage("QuestionTitle"), "Yes");
    // occupy starting block
    Sensor sensor = _OBlockMgr.getBySystemName(route[0]).getSensor();
    sensor.setState(Sensor.ACTIVE);
    pressButton(frame, Bundle.getMessage("Start"));
    JUnitUtil.waitFor(() -> {
        return (frame._learnThrottle != null);
    }, "Found throttle");
    Assert.assertNotNull("Throttle not found", frame._learnThrottle.getThrottle());
    sensor = recordtimes(route, frame._learnThrottle.getThrottle());
    pressButton(frame, Bundle.getMessage("Stop"));
    // change address and run
    frame.setAddress("111");
    sensor.setState(Sensor.INACTIVE);
    sensor = _OBlockMgr.getBySystemName(route[0]).getSensor();
    sensor.setState(Sensor.ACTIVE);
    pressButton(frame, Bundle.getMessage("ARun"));
    final Warrant warrant = w;
    jmri.util.JUnitUtil.waitFor(() -> {
        String m = warrant.getRunningMessage();
        return m.endsWith("Cmd #2.");
    }, "Train starts to move at 2nd command");
    sensor = runtimes(route);
    JUnitUtil.waitFor(() -> {
        return (warrant.getThrottle() == null);
    }, "Wait for run to end");
    String msg = w.getRunModeMessage();
    Assert.assertEquals("run finished", Bundle.getMessage("NotRunning", w.getDisplayName()), msg);
    //        sensor.setState(Sensor.INACTIVE);
    pressButton(frame, Bundle.getMessage("ButtonSave"));
    w = InstanceManager.getDefault(WarrantManager.class).getWarrant("Learning");
    List<ThrottleSetting> commands = w.getThrottleCommands();
    Assert.assertEquals("11 ThrottleCommands", 11, commands.size());
    /*
        for (ThrottleSetting ts: commands) {
            System.out.println(ts.toString());
        }*/
    WarrantTableFrame tableFrame = WarrantTableFrame.getDefault();
    //        WarrantTableFrame tableFrame = (WarrantTableFrame)jmri.util.JmriJFrame.getFrame(Bundle.getMessage("WarrantTable"));
    Assert.assertNotNull("Warrant Table save", tableFrame);
    // passed test - cleanup.  Do it here so failure leaves traces.
    TestHelper.disposeWindow(tableFrame, this);
    ControlPanelEditor panel = (ControlPanelEditor) jmri.util.JmriJFrame.getFrame("LearnWarrantTest");
    // disposing this way allows test to be rerun (i.e. reload panel file) multiple times
    panel.dispose(true);
    //        TestHelper.disposeWindow(panel, this);
    // Dialog has popped up, so handle that. First, locate it.
    //        List<JDialog> dialogList = new DialogFinder(null).findAll(panel);
    //        TestHelper.disposeWindow(dialogList.get(0), this);
    flushAWT();
    // confirm one message logged
    jmri.util.JUnitAppender.assertWarnMessage("RosterSpeedProfile not found. Using default ThrottleFactor 0.75");
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) ConfigureManager(jmri.ConfigureManager) SensorManager(jmri.SensorManager) File(java.io.File) Sensor(jmri.Sensor)

Example 14 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class JsonUtilHttpService method getPanel.

public ObjectNode getPanel(Locale locale, Editor editor, String format) {
    if (editor.getAllowInFrameServlet()) {
        String title = ((JmriJFrame) editor.getTargetPanel().getTopLevelAncestor()).getTitle();
        if (!title.isEmpty() && !Arrays.asList(WebServerPreferences.getDefault().getDisallowedFrames()).contains(title)) {
            String type = PANEL;
            String name = "Panel";
            if (editor instanceof ControlPanelEditor) {
                type = CONTROL_PANEL;
                name = "ControlPanel";
            } else if (editor instanceof LayoutEditor) {
                type = LAYOUT_PANEL;
                name = "Layout";
            } else if (editor instanceof SwitchboardEditor) {
                type = SWITCHBOARD_PANEL;
                name = "Switchboard";
            }
            ObjectNode root = this.mapper.createObjectNode();
            root.put(TYPE, PANEL);
            ObjectNode data = root.putObject(DATA);
            // NOI18N
            data.put(NAME, name + "/" + title.replaceAll(" ", "%20").replaceAll("#", "%23"));
            // NOI18N
            data.put(URL, "/panel/" + data.path(NAME).asText() + "?format=" + format);
            data.put(USERNAME, title);
            data.put(TYPE, type);
            return root;
        }
    }
    return null;
}
Also used : SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JmriJFrame(jmri.util.JmriJFrame)

Example 15 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class ShapeDrawerTest method testCTor.

@Test
public void testCTor() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    ControlPanelEditor frame = new ControlPanelEditor();
    ShapeDrawer t = new ShapeDrawer(frame);
    Assert.assertNotNull("exists", t);
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Test(org.junit.Test)

Aggregations

ControlPanelEditor (jmri.jmrit.display.controlPanelEditor.ControlPanelEditor)15 Rectangle (java.awt.Rectangle)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ConfigureManager (jmri.ConfigureManager)3 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)3 Element (org.jdom2.Element)3 Point (java.awt.Point)2 Ellipse2D (java.awt.geom.Ellipse2D)2 File (java.io.File)2 JFrame (javax.swing.JFrame)2 Sensor (jmri.Sensor)2 SensorManager (jmri.SensorManager)2 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 Positionable (jmri.jmrit.display.Positionable)2 SwitchboardEditor (jmri.jmrit.display.switchboardEditor.SwitchboardEditor)2 JmriJFrame (jmri.util.JmriJFrame)2 Attribute (org.jdom2.Attribute)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1