Example #1
0
  /**
   * InputMethod implementation For details read
   * http://docs.oracle.com/javase/7/docs/technotes/guides/imf/api-tutorial.html
   */
  @Override
  protected void processInputMethodEvent(InputMethodEvent e) {
    int commitCount = e.getCommittedCharacterCount();

    if (commitCount > 0) {
      myInputMethodUncommitedChars = null;
      AttributedCharacterIterator text = e.getText();
      if (text != null) {
        StringBuilder sb = new StringBuilder();

        //noinspection ForLoopThatDoesntUseLoopVariable
        for (char c = text.first(); commitCount > 0; c = text.next(), commitCount--) {
          if (c >= 0x20
              && c
                  != 0x7F) { // Hack just like in
                             // javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction
            sb.append(c);
          }
        }

        myTerminalStarter.sendString(sb.toString());
      }
    } else {
      myInputMethodUncommitedChars = uncommitedChars(e.getText());
    }
  }
Example #2
0
  private void sizeTerminalFromComponent() {
    if (myTerminalStarter != null) {
      final int newWidth = getWidth() / myCharSize.width;
      final int newHeight = getHeight() / myCharSize.height;

      if (newHeight > 0 && newWidth > 0) {
        final Dimension newSize = new Dimension(newWidth, newHeight);

        myTerminalStarter.postResize(newSize, RequestOrigin.User);
      }
    }
  }
Example #3
0
  private void processTerminalKeyPressed(KeyEvent e) {
    try {
      final int keycode = e.getKeyCode();
      final char keychar = e.getKeyChar();

      // numLock does not change the code sent by keypad VK_DELETE
      // although it send the char '.'
      if (keycode == KeyEvent.VK_DELETE && keychar == '.') {
        myTerminalStarter.sendBytes(new byte[] {'.'});
        return;
      }
      // CTRL + Space is not handled in KeyEvent; handle it manually
      else if (keychar == ' ' && (e.getModifiers() & InputEvent.CTRL_MASK) != 0) {
        myTerminalStarter.sendBytes(new byte[] {Ascii.NUL});
        return;
      }

      final byte[] code = myTerminalStarter.getCode(keycode, e.getModifiers());
      if (code != null) {
        myTerminalStarter.sendBytes(code);
        if (mySettingsProvider.scrollToBottomOnTyping() && isCodeThatScrolls(keycode)) {
          scrollToBottom();
        }
      } else if ((keychar & 0xff00) == 0) {
        final byte[] obuffer;
        if (mySettingsProvider.altSendsEscape() && (e.getModifiers() & InputEvent.ALT_MASK) != 0) {
          obuffer = new byte[] {Ascii.ESC, (byte) keychar};
        } else {
          obuffer = new byte[] {(byte) keychar};
        }
        myTerminalStarter.sendBytes(obuffer);

        if (mySettingsProvider.scrollToBottomOnTyping()) {
          scrollToBottom();
        }
      }
    } catch (final Exception ex) {
      LOG.error("Error sending key to emulator", ex);
    }
  }
Example #4
0
  protected void pasteSelection() {
    final String selection = getClipboardString();

    if (selection == null) {
      return;
    }

    try {
      myTerminalStarter.sendString(selection);
    } catch (RuntimeException e) {
      LOG.info(e);
    }
  }
Example #5
0
 private void processTerminalKeyTyped(KeyEvent e) {
   final char keychar = e.getKeyChar();
   if ((keychar & 0xff00) != 0) {
     final char[] foo;
     if (mySettingsProvider.altSendsEscape() && (e.getModifiers() & InputEvent.ALT_MASK) != 0) {
       foo = new char[] {Ascii.ESC, keychar};
     } else {
       foo = new char[] {keychar};
     }
     try {
       myTerminalStarter.sendString(new String(foo));
       if (mySettingsProvider.scrollToBottomOnTyping()) {
         scrollToBottom();
       }
     } catch (final RuntimeException ex) {
       LOG.error("Error sending key to emulator", ex);
     }
   }
 }