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