org.jfree.text.TextBox Java Examples

The following examples show how to use org.jfree.text.TextBox. 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: PieLabelRecordTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Confirm that cloning is not implemented.
 */
@Test
public void testCloning() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    assertFalse(p1 instanceof Cloneable);
}
 
Example #2
Source File: PieLabelRecord.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new record.
 *
 * @param key  the section key.
 * @param angle  the angle to the middle of the section (in radians).
 * @param baseY  the base y-coordinate.
 * @param label  the section label.
 * @param labelHeight  the label height (in Java2D units).
 * @param gap  the offset to the left.
 * @param linkPercent  the link percent.
 */
public PieLabelRecord(Comparable key, double angle, double baseY,
                      TextBox label, double labelHeight, double gap,
                      double linkPercent) {
    this.key = key;
    this.angle = angle;
    this.baseY = baseY;
    this.allocatedY = baseY;
    this.label = label;
    this.labelHeight = labelHeight;
    this.gap = gap;
    this.linkPercent = linkPercent;
}
 
Example #3
Source File: PieLabelRecord.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new record.
 *
 * @param key  the section key.
 * @param angle  the angle to the middle of the section (in radians).
 * @param baseY  the base y-coordinate.
 * @param label  the section label.
 * @param labelHeight  the label height (in Java2D units).
 * @param gap  the offset to the left.
 * @param linkPercent  the link percent.
 */
public PieLabelRecord(Comparable key, double angle, double baseY,
                      TextBox label, double labelHeight, double gap,
                      double linkPercent) {
    this.key = key;
    this.angle = angle;
    this.baseY = baseY;
    this.allocatedY = baseY;
    this.label = label;
    this.labelHeight = labelHeight;
    this.gap = gap;
    this.linkPercent = linkPercent;
}
 
Example #4
Source File: PieLabelRecordTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = (PieLabelRecord) TestUtilities.serialised(p1);
    boolean b = p1.equals(p2);
    assertTrue(b);
}
 
Example #5
Source File: PieLabelRecordTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Confirm that cloning is not implemented.
 */
@Test
public void testCloning() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    assertFalse(p1 instanceof Cloneable);
}
 
Example #6
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a section label on the right side of the pie chart.
 * 
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawRightLabel(Graphics2D g2, PiePlotState state, 
                              PieLabelRecord record) {
    
    double anchorX = state.getLinkArea().getMaxX();
    double targetX = anchorX + record.getGap();
    double targetY = record.getAllocatedY();
    
    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta) 
            * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta) 
            * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta) 
            * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta) 
            * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
        g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
        g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
    }
    
    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.LEFT);

}
 
Example #7
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a section label on the left side of the pie chart.
 * 
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawLeftLabel(Graphics2D g2, PiePlotState state, 
                             PieLabelRecord record) {

    double anchorX = state.getLinkArea().getMinX();
    double targetX = anchorX - record.getGap();
    double targetY = record.getAllocatedY();
    
    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta) 
            * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta) 
            * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta) 
            * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta) 
            * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
        g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
        g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
    }
    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT);
    
}
 
Example #8
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the left labels.
 * 
 * @param leftKeys  the keys.
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param linkArea  the link area.
 * @param maxLabelWidth  the maximum label width.
 * @param state  the state.
 */
protected void drawLeftLabels(KeyedValues leftKeys, Graphics2D g2, 
                              Rectangle2D plotArea, Rectangle2D linkArea, 
                              float maxLabelWidth, PiePlotState state) {
    
    PieLabelDistributor distributor1 = new PieLabelDistributor(
        leftKeys.getItemCount()
    );
    double lGap = plotArea.getWidth() * this.labelGap;
    double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
    for (int i = 0; i < leftKeys.getItemCount(); i++) {   
        String label = this.labelGenerator.generateSectionLabel(
                this.dataset, leftKeys.getKey(i));
        if (label != null) {
            TextBlock block = TextUtilities.createTextBlock(label, 
                    this.labelFont, this.labelPaint, maxLabelWidth, 
                    new G2TextMeasurer(g2));
            TextBox labelBox = new TextBox(block);
            labelBox.setBackgroundPaint(this.labelBackgroundPaint);
            labelBox.setOutlinePaint(this.labelOutlinePaint);
            labelBox.setOutlineStroke(this.labelOutlineStroke);
            labelBox.setShadowPaint(this.labelShadowPaint);
            double theta = Math.toRadians(
                    leftKeys.getValue(i).doubleValue());
            double baseY = state.getPieCenterY() - Math.sin(theta) 
                           * verticalLinkRadius;
            double hh = labelBox.getHeight(g2);

            distributor1.addPieLabelRecord(new PieLabelRecord(
                    leftKeys.getKey(i), theta, baseY, labelBox, hh,
                    lGap / 2.0 + lGap / 2.0 * -Math.cos(theta), 0.9 
                    + getExplodePercent(this.dataset.getIndex(
                            leftKeys.getKey(i)))));
        }
    }
    distributor1.distributeLabels(plotArea.getMinY(), plotArea.getHeight());
    for (int i = 0; i < distributor1.getItemCount(); i++) {
        drawLeftLabel(g2, state, distributor1.getPieLabelRecord(i));
    }
}
 
Example #9
Source File: PieLabelRecord.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new record.
 * 
 * @param key  the key.
 * @param angle  the angle.
 * @param baseY  the base y-coordinate.
 * @param label  the label.
 * @param labelHeight  the label height (in Java2D units).
 * @param gap  the gap.
 * @param linkPercent  the link percent.
 */
public PieLabelRecord(Comparable key, double angle, double baseY, 
                      TextBox label, double labelHeight, double gap, 
                      double linkPercent) {
    this.key = key;
    this.angle = angle;
    this.baseY = baseY;
    this.allocatedY = baseY;
    this.label = label;
    this.labelHeight = labelHeight;
    this.gap = gap;
    this.linkPercent = linkPercent;
}
 
Example #10
Source File: PieLabelRecord.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new record.
 *
 * @param key  the section key.
 * @param angle  the angle to the middle of the section (in radians).
 * @param baseY  the base y-coordinate.
 * @param label  the section label.
 * @param labelHeight  the label height (in Java2D units).
 * @param gap  the offset to the left.
 * @param linkPercent  the link percent.
 */
public PieLabelRecord(Comparable key, double angle, double baseY,
                      TextBox label, double labelHeight, double gap,
                      double linkPercent) {
    this.key = key;
    this.angle = angle;
    this.baseY = baseY;
    this.allocatedY = baseY;
    this.label = label;
    this.labelHeight = labelHeight;
    this.gap = gap;
    this.linkPercent = linkPercent;
}
 
Example #11
Source File: PieLabelRecordTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = (PieLabelRecord) TestUtilities.serialised(p1);
    boolean b = p1.equals(p2);
    assertTrue(b);
}
 
Example #12
Source File: PieLabelRecordTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that cloning is not implemented.
 */
@Test
public void testCloning() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    assertFalse(p1 instanceof Cloneable);
}
 
Example #13
Source File: PieLabelRecord.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new record.
 *
 * @param key  the section key.
 * @param angle  the angle to the middle of the section (in radians).
 * @param baseY  the base y-coordinate.
 * @param label  the section label.
 * @param labelHeight  the label height (in Java2D units).
 * @param gap  the offset to the left.
 * @param linkPercent  the link percent.
 */
public PieLabelRecord(Comparable key, double angle, double baseY,
                      TextBox label, double labelHeight, double gap,
                      double linkPercent) {
    this.key = key;
    this.angle = angle;
    this.baseY = baseY;
    this.allocatedY = baseY;
    this.label = label;
    this.labelHeight = labelHeight;
    this.gap = gap;
    this.linkPercent = linkPercent;
}
 
Example #14
Source File: PieLabelRecordTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = (PieLabelRecord) TestUtilities.serialised(p1);
    boolean b = p1.equals(p2);
    assertTrue(b);
}
 
Example #15
Source File: PieLabelRecordTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Confirm that cloning is not implemented.
 */
@Test
public void testCloning() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    assertFalse(p1 instanceof Cloneable);
}
 
Example #16
Source File: PieLabelRecordTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = (PieLabelRecord) TestUtilities.serialised(p1);
    boolean b = p1.equals(p2);
    assertTrue(b);
}
 
Example #17
Source File: PieLabelRecord.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new record.
 *
 * @param key  the section key.
 * @param angle  the angle to the middle of the section (in radians).
 * @param baseY  the base y-coordinate.
 * @param label  the section label.
 * @param labelHeight  the label height (in Java2D units).
 * @param gap  the offset to the left.
 * @param linkPercent  the link percent.
 */
public PieLabelRecord(Comparable key, double angle, double baseY,
                      TextBox label, double labelHeight, double gap,
                      double linkPercent) {
    this.key = key;
    this.angle = angle;
    this.baseY = baseY;
    this.allocatedY = baseY;
    this.label = label;
    this.labelHeight = labelHeight;
    this.gap = gap;
    this.linkPercent = linkPercent;
}
 
Example #18
Source File: PieLabelRecord.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new record.
 *
 * @param key  the section key.
 * @param angle  the angle to the middle of the section (in radians).
 * @param baseY  the base y-coordinate.
 * @param label  the section label.
 * @param labelHeight  the label height (in Java2D units).
 * @param gap  the offset to the left.
 * @param linkPercent  the link percent.
 */
public PieLabelRecord(Comparable key, double angle, double baseY,
                      TextBox label, double labelHeight, double gap,
                      double linkPercent) {
    this.key = key;
    this.angle = angle;
    this.baseY = baseY;
    this.allocatedY = baseY;
    this.label = label;
    this.labelHeight = labelHeight;
    this.gap = gap;
    this.linkPercent = linkPercent;
}
 
Example #19
Source File: PieLabelRecordTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = (PieLabelRecord) TestUtilities.serialised(p1);
    boolean b = p1.equals(p2);
    assertTrue(b);
}
 
Example #20
Source File: PieLabelRecordTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Confirm that cloning is not implemented.
 */
@Test
public void testCloning() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    assertFalse(p1 instanceof Cloneable);
}
 
Example #21
Source File: PieLabelRecordTest.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = new PieLabelRecord("B", 1.0, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.0, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.5);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.5);
    assertTrue(p1.equals(p2));

}
 
Example #22
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a section label on the right side of the pie chart.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawRightLabel(Graphics2D g2, PiePlotState state,
                              PieLabelRecord record) {

    double anchorX = state.getLinkArea().getMaxX();
    double targetX = anchorX + record.getGap();
    double targetY = record.getAllocatedY();

    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta)
                * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta)
                * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta)
                * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta)
                * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        PieLabelLinkStyle style = getLabelLinkStyle();
        if (style.equals(PieLabelLinkStyle.STANDARD)) {
            g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
        }
        else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
            QuadCurve2D q = new QuadCurve2D.Float();
            q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
            g2.draw(q);
            g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
        }
        else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
            CubicCurve2D c = new CubicCurve2D .Float();
            c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
                    linkX, linkY);
            g2.draw(c);
        }
    }

    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.LEFT);

}
 
Example #23
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a section label on the left side of the pie chart.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawLeftLabel(Graphics2D g2, PiePlotState state,
                             PieLabelRecord record) {

    double anchorX = state.getLinkArea().getMinX();
    double targetX = anchorX - record.getGap();
    double targetY = record.getAllocatedY();

    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta)
                * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta)
                * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta)
                * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta)
                * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        PieLabelLinkStyle style = getLabelLinkStyle();
        if (style.equals(PieLabelLinkStyle.STANDARD)) {
            g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
        }
        else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
            QuadCurve2D q = new QuadCurve2D.Float();
            q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
            g2.draw(q);
            g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
        }
        else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
            CubicCurve2D c = new CubicCurve2D .Float();
            c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
                    linkX, linkY);
            g2.draw(c);
        }
    }
    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT);

}
 
Example #24
Source File: PieLabelRecordTest.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = new PieLabelRecord("B", 1.0, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.0, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.5);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.5);
    assertTrue(p1.equals(p2));

}
 
Example #25
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a section label on the right side of the pie chart.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawRightLabel(Graphics2D g2, PiePlotState state,
                              PieLabelRecord record) {

    double anchorX = state.getLinkArea().getMaxX();
    double targetX = anchorX + record.getGap();
    double targetY = record.getAllocatedY();

    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta)
                * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta)
                * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta)
                * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta)
                * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        PieLabelLinkStyle style = getLabelLinkStyle();
        if (style.equals(PieLabelLinkStyle.STANDARD)) {
            g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
        }
        else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
            QuadCurve2D q = new QuadCurve2D.Float();
            q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
            g2.draw(q);
            g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
        }
        else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
            CubicCurve2D c = new CubicCurve2D .Float();
            c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
                    linkX, linkY);
            g2.draw(c);
        }
    }

    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.LEFT);

}
 
Example #26
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a section label on the left side of the pie chart.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawLeftLabel(Graphics2D g2, PiePlotState state,
                             PieLabelRecord record) {

    double anchorX = state.getLinkArea().getMinX();
    double targetX = anchorX - record.getGap();
    double targetY = record.getAllocatedY();

    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta)
                * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta)
                * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta)
                * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta)
                * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        PieLabelLinkStyle style = getLabelLinkStyle();
        if (style.equals(PieLabelLinkStyle.STANDARD)) {
            g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
        }
        else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
            QuadCurve2D q = new QuadCurve2D.Float();
            q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
            g2.draw(q);
            g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
        }
        else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
            CubicCurve2D c = new CubicCurve2D .Float();
            c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
                    linkX, linkY);
            g2.draw(c);
        }
    }
    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT);

}
 
Example #27
Source File: PieLabelRecordTest.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = new PieLabelRecord("B", 1.0, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.0, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.0, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("B"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("B"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.0, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.0, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.0, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.0, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.0);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.0);
    assertTrue(p1.equals(p2));

    p1 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.5);
    assertFalse(p1.equals(p2));
    p2 = new PieLabelRecord("B", 1.1, 2.2, new TextBox("C"), 3.3, 4.4, 5.5);
    assertTrue(p1.equals(p2));

}
 
Example #28
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a section label on the left side of the pie chart.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawLeftLabel(Graphics2D g2, PiePlotState state,
                             PieLabelRecord record) {

    double anchorX = state.getLinkArea().getMinX();
    double targetX = anchorX - record.getGap();
    double targetY = record.getAllocatedY();

    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta)
                * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta)
                * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta)
                * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta)
                * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        PieLabelLinkStyle style = getLabelLinkStyle();
        if (style.equals(PieLabelLinkStyle.STANDARD)) {
            g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
        }
        else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
            QuadCurve2D q = new QuadCurve2D.Float();
            q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
            g2.draw(q);
            g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
        }
        else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
            CubicCurve2D c = new CubicCurve2D .Float();
            c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
                    linkX, linkY);
            g2.draw(c);
        }
    }
    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT);

}
 
Example #29
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a section label on the right side of the pie chart.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawRightLabel(Graphics2D g2, PiePlotState state,
                              PieLabelRecord record) {

    double anchorX = state.getLinkArea().getMaxX();
    double targetX = anchorX + record.getGap();
    double targetY = record.getAllocatedY();

    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta)
                * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta)
                * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta)
                * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta)
                * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        PieLabelLinkStyle style = getLabelLinkStyle();
        if (style.equals(PieLabelLinkStyle.STANDARD)) {
            g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
        }
        else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
            QuadCurve2D q = new QuadCurve2D.Float();
            q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
            g2.draw(q);
            g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
        }
        else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
            CubicCurve2D c = new CubicCurve2D .Float();
            c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
                    linkX, linkY);
            g2.draw(c);
        }
    }

    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.LEFT);

}
 
Example #30
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the right labels.
 * 
 * @param keys  the keys.
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param linkArea  the link area.
 * @param maxLabelWidth  the maximum label width.
 * @param state  the state.
 */
protected void drawRightLabels(KeyedValues keys, Graphics2D g2, 
                               Rectangle2D plotArea, Rectangle2D linkArea, 
                               float maxLabelWidth, PiePlotState state) {

    // draw the right labels...
    PieLabelDistributor distributor2 
        = new PieLabelDistributor(keys.getItemCount());
    double lGap = plotArea.getWidth() * this.labelGap;
    double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;

    for (int i = 0; i < keys.getItemCount(); i++) {
        String label = this.labelGenerator.generateSectionLabel(
                this.dataset, keys.getKey(i));

        if (label != null) {
            TextBlock block = TextUtilities.createTextBlock(label, 
                    this.labelFont, this.labelPaint, maxLabelWidth, 
                    new G2TextMeasurer(g2));
            TextBox labelBox = new TextBox(block);
            labelBox.setBackgroundPaint(this.labelBackgroundPaint);
            labelBox.setOutlinePaint(this.labelOutlinePaint);
            labelBox.setOutlineStroke(this.labelOutlineStroke);
            labelBox.setShadowPaint(this.labelShadowPaint);
            double theta = Math.toRadians(keys.getValue(i).doubleValue());
            double baseY = state.getPieCenterY() 
                          - Math.sin(theta) * verticalLinkRadius;
            double hh = labelBox.getHeight(g2);
            distributor2.addPieLabelRecord(new PieLabelRecord(
                    keys.getKey(i), theta, baseY, labelBox, hh,
                    lGap / 2.0 + lGap / 2.0 * Math.cos(theta), 
                    0.9 + getExplodePercent(this.dataset.getIndex(
                            keys.getKey(i)))));
        }
    }
    distributor2.distributeLabels(plotArea.getMinY(), plotArea.getHeight());
    for (int i = 0; i < distributor2.getItemCount(); i++) {
        drawRightLabel(g2, state, distributor2.getPieLabelRecord(i));
    }

}