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