001package jmri.jmrit.progsupport; 002 003import java.awt.FlowLayout; 004import javax.swing.BoxLayout; 005import javax.swing.JButton; 006import javax.swing.JFrame; 007import javax.swing.JLabel; 008import jmri.Programmer; 009import org.slf4j.Logger; 010import org.slf4j.LoggerFactory; 011 012/** 013 * Provide a JPanel to configure the service mode programmer via a "simple until 014 * you need it" pane. This consists of a label with the current mode, plus a 015 * "set" button. 016 * <p> 017 * A ProgModePane may "share" between one of these and an ops-mode selection, 018 * which means that there might be _none_ of these modes selected. When that 019 * happens, the mode of the underlying programmer is left unchanged and no 020 * message is propagated. 021 * <p> 022 * Note that you should call the dispose() method when you're really done, so 023 * that a ProgModePane object can disconnect its listeners. 024 * <p> 025 * The implementation relies on a captive ProgServiceModePane which handles 026 * "set" operations by changing the actual service mode programmer state. 027 * 028 * <hr> 029 * This file is part of JMRI. 030 * <p> 031 * JMRI is free software; you can redistribute it and/or modify it under the 032 * terms of version 2 of the GNU General Public License as published by the Free 033 * Software Foundation. See the "COPYING" file for a copy of this license. 034 * <p> 035 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY 036 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 037 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 038 * 039 * @author Bob Jacobsen Copyright (C) 2001, 2014 040 */ 041public class ProgDeferredServiceModePane extends ProgModeSelector implements java.beans.PropertyChangeListener { 042 043 ProgServiceModePane servicePane; 044 JFrame setFrame; 045 JLabel currentMode = new JLabel(); 046 protected JButton setButton = new JButton(java.util.ResourceBundle.getBundle("jmri/jmrit/symbolicprog/SymbolicProgBundle").getString("SET...")); 047 048 /** 049 * Enable/Disable the "set" button in GUI 050 * 051 * @param enabled false disables button 052 */ 053 @Override 054 public void setEnabled(boolean enabled) { 055 setButton.setEnabled(enabled); 056 } 057 058 /** 059 * Get the configured programmer 060 */ 061 @Override 062 public Programmer getProgrammer() { 063 return servicePane.getProgrammer(); 064 } 065 066 /** 067 * 068 * @return true always, as we expect to always be selected 069 */ 070 @Override 071 public boolean isSelected() { 072 return true; 073 } 074 075 /** 076 * Create the object. There are no parameters, as there's only a single 077 * layout now. 078 */ 079 public ProgDeferredServiceModePane() { 080 servicePane = new ProgServiceModePane(BoxLayout.Y_AXIS); 081 082 // arrange activation 083 setButton.addActionListener(new java.awt.event.ActionListener() { 084 @Override 085 public void actionPerformed(java.awt.event.ActionEvent e) { 086 // pop the frame 087 setFrame.setVisible(true); 088 } 089 }); 090 091 // create the set frame 092 setFrame = new JFrame(Bundle.getMessage("TitleSetProgrammingMode")); 093 setFrame.getContentPane().add(servicePane); 094 setFrame.pack(); 095 096 // create the main GUI 097 setLayout(new FlowLayout()); 098 add(currentMode); 099 add(setButton); 100 101 log.error("This is missing code to listen to the programmer and update the mode display"); 102 } 103 104 @Override 105 public void propertyChange(java.beans.PropertyChangeEvent e) { 106 if (e.getPropertyName().equals("Mode")) { 107 // mode changed in programmer, change GUI here if needed 108 // take the mode from the message, not the programmer, to get 109 // proper synchronization 110 log.error("ProgDeferredServiceModePane isn't handling mode changes yet"); 111 //ProgrammingMode mode = (ProgrammingMode)e.getNewValue(); 112 //updateStatus(mode); 113 } else { 114 log.warn("propertyChange with unexpected propertyName: {}", e.getPropertyName()); 115 } 116 } 117 118 // no longer needed, disconnect if still connected 119 @Override 120 public void dispose() { 121 } 122 123 private final static Logger log = LoggerFactory.getLogger(ProgDeferredServiceModePane.class); 124}