protected void paintComponent(Graphics g) {
    final Border border = getBorder();
    int shiftX = 0;
    int shiftY = 0;

    if (border != null) {
      shiftX = border.getBorderInsets(this).left;
      shiftY = border.getBorderInsets(this).top;
    }

    setForeground(getTextColor());

    super.paintComponent(g);

    if (getText() != null) {
      g.setColor(getTextColor());
      int x = myIconWidth;
      int y = getTextBaseLine();

      if (myUnderline) {
        int k = 1;
        if (getFont().getSize() > 11) {
          k += (getFont().getSize() - 11);
        }

        y += k;

        int lineY = y + shiftY;
        if (lineY >= getSize().height) {
          lineY = getSize().height - 1;
        }
        if (getHorizontalAlignment() == LEFT) {
          UIUtil.drawLine(
              g,
              x + shiftX,
              lineY,
              x + getFontMetrics(getFont()).stringWidth(getText()) + shiftX,
              lineY);
        } else {
          UIUtil.drawLine(
              g,
              getWidth() - 1 - getFontMetrics(getFont()).stringWidth(getText()) + shiftX,
              lineY,
              getWidth() - 1 + shiftX,
              lineY);
        }
      } else {
      }

      if (myPaintDefaultIcon) {
        int endX = myIconWidth + getFontMetrics(getFont()).stringWidth(getText());
        int endY = getHeight() / 2 - LINK.getIconHeight() / 2 + 1;

        LINK.paintIcon(this, g, endX + shiftX + DEFAULT_ICON_GAP, endY);
      }
    }
  }
 private void drawIconBorder(Graphics g) {
   int i1 = a - 1;
   int j1 = e - 2;
   int k1 = i1 + myMaxGutterIconWidth + 1;
   int l1 = j1 + myMaxGutterIconWidth + 4;
   g.setColor(BegResources.m);
   UIUtil.drawLine(g, i1, j1, i1, l1);
   UIUtil.drawLine(g, i1, j1, k1, j1);
   g.setColor(BegResources.j);
   UIUtil.drawLine(g, k1, j1, k1, l1);
   UIUtil.drawLine(g, i1, l1, k1, l1);
 }
  private void paintWhitespace(
      Graphics2D g,
      CharSequence text,
      float x,
      int y,
      int start,
      int end,
      EditorImpl.LineWhitespacePaintingStrategy whitespacePaintingStrategy,
      VisualLineFragmentsIterator.Fragment fragment) {
    g.setColor(myEditor.getColorsScheme().getColor(EditorColors.WHITESPACES_COLOR));
    boolean isRtl = fragment.isRtl();
    int baseStartOffset = fragment.getStartOffset();
    int startOffset = isRtl ? baseStartOffset - start : baseStartOffset + start;
    for (int i = start; i < end; i++) {
      int charOffset = isRtl ? baseStartOffset - i - 1 : baseStartOffset + i;
      char c = text.charAt(charOffset);
      if (" \t\u3000".indexOf(c) >= 0
          && whitespacePaintingStrategy.showWhitespaceAtOffset(charOffset)) {
        int startX =
            (int)
                fragment.offsetToX(
                    x, startOffset, isRtl ? baseStartOffset - i : baseStartOffset + i);
        int endX =
            (int)
                fragment.offsetToX(
                    x, startOffset, isRtl ? baseStartOffset - i - 1 : baseStartOffset + i + 1);

        if (c == ' ') {
          g.fillRect((startX + endX) / 2, y, 1, 1);
        } else if (c == '\t') {
          endX -= myView.getPlainSpaceWidth() / 4;
          int height = myView.getCharHeight();
          int halfHeight = height / 2;
          int mid = y - halfHeight;
          int top = y - height;
          UIUtil.drawLine(g, startX, mid, endX, mid);
          UIUtil.drawLine(g, endX, y, endX, top);
          g.fillPolygon(
              new int[] {endX - halfHeight, endX - halfHeight, endX},
              new int[] {y, y - height, y - halfHeight},
              3);
        } else if (c == '\u3000') { // ideographic space
          final int charHeight = myView.getCharHeight();
          g.drawRect(startX + 2, y - charHeight, endX - startX - 4, charHeight);
        }
      }
    }
  }
 private static void drawLine(Graphics2D g, float x1, int y1, float x2, int y2, boolean rounded) {
   if (rounded) {
     UIUtil.drawLinePickedOut(g, (int) x1, y1, (int) x2, y2);
   } else {
     UIUtil.drawLine(g, (int) x1, y1, (int) x2, y2);
   }
 }
 private void lineTo(int x, int y) {
   if (myEffectType == EffectType.ROUNDED_BOX) {
     UIUtil.drawLinePickedOut(myGraphics, myX, myY, x, y);
   } else {
     UIUtil.drawLine(myGraphics, myX, myY, x, y);
   }
   myX = x;
   myY = y;
 }
  private void paintRightMargin(Graphics g, Rectangle clip) {
    EditorSettings settings = myEditor.getSettings();
    Color rightMargin = myEditor.getColorsScheme().getColor(EditorColors.RIGHT_MARGIN_COLOR);
    if (!settings.isRightMarginShown() || rightMargin == null) return;

    int x = settings.getRightMargin(myEditor.getProject()) * myView.getPlainSpaceWidth();
    g.setColor(rightMargin);
    UIUtil.drawLine(g, x, clip.y, x, clip.y + clip.height);
  }
 private static void paintRect(
     @NotNull Graphics g,
     @Nullable Color color,
     @Nullable Color borderColor,
     int x1,
     int y1,
     int x2,
     int y2) {
   if (color != null) {
     g.setColor(color);
     g.fillRect(x1, y1, x2 - x1, y2 - y1);
   }
   if (borderColor != null) {
     g.setColor(borderColor);
     UIUtil.drawLine(g, x1, y1, x2 - 1, y1);
     UIUtil.drawLine(g, x1, y1, x1, y2 - 1);
     UIUtil.drawLine(g, x1, y2 - 1, x2 - 1, y2 - 1);
   }
 }
    private void drawSpot(
        Graphics g,
        int width,
        boolean thinErrorStripeMark,
        int yStart,
        int yEnd,
        Color color,
        boolean drawTopDecoration,
        boolean drawBottomDecoration) {
      int x = isMirrored() ? 3 : 5;
      int paintWidth = width;
      if (thinErrorStripeMark) {
        paintWidth /= 2;
        paintWidth += 1;
        x = isMirrored() ? width + 2 : 0;
      }
      if (color == null) return;
      g.setColor(color);
      g.fillRect(x + 1, yStart, paintWidth - 2, yEnd - yStart + 1);

      Color brighter = color.brighter();
      g.setColor(brighter);
      // left decoration
      UIUtil.drawLine(g, x, yStart, x, yEnd /* - 1*/);
      if (drawTopDecoration) {
        // top decoration
        UIUtil.drawLine(g, x + 1, yStart, x + paintWidth - 2, yStart);
      }
      Color darker = ColorUtil.shift(color, 0.75);

      g.setColor(darker);
      if (drawBottomDecoration) {
        // bottom decoration
        UIUtil.drawLine(
            g,
            x + 1,
            yEnd /* - 1*/,
            x + paintWidth - 2,
            yEnd /* - 1*/); // large bottom to let overwrite by hl below
      }
      // right decoration
      UIUtil.drawLine(g, x + paintWidth - 2, yStart, x + paintWidth - 2, yEnd /* - 1*/);
    }
Example #9
0
 @Override
 protected void paintComponent(Graphics g) {
   g.setColor(myColor);
   g.fillRect(0, 0, ROOT_INDICATOR_WIDTH - 1, HEIGHT_CELL);
   UIUtil.drawLine(
       (Graphics2D) g,
       ROOT_INDICATOR_WIDTH - 1,
       0,
       ROOT_INDICATOR_WIDTH - 1,
       HEIGHT_CELL,
       null,
       myUi.getColorManager().getRootIndicatorBorder());
 }
  private void paintComposedTextDecoration(Graphics2D g) {
    TextRange composedTextRange = myEditor.getComposedTextRange();
    if (composedTextRange != null) {
      Point p1 =
          myView.offsetToXY(
              Math.min(composedTextRange.getStartOffset(), myDocument.getTextLength()),
              true,
              false);
      Point p2 =
          myView.offsetToXY(
              Math.min(composedTextRange.getEndOffset(), myDocument.getTextLength()), false, true);

      int y = p1.y + myView.getAscent() + 1;

      g.setStroke(IME_COMPOSED_TEXT_UNDERLINE_STROKE);
      g.setColor(myEditor.getColorsScheme().getDefaultForeground());
      UIUtil.drawLine(g, p1.x, y, p2.x, y);
    }
  }
    private void doPaintBorder(Component c, Graphics g, int x, int y, int width, int height) {
      Insets insets = getBorderInsets(c);

      if (insets.top > 0) {
        UIUtil.drawLine(g, x, y + insets.top - 1, x + width - 1, y + insets.top - 1);
        UIUtil.drawLine(g, x, y + insets.top, x + width - 1, y + insets.top);
      }

      if (insets.left > 0) {
        UIUtil.drawLine(g, x, y, x, y + height);
        UIUtil.drawLine(g, x + 1, y, x + 1, y + height);
      }

      if (insets.right > 0) {
        UIUtil.drawLine(g, x + width - 1, y + insets.top, x + width - 1, y + height);
        UIUtil.drawLine(g, x + width, y + insets.top, x + width, y + height);
      }

      if (insets.bottom > 0) {
        UIUtil.drawLine(g, x, y + height - 1, x + width, y + height - 1);
        UIUtil.drawLine(g, x, y + height, x + width, y + height);
      }
    }
  private void paintLineMarkerSeparator(RangeHighlighter marker, Rectangle clip, Graphics g) {
    Color separatorColor = marker.getLineSeparatorColor();
    LineSeparatorRenderer lineSeparatorRenderer = marker.getLineSeparatorRenderer();
    if (separatorColor == null && lineSeparatorRenderer == null) {
      return;
    }
    int line =
        myDocument.getLineNumber(
            marker.getLineSeparatorPlacement() == SeparatorPlacement.TOP
                ? marker.getStartOffset()
                : marker.getEndOffset());
    int visualLine =
        myView.logicalToVisualPosition(
                new LogicalPosition(
                    line + (marker.getLineSeparatorPlacement() == SeparatorPlacement.TOP ? 0 : 1),
                    0),
                false)
            .line;
    int y = myView.visualLineToY(visualLine) - 1;
    int endShift = clip.x + clip.width;
    EditorSettings settings = myEditor.getSettings();
    if (settings.isRightMarginShown()
        && myEditor.getColorsScheme().getColor(EditorColors.RIGHT_MARGIN_COLOR) != null) {
      endShift =
          Math.min(
              endShift,
              settings.getRightMargin(myEditor.getProject()) * myView.getPlainSpaceWidth());
    }

    g.setColor(separatorColor);
    if (lineSeparatorRenderer != null) {
      lineSeparatorRenderer.drawLine(g, 0, endShift, y);
    } else {
      UIUtil.drawLine(g, 0, y, endShift, y);
    }
  }
 public static void drawDoubleShadowedLine(
     @NotNull Graphics2D g, int startX, int endX, int y, @NotNull Color color) {
   UIUtil.drawLine(g, startX, y, endX, y, null, getFramingColor(color));
   UIUtil.drawLine(g, startX, y + 1, endX, y + 1, null, color);
 }
 private void paintTextEffect(
     Graphics2D g, float xFrom, float xTo, int y, Color effectColor, EffectType effectType) {
   int xStart = (int) xFrom;
   int xEnd = (int) xTo;
   g.setColor(effectColor);
   if (effectType == EffectType.LINE_UNDERSCORE) {
     UIUtil.drawLine(g, xStart, y + 1, xEnd, y + 1);
   } else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) {
     int height = JBUI.scale(Registry.intValue("editor.bold.underline.height", 2));
     g.fillRect(xStart, y, xEnd - xStart, height);
   } else if (effectType == EffectType.STRIKEOUT) {
     int y1 = y - myView.getCharHeight() / 2;
     UIUtil.drawLine(g, xStart, y1, xEnd, y1);
   } else if (effectType == EffectType.WAVE_UNDERSCORE) {
     UIUtil.drawWave(g, new Rectangle(xStart, y + 1, xEnd - xStart, myView.getDescent() - 1));
   } else if (effectType == EffectType.BOLD_DOTTED_LINE) {
     UIUtil.drawBoldDottedLine(
         g,
         xStart,
         xEnd,
         SystemInfo.isMac ? y : y + 1,
         myEditor.getBackgroundColor(),
         g.getColor(),
         false);
   }
 }