/* * Update radio button names in the same order as the table */ private void updateControlPanel() { schedule.removeAll(); noneButton.setName(""); // Name holds schedule id for the selected radio button noneButton.setSelected(true); commentTextArea.setText(""); // no text for the noneButton enableButtons(false); schedule.add(noneButton); schGroup.add(noneButton); for (int i = trainsScheduleModel.getFixedColumn(); i < trainsScheduleModel.getColumnCount(); i++) { log.debug("Column name: {}", trainsScheduleTable.getColumnName(i)); TrainSchedule ts = trainScheduleManager.getScheduleByName(trainsScheduleTable.getColumnName(i)); if (ts != null) { JRadioButton b = new JRadioButton(); b.setText(ts.getName()); b.setName(ts.getId()); schedule.add(b); schGroup.add(b); addRadioButtonAction(b); if (b.getName().equals(trainManager.getTrainScheduleActiveId())) { b.setSelected(true); enableButtons(true); // update comment field commentTextArea.setText(ts.getComment()); } } } schedule.revalidate(); }
public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) { log.debug("radio button activated"); if (ae.getSource() == sortByName) { trainsScheduleModel.setSort(trainsScheduleModel.SORTBYNAME); } else if (ae.getSource() == sortByTime) { trainsScheduleModel.setSort(trainsScheduleModel.SORTBYTIME); } else if (ae.getSource() == noneButton) { enableButtons(false); commentTextArea.setText(""); // no text for the noneButton // must be one of the schedule radio buttons } else { enableButtons(true); // update comment field TrainSchedule ts = trainScheduleManager.getScheduleById(getSelectedScheduleId()); commentTextArea.setText(ts.getComment()); } }
public void dispose() { Setup.removePropertyChangeListener(this); trainManager.removePropertyChangeListener(this); trainScheduleManager.removePropertyChangeListener(this); removePropertyChangeTrainSchedules(); removePropertyChangeLocations(); trainsScheduleModel.dispose(); super.dispose(); }
public TrainsScheduleTableFrame() { // general GUI configuration getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); // Set up the jtable in a Scroll Pane.. trainsPane = new JScrollPane(trainsScheduleTable); trainsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); trainsPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); trainsScheduleModel.initTable(trainsScheduleTable, this); // row comment JPanel pC = new JPanel(); pC.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Comment"))); pC.setLayout(new GridBagLayout()); addItem(pC, commentScroller, 1, 0); // adjust text area width based on window size adjustTextAreaColumnWidth(commentScroller, commentTextArea); // Set up the control panel // row 1 JPanel cp1 = new JPanel(); cp1.setLayout(new BoxLayout(cp1, BoxLayout.X_AXIS)); // row 1 JPanel sortBy = new JPanel(); sortBy.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("SortBy"))); sortBy.add(sortByTime); sortBy.add(sortByName); // row 2 schedule.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Active"))); updateControlPanel(); cp1.add(sortBy); cp1.add(schedule); JPanel pButtons = new JPanel(); pButtons.setLayout(new BoxLayout(pButtons, BoxLayout.X_AXIS)); JPanel cp3 = new JPanel(); cp3.setBorder(BorderFactory.createTitledBorder("")); cp3.add(clearButton); cp3.add(selectButton); JPanel cp4 = new JPanel(); cp4.setBorder(BorderFactory.createTitledBorder("")); cp4.add(applyButton); cp4.add(buildButton); cp4.add(printButton); cp4.add(switchListsButton); cp4.add(terminateButton); JPanel cp5 = new JPanel(); cp5.setBorder(BorderFactory.createTitledBorder("")); cp5.add(activateButton); cp5.add(saveButton); pButtons.add(cp3); pButtons.add(cp4); pButtons.add(cp5); // tool tips selectButton.setToolTipText(Bundle.getMessage("SelectAllButtonTip")); clearButton.setToolTipText(Bundle.getMessage("ClearAllButtonTip")); applyButton.setToolTipText(Bundle.getMessage("ApplyButtonTip")); buildButton.setToolTipText(Bundle.getMessage("BuildSelectedTip")); activateButton.setToolTipText(Bundle.getMessage("ActivateButtonTip")); terminateButton.setToolTipText(Bundle.getMessage("TerminateSelectedTip")); setPrintButtonText(); setSwitchListButtonText(); // place controls in scroll pane JPanel controlPanel = new JPanel(); controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS)); controlPanel.add(pC); controlPanel.add(cp1); controlPanel.add(pButtons); JScrollPane controlPane = new JScrollPane(controlPanel); // make sure control panel is the right size controlPane.setMinimumSize(new Dimension(500, 480)); controlPane.setMaximumSize(new Dimension(2000, 500)); controlPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); getContentPane().add(trainsPane); getContentPane().add(controlPane); // setup buttons addButtonAction(clearButton); addButtonAction(selectButton); addButtonAction(applyButton); addButtonAction(buildButton); addButtonAction(printButton); addButtonAction(switchListsButton); addButtonAction(terminateButton); addButtonAction(activateButton); addButtonAction(saveButton); ButtonGroup sortGroup = new ButtonGroup(); sortGroup.add(sortByTime); sortGroup.add(sortByName); sortByTime.setSelected(true); addRadioButtonAction(sortByTime); addRadioButtonAction(sortByName); addRadioButtonAction(noneButton); // build menu JMenuBar menuBar = new JMenuBar(); JMenu toolMenu = new JMenu(Bundle.getMessage("Tools")); toolMenu.add(new TrainsScheduleEditAction()); menuBar.add(toolMenu); setJMenuBar(menuBar); // add help menu to window addHelpMenu("package.jmri.jmrit.operations.Operations_Timetable", true); // NOI18N setTitle(Bundle.getMessage("TitleTimeTableTrains")); initMinimumSize(new Dimension(Control.panelWidth700, Control.panelHeight500)); addHorizontalScrollBarKludgeFix(controlPane, controlPanel); Setup.addPropertyChangeListener(this); trainManager.addPropertyChangeListener(this); trainScheduleManager.addPropertyChangeListener(this); addPropertyChangeLocations(); addPropertyChangeTrainSchedules(); }