use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class TrackSegment method editTrackSegment.
/**
* Edit a Track Segment.
*/
protected void editTrackSegment() {
if (editOpen) {
editTrackSegmentFrame.setVisible(true);
return;
}
// Initialize if needed
if (editTrackSegmentFrame == null) {
// key moved to DisplayBundle to be found by CircuitBuilder.java
editTrackSegmentFrame = new JmriJFrame(Bundle.getMessage("EditTrackSegment"), false, true);
editTrackSegmentFrame.addHelpMenu("package.jmri.jmrit.display.EditTrackSegment", true);
editTrackSegmentFrame.setLocation(50, 30);
Container contentPane = editTrackSegmentFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// add dashed choice
JPanel panel31 = new JPanel();
panel31.setLayout(new FlowLayout());
dashedBox.removeAllItems();
dashedBox.addItem(rb.getString("Solid"));
solidIndex = 0;
dashedBox.addItem(rb.getString("Dashed"));
dashedIndex = 1;
dashedBox.setToolTipText(rb.getString("DashedToolTip"));
panel31.add(new JLabel(rb.getString("Style") + " : "));
panel31.add(dashedBox);
contentPane.add(panel31);
// add mainline choice
JPanel panel32 = new JPanel();
panel32.setLayout(new FlowLayout());
mainlineBox.removeAllItems();
mainlineBox.addItem(rb.getString("Mainline"));
mainlineTrackIndex = 0;
mainlineBox.addItem(rb.getString("NotMainline"));
sideTrackIndex = 1;
mainlineBox.setToolTipText(rb.getString("MainlineToolTip"));
panel32.add(mainlineBox);
contentPane.add(panel32);
// add hidden choice
JPanel panel33 = new JPanel();
panel33.setLayout(new FlowLayout());
hiddenBox.setToolTipText(rb.getString("HiddenToolTip"));
panel33.add(hiddenBox);
contentPane.add(panel33);
// setup block name
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
JLabel blockNameLabel = new JLabel(rb.getString("BlockID"));
panel2.add(blockNameLabel);
layoutEditor.setupComboBox(blockNameComboBox, false, true);
blockNameComboBox.setToolTipText(rb.getString("EditBlockNameHint"));
panel2.add(blockNameComboBox);
contentPane.add(panel2);
if (getArc() && circle) {
JPanel panel20 = new JPanel();
panel20.setLayout(new FlowLayout());
JLabel arcLabel = new JLabel("Set Arc Angle");
panel20.add(arcLabel);
panel20.add(arcField);
arcField.setToolTipText("Set Arc Angle");
contentPane.add(panel20);
arcField.setText("" + getAngle());
}
// set up Edit Block, Done and Cancel buttons
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout());
// Edit Block
panel5.add(segmentEditBlock = new JButton(Bundle.getMessage("EditBlock", "")));
segmentEditBlock.addActionListener((ActionEvent e) -> {
segmentEditBlockPressed(e);
});
// empty value for block 1
segmentEditBlock.setToolTipText(Bundle.getMessage("EditBlockHint", ""));
panel5.add(segmentEditDone = new JButton(Bundle.getMessage("ButtonDone")));
segmentEditDone.addActionListener((ActionEvent e) -> {
segmentEditDonePressed(e);
});
segmentEditDone.setToolTipText(Bundle.getMessage("DoneHint", 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(segmentEditDone);
rootPane.setDefaultButton(segmentEditDone);
});
// Cancel
panel5.add(segmentEditCancel = new JButton(Bundle.getMessage("ButtonCancel")));
segmentEditCancel.addActionListener((ActionEvent e) -> {
segmentEditCancelPressed(e);
});
segmentEditCancel.setToolTipText(Bundle.getMessage("CancelHint", Bundle.getMessage("ButtonCancel")));
contentPane.add(panel5);
}
// Set up for Edit
if (mainline) {
mainlineBox.setSelectedIndex(mainlineTrackIndex);
} else {
mainlineBox.setSelectedIndex(sideTrackIndex);
}
if (dashed) {
dashedBox.setSelectedIndex(dashedIndex);
} else {
dashedBox.setSelectedIndex(solidIndex);
}
hiddenBox.setSelected(hidden);
blockNameComboBox.getEditor().setItem(blockName);
editTrackSegmentFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
segmentEditCancelPressed(null);
}
});
editTrackSegmentFrame.pack();
editTrackSegmentFrame.setVisible(true);
editOpen = true;
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class PanelEditor method makeFrame.
/**
* Create sequence of panels, etc, for layout: JFrame contains its
* ContentPane which contains a JPanel with BoxLayout (p1) which contains a
* JScollPane (js) which contains the targetPane
*
*/
public JmriJFrame makeFrame(String name) {
JmriJFrame targetFrame = new JmriJFrame(name);
targetFrame.setVisible(false);
JMenuBar menuBar = new JMenuBar();
JMenu editMenu = new JMenu(Bundle.getMessage("MenuEdit"));
menuBar.add(editMenu);
editMenu.add(new AbstractAction(Bundle.getMessage("OpenEditor")) {
@Override
public void actionPerformed(ActionEvent e) {
setVisible(true);
}
});
editMenu.addSeparator();
editMenu.add(new AbstractAction(Bundle.getMessage("DeletePanel")) {
@Override
public void actionPerformed(ActionEvent e) {
if (deletePanel()) {
dispose(true);
}
}
});
targetFrame.setJMenuBar(menuBar);
// add maker menu
JMenu markerMenu = new JMenu(Bundle.getMessage("MenuMarker"));
menuBar.add(markerMenu);
markerMenu.add(new AbstractAction(Bundle.getMessage("AddLoco")) {
@Override
public void actionPerformed(ActionEvent e) {
locoMarkerFromInput();
}
});
markerMenu.add(new AbstractAction(Bundle.getMessage("AddLocoRoster")) {
@Override
public void actionPerformed(ActionEvent e) {
locoMarkerFromRoster();
}
});
markerMenu.add(new AbstractAction(Bundle.getMessage("RemoveMarkers")) {
@Override
public void actionPerformed(ActionEvent e) {
removeMarkers();
}
});
JMenu warrantMenu = jmri.jmrit.logix.WarrantTableAction.makeWarrantMenu(isEditable());
if (warrantMenu != null) {
menuBar.add(warrantMenu);
}
targetFrame.addHelpMenu("package.jmri.jmrit.display.PanelTarget", true);
return targetFrame;
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class PaneProgDp3Action method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// NOI18N
log.debug("Pane programmer requested");
if (f == null) {
log.debug("found f==null");
// create the initial frame that steers
// NOI18N
f = new JmriJFrame(apps.gui3.dp3.Bundle.getMessage("FrameProgrammerSetup"));
f.getContentPane().setLayout(new BorderLayout());
// ensure status line is cleared on close so it is normal if re-opened
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
// NOI18N
statusLabel.setText(SymbolicProgBundle.getMessage("StateIdle"));
f.windowClosing(we);
}
});
// add the Roster menu
JMenuBar menuBar = new JMenuBar();
// NOI18N
JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile"));
// NOI18N
j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false));
// NOI18N
j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true));
menuBar.add(j);
// NOI18N
menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
f.setJMenuBar(menuBar);
final JPanel bottomPanel = new JPanel(new BorderLayout());
// new Loco on programming track
combinedLocoSelTree = new CombinedLocoSelTreePane(statusLabel, modePane) {
@Override
protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String progName) {
// progName is ignored here
log.debug("startProgrammer");
String title = // NOI18N
java.text.MessageFormat.format(// NOI18N
SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), // NOI18N
new Object[] { Bundle.getMessage("NewDecoder") });
if (re != null) {
title = // NOI18N
java.text.MessageFormat.format(// NOI18N
SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { re.getId() });
}
JFrame p;
if (!modePane.isSelected() || modePane.getProgrammer() == null) {
p = new PaneProgFrame(decoderFile, re, // NOI18N
title, // NOI18N
"programmers" + File.separator + "Comprehensive.xml", null, false) {
@Override
protected JPanel getModePane() {
return null;
}
};
} else {
p = new PaneServiceProgFrame(decoderFile, re, // NOI18N
title, // NOI18N
"programmers" + File.separator + "Comprehensive.xml", modePane.getProgrammer());
}
p.pack();
p.setVisible(true);
}
@Override
protected void openNewLoco() {
log.debug("openNewLoco");
// find the decoderFile object
DecoderFile decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
// NOI18N
log.debug("decoder file: {}", decoderFile.getFilename());
if (rosterIdField.getText().equals(SymbolicProgBundle.getMessage("LabelNewDecoder"))) {
// NOI18N
re = new RosterEntry();
re.setDecoderFamily(decoderFile.getFamily());
re.setDecoderModel(decoderFile.getModel());
// NOI18N
re.setId(SymbolicProgBundle.getMessage("LabelNewDecoder"));
//re.writeFile(cvModel, iCvModel, variableModel );
// note that we're leaving the filename null
// add the new roster entry to the in-memory roster
Roster.getDefault().addEntry(re);
} else {
try {
saveRosterEntry();
} catch (JmriException ex) {
// NOI18N
log.warn("Exception while saving roster entry", ex);
return;
}
}
// create a dummy RosterEntry with the decoder info
// no programmer name in this case
startProgrammer(decoderFile, re, "");
//Set our roster entry back to null so that a fresh roster entry can be created if needed
re = null;
}
@Override
protected JPanel layoutRosterSelection() {
log.debug("layoutRosterSelection");
return null;
}
@Override
protected JPanel layoutDecoderSelection() {
log.debug("layoutDecoderSelection");
JPanel pan = super.layoutDecoderSelection();
dTree.removeTreeSelectionListener(dListener);
dTree.addTreeSelectionListener(dListener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!dTree.isSelectionEmpty() && dTree.getSelectionPath() != null && // check that this isn't just a model
((TreeNode) dTree.getSelectionPath().getLastPathComponent()).isLeaf() && // can't be just a mfg, has to be at least a family
dTree.getSelectionPath().getPathCount() > 2 && // can't be a multiple decoder selection
dTree.getSelectionCount() < 2) {
log.debug("Selection event with " + dTree.getSelectionPath().toString());
//if (locoBox != null) locoBox.setSelectedIndex(0);
go2.setEnabled(true);
go2.setRequestFocusEnabled(true);
go2.requestFocus();
// NOI18N
go2.setToolTipText(SymbolicProgBundle.getMessage("TipClickToOpen"));
decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
setUpRosterPanel();
} else {
decoderFile = null;
// decoder not selected - require one
go2.setEnabled(false);
// NOI18N
go2.setToolTipText(SymbolicProgBundle.getMessage("TipSelectLoco"));
setUpRosterPanel();
}
}
});
return pan;
}
@Override
protected void selectDecoder(int mfgID, int modelID, int productID) {
log.debug("selectDecoder");
//On selecting a new decoder start a fresh with a new roster entry
super.selectDecoder(mfgID, modelID, productID);
findDecoderAddress();
}
@Override
protected JPanel createProgrammerSelection() {
log.debug("createProgrammerSelection");
JPanel pane3a = new JPanel();
pane3a.setLayout(new BoxLayout(pane3a, BoxLayout.Y_AXIS));
// NOI18N
go2 = new JButton(Bundle.getMessage("OpenProgrammer"));
go2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
// NOI18N
log.debug("Open programmer pressed");
openButton();
// close this window to prevent having
// two windows processing at the same time
//
// Alternately, could have just cleared out a
// bunch of stuff to force starting over, but
// that seems to be an even more confusing
// user experience.
log.debug("Closing f {}", f);
WindowEvent wev = new WindowEvent(f, WindowEvent.WINDOW_CLOSING);
java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
}
});
go2.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
go2.setEnabled(false);
// NOI18N
go2.setToolTipText(SymbolicProgBundle.getMessage("TipSelectLoco"));
bottomPanel.add(go2, BorderLayout.EAST);
return pane3a;
}
};
// load primary frame
JPanel topPanel = new JPanel();
topPanel.add(modePane);
topPanel.add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
f.getContentPane().add(topPanel, BorderLayout.NORTH);
//f.getContentPane().add(modePane);
//f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
combinedLocoSelTree.setAlignmentX(JLabel.CENTER_ALIGNMENT);
f.getContentPane().add(combinedLocoSelTree, BorderLayout.CENTER);
//f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
//basicRoster.setEnabled(false);
statusLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
bottomPanel.add(statusLabel, BorderLayout.SOUTH);
f.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
f.pack();
// NOI18N
log.debug("Tab-Programmer setup created");
} else {
re = null;
combinedLocoSelTree.resetSelections();
}
f.setVisible(true);
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class LogixTableAction method makeEditConditionalWindow.
// ********************* Edit Conditional Window and Methods *******************
/**
* Create and/or initialize the Edit Conditional window.
* <p>
* Note: you can get here via the New Conditional button (newConditionalPressed)
* or via an Edit button in the Conditional table of the Edit Logix window.
*/
void makeEditConditionalWindow() {
// deactivate this Logix
_curLogix.deActivateLogix();
conditionalUserName.setText(_curConditional.getUserName());
if (editConditionalFrame == null) {
editConditionalFrame = new JmriJFrame(rbx.getString("TitleEditConditional"), false, false);
editConditionalFrame.addHelpMenu("package.jmri.jmrit.beantable.ConditionalAddEdit", true);
Container contentPane = editConditionalFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
panel1.add(new JLabel(Bundle.getMessage("ColumnSystemName") + ":"));
panel1.add(new JLabel(_curConditional.getSystemName()));
contentPane.add(panel1);
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
panel2.add(new JLabel(Bundle.getMessage("ColumnUserName") + ":"));
panel2.add(conditionalUserName);
conditionalUserName.setToolTipText(rbx.getString("ConditionalUserNameHint"));
contentPane.add(panel2);
// add Logical Expression Section
JPanel logicPanel = new JPanel();
logicPanel.setLayout(new BoxLayout(logicPanel, BoxLayout.Y_AXIS));
// add Antecedent Expression Panel -ONLY appears for MIXED operator statements
_antecedent = _curConditional.getAntecedentExpression();
_logicType = _curConditional.getLogicType();
_antecedentField = new JTextField(65);
_antecedentField.setFont(new Font("SansSerif", Font.BOLD, 14));
_antecedentField.setText(_antecedent);
_antecedentPanel = makeEditPanel(_antecedentField, "LabelAntecedent", "LabelAntecedentHint");
JButton helpButton = new JButton(Bundle.getMessage("MenuHelp"));
_antecedentPanel.add(helpButton);
helpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
helpPressed(e);
}
});
_antecedentPanel.add(helpButton);
_antecedentPanel.setVisible(_logicType == Conditional.MIXED);
logicPanel.add(_antecedentPanel);
// add state variable table title
JPanel varTitle = new JPanel();
varTitle.setLayout(new FlowLayout());
varTitle.add(new JLabel(rbx.getString("StateVariableTableTitle")));
logicPanel.add(varTitle);
// set up state variables table
// initialize and populate Combo boxes for table of state variables
_notOperatorBox = new JComboBox<String>();
_notOperatorBox.addItem(" ");
_notOperatorBox.addItem(Bundle.getMessage("LogicNOT"));
_andOperatorBox = new JComboBox<String>();
_andOperatorBox.addItem(Bundle.getMessage("LogicAND"));
_andOperatorBox.addItem(Bundle.getMessage("LogicOR"));
// initialize table of state variables
_variableTableModel = new VariableTableModel();
JTable variableTable = new JTable(_variableTableModel);
variableTable.setRowHeight(_notOperatorBox.getPreferredSize().height);
variableTable.setRowSelectionAllowed(false);
int rowHeight = variableTable.getRowHeight();
TableColumnModel variableColumnModel = variableTable.getColumnModel();
TableColumn rowColumn = variableColumnModel.getColumn(VariableTableModel.ROWNUM_COLUMN);
rowColumn.setResizable(false);
rowColumn.setMaxWidth(new JTextField(3).getPreferredSize().width);
TableColumn andColumn = variableColumnModel.getColumn(VariableTableModel.AND_COLUMN);
andColumn.setResizable(false);
andColumn.setCellEditor(new DefaultCellEditor(_andOperatorBox));
andColumn.setMaxWidth(_andOperatorBox.getPreferredSize().width - 5);
TableColumn notColumn = variableColumnModel.getColumn(VariableTableModel.NOT_COLUMN);
notColumn.setCellEditor(new DefaultCellEditor(_notOperatorBox));
notColumn.setMaxWidth(_notOperatorBox.getPreferredSize().width - 5);
notColumn.setResizable(false);
TableColumn descColumn = variableColumnModel.getColumn(VariableTableModel.DESCRIPTION_COLUMN);
descColumn.setPreferredWidth(300);
descColumn.setMinWidth(200);
descColumn.setResizable(true);
TableColumn stateColumn = variableColumnModel.getColumn(VariableTableModel.STATE_COLUMN);
stateColumn.setResizable(true);
stateColumn.setMinWidth(50);
stateColumn.setMaxWidth(80);
TableColumn triggerColumn = variableColumnModel.getColumn(VariableTableModel.TRIGGERS_COLUMN);
triggerColumn.setResizable(true);
triggerColumn.setMinWidth(30);
triggerColumn.setMaxWidth(80);
TableColumn editColumn = variableColumnModel.getColumn(VariableTableModel.EDIT_COLUMN);
ButtonRenderer buttonRenderer = new ButtonRenderer();
variableTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
variableTable.setDefaultEditor(JButton.class, buttonEditor);
JButton testButton = new JButton("XXXXXX");
variableTable.setRowHeight(testButton.getPreferredSize().height);
editColumn.setMinWidth(testButton.getPreferredSize().width);
editColumn.setMaxWidth(testButton.getPreferredSize().width);
editColumn.setResizable(false);
TableColumn deleteColumn = variableColumnModel.getColumn(VariableTableModel.DELETE_COLUMN);
// ButtonRenderer and TableCellEditor already set
deleteColumn.setMinWidth(testButton.getPreferredSize().width);
deleteColumn.setMaxWidth(testButton.getPreferredSize().width);
deleteColumn.setResizable(false);
// add a scroll pane
JScrollPane variableTableScrollPane = new JScrollPane(variableTable);
Dimension dim = variableTable.getPreferredSize();
dim.height = 7 * rowHeight;
variableTableScrollPane.getViewport().setPreferredSize(dim);
logicPanel.add(variableTableScrollPane);
// set up state variable buttons and logic
JPanel panel42 = new JPanel();
panel42.setLayout(new FlowLayout());
// Add State Variable
JButton addVariableButton = new JButton(rbx.getString("AddVariableButton"));
panel42.add(addVariableButton);
addVariableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addVariablePressed(e);
}
});
addVariableButton.setToolTipText(rbx.getString("AddVariableButtonHint"));
JButton checkVariableButton = new JButton(rbx.getString("CheckVariableButton"));
panel42.add(checkVariableButton);
checkVariableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
checkVariablePressed(e);
}
});
checkVariableButton.setToolTipText(rbx.getString("CheckVariableButtonHint"));
logicPanel.add(panel42);
// logic type area
_operatorBox = new JComboBox<String>(new String[] { Bundle.getMessage("LogicAND"), Bundle.getMessage("LogicOR"), Bundle.getMessage("LogicMixed") });
JPanel typePanel = makeEditPanel(_operatorBox, "LabelLogicType", "TypeLogicHint");
_operatorBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
logicTypeChanged(e);
}
});
_operatorBox.setSelectedIndex(_logicType - 1);
logicPanel.add(typePanel);
logicPanel.add(Box.createHorizontalStrut(STRUT));
Border logicPanelBorder = BorderFactory.createEtchedBorder();
Border logicPanelTitled = BorderFactory.createTitledBorder(logicPanelBorder, rbx.getString("TitleLogicalExpression") + " ");
logicPanel.setBorder(logicPanelTitled);
contentPane.add(logicPanel);
// End of Logic Expression Section
JPanel triggerPanel = new JPanel();
triggerPanel.setLayout(new BoxLayout(triggerPanel, BoxLayout.Y_AXIS));
ButtonGroup tGroup = new ButtonGroup();
_triggerOnChangeButton = new JRadioButton(rbx.getString("triggerOnChange"));
_triggerOnChangeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_actionTableModel.fireTableDataChanged();
}
});
tGroup.add(_triggerOnChangeButton);
triggerPanel.add(_triggerOnChangeButton);
JRadioButton triggerOnAny = new JRadioButton(rbx.getString("triggerOnAny"));
triggerOnAny.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_actionTableModel.fireTableDataChanged();
}
});
tGroup.add(triggerOnAny);
triggerPanel.add(triggerOnAny);
triggerOnAny.setSelected(true);
JPanel trigPanel = new JPanel();
trigPanel.add(triggerPanel);
contentPane.add(trigPanel);
_triggerOnChangeButton.setSelected(_curConditional.getTriggerOnChange());
// add Action Consequents Section
JPanel conseqentPanel = new JPanel();
conseqentPanel.setLayout(new BoxLayout(conseqentPanel, BoxLayout.Y_AXIS));
JPanel actTitle = new JPanel();
actTitle.setLayout(new FlowLayout());
actTitle.add(new JLabel(rbx.getString("ActionTableTitle")));
conseqentPanel.add(actTitle);
// set up action consequents table
_actionTableModel = new ActionTableModel();
JTable actionTable = new JTable(_actionTableModel);
actionTable.setRowSelectionAllowed(false);
actionTable.setRowHeight(testButton.getPreferredSize().height);
JPanel actionPanel = new JPanel();
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
JPanel actionTitle = new JPanel();
actionTitle.setLayout(new FlowLayout());
conseqentPanel.add(actionPanel);
TableColumnModel actionColumnModel = actionTable.getColumnModel();
TableColumn descriptionColumn = actionColumnModel.getColumn(ActionTableModel.DESCRIPTION_COLUMN);
descriptionColumn.setResizable(true);
descriptionColumn.setPreferredWidth(600);
descriptionColumn.setMinWidth(300);
//descriptionColumn.setMaxWidth(760);
TableColumn actionEditColumn = actionColumnModel.getColumn(ActionTableModel.EDIT_COLUMN);
// ButtonRenderer already exists
actionTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor editButEditor = new ButtonEditor(new JButton());
actionTable.setDefaultEditor(JButton.class, editButEditor);
actionEditColumn.setMinWidth(testButton.getPreferredSize().width);
actionEditColumn.setMaxWidth(testButton.getPreferredSize().width);
actionEditColumn.setResizable(false);
TableColumn actionDeleteColumn = actionColumnModel.getColumn(ActionTableModel.DELETE_COLUMN);
// ButtonRenderer and TableCellEditor already set
actionDeleteColumn.setMinWidth(testButton.getPreferredSize().width);
actionDeleteColumn.setMaxWidth(testButton.getPreferredSize().width);
actionDeleteColumn.setResizable(false);
// add a scroll pane
JScrollPane actionTableScrollPane = new JScrollPane(actionTable);
dim = actionTableScrollPane.getPreferredSize();
dim.height = 7 * rowHeight;
actionTableScrollPane.getViewport().setPreferredSize(dim);
conseqentPanel.add(actionTableScrollPane);
// add action buttons to Action Section
JPanel panel43 = new JPanel();
panel43.setLayout(new FlowLayout());
JButton addActionButton = new JButton(rbx.getString("addActionButton"));
panel43.add(addActionButton);
addActionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addActionPressed(e);
}
});
addActionButton.setToolTipText(rbx.getString("addActionButtonHint"));
conseqentPanel.add(panel43);
// - Reorder action button
JButton reorderButton = new JButton(rbx.getString("ReorderButton"));
panel43.add(reorderButton);
reorderButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
reorderActionPressed(e);
}
});
reorderButton.setToolTipText(rbx.getString("ReorderButtonHint"));
conseqentPanel.add(panel43);
Border conseqentPanelBorder = BorderFactory.createEtchedBorder();
Border conseqentPanelTitled = BorderFactory.createTitledBorder(conseqentPanelBorder, rbx.getString("TitleAction"));
conseqentPanel.setBorder(conseqentPanelTitled);
contentPane.add(conseqentPanel);
// End of Action Consequents Section
// Bottom Buttons - Update Conditional
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout());
JButton updateConditional = new JButton(rbx.getString("UpdateConditionalButton"));
panel5.add(updateConditional);
updateConditional.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateConditionalPressed(e);
}
});
updateConditional.setToolTipText(rbx.getString("UpdateConditionalButtonHint"));
// Cancel
JButton cancelConditional = new JButton(Bundle.getMessage("ButtonCancel"));
panel5.add(cancelConditional);
cancelConditional.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelConditionalPressed(e);
}
});
cancelConditional.setToolTipText(rbx.getString("CancelConditionalButtonHint"));
// Delete Conditional
JButton deleteConditional = new JButton(Bundle.getMessage("ButtonDelete"));
panel5.add(deleteConditional);
deleteConditional.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteConditionalPressed(null);
}
});
deleteConditional.setToolTipText(rbx.getString("DeleteConditionalButtonHint"));
contentPane.add(panel5);
}
// setup window closing listener
editConditionalFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
cancelConditionalPressed(null);
}
});
// initialize state variable table
_variableTableModel.fireTableDataChanged();
// initialize action variables
_actionTableModel.fireTableDataChanged();
editConditionalFrame.pack();
editConditionalFrame.setVisible(true);
inEditConditionalMode = true;
// update variables to their current states
checkVariablePressed(null);
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class LogixTableAction method makeEditVariableWindow.
/**
* Create and/or initialize the Edit a Variable pane.
* <p>
* Note: you can get here via the New Variable button (addVariablePressed)
* or via an Edit button in the Variable table of the EditConditional window.
*
* @param row index of item to be edited in _variableList
*/
void makeEditVariableWindow(int row) {
if (alreadyEditingActionOrVariable()) {
return;
}
_curVariableRowNumber = row;
_curVariable = _variableList.get(row);
_editVariableFrame = new JmriJFrame(rbx.getString("TitleEditVariable"), true, true);
// _editVariableFrame.setLocation(10, 100);
JPanel topPanel = makeTopPanel(_editVariableFrame, "TitleAntecedentPhrase", 500, 160);
Box panel1 = Box.createHorizontalBox();
panel1.add(Box.createHorizontalGlue());
panel1.add(Box.createHorizontalStrut(STRUT));
// Item Type
_variableTypeBox = new JComboBox<String>();
for (int i = 0; i <= Conditional.ITEM_TYPE_LAST_STATE_VAR; i++) {
_variableTypeBox.addItem(ConditionalVariable.getItemTypeString(i));
}
panel1.add(makeEditPanel(_variableTypeBox, "LabelVariableType", "VariableTypeHint"));
panel1.add(Box.createHorizontalStrut(STRUT));
// Item Name
_variableNameField = new JTextField(30);
_variableNamePanel = makeEditPanel(_variableNameField, "LabelItemName", null);
_variableNamePanel.setMaximumSize(new Dimension(50, _variableNamePanel.getPreferredSize().height));
_variableNamePanel.setVisible(false);
panel1.add(_variableNamePanel);
panel1.add(Box.createHorizontalStrut(STRUT));
// Arbitrary name combo box to facilitate the panel construction
_variableComboNamePanel = makeEditPanel(_sensorNameBox, "LabelItemName", null);
_variableComboNamePanel.setVisible(false);
panel1.add(_variableComboNamePanel);
panel1.add(Box.createHorizontalStrut(STRUT));
// Combo box section for selecting conditional reference
// First box selects the Logix, the second selects the conditional within the logix
_selectLogixBox.addItem("XXXXXXXXXXXXXXXXXXXXX");
_selectConditionalBox.addItem("XXXXXXXXXXXXXXXXXXXXX");
_selectLogixPanel = makeEditPanel(_selectLogixBox, "SelectLogix", null);
_selectConditionalPanel = makeEditPanel(_selectConditionalBox, "SelectConditional", null);
_selectLogixPanel.setVisible(false);
_selectConditionalPanel.setVisible(false);
panel1.add(_selectLogixPanel);
panel1.add(_selectConditionalPanel);
panel1.add(Box.createHorizontalStrut(STRUT));
// State Box
_variableStateBox = new JComboBox<String>();
_variableStateBox.addItem("XXXXXXX");
_variableStatePanel = makeEditPanel(_variableStateBox, "LabelVariableState", "VariableStateHint");
_variableStatePanel.setVisible(false);
panel1.add(_variableStatePanel);
panel1.add(Box.createHorizontalStrut(STRUT));
// Aspects
_variableSignalBox = new JComboBox<String>();
_variableSignalBox.addItem("XXXXXXXXX");
_variableSignalPanel = makeEditPanel(_variableSignalBox, "LabelVariableAspect", "VariableAspectHint");
_variableSignalPanel.setVisible(false);
panel1.add(_variableSignalPanel);
panel1.add(Box.createHorizontalStrut(STRUT));
// Compare operator
_variableComparePanel = new JPanel();
_variableComparePanel.setLayout(new BoxLayout(_variableComparePanel, BoxLayout.X_AXIS));
_variableCompareOpBox = new JComboBox<String>();
for (int i = 1; i <= ConditionalVariable.NUM_COMPARE_OPERATIONS; i++) {
_variableCompareOpBox.addItem(ConditionalVariable.getCompareOperationString(i));
}
_variableComparePanel.add(makeEditPanel(_variableCompareOpBox, "LabelCompareOp", "CompareHintMemory"));
_variableComparePanel.add(Box.createHorizontalStrut(STRUT));
// Compare type
_variableCompareTypeBox = new JComboBox<String>();
for (int i = 0; i < Conditional.ITEM_TO_MEMORY_TEST.length; i++) {
_variableCompareTypeBox.addItem(ConditionalVariable.describeState(Conditional.ITEM_TO_MEMORY_TEST[i]));
}
_variableComparePanel.add(makeEditPanel(_variableCompareTypeBox, "LabelCompareType", "CompareTypeHint"));
_variableComparePanel.setVisible(false);
_variableCompareTypeBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
compareTypeChanged(_variableCompareTypeBox.getSelectedIndex());
_editVariableFrame.pack();
}
});
panel1.add(_variableComparePanel);
panel1.add(Box.createHorizontalStrut(STRUT));
// Data 1
_variableData1Field = new JTextField(30);
_variableData1Panel = makeEditPanel(_variableData1Field, "LabelStartTime", "DataHintTime");
_variableData1Panel.setMaximumSize(new Dimension(45, _variableData1Panel.getPreferredSize().height));
_variableData1Panel.setVisible(false);
panel1.add(_variableData1Panel);
panel1.add(Box.createHorizontalStrut(STRUT));
// Data 2
_variableData2Field = new JTextField(30);
_variableData2Panel = makeEditPanel(_variableData2Field, "LabelEndTime", "DataHintTime");
_variableData2Panel.setMaximumSize(new Dimension(45, _variableData2Panel.getPreferredSize().height));
_variableData2Panel.setVisible(false);
panel1.add(_variableData2Panel);
panel1.add(Box.createHorizontalStrut(STRUT));
panel1.add(Box.createHorizontalGlue());
topPanel.add(panel1);
ActionListener updateListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateVariablePressed();
}
};
ActionListener cancelListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelEditVariablePressed();
}
};
ActionListener deleteListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteVariablePressed();
}
};
JPanel panel = makeButtonPanel(updateListener, cancelListener, deleteListener);
topPanel.add(panel);
topPanel.add(Box.createVerticalGlue());
Container contentPane = _editVariableFrame.getContentPane();
contentPane.add(topPanel);
// note - this listener cannot be added before other action items
// have been created
_variableTypeBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
variableTypeChanged(_variableTypeBox.getSelectedIndex());
_editVariableFrame.pack();
}
});
// setup window closing listener
_editVariableFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
cancelEditVariablePressed();
}
});
initializeStateVariables();
_editVariableFrame.pack();
_editVariableFrame.setVisible(true);
}
Aggregations