1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.shortcut;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import javax.swing.JPanel;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
|
---|
9 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
10 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
11 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
12 | import org.openstreetmap.josm.tools.GBC;
|
---|
13 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Keyboard shortcut preferences.
|
---|
17 | */
|
---|
18 | public final class ShortcutPreference extends DefaultTabPreferenceSetting {
|
---|
19 |
|
---|
20 | private String defaultFilter;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Factory used to create a new {@code ShortcutPreference}.
|
---|
24 | */
|
---|
25 | public static class Factory implements PreferenceSettingFactory {
|
---|
26 | @Override
|
---|
27 | public PreferenceSetting createPreferenceSetting() {
|
---|
28 | return new ShortcutPreference();
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | private ShortcutPreference() {
|
---|
33 | super("shortcuts", tr("Keyboard Shortcuts"), tr("Changing keyboard shortcuts manually."));
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void addGui(PreferenceTabbedPane gui) {
|
---|
38 | JPanel p = gui.createPreferenceTab(this);
|
---|
39 |
|
---|
40 | PrefJPanel prefpanel = new PrefJPanel();
|
---|
41 | p.add(prefpanel, GBC.eol().fill(GBC.BOTH));
|
---|
42 | if (defaultFilter != null) {
|
---|
43 | prefpanel.filter(defaultFilter);
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public boolean ok() {
|
---|
49 | return Shortcut.savePrefs();
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Sets the default filter used to show only shortcuts with descriptions containing given substring.
|
---|
54 | * @param substring The substring used to filter
|
---|
55 | * @see PrefJPanel#filter(String)
|
---|
56 | */
|
---|
57 | public void setDefaultFilter(String substring) {
|
---|
58 | defaultFilter = substring;
|
---|
59 | }
|
---|
60 | }
|
---|