[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[626] | 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
[2748] | 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
[626] | 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;
|
---|
[6426] | 12 | import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
---|
| 13 | import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
---|
| 14 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
[1084] | 15 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[6426] | 16 | import org.openstreetmap.josm.tools.Utils;
|
---|
[626] | 17 |
|
---|
| 18 | /**
|
---|
| 19 | * Open the Preferences dialog.
|
---|
| 20 | *
|
---|
| 21 | * @author imi
|
---|
| 22 | */
|
---|
[1647] | 23 | public class PreferencesAction extends JosmAction implements Runnable {
|
---|
[626] | 24 |
|
---|
[6426] | 25 | private final Class<? extends TabPreferenceSetting> tab;
|
---|
| 26 | private final Class<? extends SubPreferenceSetting> subTab;
|
---|
| 27 |
|
---|
[6969] | 28 | private PreferencesAction(String name, String icon, String tooltip,
|
---|
[6426] | 29 | Class<? extends TabPreferenceSetting> tab, Class<? extends SubPreferenceSetting> subTab) {
|
---|
[7022] | 30 | super(name, icon, tooltip, null, false, "preference_" + Utils.<Class<?>>firstNonNull(tab, subTab).getName(), false);
|
---|
[6426] | 31 | this.tab = tab;
|
---|
| 32 | this.subTab = subTab;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[6969] | 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 | */
|
---|
[6426] | 42 | public static PreferencesAction forPreferenceTab(String name, String tooltip, Class<? extends TabPreferenceSetting> tab) {
|
---|
[6969] | 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) {
|
---|
[6426] | 56 | CheckParameterUtil.ensureParameterNotNull(tab);
|
---|
[6969] | 57 | return new PreferencesAction(name, icon, tooltip, tab, null);
|
---|
[6426] | 58 | }
|
---|
| 59 |
|
---|
[6969] | 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 | */
|
---|
[6426] | 67 | public static PreferencesAction forPreferenceSubTab(String name, String tooltip, Class<? extends SubPreferenceSetting> subTab) {
|
---|
[6969] | 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) {
|
---|
[6426] | 81 | CheckParameterUtil.ensureParameterNotNull(subTab);
|
---|
[6969] | 82 | return new PreferencesAction(name, icon, tooltip, null, subTab);
|
---|
[6426] | 83 | }
|
---|
| 84 |
|
---|
[1169] | 85 | /**
|
---|
[6830] | 86 | * Create the preference action with "Preferences" as label.
|
---|
[1169] | 87 | */
|
---|
| 88 | public PreferencesAction() {
|
---|
[2748] | 89 | super(tr("Preferences..."), "preference", tr("Open a preferences dialog for global settings."),
|
---|
[4982] | 90 | Shortcut.registerShortcut("system:preferences", tr("Preferences"), KeyEvent.VK_F12, Shortcut.DIRECT), true);
|
---|
[2323] | 91 | putValue("help", ht("/Action/Preferences"));
|
---|
[6426] | 92 | this.tab = null;
|
---|
| 93 | this.subTab = null;
|
---|
[1169] | 94 | }
|
---|
[626] | 95 |
|
---|
[1169] | 96 | /**
|
---|
| 97 | * Launch the preferences dialog.
|
---|
| 98 | */
|
---|
[6084] | 99 | @Override
|
---|
[1169] | 100 | public void actionPerformed(ActionEvent e) {
|
---|
[1733] | 101 | run();
|
---|
[1647] | 102 | }
|
---|
| 103 |
|
---|
[6084] | 104 | @Override
|
---|
[1647] | 105 | public void run() {
|
---|
[6426] | 106 | final PreferenceDialog p = new PreferenceDialog(Main.parent);
|
---|
| 107 | if (tab != null) {
|
---|
| 108 | p.selectPreferencesTabByClass(tab);
|
---|
[8443] | 109 | } else if (subTab != null) {
|
---|
[6426] | 110 | p.selectSubPreferencesTabByClass(subTab);
|
---|
| 111 | }
|
---|
| 112 | p.setVisible(true);
|
---|
[1169] | 113 | }
|
---|
[626] | 114 | }
|
---|