public TrainsTableFrame() { super(); updateTitle(); // create ShutDownTasks createShutDownTask(); // always check for dirty operations files setModifiedFlag(true); // general GUI configuration getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); // Set up the jtable in a Scroll Pane.. trainsModel = new TrainsTableModel(); sorter = new TableSorter(trainsModel); trainsTable = new JTable(sorter); sorter.setTableHeader(trainsTable.getTableHeader()); trainsPane = new JScrollPane(trainsTable); trainsModel.initTable(trainsTable, this); // Set up the control panel // row 1 JPanel cp1 = new JPanel(); cp1.setLayout(new BoxLayout(cp1, BoxLayout.X_AXIS)); JPanel show = new JPanel(); show.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("ShowClickToSort"))); show.add(showTime); show.add(showId); JPanel options = new JPanel(); options.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Options"))); options.add(showAllBox); options.add(buildMsgBox); options.add(buildReportBox); options.add(printPreviewBox); options.add(openFileBox); options.add(runFileBox); JPanel action = new JPanel(); action.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Action"))); action.add(moveRB); action.add(conductorRB); action.add(terminateRB); action.add(resetRB); cp1.add(show); cp1.add(options); cp1.add(action); // tool tips, see setPrintButtonText() for more tool tips addButton.setToolTipText(Bundle.getMessage("AddTrain")); buildButton.setToolTipText(Bundle.getMessage("BuildSelectedTip")); switchListsButton.setToolTipText(Bundle.getMessage("PreviewPrintSwitchLists")); terminateButton.setToolTipText(Bundle.getMessage("TerminateSelectedTip")); saveButton.setToolTipText(Bundle.getMessage("SaveBuildsTip")); openFileButton.setToolTipText(Bundle.getMessage("OpenFileButtonTip")); runFileButton.setToolTipText(Bundle.getMessage("RunFileButtonTip")); buildMsgBox.setToolTipText(Bundle.getMessage("BuildMessagesTip")); printPreviewBox.setToolTipText(Bundle.getMessage("PreviewTip")); openFileBox.setToolTipText(Bundle.getMessage("OpenFileTip")); runFileBox.setToolTipText(Bundle.getMessage("RunFileTip")); showAllBox.setToolTipText(Bundle.getMessage("ShowAllTrainsTip")); moveRB.setToolTipText(Bundle.getMessage("MoveTip")); terminateRB.setToolTipText(Bundle.getMessage("TerminateTip")); resetRB.setToolTipText(Bundle.getMessage("ResetTip")); // row 2 JPanel addTrain = new JPanel(); addTrain.setBorder(BorderFactory.createTitledBorder("")); addTrain.add(numTrains); addTrain.add(textTrains); addTrain.add(textSep1); addTrain.add(addButton); numTrains.setText(Integer.toString(trainManager.getNumEntries())); JPanel select = new JPanel(); select.setBorder(BorderFactory.createTitledBorder("")); select.add(buildButton); select.add(printButton); select.add(openFileButton); select.add(runFileButton); select.add(switchListsButton); select.add(terminateButton); JPanel save = new JPanel(); save.setBorder(BorderFactory.createTitledBorder("")); save.add(saveButton); JPanel cp2 = new JPanel(); cp2.setLayout(new BoxLayout(cp2, BoxLayout.X_AXIS)); cp2.add(addTrain); cp2.add(select); cp2.add(save); // place controls in scroll pane JPanel controlPanel = new JPanel(); controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS)); controlPanel.add(cp1); controlPanel.add(cp2); JScrollPane controlPane = new JScrollPane(controlPanel); getContentPane().add(trainsPane); getContentPane().add(controlPane); // setup buttons addButtonAction(addButton); addButtonAction(buildButton); addButtonAction(printButton); addButtonAction(openFileButton); addButtonAction(runFileButton); addButtonAction(switchListsButton); addButtonAction(terminateButton); addButtonAction(saveButton); ButtonGroup showGroup = new ButtonGroup(); showGroup.add(showTime); showGroup.add(showId); showTime.setSelected(true); ButtonGroup actionGroup = new ButtonGroup(); actionGroup.add(moveRB); actionGroup.add(conductorRB); actionGroup.add(terminateRB); actionGroup.add(resetRB); addRadioButtonAction(showTime); addRadioButtonAction(showId); addRadioButtonAction(moveRB); addRadioButtonAction(terminateRB); addRadioButtonAction(resetRB); addRadioButtonAction(conductorRB); buildMsgBox.setSelected(trainManager.isBuildMessagesEnabled()); buildReportBox.setSelected(trainManager.isBuildReportEnabled()); printPreviewBox.setSelected(trainManager.isPrintPreviewEnabled()); openFileBox.setSelected(trainManager.isOpenFileEnabled()); runFileBox.setSelected(trainManager.isRunFileEnabled()); showAllBox.setSelected(trainsModel.isShowAll()); // show open files only if create csv is enabled updateRunAndOpenButtons(); addCheckBoxAction(buildMsgBox); addCheckBoxAction(buildReportBox); addCheckBoxAction(printPreviewBox); addCheckBoxAction(showAllBox); addCheckBoxAction(openFileBox); addCheckBoxAction(runFileBox); // Set the button text to Print or Preview setPrintButtonText(); // Set the train action button text to Move or Terminate setTrainActionButton(); // build menu JMenuBar menuBar = new JMenuBar(); JMenu toolMenu = new JMenu(Bundle.getMessage("Tools")); toolMenu.add(new OptionAction(Bundle.getMessage("TitleOptions"))); toolMenu.add(new PrintOptionAction()); toolMenu.add(new BuildReportOptionAction()); toolMenu.add(new TrainsByCarTypeAction(Bundle.getMessage("TitleModifyTrains"))); toolMenu.add(new TrainByCarTypeAction(Bundle.getMessage("MenuItemShowCarTypes"), null)); toolMenu.add(new ChangeDepartureTimesAction(Bundle.getMessage("TitleChangeDepartureTime"))); toolMenu.add(new TrainsTableSetColorAction()); toolMenu.add(new TrainsScheduleAction(Bundle.getMessage("TitleTimeTableTrains"))); toolMenu.add(new TrainCopyAction(Bundle.getMessage("TitleTrainCopy"))); toolMenu.add(new TrainsScriptAction(Bundle.getMessage("MenuItemScripts"), this)); toolMenu.add( new PrintSavedTrainManifestAction(Bundle.getMessage("MenuItemPrintSavedManifest"), false)); toolMenu.add( new PrintSavedTrainManifestAction(Bundle.getMessage("MenuItemPreviewSavedManifest"), true)); toolMenu.add(new SetupExcelProgramFrameAction(Bundle.getMessage("MenuItemSetupExcelProgram"))); toolMenu.add(new ExportTrainRosterAction()); toolMenu.add( new PrintTrainsAction(Bundle.getMessage("MenuItemPrint"), new Frame(), false, this)); toolMenu.add( new PrintTrainsAction(Bundle.getMessage("MenuItemPreview"), new Frame(), true, this)); menuBar.add(toolMenu); menuBar.add(new jmri.jmrit.operations.OperationsMenu()); setJMenuBar(menuBar); // add help menu to window addHelpMenu("package.jmri.jmrit.operations.Operations_Trains", true); // NOI18N initMinimumSize(); addHorizontalScrollBarKludgeFix(controlPane, controlPanel); // listen for timetable changes trainManager.addPropertyChangeListener(this); Setup.addPropertyChangeListener(this); // listen for location switch list changes addPropertyChangeLocations(); // auto save new AutoSave(); }
// add, build, print, switch lists, terminate, and save buttons public void buttonActionPerformed(java.awt.event.ActionEvent ae) { // log.debug("train button activated"); if (ae.getSource() == addButton) { new TrainEditFrame(null); } if (ae.getSource() == buildButton) { // uses a thread which allows table updates during build trainManager.buildSelectedTrains(getSortByList()); } if (ae.getSource() == printButton) { trainManager.printSelectedTrains(getSortByList()); } if (ae.getSource() == openFileButton) { // open the csv files List<Train> trains = getSortByList(); for (Train train : trains) { if (train.isBuildEnabled()) { if (!train.isBuilt() && trainManager.isBuildMessagesEnabled()) { JOptionPane.showMessageDialog( this, MessageFormat.format( Bundle.getMessage("NeedToBuildBeforeOpenFile"), new Object[] { train.getName(), (trainManager.isPrintPreviewEnabled() ? Bundle.getMessage("preview") : Bundle.getMessage("print")) }), MessageFormat.format( Bundle.getMessage("CanNotPrintManifest"), new Object[] { trainManager.isPrintPreviewEnabled() ? Bundle.getMessage("preview") : Bundle.getMessage("print") }), JOptionPane.ERROR_MESSAGE); } else if (train.isBuilt()) { train.openFile(); } } } } if (ae.getSource() == runFileButton) { // Processes the CSV Manifest files using an external custom program. if (!TrainCustomManifest.manifestCreatorFileExists()) { log.warn( "Manifest creator file not found!, directory name: " + TrainCustomManifest.getDirectoryName() + ", file name: " + TrainCustomManifest.getFileName()); // NOI18N JOptionPane.showMessageDialog( this, MessageFormat.format( Bundle.getMessage("LoadDirectoryNameFileName"), new Object[] { TrainCustomManifest.getDirectoryName(), TrainCustomManifest.getFileName() }), Bundle.getMessage("ManifestCreatorNotFound"), JOptionPane.ERROR_MESSAGE); return; } List<Train> trains = getSortByList(); for (Train train : trains) { if (train.isBuildEnabled()) { if (!train.isBuilt() && trainManager.isBuildMessagesEnabled()) { JOptionPane.showMessageDialog( this, MessageFormat.format( Bundle.getMessage("NeedToBuildBeforeRunFile"), new Object[] { train.getName(), (trainManager.isPrintPreviewEnabled() ? Bundle.getMessage("preview") : Bundle.getMessage("print")) }), MessageFormat.format( Bundle.getMessage("CanNotPrintManifest"), new Object[] { trainManager.isPrintPreviewEnabled() ? Bundle.getMessage("preview") : Bundle.getMessage("print") }), JOptionPane.ERROR_MESSAGE); } else if (train.isBuilt()) { // Make sure our csv manifest file exists for this Train. File csvFile = train.createCSVManifestFile(); // Add it to our collection to be processed. TrainCustomManifest.addCVSFile(csvFile); } } } // Now run the user specified custom Manifest processor program TrainCustomManifest.process(); } if (ae.getSource() == switchListsButton) { if (tslef != null) { tslef.dispose(); } tslef = new TrainSwitchListEditFrame(); tslef.initComponents(); } if (ae.getSource() == terminateButton) { trainManager.terminateSelectedTrains(getSortByList()); } if (ae.getSource() == saveButton) { storeValues(); } }