001package jmri.jmrit.symbolicprog.tabbedframe; 002 003import java.awt.event.ActionEvent; 004import java.awt.event.WindowAdapter; 005import java.awt.event.WindowEvent; 006import java.io.File; 007import javax.annotation.Nonnull; 008import javax.swing.AbstractAction; 009import javax.swing.BoxLayout; 010import javax.swing.JFrame; 011import javax.swing.JLabel; 012import javax.swing.JMenu; 013import javax.swing.JMenuBar; 014import javax.swing.JPanel; 015import javax.swing.JSeparator; 016import jmri.jmrit.decoderdefn.DecoderFile; 017import jmri.jmrit.roster.RosterEntry; 018import jmri.jmrit.symbolicprog.CombinedLocoSelTreePane; 019import jmri.jmrit.symbolicprog.SymbolicProgBundle; 020import jmri.util.JmriJFrame; 021import org.slf4j.Logger; 022import org.slf4j.LoggerFactory; 023 024/** 025 * Swing action to create and register a frame for selecting the information 026 * needed to open a PaneProgFrame in service mode. 027 * <p> 028 * The name is a historical accident, and probably should have included 029 * "ServiceMode" or something. 030 * <p> 031 * The resulting JFrame is constructed on the fly here, and has no specific 032 * type. 033 * 034 * @see jmri.jmrit.symbolicprog.tabbedframe.PaneOpsProgAction 035 * 036 * @author Bob Jacobsen Copyright (C) 2001 037 */ 038public class PaneProgAction extends AbstractAction { 039 040 Object o1, o2, o3, o4; 041 JLabel statusLabel; 042 jmri.jmrit.progsupport.ProgModeSelector modePane = new jmri.jmrit.progsupport.ProgServiceModeComboBox(); 043 044 public PaneProgAction() { 045 this("DecoderPro service programmer"); 046 } 047 048 public PaneProgAction(String s) { 049 super(s); 050 051 statusLabel = new JLabel(SymbolicProgBundle.getMessage("StateIdle")); 052 053 // disable ourself if programming is not possible 054 if (jmri.InstanceManager.getNullableDefault(jmri.GlobalProgrammerManager.class) == null 055 || !jmri.InstanceManager.getDefault(jmri.GlobalProgrammerManager.class).isGlobalProgrammerAvailable()) { 056 setEnabled(false); 057 // This needs to return, so we don't start the xmlThread 058 } 059 } 060 061 @Override 062 public void actionPerformed(ActionEvent e) { 063 log.debug("Pane programmer requested"); 064 065 // create the initial frame that steers 066 final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameServiceProgrammerSetup")); 067 f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS)); 068 069 // ensure status line is cleared on close so it is normal if re-opened 070 f.addWindowListener(new WindowAdapter() { 071 @Override 072 public void windowClosing(WindowEvent we) { 073 statusLabel.setText(SymbolicProgBundle.getMessage("StateIdle")); 074 f.windowClosing(we); 075 } 076 }); 077 078 // add the Roster menu 079 JMenuBar menuBar = new JMenuBar(); 080 // menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); 081 JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile")); 082 j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false)); 083 j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true)); 084 menuBar.add(j); 085 menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f)); 086 f.setJMenuBar(menuBar); 087 088 // new Loco on programming track 089 JPanel pane1 = new CombinedLocoSelTreePane(statusLabel, modePane) { 090 091 @Override 092 protected void startProgrammer(DecoderFile decoderFile, @Nonnull RosterEntry re, 093 @Nonnull String filename) { 094 String title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), re.getId()); 095 JFrame p = new PaneServiceProgFrame(decoderFile, re, 096 title, "programmers" + File.separator + filename + ".xml", 097 modePane.getProgrammer()); 098 p.pack(); 099 p.setVisible(true); 100 101 // f.setVisible(false); 102 // f.dispose(); 103 } 104 }; 105 106 // load primary frame 107 JPanel tempPane = new JPanel(); 108 tempPane.add(modePane); 109 f.getContentPane().add(tempPane); 110 f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL)); 111 112 pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT); 113 f.getContentPane().add(pane1); 114 f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL)); 115 116 statusLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT); 117 f.getContentPane().add(statusLabel); 118 119 f.pack(); 120 log.debug("Tab-Programmer setup created"); 121 f.setVisible(true); 122 } 123 124 private final static Logger log = LoggerFactory.getLogger(PaneProgAction.class); 125 126}