001package jmri.jmrit.throttle; 002 003import java.awt.*; 004import java.beans.PropertyChangeEvent; 005import java.beans.PropertyChangeListener; 006 007import javax.swing.*; 008 009import jmri.InstanceManager; 010import jmri.swing.PreferencesPanel; 011 012import org.openide.util.lookup.ServiceProvider; 013 014/** 015 * A preferences panel to display and edit JMRI throttle keyboard shortcuts 016 * 017 * @author Lionel Jeanson - 2009-2021 018 * 019 */ 020@ServiceProvider(service = PreferencesPanel.class) 021public class ThrottlesPreferencesPane extends JPanel implements PropertyChangeListener, PreferencesPanel { 022 023 private ThrottlesPreferencesUISettingsPane uiSettingsPane; 024 private ThrottlesPreferencesControlsSettingsPane ctrlSettingsPane; 025 026 /** 027 * Creates new form ThrottlesPreferencesPane 028 */ 029 public ThrottlesPreferencesPane() { 030 initComponents(); 031 } 032 033 private void initComponents() { 034 ThrottlesPreferences tp = InstanceManager.getDefault(ThrottlesPreferences.class); 035 tp.addPropertyChangeListener(this); 036 037 uiSettingsPane = new ThrottlesPreferencesUISettingsPane(tp); 038 ctrlSettingsPane = new ThrottlesPreferencesControlsSettingsPane(tp); 039 040 JScrollPane scrollPane1 = new JScrollPane(uiSettingsPane); 041 JScrollPane scrollPane2 = new JScrollPane(ctrlSettingsPane); 042 043 JTabbedPane tabbedPane = new JTabbedPane(); 044 tabbedPane.addTab(Bundle.getMessage("UISettingsPane"),scrollPane1); 045 tabbedPane.addTab(Bundle.getMessage("ControlsSettingsPane"),scrollPane2); 046 047 this.setLayout(new BorderLayout()); 048 this.add(tabbedPane, BorderLayout.CENTER); 049 } 050 051 @Override 052 public void propertyChange(PropertyChangeEvent evt) { 053 if ((evt == null) || (evt.getPropertyName() == null)) { 054 return; 055 } 056 if (evt.getPropertyName().compareTo("ThrottlePreferences") == 0) { 057 if ((evt.getNewValue() == null) || (!(evt.getNewValue() instanceof ThrottlesPreferences))) { 058 return; 059 } 060 uiSettingsPane.resetComponents((ThrottlesPreferences) evt.getNewValue()); 061 ctrlSettingsPane.resetComponents((ThrottlesPreferences) evt.getNewValue()); 062 } 063 } 064 065 public void resetComponents() { 066 ThrottlesPreferences tp = InstanceManager.getDefault(ThrottlesPreferences.class); 067 uiSettingsPane.resetComponents(tp); 068 ctrlSettingsPane.resetComponents(tp); 069 } 070 071 @Override 072 public String getPreferencesItem() { 073 return "THROTTLE"; 074 } 075 076 @Override 077 public String getPreferencesItemText() { 078 return Bundle.getMessage("MenuThrottle"); 079 } 080 081 @Override 082 public String getTabbedPreferencesTitle() { 083 return null; 084 } 085 086 @Override 087 public String getLabelKey() { 088 return null; 089 } 090 091 @Override 092 public JComponent getPreferencesComponent() { 093 return this; 094 } 095 096 @Override 097 public boolean isPersistant() { 098 return false; 099 } 100 101 @Override 102 public String getPreferencesTooltip() { 103 return null; 104 } 105 106 @Override 107 public void savePreferences() { 108 applyPreferences(); 109 InstanceManager.getDefault(ThrottlesPreferences.class).save(); 110 } 111 112 void applyPreferences() { 113 ThrottlesPreferences tp = InstanceManager.getDefault(ThrottlesPreferences.class); 114 uiSettingsPane.updateThrottlesPreferences(tp); 115 ctrlSettingsPane.updateThrottlesPreferences(tp); 116 InstanceManager.getDefault(ThrottlesPreferences.class).set(tp); 117 InstanceManager.getDefault(ThrottleFrameManager.class).applyPreferences(); 118 } 119 120 @Override 121 public boolean isDirty() { 122 return uiSettingsPane.isDirty() && ctrlSettingsPane.isDirty(); 123 } 124 125 @Override 126 public boolean isRestartRequired() { 127 return false; 128 } 129 130 @Override 131 public boolean isPreferencesValid() { 132 return true; // no validity checking performed 133 } 134 135 // private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ThrottlesPreferencesPane.class); 136}