| 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.awt.Color;
|
|---|
| 7 | import java.awt.GridBagLayout;
|
|---|
| 8 | import java.awt.Dimension;
|
|---|
| 9 |
|
|---|
| 10 | import javax.swing.BorderFactory;
|
|---|
| 11 | import javax.swing.JComboBox;
|
|---|
| 12 | import javax.swing.JLabel;
|
|---|
| 13 | import javax.swing.JPanel;
|
|---|
| 14 | import javax.swing.table.DefaultTableCellRenderer;
|
|---|
| 15 | import javax.swing.table.DefaultTableModel;
|
|---|
| 16 | import javax.swing.JTable;
|
|---|
| 17 | import javax.swing.JScrollPane;
|
|---|
| 18 | import javax.swing.table.TableModel;
|
|---|
| 19 | import javax.swing.table.AbstractTableModel;
|
|---|
| 20 |
|
|---|
| 21 | import java.util.Collection;
|
|---|
| 22 |
|
|---|
| 23 | import org.openstreetmap.josm.Main;
|
|---|
| 24 | import org.openstreetmap.josm.data.projection.Projection;
|
|---|
| 25 | import org.openstreetmap.josm.tools.GBC;
|
|---|
| 26 | import org.openstreetmap.josm.tools.ShortCut;
|
|---|
| 27 | import org.openstreetmap.josm.gui.preferences.prefJPanel;
|
|---|
| 28 |
|
|---|
| 29 | public class ShortcutPreference implements PreferenceSetting {
|
|---|
| 30 |
|
|---|
| 31 | private DefaultTableModel model;
|
|---|
| 32 |
|
|---|
| 33 | public void addGui(PreferenceDialog gui) {
|
|---|
| 34 | // 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
|
|---|
| 35 | // icon licence: GPL
|
|---|
| 36 | // icon designer: Paolino, http://www.paolinoland.it/
|
|---|
| 37 | // icon original filename: keyboard.png
|
|---|
| 38 | // icon original size: 128x128
|
|---|
| 39 | // modifications: icon was cropped, then resized
|
|---|
| 40 | JPanel p = gui.createPreferenceTab("shortcuts", tr("Shortcut Preferences"), tr("Changing keyboard shortcuts manually."));
|
|---|
| 41 |
|
|---|
| 42 | prefJPanel prefpanel = new prefJPanel(new scListModel());
|
|---|
| 43 | p.add(prefpanel, GBC.eol().fill(GBC.BOTH));
|
|---|
| 44 |
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | public void ok() {
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | // Maybe move this to prefPanel? There's no need for it to be here.
|
|---|
| 51 | private class scListModel extends AbstractTableModel {
|
|---|
| 52 | private String[] columnNames = new String[]{tr("ID"),tr("Action"), tr("Group"), tr("Shortcut")};
|
|---|
| 53 | private Collection<ShortCut> data;
|
|---|
| 54 | public scListModel() {
|
|---|
| 55 | data = ShortCut.listAll();
|
|---|
| 56 | }
|
|---|
| 57 | public int getColumnCount() {
|
|---|
| 58 | return columnNames.length;
|
|---|
| 59 | }
|
|---|
| 60 | public int getRowCount() {
|
|---|
| 61 | return data.size();
|
|---|
| 62 | }
|
|---|
| 63 | public String getColumnName(int col) {
|
|---|
| 64 | return columnNames[col];
|
|---|
| 65 | }
|
|---|
| 66 | public Object getValueAt(int row, int col) {
|
|---|
| 67 | ShortCut sc = (ShortCut)data.toArray()[row];
|
|---|
| 68 | if (col == 0) {
|
|---|
| 69 | return sc.getShortText();
|
|---|
| 70 | } else if (col == 1) {
|
|---|
| 71 | return sc.getLongText();
|
|---|
| 72 | } else if (col == 2) {
|
|---|
| 73 | if (sc.getRequestedGroup() == ShortCut.GROUP_NONE) {
|
|---|
| 74 | return tr("None");
|
|---|
| 75 | } else if (sc.getRequestedGroup() == ShortCut.GROUP_HOTKEY) {
|
|---|
| 76 | return tr("Hotkey");
|
|---|
| 77 | } else if (sc.getRequestedGroup() == ShortCut.GROUP_MENU) {
|
|---|
| 78 | return tr("Menu");
|
|---|
| 79 | } else if (sc.getRequestedGroup() == ShortCut.GROUP_EDIT) {
|
|---|
| 80 | return tr("Edit");
|
|---|
| 81 | } else if (sc.getRequestedGroup() == ShortCut.GROUP_LAYER) {
|
|---|
| 82 | return tr("Subwindow");
|
|---|
| 83 | } else if (sc.getRequestedGroup() == ShortCut.GROUP_DIRECT) {
|
|---|
| 84 | return tr("Direct");
|
|---|
| 85 | } else if (sc.getRequestedGroup() == ShortCut.GROUP_MNEMONIC) {
|
|---|
| 86 | return tr("Mnemonic");
|
|---|
| 87 | } else if (sc.getRequestedGroup() == ShortCut.GROUP_RESERVED) {
|
|---|
| 88 | return tr("System");
|
|---|
| 89 | } else {
|
|---|
| 90 | return tr("Unknown");
|
|---|
| 91 | }
|
|---|
| 92 | } else if (col == 3) {
|
|---|
| 93 | return sc.getKeyText();
|
|---|
| 94 | } else {
|
|---|
| 95 | // This is a kind of hack that allows the actions on the editing controls
|
|---|
| 96 | // to access the underlying shortcut object without introducing another
|
|---|
| 97 | // method. I opted to stay within the interface.
|
|---|
| 98 | return sc;
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 | public boolean isCellEditable(int row, int col) {
|
|---|
| 102 | return false;
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | }
|
|---|