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

Last change on this file since 17188 was 17188, checked in by Klumbumbus, 4 years ago

fix #19851 - Fix shortcut names

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