Java Code Examples for java.awt.geom.CubicCurve2D#Float

The following examples show how to use java.awt.geom.CubicCurve2D#Float . 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: DiffSplitPaneDivider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void paintMatcher(Graphics2D g, Color fillClr, 
        int leftX, int rightX, int upL, int upR, int doR, int doL) {
    int topY = Math.min(upL, upR), bottomY = Math.max(doL, doR);
    // try rendering only curves in viewable area
    if (!g.hitClip(leftX, topY, rightX - leftX, bottomY - topY)) {
        return;
    }
    CubicCurve2D upper = new CubicCurve2D.Float(leftX, upL,
            (rightX -leftX)*.3f, upL,
            (rightX -leftX)*.7f, upR,
            rightX, upR);
    CubicCurve2D bottom = new CubicCurve2D.Float(rightX, doR,
            (rightX - leftX)*.7f, doR,
            (rightX -leftX)*.3f, doL,
            leftX, doL);
    GeneralPath path = new GeneralPath();
    path.append(upper, false);
    path.append(bottom, true);
    path.closePath();
    g.setColor(fillClr);
    g.fill(path);
    g.setColor(master.getColorLines());
    g.draw(upper);
    g.draw(bottom);
}
 
Example 2
Source File: BaseChartPainter.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
/**
 * Draws a cubic curve with the current settings.<br>
 * <code>xPoints</code> and <code>yPoints</code> must contain at least 4 points!
 * @param xPoints    x coordinates of the points of the curve
 * @param yPoints    y coordinates of the points of the curve
 * @param startIndex start index to draw segments from
 * @param endIndex   end index to draw segments up to
 */
public void drawCubicCurve2D( final int[] xPoints, final int[] yPoints, final int startIndex, final int endIndex ) {
	if ( xPoints.length < 2 )
		return;
	final CubicCurve2D.Float cubicCurve = new CubicCurve2D.Float();
	this.xPoints = xPoints;
	this.yPoints = yPoints;
	Point2D.Float p = new Point2D.Float(), p1 = new Point2D.Float(), p2 = new Point2D.Float(), p3 = new Point2D.Float(), pTemp;
	final float s = 0.25f;
	getCP( startIndex, p ); getCP( startIndex+1, p1 ); getCP( startIndex+2, p2 );
	for ( int j = startIndex; j < endIndex; j++ ) {
		getCP( j+3, p3 );
		if ( yPoints[ j ] < 0 || yPoints[ j+1 ] < 0 )
			g2.setStroke( STROKE_DASHED_DOUBLE );
		cubicCurve.setCurve(
				p1.x, p1.y,
				-s*p.x + p1.x + s*p2.x, -s*p.y + p1.y + s*p2.y,
				s*p1.x + p2.x - s*p3.x, s*p1.y + p2.y - s*p3.y,
				p2.x, p2.y );
		g2.draw( cubicCurve );
		if ( yPoints[ j ] < 0 || yPoints[ j+1 ] < 0 )
			g2.setStroke( STROKE_DOUBLE_WIDTH );
		pTemp = p; p = p1; p1 = p2; p2 = p3; p3 = pTemp;
	}
}
 
Example 3
Source File: ShapeUtilities.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to replace an arbitrary shape by one of the standard Java2D constructs.
 * For example if the given {@code path} is a {@link Path2D} containing only a single
 * line or a quadratic curve, then this method replaces it by a {@link Line2D} or
 * {@link QuadCurve2D} object respectively.
 *
 * @param  path  the shape to replace by a simpler Java2D construct.
 *         This is generally an instance of {@link Path2D}, but not necessarily.
 * @return a simpler Java construct, or {@code path} if no better construct is proposed.
 */
public static Shape toPrimitive(final Shape path) {
    final PathIterator it = path.getPathIterator(null);
    if (!it.isDone()) {
        final double[] buffer = new double[6];
        if (it.currentSegment(buffer) == PathIterator.SEG_MOVETO) {
            it.next();
            if (!it.isDone()) {
                final double x1 = buffer[0];
                final double y1 = buffer[1];
                final int code = it.currentSegment(buffer);
                it.next();
                if (it.isDone()) {
                    if (isFloat(path)) {
                        switch (code) {
                            case PathIterator.SEG_LINETO:  return new       Line2D.Float((float) x1, (float) y1, (float) buffer[0], (float) buffer[1]);
                            case PathIterator.SEG_QUADTO:  return new  QuadCurve2D.Float((float) x1, (float) y1, (float) buffer[0], (float) buffer[1], (float) buffer[2], (float) buffer[3]);
                            case PathIterator.SEG_CUBICTO: return new CubicCurve2D.Float((float) x1, (float) y1, (float) buffer[0], (float) buffer[1], (float) buffer[2], (float) buffer[3], (float) buffer[4], (float) buffer[5]);
                        }
                    } else {
                        switch (code) {
                            case PathIterator.SEG_LINETO:  return new       Line2D.Double(x1,y1, buffer[0], buffer[1]);
                            case PathIterator.SEG_QUADTO:  return new  QuadCurve2D.Double(x1,y1, buffer[0], buffer[1], buffer[2], buffer[3]);
                            case PathIterator.SEG_CUBICTO: return new CubicCurve2D.Double(x1,y1, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
                        }
                    }
                }
            }
        }
    }
    return path;
}
 
Example 4
Source File: PlotInstanceLegendCreator.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Shape shapeFromSvgRelativeBezierPath(String pathString, float scalingFactor) {
	String[] points = pathString.split(" ");
	float x1, y1, x2, y2, cx1, cy1, cx2, cy2;
	x2 = y2 = 0;

	float s = scalingFactor;

	Path2D.Float path = new Path2D.Float();
	for (int i = 0; i < points.length / 3; ++i) {
		String c1String = points[i * 3 + 0];
		String c2String = points[i * 3 + 1];
		String targetString = points[i * 3 + 2];

		String[] c1Split = c1String.split(",");
		String[] c2Split = c2String.split(",");
		String[] targetSplit = targetString.split(",");
		x1 = x2;
		y1 = y2;
		x2 = s * Float.parseFloat(targetSplit[0]) + x1;
		y2 = s * Float.parseFloat(targetSplit[1]) + y1;
		cx1 = s * Float.parseFloat(c1Split[0]) + x1;
		cy1 = s * Float.parseFloat(c1Split[1]) + y1;
		cx2 = s * Float.parseFloat(c2Split[0]) + x1;
		cy2 = s * Float.parseFloat(c2Split[1]) + y1;

		CubicCurve2D.Float curve = new CubicCurve2D.Float(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
		path.append(curve, true);
	}
	return path;
}
 
Example 5
Source File: AWTShape.java    From depan with Apache License 2.0 5 votes vote down vote up
/**
 * Draw the given shape on the given OpenGL object.
 *
 * @param gl
 * @param s
 */
private static void drawShape(GL2 gl, Shape s) {
  PathIterator it = s.getPathIterator(new AffineTransform(), shapeFlatness);
  float[] lastMoveTo = new float[6];
  float[] f = new float[6];
  while (!it.isDone()) {
    int res = it.currentSegment(f);
    switch (res) {
      case PathIterator.SEG_CLOSE:
        GLPanel.V(gl, lastMoveTo[0], lastMoveTo[1]);
        break;
      case PathIterator.SEG_MOVETO:
        GLPanel.V(gl, f[0], f[1]);
        System.arraycopy(f, 0, lastMoveTo, 0, 6);
        break;
      case PathIterator.SEG_LINETO:
        GLPanel.V(gl, f[0], f[1]);
        break;
      case PathIterator.SEG_CUBICTO:
      CubicCurve2D c = new CubicCurve2D.Float(lastMoveTo[0], lastMoveTo[1],
          f[0], f[1], f[2], f[3], f[4], f[5]);
      drawShape(gl, c);
        break;
      default:
        throw new Error("Error while drawing AWT shape. "
            + "Path iterator setment not handled:" + res);
    }
    it.next();
  }
}
 
Example 6
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 7
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 8
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 9
Source File: PiePlot.java    From astor with GNU General Public License v2.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 10
Source File: PiePlot.java    From astor with GNU General Public License v2.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 11
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 12
Source File: PiePlot.java    From astor with GNU General Public License v2.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 13
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.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 14
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.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 15
Source File: PiePlot.java    From SIMVA-SoS with Apache License 2.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 16
Source File: PiePlot.java    From SIMVA-SoS with Apache License 2.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 17
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 18
Source File: PiePlot.java    From ccu-historian 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 19
Source File: PiePlot.java    From ccu-historian 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 20
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);

}