use of javax.swing.table.TableColumnModel in project JMRI by JMRI.
the class AutomationTableModel method initTable.
private void initTable(JTable table) {
// Install the button handlers
TableColumnModel tcm = table.getColumnModel();
ButtonRenderer buttonRenderer = new ButtonRenderer();
TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
tcm.getColumn(MESSAGE_COLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(MESSAGE_COLUMN).setCellEditor(buttonEditor);
tcm.getColumn(UP_COLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(UP_COLUMN).setCellEditor(buttonEditor);
tcm.getColumn(DOWN_COLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(DOWN_COLUMN).setCellEditor(buttonEditor);
tcm.getColumn(DELETE_COLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(DELETE_COLUMN).setCellEditor(buttonEditor);
table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
// set column preferred widths
table.getColumnModel().getColumn(ID_COLUMN).setPreferredWidth(35);
table.getColumnModel().getColumn(CURRENT_COLUMN).setPreferredWidth(60);
table.getColumnModel().getColumn(ACTION_COLUMN).setPreferredWidth(200);
table.getColumnModel().getColumn(TRAIN_COLUMN).setPreferredWidth(200);
table.getColumnModel().getColumn(ROUTE_COLUMN).setPreferredWidth(200);
table.getColumnModel().getColumn(AUTOMATION_COLUMN).setPreferredWidth(200);
table.getColumnModel().getColumn(STATUS_COLUMN).setPreferredWidth(70);
table.getColumnModel().getColumn(HIAF_COLUMN).setPreferredWidth(50);
table.getColumnModel().getColumn(MESSAGE_COLUMN).setPreferredWidth(70);
table.getColumnModel().getColumn(UP_COLUMN).setPreferredWidth(60);
table.getColumnModel().getColumn(DOWN_COLUMN).setPreferredWidth(70);
table.getColumnModel().getColumn(DELETE_COLUMN).setPreferredWidth(70);
_frame.loadTableDetails(table);
// does not use a table sorter
table.setRowSorter(null);
updateList();
}
use of javax.swing.table.TableColumnModel in project JMRI by JMRI.
the class NceShowCabPanel method setColumnToHoldButton.
void setColumnToHoldButton(JTable table, int column) {
TableColumnModel tcm = table.getColumnModel();
// install the button renderers & editors in this column
ButtonRenderer buttonRenderer = new ButtonRenderer();
tcm.getColumn(column).setCellRenderer(buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton(rb.getString("ButtonPurgeCab")));
tcm.getColumn(column).setCellEditor(buttonEditor);
// ensure the table rows, columns have enough room for buttons
table.setRowHeight(new JButton(" " + cabModel.getValueAt(1, column)).getPreferredSize().height);
table.getColumnModel().getColumn(column).setPreferredWidth(new JButton(rb.getString("ButtonPurgeCab")).getPreferredSize().width + 1);
}
use of javax.swing.table.TableColumnModel in project JMRI by JMRI.
the class RouteTableAction method addPressed.
@Override
protected void addPressed(ActionEvent e) {
pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
if (editMode) {
cancelEdit();
}
jmri.TurnoutManager tm = InstanceManager.turnoutManagerInstance();
List<String> systemNameList = tm.getSystemNameList();
_turnoutList = new ArrayList<>(systemNameList.size());
Iterator<String> iter = systemNameList.iterator();
while (iter.hasNext()) {
String systemName = iter.next();
String userName = tm.getBySystemName(systemName).getUserName();
_turnoutList.add(new RouteTurnout(systemName, userName));
}
jmri.SensorManager sm = InstanceManager.sensorManagerInstance();
systemNameList = sm.getSystemNameList();
_sensorList = new ArrayList<>(systemNameList.size());
iter = systemNameList.iterator();
while (iter.hasNext()) {
String systemName = iter.next();
Sensor s = sm.getBySystemName(systemName);
if (s != null) {
String userName = s.getUserName();
_sensorList.add(new RouteSensor(systemName, userName));
} else {
log.error("Failed to get sensor {}", systemName);
}
}
initializeIncludedList();
// Set up window
if (addFrame == null) {
turnoutsAlignedSensor = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
sensor1 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
sensor2 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
sensor3 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
cTurnout = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance());
cLockTurnout = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance());
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddRoute"), false, true);
addFrame.addHelpMenu("package.jmri.jmrit.beantable.RouteAddEdit", true);
addFrame.setLocation(100, 30);
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
// add system name
JPanel ps = new JPanel();
ps.setLayout(new FlowLayout());
ps.add(nameLabel);
ps.add(_systemName);
ps.add(_autoSystemName);
_autoSystemName.addActionListener((ActionEvent e1) -> {
autoSystemName();
});
if (pref.getSimplePreferenceState(systemNameAuto)) {
_autoSystemName.setSelected(true);
}
_systemName.setToolTipText(Bundle.getMessage("TooltipRouteSystemName"));
ps.add(fixedSystemName);
fixedSystemName.setVisible(false);
contentPanel.add(ps);
// add user name
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(userLabel);
p.add(_userName);
_userName.setToolTipText(Bundle.getMessage("TooltipRouteUserName"));
contentPanel.add(p);
// add Turnout Display Choice
JPanel py = new JPanel();
py.add(new JLabel(Bundle.getMessage("Show") + ":"));
selGroup = new ButtonGroup();
allButton = new JRadioButton(Bundle.getMessage("All"), true);
selGroup.add(allButton);
py.add(allButton);
allButton.addActionListener((ActionEvent e1) -> {
// Setup for display of all Turnouts, if needed
if (!showAll) {
showAll = true;
_routeTurnoutModel.fireTableDataChanged();
_routeSensorModel.fireTableDataChanged();
}
});
includedButton = new JRadioButton(Bundle.getMessage("Included"), false);
selGroup.add(includedButton);
py.add(includedButton);
includedButton.addActionListener((ActionEvent e1) -> {
// Setup for display of included Turnouts only, if needed
if (showAll) {
showAll = false;
initializeIncludedList();
_routeTurnoutModel.fireTableDataChanged();
_routeSensorModel.fireTableDataChanged();
}
});
py.add(new JLabel(Bundle.getMessage("_and_", Bundle.getMessage("Turnouts"), Bundle.getMessage("Sensors"))));
// keys are in jmri.jmrit.Bundle
contentPanel.add(py);
// add Turnout table
p2xt = new JPanel();
JPanel p2xtSpace = new JPanel();
p2xtSpace.setLayout(new BoxLayout(p2xtSpace, BoxLayout.Y_AXIS));
p2xtSpace.add(new JLabel("XXX"));
p2xt.add(p2xtSpace);
JPanel p21t = new JPanel();
p21t.setLayout(new BoxLayout(p21t, BoxLayout.Y_AXIS));
p21t.add(new JLabel(Bundle.getMessage("SelectInRoute", Bundle.getMessage("Turnouts"))));
p2xt.add(p21t);
_routeTurnoutModel = new RouteTurnoutModel();
JTable routeTurnoutTable = new JTable(_routeTurnoutModel);
TableRowSorter<RouteTurnoutModel> rtSorter = new TableRowSorter<>(_routeTurnoutModel);
rtSorter.setComparator(RouteTurnoutModel.SNAME_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(rtSorter, RouteTurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
routeTurnoutTable.setRowSorter(rtSorter);
routeTurnoutTable.setRowSelectionAllowed(false);
routeTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
ROW_HEIGHT = routeTurnoutTable.getRowHeight();
JComboBox<String> stateTCombo = new JComboBox<>();
stateTCombo.addItem(SET_TO_CLOSED);
stateTCombo.addItem(SET_TO_THROWN);
stateTCombo.addItem(SET_TO_TOGGLE);
TableColumnModel routeTurnoutColumnModel = routeTurnoutTable.getColumnModel();
TableColumn includeColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.INCLUDE_COLUMN);
includeColumnT.setResizable(false);
includeColumnT.setMinWidth(50);
includeColumnT.setMaxWidth(60);
TableColumn sNameColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.SNAME_COLUMN);
sNameColumnT.setResizable(true);
sNameColumnT.setMinWidth(75);
sNameColumnT.setMaxWidth(95);
TableColumn uNameColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.UNAME_COLUMN);
uNameColumnT.setResizable(true);
uNameColumnT.setMinWidth(210);
uNameColumnT.setMaxWidth(260);
TableColumn stateColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.STATE_COLUMN);
stateColumnT.setCellEditor(new DefaultCellEditor(stateTCombo));
stateColumnT.setResizable(false);
stateColumnT.setMinWidth(90);
stateColumnT.setMaxWidth(100);
_routeTurnoutScrollPane = new JScrollPane(routeTurnoutTable);
p2xt.add(_routeTurnoutScrollPane, BorderLayout.CENTER);
contentPanel.add(p2xt);
p2xt.setVisible(true);
// add Sensor table
p2xs = new JPanel();
JPanel p2xsSpace = new JPanel();
p2xsSpace.setLayout(new BoxLayout(p2xsSpace, BoxLayout.Y_AXIS));
p2xsSpace.add(new JLabel("XXX"));
p2xs.add(p2xsSpace);
JPanel p21s = new JPanel();
p21s.setLayout(new BoxLayout(p21s, BoxLayout.Y_AXIS));
p21s.add(new JLabel(Bundle.getMessage("SelectInRoute", Bundle.getMessage("Sensors"))));
p2xs.add(p21s);
_routeSensorModel = new RouteSensorModel();
JTable routeSensorTable = new JTable(_routeSensorModel);
TableRowSorter<RouteSensorModel> rsSorter = new TableRowSorter<>(_routeSensorModel);
rsSorter.setComparator(RouteSensorModel.SNAME_COLUMN, new SystemNameComparator());
RowSorterUtil.setSortOrder(rsSorter, RouteSensorModel.SNAME_COLUMN, SortOrder.ASCENDING);
routeSensorTable.setRowSorter(rsSorter);
routeSensorTable.setRowSelectionAllowed(false);
routeSensorTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
JComboBox<String> stateSCombo = new JComboBox<>();
stateSCombo.addItem(SET_TO_ACTIVE);
stateSCombo.addItem(SET_TO_INACTIVE);
stateSCombo.addItem(SET_TO_TOGGLE);
TableColumnModel routeSensorColumnModel = routeSensorTable.getColumnModel();
TableColumn includeColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.INCLUDE_COLUMN);
includeColumnS.setResizable(false);
includeColumnS.setMinWidth(50);
includeColumnS.setMaxWidth(60);
TableColumn sNameColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.SNAME_COLUMN);
sNameColumnS.setResizable(true);
sNameColumnS.setMinWidth(75);
sNameColumnS.setMaxWidth(95);
TableColumn uNameColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.UNAME_COLUMN);
uNameColumnS.setResizable(true);
uNameColumnS.setMinWidth(210);
uNameColumnS.setMaxWidth(260);
TableColumn stateColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.STATE_COLUMN);
stateColumnS.setCellEditor(new DefaultCellEditor(stateSCombo));
stateColumnS.setResizable(false);
stateColumnS.setMinWidth(90);
stateColumnS.setMaxWidth(100);
_routeSensorScrollPane = new JScrollPane(routeSensorTable);
p2xs.add(_routeSensorScrollPane, BorderLayout.CENTER);
contentPanel.add(p2xs);
p2xs.setVisible(true);
// Enter filenames for sound, script
JPanel p25 = new JPanel();
p25.setLayout(new FlowLayout());
p25.add(new JLabel(Bundle.getMessage("LabelPlaySound")));
p25.add(soundFile);
//NO18N
JButton ss = new JButton("...");
ss.addActionListener((ActionEvent e1) -> {
setSoundPressed();
});
ss.setToolTipText(Bundle.getMessage("TooltipOpenFile", Bundle.getMessage("BeanNameAudio")));
p25.add(ss);
p25.add(new JLabel(Bundle.getMessage("LabelRunScript")));
p25.add(scriptFile);
//NO18N
ss = new JButton("...");
ss.addActionListener((ActionEvent e1) -> {
setScriptPressed();
});
ss.setToolTipText(Bundle.getMessage("TooltipOpenFile", Bundle.getMessage("Script")));
p25.add(ss);
contentPanel.add(p25);
//add turnouts aligned Sensor
JPanel p27 = new JPanel();
p27.setLayout(new FlowLayout());
p27.add(new JLabel(Bundle.getMessage("LabelEnterSensorAligned")));
p27.add(turnoutsAlignedSensor);
turnoutsAlignedSensor.setFirstItemBlank(true);
turnoutsAlignedSensor.setSelectedBean(null);
turnoutsAlignedSensor.setToolTipText(Bundle.getMessage("TooltipEnterSensor"));
contentPanel.add(p27);
// add Control Sensor table
JPanel p3 = new JPanel();
p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
JPanel p31 = new JPanel();
p31.add(new JLabel(Bundle.getMessage("LabelEnterSensors")));
p3.add(p31);
JPanel p32 = new JPanel();
//Sensor 1
JPanel pS = new JPanel();
pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 1"));
pS.add(sensor1);
pS.add(sensor1mode);
p32.add(pS);
//Sensor 2
pS = new JPanel();
pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 2"));
pS.add(sensor2);
pS.add(sensor2mode);
p32.add(pS);
//Sensor 3
pS = new JPanel();
pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 3"));
pS.add(sensor3);
pS.add(sensor3mode);
p32.add(pS);
sensor1.setFirstItemBlank(true);
sensor2.setFirstItemBlank(true);
sensor3.setFirstItemBlank(true);
sensor1.setSelectedBean(null);
sensor2.setSelectedBean(null);
sensor3.setSelectedBean(null);
String sensorHint = Bundle.getMessage("TooltipEnterSensors");
sensor1.setToolTipText(sensorHint);
sensor2.setToolTipText(sensorHint);
sensor3.setToolTipText(sensorHint);
p3.add(p32);
// add control turnout
JPanel p33 = new JPanel();
p33.add(new JLabel(Bundle.getMessage("LabelEnterTurnout")));
p3.add(p33);
JPanel p34 = new JPanel();
p34.add(new JLabel(Bundle.getMessage("BeanNameTurnout") + ":"));
p34.add(cTurnout);
cTurnout.setFirstItemBlank(true);
cTurnout.setSelectedBean(null);
cTurnout.setToolTipText(Bundle.getMessage("TooltipEnterTurnout"));
p34.add(new JLabel(" " + Bundle.getMessage("LabelCondition") + ":"));
cTurnoutStateBox.setToolTipText(Bundle.getMessage("TooltipTurnoutCondition"));
p34.add(cTurnoutStateBox);
p3.add(p34);
// add added delay
JPanel p36 = new JPanel();
p36.add(new JLabel(Bundle.getMessage("LabelTurnoutDelay") + ":"));
p36.add(timeDelay);
timeDelay.setText("0");
timeDelay.setToolTipText(Bundle.getMessage("TooltipTurnoutDelay"));
p36.add(new JLabel(" " + Bundle.getMessage("LabelMilliseconds")));
p3.add(p36);
// complete this panel
Border p3Border = BorderFactory.createEtchedBorder();
p3.setBorder(p3Border);
contentPanel.add(p3);
// add lock control table
JPanel p4 = new JPanel();
p4.setLayout(new BoxLayout(p4, BoxLayout.Y_AXIS));
// add lock control turnout
JPanel p43 = new JPanel();
p43.add(new JLabel(Bundle.getMessage("LabelLockTurnout")));
p4.add(p43);
JPanel p44 = new JPanel();
p44.add(new JLabel(Bundle.getMessage("BeanNameTurnout") + ":"));
p44.add(cLockTurnout);
cLockTurnout.setFirstItemBlank(true);
cLockTurnout.setSelectedBean(null);
cLockTurnout.setToolTipText(Bundle.getMessage("TooltipEnterTurnout"));
p44.add(new JLabel(" " + Bundle.getMessage("LabelCondition") + ":"));
cLockTurnoutStateBox.setToolTipText(Bundle.getMessage("TooltipLockTurnout"));
p44.add(cLockTurnoutStateBox);
p4.add(p44);
// complete this panel
Border p4Border = BorderFactory.createEtchedBorder();
p4.setBorder(p4Border);
contentPanel.add(p4);
// add notes panel
JPanel pa = new JPanel();
pa.setLayout(new BoxLayout(pa, BoxLayout.Y_AXIS));
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(status1);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(status2);
pa.add(p1);
pa.add(p2);
Border pBorder = BorderFactory.createEtchedBorder();
pa.setBorder(pBorder);
contentPanel.add(pa);
// add Buttons panel
JPanel pb = new JPanel();
pb.setLayout(new FlowLayout(FlowLayout.TRAILING));
// Cancel (Add) button
pb.add(cancelButton);
cancelButton.addActionListener(this::cancelAddPressed);
// CancelEdit button
pb.add(cancelEditButton);
cancelEditButton.addActionListener(this::cancelPressed);
cancelEditButton.setToolTipText(Bundle.getMessage("TooltipCancelRoute"));
// Add Create Route button
pb.add(createButton);
createButton.addActionListener(this::createPressed);
createButton.setToolTipText(Bundle.getMessage("TooltipCreateRoute"));
// Edit Route button
pb.add(editButton);
editButton.addActionListener(this::editPressed);
editButton.setToolTipText(Bundle.getMessage("TooltipEditRoute"));
// Delete Route button
pb.add(deleteButton);
deleteButton.addActionListener(this::deletePressed);
deleteButton.setToolTipText(Bundle.getMessage("TooltipDeleteRoute"));
// Update Route button
pb.add(updateButton);
updateButton.addActionListener((ActionEvent e1) -> {
updatePressed(e1, false);
});
updateButton.setToolTipText(Bundle.getMessage("TooltipUpdateRoute"));
// Export button
pb.add(exportButton);
exportButton.addActionListener(this::exportPressed);
exportButton.setToolTipText(Bundle.getMessage("TooltipExportRoute"));
// Show the initial buttons, and hide the others
exportButton.setVisible(false);
// show CancelAdd button
cancelButton.setVisible(true);
cancelEditButton.setVisible(false);
updateButton.setVisible(true);
editButton.setVisible(true);
createButton.setVisible(true);
deleteButton.setVisible(false);
contentPanel.add(pb);
addFrame.getContentPane().add(new JScrollPane(contentPanel), BorderLayout.CENTER);
// pack and release space
addFrame.pack();
p2xsSpace.setVisible(false);
p2xtSpace.setVisible(false);
}
// set listener for window closing
addFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
// remind to save, if Route was created or edited
if (routeDirty) {
InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ReminderTitle"), Bundle.getMessage("ReminderSaveString", Bundle.getMessage("MenuItemRouteTable")), getClassName(), //NOI18N
"remindSaveRoute");
routeDirty = false;
}
// hide addFrame
if (addFrame != null) {
addFrame.setVisible(false);
// addFrame.dispose(); // causes multiple empty Routes next time
}
// if in Edit, cancel edit mode
if (editMode) {
cancelEdit();
}
_routeSensorModel.dispose();
_routeTurnoutModel.dispose();
}
});
// display the window
addFrame.setVisible(true);
autoSystemName();
}
use of javax.swing.table.TableColumnModel in project JMRI by JMRI.
the class TransitTableAction method addEditPressed.
void addEditPressed() {
pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
if (addFrame == null) {
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddTransit"));
addFrame.addHelpMenu("package.jmri.jmrit.beantable.TransitAddEdit", true);
addFrame.getContentPane().setLayout(new BoxLayout(addFrame.getContentPane(), BoxLayout.Y_AXIS));
JPanel p;
p = new JPanel();
p.setLayout(new FlowLayout());
p.add(sysNameLabel);
p.add(sysNameFixed);
p.add(sysName);
sysName.setToolTipText(rbx.getString("TransitSystemNameHint"));
p.add(new JLabel(" "));
p.add(userNameLabel);
p.add(userName);
userName.setToolTipText(rbx.getString("TransitUserNameHint"));
addFrame.getContentPane().add(p);
p = new JPanel();
((FlowLayout) p.getLayout()).setVgap(0);
p.add(_autoSystemName);
_autoSystemName.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
autoSystemName();
}
});
if (pref.getSimplePreferenceState(systemNameAuto)) {
_autoSystemName.setSelected(true);
}
addFrame.getContentPane().add(p);
addFrame.getContentPane().add(new JSeparator());
JPanel p1 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
JPanel p11 = new JPanel();
p11.setLayout(new FlowLayout());
p11.add(new JLabel(rbx.getString("SectionTableMessage")));
p1.add(p11);
JPanel p12 = new JPanel();
// initialize table of sections
sectionTableModel = new SectionTableModel();
JTable sectionTable = new JTable(sectionTableModel);
sectionTable.setRowSelectionAllowed(false);
sectionTable.setPreferredScrollableViewportSize(new java.awt.Dimension(650, 150));
TableColumnModel sectionColumnModel = sectionTable.getColumnModel();
TableColumn sequenceColumn = sectionColumnModel.getColumn(SectionTableModel.SEQUENCE_COLUMN);
sequenceColumn.setResizable(true);
sequenceColumn.setMinWidth(50);
sequenceColumn.setMaxWidth(70);
TableColumn sectionColumn = sectionColumnModel.getColumn(SectionTableModel.SECTIONNAME_COLUMN);
sectionColumn.setResizable(true);
sectionColumn.setMinWidth(150);
sectionColumn.setMaxWidth(210);
TableColumn actionColumn = sectionColumnModel.getColumn(SectionTableModel.ACTION_COLUMN);
// install button renderer and editor
ButtonRenderer buttonRenderer = new ButtonRenderer();
sectionTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
sectionTable.setDefaultEditor(JButton.class, buttonEditor);
JButton testButton = new JButton(rbx.getString("AddEditActions"));
sectionTable.setRowHeight(testButton.getPreferredSize().height);
actionColumn.setResizable(false);
actionColumn.setMinWidth(testButton.getPreferredSize().width);
TableColumn alternateColumn = sectionColumnModel.getColumn(SectionTableModel.ALTERNATE_COLUMN);
alternateColumn.setResizable(true);
alternateColumn.setMinWidth(140);
alternateColumn.setMaxWidth(170);
JScrollPane sectionTableScrollPane = new JScrollPane(sectionTable);
p12.add(sectionTableScrollPane, BorderLayout.CENTER);
p1.add(p12);
JPanel p13 = new JPanel();
p13.setLayout(new FlowLayout());
p13.add(primarySectionBox);
primarySectionBox.setToolTipText(rbx.getString("PrimarySectionBoxHint"));
p13.add(addNextSection = new JButton(rbx.getString("AddPrimaryButton")));
addNextSection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addNextSectionPressed(e);
}
});
addNextSection.setToolTipText(rbx.getString("AddPrimaryButtonHint"));
p1.add(p13);
JPanel p14 = new JPanel();
p14.setLayout(new FlowLayout());
p14.add(alternateSectionBox);
alternateSectionBox.setToolTipText(rbx.getString("AlternateSectionBoxHint"));
p14.add(addAlternateSection = new JButton(rbx.getString("AddAlternateButton")));
addAlternateSection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addAlternateSectionPressed(e);
}
});
addAlternateSection.setToolTipText(rbx.getString("AddAlternateButtonHint"));
p14.add(new JLabel(" "));
p14.add(insertAtBeginningBox);
insertAtBeginningBox.setToolTipText(rbx.getString("InsertAtBeginningBoxHint"));
p14.add(insertAtBeginning = new JButton(rbx.getString("InsertAtBeginningButton")));
insertAtBeginning.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
insertAtBeginningPressed(e);
}
});
insertAtBeginning.setToolTipText(rbx.getString("InsertAtBeginningButtonHint"));
p1.add(p14);
p1.add(new JSeparator());
JPanel p15 = new JPanel();
p15.setLayout(new FlowLayout());
p15.add(deleteSections = new JButton(rbx.getString("DeleteSectionsButton")));
deleteSections.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteAllSections(e);
}
});
deleteSections.setToolTipText(rbx.getString("DeleteSectionsButtonHint"));
p15.add(new JLabel(" "));
p15.add(removeLastSection = new JButton(rbx.getString("RemoveLastButton")));
removeLastSection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeLastSectionPressed(e);
}
});
removeLastSection.setToolTipText(rbx.getString("RemoveLastButtonHint"));
p15.add(new JLabel(" "));
p15.add(removeFirstSection = new JButton(rbx.getString("RemoveFirstButton")));
removeFirstSection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeFirstSectionPressed(e);
}
});
removeFirstSection.setToolTipText(rbx.getString("RemoveFirstButtonHint"));
p1.add(p15);
JPanel p16 = new JPanel();
p16.setLayout(new FlowLayout());
p16.add(seqNumLabel);
p16.add(new JLabel(" "));
p16.add(seqNum);
seqNum.setToolTipText(rbx.getString("SeqNumHint"));
p1.add(p16);
JPanel p17 = new JPanel();
p17.setLayout(new FlowLayout());
p17.add(replacePrimaryForSequence = new JButton(rbx.getString("ReplacePrimaryForSeqButton")));
replacePrimaryForSequence.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
replacePrimaryForSeqPressed(e);
}
});
replacePrimaryForSequence.setToolTipText(rbx.getString("ReplacePrimaryForSeqButtonHint"));
p17.add(new JLabel(" "));
p17.add(deleteAlternateForSequence = new JButton(rbx.getString("DeleteAlternateForSeqButton")));
deleteAlternateForSequence.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteAlternateForSeqPressed(e);
}
});
deleteAlternateForSequence.setToolTipText(rbx.getString("DeleteAlternateForSeqButtonHint"));
p17.add(new JLabel(" "));
p17.add(addAlternateForSequence = new JButton(rbx.getString("AddAlternateForSeqButton")));
addAlternateForSequence.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addAlternateForSeqPressed(e);
}
});
addAlternateForSequence.setToolTipText(rbx.getString("AddAlternateForSeqButtonHint"));
p1.add(p17);
addFrame.getContentPane().add(p1);
// set up bottom buttons
addFrame.getContentPane().add(new JSeparator());
JButton cancel = null;
JPanel pb = new JPanel();
pb.setLayout(new FlowLayout());
pb.add(cancel = new JButton(Bundle.getMessage("ButtonCancel")));
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelPressed(e);
}
});
cancel.setToolTipText(rbx.getString("CancelButtonHint"));
pb.add(create = new JButton(Bundle.getMessage("ButtonCreate")));
create.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createPressed(e);
}
});
create.setToolTipText(rbx.getString("SectionCreateButtonHint"));
pb.add(update = new JButton(Bundle.getMessage("ButtonUpdate")));
update.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updatePressed(e);
}
});
update.setToolTipText(rbx.getString("SectionUpdateButtonHint"));
addFrame.getContentPane().add(pb);
}
if (editMode) {
// setup for edit window
_autoSystemName.setVisible(false);
sysNameLabel.setEnabled(true);
create.setVisible(false);
update.setVisible(true);
sysName.setVisible(false);
sysNameFixed.setVisible(true);
initializeEditInformation();
} else {
// setup for create window
_autoSystemName.setVisible(true);
_autoSystemName.setEnabled(true);
autoSystemName();
create.setVisible(true);
create.setEnabled(true);
update.setVisible(false);
sysName.setVisible(true);
sysNameFixed.setVisible(false);
if (duplicateMode) {
// setup with information from previous Transit
initializeEditInformation();
sysName.setText(curTransit.getSystemName());
curTransit = null;
} else {
deleteAllSections(null);
}
}
initializeSectionCombos();
addFrame.pack();
addFrame.setVisible(true);
}
use of javax.swing.table.TableColumnModel in project JMRI by JMRI.
the class LocationsTableModel method initTable.
void initTable(LocationsTableFrame frame, JTable table) {
// Install the button handlers
TableColumnModel tcm = table.getColumnModel();
ButtonRenderer buttonRenderer = new ButtonRenderer();
TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
tcm.getColumn(ACTIONCOLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(ACTIONCOLUMN).setCellEditor(buttonEditor);
tcm.getColumn(EDITCOLUMN).setCellRenderer(buttonRenderer);
tcm.getColumn(EDITCOLUMN).setCellEditor(buttonEditor);
// set column preferred widths
table.getColumnModel().getColumn(IDCOLUMN).setPreferredWidth(40);
table.getColumnModel().getColumn(NAMECOLUMN).setPreferredWidth(200);
table.getColumnModel().getColumn(TRACKCOLUMN).setPreferredWidth(Math.max(60, new JLabel(Bundle.getMessage("Class/Interchange") + Bundle.getMessage("Spurs") + Bundle.getMessage("Yards")).getPreferredSize().width + 20));
table.getColumnModel().getColumn(LENGTHCOLUMN).setPreferredWidth(Math.max(60, new JLabel(getColumnName(LENGTHCOLUMN)).getPreferredSize().width + 10));
table.getColumnModel().getColumn(USEDLENGTHCOLUMN).setPreferredWidth(60);
table.getColumnModel().getColumn(ROLLINGSTOCK).setPreferredWidth(Math.max(80, new JLabel(getColumnName(ROLLINGSTOCK)).getPreferredSize().width + 10));
table.getColumnModel().getColumn(PICKUPS).setPreferredWidth(Math.max(60, new JLabel(getColumnName(PICKUPS)).getPreferredSize().width + 10));
table.getColumnModel().getColumn(DROPS).setPreferredWidth(Math.max(60, new JLabel(getColumnName(DROPS)).getPreferredSize().width + 10));
table.getColumnModel().getColumn(ACTIONCOLUMN).setPreferredWidth(Math.max(80, new JLabel(Bundle.getMessage("Yardmaster")).getPreferredSize().width + 40));
table.getColumnModel().getColumn(EDITCOLUMN).setPreferredWidth(80);
frame.loadTableDetails(table);
}
Aggregations