use of javax.swing.table.TableCellEditor in project JMRI by JMRI.
the class LightTableAction method addPressed.
@Override
protected void addPressed(ActionEvent e) {
if (inEditMode) {
// cancel Edit and reactivate the edited light
cancelPressed(null);
}
if (addFrame == null) {
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddLight"), false, true);
addFrame.addHelpMenu("package.jmri.jmrit.beantable.LightAddEdit", true);
addFrame.setLocation(100, 30);
Container contentPane = addFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
initializePrefixCombo();
panel1.add(systemLabel);
panel1.add(prefixBox);
panel1.add(new JLabel(" "));
panel1.add(addRangeBox);
addRangeBox.setToolTipText(Bundle.getMessage("LightAddRangeHint"));
addRangeBox.addActionListener((ActionEvent e1) -> {
addRangeChanged();
});
panel1.add(systemNameLabel);
systemNameLabel.setVisible(false);
panel1.add(fixedSystemName);
fixedSystemName.setVisible(false);
prefixBox.setToolTipText(Bundle.getMessage("LightSystemHint"));
prefixBox.addActionListener((ActionEvent e1) -> {
prefixChanged();
});
contentPane.add(panel1);
panel1a = new JPanel();
panel1a.setLayout(new FlowLayout());
panel1a.add(new JLabel(Bundle.getMessage("LabelHardwareAddress")));
panel1a.add(fieldHardwareAddress);
fieldHardwareAddress.setToolTipText(Bundle.getMessage("LightHardwareAddressHint"));
panel1a.add(labelNumToAdd);
panel1a.add(fieldNumToAdd);
fieldNumToAdd.setToolTipText(Bundle.getMessage("LightNumberToAddHint"));
contentPane.add(panel1a);
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
panel2.add(userNameLabel);
panel2.add(userName);
userName.setToolTipText(Bundle.getMessage("LightUserNameHint"));
contentPane.add(panel2);
// items for variable intensity lights
varPanel = new JPanel();
varPanel.setLayout(new BoxLayout(varPanel, BoxLayout.X_AXIS));
varPanel.add(new JLabel(" "));
varPanel.add(labelMinIntensity);
fieldMinIntensity.setToolTipText(Bundle.getMessage("LightMinIntensityHint"));
fieldMinIntensity.setHorizontalAlignment(JTextField.RIGHT);
fieldMinIntensity.setText(" 0");
varPanel.add(fieldMinIntensity);
varPanel.add(labelMinIntensityTail);
varPanel.add(labelMaxIntensity);
fieldMaxIntensity.setToolTipText(Bundle.getMessage("LightMaxIntensityHint"));
fieldMaxIntensity.setHorizontalAlignment(JTextField.RIGHT);
fieldMaxIntensity.setText("100");
varPanel.add(fieldMaxIntensity);
varPanel.add(labelMaxIntensityTail);
varPanel.add(labelTransitionTime);
fieldTransitionTime.setToolTipText(Bundle.getMessage("LightTransitionTimeHint"));
fieldTransitionTime.setHorizontalAlignment(JTextField.RIGHT);
fieldTransitionTime.setText("0");
varPanel.add(fieldTransitionTime);
varPanel.add(new JLabel(" "));
Border varPanelBorder = BorderFactory.createEtchedBorder();
Border varPanelTitled = BorderFactory.createTitledBorder(varPanelBorder, Bundle.getMessage("LightVariableBorder"));
varPanel.setBorder(varPanelTitled);
contentPane.add(varPanel);
// light control table
JPanel panel3 = new JPanel();
panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
JPanel panel31 = new JPanel();
lightControlTableModel = new LightControlTableModel();
JTable lightControlTable = new JTable(lightControlTableModel);
lightControlTable.setRowSelectionAllowed(false);
lightControlTable.setPreferredScrollableViewportSize(new java.awt.Dimension(550, 100));
TableColumnModel lightControlColumnModel = lightControlTable.getColumnModel();
TableColumn typeColumn = lightControlColumnModel.getColumn(LightControlTableModel.TYPE_COLUMN);
typeColumn.setResizable(true);
typeColumn.setMinWidth(110);
typeColumn.setMaxWidth(150);
TableColumn descriptionColumn = lightControlColumnModel.getColumn(LightControlTableModel.DESCRIPTION_COLUMN);
descriptionColumn.setResizable(true);
descriptionColumn.setMinWidth(270);
descriptionColumn.setMaxWidth(340);
ButtonRenderer buttonRenderer = new ButtonRenderer();
lightControlTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
lightControlTable.setDefaultEditor(JButton.class, buttonEditor);
JButton testButton = new JButton(Bundle.getMessage("ButtonDelete"));
lightControlTable.setRowHeight(testButton.getPreferredSize().height);
TableColumn editColumn = lightControlColumnModel.getColumn(LightControlTableModel.EDIT_COLUMN);
editColumn.setResizable(false);
editColumn.setMinWidth(testButton.getPreferredSize().width);
TableColumn removeColumn = lightControlColumnModel.getColumn(LightControlTableModel.REMOVE_COLUMN);
removeColumn.setResizable(false);
removeColumn.setMinWidth(testButton.getPreferredSize().width);
JScrollPane lightControlTableScrollPane = new JScrollPane(lightControlTable);
panel31.add(lightControlTableScrollPane, BorderLayout.CENTER);
panel3.add(panel31);
JPanel panel35 = new JPanel();
panel35.setLayout(new FlowLayout());
panel35.add(addControl = new JButton(Bundle.getMessage("LightAddControlButton")));
addControl.addActionListener(this::addControlPressed);
addControl.setToolTipText(Bundle.getMessage("LightAddControlButtonHint"));
panel3.add(panel35);
Border panel3Border = BorderFactory.createEtchedBorder();
Border panel3Titled = BorderFactory.createTitledBorder(panel3Border, Bundle.getMessage("LightControlBorder"));
panel3.setBorder(panel3Titled);
contentPane.add(panel3);
// message items
JPanel panel4 = new JPanel();
panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
JPanel panel41 = new JPanel();
panel41.setLayout(new FlowLayout());
panel41.add(status1);
status1.setText(Bundle.getMessage("LightCreateInst"));
JPanel panel42 = new JPanel();
panel42.setLayout(new FlowLayout());
panel42.add(status2);
status2.setText("");
status2.setVisible(false);
panel4.add(panel41);
panel4.add(panel42);
Border panel4Border = BorderFactory.createEtchedBorder();
panel4.setBorder(panel4Border);
contentPane.add(panel4);
// buttons at bottom of window
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout(FlowLayout.TRAILING));
panel5.add(cancel = new JButton(Bundle.getMessage("ButtonCancel")));
cancel.addActionListener(this::cancelPressed);
cancel.setToolTipText(Bundle.getMessage("LightCancelButtonHint"));
panel5.add(create = new JButton(Bundle.getMessage("ButtonCreate")));
create.addActionListener(this::createPressed);
create.setToolTipText(Bundle.getMessage("LightCreateButtonHint"));
panel5.add(update = new JButton(Bundle.getMessage("ButtonUpdate")));
update.addActionListener(this::updatePressed);
update.setToolTipText(Bundle.getMessage("LightUpdateButtonHint"));
cancel.setVisible(true);
create.setVisible(true);
update.setVisible(false);
contentPane.add(panel5);
}
prefixChanged();
addFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
cancelPressed(null);
}
});
addFrame.pack();
addFrame.setVisible(true);
}
use of javax.swing.table.TableCellEditor in project JMRI by JMRI.
the class LocationTrackBlockingOrderTableModel method initTable.
private void initTable() {
// Use XTableColumnModel so we can control which columns are visible
XTableColumnModel tcm = new XTableColumnModel();
_table.setColumnModel(tcm);
_table.createDefaultColumnsFromModel();
ButtonRenderer buttonRenderer = new ButtonRenderer();
TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
tcm.getColumn(UP_COLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(UP_COLUMN).setCellEditor(buttonEditor);
tcm.getColumn(DOWN_COLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(DOWN_COLUMN).setCellEditor(buttonEditor);
// set column preferred widths
tcm.getColumn(ID_COLUMN).setPreferredWidth(40);
tcm.getColumn(NAME_COLUMN).setPreferredWidth(200);
tcm.getColumn(TYPE_COLUMN).setPreferredWidth(80);
tcm.getColumn(ORDER_COLUMN).setPreferredWidth(60);
tcm.getColumn(UP_COLUMN).setPreferredWidth(60);
tcm.getColumn(DOWN_COLUMN).setPreferredWidth(70);
}
use of javax.swing.table.TableCellEditor in project JMRI by JMRI.
the class BeanTableDataModel method setColumnToHoldButton.
/**
* Service method to setup a column so that it will hold a button for it's
* values
*
* @param table {@link JTable} to use
* @param column Column to setup
* @param sample Typical button, used for size
*/
protected void setColumnToHoldButton(JTable table, int column, JButton sample) {
// install a button renderer & editor
ButtonRenderer buttonRenderer = new ButtonRenderer();
table.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
table.setDefaultEditor(JButton.class, buttonEditor);
// ensure the table rows, columns have enough room for buttons
table.setRowHeight(sample.getPreferredSize().height);
table.getColumnModel().getColumn(column).setPreferredWidth((sample.getPreferredSize().width) + 4);
}
use of javax.swing.table.TableCellEditor 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 javax.swing.table.TableCellEditor in project JMRI by JMRI.
the class TransitTableAction method addEditActionsPressed.
private void addEditActionsPressed(int r) {
activeRow = r;
if (actionTableModel != null) {
actionTableModel.fireTableStructureChanged();
}
if (actionTableFrame == null) {
actionTableFrame = new JmriJFrame(rbx.getString("TitleViewActions"));
actionTableFrame.addHelpMenu("package.jmri.jmrit.beantable.ViewSpecialActions", true);
actionTableFrame.setLocation(50, 60);
Container contentPane = actionTableFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
JLabel sectionNameLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanNameSection")));
panel1.add(sectionNameLabel);
panel1.add(fixedSectionLabel);
contentPane.add(panel1);
// add table of Actions
JPanel pctSpace = new JPanel();
pctSpace.setLayout(new FlowLayout());
pctSpace.add(new JLabel(" "));
contentPane.add(pctSpace);
JPanel pct = new JPanel();
// initialize table of actions
actionTableModel = new SpecialActionTableModel();
JTable actionTable = new JTable(actionTableModel);
actionTable.setRowSelectionAllowed(false);
actionTable.setPreferredScrollableViewportSize(new java.awt.Dimension(750, 200));
TableColumnModel actionColumnModel = actionTable.getColumnModel();
TableColumn whenColumn = actionColumnModel.getColumn(SpecialActionTableModel.WHEN_COLUMN);
whenColumn.setResizable(true);
whenColumn.setMinWidth(270);
whenColumn.setMaxWidth(300);
TableColumn whatColumn = actionColumnModel.getColumn(SpecialActionTableModel.WHAT_COLUMN);
whatColumn.setResizable(true);
whatColumn.setMinWidth(290);
whatColumn.setMaxWidth(350);
TableColumn editColumn = actionColumnModel.getColumn(SpecialActionTableModel.EDIT_COLUMN);
// install button renderer and editor
ButtonRenderer buttonRenderer = new ButtonRenderer();
actionTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
actionTable.setDefaultEditor(JButton.class, buttonEditor);
JButton testButton = new JButton(Bundle.getMessage("ButtonDelete"));
actionTable.setRowHeight(testButton.getPreferredSize().height);
editColumn.setResizable(false);
editColumn.setMinWidth(testButton.getPreferredSize().width);
TableColumn removeColumn = actionColumnModel.getColumn(SpecialActionTableModel.REMOVE_COLUMN);
removeColumn.setMinWidth(testButton.getPreferredSize().width);
removeColumn.setResizable(false);
JScrollPane actionTableScrollPane = new JScrollPane(actionTable);
pct.add(actionTableScrollPane, BorderLayout.CENTER);
contentPane.add(pct);
pct.setVisible(true);
// add view action panel buttons
JPanel but = new JPanel();
but.setLayout(new BoxLayout(but, BoxLayout.Y_AXIS));
JPanel panel4 = new JPanel();
panel4.setLayout(new FlowLayout());
JButton newActionButton = new JButton(rbx.getString("ButtonAddNewAction"));
panel4.add(newActionButton);
newActionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
newActionPressed(e);
}
});
newActionButton.setToolTipText(rbx.getString("NewActionButtonHint"));
JButton doneButton = new JButton(Bundle.getMessage("ButtonDone"));
panel4.add(doneButton);
doneButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doneWithActionsPressed(e);
}
});
doneButton.setToolTipText(rbx.getString("DoneButtonHint"));
but.add(panel4);
contentPane.add(but);
}
fixedSectionLabel.setText(getSectionNameByRow(r) + " " + rbx.getString("SequenceAbbrev") + ": " + sequence[r]);
actionTableFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
if (actionTableFrame != null) {
actionTableFrame.setVisible(false);
actionTableFrame.dispose();
actionTableFrame = null;
}
if (addEditActionFrame != null) {
addEditActionFrame.setVisible(false);
addEditActionFrame.dispose();
addEditActionFrame = null;
}
}
});
actionTableFrame.pack();
actionTableFrame.setVisible(true);
}
Aggregations