Esempio n. 1
0
  /** To support drag-drop of strings, and cut-copy-paste actions in the code window text editor. */
  protected void setShortcutKeystrokes() {
    final int SHORTCUT_KEY_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    InputMap imap = textarea.getInputMap();
    imap.put(
        KeyStroke.getKeyStroke('X', SHORTCUT_KEY_MASK),
        TransferHandler.getCutAction().getValue(Action.NAME));
    imap.put(
        KeyStroke.getKeyStroke('C', SHORTCUT_KEY_MASK),
        TransferHandler.getCopyAction().getValue(Action.NAME));
    imap.put(
        KeyStroke.getKeyStroke('V', SHORTCUT_KEY_MASK),
        TransferHandler.getPasteAction().getValue(Action.NAME));
    imap.put(KeyStroke.getKeyStroke('A', SHORTCUT_KEY_MASK), "selectAll");
    imap.put(KeyStroke.getKeyStroke('/', SHORTCUT_KEY_MASK), "commentUncomment");
    imap.put(KeyStroke.getKeyStroke(']', SHORTCUT_KEY_MASK), "increaseIndent");
    imap.put(KeyStroke.getKeyStroke('[', SHORTCUT_KEY_MASK), "decreaseIndent");

    ActionMap amap = textarea.getActionMap();
    amap.put(
        TransferHandler.getCutAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> cut "+e.getSource());
            ((JEditTextArea) e.getSource()).cut();
          }
        });
    amap.put(
        TransferHandler.getCopyAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> copy "+e.getSource());
            ((JEditTextArea) e.getSource()).copy();
          }
        });
    amap.put(
        TransferHandler.getPasteAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> paste "+e.getSource());
            ((JEditTextArea) e.getSource()).paste();
          }
        });
    amap.put(
        "selectAll",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> select all "+e.getSource());
            ((JEditTextArea) e.getSource()).selectAll();
          }
        });
    amap.put(
        "commentUncomment",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> comment
            // uncomment"+e.getSource());
            handleCommentUncomment();
          }
        });
    amap.put(
        "increaseIndent",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> increaseIndent"+e.getSource());
            handleIndentOutdent(true);
          }
        });
    amap.put(
        "decreaseIndent",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> decreaseIndent"+e.getSource());
            handleIndentOutdent(false);
          }
        });
  }