source: josm/trunk/src/org/openstreetmap/josm/actions/PreferencesAction.java@ 17265

Last change on this file since 17265 was 17265, checked in by GerdP, 3 years ago

see #7548: Re-organize the preference dialog
Apply 7548-no-empty.patch to avoid empty top panel

  • make sure that a panel is selected when selectPreviouslySelectedPreferences() is called and nothing was previously selected
  • reverts r17097
  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9
10import org.openstreetmap.josm.gui.MainApplication;
11import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
12import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
13import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
14import org.openstreetmap.josm.tools.CheckParameterUtil;
15import org.openstreetmap.josm.tools.Shortcut;
16import org.openstreetmap.josm.tools.Utils;
17
18/**
19 * Open the Preferences dialog.
20 *
21 * @author imi
22 */
23public class PreferencesAction extends JosmAction implements Runnable {
24
25 private final Class<? extends TabPreferenceSetting> tab;
26 private final Class<? extends SubPreferenceSetting> subTab;
27
28 private PreferencesAction(String name, String icon, String tooltip,
29 Class<? extends TabPreferenceSetting> tab, Class<? extends SubPreferenceSetting> subTab) {
30 super(name, icon, tooltip, null, false, "preference_" + Utils.<Class<?>>firstNonNull(tab, subTab).getName(), false);
31 this.tab = tab;
32 this.subTab = subTab;
33 }
34
35 /**
36 * Returns a new {@code PreferenceAction} opening preferences dialog directly to the given tab, with default icon.
37 * @param name The action name
38 * @param tooltip The action tooltip
39 * @param tab The preferences tab to select
40 * @return The created action
41 */
42 public static PreferencesAction forPreferenceTab(String name, String tooltip, Class<? extends TabPreferenceSetting> tab) {
43 return forPreferenceTab(name, tooltip, tab, "preference");
44 }
45
46 /**
47 * Returns a new {@code PreferenceAction} opening preferences dialog directly to the given tab, with custom icon.
48 * @param name The action name
49 * @param tooltip The action tooltip
50 * @param tab The preferences tab to select
51 * @param icon The action icon
52 * @return The created action
53 * @since 6969
54 */
55 public static PreferencesAction forPreferenceTab(String name, String tooltip, Class<? extends TabPreferenceSetting> tab, String icon) {
56 CheckParameterUtil.ensureParameterNotNull(tab);
57 return new PreferencesAction(name, icon, tooltip, tab, null);
58 }
59
60 /**
61 * Returns a new {@code PreferenceAction} opening preferences dialog directly to the given subtab, with default icon.
62 * @param name The action name
63 * @param tooltip The action tooltip
64 * @param subTab The preferences subtab to select
65 * @return The created action
66 */
67 public static PreferencesAction forPreferenceSubTab(String name, String tooltip, Class<? extends SubPreferenceSetting> subTab) {
68 return forPreferenceSubTab(name, tooltip, subTab, "preference");
69 }
70
71 /**
72 * Returns a new {@code PreferenceAction} opening preferences dialog directly to the given subtab, with custom icon.
73 * @param name The action name
74 * @param tooltip The action tooltip
75 * @param subTab The preferences subtab to select
76 * @param icon The action icon
77 * @return The created action
78 * @since 6969
79 */
80 public static PreferencesAction forPreferenceSubTab(String name, String tooltip, Class<? extends SubPreferenceSetting> subTab, String icon) {
81 CheckParameterUtil.ensureParameterNotNull(subTab);
82 return new PreferencesAction(name, icon, tooltip, null, subTab);
83 }
84
85 /**
86 * Create the preference action with "Preferences" as label.
87 */
88 public PreferencesAction() {
89 super(tr("Preferences..."), "preference", tr("Open a preferences dialog for global settings."),
90 Shortcut.registerShortcut("system:preferences", tr("Edit: {0}", tr("Preferences")), KeyEvent.VK_F12, Shortcut.DIRECT),
91 true, false);
92 setHelpId(ht("/Action/Preferences"));
93 this.tab = null;
94 this.subTab = null;
95 }
96
97 /**
98 * Launch the preferences dialog.
99 */
100 @Override
101 public void actionPerformed(ActionEvent e) {
102 run();
103 }
104
105 @Override
106 public void run() {
107 final PreferenceDialog p = new PreferenceDialog(MainApplication.getMainFrame());
108 if (tab != null) {
109 p.selectPreferencesTabByClass(tab);
110 } else if (subTab != null) {
111 p.selectSubPreferencesTabByClass(subTab);
112 } else {
113 p.selectPreviouslySelectedPreferences();
114 }
115 p.setVisible(true);
116 }
117}
Note: See TracBrowser for help on using the repository browser.