use of jmri.util.table.ButtonRenderer in project JMRI by JMRI.
the class LocoDataModel method setColumnToHoldEStopButton.
void setColumnToHoldEStopButton(JTable slotTable, int column) {
TableColumnModel tcm = slotTable.getColumnModel();
// install the button renderers & editors in this column
ButtonRenderer buttonRenderer = new ButtonRenderer();
tcm.getColumn(column).setCellRenderer(buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton()) {
@Override
public void mousePressed(MouseEvent e) {
stopCellEditing();
}
};
tcm.getColumn(column).setCellEditor(buttonEditor);
// ensure the table rows, columns have enough room for buttons
slotTable.setRowHeight(new JButton(" " + getValueAt(1, column)).getPreferredSize().height);
slotTable.getColumnModel().getColumn(column).setPreferredWidth(new JButton(" " + getValueAt(1, column)).getPreferredSize().width);
}
use of jmri.util.table.ButtonRenderer in project JMRI by JMRI.
the class LocoDataModel method setColumnToHoldButton.
void setColumnToHoldButton(JTable slotTable, int column) {
TableColumnModel tcm = slotTable.getColumnModel();
// install the button renderers & editors in this column
ButtonRenderer buttonRenderer = new ButtonRenderer();
tcm.getColumn(column).setCellRenderer(buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
tcm.getColumn(column).setCellEditor(buttonEditor);
// ensure the table rows, columns have enough room for buttons
slotTable.setRowHeight(new JButton(" " + getValueAt(1, column)).getPreferredSize().height);
slotTable.getColumnModel().getColumn(column).setPreferredWidth(new JButton(" " + getValueAt(1, column)).getPreferredSize().width);
}
use of jmri.util.table.ButtonRenderer in project JMRI by JMRI.
the class LogixTableAction method makeEditLogixWindow.
/**
* Create and/or initialize the Edit Logix pane.
*/
void makeEditLogixWindow() {
// Setup the name box components.
setNameBoxListeners();
//if (log.isDebugEnabled()) log.debug("makeEditLogixWindow ");
editUserName.setText(_curLogix.getUserName());
// clear conditional table if needed
if (conditionalTableModel != null) {
conditionalTableModel.fireTableStructureChanged();
}
inEditMode = true;
if (editLogixFrame == null) {
editLogixFrame = new JmriJFrame(rbx.getString("TitleEditLogix"), false, false);
editLogixFrame.addHelpMenu("package.jmri.jmrit.beantable.LogixAddEdit", true);
editLogixFrame.setLocation(100, 30);
Container contentPane = editLogixFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
JLabel systemNameLabel = new JLabel(Bundle.getMessage("ColumnSystemName") + ":");
panel1.add(systemNameLabel);
JLabel fixedSystemName = new JLabel(_curLogix.getSystemName());
panel1.add(fixedSystemName);
contentPane.add(panel1);
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
JLabel userNameLabel = new JLabel(Bundle.getMessage("ColumnUserName") + ":");
panel2.add(userNameLabel);
panel2.add(editUserName);
editUserName.setToolTipText(rbx.getString("LogixUserNameHint2"));
contentPane.add(panel2);
// add table of Conditionals
JPanel pctSpace = new JPanel();
pctSpace.setLayout(new FlowLayout());
pctSpace.add(new JLabel(" "));
contentPane.add(pctSpace);
JPanel pTitle = new JPanel();
pTitle.setLayout(new FlowLayout());
pTitle.add(new JLabel(rbx.getString("ConditionalTableTitle")));
contentPane.add(pTitle);
// initialize table of conditionals
conditionalTableModel = new ConditionalTableModel();
JTable conditionalTable = new JTable(conditionalTableModel);
conditionalTable.setRowSelectionAllowed(false);
TableColumnModel conditionalColumnModel = conditionalTable.getColumnModel();
TableColumn sNameColumn = conditionalColumnModel.getColumn(ConditionalTableModel.SNAME_COLUMN);
sNameColumn.setResizable(true);
sNameColumn.setMinWidth(100);
sNameColumn.setPreferredWidth(130);
TableColumn uNameColumn = conditionalColumnModel.getColumn(ConditionalTableModel.UNAME_COLUMN);
uNameColumn.setResizable(true);
uNameColumn.setMinWidth(210);
uNameColumn.setPreferredWidth(260);
TableColumn stateColumn = conditionalColumnModel.getColumn(ConditionalTableModel.STATE_COLUMN);
stateColumn.setResizable(true);
stateColumn.setMinWidth(50);
stateColumn.setMaxWidth(100);
TableColumn buttonColumn = conditionalColumnModel.getColumn(ConditionalTableModel.BUTTON_COLUMN);
// install button renderer and editor
ButtonRenderer buttonRenderer = new ButtonRenderer();
conditionalTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
conditionalTable.setDefaultEditor(JButton.class, buttonEditor);
JButton testButton = new JButton("XXXXXX");
conditionalTable.setRowHeight(testButton.getPreferredSize().height);
buttonColumn.setMinWidth(testButton.getPreferredSize().width);
buttonColumn.setMaxWidth(testButton.getPreferredSize().width);
buttonColumn.setResizable(false);
JScrollPane conditionalTableScrollPane = new JScrollPane(conditionalTable);
Dimension dim = conditionalTable.getPreferredSize();
dim.height = 450;
conditionalTableScrollPane.getViewport().setPreferredSize(dim);
contentPane.add(conditionalTableScrollPane);
// add message area between table and buttons
JPanel panel4 = new JPanel();
panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
JPanel panel41 = new JPanel();
panel41.setLayout(new FlowLayout());
panel41.add(status);
panel4.add(panel41);
JPanel panel42 = new JPanel();
panel42.setLayout(new FlowLayout());
// Conditional panel buttons - New Conditional
JButton newConditionalButton = new JButton(rbx.getString("NewConditionalButton"));
panel42.add(newConditionalButton);
newConditionalButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
newConditionalPressed(e);
}
});
newConditionalButton.setToolTipText(rbx.getString("NewConditionalButtonHint"));
// Conditional panel buttons - Reorder
JButton reorderButton = new JButton(rbx.getString("ReorderButton"));
panel42.add(reorderButton);
reorderButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
reorderPressed(e);
}
});
reorderButton.setToolTipText(rbx.getString("ReorderButtonHint"));
// Conditional panel buttons - Calculate
JButton calculateButton = new JButton(rbx.getString("CalculateButton"));
panel42.add(calculateButton);
calculateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
calculatePressed(e);
}
});
calculateButton.setToolTipText(rbx.getString("CalculateButtonHint"));
panel4.add(panel42);
Border panel4Border = BorderFactory.createEtchedBorder();
panel4.setBorder(panel4Border);
contentPane.add(panel4);
// add buttons at bottom of window
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout());
// Bottom Buttons - Done Logix
JButton done = new JButton(Bundle.getMessage("ButtonDone"));
panel5.add(done);
done.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
donePressed(e);
}
});
done.setToolTipText(rbx.getString("DoneButtonHint"));
// Delete Logix
JButton delete = new JButton(Bundle.getMessage("ButtonDelete"));
panel5.add(delete);
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deletePressed(e);
}
});
delete.setToolTipText(rbx.getString("DeleteLogixButtonHint"));
contentPane.add(panel5);
}
editLogixFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
if (inEditMode) {
donePressed(null);
} else {
finishDone();
}
}
});
editLogixFrame.pack();
editLogixFrame.setVisible(true);
}
use of jmri.util.table.ButtonRenderer in project JMRI by JMRI.
the class SignalGroupTableAction method setColumnToHoldButton.
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 jmri.util.table.ButtonRenderer in project JMRI by JMRI.
the class TableFrames method makeBlockFrame.
/*
* ********************* BlockFrame *****************************
*/
protected JInternalFrame makeBlockFrame() {
JInternalFrame frame = new JInternalFrame(Bundle.getMessage("TitleBlockTable"), true, false, false, true);
_oBlockModel = new OBlockTableModel(this);
_oBlockTable = new JTable(_oBlockModel);
TableRowSorter<OBlockTableModel> sorter = new TableRowSorter<>(_oBlockModel);
sorter.setComparator(OBlockTableModel.SYSNAMECOL, new jmri.util.SystemNameComparator());
_oBlockTable.setRowSorter(sorter);
_oBlockTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { OBlockTableModel.EDIT_COL, OBlockTableModel.DELETE_COL, OBlockTableModel.REPORT_CURRENTCOL, OBlockTableModel.SPEEDCOL, OBlockTableModel.PERMISSIONCOL, OBlockTableModel.UNITSCOL }));
_oBlockTable.setDragEnabled(true);
// Use XTableColumnModel so we can control which columns are visible
XTableColumnModel tcm = new XTableColumnModel();
_oBlockTable.setColumnModel(tcm);
_oBlockTable.getTableHeader().setReorderingAllowed(true);
_oBlockTable.createDefaultColumnsFromModel();
_oBlockModel.addHeaderListener(_oBlockTable);
_oBlockTable.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.EDIT_COL).setCellEditor(new ButtonEditor(new JButton()));
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.EDIT_COL).setCellRenderer(new ButtonRenderer());
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.UNITSCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("cm"), Bundle.getMessage("in")));
JComboBox<String> box = new JComboBox<String>(OBlockTableModel.curveOptions);
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.CURVECOL).setCellEditor(new DefaultCellEditor(box));
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.REPORT_CURRENTCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("Current"), Bundle.getMessage("Last")));
box = new JComboBox<String>(jmri.InstanceManager.getDefault(SignalSpeedMap.class).getValidSpeedNames());
box.addItem("");
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.SPEEDCOL).setCellEditor(new DefaultCellEditor(box));
_oBlockTable.getColumnModel().getColumn(OBlockTableModel.PERMISSIONCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("Permissive"), Bundle.getMessage("Absolute")));
_oBlockTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
showPopup(me);
}
@Override
public void mouseReleased(MouseEvent me) {
showPopup(me);
}
});
for (int i = 0; i < _oBlockModel.getColumnCount(); i++) {
int width = _oBlockModel.getPreferredWidth(i);
_oBlockTable.getColumnModel().getColumn(i).setPreferredWidth(width);
}
_oBlockTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
ROW_HEIGHT = _oBlockTable.getRowHeight();
int tableWidth = _desktop.getPreferredSize().width;
_oBlockTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 10));
_blockTablePane = new JScrollPane(_oBlockTable);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.REPORTERCOL), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.REPORT_CURRENTCOL), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.PERMISSIONCOL), false);
// tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.SPEEDCOL), false);
// tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.ERR_SENSORCOL), false);
tcm.setColumnVisible(tcm.getColumnByModelIndex(OBlockTableModel.CURVECOL), false);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(5, 5));
JLabel prompt = new JLabel(Bundle.getMessage("AddBlockPrompt"));
contentPane.add(prompt, BorderLayout.NORTH);
contentPane.add(_blockTablePane, BorderLayout.CENTER);
frame.setContentPane(contentPane);
frame.pack();
return frame;
}
Aggregations