001package apps.gui3.tabbedpreferences; 002 003import java.awt.event.ActionEvent; 004import javax.swing.Icon; 005 006import jmri.InstanceManager; 007import jmri.util.swing.JmriPanel; 008import jmri.util.swing.WindowInterface; 009 010/** 011 * Action launches the tabbed preferences window. 012 * 013 * The {@link TabbedPreferencesFrame} object is requested from the InstanceManager, and 014 * if need-be created and initialized in the process of doing that. 015 * 016 * @author Kevin Dickerson Copyright (C) 2009 017 * @author Bob Jacobsen Copyright (C) 2019 018 */ 019public class TabbedPreferencesAction extends jmri.util.swing.JmriAbstractAction { 020 021 String preferencesItem = null; 022 String preferenceSubCat = null; 023 024 /** 025 * Create an action with a specific title. 026 * <p> 027 * Note that the argument is the Action title, not the title of the 028 * resulting frame. Perhaps this should be changed? 029 * 030 * @param s action title 031 * @param category action category 032 * @param subCategory action sub-category 033 */ 034 public TabbedPreferencesAction(String s, String category, String subCategory) { 035 super(s); 036 preferencesItem = category; 037 preferenceSubCat = subCategory; 038 } 039 040 public TabbedPreferencesAction(String s, String category) { 041 super(s); 042 preferencesItem = category; 043 } 044 045 public TabbedPreferencesAction(String s) { 046 super(s); 047 } 048 049 public TabbedPreferencesAction() { 050 this(Bundle.getMessage("MenuItemPreferences")); 051 } 052 053 public TabbedPreferencesAction(String s, WindowInterface wi) { 054 super(s, wi); 055 } 056 057 public TabbedPreferencesAction(String s, Icon i, WindowInterface wi) { 058 super(s, i, wi); 059 } 060 061 public TabbedPreferencesAction(String s, WindowInterface wi, String category, String subCategory) { 062 super(s, wi); 063 preferencesItem = category; 064 preferenceSubCat = subCategory; 065 } 066 067 public TabbedPreferencesAction(String s, Icon i, WindowInterface wi, String category) { 068 super(s, i, wi); 069 preferencesItem = category; 070 } 071 072 final public void actionPerformed() { 073 TabbedPreferencesFrame f = InstanceManager.getOptionalDefault(TabbedPreferencesFrame.class).orElseGet(() -> { 074 return InstanceManager.setDefault(TabbedPreferencesFrame.class, new TabbedPreferencesFrame()); 075 }); 076 077 showPreferences(f); 078 079 } 080 081 private void showPreferences(TabbedPreferencesFrame f) { 082 // Update the GUI Look and Feel 083 // This is needed as certain controls are instantiated 084 // prior to the setup of the Look and Feel 085 086 // might not be a preferences item set yet 087 if (preferencesItem != null) f.gotoPreferenceItem(preferencesItem, preferenceSubCat); 088 089 f.pack(); 090 091 f.setVisible(true); 092 } 093 094 @Override 095 public void actionPerformed(ActionEvent e) { 096 actionPerformed(); 097 } 098 099 void setTitle() { //Note required as sub-panels will set them 100 } 101 102 String helpTarget() { 103 return "package.apps.TabbedPreferences"; 104 } 105 106 // never invoked, because we overrode actionPerformed above 107 @Override 108 public JmriPanel makePanel() { 109 throw new IllegalArgumentException("Should not be invoked"); 110 } 111 112 // private final static Logger log = LoggerFactory.getLogger(TabbedPreferencesAction.class); 113 114}