/** * Returns the value within the range that is closest to the specified * value. * * @param value the value. * * @return The constrained value. */ public double constrain(double value) { double result = value; if (!contains(value)) { if (value > this.upper) { result = this.upper; } else if (value < this.lower) { result = this.lower; } } return result; }
/** * Returns the value within the range that is closest to the specified * value. * * @param value the value. * * @return The constrained value. */ public double constrain(double value) { double result = value; if (!contains(value)) { if (value > this.upper) { result = this.upper; } else if (value < this.lower) { result = this.lower; } } return result; }
/** * Utility method for drawing a vertical line on the data area of the plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getDomainAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getRangeAxis(); } if (axis.getRange().contains(value)) { double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
/** * Arranges the content for this title assuming a range constraint for the * width and no bounds on the height, and returns the required size. * * @param g2 the graphics target. * @param widthRange the range for the width. * * @return The content size. */ 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); }
/** * Arranges the content for this title assuming a range constraint for the * width and no bounds on the height, and returns the required size. * * @param g2 the graphics target. * @param widthRange the range for the width. * * @return The content size. */ @Override 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); }
/** * 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); }
/** * Arranges the blocks with the overall width and height to fit within * specified ranges. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size after the arrangement. */ protected Size2D arrangeRR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // first arrange without constraints, and see if this fits within // the required ranges... Size2D s1 = arrangeNN(container, g2); if (constraint.getWidthRange().contains(s1.width)) { return s1; // TODO: we didn't check the height yet } else { RectangleConstraint c = constraint.toFixedWidth( constraint.getWidthRange().getUpperBound()); return arrangeFR(container, g2, c); } }
/** * 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); } }
/** * Arranges the blocks in the container with a range constraint on the * width and a fixed height. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @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); } }
/** * Arranges the blocks in the container using a fixed height and a * range for the width. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size of the container after 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); } }
/** * Arranges the blocks in the container with a fixed width and a range * constraint on the height. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @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); } }
/** * 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); } }
/** * Arranges the blocks in the container with a fixed width and a range * constraint on the height. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @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); } }
/** * Arranges the blocks in the container with a range constraint on the * width and a fixed height. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @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); } }
/** * 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); } }
/** * Arrange with a fixed width and no height constraint. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeRN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedWidth(); Size2D size1 = arrange(container, g2, c1); if (constraint.getWidthRange().contains(size1.getWidth())) { return size1; } else { double w = constraint.getWidthRange().constrain(size1.getWidth()); RectangleConstraint c2 = constraint.toFixedWidth(w); return arrange(container, g2, c2); } }
/** * Arrange with a fixed height and a width within a given range. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeRF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedWidth(); Size2D size1 = arrange(container, g2, c1); if (constraint.getWidthRange().contains(size1.getWidth())) { return size1; } else { double w = constraint.getWidthRange().constrain(size1.getWidth()); RectangleConstraint c2 = constraint.toFixedWidth(w); return arrange(container, g2, c2); } }
/** * Arrange with a fixed height and no width constraint. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeNR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedHeight(); Size2D size1 = arrange(container, g2, c1); 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); } }
/** * Arrange with a fixed width and a height within a given range. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeFR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedHeight(); Size2D size1 = arrange(container, g2, c1); 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); } }
/** * Arrange with a fixed height and no width constraint. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeNR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedHeight(); Size2D size1 = arrange(container, g2, c1); 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); } }