01: package abbot.editor;
02:
03: import javax.swing.InputMap;
04: import javax.swing.KeyStroke;
05: import javax.swing.table.AbstractTableModel;
06: import abbot.i18n.Strings;
07:
08: public class InputMapModel extends AbstractTableModel {
09:
10: public static InputMapModel EMPTY = new InputMapModel() {
11: public int getRowCount() {
12: return 1;
13: }
14:
15: public Object getValueAt(int row, int col) {
16: return col == 0 ? Strings.get("inputmap.unavailable") : "";
17: }
18: };
19:
20: private static final String[] COLUMN_NAMES = {
21: Strings.get("inputmap.key"), Strings.get("inputmap.value"), };
22:
23: private InputMap map;
24:
25: public InputMapModel() {
26: this (new InputMap());
27: }
28:
29: public InputMapModel(InputMap map) {
30: this .map = map;
31: }
32:
33: public String getColumnName(int col) {
34: return COLUMN_NAMES[col];
35: }
36:
37: public int getRowCount() {
38: KeyStroke[] keys = map.allKeys();
39: return keys == null ? 0 : keys.length;
40: }
41:
42: public int getColumnCount() {
43: return 2;
44: }
45:
46: public Object getValueAt(int row, int col) {
47: KeyStroke key = map.allKeys()[row];
48: return col == 0 ? key : map.get(key);
49: }
50:
51: public boolean isCellEditable(int row, int col) {
52: return false;
53: }
54: }
|