001 // License: GPL. Copyright 2007 by Immanuel Scholz and others
002 package org.openstreetmap.josm.gui.preferences.shortcut;
003
004 import static org.openstreetmap.josm.tools.I18n.tr;
005
006 import java.util.List;
007
008 import javax.swing.JPanel;
009 import javax.swing.table.AbstractTableModel;
010
011 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
012 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
013 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
014 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
015 import org.openstreetmap.josm.tools.GBC;
016 import org.openstreetmap.josm.tools.Shortcut;
017
018 public class ShortcutPreference extends DefaultTabPreferenceSetting {
019
020 public static class Factory implements PreferenceSettingFactory {
021 public PreferenceSetting createPreferenceSetting() {
022 return new ShortcutPreference();
023 }
024 }
025
026 private ShortcutPreference() {
027 // 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
028 // icon licence: GPL
029 // icon designer: Paolino, http://www.paolinoland.it/
030 // icon original filename: keyboard.png
031 // icon original size: 128x128
032 // modifications: icon was cropped, then resized
033 super("shortcuts", tr("Keyboard Shortcuts"), tr("Changing keyboard shortcuts manually."));
034 }
035
036 public void addGui(PreferenceTabbedPane gui) {
037 JPanel p = gui.createPreferenceTab(this);
038
039 PrefJPanel prefpanel = new PrefJPanel(new scListModel());
040 p.add(prefpanel, GBC.eol().fill(GBC.BOTH));
041
042 }
043
044 public boolean ok() {
045 return Shortcut.savePrefs();
046 }
047
048 // Maybe move this to prefPanel? There's no need for it to be here.
049 private static class scListModel extends AbstractTableModel {
050 private String[] columnNames = new String[]{tr("Action"), tr("Shortcut")};
051 private List<Shortcut> data;
052
053 public scListModel() {
054 data = Shortcut.listAll();
055 }
056 public int getColumnCount() {
057 return columnNames.length;
058 }
059 public int getRowCount() {
060 return data.size();
061 }
062 @Override
063 public String getColumnName(int col) {
064 return columnNames[col];
065 }
066 public Object getValueAt(int row, int col) {
067 return (col==0)? data.get(row).getLongText() : data.get(row);
068 }
069 @Override
070 public boolean isCellEditable(int row, int col) {
071 return false;
072 }
073 }
074 }