1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui.preferences.shortcut;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import javax.swing.JPanel;
|
---|
9 | import javax.swing.table.AbstractTableModel;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
|
---|
12 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
13 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
14 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
15 | import org.openstreetmap.josm.tools.GBC;
|
---|
16 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
17 |
|
---|
18 | public class ShortcutPreference extends DefaultTabPreferenceSetting {
|
---|
19 |
|
---|
20 | private String defaultFilter;
|
---|
21 |
|
---|
22 | public static class Factory implements PreferenceSettingFactory {
|
---|
23 | public PreferenceSetting createPreferenceSetting() {
|
---|
24 | return new ShortcutPreference();
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | private ShortcutPreference() {
|
---|
29 | // icon source: http://www.iconfinder.net/index.php?q=key&page=icondetails&iconid=8553&size=128&q=key&s12=on&s16=on&s22=on&s32=on&s48=on&s64=on&s128=on
|
---|
30 | // icon licence: GPL
|
---|
31 | // icon designer: Paolino, http://www.paolinoland.it/
|
---|
32 | // icon original filename: keyboard.png
|
---|
33 | // icon original size: 128x128
|
---|
34 | // modifications: icon was cropped, then resized
|
---|
35 | super("shortcuts", tr("Keyboard Shortcuts"), tr("Changing keyboard shortcuts manually."));
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public void addGui(PreferenceTabbedPane gui) {
|
---|
40 | JPanel p = gui.createPreferenceTab(this);
|
---|
41 |
|
---|
42 | PrefJPanel prefpanel = new PrefJPanel(new scListModel());
|
---|
43 | p.add(prefpanel, GBC.eol().fill(GBC.BOTH));
|
---|
44 | if (defaultFilter!=null) prefpanel.filter(defaultFilter);
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public boolean ok() {
|
---|
49 | return Shortcut.savePrefs();
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void setDefaultFilter(String substring) {
|
---|
53 | defaultFilter = substring;
|
---|
54 | }
|
---|
55 |
|
---|
56 | // Maybe move this to prefPanel? There's no need for it to be here.
|
---|
57 | private static class scListModel extends AbstractTableModel {
|
---|
58 | private String[] columnNames = new String[]{tr("Action"), tr("Shortcut")};
|
---|
59 | private List<Shortcut> data;
|
---|
60 |
|
---|
61 | public scListModel() {
|
---|
62 | data = Shortcut.listAll();
|
---|
63 | }
|
---|
64 | @Override
|
---|
65 | public int getColumnCount() {
|
---|
66 | return columnNames.length;
|
---|
67 | }
|
---|
68 | @Override
|
---|
69 | public int getRowCount() {
|
---|
70 | return data.size();
|
---|
71 | }
|
---|
72 | @Override
|
---|
73 | public String getColumnName(int col) {
|
---|
74 | return columnNames[col];
|
---|
75 | }
|
---|
76 | @Override
|
---|
77 | public Object getValueAt(int row, int col) {
|
---|
78 | return (col==0)? data.get(row).getLongText() : data.get(row);
|
---|
79 | }
|
---|
80 | @Override
|
---|
81 | public boolean isCellEditable(int row, int col) {
|
---|
82 | return false;
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|