コード例 #1
0
 /**
  * Arranges the contents of the block, within the given constraints, and returns the block size.
  *
  * @param g2 the graphics device.
  * @param constraint the constraint (<code>null</code> not permitted).
  * @return The block size (in Java2D units, never <code>null</code>).
  */
 public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
   RectangleConstraint cc = toContentConstraint(constraint);
   LengthConstraintType w = cc.getWidthConstraintType();
   LengthConstraintType h = cc.getHeightConstraintType();
   Size2D contentSize = null;
   if (w == LengthConstraintType.NONE) {
     if (h == LengthConstraintType.NONE) {
       contentSize = new Size2D(getWidth(), getHeight());
     } else if (h == LengthConstraintType.RANGE) {
       throw new RuntimeException("Not yet implemented.");
     } else if (h == LengthConstraintType.FIXED) {
       throw new RuntimeException("Not yet implemented.");
     }
   } else if (w == LengthConstraintType.RANGE) {
     if (h == LengthConstraintType.NONE) {
       throw new RuntimeException("Not yet implemented.");
     } else if (h == LengthConstraintType.RANGE) {
       contentSize = arrangeRR(g2, cc.getWidthRange(), cc.getHeightRange());
     } else if (h == LengthConstraintType.FIXED) {
       throw new RuntimeException("Not yet implemented.");
     }
   } else if (w == LengthConstraintType.FIXED) {
     if (h == LengthConstraintType.NONE) {
       throw new RuntimeException("Not yet implemented.");
     } else if (h == LengthConstraintType.RANGE) {
       throw new RuntimeException("Not yet implemented.");
     } else if (h == LengthConstraintType.FIXED) {
       throw new RuntimeException("Not yet implemented.");
     }
   }
   return new Size2D(
       calculateTotalWidth(contentSize.getWidth()), calculateTotalHeight(contentSize.getHeight()));
 }
コード例 #2
0
 /**
  * Arranges the content for this title assuming a range constraint for the width and no bounds on
  * the height, and returns the required size. This will reflect the fact that a text title
  * positioned on the left or right of a chart will be rotated by 90 degrees.
  *
  * @param g2 the graphics target.
  * @param widthRange the range for the width.
  * @return The content size.
  * @since 1.0.9
  */
 protected Size2D arrangeRN(Graphics2D g2, Range widthRange) {
   Size2D s = arrangeNN(g2);
   if (widthRange.contains(s.getWidth())) {
     return s;
   }
   double ww = widthRange.constrain(s.getWidth());
   return arrangeFN(g2, ww);
 }
コード例 #3
0
ファイル: TextBlock.java プロジェクト: ti-cortex-m4/jtstand
  /**
   * Draws the text block, aligning it with the specified anchor point and rotating it about the
   * specified rotation point.
   *
   * @param g2 the graphics device.
   * @param anchorX the x-coordinate for the anchor point.
   * @param anchorY the y-coordinate for the anchor point.
   * @param anchor the point on the text block that is aligned to the anchor point.
   * @param rotateX the x-coordinate for the rotation point.
   * @param rotateY the x-coordinate for the rotation point.
   * @param angle the rotation (in radians).
   */
  public void draw(
      final Graphics2D g2,
      final float anchorX,
      final float anchorY,
      final TextBlockAnchor anchor,
      final float rotateX,
      final float rotateY,
      final double angle) {

    final Size2D d = calculateDimensions(g2);
    final float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    final Iterator iterator = this.lines.iterator();
    float yCursor = 0.0f;
    while (iterator.hasNext()) {
      TextLine line = (TextLine) iterator.next();
      Size2D dimension = line.calculateDimensions(g2);
      float lineOffset = 0.0f;
      if (this.lineAlignment == HorizontalAlignment.CENTER) {
        lineOffset = (float) (d.getWidth() - dimension.getWidth()) / 2.0f;
      } else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
        lineOffset = (float) (d.getWidth() - dimension.getWidth());
      }
      line.draw(
          g2,
          anchorX + offsets[0] + lineOffset,
          anchorY + offsets[1] + yCursor,
          TextAnchor.TOP_LEFT,
          rotateX,
          rotateY,
          angle);
      yCursor = yCursor + (float) dimension.getHeight();
    }
  }
コード例 #4
0
  /**
   * Arranges the blocks in the container with a range constraint on the width and a fixed height.
   *
   * @param container the container.
   * @param g2 the graphics device.
   * @param constraint the constraint.
   * @return The size following the arrangement.
   */
  protected Size2D arrangeRF(
      BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {

    Size2D s = arrangeNF(container, g2, constraint);
    if (constraint.getWidthRange().contains(s.width)) {
      return s;
    } else {
      RectangleConstraint c =
          constraint.toFixedWidth(constraint.getWidthRange().constrain(s.getWidth()));
      return arrangeFF(container, g2, c);
    }
  }
コード例 #5
0
  /**
   * Arranges the blocks in the container with a fixed with and a range constraint on the height.
   *
   * @param container the container.
   * @param g2 the graphics device.
   * @param constraint the constraint.
   * @return The size following the arrangement.
   */
  protected Size2D arrangeFR(
      BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {

    Size2D s = arrangeFN(container, g2, constraint);
    if (constraint.getHeightRange().contains(s.height)) {
      return s;
    } else {
      RectangleConstraint c =
          constraint.toFixedHeight(constraint.getHeightRange().constrain(s.getHeight()));
      return arrangeFF(container, g2, c);
    }
  }
コード例 #6
0
ファイル: TextBlock.java プロジェクト: ti-cortex-m4/jtstand
 /**
  * Returns the width and height of the text block.
  *
  * @param g2 the graphics device.
  * @return The width and height.
  */
 public Size2D calculateDimensions(final Graphics2D g2) {
   double width = 0.0;
   double height = 0.0;
   final Iterator iterator = this.lines.iterator();
   while (iterator.hasNext()) {
     final TextLine line = (TextLine) iterator.next();
     final Size2D dimension = line.calculateDimensions(g2);
     width = Math.max(width, dimension.getWidth());
     height = height + dimension.getHeight();
   }
   return new Size2D(width, height);
 }
コード例 #7
0
 /**
  * Arranges the contents of the block, within the given constraints, and returns the block size.
  *
  * @param g2 the graphics device.
  * @param constraint the constraint (<code>null</code> not permitted).
  * @return The block size (in Java2D units, never <code>null</code>).
  */
 public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
   Size2D result = new Size2D();
   fetchLegendItems();
   if (this.items.isEmpty()) {
     return result;
   }
   BlockContainer container = this.wrapper;
   if (container == null) {
     container = this.items;
   }
   RectangleConstraint c = toContentConstraint(constraint);
   Size2D size = container.arrange(g2, c);
   result.height = calculateTotalHeight(size.height);
   result.width = calculateTotalWidth(size.width);
   return result;
 }
コード例 #8
0
ファイル: TextBlock.java プロジェクト: ti-cortex-m4/jtstand
  /**
   * Returns the bounds of the text block.
   *
   * @param g2 the graphics device (<code>null</code> not permitted).
   * @param anchorX the x-coordinate for the anchor point.
   * @param anchorY the y-coordinate for the anchor point.
   * @param anchor the text block anchor (<code>null</code> not permitted).
   * @param rotateX the x-coordinate for the rotation point.
   * @param rotateY the y-coordinate for the rotation point.
   * @param angle the rotation angle.
   * @return The bounds.
   */
  public Shape calculateBounds(
      final Graphics2D g2,
      final float anchorX,
      final float anchorY,
      final TextBlockAnchor anchor,
      final float rotateX,
      final float rotateY,
      final double angle) {

    final Size2D d = calculateDimensions(g2);
    final float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    final Rectangle2D bounds =
        new Rectangle2D.Double(
            anchorX + offsets[0], anchorY + offsets[1], d.getWidth(), d.getHeight());
    final Shape rotatedBounds = ShapeUtilities.rotateShape(bounds, angle, rotateX, rotateY);
    return rotatedBounds;
  }
コード例 #9
0
  /**
   * Returns the content size for the title. This will reflect the fact that a text title positioned
   * on the left or right of a chart will be rotated 90 degrees.
   *
   * @param g2 the graphics device.
   * @param widthRange the width range.
   * @param heightRange the height range.
   * @return The content size.
   */
  protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) {
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
      float maxWidth = (float) widthRange.getUpperBound();
      g2.setFont(this.font);
      this.content =
          TextUtilities.createTextBlock(
              this.text,
              this.font,
              this.paint,
              maxWidth,
              this.maximumLinesToDisplay,
              new G2TextMeasurer(g2));
      this.content.setLineAlignment(this.textAlignment);
      Size2D contentSize = this.content.calculateDimensions(g2);
      if (this.expandToFitSpace) {
        return new Size2D(maxWidth, contentSize.getHeight());
      } else {
        return contentSize;
      }
    } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
      float maxWidth = (float) heightRange.getUpperBound();
      g2.setFont(this.font);
      this.content =
          TextUtilities.createTextBlock(
              this.text,
              this.font,
              this.paint,
              maxWidth,
              this.maximumLinesToDisplay,
              new G2TextMeasurer(g2));
      this.content.setLineAlignment(this.textAlignment);
      Size2D contentSize = this.content.calculateDimensions(g2);

      // transpose the dimensions, because the title is rotated
      if (this.expandToFitSpace) {
        return new Size2D(contentSize.getHeight(), maxWidth);
      } else {
        return new Size2D(contentSize.height, contentSize.width);
      }
    } else {
      throw new RuntimeException("Unrecognised exception.");
    }
  }
コード例 #10
0
 /**
  * Arranges the contents of the block, within the given constraints, and returns the block size.
  *
  * @param g2 the graphics device.
  * @param constraint the constraint (<code>null</code> not permitted).
  * @return The block size (in Java2D units, never <code>null</code>).
  */
 @Override
 public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
   Size2D contentSize = arrangeExtracted(constraint, g2);
   return new Size2D(
       calculateTotalWidth(contentSize.getWidth()), calculateTotalHeight(contentSize.getHeight()));
 }