@Override public void actionPerformed(java.awt.event.ActionEvent e) { ListSelectionModel lsm = panel.shortcutTable.getSelectionModel(); if (lsm != null && !lsm.isSelectionEmpty()) { if (e != null) { // only if we've been called by a user action int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex()); Shortcut sc = (Shortcut) panel.model.getValueAt(row, -1); if (panel.cbDisable.isSelected()) { sc.setAssignedModifier(-1); } else if (panel.tfKey.getSelectedItem() == null || panel.tfKey.getSelectedItem().equals("")) { sc.setAssignedModifier(KeyEvent.VK_CANCEL); } else { sc.setAssignedModifier( (panel.cbShift.isSelected() ? KeyEvent.SHIFT_DOWN_MASK : 0) | (panel.cbCtrl.isSelected() ? KeyEvent.CTRL_DOWN_MASK : 0) | (panel.cbAlt.isSelected() ? KeyEvent.ALT_DOWN_MASK : 0) | (panel.cbMeta.isSelected() ? KeyEvent.META_DOWN_MASK : 0)); for (Map.Entry<Integer, String> entry : keyList.entrySet()) { if (entry.getValue().equals(panel.tfKey.getSelectedItem())) { sc.setAssignedKey(entry.getKey()); } } } sc.setAssignedUser(!panel.cbDefault.isSelected()); valueChanged(null); } boolean state = !panel.cbDefault.isSelected(); panel.cbDisable.setEnabled(state); state = state && !panel.cbDisable.isSelected(); panel.cbShift.setEnabled(state); panel.cbCtrl.setEnabled(state); panel.cbAlt.setEnabled(state); panel.cbMeta.setEnabled(state); panel.tfKey.setEnabled(state); } else { panel.disableAllModifierCheckboxes(); panel.tfKey.setEnabled(false); } }
@Override public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsm = panel.shortcutTable.getSelectionModel(); // can't use e here if (!lsm.isSelectionEmpty()) { int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex()); Shortcut sc = (Shortcut) panel.model.getValueAt(row, -1); panel.cbDefault.setSelected(!sc.getAssignedUser()); panel.cbDisable.setSelected(sc.getKeyStroke() == null); panel.cbShift.setSelected( sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.SHIFT_DOWN_MASK) != 0); panel.cbCtrl.setSelected( sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.CTRL_DOWN_MASK) != 0); panel.cbAlt.setSelected( sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.ALT_DOWN_MASK) != 0); panel.cbMeta.setSelected( sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.META_DOWN_MASK) != 0); if (sc.getKeyStroke() != null) { tfKey.setSelectedItem(keyList.get(sc.getKeyStroke().getKeyCode())); } else { tfKey.setSelectedItem(keyList.get(-1)); } if (!sc.isChangeable()) { disableAllModifierCheckboxes(); panel.tfKey.setEnabled(false); } else { panel.cbDefault.setEnabled(true); actionPerformed(null); } model.fireTableRowsUpdated(row, row); } else { panel.disableAllModifierCheckboxes(); panel.tfKey.setEnabled(false); } }