示例#1
0
  @Nullable
  private RangeHighlighter addBlock(
      String text,
      ChangeSide changeSide,
      final ChangeHighlighterHolder markup,
      TextDiffType diffType) {
    EditorColorsScheme colorScheme = markup.getEditor().getColorsScheme();
    Color separatorColor = getSeparatorColor(diffType.getLegendColor(colorScheme));

    int length = text.length();
    int start = changeSide.getStart();
    int end = start + length;
    RangeHighlighter highlighter =
        markup.addRangeHighlighter(
            start, end, LAYER, diffType, HighlighterTargetArea.EXACT_RANGE, myApplied);

    LineSeparatorRenderer lineSeparatorRenderer =
        new LineSeparatorRenderer() {
          @Override
          public void drawLine(Graphics g, int x1, int x2, int y) {
            Graphics2D g2 = (Graphics2D) g;
            Color color = myDiffType.getPolygonColor(markup.getEditor());
            if (color != null) {
              if (myApplied) {
                UIUtil.drawBoldDottedLine(g2, x1, x2, y, null, color, false);
              } else {
                UIUtil.drawLine(g2, x1, y, x2, y, null, DiffUtil.getFramingColor(color));
              }
            }
          }
        };

    if (highlighter != null) {
      highlighter.setLineSeparatorPlacement(SeparatorPlacement.TOP);
      highlighter.setLineSeparatorColor(separatorColor);
      highlighter.setLineSeparatorRenderer(lineSeparatorRenderer);
    }

    if (text.charAt(length - 1) == '\n') {
      end--;
    }

    highlighter =
        markup.addRangeHighlighter(
            start, end, LAYER, TextDiffType.NONE, HighlighterTargetArea.EXACT_RANGE, myApplied);
    if (highlighter != null) {
      highlighter.setLineSeparatorPlacement(SeparatorPlacement.BOTTOM);
      highlighter.setLineSeparatorColor(separatorColor);
      highlighter.setLineSeparatorRenderer(lineSeparatorRenderer);
    }
    return highlighter;
  }
示例#2
0
 @Nullable
 private RangeHighlighter addLine(
     final ChangeHighlighterHolder markup,
     int line,
     final TextDiffType type,
     SeparatorPlacement placement) {
   RangeHighlighter highlighter = markup.addLineHighlighter(line, LAYER, type, myApplied);
   if (highlighter == null) {
     return null;
   }
   highlighter.setLineSeparatorPlacement(placement);
   highlighter.setLineSeparatorRenderer(
       new LineSeparatorRenderer() {
         @Override
         public void drawLine(Graphics g, int x1, int x2, int y) {
           Graphics2D g2 = (Graphics2D) g;
           Color color = myDiffType.getPolygonColor(markup.getEditor());
           if (color != null) {
             if (type.isApplied()) {
               UIUtil.drawBoldDottedLine(g2, x1, x2, y, null, color, false);
             } else {
               DiffUtil.drawDoubleShadowedLine(g2, x1, x2, y, color);
             }
           }
         }
       });
   return highlighter;
 }