示例#1
0
 @Override
 public void paint(Graphics g) {
   Rectangle clipBounds = g.getClipBounds();
   paintBackgroundAndFoldingLine(g, clipBounds);
   paintTextColumns(g, clipBounds);
   paintIconRenderers(g, clipBounds);
   paintFoldingArea(g, clipBounds);
 }
示例#2
0
文件: LiteGroup.java 项目: URMC/i2b2
 /**
  * Paint each <code>Lite</code> object in turn after testing if it is inside the clip of the
  * Graphics. This is the right way to do it if the repainting time of <code>Lite</code> objects is
  * much greater than the time required to compute its bounds.
  *
  * @see excentric.LiteGroup#paintAll(java.awt.Graphics)
  */
 public void paint(Graphics g) {
   Rectangle clip = g.getClipBounds();
   for (Enumeration e = lites.elements(); e.hasMoreElements(); ) {
     Lite l = (Lite) e.nextElement();
     // if (l.getBounds().intersects(clip))
     l.paint(g);
   }
 }
示例#3
0
  /**
   * This method will draw the axes.
   *
   * @param gc the graphics
   * @return the (clipped) graphics for the line
   */
  Graphics paintAxis(Graphics gc) {
    int originx = 0;
    int originy = 0;

    Rectangle space = gc.getClipBounds();
    int yTickLen = (int) (space.width * axispercent / 100.0);
    if (yTickLen < 2) {
      yTickLen = 2;
    } else if (yTickLen > 5) {
      yTickLen = 5;
    }

    int xTickLen = (int) (space.height * axispercent / 100.0);
    if (xTickLen < 2) {
      xTickLen = 2;
    } else if (xTickLen > 5) {
      xTickLen = 5;
    }
    originx = yTickLen;
    originy = space.height - xTickLen;

    // do the Y axis
    int tickoff = space.height / (numYTicks - 1);
    int x1 = 0;
    int x2 = originx;
    int y1 = originy;

    for (int tick = 0; tick < numYTicks; tick++) {
      gc.drawLine(x1, y1, x2, y1);
      y1 -= tickoff;
    }
    gc.drawLine(originx, originy, originx, y1 + tickoff);

    // do the X axis
    tickoff = space.width / (numXTicks - 1);
    x1 = originx;
    y1 = space.height;
    int y2 = originy;

    for (int tick = 0; tick < numXTicks; tick++) {
      gc.drawLine(x1, y1, x1, y2);
      x1 += tickoff;
    }

    // now draw the X axis
    gc.drawLine(originx, originy, space.width, originy);

    gc = gc.create(originx + 1, 0, space.width - originx - 1, originy);
    return gc;
  }
  public void paint(Graphics g, JComponent c) {
    if (grid.getRowCount() <= 0 || grid.getColumnCount() <= 0) {
      return; // nothing to paint
    }

    Rectangle clip = g.getClipBounds();
    Point minLocation = clip.getLocation();
    Point maxLocation = new Point(clip.x + clip.width - 1, clip.y + clip.height - 1);
    int rowMin = grid.rowAtPoint(minLocation);
    int rowMax = grid.rowAtPoint(maxLocation);
    // This should never happen.
    if (rowMin == -1) {
      rowMin = 0;
    }
    // If the spread does not have enough rows to fill the view we'll get -1.
    // Replace this with the index of the last row.
    if (rowMax == -1) {
      rowMax = grid.getRowCount() - 1;
    }
    int colMin = grid.columnAtPoint(minLocation);
    int colMax = grid.columnAtPoint(maxLocation);
    // This should never happen.
    if (colMin == -1) {
      colMin = 0;
    }
    // If the spread does not have enough columns to fill the view we'll get -1.
    // Replace this with the index of the last column.
    if (colMax == -1) {
      colMax = grid.getColumnCount() - 1;
    }

    // Paint cells
    paintCells(g, rowMin, rowMax, colMin, colMax);

    // Paint grid
    paintGrid(g, rowMin, rowMax, colMin, colMax);

    // Paint spans
    paintSpans(g, rowMin, rowMax, colMin, colMax);

    // Paint borders
    paintBorders(g, rowMin, rowMax, colMin, colMax);

    // Paint editor
    paintEditor(g);
  }
    @Override
    protected void paintTrack(Graphics g, JComponent c, Rectangle bounds) {
      g.setColor(TRACK_BACKGROUND);
      g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);

      g.setColor(TRACK_BORDER);
      int border = isMirrored() ? bounds.x + bounds.width - 1 : bounds.x;
      g.drawLine(border, bounds.y, border, bounds.y + bounds.height);

      ((ApplicationImpl) ApplicationManager.getApplication()).editorPaintStart();

      try {
        Rectangle clipBounds = g.getClipBounds();
        repaint(g, ERROR_ICON_WIDTH - 1, clipBounds);
      } finally {
        ((ApplicationImpl) ApplicationManager.getApplication()).editorPaintFinish();
      }
    }
  /** special paint handler for merged cell regions */
  protected void paintSpans(Graphics g, int rowMin, int rowMax, int colMin, int colMax) {
    Rectangle clip = g.getClipBounds();
    Iterator cell = grid.getSpanModel().getSpanIterator();
    while (cell.hasNext()) {
      CellSpan span = (CellSpan) cell.next();
      Rectangle cellBounds = grid.getCellBounds(span.getRow(), span.getColumn());

      // Only paint cell if visible
      if (span.getLastRow() >= rowMin
          && span.getLastColumn() >= colMin
          && span.getFirstRow() <= rowMax
          && span.getFirstColumn() <= colMax) {
        paintCell(g, cellBounds, span.getRow(), span.getColumn());
        // Paint grid line around cell
        if (grid.getShowGrid()) {
          g.setColor(grid.getGridColor());
          g.drawRect(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height);
        }
      }
    }
  }
示例#7
0
        @Override
        @SuppressWarnings({"AssignmentToForLoopParameter"})
        public void paint(
            @NotNull Editor editor, @NotNull RangeHighlighter highlighter, @NotNull Graphics g) {
          int startOffset = highlighter.getStartOffset();
          final Document doc = highlighter.getDocument();
          if (startOffset >= doc.getTextLength()) return;

          final int endOffset = highlighter.getEndOffset();
          final int endLine = doc.getLineNumber(endOffset);

          int off;
          int startLine = doc.getLineNumber(startOffset);
          IndentGuideDescriptor descriptor =
              editor.getIndentsModel().getDescriptor(startLine, endLine);

          final CharSequence chars = doc.getCharsSequence();
          do {
            int start = doc.getLineStartOffset(startLine);
            int end = doc.getLineEndOffset(startLine);
            off = CharArrayUtil.shiftForward(chars, start, end, " \t");
            startLine--;
          } while (startLine > 1 && off < doc.getTextLength() && chars.charAt(off) == '\n');

          final VisualPosition startPosition = editor.offsetToVisualPosition(off);
          int indentColumn = startPosition.column;

          // It's considered that indent guide can cross not only white space but comments, javadocs
          // etc. Hence, there is a possible
          // case that the first indent guide line is, say, single-line comment where comment
          // symbols ('//') are located at the first
          // visual column. We need to calculate correct indent guide column then.
          int lineShift = 1;
          if (indentColumn <= 0 && descriptor != null) {
            indentColumn = descriptor.indentLevel;
            lineShift = 0;
          }
          if (indentColumn <= 0) return;

          final FoldingModel foldingModel = editor.getFoldingModel();
          if (foldingModel.isOffsetCollapsed(off)) return;

          final FoldRegion headerRegion =
              foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(doc.getLineNumber(off)));
          final FoldRegion tailRegion =
              foldingModel.getCollapsedRegionAtOffset(
                  doc.getLineStartOffset(doc.getLineNumber(endOffset)));

          if (tailRegion != null && tailRegion == headerRegion) return;

          final boolean selected;
          final IndentGuideDescriptor guide = editor.getIndentsModel().getCaretIndentGuide();
          if (guide != null) {
            final CaretModel caretModel = editor.getCaretModel();
            final int caretOffset = caretModel.getOffset();
            selected =
                caretOffset >= off
                    && caretOffset < endOffset
                    && caretModel.getLogicalPosition().column == indentColumn;
          } else {
            selected = false;
          }

          Point start =
              editor.visualPositionToXY(
                  new VisualPosition(startPosition.line + lineShift, indentColumn));
          final VisualPosition endPosition = editor.offsetToVisualPosition(endOffset);
          Point end =
              editor.visualPositionToXY(new VisualPosition(endPosition.line, endPosition.column));
          int maxY = end.y;
          if (endPosition.line == editor.offsetToVisualPosition(doc.getTextLength()).line) {
            maxY += editor.getLineHeight();
          }

          Rectangle clip = g.getClipBounds();
          if (clip != null) {
            if (clip.y >= maxY || clip.y + clip.height <= start.y) {
              return;
            }
            maxY = Math.min(maxY, clip.y + clip.height);
          }

          final EditorColorsScheme scheme = editor.getColorsScheme();
          g.setColor(
              selected
                  ? scheme.getColor(EditorColors.SELECTED_INDENT_GUIDE_COLOR)
                  : scheme.getColor(EditorColors.INDENT_GUIDE_COLOR));

          // There is a possible case that indent line intersects soft wrap-introduced text.
          // Example:
          //     this is a long line <soft-wrap>
          // that| is soft-wrapped
          //     |
          //     | <- vertical indent
          //
          // Also it's possible that no additional intersections are added because of soft wrap:
          //     this is a long line <soft-wrap>
          //     |   that is soft-wrapped
          //     |
          //     | <- vertical indent
          // We want to use the following approach then:
          //     1. Show only active indent if it crosses soft wrap-introduced text;
          //     2. Show indent as is if it doesn't intersect with soft wrap-introduced text;
          if (selected) {
            g.drawLine(start.x + 2, start.y, start.x + 2, maxY);
          } else {
            int y = start.y;
            int newY = start.y;
            SoftWrapModel softWrapModel = editor.getSoftWrapModel();
            int lineHeight = editor.getLineHeight();
            for (int i = Math.max(0, startLine + lineShift); i < endLine && newY < maxY; i++) {
              List<? extends SoftWrap> softWraps = softWrapModel.getSoftWrapsForLine(i);
              int logicalLineHeight = softWraps.size() * lineHeight;
              if (i > startLine + lineShift) {
                logicalLineHeight +=
                    lineHeight; // We assume that initial 'y' value points just below the target
                // line.
              }
              if (!softWraps.isEmpty() && softWraps.get(0).getIndentInColumns() < indentColumn) {
                if (y < newY
                    || i
                        > startLine
                            + lineShift) { // There is a possible case that soft wrap is located on
                  // indent start line.
                  g.drawLine(start.x + 2, y, start.x + 2, newY + lineHeight);
                }
                newY += logicalLineHeight;
                y = newY;
              } else {
                newY += logicalLineHeight;
              }

              FoldRegion foldRegion =
                  foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(i));
              if (foldRegion != null && foldRegion.getEndOffset() < doc.getTextLength()) {
                i = doc.getLineNumber(foldRegion.getEndOffset());
              }
            }

            if (y < maxY) {
              g.drawLine(start.x + 2, y, start.x + 2, maxY);
            }
          }
        }
示例#8
0
  /**
   * This method will draw the line.
   *
   * @param gc the graphics
   * @see #setLog
   */
  void paintLine(Graphics g) {
    double dvalue;
    int[] values = dataSet.getValues();
    // first decide the x scale factor;
    if ((dataSet == null) || (dataSet.getSize() < 1)) {
      return; // nothing to draw
    }

    // the maximum number of values we are every going to get
    int capacity = dataSet.getCapacity();

    // the available number of values at the moment
    int nr = dataSet.getSize();
    Rectangle space = g.getClipBounds();

    // pixel width of x values
    int width = space.width;
    int xscale = (int) (width / capacity);
    if (xscale < 1) {
      xscale = 1;
    }
    width = xscale * capacity;
    if (width > space.width) {
      width = space.width;
    }

    // pixel width of y values
    float yscale = (space.height) / (float) (dmax - dmin);

    // offset into array
    int xstart = 0;
    if (width < (nr * xscale)) {
      // we are lacking space
      xstart = nr - (int) (width / xscale);
    }

    // if needed reallocate some space
    int totx = nr - xstart + 1;
    if (xline.length < totx) {
      xline = new int[totx + 100];
      yline = new int[totx + 100];
    }

    // now workout where to put the first point so that
    // the last one ends up on the right hand edge
    int x = width - (int) ((nr - xstart - 1) * xscale);
    if (x < 0) {
      x = 0; // can't be negative
      System.out.println("negative start point in graph.");
    }

    int y;
    int ox = x;
    x += xscale;
    dvalue = values[xstart];
    if (doLog) {
      dvalue = log10(values[xstart]);
    }
    xstart++;
    int oy = space.height - (int) ((dvalue - dmin) * yscale);
    int pt = 0;
    for (int i = xstart; i < nr; i++) {
      dvalue = values[i];
      if (doLog) {
        dvalue = log10(values[i]);
      }
      y = space.height - (int) ((dvalue - dmin) * yscale);
      xline[pt] = x;
      yline[pt] = y;
      pt++;
      ox = x;
      oy = y;
      x += xscale;
    }
    g.drawPolyline(xline, yline, pt);
  }