/** * 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())); }
/** * 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; }
/** * 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); } }
/** * Draws the text line. * * @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 line that is aligned to the anchor point. * @param rotateX the x-coordinate for the rotation point. * @param rotateY the y-coordinate for the rotation point. * @param angle the rotation angle (in radians). */ public void draw( Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle) { Size2D dim = calculateDimensions(g2); float xAdj = 0.0f; if (anchor.isHorizontalCenter()) { xAdj = (float) -dim.getWidth() / 2.0f; } else if (anchor.isHorizontalRight()) { xAdj = (float) -dim.getWidth(); } float x = anchorX + xAdj; float yOffset = calculateBaselineOffset(g2, anchor); for (TextFragment fragment : this.fragments) { Size2D d = fragment.calculateDimensions(g2); fragment.draw(g2, x, anchorY + yOffset, TextAnchor.BASELINE_LEFT, rotateX, rotateY, angle); x = x + (float) d.getWidth(); } }
/** * 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())); }