コード例 #1
0
  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);
  }
コード例 #2
0
  private RangeHighlighter getNearestRangeHighlighter(final MouseEvent e, final int width) {
    List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
    getNearestHighlighters(this, e, width, highlighters);
    getNearestHighlighters(
        (MarkupModelEx) myEditor.getDocument().getMarkupModel(myEditor.getProject()),
        e,
        width,
        highlighters);
    RangeHighlighter nearestMarker = null;
    int yPos = 0;
    for (RangeHighlighter highlighter : highlighters) {
      final int newYPos =
          offsetToYPosition(highlighter.getStartOffset(), highlighter.getEndOffset())
              .getStartOffset();

      if (nearestMarker == null || Math.abs(yPos - e.getY()) > Math.abs(newYPos - e.getY())) {
        nearestMarker = highlighter;
        yPos = newYPos;
      }
    }
    return nearestMarker;
  }
コード例 #3
0
  void paint(Graphics2D g) {
    Rectangle clip = g.getClipBounds();

    if (myEditor.getContentComponent().isOpaque()) {
      g.setColor(myEditor.getBackgroundColor());
      g.fillRect(clip.x, clip.y, clip.width, clip.height);
    }

    if (paintPlaceholderText(g)) {
      paintCaret(g);
      return;
    }

    int startLine = myView.yToVisualLine(Math.max(clip.y, 0));
    int endLine = myView.yToVisualLine(Math.max(clip.y + clip.height, 0));
    int startOffset = myView.visualPositionToOffset(new VisualPosition(startLine, 0));
    int endOffset = myView.visualPositionToOffset(new VisualPosition(endLine + 1, 0, true));
    ClipDetector clipDetector = new ClipDetector(myEditor, clip);

    paintBackground(g, clip, startLine, endLine);
    paintRightMargin(g, clip);
    paintCustomRenderers(g, startOffset, endOffset);
    MarkupModelEx docMarkup =
        (MarkupModelEx) DocumentMarkupModel.forDocument(myDocument, myEditor.getProject(), true);
    paintLineMarkersSeparators(g, clip, docMarkup, startOffset, endOffset);
    paintLineMarkersSeparators(g, clip, myEditor.getMarkupModel(), startOffset, endOffset);
    paintTextWithEffects(g, clip, startLine, endLine);
    paintHighlightersAfterEndOfLine(g, docMarkup, startOffset, endOffset);
    paintHighlightersAfterEndOfLine(g, myEditor.getMarkupModel(), startOffset, endOffset);
    paintBorderEffect(g, clipDetector, myEditor.getHighlighter(), startOffset, endOffset);
    paintBorderEffect(g, clipDetector, docMarkup, startOffset, endOffset);
    paintBorderEffect(g, clipDetector, myEditor.getMarkupModel(), startOffset, endOffset);

    paintCaret(g);

    paintComposedTextDecoration(g);
  }
コード例 #4
0
 private void paintLineExtensions(Graphics2D g, int line, float x, int y) {
   Project project = myEditor.getProject();
   VirtualFile virtualFile = myEditor.getVirtualFile();
   if (project == null || virtualFile == null) return;
   for (EditorLinePainter painter : EditorLinePainter.EP_NAME.getExtensions()) {
     Collection<LineExtensionInfo> extensions =
         painter.getLineExtensions(project, virtualFile, line);
     if (extensions != null) {
       for (LineExtensionInfo info : extensions) {
         LineLayout layout =
             new LineLayout(myView, info.getText(), info.getFontType(), g.getFontRenderContext());
         g.setColor(info.getColor());
         x =
             paintLineLayoutWithEffect(
                 g, layout, x, y, info.getEffectColor(), info.getEffectType());
         int currentLineWidth = (int) x;
         EditorSizeManager sizeManager = myView.getSizeManager();
         if (currentLineWidth > sizeManager.getMaxLineWithExtensionWidth()) {
           sizeManager.setMaxLineWithExtensionWidth(line, currentLineWidth);
         }
       }
     }
   }
 }
コード例 #5
0
  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);
    }
  }