source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/ShortcutPreference.java@ 6084

Last change on this file since 6084 was 6084, checked in by bastiK, 11 years ago

see #8902 - add missing @Override annotations (patch by shinigami)

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