use of javax.swing.JTable in project JMRI by JMRI.
the class TableFrames method makeBlockPortalFrame.
/*
* ********************* BlockPortalFrame *****************************
*/
protected JInternalFrame makeBlockPortalFrame() {
JInternalFrame frame = new JInternalFrame(Bundle.getMessage("TitleBlockPortalXRef"), true, false, false, true);
_blockPortalXRefModel = new BlockPortalTableModel(_oBlockModel);
_blockPortalTable = new JTable(_blockPortalXRefModel);
_blockPortalTable.setTransferHandler(new jmri.util.DnDTableExportHandler());
_blockPortalTable.setDragEnabled(true);
_blockPortalTable.setDefaultRenderer(String.class, new jmri.jmrit.symbolicprog.ValueRenderer());
_blockPortalTable.setDefaultEditor(String.class, new jmri.jmrit.symbolicprog.ValueEditor());
for (int i = 0; i < _blockPortalXRefModel.getColumnCount(); i++) {
int width = _blockPortalXRefModel.getPreferredWidth(i);
_blockPortalTable.getColumnModel().getColumn(i).setPreferredWidth(width);
}
_blockPortalTable.sizeColumnsToFit(-1);
int tableWidth = _blockPortalTable.getPreferredSize().width;
_blockPortalTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 25));
JScrollPane tablePane = new JScrollPane(_blockPortalTable);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(5, 5));
contentPane.add(tablePane, BorderLayout.CENTER);
frame.addInternalFrameListener(this);
frame.setContentPane(contentPane);
frame.setLocation(700, 30);
frame.pack();
return frame;
}
use of javax.swing.JTable in project JMRI by JMRI.
the class TableFrames method makePortalFrame.
/*
* ********************* PortalFrame *****************************
*/
protected JInternalFrame makePortalFrame() {
JInternalFrame frame = new JInternalFrame(Bundle.getMessage("TitlePortalTable"), true, false, false, true);
_portalModel = new PortalTableModel(this);
_portalTable = new JTable(_portalModel);
TableRowSorter<PortalTableModel> sorter = new TableRowSorter<>(_portalModel);
sorter.setComparator(PortalTableModel.FROM_BLOCK_COLUMN, new jmri.util.SystemNameComparator());
sorter.setComparator(PortalTableModel.TO_BLOCK_COLUMN, new jmri.util.SystemNameComparator());
_portalTable.setRowSorter(sorter);
_portalTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { PortalTableModel.DELETE_COL }));
_portalTable.setDragEnabled(true);
_portalTable.getColumnModel().getColumn(PortalTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
_portalTable.getColumnModel().getColumn(PortalTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
for (int i = 0; i < _portalModel.getColumnCount(); i++) {
int width = _portalModel.getPreferredWidth(i);
_portalTable.getColumnModel().getColumn(i).setPreferredWidth(width);
}
_portalTable.sizeColumnsToFit(-1);
int tableWidth = _portalTable.getPreferredSize().width;
_portalTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 10));
_portalTablePane = new JScrollPane(_portalTable);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(5, 5));
JLabel prompt = new JLabel(Bundle.getMessage("AddPortalPrompt"));
contentPane.add(prompt, BorderLayout.NORTH);
contentPane.add(_portalTablePane, BorderLayout.CENTER);
frame.setContentPane(contentPane);
frame.setLocation(0, 200);
frame.pack();
return frame;
}
use of javax.swing.JTable in project JMRI by JMRI.
the class DispatcherFrame method openDispatcherWindow.
void openDispatcherWindow() {
if (dispatcherFrame == null) {
dispatcherFrame = this;
dispatcherFrame.setTitle(Bundle.getMessage("TitleDispatcher"));
JMenuBar menuBar = new JMenuBar();
optionsMenu = new OptionsMenu(this);
menuBar.add(optionsMenu);
setJMenuBar(menuBar);
dispatcherFrame.addHelpMenu("package.jmri.jmrit.dispatcher.Dispatcher", true);
contentPane = dispatcherFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// set up active trains table
JPanel p11 = new JPanel();
p11.setLayout(new FlowLayout());
p11.add(new JLabel(Bundle.getMessage("ActiveTrainTableTitle")));
contentPane.add(p11);
JPanel p12 = new JPanel();
p12.setLayout(new FlowLayout());
activeTrainsTableModel = new ActiveTrainsTableModel();
JTable activeTrainsTable = new JTable(activeTrainsTableModel);
activeTrainsTable.setRowSelectionAllowed(false);
activeTrainsTable.setPreferredScrollableViewportSize(new java.awt.Dimension(950, 160));
TableColumnModel activeTrainsColumnModel = activeTrainsTable.getColumnModel();
TableColumn transitColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TRANSIT_COLUMN);
transitColumn.setResizable(true);
transitColumn.setMinWidth(140);
transitColumn.setMaxWidth(220);
TableColumn trainColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TRAIN_COLUMN);
trainColumn.setResizable(true);
trainColumn.setMinWidth(90);
trainColumn.setMaxWidth(160);
TableColumn typeColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TYPE_COLUMN);
typeColumn.setResizable(true);
typeColumn.setMinWidth(130);
typeColumn.setMaxWidth(190);
TableColumn statusColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.STATUS_COLUMN);
statusColumn.setResizable(true);
statusColumn.setMinWidth(90);
statusColumn.setMaxWidth(140);
TableColumn modeColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.MODE_COLUMN);
modeColumn.setResizable(true);
modeColumn.setMinWidth(90);
modeColumn.setMaxWidth(140);
TableColumn allocatedColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.ALLOCATED_COLUMN);
allocatedColumn.setResizable(true);
allocatedColumn.setMinWidth(120);
allocatedColumn.setMaxWidth(200);
TableColumn nextSectionColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.NEXTSECTION_COLUMN);
nextSectionColumn.setResizable(true);
nextSectionColumn.setMinWidth(120);
nextSectionColumn.setMaxWidth(200);
TableColumn allocateButtonColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.ALLOCATEBUTTON_COLUMN);
allocateButtonColumn.setCellEditor(new ButtonEditor(new JButton()));
allocateButtonColumn.setMinWidth(110);
allocateButtonColumn.setMaxWidth(190);
allocateButtonColumn.setResizable(false);
ButtonRenderer buttonRenderer = new ButtonRenderer();
activeTrainsTable.setDefaultRenderer(JButton.class, buttonRenderer);
JButton sampleButton = new JButton(Bundle.getMessage("AllocateButtonName"));
activeTrainsTable.setRowHeight(sampleButton.getPreferredSize().height);
allocateButtonColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
JScrollPane activeTrainsTableScrollPane = new JScrollPane(activeTrainsTable);
p12.add(activeTrainsTableScrollPane, BorderLayout.CENTER);
contentPane.add(p12);
JPanel p13 = new JPanel();
p13.setLayout(new FlowLayout());
p13.add(addTrainButton = new JButton(Bundle.getMessage("InitiateTrain") + "..."));
addTrainButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!newTrainActive) {
atFrame.initiateTrain(e);
newTrainActive = true;
} else {
atFrame.showActivateFrame();
}
}
});
addTrainButton.setToolTipText(Bundle.getMessage("InitiateTrainButtonHint"));
p13.add(new JLabel(" "));
p13.add(new JLabel(" "));
p13.add(allocateExtraButton = new JButton(Bundle.getMessage("AllocateExtra") + "..."));
allocateExtraButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
allocateExtraSection(e);
}
});
allocateExtraButton.setToolTipText(Bundle.getMessage("AllocateExtraButtonHint"));
p13.add(new JLabel(" "));
p13.add(cancelRestartButton = new JButton(Bundle.getMessage("CancelRestart") + "..."));
cancelRestartButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!newTrainActive) {
cancelRestart(e);
} else if (restartingTrainsList.size() > 0) {
atFrame.showActivateFrame();
JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Message2"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
} else {
atFrame.showActivateFrame();
}
}
});
cancelRestartButton.setToolTipText(Bundle.getMessage("CancelRestartButtonHint"));
p13.add(new JLabel(" "));
p13.add(terminateTrainButton = new JButton(Bundle.getMessage("TerminateTrain") + "..."));
terminateTrainButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!newTrainActive) {
terminateTrain(e);
} else if (activeTrainsList.size() > 0) {
atFrame.showActivateFrame();
JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Message1"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
} else {
atFrame.showActivateFrame();
}
}
});
terminateTrainButton.setToolTipText(Bundle.getMessage("TerminateTrainButtonHint"));
contentPane.add(p13);
// set up pending allocations table
contentPane.add(new JSeparator());
JPanel p21 = new JPanel();
p21.setLayout(new FlowLayout());
p21.add(new JLabel(Bundle.getMessage("RequestedAllocationsTableTitle")));
contentPane.add(p21);
JPanel p22 = new JPanel();
p22.setLayout(new FlowLayout());
allocationRequestTableModel = new AllocationRequestTableModel();
JTable allocationRequestTable = new JTable(allocationRequestTableModel);
allocationRequestTable.setRowSelectionAllowed(false);
allocationRequestTable.setPreferredScrollableViewportSize(new java.awt.Dimension(950, 100));
TableColumnModel allocationRequestColumnModel = allocationRequestTable.getColumnModel();
TableColumn activeColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.ACTIVE_COLUMN);
activeColumn.setResizable(true);
activeColumn.setMinWidth(210);
activeColumn.setMaxWidth(260);
TableColumn priorityColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.PRIORITY_COLUMN);
priorityColumn.setResizable(true);
priorityColumn.setMinWidth(40);
priorityColumn.setMaxWidth(60);
TableColumn trainTypColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.TRAINTYPE_COLUMN);
trainTypColumn.setResizable(true);
trainTypColumn.setMinWidth(130);
trainTypColumn.setMaxWidth(190);
TableColumn sectionColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.SECTION_COLUMN);
sectionColumn.setResizable(true);
sectionColumn.setMinWidth(140);
sectionColumn.setMaxWidth(210);
TableColumn secStatusColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.STATUS_COLUMN);
secStatusColumn.setResizable(true);
secStatusColumn.setMinWidth(90);
secStatusColumn.setMaxWidth(150);
TableColumn occupancyColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.OCCUPANCY_COLUMN);
occupancyColumn.setResizable(true);
occupancyColumn.setMinWidth(80);
occupancyColumn.setMaxWidth(130);
TableColumn secLengthColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.SECTIONLENGTH_COLUMN);
secLengthColumn.setResizable(true);
secLengthColumn.setMinWidth(40);
secLengthColumn.setMaxWidth(60);
TableColumn allocateColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.ALLOCATEBUTTON_COLUMN);
allocateColumn.setCellEditor(new ButtonEditor(new JButton()));
allocateColumn.setMinWidth(90);
allocateColumn.setMaxWidth(170);
allocateColumn.setResizable(false);
allocationRequestTable.setDefaultRenderer(JButton.class, buttonRenderer);
sampleButton = new JButton(Bundle.getMessage("AllocateButton"));
allocationRequestTable.setRowHeight(sampleButton.getPreferredSize().height);
allocateColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
TableColumn cancelButtonColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.CANCELBUTTON_COLUMN);
cancelButtonColumn.setCellEditor(new ButtonEditor(new JButton()));
cancelButtonColumn.setMinWidth(75);
cancelButtonColumn.setMaxWidth(170);
cancelButtonColumn.setResizable(false);
cancelButtonColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
JScrollPane allocationRequestTableScrollPane = new JScrollPane(allocationRequestTable);
p22.add(allocationRequestTableScrollPane, BorderLayout.CENTER);
contentPane.add(p22);
// set up allocated sections table
contentPane.add(new JSeparator());
JPanel p30 = new JPanel();
p30.setLayout(new FlowLayout());
p30.add(new JLabel(Bundle.getMessage("AllocatedSectionsTitle") + " "));
autoReleaseBox = new JCheckBox(Bundle.getMessage("AutoReleaseBoxLabel"));
p30.add(autoReleaseBox);
autoReleaseBox.setToolTipText(Bundle.getMessage("AutoReleaseBoxHint"));
autoReleaseBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handleAutoReleaseChanged(e);
}
});
// initiallize autoRelease to match autoAllocate
autoReleaseBox.setSelected(_AutoAllocate);
autoAllocateBox = new JCheckBox(Bundle.getMessage("AutoDispatchItem"));
p30.add(autoAllocateBox);
autoAllocateBox.setToolTipText(Bundle.getMessage("AutoAllocateBoxHint"));
autoAllocateBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handleAutoAllocateChanged(e);
}
});
contentPane.add(p30);
autoAllocateBox.setSelected(_AutoAllocate);
JPanel p31 = new JPanel();
p31.setLayout(new FlowLayout());
allocatedSectionTableModel = new AllocatedSectionTableModel();
JTable allocatedSectionTable = new JTable(allocatedSectionTableModel);
allocatedSectionTable.setRowSelectionAllowed(false);
allocatedSectionTable.setPreferredScrollableViewportSize(new java.awt.Dimension(730, 200));
TableColumnModel allocatedSectionColumnModel = allocatedSectionTable.getColumnModel();
TableColumn activeAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.ACTIVE_COLUMN);
activeAColumn.setResizable(true);
activeAColumn.setMinWidth(250);
activeAColumn.setMaxWidth(350);
TableColumn sectionAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.SECTION_COLUMN);
sectionAColumn.setResizable(true);
sectionAColumn.setMinWidth(200);
sectionAColumn.setMaxWidth(350);
TableColumn occupancyAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.OCCUPANCY_COLUMN);
occupancyAColumn.setResizable(true);
occupancyAColumn.setMinWidth(80);
occupancyAColumn.setMaxWidth(140);
TableColumn useStatusColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.USESTATUS_COLUMN);
useStatusColumn.setResizable(true);
useStatusColumn.setMinWidth(90);
useStatusColumn.setMaxWidth(150);
TableColumn releaseColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.RELEASEBUTTON_COLUMN);
releaseColumn.setCellEditor(new ButtonEditor(new JButton()));
releaseColumn.setMinWidth(90);
releaseColumn.setMaxWidth(170);
releaseColumn.setResizable(false);
allocatedSectionTable.setDefaultRenderer(JButton.class, buttonRenderer);
JButton sampleAButton = new JButton(Bundle.getMessage("ReleaseButton"));
allocatedSectionTable.setRowHeight(sampleAButton.getPreferredSize().height);
releaseColumn.setPreferredWidth((sampleAButton.getPreferredSize().width) + 2);
JScrollPane allocatedSectionTableScrollPane = new JScrollPane(allocatedSectionTable);
p31.add(allocatedSectionTableScrollPane, BorderLayout.CENTER);
contentPane.add(p31);
}
dispatcherFrame.pack();
dispatcherFrame.setVisible(true);
}
use of javax.swing.JTable in project JMRI by JMRI.
the class ManageLocationsFrame method initGui.
private void initGui() {
this.setTitle(Bundle.getMessage("FieldManageLocationsFrameTitle"));
this.buildMenu();
// Panel for managing listeners
listenerPanel = new JPanel();
listenerPanel.setLayout(new BoxLayout(listenerPanel, BoxLayout.Y_AXIS));
// Audio Mode Buttons
JRadioButton b1 = new JRadioButton(Bundle.getMessage("ButtonAudioModeRoom"));
b1.setToolTipText(Bundle.getMessage("ToolTipButtonAudioModeRoom"));
// NOI18N
b1.setMnemonic(Mnemonics.get("RoomMode"));
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modeRadioButtonPressed(e);
}
});
JRadioButton b2 = new JRadioButton(Bundle.getMessage("ButtonAudioModeHeadphone"));
// NOI18N
b2.setMnemonic(Mnemonics.get("HeadphoneMode"));
b2.setToolTipText(Bundle.getMessage("ToolTipButtonAudioModeHeadphone"));
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modeRadioButtonPressed(e);
}
});
b2.setEnabled(false);
ButtonGroup bg = new ButtonGroup();
bg.add(b1);
bg.add(b2);
b1.setSelected(true);
JPanel modePanel = new JPanel();
modePanel.setLayout(new BoxLayout(modePanel, BoxLayout.LINE_AXIS));
modePanel.add(new JLabel(Bundle.getMessage("FieldAudioMode")));
modePanel.add(b1);
modePanel.add(b2);
// Build Listener Locations Table
locData = new Object[1][7];
locData[0][0] = listenerLoc.getName();
locData[0][1] = true;
locData[0][2] = listenerLoc.getLocation().x;
locData[0][3] = listenerLoc.getLocation().y;
locData[0][4] = listenerLoc.getLocation().z;
locData[0][5] = listenerLoc.getBearing();
locData[0][6] = listenerLoc.getAzimuth();
log.debug("Listener:" + listenerLoc.toString());
log.debug("locData:");
for (int i = 0; i < 7; i++) {
log.debug("" + locData[0][i]);
}
JPanel locPanel = new JPanel();
locPanel.setLayout(new BoxLayout(locPanel, BoxLayout.LINE_AXIS));
JScrollPane locScrollPanel = new JScrollPane();
locModel = new ListenerTableModel(locData);
JTable locTable = new JTable(locModel);
locTable.setFillsViewportHeight(true);
locTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
locScrollPanel.getViewport().add(locTable);
listenerPanel.add(modePanel);
listenerPanel.add(locScrollPanel);
reporterPanel = new JPanel();
reporterPanel.setLayout(new GridBagLayout());
JScrollPane reporterScrollPanel = new JScrollPane();
reporterModel = new LocationTableModel(reporterData);
JTable reporterTable = new JTable(reporterModel);
reporterTable.setFillsViewportHeight(true);
reporterScrollPanel.getViewport().add(reporterTable);
reporterTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
blockPanel = new JPanel();
blockPanel.setLayout(new GridBagLayout());
JScrollPane blockScrollPanel = new JScrollPane();
blockModel = new LocationTableModel(blockData);
JTable blockTable = new JTable(blockModel);
blockTable.setFillsViewportHeight(true);
blockScrollPanel.getViewport().add(blockTable);
blockTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
opsPanel = new JPanel();
opsPanel.setLayout(new GridBagLayout());
opsPanel.revalidate();
JScrollPane opsScrollPanel = new JScrollPane();
opsModel = new LocationTableModel(opsData);
JTable opsTable = new JTable(opsModel);
opsTable.setFillsViewportHeight(true);
opsTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
opsScrollPanel.getViewport().add(opsTable);
tabbedPane = new JTabbedPane();
// Reporters Tab Title
tabbedPane.addTab(Bundle.getMessage("Reporters"), reporterScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipReporterTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("ReporterTab"));
tabbedPane.addTab(Bundle.getMessage("Blocks"), blockScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipBlockTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("BlockTab"));
tabbedPane.addTab(Bundle.getMessage("FieldOpsTabTitle"), opsScrollPanel);
tabbedPane.setToolTipTextAt(1, Bundle.getMessage("ToolTipOpsTab"));
// NOI18N
tabbedPane.setMnemonicAt(1, Mnemonics.get("OpsTab"));
tabbedPane.addTab(Bundle.getMessage("FieldListenersTabTitle"), listenerPanel);
tabbedPane.setToolTipTextAt(2, Bundle.getMessage("ToolTipListenerTab"));
// NOI18N
tabbedPane.setMnemonicAt(2, Mnemonics.get("ListenerTab"));
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
JButton closeButton = new JButton(Bundle.getMessage("ButtonCancel"));
closeButton.setToolTipText(Bundle.getMessage("ToolTipButtonMLFClose"));
// NOI18N
closeButton.setMnemonic(Mnemonics.get("CloseButton"));
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeButtonPressed(e);
}
});
JButton saveButton = new JButton(Bundle.getMessage("ButtonSave"));
saveButton.setToolTipText(Bundle.getMessage("ToolTipButtonMLFSave"));
// NOI18N
saveButton.setMnemonic(Mnemonics.get("SaveButton"));
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveButtonPressed(e);
}
});
buttonPane.add(closeButton);
buttonPane.add(saveButton);
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.getContentPane().add(tabbedPane);
this.getContentPane().add(buttonPane);
this.pack();
this.setVisible(true);
}
use of javax.swing.JTable in project JMRI by JMRI.
the class ConfigBaseStationFrame method initGui.
private void initGui() {
// NOTE: Look at jmri.jmrit.vsdecoder.swing.ManageLocationsFrame
// for how to add a tab for turnouts and other things.
this.setTitle(Bundle.getMessage("FieldManageBaseStationFrameTitle"));
this.buildMenu();
// Panel for managing sensors
sensorPanel = new JPanel();
sensorPanel.setLayout(new GridBagLayout());
JButton addButton = new JButton(Bundle.getMessage("ButtonAddSensor"));
addButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFAdd"));
// NOI18N
addButton.setMnemonic(Mnemonics.get("AddButton"));
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addButtonPressed(e);
}
});
JButton closeButton = new JButton(Bundle.getMessage("ButtonClose"));
closeButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFClose"));
// NOI18N
closeButton.setMnemonic(Mnemonics.get("CloseButton"));
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeButtonPressed(e);
}
});
JButton saveButton = new JButton(Bundle.getMessage("ButtonSaveSensors"));
saveButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFSave"));
// NOI18N
saveButton.setMnemonic(Mnemonics.get("SaveButton"));
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveButtonPressed(e);
}
});
JScrollPane sensorScrollPanel = new JScrollPane();
sensorModel = new SensorTableModel();
sensorTable = new JTable(sensorModel);
sensorTable.setFillsViewportHeight(true);
sensorScrollPanel.getViewport().add(sensorTable);
sensorTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
sensorTable.removeColumn(sensorTable.getColumn("isNew"));
sensorTable.removeColumn(sensorTable.getColumn("isDirty"));
sensorTable.removeColumn(sensorTable.getColumn("isDelete"));
sensorTable.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
handleTableMouseClick(sensorTable, evt);
}
});
sensorTable.setAutoCreateRowSorter(true);
sensorSorter = new TableRowSorter<>(sensorTable.getModel());
sensorTable.setRowSorter(sensorSorter);
List<RowSorter.SortKey> sensorSortKeys = new ArrayList<>();
//int columnIndexToSort = 1;
sensorSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
sensorSorter.setSortKeys(sensorSortKeys);
sensorSorter.sort();
sensorSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
JScrollPane turnoutScrollPanel = new JScrollPane();
turnoutModel = new TurnoutTableModel();
turnoutTable = new JTable(turnoutModel);
turnoutTable.setFillsViewportHeight(true);
turnoutScrollPanel.getViewport().add(turnoutTable);
turnoutTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
turnoutTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
turnoutTable.removeColumn(turnoutTable.getColumn("isNew"));
turnoutTable.removeColumn(turnoutTable.getColumn("isDirty"));
turnoutTable.removeColumn(turnoutTable.getColumn("isDelete"));
turnoutTable.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
handleTableMouseClick(turnoutTable, evt);
}
});
turnoutTable.setAutoCreateRowSorter(true);
turnoutSorter = new TableRowSorter<>(turnoutTable.getModel());
turnoutTable.setRowSorter(turnoutSorter);
List<RowSorter.SortKey> turnoutSortKeys = new ArrayList<>();
//int columnIndexToSort = 1;
turnoutSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
turnoutSorter.setSortKeys(turnoutSortKeys);
turnoutSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
turnoutSorter.sort();
JScrollPane outputScrollPanel = new JScrollPane();
outputModel = new OutputTableModel();
outputTable = new JTable(outputModel);
outputTable.setFillsViewportHeight(true);
outputScrollPanel.getViewport().add(outputTable);
outputTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
outputTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
outputTable.removeColumn(outputTable.getColumn("isNew"));
outputTable.removeColumn(outputTable.getColumn("isDirty"));
outputTable.removeColumn(outputTable.getColumn("isDelete"));
outputTable.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
handleTableMouseClick(outputTable, evt);
}
});
outputTable.setAutoCreateRowSorter(true);
outputSorter = new TableRowSorter<>(outputTable.getModel());
outputTable.setRowSorter(outputSorter);
List<RowSorter.SortKey> outputSortKeys = new ArrayList<>();
//int columnIndexToSort = 1;
outputSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
outputSorter.setSortKeys(outputSortKeys);
outputSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
outputSorter.sort();
tabbedPane = new JTabbedPane();
tabbedPane.addTab(Bundle.getMessage("FieldSensorsTabTitle"), sensorScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipSensorTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("SensorTab"));
tabbedPane.addTab(Bundle.getMessage("FieldTurnoutsTabTitle"), turnoutScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipTurnoutTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("TurnoutTab"));
tabbedPane.addTab(Bundle.getMessage("FieldOutputsTabTitle"), outputScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipOutputTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("OutputTab"));
cTab = CurrentTab.SENSOR;
tabbedPane.setSelectedIndex(0);
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
switch(tabbedPane.getSelectedIndex()) {
case 2:
// Set Add to "Add Output"
cTab = CurrentTab.OUTPUT;
addButton.setText(Bundle.getMessage("ButtonAddOutput"));
saveButton.setText(Bundle.getMessage("ButtonSaveOutputs"));
log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
break;
case 1:
// Set Add to "Add Turnout"
cTab = CurrentTab.TURNOUT;
addButton.setText(Bundle.getMessage("ButtonAddTurnout"));
saveButton.setText(Bundle.getMessage("ButtonSaveTurnouts"));
log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
break;
case 0:
default:
// Set Add to "Add Sensor"
cTab = CurrentTab.SENSOR;
addButton.setText(Bundle.getMessage("ButtonAddSensor"));
saveButton.setText(Bundle.getMessage("ButtonSaveSensors"));
log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
}
}
});
JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel buttonPane2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
buttonPane.add(addButton);
buttonPane.add(saveButton);
buttonPane2.add(closeButton);
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.getContentPane().add(tabbedPane);
this.getContentPane().add(buttonPane);
this.getContentPane().add(buttonPane2);
this.pack();
this.setVisible(true);
}
Aggregations