예제 #1
0
 private static void installCutCopyPasteShortcuts(InputMap inputMap, boolean useSimpleActionKeys) {
   String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction;
   String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction;
   String cutActionKey = useSimpleActionKeys ? "cut" : DefaultEditorKit.cutAction;
   // Ctrl+Ins, Shift+Ins, Shift+Del
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_INSERT, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       copyActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_INSERT, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK),
       pasteActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_DELETE, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK),
       cutActionKey);
   // Ctrl+C, Ctrl+V, Ctrl+X
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       copyActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       pasteActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       DefaultEditorKit.cutAction);
 }
 private static void addShortcut(
     @NotNull final String shortcutString,
     @NotNull final String actionIdString,
     boolean isAdditional) {
   Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
   Shortcut[] shortcuts = keymap.getShortcuts(actionIdString);
   if (shortcuts.length > 0 && !isAdditional) {
     return;
   }
   Shortcut studyActionShortcut =
       new KeyboardShortcut(KeyStroke.getKeyStroke(shortcutString), null);
   String[] actionsIds = keymap.getActionIds(studyActionShortcut);
   for (String actionId : actionsIds) {
     myDeletedShortcuts.put(actionId, shortcutString);
     keymap.removeShortcut(actionId, studyActionShortcut);
   }
   keymap.addShortcut(actionIdString, studyActionShortcut);
 }
 @Override
 public void projectClosed() {
   //noinspection AssignmentToStaticFieldFromInstanceMethod
   StudyCondition.VALUE = false;
   if (myCourse != null) {
     ToolWindowManager.getInstance(myProject)
         .getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW)
         .getContentManager()
         .removeAllContents(false);
     if (!myDeletedShortcuts.isEmpty()) {
       for (Map.Entry<String, String> shortcut : myDeletedShortcuts.entrySet()) {
         final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
         final Shortcut actionShortcut =
             new KeyboardShortcut(KeyStroke.getKeyStroke(shortcut.getValue()), null);
         keymap.addShortcut(shortcut.getKey(), actionShortcut);
       }
     }
   }
 }
예제 #4
0
 @SuppressWarnings({"HardCodedStringLiteral"})
 public static void initInputMapDefaults(UIDefaults defaults) {
   // Make ENTER work in JTrees
   InputMap treeInputMap = (InputMap) defaults.get("Tree.focusInputMap");
   if (treeInputMap != null) { // it's really possible. For example,  GTK+ doesn't have such map
     treeInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "toggle");
   }
   // Cut/Copy/Paste in JTextAreas
   InputMap textAreaInputMap = (InputMap) defaults.get("TextArea.focusInputMap");
   if (textAreaInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(textAreaInputMap, false);
   }
   // Cut/Copy/Paste in JTextFields
   InputMap textFieldInputMap = (InputMap) defaults.get("TextField.focusInputMap");
   if (textFieldInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(textFieldInputMap, false);
   }
   // Cut/Copy/Paste in JPasswordField
   InputMap passwordFieldInputMap = (InputMap) defaults.get("PasswordField.focusInputMap");
   if (passwordFieldInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(passwordFieldInputMap, false);
   }
   // Cut/Copy/Paste in JTables
   InputMap tableInputMap = (InputMap) defaults.get("Table.ancestorInputMap");
   if (tableInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(tableInputMap, true);
   }
 }