1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui.preferences;
|
---|
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.tools.GBC;
|
---|
12 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
13 |
|
---|
14 | public class ShortcutPreference implements PreferenceSetting {
|
---|
15 |
|
---|
16 | public static class Factory implements PreferenceSettingFactory {
|
---|
17 | public PreferenceSetting createPreferenceSetting() {
|
---|
18 | return new ShortcutPreference();
|
---|
19 | }
|
---|
20 | }
|
---|
21 |
|
---|
22 | public void addGui(PreferenceTabbedPane gui) {
|
---|
23 | // 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
|
---|
24 | // icon licence: GPL
|
---|
25 | // icon designer: Paolino, http://www.paolinoland.it/
|
---|
26 | // icon original filename: keyboard.png
|
---|
27 | // icon original size: 128x128
|
---|
28 | // modifications: icon was cropped, then resized
|
---|
29 | JPanel p = gui.createPreferenceTab("shortcuts", tr("Shortcut Preferences"),
|
---|
30 | tr("Changing keyboard shortcuts manually."), false);
|
---|
31 |
|
---|
32 | PrefJPanel prefpanel = new PrefJPanel(new scListModel());
|
---|
33 | p.add(prefpanel, GBC.eol().fill(GBC.BOTH));
|
---|
34 |
|
---|
35 | }
|
---|
36 |
|
---|
37 | public boolean ok() {
|
---|
38 | return Shortcut.savePrefs();
|
---|
39 | }
|
---|
40 |
|
---|
41 | // Maybe move this to prefPanel? There's no need for it to be here.
|
---|
42 | private static class scListModel extends AbstractTableModel {
|
---|
43 | private String[] columnNames = new String[]{tr("Action"), tr("Shortcut")};
|
---|
44 | private List<Shortcut> data;
|
---|
45 |
|
---|
46 | public scListModel() {
|
---|
47 | data = Shortcut.listAll();
|
---|
48 | }
|
---|
49 | public int getColumnCount() {
|
---|
50 | return columnNames.length;
|
---|
51 | }
|
---|
52 | public int getRowCount() {
|
---|
53 | return data.size();
|
---|
54 | }
|
---|
55 | @Override
|
---|
56 | public String getColumnName(int col) {
|
---|
57 | return columnNames[col];
|
---|
58 | }
|
---|
59 | public Object getValueAt(int row, int col) {
|
---|
60 | Shortcut sc = data.get(row);
|
---|
61 | if (col == 0)
|
---|
62 | return sc.getLongText();
|
---|
63 | else if (col == 1)
|
---|
64 | return sc.getKeyText();
|
---|
65 | else
|
---|
66 | // This is a kind of hack that allows the actions on the editing controls
|
---|
67 | // to access the underlying shortcut object without introducing another
|
---|
68 | // method. I opted to stay within the interface.
|
---|
69 | return sc;
|
---|
70 | }
|
---|
71 | @Override
|
---|
72 | public boolean isCellEditable(int row, int col) {
|
---|
73 | return false;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|