1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
|
---|
12 | import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
---|
13 | import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
---|
14 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
15 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
16 | import org.openstreetmap.josm.tools.Utils;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Open the Preferences dialog.
|
---|
20 | *
|
---|
21 | * @author imi
|
---|
22 | */
|
---|
23 | public 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 tooltip,
|
---|
29 | Class<? extends TabPreferenceSetting> tab, Class<? extends SubPreferenceSetting> subTab) {
|
---|
30 | super(name, "preference", tooltip, null, false, "preference_" + Utils.<Class>firstNonNull(tab, subTab).getName(), false);
|
---|
31 | this.tab = tab;
|
---|
32 | this.subTab = subTab;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public static PreferencesAction forPreferenceTab(String name, String tooltip, Class<? extends TabPreferenceSetting> tab) {
|
---|
36 | CheckParameterUtil.ensureParameterNotNull(tab);
|
---|
37 | return new PreferencesAction(name, tooltip, tab, null);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public static PreferencesAction forPreferenceSubTab(String name, String tooltip, Class<? extends SubPreferenceSetting> subTab) {
|
---|
41 | CheckParameterUtil.ensureParameterNotNull(subTab);
|
---|
42 | return new PreferencesAction(name, tooltip, null, subTab);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Create the preference action with "&Preferences" as label.
|
---|
47 | */
|
---|
48 | public PreferencesAction() {
|
---|
49 | super(tr("Preferences..."), "preference", tr("Open a preferences dialog for global settings."),
|
---|
50 | Shortcut.registerShortcut("system:preferences", tr("Preferences"), KeyEvent.VK_F12, Shortcut.DIRECT), true);
|
---|
51 | putValue("help", ht("/Action/Preferences"));
|
---|
52 | this.tab = null;
|
---|
53 | this.subTab = null;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Launch the preferences dialog.
|
---|
58 | */
|
---|
59 | @Override
|
---|
60 | public void actionPerformed(ActionEvent e) {
|
---|
61 | run();
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public void run() {
|
---|
66 | final PreferenceDialog p = new PreferenceDialog(Main.parent);
|
---|
67 | if (tab != null) {
|
---|
68 | p.selectPreferencesTabByClass(tab);
|
---|
69 | } else if( subTab != null) {
|
---|
70 | p.selectSubPreferencesTabByClass(subTab);
|
---|
71 | }
|
---|
72 | p.setVisible(true);
|
---|
73 | new PreferenceDialog(Main.parent).setVisible(true);
|
---|
74 | }
|
---|
75 | }
|
---|