001package jmri.jmrit.operations.routes.gui; 002 003import java.awt.Dimension; 004import java.awt.FlowLayout; 005 006import javax.swing.*; 007 008import org.slf4j.Logger; 009import org.slf4j.LoggerFactory; 010 011import jmri.InstanceManager; 012import jmri.jmrit.operations.OperationsFrame; 013import jmri.jmrit.operations.routes.tools.*; 014import jmri.jmrit.operations.setup.Control; 015import jmri.swing.JTablePersistenceManager; 016 017/** 018 * Frame for adding and editing the route roster for operations. 019 * 020 * @author Bob Jacobsen Copyright (C) 2001 021 * @author Daniel Boudreau Copyright (C) 2008, 2009 022 */ 023public class RoutesTableFrame extends OperationsFrame { 024 025 RoutesTableModel routesModel = new RoutesTableModel(); 026 JTable routesTable; 027 028 // labels 029 JLabel textSort = new JLabel(Bundle.getMessage("SortBy")); 030 JLabel textSep = new JLabel(" "); 031 032 // radio buttons 033 JRadioButton sortByName = new JRadioButton(Bundle.getMessage("Name")); 034 JRadioButton sortById = new JRadioButton(Bundle.getMessage("Id")); 035 036 // major buttons 037 JButton addButton = new JButton(Bundle.getMessage("AddRoute")); 038 039 public RoutesTableFrame() { 040 super(Bundle.getMessage("TitleRoutesTable")); 041 // general GUI config 042 043 getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); 044 045 // Set up the jtable in a Scroll Pane.. 046 routesTable = new JTable(routesModel); 047 JScrollPane routesPane = new JScrollPane(routesTable); 048 routesPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); 049 routesModel.initTable(this, routesTable); 050 getContentPane().add(routesPane); 051 052 // Set up the control panel 053 JPanel controlPanel = new JPanel(); 054 controlPanel.setLayout(new FlowLayout()); 055 056 controlPanel.add(textSort); 057 controlPanel.add(sortByName); 058 controlPanel.add(sortById); 059 controlPanel.add(textSep); 060 controlPanel.add(addButton); 061 controlPanel.setMaximumSize(new Dimension(Control.panelWidth1025, 50)); 062 063 getContentPane().add(controlPanel); 064 065 sortByName.setSelected(true); 066 067 // setup buttons 068 addButtonAction(addButton); 069 addButton.setToolTipText(Bundle.getMessage("AddRouteTip")); 070 071 addRadioButtonAction(sortByName); 072 addRadioButtonAction(sortById); 073 074 ButtonGroup bGroup = new ButtonGroup(); 075 bGroup.add(sortByName); 076 bGroup.add(sortById); 077 078 // build menu 079 JMenuBar menuBar = new JMenuBar(); 080 JMenu toolMenu = new JMenu(Bundle.getMessage("MenuTools")); 081 toolMenu.add(new RouteCopyAction()); 082 toolMenu.add(new SetTrainIconPositionAction()); 083 toolMenu.addSeparator(); 084 toolMenu.add(new ExportRoutesAction()); 085 toolMenu.add(new ImportRoutesAction()); 086 toolMenu.addSeparator(); 087 toolMenu.add(new ShowRoutesServingLocationAction(null)); 088 toolMenu.addSeparator(); 089 toolMenu.add(new PrintRoutesAction(false)); 090 toolMenu.add(new PrintRoutesAction(true)); 091 092 menuBar.add(toolMenu); 093 menuBar.add(new jmri.jmrit.operations.OperationsMenu()); 094 setJMenuBar(menuBar); 095 096 // add help menu to window 097 addHelpMenu("package.jmri.jmrit.operations.Operations_Routes", true); // NOI18N 098 099 initMinimumSize(new Dimension(Control.panelWidth700, Control.panelHeight300)); 100 101 // create ShutDownTasks 102 createShutDownTask(); 103 } 104 105 @Override 106 public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) { 107 log.debug("radio button activated"); 108 // clear any sorts by column 109 clearTableSort(routesTable); 110 if (ae.getSource() == sortByName) { 111 routesModel.setSort(routesModel.SORTBYNAME); 112 } 113 if (ae.getSource() == sortById) { 114 routesModel.setSort(routesModel.SORTBYID); 115 } 116 } 117 118 // add button 119 @Override 120 public void buttonActionPerformed(java.awt.event.ActionEvent ae) { 121 // log.debug("route button activated"); 122 if (ae.getSource() == addButton) { 123 RouteEditFrame f = new RouteEditFrame(); 124 f.initComponents(null); 125 } 126 } 127 128 @Override 129 public void dispose() { 130 InstanceManager.getOptionalDefault(JTablePersistenceManager.class).ifPresent(tpm -> { 131 tpm.stopPersisting(routesTable); 132 }); 133 routesModel.dispose(); 134 super.dispose(); 135 } 136 137 private final static Logger log = LoggerFactory.getLogger(RoutesTableFrame.class); 138}