Search in sources :

Example 1 with CdiPanel

use of org.openlcb.cdi.swing.CdiPanel in project JMRI by JMRI.

the class ClientActions method openCdiWindow.

public void openCdiWindow(NodeID destNode, String description) {
    final java.util.ArrayList<JButton> readList = new java.util.ArrayList<JButton>();
    final java.util.ArrayList<JButton> sensorButtonList = new java.util.ArrayList<JButton>();
    final java.util.ArrayList<JButton> turnoutButtonList = new java.util.ArrayList<JButton>();
    JmriJFrame f = new JmriJFrame();
    f.setTitle(Bundle.getMessage("CdiPanelConfigure", description));
    f.setLayout(new javax.swing.BoxLayout(f.getContentPane(), javax.swing.BoxLayout.Y_AXIS));
    CdiPanel m = new CdiPanel();
    f.add(m);
    m.setEventTable(iface.getNodeStore().getSimpleNodeIdent(destNode).getUserName(), iface.getEventTable());
    // create an object to add "New Sensor" buttons
    CdiPanel.GuiItemFactory factory = new CdiPanel.GuiItemFactory() {

        private boolean haveButtons = false;

        @Override
        public JButton handleReadButton(JButton button) {
            readList.add(button);
            return button;
        }

        @Override
        public JButton handleWriteButton(JButton button) {
            return button;
        }

        @Override
        public void handleGroupPaneStart(JPanel pane) {
            this.gpane = pane;
            evt1 = null;
            evt2 = null;
            desc = null;
            return;
        }

        @Override
        public void handleGroupPaneEnd(JPanel pane) {
            if (gpane != null && evt1 != null && evt2 != null && desc != null) {
                JPanel p = new JPanel();
                p.setLayout(new FlowLayout());
                p.setAlignmentX(-1.0f);
                pane.add(p);
                JButton button = new JButton(Bundle.getMessage("CdiPanelMakeSensor"));
                p.add(button);
                sensorButtonList.add(button);
                button.addActionListener(new java.awt.event.ActionListener() {

                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                        jmri.Sensor sensor = jmri.InstanceManager.sensorManagerInstance().provideSensor("MS" + mevt1.getText() + ";" + mevt2.getText());
                        if (mdesc.getText().length() > 0) {
                            sensor.setUserName(mdesc.getText());
                        }
                        log.info("make sensor MS" + mevt1.getText() + ";" + mevt2.getText() + " [" + mdesc.getText() + "]");
                    }

                    JTextField mdesc = desc;

                    JFormattedTextField mevt1 = evt1;

                    JFormattedTextField mevt2 = evt2;
                });
                button = new JButton(Bundle.getMessage("CdiPanelMakeTurnout"));
                p.add(button);
                turnoutButtonList.add(button);
                button.addActionListener(new java.awt.event.ActionListener() {

                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                        jmri.Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().provideTurnout("MT" + mevt1.getText() + ";" + mevt2.getText());
                        if (mdesc.getText().length() > 0) {
                            turnout.setUserName(mdesc.getText());
                        }
                        log.info("make turnout MT" + mevt1.getText() + ";" + mevt2.getText() + " [" + mdesc.getText() + "]");
                    }

                    JTextField mdesc = desc;

                    JFormattedTextField mevt1 = evt1;

                    JFormattedTextField mevt2 = evt2;
                });
                if (!haveButtons) {
                    haveButtons = true;
                    m.addButtonToFooter(buttonForList(sensorButtonList, Bundle.getMessage("CdiPanelMakeAllSensors")));
                    m.addButtonToFooter(buttonForList(turnoutButtonList, Bundle.getMessage("CdiPanelMakeAllTurnouts")));
                }
                gpane = null;
                evt1 = null;
                evt2 = null;
                desc = null;
            }
            return;
        }

        @Override
        public JFormattedTextField handleEventIdTextField(JFormattedTextField field) {
            if (evt1 == null) {
                evt1 = field;
            } else if (evt2 == null) {
                evt2 = field;
            } else {
                // flag too many
                gpane = null;
            }
            return field;
        }

        @Override
        public JTextField handleStringValue(JTextField value) {
            desc = value;
            return value;
        }

        JPanel gpane = null;

        JTextField desc = null;

        JFormattedTextField evt1 = null;

        JFormattedTextField evt2 = null;
    };
    ConfigRepresentation rep = iface.getConfigForNode(destNode);
    m.initComponents(rep, factory);
    f.pack();
    f.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) CdiPanel(org.openlcb.cdi.swing.CdiPanel) FlowLayout(java.awt.FlowLayout) ActionListener(java.awt.event.ActionListener) JButton(javax.swing.JButton) JFormattedTextField(javax.swing.JFormattedTextField) JTextField(javax.swing.JTextField) ActionEvent(java.awt.event.ActionEvent) ConfigRepresentation(org.openlcb.cdi.impl.ConfigRepresentation) JmriJFrame(jmri.util.JmriJFrame)

Example 2 with CdiPanel

use of org.openlcb.cdi.swing.CdiPanel in project JMRI by JMRI.

the class CdiPanelDemo method testDisplay.

@Test
public void testDisplay() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    JFrame f = new JFrame();
    f.setTitle("Configuration Demonstration");
    CdiPanel m = new CdiPanel();
    m.initComponents(demoRepFromSample(SampleFactory.getBasicSample()), new CdiPanel.GuiItemFactory() {

        @Override
        public JButton handleReadButton(JButton button) {
            //System.out.println("process button");
            button.setBorder(BorderFactory.createLineBorder(java.awt.Color.yellow));
            return button;
        }
    });
    f.add(m);
    // show
    f.pack();
    f.setVisible(true);
    f.dispose();
}
Also used : CdiPanel(org.openlcb.cdi.swing.CdiPanel) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) Test(org.junit.Test)

Example 3 with CdiPanel

use of org.openlcb.cdi.swing.CdiPanel in project JMRI by JMRI.

the class CdiPanelDemo method testCtor.

public void testCtor() {
    CdiPanel m = new CdiPanel();
    Assert.assertNotNull(m);
}
Also used : CdiPanel(org.openlcb.cdi.swing.CdiPanel)

Example 4 with CdiPanel

use of org.openlcb.cdi.swing.CdiPanel in project JMRI by JMRI.

the class CdiPanelDemo method makeFrameFromFile.

JFrame makeFrameFromFile(String fileName) {
    JFrame f = new JFrame();
    CdiPanel m = new CdiPanel();
    m.initComponents(demoRepFromFile(new File(fileName)), new CdiPanel.GuiItemFactory() {

        @Override
        public JButton handleReadButton(JButton button) {
            //System.out.println("process button");
            button.setBorder(BorderFactory.createLineBorder(java.awt.Color.yellow));
            return button;
        }
    });
    f.add(m);
    f.pack();
    return f;
}
Also used : CdiPanel(org.openlcb.cdi.swing.CdiPanel) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) DemoReadWriteAccess.demoRepFromFile(org.openlcb.cdi.impl.DemoReadWriteAccess.demoRepFromFile) File(java.io.File)

Aggregations

CdiPanel (org.openlcb.cdi.swing.CdiPanel)4 JButton (javax.swing.JButton)3 JFrame (javax.swing.JFrame)2 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 JFormattedTextField (javax.swing.JFormattedTextField)1 JPanel (javax.swing.JPanel)1 JTextField (javax.swing.JTextField)1 JmriJFrame (jmri.util.JmriJFrame)1 Test (org.junit.Test)1 ConfigRepresentation (org.openlcb.cdi.impl.ConfigRepresentation)1 DemoReadWriteAccess.demoRepFromFile (org.openlcb.cdi.impl.DemoReadWriteAccess.demoRepFromFile)1