org.jfree.chart.block.LengthConstraintType Java Examples

The following examples show how to use org.jfree.chart.block.LengthConstraintType. 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: 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 #2
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 #3
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 #4
Source File: TextTitle.java    From astor with GNU General Public License v2.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>).
 */
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.");
        }
    }
    return new Size2D(calculateTotalWidth(contentSize.getWidth()),
            calculateTotalHeight(contentSize.getHeight()));
}
 
Example #5
Source File: ShortTextTitle.java    From astor with GNU General Public License v2.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.
 */
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.");
        }
    }
    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 #6
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 #7
Source File: TextTitle.java    From astor with GNU General Public License v2.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>).
 */
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) {
            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.");                 
        }            
    }
    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()));
}
 
Example #8
Source File: TextTitle.java    From opensim-gui with Apache License 2.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>).
 */
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) {
            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.");                 
        }            
    }
    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()));
}