コード例 #1
0
ファイル: ProgramCanvas.java プロジェクト: RWTH-OS/MP-MPICH
  /** Handles the event when the key is pressed */
  public void processKeyEvent(KeyEvent e) {
    int keyCode = e.getKeyCode();

    if (e.getID() == KeyEvent.KEY_PRESSED) {
      if (keyCode == KeyEvent.VK_Z) lockZoom();
      else if (keyCode == KeyEvent.VK_T) fixElTimePointer(currTime);
    } else super.processKeyEvent(e);
  }
コード例 #2
0
ファイル: ActionBar.java プロジェクト: RoDaniel/featurehouse
    public void processKeyEvent(KeyEvent evt) {
      evt = KeyEventWorkaround.processKeyEvent(evt);
      if (evt == null) return;

      switch (evt.getID()) {
        case KeyEvent.KEY_TYPED:
          char ch = evt.getKeyChar();
          if (!nonDigit && Character.isDigit(ch)) {
            super.processKeyEvent(evt);
            repeat = true;
            repeatCount = Integer.parseInt(action.getText());
          } else {
            nonDigit = true;
            if (repeat) {
              passToView(evt);
            } else super.processKeyEvent(evt);
          }
          break;
        case KeyEvent.KEY_PRESSED:
          int keyCode = evt.getKeyCode();
          if (evt.isActionKey()
              || evt.isControlDown()
              || evt.isAltDown()
              || evt.isMetaDown()
              || keyCode == KeyEvent.VK_BACK_SPACE
              || keyCode == KeyEvent.VK_DELETE
              || keyCode == KeyEvent.VK_ENTER
              || keyCode == KeyEvent.VK_TAB
              || keyCode == KeyEvent.VK_ESCAPE) {
            nonDigit = true;
            if (repeat) {
              passToView(evt);
              break;
            } else if (keyCode == KeyEvent.VK_TAB) {
              complete(true);
              evt.consume();
            } else if (keyCode == KeyEvent.VK_ESCAPE) {
              evt.consume();
              if (popup != null) {
                popup.dispose();
                popup = null;
                action.requestFocus();
              } else {
                if (temp) view.removeToolBar(ActionBar.this);
                view.getEditPane().focusOnTextArea();
              }
              break;
            } else if ((keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN)
                && popup != null) {
              popup.list.processKeyEvent(evt);
              break;
            }
          }
          super.processKeyEvent(evt);
          break;
      }
    }
コード例 #3
0
ファイル: TerminalPanel.java プロジェクト: bitekas/jediterm
 public void handleKeyEvent(KeyEvent e) {
   final int id = e.getID();
   if (id == KeyEvent.KEY_PRESSED) {
     myKeyListener.keyPressed(e);
   } else if (id == KeyEvent.KEY_RELEASED) {
     /* keyReleased(e); */
   } else if (id == KeyEvent.KEY_TYPED) {
     myKeyListener.keyTyped(e);
   }
 }
コード例 #4
0
 @Override
 public boolean dispatchKeyEvent(KeyEvent e) {
   if (isDraggingNow()
       && e.getKeyCode() == KeyEvent.VK_ESCAPE
       && e.getID() == KeyEvent.KEY_PRESSED) {
     myDragCancelled = true;
     finishDragging();
     return true;
   }
   return false;
 }
コード例 #5
0
ファイル: WizardPopup.java プロジェクト: ngoanhtan/consulo
 private boolean proceedKeyEvent(KeyEvent event, KeyStroke stroke) {
   if (myInputMap.get(stroke) != null) {
     final Action action = myActionMap.get(myInputMap.get(stroke));
     if (action != null && action.isEnabled()) {
       action.actionPerformed(
           new ActionEvent(
               getContent(), event.getID(), "", event.getWhen(), event.getModifiers()));
       return true;
     }
   }
   return false;
 }
コード例 #6
0
ファイル: JEditTextArea.java プロジェクト: zeph/grinder
 /**
  * Forwards key events directly to the input handler. This is slightly faster than using a
  * KeyListener because some Swing overhead is avoided.
  */
 public void processKeyEvent(KeyEvent evt) {
   if (inputHandler == null) return;
   switch (evt.getID()) {
     case KeyEvent.KEY_TYPED:
       inputHandler.keyTyped(evt);
       break;
     case KeyEvent.KEY_PRESSED:
       inputHandler.keyPressed(evt);
       break;
     case KeyEvent.KEY_RELEASED:
       inputHandler.keyReleased(evt);
       break;
   }
 }
コード例 #7
0
ファイル: WizardPopup.java プロジェクト: ngoanhtan/consulo
  public final boolean dispatch(KeyEvent event) {
    if (event.getID() != KeyEvent.KEY_PRESSED && event.getID() != KeyEvent.KEY_RELEASED) {
      return false;
    }

    if (event.getID() == KeyEvent.KEY_PRESSED) {
      final KeyStroke stroke =
          KeyStroke.getKeyStroke(event.getKeyCode(), event.getModifiers(), false);
      if (proceedKeyEvent(event, stroke)) return false;
    }

    if (event.getID() == KeyEvent.KEY_RELEASED) {
      final KeyStroke stroke =
          KeyStroke.getKeyStroke(event.getKeyCode(), event.getModifiers(), true);
      return proceedKeyEvent(event, stroke);
    }

    myMnemonicsSearch.process(event);
    mySpeedSearch.process(event);

    if (event.isConsumed()) return true;
    process(event);
    return event.isConsumed();
  }
コード例 #8
0
  private void displayInfo(KeyEvent e, String keyStatus) {
    // Method copied from http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

    // You should only rely on the key char if the event
    // is a key typed event.
    int id = e.getID();
    String keyString;
    if (id == KeyEvent.KEY_TYPED) {
      char c = e.getKeyChar();
      keyString = "key character = '" + c + "'";
    } else {
      int keyCode = e.getKeyCode();
      keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")";
    }

    int modifiersEx = e.getModifiersEx();
    String modString = "extended modifiers = " + modifiersEx;
    String tmpString = KeyEvent.getModifiersExText(modifiersEx);
    if (tmpString.length() > 0) {
      modString += " (" + tmpString + ")";
    } else {
      modString += " (no extended modifiers)";
    }

    String actionString = "action key? ";
    if (e.isActionKey()) {
      actionString += "YES";
    } else {
      actionString += "NO";
    }

    String locationString = "key location: ";
    int location = e.getKeyLocation();
    if (location == KeyEvent.KEY_LOCATION_STANDARD) {
      locationString += "standard";
    } else if (location == KeyEvent.KEY_LOCATION_LEFT) {
      locationString += "left";
    } else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
      locationString += "right";
    } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
      locationString += "numpad";
    } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
      locationString += "unknown";
    }

    // Added:
    System.out.println("Keypress: " + keyString);
  }
コード例 #9
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
    private synchronized void type(KeyEvent e) {
      switch (e.getKeyCode()) {
        case (KeyEvent.VK_ENTER):
          if (e.getID() == KeyEvent.KEY_PRESSED) {
            processCommand();
            initCommandPos();
            text.setCaretPosition(commandPos);
          }
          e.consume();
          text.repaint();
          break;
        case (KeyEvent.VK_UP):
          if (e.getID() == KeyEvent.KEY_PRESSED) prevHistory();
          e.consume();
          break;

        case (KeyEvent.VK_DOWN):
          if (e.getID() == KeyEvent.KEY_PRESSED) nextHistory();
          e.consume();
          break;
        case (KeyEvent.VK_LEFT):
        case (KeyEvent.VK_BACK_SPACE):
        case (KeyEvent.VK_DELETE):
          if (text.getCaretPosition() <= commandPos) e.consume();
          break;
        case (KeyEvent.VK_HOME):
          text.setCaretPosition(commandPos);
          e.consume();
          break;
        case (KeyEvent.VK_U):
          if ((e.getModifiers() & InputEvent.CTRL_MASK) > 0) {
            replaceConsoleText("", commandPos, textLength());
            commandHistoryIndex = 0;
            e.consume();
          }
          break;
        case (KeyEvent.VK_ALT):
        case (KeyEvent.VK_CAPS_LOCK):
        case (KeyEvent.VK_CONTROL):
        case (KeyEvent.VK_META):
        case (KeyEvent.VK_SHIFT):
        case (KeyEvent.VK_PRINTSCREEN):
        case (KeyEvent.VK_SCROLL_LOCK):
        case (KeyEvent.VK_PAUSE):
        case (KeyEvent.VK_INSERT):
        case (KeyEvent.VK_F1):
        case (KeyEvent.VK_F2):
        case (KeyEvent.VK_F3):
        case (KeyEvent.VK_F4):
        case (KeyEvent.VK_F5):
        case (KeyEvent.VK_F6):
        case (KeyEvent.VK_F7):
        case (KeyEvent.VK_F8):
        case (KeyEvent.VK_F9):
        case (KeyEvent.VK_F10):
        case (KeyEvent.VK_F11):
        case (KeyEvent.VK_F12):
        case (KeyEvent.VK_ESCAPE):
        case (KeyEvent.VK_C):
          break;
        default:
          if ((e.getModifiers()
                  & (InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.META_MASK))
              == 0) {
            moveCaret();
          }

          if ((e.paramString().contains("Backspace")) && (text.getCaretPosition() <= commandPos)) {
            e.consume();
          }
          break;
      }
    }
コード例 #10
0
 // {{{ processKeyEvent() method
 public void processKeyEvents(KeyEvent ke) {
   if ((ke.getID() == KeyEvent.KEY_PRESSED) && (ke.getKeyCode() == KeyEvent.VK_ESCAPE)) {
     cancel();
     ke.consume();
   }
 } // }}}
コード例 #11
0
 @Override
 protected void processKeyEvent(KeyEvent evt) {
   if (evt.getID() == KeyEvent.KEY_PRESSED) {
     ActionContext ac = VFSBrowser.getActionContext();
     int row = parentDirectories.getSelectedIndex();
     switch (evt.getKeyCode()) {
       case KeyEvent.VK_DOWN:
         evt.consume();
         if (row < parentDirectories.getSize().height - 1)
           parentDirectories.setSelectedIndex(++row);
         break;
       case KeyEvent.VK_LEFT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.previousDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_RIGHT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.nextDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_TAB:
         evt.consume();
         if ((evt.getModifiers() & InputEvent.SHIFT_MASK) > 0) browser.focusOnDefaultComponent();
         else table.requestFocus();
         break;
       case KeyEvent.VK_UP:
         evt.consume();
         if (row > 0) {
           parentDirectories.setSelectedIndex(--row);
         }
         break;
       case KeyEvent.VK_BACK_SPACE:
         evt.consume();
         EditAction up = ac.getAction("vfs.browser.up");
         ac.invokeAction(evt, up);
         break;
       case KeyEvent.VK_F5:
         evt.consume();
         EditAction reload = ac.getAction("vfs.browser.reload");
         ac.invokeAction(evt, reload);
         break;
       case KeyEvent.VK_ENTER:
         evt.consume();
         if (row != -1) {
           // basically the same handling as in ParentMouseHandler#mouseReleased
           Object obj = parentDirectories.getModel().getElementAt(row);
           if (obj instanceof VFSFile) {
             VFSFile dirEntry = (VFSFile) obj;
             browser.setDirectory(dirEntry.getPath());
             if (browser.getMode() == VFSBrowser.BROWSER) focusOnFileView();
           }
         }
         break;
         /* These actions don't work because they look at the EntryTable for the current selected
         * 	item. We need actions that look at the parentDirectoryList item instead.
         *
         			case KeyEvent.VK_DELETE:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.delete");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.CTRL_MASK | KeyEvent.VK_N:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-file");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.VK_INSERT:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-directory");
         				ac.invokeAction(evt, ea);
         				break; */
     }
   } else if (evt.getID() == KeyEvent.KEY_TYPED) {
     if (evt.isControlDown() || evt.isAltDown() || evt.isMetaDown()) {
       evt.consume();
       return;
     }
     switch (evt.getKeyChar()) {
       case '~':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER)
           browser.setDirectory(System.getProperty("user.home"));
         break;
       case '/':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) browser.rootDirectory();
         break;
       case '-':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) {
           browser.setDirectory(browser.getView().getBuffer().getDirectory());
         }
         break;
     }
   }
   if (!evt.isConsumed()) super.processKeyEvent(evt);
 }
コード例 #12
0
  public void keyTyped(KeyEvent e) {
    if (debug) {
      System.out.println(
          "--- RecordingModule: key typed = "
              + e
              + "\n  > Key char->int = "
              + (int) e.getKeyChar());
      System.out.println(" -- isActionKey() = " + e.isActionKey());
      System.out.println(" -- isISOControl() = " + Character.isISOControl(e.getKeyChar()));
      System.out.println(" -- isWhitespace() = " + Character.isWhitespace(e.getKeyChar()));
    }

    if (isKeyReserved(e)) {
      return;
    }

    if (enabled && !readOnly && lastKeyPressEvent != null) {

      if (enableKeyboard) {
        boolean replace = false;
        String text = "";
        if (isControl(e)) {
          if (lastKeyPressEvent.getKeyCode() == KeyEvent.VK_ENTER) {

            // Change the Type cmd prior to Typeline if the delay from the last type key is less
            // than 1 sec
            if (useTypeline && e.getModifiers() == 0 && lastElement != null) {
              String s = DocumentUtils.getElementText(lastElement);
              if (s.startsWith("Type ")
                  && (System.currentTimeMillis() - lastInsertTime) < typelineDelay) {
                replace = true;
                text = s.replaceFirst("Type", "Typeline");
              }
            }
          }

          if ("".equals(text)) {
            int count = 1;
            KeyEvent e2;

            long lastEventTime = e.getWhen();

            // We go through the vector of events and check whether there are events corresponding
            // to a typed text.
            for (int i = 0; i < events.size() && events.get(i) instanceof KeyEvent; i++) {
              e2 = (KeyEvent) events.get(i);
              if (e.getID() == e2.getID()
                  && e.getKeyChar() == e2.getKeyChar()
                  && e.getKeyCode() == e2.getKeyCode()
                  && e.getModifiers() == e2.getModifiers()
                  && (lastEventTime - e2.getWhen() < keyMutiDelay)) {
                count++;
                replace = true;
                lastEventTime = e2.getWhen();
              } else {
                break;
              }
            }

            text = "Press ";
            //                    String modifiers = KeyEvent.getKeyModifiersText(e.getModifiers());
            String modifiers = parser.modifiersToString(e.getModifiers());
            if (!"".equals(modifiers)) {
              text += modifiers + "+";
            }
            String charText = KeyEvent.getKeyText(lastKeyPressEvent.getKeyCode());
            if (charText == null) {
              charText = "<unknown>";
            }
            text += charText;
            if (count > 1) {
              text += " " + PressCommand.PARAM_COUNT + "=" + count;
            }

            if (debug) {
              System.out.println("--- RecordingModule: Inserting '" + text + "'");
            }
          }

        } else {
          text = "" + e.getKeyChar();
          KeyEvent e2;

          // We go through the vector of events and check whether there are events corresponding to
          // a typed text.
          for (int i = 0; i < events.size() && events.get(i) instanceof KeyEvent; i++) {
            e2 = (KeyEvent) events.get(i);
            if (!isControl(e2) && !e2.isActionKey()) {
              text = e2.getKeyChar() + text;
              replace = true;
            } else {
              break;
            }
          }

          text = "Type \"" + Utils.escapeUnescapedDoubleQuotes(text) + "\"";
        }

        // Insert the command to the current editor
        insertLine(text, replace, true, false);
      }
      insertEvent(e);
    }
  }
コード例 #13
0
  public void keyPressed(KeyEvent e) {

    if (debug) {
      System.out.println(
          "--- RecordingModule: key pressed = "
              + e
              + "\n  > Key char->int = "
              + (int) e.getKeyChar());
    }

    // Here we process just action keys because they do not generate KEY_TYPED events.
    // Other key events are handled by the keyTyped method.
    lastInteractionTime = System.currentTimeMillis();

    if (isKeyReserved(e)) {
      return;
    }

    if (enabled && !readOnly) {
      //        System.out.println("keyPressed (e.isActionKey()=)"+e.isActionKey()+":
      // "+e.toString());
      // TODO: implement text corrections in type like Delete, Backspace

      if (e.isActionKey()) {

        if (enableKeyboard) {
          int count = 1;
          KeyEvent e2;

          long lastEventTime = e.getWhen();

          // We go through the vector of events and check whether there are events corresponding to
          // a typed text.
          for (int i = 0; i < events.size() && events.get(i) instanceof KeyEvent; i++) {
            e2 = (KeyEvent) events.get(i);
            if (e.getID() == e2.getID()
                && e.getKeyChar() == e2.getKeyChar()
                && e.getKeyCode() == e2.getKeyCode()
                && e.getModifiers() == e2.getModifiers()
                && (lastEventTime - e2.getWhen() < keyMutiDelay)) {
              count++;
              lastEventTime = e2.getWhen();
            } else {
              break;
            }
          }

          String text = "Press ";
          //                String modifiers = KeyEvent.getKeyModifiersText(e.getModifiers());
          String modifiers = parser.modifiersToString(e.getModifiers());
          if (!"".equals(modifiers)) {
            text += modifiers + "+";
          }
          String charText = (String) keyCodes.get(new Integer(e.getKeyCode()));
          if (charText == null) {
            charText = "<unknown>";
          }
          text += charText;
          if (count > 1) {
            text += " " + PressCommand.PARAM_COUNT + "=" + count;
          }
          //                text += '\n';

          if (debug) {
            System.out.println("--- RecordingModule: Inserting '" + text + "'");
          }

          // Insert the command to the current editor
          insertLine(text, count > 1, true, false);
        }
        insertEvent(e);
      }
      lastKeyPressEvent = e;
    }
  }