Search in sources :

Example 1 with TextLine

use of org.jfree.text.TextLine in project SIMVA-SoS by SESoS.

the class CategoryTickTest method testHashCode.

/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    Comparable c1 = "C1";
    TextBlock tb1 = new TextBlock();
    tb1.addLine(new TextLine("Block 1"));
    tb1.addLine(new TextLine("Block 2"));
    TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
    TextAnchor ta1 = TextAnchor.CENTER;
    CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    assertTrue(t1.equals(t2));
    int h1 = t1.hashCode();
    int h2 = t2.hashCode();
    assertEquals(h1, h2);
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) TextLine(org.jfree.text.TextLine) TextBlockAnchor(org.jfree.text.TextBlockAnchor) TextBlock(org.jfree.text.TextBlock) Test(org.junit.Test)

Example 2 with TextLine

use of org.jfree.text.TextLine in project SIMVA-SoS by SESoS.

the class CategoryTickTest method testEquals.

/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    Comparable c1 = "C1";
    Comparable c2 = "C2";
    TextBlock tb1 = new TextBlock();
    tb1.addLine(new TextLine("Block 1"));
    TextBlock tb2 = new TextBlock();
    tb1.addLine(new TextLine("Block 2"));
    TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
    TextBlockAnchor tba2 = TextBlockAnchor.BOTTOM_CENTER;
    TextAnchor ta1 = TextAnchor.CENTER;
    TextAnchor ta2 = TextAnchor.BASELINE_LEFT;
    CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    assertTrue(t1.equals(t2));
    t1 = new CategoryTick(c2, tb1, tba1, ta1, 1.0f);
    assertFalse(t1.equals(t2));
    t2 = new CategoryTick(c2, tb1, tba1, ta1, 1.0f);
    assertTrue(t1.equals(t2));
    t1 = new CategoryTick(c2, tb2, tba1, ta1, 1.0f);
    assertFalse(t1.equals(t2));
    t2 = new CategoryTick(c2, tb2, tba1, ta1, 1.0f);
    assertTrue(t1.equals(t2));
    t1 = new CategoryTick(c2, tb2, tba2, ta1, 1.0f);
    assertFalse(t1.equals(t2));
    t2 = new CategoryTick(c2, tb2, tba2, ta1, 1.0f);
    assertTrue(t1.equals(t2));
    t1 = new CategoryTick(c2, tb2, tba2, ta2, 1.0f);
    assertFalse(t1.equals(t2));
    t2 = new CategoryTick(c2, tb2, tba2, ta2, 1.0f);
    assertTrue(t1.equals(t2));
    t1 = new CategoryTick(c2, tb2, tba2, ta2, 2.0f);
    assertFalse(t1.equals(t2));
    t2 = new CategoryTick(c2, tb2, tba2, ta2, 2.0f);
    assertTrue(t1.equals(t2));
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) TextLine(org.jfree.text.TextLine) TextBlockAnchor(org.jfree.text.TextBlockAnchor) TextBlock(org.jfree.text.TextBlock) Test(org.junit.Test)

Example 3 with TextLine

use of org.jfree.text.TextLine in project SIMVA-SoS by SESoS.

the class ExtendedCategoryAxis method createLabel.

/**
 * Overrides the default behaviour by adding the sublabel to the text
 * block that is used for the category label.
 *
 * @param category  the category.
 * @param width  the width (not used yet).
 * @param edge  the location of the axis.
 * @param g2  the graphics device.
 *
 * @return A label.
 */
@Override
protected TextBlock createLabel(Comparable category, float width, RectangleEdge edge, Graphics2D g2) {
    TextBlock label = super.createLabel(category, width, edge, g2);
    String s = (String) this.sublabels.get(category);
    if (s != null) {
        if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
            TextLine line = new TextLine(s, this.sublabelFont, this.sublabelPaint);
            label.addLine(line);
        } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            TextLine line = label.getLastLine();
            if (line != null) {
                line.addFragment(new TextFragment("  " + s, this.sublabelFont, this.sublabelPaint));
            }
        }
    }
    return label;
}
Also used : TextLine(org.jfree.text.TextLine) TextFragment(org.jfree.text.TextFragment) TextBlock(org.jfree.text.TextBlock)

Aggregations

TextBlock (org.jfree.text.TextBlock)3 TextLine (org.jfree.text.TextLine)3 TextBlockAnchor (org.jfree.text.TextBlockAnchor)2 TextAnchor (org.jfree.ui.TextAnchor)2 Test (org.junit.Test)2 TextFragment (org.jfree.text.TextFragment)1