コード例 #1
0
ファイル: PhotoGraphAxis.java プロジェクト: BodyTrack/Grapher
  /** Draws this axis. */
  @Override
  public void paint(final int newPaintEventId) {
    // guard against redundant paints
    if (previousPaintEventId != newPaintEventId) {
      previousPaintEventId = newPaintEventId;

      final Canvas canvas = getDrawingCanvas();
      if (canvas == null) {
        return;
      }

      canvas.getSurface().clear();

      // Pick the color to use, based on highlighting status
      if (isHighlighted()) {
        canvas.setStrokeStyle(HIGHLIGHTED_COLOR);
      } else {
        canvas.setStrokeStyle(NORMAL_COLOR);
      }

      final double x = project2D(INITIAL_MIN).getX();
      final double width = getWidth();

      // Now figure out where the line should go, drawing ticks
      // as we go along
      double topValue = PHOTO_CENTER_LOCATION + PHOTO_HEIGHT / 2.0;
      double bottomValue = PHOTO_CENTER_LOCATION - PHOTO_HEIGHT / 2.0;

      // Don't draw anything at all if the line is out of bounds
      if (bottomValue > getMax() || topValue < getMin()) {
        return;
      }

      // Allow ourselves to begin drawing
      canvas.beginPath();

      if (topValue > getMax()) {
        topValue = getMax();
      } else {
        drawTick(canvas, topValue, x, width);
      }

      if (bottomValue < getMin()) {
        bottomValue = getMin();
      } else {
        drawTick(canvas, bottomValue, x, width);
      }

      // Get the values in pixels for where the line should go
      final double topY = projectY(topValue);
      final double bottomY = projectY(bottomValue);

      // Now draw the vertical line
      canvas.getRenderer().drawLineSegment(x, topY, x, bottomY);

      // Actually render all our ticks and lines on the canvas
      canvas.stroke();

      // Clean up after ourselves
      canvas.setStrokeStyle(Canvas.DEFAULT_COLOR);
    }
  }