[3719] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[4968] | 2 | package org.openstreetmap.josm.gui.preferences.shortcut;
|
---|
[1047] | 3 |
|
---|
[5006] | 4 | import java.awt.Color;
|
---|
| 5 | import java.awt.Component;
|
---|
[4909] | 6 | import java.awt.Dimension;
|
---|
| 7 | import java.awt.GridBagConstraints;
|
---|
| 8 | import java.awt.GridBagLayout;
|
---|
| 9 | import java.awt.Insets;
|
---|
[4929] | 10 | import java.awt.Toolkit;
|
---|
| 11 |
|
---|
[5006] | 12 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
---|
[1023] | 13 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
[1053] | 14 |
|
---|
[1023] | 15 | import java.awt.event.KeyEvent;
|
---|
[4930] | 16 | import java.lang.reflect.Field;
|
---|
[4914] | 17 | import java.util.ArrayList;
|
---|
[1053] | 18 | import java.util.LinkedHashMap;
|
---|
[4897] | 19 | import java.util.HashMap;
|
---|
[1023] | 20 | import java.util.Map;
|
---|
[1053] | 21 |
|
---|
[4909] | 22 | import java.util.regex.PatternSyntaxException;
|
---|
[4916] | 23 | import javax.swing.AbstractAction;
|
---|
| 24 | import javax.swing.BorderFactory;
|
---|
| 25 | import javax.swing.BoxLayout;
|
---|
| 26 | import javax.swing.DefaultComboBoxModel;
|
---|
| 27 | import javax.swing.JCheckBox;
|
---|
| 28 | import javax.swing.JComboBox;
|
---|
| 29 | import javax.swing.JEditorPane;
|
---|
| 30 | import javax.swing.JLabel;
|
---|
| 31 | import javax.swing.JPanel;
|
---|
| 32 | import javax.swing.JScrollPane;
|
---|
| 33 | import javax.swing.JTable;
|
---|
| 34 | import javax.swing.JTextField;
|
---|
| 35 | import javax.swing.KeyStroke;
|
---|
| 36 | import javax.swing.ListSelectionModel;
|
---|
| 37 | import javax.swing.RowFilter;
|
---|
| 38 | import javax.swing.SwingConstants;
|
---|
[4909] | 39 | import javax.swing.event.DocumentEvent;
|
---|
| 40 | import javax.swing.event.DocumentListener;
|
---|
[1053] | 41 | import javax.swing.event.ListSelectionEvent;
|
---|
| 42 | import javax.swing.event.ListSelectionListener;
|
---|
[4916] | 43 | import javax.swing.table.AbstractTableModel;
|
---|
[1053] | 44 | import javax.swing.table.TableModel;
|
---|
[5006] | 45 | import javax.swing.table.DefaultTableCellRenderer;
|
---|
| 46 | import javax.swing.table.TableColumnModel;
|
---|
[1053] | 47 |
|
---|
[4909] | 48 | import javax.swing.table.TableRowSorter;
|
---|
[1023] | 49 | import org.openstreetmap.josm.Main;
|
---|
[4909] | 50 | import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
|
---|
[1084] | 51 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[1023] | 52 |
|
---|
| 53 | /**
|
---|
| 54 | * This is the keyboard preferences content.
|
---|
| 55 | * If someone wants to merge it with ShortcutPreference.java, feel free.
|
---|
| 56 | */
|
---|
[4914] | 57 | public class PrefJPanel extends JPanel {
|
---|
[1023] | 58 |
|
---|
[2875] | 59 | // table of shortcuts
|
---|
[4916] | 60 | private AbstractTableModel model;
|
---|
[2875] | 61 | // comboboxes of modifier groups, mapping selectedIndex to real data
|
---|
| 62 | private static int[] modifInts = new int[]{
|
---|
| 63 | -1,
|
---|
| 64 | 0,
|
---|
| 65 | KeyEvent.SHIFT_DOWN_MASK,
|
---|
| 66 | KeyEvent.CTRL_DOWN_MASK,
|
---|
| 67 | KeyEvent.ALT_DOWN_MASK,
|
---|
| 68 | KeyEvent.META_DOWN_MASK,
|
---|
| 69 | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
|
---|
| 70 | KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
|
---|
| 71 | KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
|
---|
| 72 | KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK,
|
---|
| 73 | KeyEvent.CTRL_DOWN_MASK | KeyEvent.META_DOWN_MASK,
|
---|
| 74 | KeyEvent.ALT_DOWN_MASK | KeyEvent.META_DOWN_MASK,
|
---|
| 75 | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK | KeyEvent.ALT_DOWN_MASK,
|
---|
| 76 | KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK | KeyEvent.ALT_DOWN_MASK
|
---|
| 77 | };
|
---|
| 78 | // and here are the texts fro the comboboxes
|
---|
| 79 | private static String[] modifList = new String[] {
|
---|
| 80 | tr("disabled"),
|
---|
| 81 | tr("no modifier"),
|
---|
[4914] | 82 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[2]).getModifiers()),
|
---|
| 83 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[3]).getModifiers()),
|
---|
| 84 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[4]).getModifiers()),
|
---|
| 85 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[5]).getModifiers()),
|
---|
| 86 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[6]).getModifiers()),
|
---|
| 87 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[7]).getModifiers()),
|
---|
| 88 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[8]).getModifiers()),
|
---|
| 89 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[9]).getModifiers()),
|
---|
| 90 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[10]).getModifiers()),
|
---|
| 91 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[11]).getModifiers()),
|
---|
| 92 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[12]).getModifiers()),
|
---|
| 93 | KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[13]).getModifiers())
|
---|
[2875] | 94 | };
|
---|
| 95 | // this are the display(!) texts for the checkboxes. Let the JVM do the i18n for us <g>.
|
---|
| 96 | // Ok, there's a real reason for this: The JVM should know best how the keys are labelled
|
---|
| 97 | // on the physical keyboard. What language pack is installed in JOSM is completely
|
---|
| 98 | // independent from the keyboard's labelling. But the operation system's locale
|
---|
| 99 | // usually matches the keyboard. This even works with my English Windows and my German
|
---|
| 100 | // keyboard.
|
---|
[4914] | 101 | private static String SHIFT = KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.SHIFT_DOWN_MASK).getModifiers());
|
---|
| 102 | private static String CTRL = KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK).getModifiers());
|
---|
| 103 | private static String ALT = KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.ALT_DOWN_MASK).getModifiers());
|
---|
| 104 | private static String META = KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.META_DOWN_MASK).getModifiers());
|
---|
[1023] | 105 |
|
---|
[2875] | 106 | // A list of keys to present the user. Sadly this really is a list of keys Java knows about,
|
---|
| 107 | // not a list of real physical keys. If someone knows how to get that list?
|
---|
| 108 | private static Map<Integer, String> keyList = setKeyList();
|
---|
[4956] | 109 |
|
---|
[2875] | 110 | private static Map<Integer, String> setKeyList() {
|
---|
| 111 | Map<Integer, String> list = new LinkedHashMap<Integer, String>();
|
---|
[4929] | 112 | String unknown = Toolkit.getProperty("AWT.unknown", "Unknown");
|
---|
[4930] | 113 | // Assume all known keys are declared in KeyEvent as "public static int VK_*"
|
---|
| 114 | for (Field field : KeyEvent.class.getFields()) {
|
---|
| 115 | if (field.getName().startsWith("VK_")) {
|
---|
| 116 | try {
|
---|
| 117 | int i = field.getInt(null);
|
---|
| 118 | String s = KeyEvent.getKeyText(i);
|
---|
| 119 | if (s != null && s.length() > 0 && !s.contains(unknown)) {
|
---|
| 120 | list.put(Integer.valueOf(i), s);
|
---|
| 121 | //System.out.println(i+": "+s);
|
---|
| 122 | }
|
---|
| 123 | } catch (Exception e) {
|
---|
| 124 | e.printStackTrace();
|
---|
| 125 | }
|
---|
[1169] | 126 | }
|
---|
| 127 | }
|
---|
[2875] | 128 | list.put(Integer.valueOf(-1), "");
|
---|
| 129 | return list;
|
---|
| 130 | }
|
---|
[4956] | 131 |
|
---|
[4914] | 132 | private JCheckBox cbAlt = new JCheckBox();
|
---|
| 133 | private JCheckBox cbCtrl = new JCheckBox();
|
---|
| 134 | private JCheckBox cbMeta = new JCheckBox();
|
---|
| 135 | private JCheckBox cbShift = new JCheckBox();
|
---|
| 136 | private JCheckBox cbDefault = new JCheckBox();
|
---|
| 137 | private JCheckBox cbDisable = new JCheckBox();
|
---|
| 138 | private JComboBox tfKey = new JComboBox();
|
---|
[4956] | 139 |
|
---|
[4914] | 140 | JTable shortcutTable = new JTable();
|
---|
[4956] | 141 |
|
---|
[4914] | 142 | private JTextField filterField = new JTextField();
|
---|
[1023] | 143 |
|
---|
| 144 | /** Creates new form prefJPanel */
|
---|
| 145 | // Ain't those auto-generated comments helpful or what? <g>
|
---|
[4916] | 146 | public PrefJPanel(AbstractTableModel model) {
|
---|
[1169] | 147 | this.model = model;
|
---|
[1023] | 148 | initComponents();
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[5006] | 151 | private static class ShortcutTableCellRenderer extends DefaultTableCellRenderer {
|
---|
| 152 |
|
---|
| 153 | private boolean name;
|
---|
| 154 |
|
---|
| 155 | public ShortcutTableCellRenderer(boolean name) {
|
---|
| 156 | this.name = name;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | @Override
|
---|
| 160 | public Component getTableCellRendererComponent(JTable table, Object value, boolean
|
---|
| 161 | isSelected, boolean hasFocus, int row, int column) {
|
---|
| 162 | if(value instanceof Shortcut)
|
---|
| 163 | {
|
---|
| 164 | Shortcut sc = (Shortcut) value;
|
---|
| 165 | JLabel label = (JLabel) super.getTableCellRendererComponent(
|
---|
| 166 | table, name ? sc.getLongText() : sc.getKeyText(), isSelected, hasFocus, row, column);
|
---|
| 167 | label.setBackground(Main.pref.getUIColor("Table.background"));
|
---|
| 168 | if (isSelected) {
|
---|
| 169 | label.setForeground(Main.pref.getUIColor("Table.foreground"));
|
---|
| 170 | }
|
---|
| 171 | if(sc.getAssignedUser()) {
|
---|
| 172 | label.setBackground(Main.pref.getColor(
|
---|
| 173 | marktr("Shortcut Background: User"),
|
---|
| 174 | new Color(200,255,200)));
|
---|
| 175 | } else if(!sc.getAssignedDefault()) {
|
---|
| 176 | label.setBackground(Main.pref.getColor(
|
---|
| 177 | marktr("Shortcut Background: Modified"),
|
---|
| 178 | new Color(255,255,200)));
|
---|
| 179 | }
|
---|
| 180 | return label;
|
---|
| 181 | }
|
---|
| 182 | return null;
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[1023] | 186 | private void initComponents() {
|
---|
[4914] | 187 | JPanel listPane = new JPanel();
|
---|
| 188 | JScrollPane listScrollPane = new JScrollPane();
|
---|
| 189 | JPanel shortcutEditPane = new JPanel();
|
---|
[1023] | 190 |
|
---|
[4914] | 191 | CbAction action = new CbAction(this);
|
---|
| 192 | setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
---|
[4980] | 193 | add(buildFilterPanel());
|
---|
[1023] | 194 | listPane.setLayout(new java.awt.GridLayout());
|
---|
| 195 |
|
---|
| 196 | // This is the list of shortcuts:
|
---|
| 197 | shortcutTable.setModel(model);
|
---|
[4914] | 198 | shortcutTable.getSelectionModel().addListSelectionListener(new CbAction(this));
|
---|
[4916] | 199 | shortcutTable.setFillsViewportHeight(true);
|
---|
[4914] | 200 | shortcutTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
[3594] | 201 | shortcutTable.setAutoCreateRowSorter(true);
|
---|
[5006] | 202 | TableColumnModel mod = shortcutTable.getColumnModel();
|
---|
| 203 | mod.getColumn(0).setCellRenderer(new ShortcutTableCellRenderer(true));
|
---|
| 204 | mod.getColumn(1).setCellRenderer(new ShortcutTableCellRenderer(false));
|
---|
[1023] | 205 | listScrollPane.setViewportView(shortcutTable);
|
---|
| 206 |
|
---|
| 207 | listPane.add(listScrollPane);
|
---|
[4956] | 208 |
|
---|
[4980] | 209 | add(listPane);
|
---|
[1023] | 210 |
|
---|
| 211 | // and here follows the edit area. I won't object to someone re-designing it, it looks, um, "minimalistic" ;)
|
---|
| 212 | shortcutEditPane.setLayout(new java.awt.GridLayout(5, 2));
|
---|
| 213 |
|
---|
| 214 | cbDefault.setAction(action);
|
---|
| 215 | cbDefault.setText(tr("Use default"));
|
---|
| 216 | cbShift.setAction(action);
|
---|
| 217 | cbShift.setText(SHIFT); // see above for why no tr()
|
---|
| 218 | cbDisable.setAction(action);
|
---|
| 219 | cbDisable.setText(tr("Disable"));
|
---|
| 220 | cbCtrl.setAction(action);
|
---|
| 221 | cbCtrl.setText(CTRL); // see above for why no tr()
|
---|
| 222 | cbAlt.setAction(action);
|
---|
| 223 | cbAlt.setText(ALT); // see above for why no tr()
|
---|
| 224 | tfKey.setAction(action);
|
---|
[4914] | 225 | tfKey.setModel(new DefaultComboBoxModel(keyList.values().toArray()));
|
---|
[1023] | 226 | cbMeta.setAction(action);
|
---|
| 227 | cbMeta.setText(META); // see above for why no tr()
|
---|
[4956] | 228 |
|
---|
[4914] | 229 | shortcutEditPane.add(cbDefault);
|
---|
| 230 | shortcutEditPane.add(new JLabel());
|
---|
| 231 | shortcutEditPane.add(cbShift);
|
---|
| 232 | shortcutEditPane.add(cbDisable);
|
---|
| 233 | shortcutEditPane.add(cbCtrl);
|
---|
| 234 | shortcutEditPane.add(new JLabel(tr("Key:"), SwingConstants.LEFT));
|
---|
| 235 | shortcutEditPane.add(cbAlt);
|
---|
| 236 | shortcutEditPane.add(tfKey);
|
---|
[1023] | 237 | shortcutEditPane.add(cbMeta);
|
---|
| 238 |
|
---|
[4914] | 239 | shortcutEditPane.add(new JLabel(tr("Attention: Use real keyboard keys only!")));
|
---|
[1023] | 240 |
|
---|
| 241 | action.actionPerformed(null); // init checkboxes
|
---|
| 242 |
|
---|
[4980] | 243 | add(shortcutEditPane);
|
---|
[1023] | 244 | }
|
---|
| 245 |
|
---|
[4909] | 246 | private JPanel buildFilterPanel() {
|
---|
| 247 | // copied from PluginPreference
|
---|
| 248 | JPanel pnl = new JPanel(new GridBagLayout());
|
---|
| 249 | pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 250 | GridBagConstraints gc = new GridBagConstraints();
|
---|
| 251 |
|
---|
| 252 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
| 253 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
| 254 | gc.weightx = 0.0;
|
---|
| 255 | gc.insets = new Insets(0,0,0,5);
|
---|
| 256 | pnl.add(new JLabel(tr("Search:")), gc);
|
---|
| 257 |
|
---|
| 258 | gc.gridx = 1;
|
---|
| 259 | gc.weightx = 1.0;
|
---|
[4914] | 260 | pnl.add(filterField, gc);
|
---|
[4909] | 261 | filterField.setToolTipText(tr("Enter a search expression"));
|
---|
| 262 | SelectAllOnFocusGainedDecorator.decorate(filterField);
|
---|
| 263 | filterField.getDocument().addDocumentListener(new FilterFieldAdapter());
|
---|
| 264 | pnl.setMaximumSize(new Dimension(300,10));
|
---|
| 265 | return pnl;
|
---|
| 266 | }
|
---|
[4956] | 267 |
|
---|
[4914] | 268 | private void disableAllModifierCheckboxes() {
|
---|
| 269 | cbDefault.setEnabled(false);
|
---|
| 270 | cbDisable.setEnabled(false);
|
---|
| 271 | cbShift.setEnabled(false);
|
---|
| 272 | cbCtrl.setEnabled(false);
|
---|
| 273 | cbAlt.setEnabled(false);
|
---|
| 274 | cbMeta.setEnabled(false);
|
---|
| 275 | }
|
---|
[4909] | 276 |
|
---|
[1169] | 277 | // this allows to edit shortcuts. it:
|
---|
| 278 | // * sets the edit controls to the selected shortcut
|
---|
| 279 | // * enabled/disables the controls as needed
|
---|
| 280 | // * writes the user's changes to the shortcut
|
---|
| 281 | // And after I finally had it working, I realized that those two methods
|
---|
| 282 | // are playing ping-pong (politically correct: table tennis, I know) and
|
---|
| 283 | // even have some duplicated code. Feel free to refactor, If you have
|
---|
| 284 | // more expirience with GUI coding than I have.
|
---|
[4914] | 285 | private class CbAction extends AbstractAction implements ListSelectionListener {
|
---|
[2789] | 286 | private PrefJPanel panel;
|
---|
[4914] | 287 | public CbAction (PrefJPanel panel) {
|
---|
[2875] | 288 | this.panel = panel;
|
---|
[1169] | 289 | }
|
---|
| 290 | public void valueChanged(ListSelectionEvent e) {
|
---|
| 291 | ListSelectionModel lsm = panel.shortcutTable.getSelectionModel(); // can't use e here
|
---|
| 292 | if (!lsm.isSelectionEmpty()) {
|
---|
[4766] | 293 | int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex());
|
---|
[1169] | 294 | Shortcut sc = (Shortcut)panel.model.getValueAt(row, -1);
|
---|
| 295 | panel.cbDefault.setSelected(!sc.getAssignedUser());
|
---|
| 296 | panel.cbDisable.setSelected(sc.getKeyStroke() == null);
|
---|
| 297 | panel.cbShift.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.SHIFT_DOWN_MASK) != 0);
|
---|
| 298 | panel.cbCtrl.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.CTRL_DOWN_MASK) != 0);
|
---|
| 299 | panel.cbAlt.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.ALT_DOWN_MASK) != 0);
|
---|
| 300 | panel.cbMeta.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.META_DOWN_MASK) != 0);
|
---|
| 301 | if (sc.getKeyStroke() != null) {
|
---|
| 302 | tfKey.setSelectedItem(keyList.get(sc.getKeyStroke().getKeyCode()));
|
---|
| 303 | } else {
|
---|
| 304 | tfKey.setSelectedItem(keyList.get(-1));
|
---|
| 305 | }
|
---|
[1244] | 306 | if (!sc.isChangeable()) {
|
---|
[4914] | 307 | disableAllModifierCheckboxes();
|
---|
[1169] | 308 | panel.tfKey.setEnabled(false);
|
---|
| 309 | } else {
|
---|
| 310 | panel.cbDefault.setEnabled(true);
|
---|
| 311 | actionPerformed(null);
|
---|
| 312 | }
|
---|
[5006] | 313 | model.fireTableRowsUpdated(row, row);
|
---|
[1169] | 314 | } else {
|
---|
[4914] | 315 | panel.disableAllModifierCheckboxes();
|
---|
[1169] | 316 | panel.tfKey.setEnabled(false);
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
| 319 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
| 320 | ListSelectionModel lsm = panel.shortcutTable.getSelectionModel();
|
---|
| 321 | if (lsm != null && !lsm.isSelectionEmpty()) {
|
---|
| 322 | if (e != null) { // only if we've been called by a user action
|
---|
[4766] | 323 | int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex());
|
---|
[1169] | 324 | Shortcut sc = (Shortcut)panel.model.getValueAt(row, -1);
|
---|
| 325 | if (panel.cbDisable.isSelected()) {
|
---|
| 326 | sc.setAssignedModifier(-1);
|
---|
| 327 | } else if (panel.tfKey.getSelectedItem().equals("")) {
|
---|
| 328 | sc.setAssignedModifier(KeyEvent.VK_CANCEL);
|
---|
| 329 | } else {
|
---|
| 330 | sc.setAssignedModifier(
|
---|
[2875] | 331 | (panel.cbShift.isSelected() ? KeyEvent.SHIFT_DOWN_MASK : 0) |
|
---|
| 332 | (panel.cbCtrl.isSelected() ? KeyEvent.CTRL_DOWN_MASK : 0) |
|
---|
| 333 | (panel.cbAlt.isSelected() ? KeyEvent.ALT_DOWN_MASK : 0) |
|
---|
| 334 | (panel.cbMeta.isSelected() ? KeyEvent.META_DOWN_MASK : 0)
|
---|
[1169] | 335 | );
|
---|
| 336 | for (Map.Entry<Integer, String> entry : keyList.entrySet()) {
|
---|
| 337 | if (entry.getValue().equals(panel.tfKey.getSelectedItem())) {
|
---|
| 338 | sc.setAssignedKey(entry.getKey());
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | }
|
---|
[4916] | 342 | sc.setAssignedUser(!panel.cbDefault.isSelected());
|
---|
[1169] | 343 | valueChanged(null);
|
---|
| 344 | }
|
---|
| 345 | boolean state = !panel.cbDefault.isSelected();
|
---|
| 346 | panel.cbDisable.setEnabled(state);
|
---|
| 347 | state = state && !panel.cbDisable.isSelected();
|
---|
| 348 | panel.cbShift.setEnabled(state);
|
---|
| 349 | panel.cbCtrl.setEnabled(state);
|
---|
| 350 | panel.cbAlt.setEnabled(state);
|
---|
| 351 | panel.cbMeta.setEnabled(state);
|
---|
| 352 | panel.tfKey.setEnabled(state);
|
---|
| 353 | } else {
|
---|
[4914] | 354 | panel.disableAllModifierCheckboxes();
|
---|
[1169] | 355 | panel.tfKey.setEnabled(false);
|
---|
| 356 | }
|
---|
| 357 | }
|
---|
| 358 | }
|
---|
[1023] | 359 |
|
---|
[4971] | 360 | class FilterFieldAdapter implements DocumentListener {
|
---|
[4909] | 361 | public void filter() {
|
---|
| 362 | String expr = filterField.getText().trim();
|
---|
| 363 | if (expr.length()==0) { expr=null; }
|
---|
| 364 | try {
|
---|
[4916] | 365 | final TableRowSorter<? extends TableModel> sorter =
|
---|
| 366 | ((TableRowSorter<? extends TableModel> )shortcutTable.getRowSorter());
|
---|
[4914] | 367 | if (expr == null) {
|
---|
| 368 | sorter.setRowFilter(null);
|
---|
| 369 | } else {
|
---|
[5049] | 370 | expr = expr.replace("+", "\\+");
|
---|
[4956] | 371 | // split search string on whitespace, do case-insensitive AND search
|
---|
[4914] | 372 | ArrayList<RowFilter<Object, Object>> andFilters = new ArrayList<RowFilter<Object, Object>>();
|
---|
| 373 | for (String word : expr.split("\\s+")) {
|
---|
| 374 | andFilters.add(RowFilter.regexFilter("(?i)" + word));
|
---|
| 375 | }
|
---|
| 376 | sorter.setRowFilter(RowFilter.andFilter(andFilters));
|
---|
| 377 | }
|
---|
[5049] | 378 | model.fireTableDataChanged();
|
---|
[4909] | 379 | }
|
---|
| 380 | catch (PatternSyntaxException ex) { }
|
---|
| 381 | catch (ClassCastException ex2) { /* eliminate warning */ }
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | public void changedUpdate(DocumentEvent arg0) { filter(); }
|
---|
| 385 | public void insertUpdate(DocumentEvent arg0) { filter(); }
|
---|
| 386 | public void removeUpdate(DocumentEvent arg0) { filter(); }
|
---|
| 387 | }
|
---|
[4956] | 388 |
|
---|
[1023] | 389 | }
|
---|