/**
  * Performs an arrangement with a fixed width and a range for the height.
  *
  * @param container the container.
  * @param g2 the graphics device.
  * @param constraint the constraint.
  * @return The container size after the arrangement.
  */
 protected Size2D arrangeFR(
     BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {
   Size2D size1 = arrangeFN(container, g2, constraint.getWidth());
   if (constraint.getHeightRange().contains(size1.getHeight())) {
     return size1;
   } else {
     double h = constraint.getHeightRange().constrain(size1.getHeight());
     RectangleConstraint c2 = constraint.toFixedHeight(h);
     return arrange(container, g2, c2);
   }
 }
 /**
  * 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) {
   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()));
 }
Beispiel #3
0
 /**
  * Calculates the width and height of the text line.
  *
  * @param g2 the graphics device.
  * @return The width and height.
  */
 public Size2D calculateDimensions(Graphics2D g2) {
   double width = 0.0;
   double height = 0.0;
   for (TextFragment fragment : this.fragments) {
     final Size2D dimension = fragment.calculateDimensions(g2);
     width = width + dimension.getWidth();
     height = Math.max(height, dimension.getHeight());
   }
   return new Size2D(width, height);
 }
  /**
   * A utility method for determining the height of a text block.
   *
   * @param block the text block.
   * @param position the label position.
   * @param g2 the graphics device.
   * @return The height.
   */
  protected double calculateTextBlockHeight(
      TextBlock block, CategoryLabelPosition position, Graphics2D g2) {

    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(), 0.0f, 0.0f);
    double h = rotatedBox.getBounds2D().getHeight() + insets.getTop() + insets.getBottom();
    return h;
  }
 /**
  * Arranges the items in the specified container, subject to the given constraint.
  *
  * @param container the container.
  * @param g2 the graphics device.
  * @param constraint the constraint.
  * @return The block size.
  */
 @Override
 public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {
   RectangleConstraint contentConstraint = container.toContentConstraint(constraint);
   Size2D contentSize = null;
   LengthConstraintType w = contentConstraint.getWidthConstraintType();
   LengthConstraintType h = contentConstraint.getHeightConstraintType();
   if (w == LengthConstraintType.NONE) {
     if (h == LengthConstraintType.NONE) {
       contentSize = arrangeNN(container, g2);
     } else if (h == LengthConstraintType.FIXED) {
       throw new RuntimeException("Not implemented.");
     } else if (h == LengthConstraintType.RANGE) {
       throw new RuntimeException("Not implemented.");
     }
   } else if (w == LengthConstraintType.FIXED) {
     if (h == LengthConstraintType.NONE) {
       contentSize = arrangeFN(container, g2, constraint.getWidth());
     } else if (h == LengthConstraintType.FIXED) {
       contentSize = arrangeFF(container, g2, constraint);
     } else if (h == LengthConstraintType.RANGE) {
       contentSize = arrangeFR(container, g2, constraint);
     }
   } else if (w == LengthConstraintType.RANGE) {
     if (h == LengthConstraintType.NONE) {
       throw new RuntimeException("Not implemented.");
     } else if (h == LengthConstraintType.FIXED) {
       throw new RuntimeException("Not implemented.");
     } else if (h == LengthConstraintType.RANGE) {
       contentSize =
           arrangeRR(container, constraint.getWidthRange(), constraint.getHeightRange(), g2);
     }
   }
   return new Size2D(
       container.calculateTotalWidth(contentSize.getWidth()),
       container.calculateTotalHeight(contentSize.getHeight()));
 }