use of jmri.util.swing.JmriBeanComboBox in project JMRI by JMRI.
the class LayoutSlip method editLayoutSlip.
/**
* Edit a Slip
*/
protected void editLayoutSlip(LayoutTurnout o) {
if (editOpen) {
editLayoutTurnoutFrame.setVisible(true);
return;
}
// Initialize if needed
if (editLayoutTurnoutFrame == null) {
editLayoutTurnoutFrame = new JmriJFrame(rb.getString("EditSlip"), false, true);
editLayoutTurnoutFrame.addHelpMenu("package.jmri.jmrit.display.EditLayoutSlip", true);
editLayoutTurnoutFrame.setLocation(50, 30);
Container contentPane = editLayoutTurnoutFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
JLabel turnoutNameLabel = new JLabel(Bundle.getMessage("BeanNameTurnout") + " A " + Bundle.getMessage("Name"));
turnoutAComboBox = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance(), getTurnout(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
panel1.add(turnoutNameLabel);
panel1.add(turnoutAComboBox);
contentPane.add(panel1);
JPanel panel1a = new JPanel();
panel1a.setLayout(new FlowLayout());
JLabel turnoutBNameLabel = new JLabel(Bundle.getMessage("BeanNameTurnout") + " B " + Bundle.getMessage("Name"));
turnoutBComboBox = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance(), getTurnoutB(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
panel1a.add(turnoutBNameLabel);
panel1a.add(turnoutBComboBox);
contentPane.add(panel1a);
JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayout(0, 3, 2, 2));
panel2.add(new Label(" "));
panel2.add(new Label(Bundle.getMessage("BeanNameTurnout") + " A:"));
panel2.add(new Label(Bundle.getMessage("BeanNameTurnout") + " B:"));
for (Entry<Integer, TurnoutState> ts : turnoutStates.entrySet()) {
SampleStates draw = new SampleStates(ts.getKey());
draw.repaint();
draw.setPreferredSize(new Dimension(40, 40));
panel2.add(draw);
panel2.add(ts.getValue().getComboA());
panel2.add(ts.getValue().getComboB());
}
testPanel = new TestState();
testPanel.setSize(40, 40);
testPanel.setPreferredSize(new Dimension(40, 40));
panel2.add(testPanel);
JButton testButton = new JButton("Test");
testButton.addActionListener((ActionEvent e) -> {
toggleStateTest();
});
panel2.add(testButton);
contentPane.add(panel2);
JPanel panel33 = new JPanel();
panel33.setLayout(new FlowLayout());
hiddenBox.setToolTipText(rb.getString("HiddenToolTip"));
panel33.add(hiddenBox);
contentPane.add(panel33);
// setup block name
JPanel panel3 = new JPanel();
panel3.setLayout(new FlowLayout());
JLabel block1NameLabel = new JLabel(rb.getString("BlockID"));
panel3.add(block1NameLabel);
panel3.add(blockNameComboBox);
layoutEditor.setupComboBox(blockNameComboBox, false, true);
blockNameComboBox.setToolTipText(rb.getString("EditBlockNameHint"));
contentPane.add(panel3);
// set up Edit Block buttons
JPanel panel4 = new JPanel();
panel4.setLayout(new FlowLayout());
// Edit Block
panel4.add(turnoutEditBlock = new JButton(Bundle.getMessage("EditBlock", "")));
turnoutEditBlock.addActionListener((ActionEvent event) -> {
turnoutEditBlockPressed(event);
});
// empty value for block 1
turnoutEditBlock.setToolTipText(Bundle.getMessage("EditBlockHint", ""));
contentPane.add(panel4);
// set up Done and Cancel buttons
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout());
panel5.add(slipEditDone = new JButton(Bundle.getMessage("ButtonDone")));
// make this button the default button (return or enter activates)
// Note: We have to invoke this later because we don't currently have a root pane
SwingUtilities.invokeLater(() -> {
JRootPane rootPane = SwingUtilities.getRootPane(slipEditDone);
rootPane.setDefaultButton(slipEditDone);
});
slipEditDone.addActionListener((ActionEvent event) -> {
slipEditDonePressed(event);
});
slipEditDone.setToolTipText(Bundle.getMessage("DoneHint", Bundle.getMessage("ButtonDone")));
// Cancel
panel5.add(slipEditCancel = new JButton(Bundle.getMessage("ButtonCancel")));
slipEditCancel.addActionListener((ActionEvent event) -> {
slipEditCancelPressed(event);
});
slipEditCancel.setToolTipText(Bundle.getMessage("CancelHint", Bundle.getMessage("ButtonCancel")));
contentPane.add(panel5);
}
hiddenBox.setSelected(hidden);
// Set up for Edit
blockNameComboBox.getEditor().setItem(blockName);
editLayoutTurnoutFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
slipEditCancelPressed(null);
}
});
editLayoutTurnoutFrame.pack();
editLayoutTurnoutFrame.setVisible(true);
editOpen = true;
needsBlockUpdate = false;
}
use of jmri.util.swing.JmriBeanComboBox in project JMRI by JMRI.
the class AddSignalMastPanel method okPressed.
/**
* Store user input for a signal mast definition in new or existing mast object.
* <p>
* Invoked from Apply/Create button.
*
* @param e the event heard
*/
void okPressed(ActionEvent e) {
String mastname = mastNames.get(mastBox.getSelectedIndex()).getName();
// N11N
String user = userName.getText().trim();
if (user.equals("")) {
int i = JOptionPane.showConfirmDialog(null, "No Username has been defined, this may cause issues when editing the mast later.\nAre you sure that you want to continue?", "No UserName Given", JOptionPane.YES_NO_OPTION);
if (i != 0) {
return;
}
}
// create new mast
if (mast == null) {
if (!checkUserName(userName.getText())) {
return;
}
if (Bundle.getMessage("HeadCtlMast").equals(signalMastDriver.getSelectedItem())) {
if (!checkSignalHeadUse()) {
return;
}
StringBuilder build = new StringBuilder();
build.append("IF$shsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4));
for (JmriBeanComboBox head : headList) {
if (head != null && head.getSelectedDisplayName() != null)
build.append("(" + StringUtil.parenQuote(head.getSelectedDisplayName()) + ")");
}
String name = build.toString();
log.debug("add signal: " + name);
SignalMast m = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name);
if (m != null) {
JOptionPane.showMessageDialog(null, java.text.MessageFormat.format(Bundle.getMessage("DuplicateMast"), new Object[] { m.getDisplayName() }), Bundle.getMessage("DuplicateMastTitle"), JOptionPane.INFORMATION_MESSAGE);
return;
}
try {
m = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(name);
} catch (IllegalArgumentException ex) {
// user input no good
handleCreateException(name);
// without creating
return;
}
if (!user.equals("")) {
m.setUserName(user);
}
for (String aspect : disabledAspects.keySet()) {
if (disabledAspects.get(aspect).isSelected()) {
((SignalHeadSignalMast) m).setAspectDisabled(aspect);
} else {
((SignalHeadSignalMast) m).setAspectEnabled(aspect);
}
}
m.setAllowUnLit(allowUnLit.isSelected());
} else if (Bundle.getMessage("TurnCtlMast").equals(signalMastDriver.getSelectedItem())) {
String name = "IF$tsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
name += "($" + (paddedNumber.format(TurnoutSignalMast.getLastRef() + 1)) + ")";
TurnoutSignalMast turnMast = new TurnoutSignalMast(name);
for (String aspect : turnoutAspect.keySet()) {
turnoutAspect.get(aspect).setReference(name + ":" + aspect);
turnoutMastPanel.add(turnoutAspect.get(aspect).getPanel());
if (turnoutAspect.get(aspect).isAspectDisabled()) {
turnMast.setAspectDisabled(aspect);
} else {
turnMast.setAspectEnabled(aspect);
turnMast.setTurnout(aspect, turnoutAspect.get(aspect).getTurnoutName(), turnoutAspect.get(aspect).getTurnoutState());
}
}
turnMast.resetPreviousStates(resetPreviousState.isSelected());
if (!user.equals("")) {
turnMast.setUserName(user);
}
InstanceManager.getDefault(jmri.SignalMastManager.class).register(turnMast);
turnMast.setAllowUnLit(allowUnLit.isSelected());
if (allowUnLit.isSelected()) {
turnMast.setUnLitTurnout(turnoutUnLitBox.getDisplayName(), turnoutStateValues[turnoutUnLitState.getSelectedIndex()]);
}
} else if (Bundle.getMessage("VirtualMast").equals(signalMastDriver.getSelectedItem())) {
String name = "IF$vsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
name += "($" + (paddedNumber.format(VirtualSignalMast.getLastRef() + 1)) + ")";
VirtualSignalMast virtMast = new VirtualSignalMast(name);
if (!user.equals("")) {
virtMast.setUserName(user);
}
InstanceManager.getDefault(jmri.SignalMastManager.class).register(virtMast);
for (String aspect : disabledAspects.keySet()) {
if (disabledAspects.get(aspect).isSelected()) {
virtMast.setAspectDisabled(aspect);
} else {
virtMast.setAspectEnabled(aspect);
}
}
virtMast.setAllowUnLit(allowUnLit.isSelected());
} else if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
if (!validateDCCAddress()) {
return;
}
String systemNameText = ConnectionNameFromSystemName.getPrefixFromName((String) systemPrefixBox.getSelectedItem());
// if we return a null string then we will set it to use internal, thus picking up the default command station at a later date.
if (systemNameText.equals("\0")) {
systemNameText = "I";
}
if (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem())) {
systemNameText = systemNameText + "F$lncpsm:";
} else {
systemNameText = systemNameText + "F$dsm:";
}
String name = systemNameText + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
name += "(" + dccAspectAddressField.getText() + ")";
DccSignalMast dccMast;
if (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem())) {
dccMast = new jmri.jmrix.loconet.LNCPSignalMast(name);
} else {
dccMast = new DccSignalMast(name);
}
for (String aspect : dccAspect.keySet()) {
// update mast from aspect subpanel panel
dccMastPanel.add(dccAspect.get(aspect).getPanel());
if (dccAspect.get(aspect).isAspectDisabled()) {
dccMast.setAspectDisabled(aspect);
} else {
dccMast.setAspectEnabled(aspect);
dccMast.setOutputForAppearance(aspect, dccAspect.get(aspect).getAspectId());
}
}
if (!user.equals("")) {
dccMast.setUserName(user);
}
dccMast.setAllowUnLit(allowUnLit.isSelected());
if (allowUnLit.isSelected()) {
dccMast.setUnlitId(Integer.parseInt(unLitAspectField.getText()));
}
InstanceManager.getDefault(jmri.SignalMastManager.class).register(dccMast);
} else if (Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem())) {
// Create was pressed for new mast, check all boxes are filled
if (turnoutBox1.getDisplayName().isEmpty() || (bitNum > 1 && turnoutBox2.getDisplayName().isEmpty()) || (bitNum > 2 && turnoutBox3.getDisplayName().isEmpty()) || (bitNum > 3 && turnoutBox4.getDisplayName().equals("")) || (bitNum > 4 && turnoutBox5.getDisplayName().equals("")) || (bitNum > 5 && turnoutBox6.getDisplayName().equals(""))) {
// radd extra OR in order to set MAXMATRIXBITS > 6
//error dialog
JOptionPane.showMessageDialog(null, Bundle.getMessage("MatrixOutputEmpty", mastname), Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
log.error("Empty output on panel");
return;
}
//create new MatrixMast with props from panel
String name = "IF$xsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
name += "($" + (paddedNumber.format(MatrixSignalMast.getLastRef() + 1));
// for the number of t = "turnout-outputs", add option for direct packets
name += ")" + "-" + bitNum + "t";
MatrixSignalMast matrixMast = new MatrixSignalMast(name);
// store number of columns in aspect - outputs matrix in mast
matrixMast.setBitNum(bitNum);
//store outputs from turnoutBoxes; method in line 976
// store choice from turnoutBox1
matrixMast.setOutput("output1", turnoutBox1.getDisplayName());
// write mast name to output1 bean comment
setMatrixReference(turnoutBox1, name + ":output1");
if (bitNum > 1) {
// store choice from turnoutBox2
matrixMast.setOutput("output2", turnoutBox2.getDisplayName());
// write mast name to output2 bean comment
setMatrixReference(turnoutBox2, name + ":output2");
if (bitNum > 2) {
// store choice from turnoutBox3
matrixMast.setOutput("output3", turnoutBox3.getDisplayName());
// write mast name to output3 bean comment
setMatrixReference(turnoutBox3, name + ":output3");
if (bitNum > 3) {
// store choice from turnoutBox4
matrixMast.setOutput("output4", turnoutBox4.getDisplayName());
// write mast name to output4 bean comment
setMatrixReference(turnoutBox4, name + ":output4");
if (bitNum > 4) {
// store choice from turnoutBox5
matrixMast.setOutput("output5", turnoutBox5.getDisplayName());
// write mast name to output5 bean comment
setMatrixReference(turnoutBox5, name + ":output5");
if (bitNum > 5) {
// store choice from turnoutBox6
matrixMast.setOutput("output6", turnoutBox6.getDisplayName());
// write mast name to output6 bean comment
setMatrixReference(turnoutBox6, name + ":output6");
// repeat in order to set MAXMATRIXBITS > 6
}
}
}
}
}
for (String aspect : matrixAspect.keySet()) {
// store matrix in mast per aspect, compare with line 991
// read from aspect panel to mast
matrixMastPanel.add(matrixAspect.get(aspect).getPanel());
if (matrixAspect.get(aspect).isAspectDisabled()) {
// don't store bits when this aspect is disabled
matrixMast.setAspectDisabled(aspect);
} else {
matrixMast.setAspectEnabled(aspect);
// return as char[]
matrixMast.setBitsForAspect(aspect, matrixAspect.get(aspect).trimAspectBits());
}
}
// read from panel, not displayed?
matrixMast.resetPreviousStates(resetPreviousState.isSelected());
matrixMast.setAllowUnLit(allowUnLit.isSelected());
if (allowUnLit.isSelected()) {
// copy bits from UnLitPanel var unLitPanelBits
try {
// same as line 1046,
matrixMast.setUnLitBits(trimUnLitBits());
} catch (Exception ex) {
log.error("failed to read and copy unLitPanelBits");
}
}
if (!user.equals("")) {
matrixMast.setUserName(user);
}
// store bitNum pref
prefs.addComboBoxLastSelection(matrixBitNumSelectionCombo, (String) columnChoice.getSelectedItem());
InstanceManager.getDefault(jmri.SignalMastManager.class).register(matrixMast);
}
prefs.addComboBoxLastSelection(systemSelectionCombo, (String) sigSysBox.getSelectedItem());
prefs.addComboBoxLastSelection(driverSelectionCombo, (String) signalMastDriver.getSelectedItem());
prefs.addComboBoxLastSelection(mastSelectionCombo + ":" + ((String) sigSysBox.getSelectedItem()), (String) mastBox.getSelectedItem());
refreshHeadComboBox();
} else {
// Edit mode, mast was already available
if (Bundle.getMessage("HeadCtlMast").equals(signalMastDriver.getSelectedItem())) {
SignalHeadSignalMast headMast = (SignalHeadSignalMast) mast;
for (String aspect : disabledAspects.keySet()) {
if (disabledAspects.get(aspect).isSelected()) {
headMast.setAspectDisabled(aspect);
} else {
headMast.setAspectEnabled(aspect);
}
}
headMast.setAllowUnLit(allowUnLit.isSelected());
} else if (Bundle.getMessage("TurnCtlMast").equals(signalMastDriver.getSelectedItem())) {
String name = "IF$tsm:" + sigsysname + ":" + mastname.substring(11, mastname.length() - 4);
TurnoutSignalMast turnMast = (TurnoutSignalMast) mast;
for (String aspect : turnoutAspect.keySet()) {
turnoutAspect.get(aspect).setReference(name + ":" + aspect);
turnMast.setTurnout(aspect, turnoutAspect.get(aspect).getTurnoutName(), turnoutAspect.get(aspect).getTurnoutState());
turnoutMastPanel.add(turnoutAspect.get(aspect).getPanel());
if (turnoutAspect.get(aspect).isAspectDisabled()) {
turnMast.setAspectDisabled(aspect);
} else {
turnMast.setAspectEnabled(aspect);
}
}
turnMast.resetPreviousStates(resetPreviousState.isSelected());
turnMast.setAllowUnLit(allowUnLit.isSelected());
if (allowUnLit.isSelected()) {
turnMast.setUnLitTurnout(turnoutUnLitBox.getDisplayName(), turnoutStateValues[turnoutUnLitState.getSelectedIndex()]);
}
} else if (Bundle.getMessage("VirtualMast").equals(signalMastDriver.getSelectedItem())) {
VirtualSignalMast virtMast = (VirtualSignalMast) mast;
for (String aspect : disabledAspects.keySet()) {
if (disabledAspects.get(aspect).isSelected()) {
virtMast.setAspectDisabled(aspect);
} else {
virtMast.setAspectEnabled(aspect);
}
}
virtMast.setAllowUnLit(allowUnLit.isSelected());
} else if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
DccSignalMast dccMast = (DccSignalMast) mast;
for (String aspect : dccAspect.keySet()) {
dccMastPanel.add(dccAspect.get(aspect).getPanel());
if (dccAspect.get(aspect).isAspectDisabled()) {
dccMast.setAspectDisabled(aspect);
} else {
dccMast.setAspectEnabled(aspect);
dccMast.setOutputForAppearance(aspect, dccAspect.get(aspect).getAspectId());
}
}
dccMast.setAllowUnLit(allowUnLit.isSelected());
if (allowUnLit.isSelected()) {
dccMast.setUnlitId(Integer.parseInt(unLitAspectField.getText()));
}
} else if (Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem())) {
// Apply was pressed, store existing MatrixMast
MatrixSignalMast matrixMast = (MatrixSignalMast) mast;
// store number of columns in aspect - outputs matrix in mast
matrixMast.setBitNum(bitNum);
//store outputs from turnoutBoxes; method in line 865
// store choice from turnoutBox1
matrixMast.setOutput("output1", turnoutBox1.getDisplayName());
// write mast name to output1 bean comment
setMatrixReference(turnoutBox1, matrixMast.getSystemName() + ":output1");
if (bitNum > 1) {
// store choice from turnoutBox2
matrixMast.setOutput("output2", turnoutBox2.getDisplayName());
// write mast name to output2 bean comment
setMatrixReference(turnoutBox2, matrixMast.getSystemName() + ":output2");
if (bitNum > 2) {
// store choice from turnoutBox3
matrixMast.setOutput("output3", turnoutBox3.getDisplayName());
// write mast name to output3 bean comment
setMatrixReference(turnoutBox3, matrixMast.getSystemName() + ":output3");
if (bitNum > 3) {
// store choice from turnoutBox4
matrixMast.setOutput("output4", turnoutBox4.getDisplayName());
// write mast name to output4 bean comment
setMatrixReference(turnoutBox4, matrixMast.getSystemName() + ":output4");
if (bitNum > 4) {
// store choice from turnoutBox5
matrixMast.setOutput("output5", turnoutBox5.getDisplayName());
// write mast name to output5 bean comment
setMatrixReference(turnoutBox5, matrixMast.getSystemName() + ":output5");
if (bitNum > 4) {
// store choice from turnoutBox6
matrixMast.setOutput("output6", turnoutBox6.getDisplayName());
// write mast name to output6 bean comment
setMatrixReference(turnoutBox6, matrixMast.getSystemName() + ":output6");
// nest if in order to set MAXMATRIXBITS > 6
}
}
}
}
}
for (String aspect : matrixAspect.keySet()) {
// store matrix in mast, compare with line 881
// from matrixMastPanel hashtable to matrixMast
// update from aspect panel to mast
matrixMastPanel.add(matrixAspect.get(aspect).getPanel());
if (matrixAspect.get(aspect).isAspectDisabled()) {
// don't store bits when this aspect is disabled
matrixMast.setAspectDisabled(aspect);
} else {
matrixMast.setAspectEnabled(aspect);
// return as char[]
matrixMast.setBitsForAspect(aspect, matrixAspect.get(aspect).trimAspectBits());
}
}
matrixMast.resetPreviousStates(resetPreviousState.isSelected());
matrixMast.setAllowUnLit(allowUnLit.isSelected());
if (allowUnLit.isSelected()) {
try {
// same as line 929
matrixMast.setUnLitBits(trimUnLitBits());
} catch (Exception ex) {
log.error("failed to read and copy unLitPanelBits");
}
}
}
}
// close and dispose JPanel
clearPanel();
}
Aggregations