org.jfree.chart.block.RectangleConstraint Java Examples

The following examples show how to use org.jfree.chart.block.RectangleConstraint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BorderArrangementTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This test is for a particular bug that arose just prior to the release
 * of JFreeChart 1.0.10.  A BorderArrangement with LEFT, CENTRE and RIGHT
 * blocks that is too wide, by default, for the available space, wasn't
 * shrinking the centre block as expected.
 */
public void testBugX() {
    RectangleConstraint constraint = new RectangleConstraint(
            new Range(0.0, 200.0), new Range(0.0, 100.0));
    BlockContainer container = new BlockContainer(new BorderArrangement());
    BufferedImage image = new BufferedImage(200, 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();

    container.add(new EmptyBlock(10.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(20.0, 6.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(30.0, 6.0));
    Size2D size = container.arrange(g2, constraint);
    assertEquals(60.0, size.width, EPSILON);
    assertEquals(6.0, size.height, EPSILON);

    container.clear();
    container.add(new EmptyBlock(10.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(20.0, 6.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(300.0, 6.0));
    size = container.arrange(g2, constraint);
    assertEquals(200.0, size.width, EPSILON);
    assertEquals(6.0, size.height, EPSILON);


}
 
Example #2
Source File: LegendTitle.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: LegendTitle.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: LegendTitle.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * 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 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;
}
 
Example #5
Source File: LegendTitle.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 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;
}
 
Example #6
Source File: LegendTitle.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 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;
}
 
Example #7
Source File: LegendTitle.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 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;
}
 
Example #8
Source File: LegendTitle.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: LegendTitle.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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;
}
 
Example #10
Source File: LegendTitle.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 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;
}
 
Example #11
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle less blocks than grid spaces.
 */
public void testGridNotFull_NN() {
    Block b1 = new EmptyBlock(5, 5);
    BlockContainer c = new BlockContainer(new GridArrangement(2, 3));
    c.add(b1);
    Size2D s = c.arrange(null, RectangleConstraint.NONE);
    assertEquals(15.0, s.getWidth(), EPSILON);
    assertEquals(10.0, s.getHeight(), EPSILON);
}
 
Example #12
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle less blocks than grid spaces.
 */
public void testGridNotFull_FR() {
    Block b1 = new EmptyBlock(5, 5);
    BlockContainer c = new BlockContainer(new GridArrangement(2, 3));
    c.add(b1);
    Size2D s = c.arrange(null, new RectangleConstraint(30.0, new Range(5.0,
            10.0)));
    assertEquals(30.0, s.getWidth(), EPSILON);
    assertEquals(10.0, s.getHeight(), EPSILON);
}
 
Example #13
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle less blocks than grid spaces.
 */
public void testGridNotFull_FN() {
    Block b1 = new EmptyBlock(5, 5);
    BlockContainer c = new BlockContainer(new GridArrangement(2, 3));
    c.add(b1);
    Size2D s = c.arrange(null, RectangleConstraint.NONE.toFixedWidth(30.0));
    assertEquals(30.0, s.getWidth(), EPSILON);
    assertEquals(10.0, s.getHeight(), EPSILON);
}
 
Example #14
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with no constraints.
 */
public void testNN() {
    BlockContainer c = createTestContainer1();
    Size2D s = c.arrange(null, RectangleConstraint.NONE);
    assertEquals(90.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}
 
Example #15
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with no constraints.
 */
public void testFN() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = new RectangleConstraint(
        100.0, null, LengthConstraintType.FIXED, 
        0.0, null, LengthConstraintType.NONE
    );
    Size2D s = c.arrange(null, constraint);
    assertEquals(100.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}
 
Example #16
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with no constraints.
 */
public void testNN() {
    BlockContainer c = createTestContainer1();
    Size2D s = c.arrange(null, RectangleConstraint.NONE);
    assertEquals(90.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}
 
Example #17
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle null blocks in the layout.
 */
public void testNullBlock_NN() {
    BlockContainer c = new BlockContainer(new GridArrangement(1, 1));
    c.add(null);
    Size2D s = c.arrange(null, RectangleConstraint.NONE);
    assertEquals(0.0, s.getWidth(), EPSILON);
    assertEquals(0.0, s.getHeight(), EPSILON);
}
 
Example #18
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with a fixed width and no height constraint.
 */
public void testFN() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = new RectangleConstraint(100.0, null,
            LengthConstraintType.FIXED, 0.0, null,
            LengthConstraintType.NONE);
    Size2D s = c.arrange(null, constraint);
    assertEquals(100.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}
 
Example #19
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with a fixed height and no width constraint.
 */
public void testNF() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = RectangleConstraint.NONE.toFixedHeight(
            100.0);
    Size2D s = c.arrange(null, constraint);
    assertEquals(90.0, s.width, EPSILON);
    assertEquals(100.0, s.height, EPSILON);
}
 
Example #20
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with a range for the width and a fixed height.
 */
public void testRF() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = new RectangleConstraint(new Range(40.0,
            60.0), 100.0);
    Size2D s = c.arrange(null, constraint);
    assertEquals(60.0, s.width, EPSILON);
    assertEquals(100.0, s.height, EPSILON);
}
 
Example #21
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with a range for the width and height.
 */
public void testRR() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = new RectangleConstraint(new Range(40.0,
            60.0), new Range(50.0, 70.0));
    Size2D s = c.arrange(null, constraint);
    assertEquals(60.0, s.width, EPSILON);
    assertEquals(50.0, s.height, EPSILON);
}
 
Example #22
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with a range for the width and no height constraint.
 */
public void testRN() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = RectangleConstraint.NONE.toRangeWidth(
            new Range(40.0, 60.0));
    Size2D s = c.arrange(null, constraint);
    assertEquals(60.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}
 
Example #23
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test arrangement with a range for the height and no width constraint.
 */
public void testNR() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = RectangleConstraint.NONE.toRangeHeight(
            new Range(40.0, 60.0));
    Size2D s = c.arrange(null, constraint);
    assertEquals(90.0, s.width, EPSILON);
    assertEquals(40.0, s.height, EPSILON);
}
 
Example #24
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle null blocks in the layout.
 */
public void testNullBlock_FF() {
    BlockContainer c = new BlockContainer(new GridArrangement(1, 1));
    c.add(null);
    Size2D s = c.arrange(null, new RectangleConstraint(20, 10));
    assertEquals(20.0, s.getWidth(), EPSILON);
    assertEquals(10.0, s.getHeight(), EPSILON);
}
 
Example #25
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle null blocks in the layout.
 */
public void testNullBlock_FN() {
    BlockContainer c = new BlockContainer(new GridArrangement(1, 1));
    c.add(null);
    Size2D s = c.arrange(null, RectangleConstraint.NONE.toFixedWidth(10));
    assertEquals(10.0, s.getWidth(), EPSILON);
    assertEquals(0.0, s.getHeight(), EPSILON);
}
 
Example #26
Source File: GridArrangementTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle less blocks than grid spaces.
 */
public void testGridNotFull_FF() {
    Block b1 = new EmptyBlock(5, 5);
    BlockContainer c = new BlockContainer(new GridArrangement(2, 3));
    c.add(b1);
    Size2D s = c.arrange(null, new RectangleConstraint(200, 100));
    assertEquals(200.0, s.getWidth(), EPSILON);
    assertEquals(100.0, s.getHeight(), EPSILON);
}
 
Example #27
Source File: RectangleConstraintTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Run some checks on the constrained size calculation.
 */
public void testCalculateConstrainedSize() {
    Size2D s;

    // NONE / NONE
    RectangleConstraint c1 = RectangleConstraint.NONE;
    s = c1.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 1.2, EPSILON);
    assertEquals(s.height, 3.4, EPSILON);

    // NONE / RANGE
    RectangleConstraint c2 = new RectangleConstraint(
        0.0, new Range(0.0, 0.0), LengthConstraintType.NONE,
        0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE
    );
    s = c2.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 1.2, EPSILON);
    assertEquals(s.height, 3.0, EPSILON);

    // NONE / FIXED
    RectangleConstraint c3 = new RectangleConstraint(
        0.0, null, LengthConstraintType.NONE,
        9.9, null, LengthConstraintType.FIXED
    );
    s = c3.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 1.2, EPSILON);
    assertEquals(s.height, 9.9, EPSILON);

    // RANGE / NONE
    RectangleConstraint c4 = new RectangleConstraint(
        0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE,
        0.0, new Range(0.0, 0.0), LengthConstraintType.NONE
    );
    s = c4.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 2.0, EPSILON);
    assertEquals(s.height, 3.4, EPSILON);

    // RANGE / RANGE
    RectangleConstraint c5 = new RectangleConstraint(
        0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE,
        0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE
    );
    s = c5.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 2.0, EPSILON);
    assertEquals(s.height, 3.0, EPSILON);

    // RANGE / FIXED
    RectangleConstraint c6 = new RectangleConstraint(
        0.0, null, LengthConstraintType.NONE,
        9.9, null, LengthConstraintType.FIXED
    );
    s = c6.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 1.2, EPSILON);
    assertEquals(s.height, 9.9, EPSILON);

    // FIXED / NONE
    RectangleConstraint c7 = RectangleConstraint.NONE;
    s = c7.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 1.2, EPSILON);
    assertEquals(s.height, 3.4, EPSILON);

    // FIXED / RANGE
    RectangleConstraint c8 = new RectangleConstraint(
        0.0, new Range(0.0, 0.0), LengthConstraintType.NONE,
        0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE
    );
    s = c8.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 1.2, EPSILON);
    assertEquals(s.height, 3.0, EPSILON);

    // FIXED / FIXED
    RectangleConstraint c9 = new RectangleConstraint(
        0.0, null, LengthConstraintType.NONE,
        9.9, null, LengthConstraintType.FIXED
    );
    s = c9.calculateConstrainedSize(new Size2D(1.2, 3.4));
    assertEquals(s.width, 1.2, EPSILON);
    assertEquals(s.height, 9.9, EPSILON);

}
 
Example #28
Source File: XYTitleAnnotation.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the annotation.  This method is called by the drawing code in the 
 * {@link XYPlot} class, you don't normally need to call this method 
 * directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis, 
                 int rendererIndex,
                 PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            rangeAxisLocation, orientation);
    Range xRange = domainAxis.getRange();
    Range yRange = rangeAxis.getRange();
    double anchorX = 0.0;
    double anchorY = 0.0;
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
        anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
    }
    else {
        anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
        anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    }
    
    float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, 
            domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, 
            rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }
    
    double maxW = dataArea.getWidth();
    double maxH = dataArea.getHeight();
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        if (this.maxWidth > 0.0) {
            maxW = maxW * this.maxWidth;
        }
        if (this.maxHeight > 0.0) {
            maxH = maxH * this.maxHeight;
        }
    }
    if (this.coordinateType == XYCoordinateType.DATA) {
        maxW = this.maxWidth;
        maxH = this.maxHeight;
    }
    RectangleConstraint rc = new RectangleConstraint(
            new Range(0, maxW), new Range(0, maxH));
    
    Size2D size = this.title.arrange(g2, rc);
    Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, 
            size.height);
    Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, 
            this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight());
    BlockParams p = new BlockParams();
    if (info != null) {
        if (info.getOwner().getEntityCollection() != null) {
            p.setGenerateEntities(true);
        }
    }
    Object result = this.title.draw(g2, titleRect, p);
    if (info != null) {
        if (result instanceof EntityBlockResult) {
            EntityBlockResult ebr = (EntityBlockResult) result;
            info.getOwner().getEntityCollection().addAll(
                    ebr.getEntityCollection());
        }
        String toolTip = getToolTipText();
        String url = getURL();
        if (toolTip != null || url != null) {
            addEntity(info, new Rectangle2D.Float(xx, yy, 
            		(float) size.width, (float) size.height), 
            		rendererIndex, toolTip, url);
        }
    }
}
 
Example #29
Source File: ShortTextTitle.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Performs a layout for this title, subject to the supplied constraint,
 * and returns the dimensions required for the title (if the title
 * cannot be displayed in the available space, this method will return
 * zero width and height for the dimensions).
 *
 * @param g2  the graphics target.
 * @param constraint  the layout constraints.
 *
 * @return The dimensions for the title.
 */
@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 = arrangeNN(g2);
        }
        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) {
            contentSize = arrangeRN(g2, cc.getWidthRange());
        }
        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) {
            contentSize = arrangeFN(g2, cc.getWidth());
        }
        else if (h == LengthConstraintType.RANGE) {
            throw new RuntimeException("Not yet implemented.");
        }
        else if (h == LengthConstraintType.FIXED) {
            throw new RuntimeException("Not yet implemented.");
        }
    }
    assert contentSize != null;
    if (contentSize.width <= 0.0 || contentSize.height <= 0.0) {
        return new Size2D(0.0, 0.0);
    }
    else {
        return new Size2D(calculateTotalWidth(contentSize.getWidth()),
                calculateTotalHeight(contentSize.getHeight()));
    }
}
 
Example #30
Source File: PaintScaleLegend.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.");
        }
    }
    assert contentSize != null; // suppress compiler warning
    return new Size2D(calculateTotalWidth(contentSize.getWidth()),
            calculateTotalHeight(contentSize.getHeight()));
}