001package jmri.jmrit.operations.locations.schedules; 002 003import java.awt.Dimension; 004import java.awt.FlowLayout; 005 006import javax.swing.*; 007 008import jmri.InstanceManager; 009import jmri.jmrit.operations.OperationsFrame; 010import jmri.jmrit.operations.locations.schedules.tools.*; 011import jmri.jmrit.operations.locations.tools.PrintLocationsAction; 012import jmri.jmrit.operations.setup.Control; 013import jmri.swing.JTablePersistenceManager; 014 015import org.slf4j.Logger; 016import org.slf4j.LoggerFactory; 017 018/** 019 * Frame for adding and editing the Schedule roster for operations. 020 * 021 * @author Bob Jacobsen Copyright (C) 2001 022 * @author Daniel Boudreau Copyright (C) 2009, 2012 023 */ 024public class SchedulesTableFrame extends OperationsFrame { 025 026 SchedulesTableModel schedulesModel = new SchedulesTableModel(); 027 javax.swing.JTable schedulesTable = new javax.swing.JTable(schedulesModel); 028 JScrollPane schedulesPane; 029 030 // labels 031 javax.swing.JLabel textSort = new javax.swing.JLabel(); 032 javax.swing.JLabel textSep = new javax.swing.JLabel(); 033 034 // radio buttons 035 javax.swing.JRadioButton sortByName = new javax.swing.JRadioButton(Bundle.getMessage("Name")); 036 javax.swing.JRadioButton sortById = new javax.swing.JRadioButton(Bundle.getMessage("Id")); 037 038 // major buttons 039 // javax.swing.JButton addButton = new javax.swing.JButton(); 040 public SchedulesTableFrame() { 041 super(Bundle.getMessage("TitleSchedulesTable")); 042 // general GUI config 043 044 getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); 045 046 // Set up the jtable in a Scroll Pane.. 047 schedulesPane = new JScrollPane(schedulesTable); 048 schedulesPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); 049 schedulesPane 050 .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 051 schedulesModel.initTable(this, schedulesTable); 052 getContentPane().add(schedulesPane); 053 054 // Set up the control panel 055 JPanel controlPanel = new JPanel(); 056 controlPanel.setLayout(new FlowLayout()); 057 058 textSort.setText(Bundle.getMessage("SortBy")); 059 controlPanel.add(textSort); 060 controlPanel.add(sortByName); 061 sortByName.setSelected(true); 062 controlPanel.add(sortById); 063 textSep.setText(" "); 064 controlPanel.add(textSep); 065 066 // TODO allow user to add schedule to a spur 067 // addButton.setText(Bundle.getMessage("Add")); 068 // addButton.setVisible(true); 069 // controlPanel.add (addButton); 070 controlPanel.setMaximumSize(new Dimension(Control.panelWidth1025, 50)); 071 getContentPane().add(controlPanel); 072 073 // set up buttons 074 // addButtonAction(addButton); 075 addRadioButtonAction(sortByName); 076 addRadioButtonAction(sortById); 077 078 // build menu 079 JMenuBar menuBar = new JMenuBar(); 080 JMenu toolMenu = new JMenu(Bundle.getMessage("MenuTools")); 081 toolMenu.add(new ScheduleCopyAction()); 082 toolMenu.add(new SchedulesResetHitsAction()); 083 toolMenu.addSeparator(); 084 toolMenu.add(new ExportSchedulesAction()); 085 toolMenu.addSeparator(); 086 toolMenu.add(new SchedulesByLoadAction()); 087 toolMenu.add(new SchedulesAndStagingAction()); 088 toolMenu.addSeparator(); 089 toolMenu.add(new PrintLocationsAction(false)); 090 toolMenu.add(new PrintLocationsAction(true)); 091 menuBar.add(toolMenu); 092 setJMenuBar(menuBar); 093 addHelpMenu("package.jmri.jmrit.operations.Operations_LocationSchedules", true); // NOI18N 094 095 initMinimumSize(); 096 // make panel a bit wider than minimum if the very first time opened 097 if (getWidth() == Control.panelWidth500) { 098 setSize(Control.panelWidth1025, getHeight()); 099 } 100 } 101 102 @Override 103 public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) { 104 log.debug("radio button activated"); 105 // clear any sorts by column 106 clearTableSort(schedulesTable); 107 if (ae.getSource() == sortByName) { 108 sortByName.setSelected(true); 109 sortById.setSelected(false); 110 schedulesModel.setSort(schedulesModel.SORTBYNAME); 111 } 112 if (ae.getSource() == sortById) { 113 sortByName.setSelected(false); 114 sortById.setSelected(true); 115 schedulesModel.setSort(schedulesModel.SORTBYID); 116 } 117 } 118 119 @Override 120 public void dispose() { 121 schedulesModel.dispose(); 122 InstanceManager.getOptionalDefault(JTablePersistenceManager.class).ifPresent(tpm -> { 123 tpm.stopPersisting(schedulesTable); 124 }); 125 super.dispose(); 126 } 127 128 private static final Logger log = LoggerFactory.getLogger(SchedulesTableFrame.class); 129}