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);
}
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();
}
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);
}
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;
}
Aggregations