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.Collection;
|
---|
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 false;
|
---|
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"), tr("Group"), tr("ID")};
|
---|
44 | private String[] columnNames = new String[]{tr("Action"), tr("Shortcut")};
|
---|
45 | private Collection<Shortcut> data;
|
---|
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 | public String getColumnName(int col) {
|
---|
56 | return columnNames[col];
|
---|
57 | }
|
---|
58 | public Object getValueAt(int row, int col) {
|
---|
59 | Shortcut sc = (Shortcut)data.toArray()[row];
|
---|
60 | if (col == 0) {
|
---|
61 | return sc.getLongText();
|
---|
62 | } else if (col == 1) {
|
---|
63 | return sc.getKeyText();
|
---|
64 | } /*else if (col == 2) {
|
---|
65 | if (sc.getRequestedGroup() == Shortcut.GROUP_NONE) {
|
---|
66 | return tr("None");
|
---|
67 | } else if (sc.getRequestedGroup() == Shortcut.GROUP_HOTKEY) {
|
---|
68 | return tr("Hotkey");
|
---|
69 | } else if (sc.getRequestedGroup() == Shortcut.GROUP_MENU) {
|
---|
70 | return tr("Menu");
|
---|
71 | } else if (sc.getRequestedGroup() == Shortcut.GROUP_EDIT) {
|
---|
72 | return tr("Edit");
|
---|
73 | } else if (sc.getRequestedGroup() == Shortcut.GROUP_LAYER) {
|
---|
74 | return tr("Subwindow");
|
---|
75 | } else if (sc.getRequestedGroup() == Shortcut.GROUP_DIRECT) {
|
---|
76 | return tr("Direct");
|
---|
77 | } else if (sc.getRequestedGroup() == Shortcut.GROUP_MNEMONIC) {
|
---|
78 | return tr("Mnemonic");
|
---|
79 | } else if (sc.getRequestedGroup() == Shortcut.GROUP_RESERVED) {
|
---|
80 | return tr("System");
|
---|
81 | } else {
|
---|
82 | return tr("Unknown");
|
---|
83 | }
|
---|
84 | } else if (col == 3) {
|
---|
85 | return sc.getShortText();
|
---|
86 | } */else {
|
---|
87 | // This is a kind of hack that allows the actions on the editing controls
|
---|
88 | // to access the underlying shortcut object without introducing another
|
---|
89 | // method. I opted to stay within the interface.
|
---|
90 | return sc;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | public boolean isCellEditable(int row, int col) {
|
---|
94 | return false;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|