Esempio n. 1
0
  /**
   * Draws the text box.
   *
   * @param g2 the graphics device.
   * @param x the x-coordinate.
   * @param y the y-coordinate.
   * @param anchor the anchor point.
   */
  public void draw(final Canvas g2, final float x, final float y, final RectangleAnchor anchor) {
    final Size2D d1 = this.textBlock.calculateDimensions(g2);
    final double w = this.interiorGap.extendWidth(d1.getWidth());
    final double h = this.interiorGap.extendHeight(d1.getHeight());
    final Size2D d2 = new Size2D(w, h);
    final Rectangle2D bounds = RectangleAnchor.createRectangle(d2, x, y, anchor);

    if (this.shadowPaint != null) {
      final Rectangle2D shadow =
          new Rectangle2D.Double(
              bounds.getX() + this.shadowXOffset,
              bounds.getY() + this.shadowYOffset,
              bounds.getWidth(),
              bounds.getHeight());
      shadowPaint.setStyle(Paint.Style.FILL);
      g2.drawRect(
          (float) shadow.getMinX(),
          (float) shadow.getMinY(),
          (float) shadow.getMaxX(),
          (float) shadow.getMaxY(),
          shadowPaint);
    }
    if (this.backgroundPaint != null) {
      this.backgroundPaint.setStyle(Paint.Style.FILL);

      g2.drawRect(
          (float) bounds.getMinX(),
          (float) bounds.getMinY(),
          (float) bounds.getMaxX(),
          (float) bounds.getMaxY(),
          backgroundPaint);
    }

    if (this.outlinePaint != null && this.outlineStroke != null) {
      this.outlinePaint.setStyle(Paint.Style.STROKE);
      this.outlinePaint.setStrokeWidth(outlineStroke);
      g2.drawRect(
          (float) bounds.getMinX(),
          (float) bounds.getMinY(),
          (float) bounds.getMaxX(),
          (float) bounds.getMaxY(),
          outlinePaint);
    }

    this.textBlock.draw(
        g2,
        (float) bounds.getCenterX(),
        (float) bounds.getCenterY(),
        TextBlockAnchor.CENTER,
        BLACK);
  }
Esempio n. 2
0
 /**
  * Returns the height of the text box.
  *
  * @param g2 the graphics device.
  * @return The height (in Java2D units).
  */
 public double getHeight(final Canvas g2) {
   final Size2D d = this.textBlock.calculateDimensions(g2);
   return this.interiorGap.extendHeight(d.getHeight());
 }