001package jmri.jmrit.beantable; 002 003import java.awt.event.ActionEvent; 004import javax.swing.JMenu; 005import javax.swing.JMenuBar; 006import javax.swing.JMenuItem; 007 008import jmri.SignalMast; 009import jmri.jmrit.beantable.signalmast.SignalMastTableDataModel; 010import org.slf4j.Logger; 011import org.slf4j.LoggerFactory; 012 013/** 014 * Swing action to create and register a SignalMastTable GUI. 015 * 016 * @author Bob Jacobsen Copyright (C) 2003, 2009, 2010 017 */ 018public class SignalMastTableAction extends AbstractTableAction<SignalMast> { 019 020 /** 021 * Create an action with a specific title. 022 * <p> 023 * Note that the argument is the Action title, not the title of the 024 * resulting frame. Perhaps this should be changed? 025 * 026 * @param actionName title of the action 027 */ 028 public SignalMastTableAction(String actionName) { 029 super(actionName); 030 } 031 032 public SignalMastTableAction() { 033 this(Bundle.getMessage("TitleSignalMastTable")); 034 } 035 036 /** 037 * Create the JTable DataModel, along with the changes for the specific case 038 * of Signal Masts. 039 */ 040 @Override 041 protected void createModel() { 042 m = new SignalMastTableDataModel(); 043 } 044 045 @Override 046 protected void setTitle() { 047 f.setTitle(Bundle.getMessage("TitleSignalMastTable")); 048 } 049 050 @Override 051 protected String helpTarget() { 052 return "package.jmri.jmrit.beantable.SignalMastTable"; 053 } 054 055 // prepare the Add Signal Mast frame 056 jmri.jmrit.beantable.signalmast.AddSignalMastJFrame addFrame = null; 057 058 // has to agree with number in SignalMastDataModel 059 final static int VALUECOL = BeanTableDataModel.VALUECOL; 060 final static int SYSNAMECOL = BeanTableDataModel.SYSNAMECOL; 061 062 @Override 063 protected void addPressed(ActionEvent e) { 064 if (addFrame == null) { 065 addFrame = new jmri.jmrit.beantable.signalmast.AddSignalMastJFrame(); 066 } else { 067 addFrame.refresh(); 068 } 069 addFrame.setVisible(true); 070 } 071 072 /** 073 * Insert a table specific Tools menu. 074 * Account for the Window and Help menus, which are already added to the menu bar 075 * as part of the creation of the JFrame, by adding the Tools menu 2 places earlier 076 * unless the table is part of the ListedTableFrame, that adds the Help menu later on. 077 * @param f the JFrame of this table 078 */ 079 @Override 080 public void setMenuBar(BeanTableFrame<SignalMast> f) { 081 JMenuBar menuBar = f.getJMenuBar(); 082 int pos = menuBar.getMenuCount() -1; // count the number of menus to insert the TableMenu before 'Window' and 'Help' 083 int offset = 1; 084 log.debug("setMenuBar number of menu items = {}", pos); 085 for (int i = 0; i <= pos; i++) { 086 if (menuBar.getComponent(i) instanceof JMenu) { 087 if (((JMenu) menuBar.getComponent(i)).getText().equals(Bundle.getMessage("MenuHelp"))) { 088 offset = -1; // correct for use as part of ListedTableAction where the Help Menu is not yet present 089 } 090 } 091 } 092 JMenu pathMenu = new JMenu(Bundle.getMessage("MenuTools")); 093 menuBar.add(pathMenu, pos + offset); 094 JMenuItem item = new JMenuItem(Bundle.getMessage("MenuItemRepeaters")); 095 pathMenu.add(item); 096 item.addActionListener(e -> { 097 jmri.jmrit.beantable.signalmast.SignalMastRepeaterJFrame frame = new jmri.jmrit.beantable.signalmast.SignalMastRepeaterJFrame(); 098 frame.setVisible(true); 099 }); 100 } 101 102 @Override 103 protected String getClassName() { 104 return SignalMastTableAction.class.getName(); 105 } 106 107 @Override 108 public String getClassDescription() { 109 return Bundle.getMessage("TitleSignalMastTable"); 110 } 111 112 private final static Logger log = LoggerFactory.getLogger(SignalMastTableAction.class); 113 114}