Ejemplo n.º 1
0
  private void drawInputMethodUncommitedChars(Graphics2D gfx) {
    if (myInputMethodUncommitedChars != null && myInputMethodUncommitedChars.length() > 0) {
      int x = myCursor.getCoordX() * myCharSize.width;
      int y = (myCursor.getCoordY()) * myCharSize.height - 2;

      int len = (myInputMethodUncommitedChars.length()) * myCharSize.width;

      gfx.setColor(getBackground());
      gfx.fillRect(x, (myCursor.getCoordY() - 1) * myCharSize.height, len, myCharSize.height);

      gfx.setColor(getForeground());
      gfx.setFont(myNormalFont);

      gfx.drawString(myInputMethodUncommitedChars, x, y);
      Stroke saved = gfx.getStroke();
      BasicStroke dotted =
          new BasicStroke(
              1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[] {0, 2, 0, 2}, 0);
      gfx.setStroke(dotted);

      gfx.drawLine(x, y, x + len, y);
      gfx.setStroke(saved);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void paintComponent(final Graphics g) {
    final Graphics2D gfx = (Graphics2D) g;

    setupAntialiasing(gfx);

    gfx.setColor(getBackground());

    gfx.fillRect(0, 0, getWidth(), getHeight());

    myTerminalTextBuffer.processHistoryAndScreenLines(
        myClientScrollOrigin,
        new StyledTextConsumer() {
          final int columnCount = getColumnCount();

          @Override
          public void consume(
              int x,
              int y,
              @NotNull TextStyle style,
              @NotNull CharBuffer characters,
              int startRow) {
            int row = y - startRow;
            drawCharacters(x, row, style, characters, gfx);
            if (mySelection != null) {
              Pair<Integer, Integer> interval =
                  mySelection.intersect(x, row + myClientScrollOrigin, characters.length());
              if (interval != null) {
                TextStyle selectionStyle = getSelectionStyle(style);
                CharBuffer selectionChars =
                    characters.subBuffer(interval.first - x, interval.second);

                drawCharacters(interval.first, row, selectionStyle, selectionChars, gfx);
              }
            }
          }

          @Override
          public void consumeNul(
              int x, int y, int nulIndex, TextStyle style, CharBuffer characters, int startRow) {
            int row = y - startRow;
            if (mySelection != null) {
              // compute intersection with all NUL areas, non-breaking
              Pair<Integer, Integer> interval =
                  mySelection.intersect(
                      nulIndex, row + myClientScrollOrigin, columnCount - nulIndex);
              if (interval != null) {
                TextStyle selectionStyle = getSelectionStyle(style);
                drawCharacters(x, row, selectionStyle, characters, gfx);
                return;
              }
            }
            drawCharacters(x, row, style, characters, gfx);
          }

          @Override
          public void consumeQueue(int x, int y, int nulIndex, int startRow) {
            if (x < columnCount) {
              consumeNul(
                  x,
                  y,
                  nulIndex,
                  TextStyle.EMPTY,
                  new CharBuffer(CharUtils.EMPTY_CHAR, columnCount - x),
                  startRow);
            }
          }
        });

    int cursorY = myCursor.getCoordY();
    if (myClientScrollOrigin + getRowCount() > cursorY) {
      int cursorX = myCursor.getCoordX();
      Pair<Character, TextStyle> sc = myTerminalTextBuffer.getStyledCharAt(cursorX, cursorY);
      TextStyle normalStyle = sc.second != null ? sc.second : myStyleState.getCurrent();
      TextStyle selectionStyle = getSelectionStyle(normalStyle);
      boolean inSelection = inSelection(cursorX, cursorY);
      myCursor.drawCursor(sc.first, gfx, inSelection ? selectionStyle : normalStyle);
    }

    drawInputMethodUncommitedChars(gfx);

    drawMargins(gfx, getWidth(), getHeight());
  }