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 .ensureAtLeastPermission(PermissionsSystemAdmin.PERMISSION_EDIT_PREFERENCES, 076 BooleanPermission.BooleanValue.TRUE)) { 077 return; 078 } 079 TabbedPreferencesFrame f = InstanceManager.getOptionalDefault(TabbedPreferencesFrame.class).orElseGet(() -> { 080 return InstanceManager.setDefault(TabbedPreferencesFrame.class, new TabbedPreferencesFrame()); 081 }); 082 083 showPreferences(f); 084 085 } 086 087 private void showPreferences(TabbedPreferencesFrame f) { 088 // Update the GUI Look and Feel 089 // This is needed as certain controls are instantiated 090 // prior to the setup of the Look and Feel 091 092 // might not be a preferences item set yet 093 if (preferencesItem != null) f.gotoPreferenceItem(preferencesItem, preferenceSubCat); 094 095 f.pack(); 096 097 f.setVisible(true); 098 } 099 100 @Override 101 public void actionPerformed(ActionEvent e) { 102 actionPerformed(); 103 } 104 105 void setTitle() { //Note required as sub-panels will set them 106 } 107 108 String helpTarget() { 109 return "package.apps.TabbedPreferences"; 110 } 111 112 // never invoked, because we overrode actionPerformed above 113 @Override 114 public JmriPanel makePanel() { 115 throw new IllegalArgumentException("Should not be invoked"); 116 } 117 118 // private final static Logger log = LoggerFactory.getLogger(TabbedPreferencesAction.class); 119 120}