Java Code Examples for java.awt.geom.Arc2D

The following are top voted examples for showing how to use java.awt.geom.Arc2D. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: parabuild-ci   File: PlumNeedle.java   Source Code and License 9 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 
                          Point2D rotate, double angle) {

    Arc2D shape = new Arc2D.Double(Arc2D.PIE);
    double radius = plotArea.getHeight();
    double halfX = plotArea.getWidth() / 2;
    double diameter = 2 * radius;

    shape.setFrame(plotArea.getMinX() + halfX - radius ,
                   plotArea.getMinY() - radius,
                   diameter, diameter);
    radius = Math.toDegrees(Math.asin(halfX / radius));
    shape.setAngleStart(270 - radius);
    shape.setAngleExtent(2 * radius);

    Area s = new Area(shape);

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation houston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s.transform(getTransform());
    }

    defaultDisplay(g2, s);
}
 
Example 2
Project: jmt   File: StatiDrawer.java   Source Code and License 6 votes vote down vote up
public void drawStatus(int status, double probability, Graphics2D g2d, Color sc, Color pc, Color borderC, boolean bold) {
	double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * status + START_GAP;
	double y = panelH / 2.0 - STATUS_RAD;
	double pie = probability * 360;
	Color ctmp = g2d.getColor();
	if (bold) {
		g2d.setStroke(strokeB);
	}
	statusE[status] = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
	statusP[status] = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
	g2d.setPaint(sc);
	g2d.fill(statusE[status]);
	g2d.setPaint(pc);
	g2d.fill(statusP[status]);
	g2d.setPaint(borderC);
	g2d.draw(statusE[status]);
	drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
	drawCenteredText("" + status, borderC, x + STATUS_RAD, panelH / 2.0, g2d, false);
	g2d.setColor(ctmp);
	g2d.setStroke(stroke);
}
 
Example 3
Project: jmt   File: StatiDrawer.java   Source Code and License 6 votes vote down vote up
public void drawLastStatus(String jobStr, double probability, Graphics2D g2d, Color sc, Color pc) {
	double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * (queueLength() - 1) + START_GAP;
	double y = panelH / 2.0 - STATUS_RAD;
	Color ctmp = g2d.getColor();
	lastStatusE = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
	g2d.setPaint(sc);
	g2d.fill(lastStatusE);
	//if (queueMax != 0) {
	double pie = probability * 360;
	lastStatusP = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
	g2d.setPaint(pc);
	g2d.fill(lastStatusP);
	g2d.setPaint(Color.BLACK);
	drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
	//drawCenteredText("" + queueMax, Color.BLACK, x + STATUS_RAD, panelH/2.0, g2d, false);
	drawCenteredText(jobStr, Color.BLACK, x + STATUS_RAD, panelH / 2.0, g2d, false);
	//}
	g2d.setPaint(Color.BLACK);
	g2d.draw(lastStatusE);
	g2d.setColor(ctmp);
}
 
Example 4
Project: QN-ACTR-Release   File: StatiDrawer.java   Source Code and License 6 votes vote down vote up
public void drawStatus(int status, double probability, Graphics2D g2d, Color sc, Color pc, Color borderC, boolean bold) {
	double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * status + START_GAP;
	double y = panelH / 2.0 - STATUS_RAD;
	double pie = probability * 360;
	Color ctmp = g2d.getColor();
	if (bold) {
		g2d.setStroke(strokeB);
	}
	statusE[status] = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
	statusP[status] = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
	g2d.setPaint(sc);
	g2d.fill(statusE[status]);
	g2d.setPaint(pc);
	g2d.fill(statusP[status]);
	g2d.setPaint(borderC);
	g2d.draw(statusE[status]);
	drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
	drawCenteredText("" + status, borderC, x + STATUS_RAD, panelH / 2.0, g2d, false);
	g2d.setColor(ctmp);
	g2d.setStroke(stroke);
}
 
Example 5
Project: QN-ACTR-Release   File: StatiDrawer.java   Source Code and License 6 votes vote down vote up
public void drawLastStatus(String jobStr, double probability, Graphics2D g2d, Color sc, Color pc) {
	double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * (queueLenght() - 1) + START_GAP;
	double y = panelH / 2.0 - STATUS_RAD;
	Color ctmp = g2d.getColor();
	lastStatusE = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
	g2d.setPaint(sc);
	g2d.fill(lastStatusE);
	//if(queueMax != 0){
	double pie = probability * 360;
	lastStatusP = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
	g2d.setPaint(pc);
	g2d.fill(lastStatusP);
	g2d.setPaint(Color.BLACK);
	drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
	//drawCenteredText("" + queueMax, Color.BLACK, x + STATUS_RAD, panelH/2.0, g2d, false);
	drawCenteredText(jobStr, Color.BLACK, x + STATUS_RAD, panelH / 2.0, g2d, false);
	//}
	g2d.setPaint(Color.BLACK);
	g2d.draw(lastStatusE);
	g2d.setColor(ctmp);
}
 
Example 6
Project: ramus   File: ArrowPainter.java   Source Code and License 6 votes vote down vote up
public static void paintTilda(final Graphics2D g, final double x1,
                              final double y1, final double x2, final double y2, final double x3,
                              final double y3, double w, MovingArea movingArea) {
    double x = x1;
    double y = y1;
    if (x3 < x)
        x = x3;
    else if (x2 > x)
        x = x2;
    if (y3 < y)
        y = y3;
    else if (y2 > y)
        y = y2;

    g.fill(new Arc2D.Double(x1 - w / 2, y1 - w / 2, w, w, 0, 360, Arc2D.PIE));
    paintTilda(g, x1, y1, x, y, movingArea);
}
 
Example 7
Project: parabuild-ci   File: PiePlot.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are drawn.
 * @param exploded  the area inside which the exploded pie sections are drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return a rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded, Rectangle2D exploded,
                                   double angle, double extent, double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    else {
        Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2, Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2, Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * explodePercent;
        double deltaY = (point1.getY() - point2.getY()) * explodePercent;
        return new Rectangle2D.Double(unexploded.getX() - deltaX,
            unexploded.getY() - deltaY,
            unexploded.getWidth(),
            unexploded.getHeight());

    }
}
 
Example 8
Project: parabuild-ci   File: PlumNeedle.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    Arc2D shape = new Arc2D.Double(Arc2D.PIE);
    double radius = plotArea.getHeight();
    double halfX = plotArea.getWidth() / 2;
    double diameter = 2 * radius;

    shape.setFrame(plotArea.getMinX() + halfX - radius ,
                   plotArea.getMinY() - radius,
                   diameter, diameter);
    radius = Math.toDegrees(Math.asin(halfX / radius));
    shape.setAngleStart(270 - radius);
    shape.setAngleExtent(2 * radius);

    Area s = new Area(shape);

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation houston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s.transform(getTransform());
    }

    defaultDisplay(g2, s);
}
 
Example 9
Project: parabuild-ci   File: ShipNeedle.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    GeneralPath shape = new GeneralPath();
    shape.append(new Arc2D.Double(-9.0, -7.0, 10,
                                  14, 0.0, 25.5,  Arc2D.OPEN), true);
    shape.append(new Arc2D.Double(0.0, -7.0, 10,
                                  14, 154.5, 25.5,  Arc2D.OPEN), true);
    shape.closePath();
    getTransform().setToTranslation(plotArea.getMinX(), plotArea.getMaxY());
    getTransform().scale(plotArea.getWidth(), plotArea.getHeight() / 3);
    shape.transform(getTransform());

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
}
 
Example 10
Project: parabuild-ci   File: StandardDialFrame.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame (<code>null</code> not permitted).
 *
 * @return The shape of the dial's window.
 */
public Shape getWindow(Rectangle2D frame) {
    
    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, 
            this.innerRadius, this.innerRadius);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, 
            this.outerRadius, this.outerRadius);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle, this.extent, 
            Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle 
            + this.extent, - this.extent, Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;
    
}
 
Example 11
Project: parabuild-ci   File: StandardDialFrame.java   Source Code and License 6 votes vote down vote up
protected Shape getOuterWindow(Rectangle2D frame) {
    double radiusMargin = 0.02;
    double angleMargin = 1.5;
    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, 
            this.innerRadius - radiusMargin, this.innerRadius 
            - radiusMargin);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, 
            this.outerRadius + radiusMargin, this.outerRadius 
            + radiusMargin);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle 
            - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle 
            + angleMargin + this.extent, - this.extent - 2 * angleMargin, 
            Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;
    
}
 
Example 12
Project: parabuild-ci   File: DialPointer.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the pointer.
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, 
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(), 
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 13
Project: parabuild-ci   File: StandardDialRange.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the range.
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {
    
    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, 
            this.innerRadius, this.innerRadius);
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, 
            this.outerRadius, this.outerRadius);
    //double range = this.upperBound - this.lowerBound;
    
    DialScale scale = plot.getScaleForDataset(0);
    double angleMin = scale.valueToAngle(this.lowerBound);
    double angleMax = scale.valueToAngle(this.upperBound);

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, 
            angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, 
            angleMin - angleMax, Arc2D.OPEN);
    
    g2.setPaint(this.paint);
    g2.setStroke(new BasicStroke(2.0f));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}
 
Example 14
Project: parabuild-ci   File: MeterPlot.java   Source Code and License 6 votes vote down vote up
/**
 * Draws an arc.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param minValue  the minimum value.
 * @param maxValue  the maximum value.
 * @param paint  the paint.
 * @param stroke  the stroke.
 */
protected void drawArc(Graphics2D g2, Rectangle2D area, double minValue, 
                       double maxValue, Paint paint, Stroke stroke) {

    double startAngle = valueToAngle(maxValue);
    double endAngle = valueToAngle(minValue);
    double extent = endAngle - startAngle;

    double x = area.getX();
    double y = area.getY();
    double w = area.getWidth();
    double h = area.getHeight();
    g2.setPaint(paint);
    g2.setStroke(stroke);

    if (paint != null && stroke != null) {
        Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, 
                extent, Arc2D.OPEN);
        g2.setPaint(paint); 
        g2.setStroke(stroke);
        g2.draw(arc);
    }

}
 
Example 15
Project: parabuild-ci   File: PiePlot.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are 
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded, 
                                   Rectangle2D exploded,
                                   double angle, double extent, 
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    else {
        Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2, 
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2, 
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * explodePercent;
        double deltaY = (point1.getY() - point2.getY()) * explodePercent;
        return new Rectangle2D.Double(unexploded.getX() - deltaX, 
                unexploded.getY() - deltaY, unexploded.getWidth(), 
                unexploded.getHeight());
    }
}
 
Example 16
Project: parabuild-ci   File: ShipNeedle.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 
                          Point2D rotate, double angle) {

    GeneralPath shape = new GeneralPath();
    shape.append(new Arc2D.Double(-9.0, -7.0, 10, 14, 0.0, 25.5, 
            Arc2D.OPEN), true);
    shape.append(new Arc2D.Double(0.0, -7.0, 10, 14, 154.5, 25.5, 
            Arc2D.OPEN), true);
    shape.closePath();
    getTransform().setToTranslation(plotArea.getMinX(), plotArea.getMaxY());
    getTransform().scale(plotArea.getWidth(), plotArea.getHeight() / 3);
    shape.transform(getTransform());

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
}
 
Example 17
Project: geomapapp   File: CustomDB.java   Source Code and License 6 votes vote down vote up
public void drawCurrentPoint() {
	if( map==null || point==null || !map.isVisible() ) return;
	synchronized (map.getTreeLock() ) {
		Graphics2D g = map.getGraphics2D();
		float zoom = (float)map.getZoom();
		g.setStroke( new BasicStroke( 2f/ zoom ) );
		g.setColor(Color.RED);
		g.setXORMode( Color.white );
		Rectangle2D rect = map.getClipRect2D();
		double wrap = map.getWrap();
		if( wrap>0. ) while( point.x-wrap > rect.getX() ) point.x-=wrap;
		double size = 10./map.getZoom();
		Arc2D.Double arc = new Arc2D.Double( 0., point.y-.5*size, 
						size, size, 0., 360., Arc2D.CHORD);
		if( wrap>0. ) {
			while( point.x < rect.getX()+rect.getWidth() ) {
				arc.x = point.x-.5*size;
				g.draw(arc);
				point.x += wrap;
			}
		} else {
			arc.x = point.x-.5*size;
			g.draw(arc);
		}
	}
}
 
Example 18
Project: geomapapp   File: D18oObservations.java   Source Code and License 6 votes vote down vote up
public void plotXY( Graphics2D g,
			Rectangle2D bounds,
			double xScale, double yScale ) {
	g.setColor( Color.blue );
	float x0 = (float)bounds.getX();
	float y0 = (float)bounds.getY();
	float sy = (float)yScale;
	float sx = (float)xScale;
	Arc2D.Float arc = new Arc2D.Float(0f, 0f, 5f, 5f, 0f, 360f,
			Arc2D.CHORD);
	for(int k=0 ; k<xyd.length ; k++) {
		float x = (xyd[k][4]-x0)*sx;
		float y = (xyd[k][3]-y0)*sy;
		arc.x = x-2.5f;
		arc.y = y-2.5f;
		g.draw(arc);
	}
}
 
Example 19
Project: pumpernickel   File: DetachingArcThrobberUI.java   Source Code and License 6 votes vote down vote up
private void paintArc(Graphics2D g,JComponent jc,float f,float w,float h,float multiplier,float angleOffset,float a) {
	float z = f*f*f*f;
	float r = f * w / 2f;
	float arcX = w/2f - r;
	float arcY = h/2f - r;
	float arcW = 2*r;
	float arcH = 2*r;
	float arcStart = (float)( multiplier*Math.sqrt(f)*360 + angleOffset );
	float arcExtent = (1-f)*(1-f)*360/3;
	
	Arc2D arc = new Arc2D.Float( arcX, arcY, arcW, arcH, arcStart, arcExtent, Arc2D.OPEN);
	g.setStroke(new BasicStroke(4*(1-z)));
	
	Color c = jc==null ? getDefaultForeground() : jc.getForeground();
	int alpha = (int)( 255*(1-f)*a );
	g.setColor(new Color( c.getRed(), c.getGreen(), c.getBlue(), Math.min(alpha, 255) ));
	g.draw(arc);
}
 
Example 20
Project: ccu-historian   File: FXGraphics2D.java   Source Code and License 6 votes vote down vote up
/**
 * Fills the specified shape with the current {@code paint}.  There is
 * direct handling for {@code RoundRectangle2D}, 
 * {@code Rectangle2D}, {@code Ellipse2D} and {@code Arc2D}.  
 * All other shapes are mapped to a path outline and then filled.
 * 
 * @param s  the shape ({@code null} not permitted). 
 * 
 * @see #draw(java.awt.Shape) 
 */
@Override
public void fill(Shape s) {
    if (s instanceof RoundRectangle2D) {
        RoundRectangle2D rr = (RoundRectangle2D) s;
        this.gc.fillRoundRect(rr.getX(), rr.getY(), rr.getWidth(), 
                rr.getHeight(), rr.getArcWidth(), rr.getArcHeight());
    } else if (s instanceof Rectangle2D) {
        Rectangle2D r = (Rectangle2D) s;
        this.gc.fillRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    } else if (s instanceof Ellipse2D) {
        Ellipse2D e = (Ellipse2D) s;
        this.gc.fillOval(e.getX(), e.getY(), e.getWidth(), e.getHeight());
    } else if (s instanceof Arc2D) {
        Arc2D a = (Arc2D) s;
        this.gc.fillArc(a.getX(), a.getY(), a.getWidth(), a.getHeight(), 
                a.getAngleStart(), a.getAngleExtent(), 
                intToArcType(a.getArcType()));
    } else {
        shapeToPath(s);
        this.gc.fill();
    }
}
 
Example 21
Project: ccu-historian   File: MeterPlot.java   Source Code and License 6 votes vote down vote up
/**
 * Draws an arc.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param minValue  the minimum value.
 * @param maxValue  the maximum value.
 * @param paint  the paint.
 * @param stroke  the stroke.
 */
protected void drawArc(Graphics2D g2, Rectangle2D area, double minValue,
                       double maxValue, Paint paint, Stroke stroke) {

    double startAngle = valueToAngle(maxValue);
    double endAngle = valueToAngle(minValue);
    double extent = endAngle - startAngle;

    double x = area.getX();
    double y = area.getY();
    double w = area.getWidth();
    double h = area.getHeight();
    g2.setPaint(paint);
    g2.setStroke(stroke);

    if (paint != null && stroke != null) {
        Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle,
                extent, Arc2D.OPEN);
        g2.setPaint(paint);
        g2.setStroke(stroke);
        g2.draw(arc);
    }

}
 
Example 22
Project: ccu-historian   File: DialTextAnnotation.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius,
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(this.label, g2, (float) pt.getX(),
            (float) pt.getY(), this.anchor);

}
 
Example 23
Project: ccu-historian   File: DialPointer.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 24
Project: ccu-historian   File: ArcDialFrame.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame (<code>null</code> not permitted).
 *
 * @return The shape of the dial's window.
 */
@Override
public Shape getWindow(Rectangle2D frame) {

    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
            this.innerRadius, this.innerRadius);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
            this.outerRadius, this.outerRadius);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle,
            this.extent, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
            + this.extent, -this.extent, Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;

}
 
Example 25
Project: ccu-historian   File: ArcDialFrame.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the outer window.
 *
 * @param frame  the frame.
 *
 * @return The outer window.
 */
protected Shape getOuterWindow(Rectangle2D frame) {
    double radiusMargin = 0.02;
    double angleMargin = 1.5;
    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
            this.innerRadius - radiusMargin, this.innerRadius
            - radiusMargin);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
            this.outerRadius + radiusMargin, this.outerRadius
            + radiusMargin);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle
            - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
            + angleMargin + this.extent, -this.extent - 2 * angleMargin,
            Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;
}
 
Example 26
Project: ccu-historian   File: PiePlot.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded,
                                   Rectangle2D exploded,
                                   double angle, double extent,
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();
    Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point2 = arc2.getEndPoint();
    double deltaX = (point1.getX() - point2.getX()) * explodePercent;
    double deltaY = (point1.getY() - point2.getY()) * explodePercent;
    return new Rectangle2D.Double(unexploded.getX() - deltaX,
            unexploded.getY() - deltaY, unexploded.getWidth(),
            unexploded.getHeight());
}
 
Example 27
Project: ccu-historian   File: ShipNeedle.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
@Override
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                          Point2D rotate, double angle) {

    GeneralPath shape = new GeneralPath();
    shape.append(new Arc2D.Double(-9.0, -7.0, 10, 14, 0.0, 25.5,
            Arc2D.OPEN), true);
    shape.append(new Arc2D.Double(0.0, -7.0, 10, 14, 154.5, 25.5,
            Arc2D.OPEN), true);
    shape.closePath();
    getTransform().setToTranslation(plotArea.getMinX(), plotArea.getMaxY());
    getTransform().scale(plotArea.getWidth(), plotArea.getHeight() / 3);
    shape.transform(getTransform());

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
}
 
Example 28
Project: pumpernickel   File: RadialWipeTransition2D.java   Source Code and License 6 votes vote down vote up
@Override
public Transition2DInstruction[] getInstructions(float progress,
		Dimension size) {
	
	int multiplier2 = -1;
	if(type==COUNTER_CLOCKWISE) 
		multiplier2 = 1;
	//for a good time, don't make multiplier1 = 0
	int multiplier1 = 0; //multiplier2;
	int k = Math.max(size.width,size.height);
	Area area = new Area(new Arc2D.Double(new Rectangle2D.Double(size.width/2-2*k,size.height/2-2*k,k*4,k*4),
			90+multiplier1*progress*360, multiplier2*progress*360,Arc2D.PIE));
	area.intersect(new Area(new Rectangle(0,0,size.width,size.height)));
	
	return new ImageInstruction[] {
			new ImageInstruction(true),
			new ImageInstruction(false, null, area)
	};
}
 
Example 29
Project: jfreechart   File: DialTextAnnotation.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device ({@code null} not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle ({@code null} not permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius,
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtils.drawAlignedString(this.label, g2, (float) pt.getX(),
            (float) pt.getY(), this.anchor);

}
 
Example 30
Project: jfreechart   File: DialPointer.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 31
Project: jfreechart   File: ArcDialFrame.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame ({@code null} not permitted).
 *
 * @return The shape of the dial's window.
 */
@Override
public Shape getWindow(Rectangle2D frame) {

    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
            this.innerRadius, this.innerRadius);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
            this.outerRadius, this.outerRadius);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle,
            this.extent, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
            + this.extent, -this.extent, Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;

}
 
Example 32
Project: jfreechart   File: PiePlot.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded,
                                   Rectangle2D exploded,
                                   double angle, double extent,
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();
    Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point2 = arc2.getEndPoint();
    double deltaX = (point1.getX() - point2.getX()) * explodePercent;
    double deltaY = (point1.getY() - point2.getY()) * explodePercent;
    return new Rectangle2D.Double(unexploded.getX() - deltaX,
            unexploded.getY() - deltaY, unexploded.getWidth(),
            unexploded.getHeight());
}
 
Example 33
Project: jfreechart   File: ShapeUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Compares two arcs and returns {@code true} if they are equal or
 * both {@code null}.
 *
 * @param a1  the first arc ({@code null} permitted).
 * @param a2  the second arc ({@code null} permitted).
 *
 * @return A boolean.
 */
public static boolean equal(Arc2D a1, Arc2D a2) {
    if (a1 == null) {
        return (a2 == null);
    }
    if (a2 == null) {
        return false;
    }
    if (!a1.getFrame().equals(a2.getFrame())) {
        return false;
    }
    if (a1.getAngleStart() != a2.getAngleStart()) {
        return false;
    }
    if (a1.getAngleExtent() != a2.getAngleExtent()) {
        return false;
    }
    if (a1.getArcType() != a2.getArcType()) {
        return false;
    }
    return true;
}
 
Example 34
Project: orbit-image-analysis   File: TestImageGenerator.java   Source Code and License 6 votes vote down vote up
public TestImageGenerator(double[][] matrix, double[] gain, String[] channelNames, int width, int height) {
    this.matrix = matrix;
    this.gain = gain;
    this.channelNames = channelNames;
    this.rand = new Random();
    this.sizeC = channelNames.length;
    this.width = width;
    this.height = height;
    this.concentrations = new List[sizeC];
    this.signals = new double[sizeC][numCells];


    // generate concentrations
    for (int s=0; s<sizeC; s++) {
         concentrations[s] = new ArrayList<>(numCells);
        for (int i=0; i<numCells; i++) {
            int x = rand.nextInt((int)(width-cellRadius));
            int y = rand.nextInt((int)(height-cellRadius));
            Arc2D p = new Arc2D.Double(Arc2D.CHORD);
            p.setArcByCenter(x, y, cellRadius, 0d, 360d, Arc2D.CHORD);
            concentrations[s].add(p);
            double density = (rand.nextGaussian() * 100d) + 100;
            signals[s][i] = density;
        }
    }
}
 
Example 35
Project: orbit-image-analysis   File: SpotImagePanel.java   Source Code and License 6 votes vote down vote up
protected SpotPos detectSpot(double x, double y) {
    Arc2D.Double arc;
    x -= iOffsX;
    y -= iOffsY;
    x /= scale;
    y /= scale;
    Point p;

    if (SpotImagePanel.this.spotPosList != null && SpotImagePanel.this.spotPosList.size() > 0) {
        for (SpotPos sp : SpotImagePanel.this.spotPosList) {
            p = sp.getPos();
            arc = new Arc2D.Double(p.x - SpotImagePanel.this.radius, p.y - SpotImagePanel.this.radius, SpotImagePanel.this.radius * 2, SpotImagePanel.this.radius * 2, 0, 360, Arc2D.CHORD);
            if (arc.contains(new Point((int) x, (int) y))) {
                return sp;
            }

        }
    }
    return null;
}
 
Example 36
Project: PhET   File: Protractor.java   Source Code and License 6 votes vote down vote up
public void update() {
//            System.out.println( "leftLeg.getAngle() = " + leftLeg.getAngle() );
//            System.out.println( "right.getAngle() = " + rightLeg.getAngle() );
            double arcDist = 30;
            Arc2D.Double arc = new Arc2D.Double( -arcDist, -arcDist, arcDist * 2, arcDist * 2, toDegrees( 0 ), toDegrees( 0 ), Arc2D.Double.OPEN );

            Point2D p1 = Vector2D.createPolar( 20, leftLeg.getAngle() ).getDestination( new Point2D.Double() );
            Point2D p2 = Vector2D.createPolar( 20, rightLeg.getAngle() ).getDestination( new Point2D.Double() );
            if ( getDegreesSigned() >= 0 ) {
                arc.setAngles( p1, p2 );
            }
            else {
                arc.setAngles( p2, p1 );
            }
            path.setPathTo( arc );
        }
 
Example 37
Project: PhET   File: CircularGradientPaint.java   Source Code and License 6 votes vote down vote up
public static void main( String[] args ) {
    new JFrame() {{
        setContentPane( new JPanel() {
            @Override
            protected void paintComponent( Graphics g ) {
                super.paintComponent( g );
                Graphics2D g2 = (Graphics2D) g;

                Arc2D.Double ellipse2 = new Arc2D.Double( 0, 0, 200, 200, 0, 90, Arc2D.PIE );
                CircularGradientPaint rgp2 = new CircularGradientPaint( new Point2D.Double( 100, 100 ), Color.red, Color.white );
                g2.setPaint( rgp2 );
                g2.fill( ellipse2 );

                Arc2D.Double ellipse = new Arc2D.Double( 0, 0, 200, 200, 90, 90, Arc2D.PIE );
                CircularGradientPaint rgp = new CircularGradientPaint( new Point2D.Double( 100, 100 ), Color.white, Color.blue );
                g2.setPaint( rgp );
                g2.fill( ellipse );

            }
        } );
        setSize( 800, 700 );
        setVisible( true );
        setDefaultCloseOperation( EXIT_ON_CLOSE );
    }};
}
 
Example 38
Project: PhET   File: PlatformNode2.java   Source Code and License 6 votes vote down vote up
public void updateAngle() {

            final double extent = ( endAngle - startAngle ) * 360 / 2 / Math.PI;
//            final double platformAngle = platform.getPosition() * 360 / Math.PI / 2;
            final double platformAngle = -platform.getPosition() * 360 / Math.PI / 2;
            final double angle1 = startAngle * 360 / 2 / Math.PI + platformAngle;
//            System.out.println( "platform.getPosition() = " + platform.getPosition() + ", angle=" + angle1 );
            Arc2D.Double outerArc = new Arc2D.Double( -outerRadius, -outerRadius, outerRadius * 2, outerRadius * 2, angle1, extent, Arc2D.Double.OPEN );
            Arc2D.Double outerArcRev = new Arc2D.Double( -outerRadius, -outerRadius, outerRadius * 2, outerRadius * 2, angle1 + extent, -extent, Arc2D.Double.OPEN );
            Arc2D.Double innerArc = new Arc2D.Double( -innerRadius, -innerRadius, innerRadius * 2, innerRadius * 2, startAngle * 360 / 2 / Math.PI + extent + platformAngle, -extent, Arc2D.Double.OPEN );
            Arc2D.Double innerArcRev = new Arc2D.Double( -innerRadius, -innerRadius, innerRadius * 2, innerRadius * 2, angle1, extent, Arc2D.Double.OPEN );
            GeneralPath path = toPathSegment( outerArc, innerArc );
            body.setPathTo( path );

            Arc2D.Double outerArcDepth = new Arc2D.Double( -outerRadius + edgeDX, -outerRadius + edgeDY, outerRadius * 2, outerRadius * 2, angle1, extent, Arc2D.Double.OPEN );
            Arc2D.Double innerArcDepth = new Arc2D.Double( -innerRadius + edgeDX, -innerRadius + edgeDY, innerRadius * 2, innerRadius * 2, startAngle * 360 / 2 / Math.PI + extent + platformAngle, -extent, Arc2D.Double.OPEN );

//            Shape p2 = path.createTransformedShape( AffineTransform.getTranslateInstance( edgeDX, edgeDY ) );
//            bottomPanel.setPathTo( toPathSegment( outerArcDepth, innerArcDepth ) );
            northPanel.setPathTo( toPathSegment( outerArcRev, outerArcDepth ) );
            southPanel.setPathTo( toPathSegment( innerArcRev, innerArcDepth ) );
        }
 
Example 39
Project: PhET   File: PSWTPath.java   Source Code and License 6 votes vote down vote up
private void drawShape(final SWTGraphics2D g2) {
    final double lineWidth = g2.getTransformedLineWidth();
    if (shape instanceof Rectangle2D) {
        g2.drawRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3]
                - lineWidth);
    }
    else if (shape instanceof Ellipse2D) {
        g2.drawOval(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3]
                - lineWidth);
    }
    else if (shape instanceof Arc2D) {
        g2.drawArc(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3]
                - lineWidth, shapePts[4], shapePts[5]);
    }
    else if (shape instanceof RoundRectangle2D) {
        g2.drawRoundRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth,
                shapePts[3] - lineWidth, shapePts[4], shapePts[5]);
    }
    else {
        g2.draw(shape);
    }
}
 
Example 40
Project: PhET   File: PSWTPath.java   Source Code and License 6 votes vote down vote up
private void fillShape(final SWTGraphics2D g2) {
    final double lineWidth = g2.getTransformedLineWidth();
    if (shape instanceof Rectangle2D) {
        g2.fillRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3]
                - lineWidth);
    }
    else if (shape instanceof Ellipse2D) {
        g2.fillOval(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3]
                - lineWidth);
    }
    else if (shape instanceof Arc2D) {
        g2.fillArc(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3]
                - lineWidth, shapePts[4], shapePts[5]);
    }
    else if (shape instanceof RoundRectangle2D) {
        g2.fillRoundRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth,
                shapePts[3] - lineWidth, shapePts[4], shapePts[5]);
    }
    else {
        g2.fill(shape);
    }
}
 
Example 41
Project: aya-lang   File: FXGraphics2D.java   Source Code and License 6 votes vote down vote up
/**
 * Fills the specified shape with the current {@code paint}.  There is
 * direct handling for {@code RoundRectangle2D}, 
 * {@code Rectangle2D}, {@code Ellipse2D} and {@code Arc2D}.  
 * All other shapes are mapped to a path outline and then filled.
 * 
 * @param s  the shape ({@code null} not permitted). 
 * 
 * @see #draw(java.awt.Shape) 
 */
@Override
public void fill(Shape s) {
    if (s instanceof RoundRectangle2D) {
        RoundRectangle2D rr = (RoundRectangle2D) s;
        this.gc.fillRoundRect(rr.getX(), rr.getY(), rr.getWidth(), 
                rr.getHeight(), rr.getArcWidth(), rr.getArcHeight());
    } else if (s instanceof Rectangle2D) {
        Rectangle2D r = (Rectangle2D) s;
        this.gc.fillRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    } else if (s instanceof Ellipse2D) {
        Ellipse2D e = (Ellipse2D) s;
        this.gc.fillOval(e.getX(), e.getY(), e.getWidth(), e.getHeight());
    } else if (s instanceof Arc2D) {
        Arc2D a = (Arc2D) s;
        this.gc.fillArc(a.getX(), a.getY(), a.getWidth(), a.getHeight(), 
                a.getAngleStart(), a.getAngleExtent(), 
                intToArcType(a.getArcType()));
    } else {
        shapeToPath(s);
        this.gc.fill();
    }
}
 
Example 42
Project: aya-lang   File: MeterPlot.java   Source Code and License 6 votes vote down vote up
/**
 * Draws an arc.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param minValue  the minimum value.
 * @param maxValue  the maximum value.
 * @param paint  the paint.
 * @param stroke  the stroke.
 */
protected void drawArc(Graphics2D g2, Rectangle2D area, double minValue,
                       double maxValue, Paint paint, Stroke stroke) {

    double startAngle = valueToAngle(maxValue);
    double endAngle = valueToAngle(minValue);
    double extent = endAngle - startAngle;

    double x = area.getX();
    double y = area.getY();
    double w = area.getWidth();
    double h = area.getHeight();
    g2.setPaint(paint);
    g2.setStroke(stroke);

    if (paint != null && stroke != null) {
        Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle,
                extent, Arc2D.OPEN);
        g2.setPaint(paint);
        g2.setStroke(stroke);
        g2.draw(arc);
    }

}
 
Example 43
Project: aya-lang   File: DialTextAnnotation.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius,
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(this.label, g2, (float) pt.getX(),
            (float) pt.getY(), this.anchor);

}
 
Example 44
Project: aya-lang   File: ArcDialFrame.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame (<code>null</code> not permitted).
 *
 * @return The shape of the dial's window.
 */
@Override
public Shape getWindow(Rectangle2D frame) {

    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
            this.innerRadius, this.innerRadius);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
            this.outerRadius, this.outerRadius);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle,
            this.extent, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
            + this.extent, -this.extent, Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;

}
 
Example 45
Project: aya-lang   File: ArcDialFrame.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the outer window.
 *
 * @param frame  the frame.
 *
 * @return The outer window.
 */
protected Shape getOuterWindow(Rectangle2D frame) {
    double radiusMargin = 0.02;
    double angleMargin = 1.5;
    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
            this.innerRadius - radiusMargin, this.innerRadius
            - radiusMargin);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
            this.outerRadius + radiusMargin, this.outerRadius
            + radiusMargin);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle
            - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
            + angleMargin + this.extent, -this.extent - 2 * angleMargin,
            Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;
}
 
Example 46
Project: litiengine   File: Ability.java   Source Code and License 5 votes vote down vote up
protected Shape internalCalculateImpactArea(final float angle) {
  final int impact = this.getAttributes().getImpact().getCurrentValue();
  final int impactAngle = this.getAttributes().getImpactAngle().getCurrentValue();
  final double arcX = this.getOrigin().getX() - impact * 0.5;
  final double arcY = this.getOrigin().getY() - impact * 0.5;

  // project
  final Point2D appliedRange = GeometricUtilities.project(new Point2D.Double(arcX, arcY), angle, this.getAttributes().getRange().getCurrentValue() * 0.5);
  final double start = angle - 90;
  if (impactAngle % 360 == 0) {
    return new Ellipse2D.Double(appliedRange.getX(), appliedRange.getY(), impact, impact);
  }

  return new Arc2D.Double(appliedRange.getX(), appliedRange.getY(), impact, impact, start, impactAngle, Arc2D.PIE);
}
 
Example 47
Project: rapidminer   File: ProcessDrawer.java   Source Code and License 5 votes vote down vote up
/**
 * Draws the given {@link Ports}.
 *
 * @param ports
 * @param g2
 */
private void renderPortsBackground(final Ports<? extends Port> ports, final Graphics2D g2) {
	boolean input = ports instanceof InputPorts;
	g2.setStroke(LINE_STROKE);

	for (Port port : ports.getAllPorts()) {
		Point location = ProcessDrawUtils.createPortLocation(port, model);

		// the first paint can come before any of the operator register listeners fire
		// thus we need to check the location for null; subsequent calls will have a location
		if (location == null) {
			return;
		}

		double x = location.getX();
		double y = location.getY();

		Shape ellipseBoth;
		int startAngle;
		if (input) {
			startAngle = 90;
			ellipseBoth = new Arc2D.Double(new Rectangle2D.Double(x - PORT_SIZE_BACKGROUND / 2, y - PORT_SIZE_BACKGROUND
					/ 2, PORT_SIZE_BACKGROUND, PORT_SIZE_BACKGROUND), startAngle, 180, Arc2D.PIE);
		} else {
			startAngle = 270;
			ellipseBoth = new Arc2D.Double(new Rectangle2D.Double(x - PORT_SIZE_BACKGROUND / 2, y - PORT_SIZE_BACKGROUND
					/ 2, PORT_SIZE_BACKGROUND, PORT_SIZE_BACKGROUND), startAngle, 180, Arc2D.PIE);
		}

		g2.setColor(Color.WHITE);
		g2.fill(ellipseBoth);

	}
}
 
Example 48
Project: vexillo   File: Symbol.java   Source Code and License 5 votes vote down vote up
private static void coArcTo(GeneralPath p, double x2, double y2, double x3, double y3) {
	Point2D p1 = p.getCurrentPoint();
	double x1 = p1.getX();
	double y1 = p1.getY();
	boolean xe = (x1 == x2 && x2 == x3);
	boolean ye = (y1 == y2 && y2 == y3);
	if (xe && ye) return;
	if (xe || ye) { p.lineTo(x3, y3); return; }
	double d = arcHK(x1, y1, x2, y2, x3, y3);
	double h = arcH(x1, y1, x2, y2, x3, y3) / d;
	double k = arcK(x1, y1, x2, y2, x3, y3) / d;
	if (Double.isNaN(h) || Double.isInfinite(h)) { p.lineTo(x3, y3); return; }
	if (Double.isNaN(k) || Double.isInfinite(k)) { p.lineTo(x3, y3); return; }
	double r = Math.hypot(k - y1, x1 - h);
	double a1 = Math.toDegrees(Math.atan2(k - y1, x1 - h));
	double a2 = Math.toDegrees(Math.atan2(k - y2, x2 - h));
	double a3 = Math.toDegrees(Math.atan2(k - y3, x3 - h));
	Arc2D.Double arc = new Arc2D.Double();
	arc.x = h - r;
	arc.y = k - r;
	arc.width = r + r;
	arc.height = r + r;
	arc.start = a1;
	if ((a1 <= a2 && a2 <= a3) || (a3 <= a2 && a2 <= a1)) {
		arc.extent = a3 - a1;
	} else if (a3 <= a1) {
		arc.extent = a3 - a1 + 360;
	} else {
		arc.extent = a3 - a1 - 360;
	}
	p.append(arc, true);
}
 
Example 49
Project: ramus   File: ArrowPainter.java   Source Code and License 5 votes vote down vote up
private void paintD1(final Graphics2D g, final boolean tunelS) {
    if (tunelS) {
        g.draw(new Line2D.Double(0, 0, tunnelWidth, 0));
        g.draw(new Line2D.Double(0, 0, 0, tunnelLength));
        g.draw(new Line2D.Double(0, tunnelLength, tunnelWidth, tunnelLength));
    } else {
        g.draw(new Arc2D.Double(0, 0, tunnelWidth * 3, tunnelLength, 90,
                180, Arc2D.OPEN));
    }
}
 
Example 50
Project: ramus   File: ArrowPainter.java   Source Code and License 5 votes vote down vote up
private void paintD2(final Graphics2D g, final boolean tunelS) {
    if (tunelS) {
        g.draw(new Line2D.Double(0, 0, -tunnelWidth, 0));
        g.draw(new Line2D.Double(0, 0, 0, tunnelLength));
        g.draw(new Line2D.Double(0, tunnelLength, -tunnelWidth,
                tunnelLength));
    } else {
        g.draw(new Arc2D.Double(-tunnelWidth * 3, 0, tunnelWidth * 3,
                tunnelLength, 90, -180, Arc2D.OPEN));

    }
}
 
Example 51
Project: ramus   File: ArrowPainter.java   Source Code and License 5 votes vote down vote up
private void paintA1(final Graphics2D g, final boolean tunelS) {
    if (tunelS) {
        g.draw(new Line2D.Double(0, tunnelWidth, 0, 0));
        g.draw(new Line2D.Double(0, 0, tunnelLength, 0));
        g.draw(new Line2D.Double(tunnelLength, tunnelWidth, tunnelLength, 0));
    } else {
        g.draw(new Arc2D.Double(0, 0, tunnelLength, tunnelWidth * 3, 180,
                -180, Arc2D.OPEN));
    }
}
 
Example 52
Project: ramus   File: ArrowPainter.java   Source Code and License 5 votes vote down vote up
private void paintA2(final Graphics2D g, final boolean tunelS) {
    if (tunelS) {
        g.draw(new Line2D.Double(0, -tunnelWidth, 0, 0));
        g.draw(new Line2D.Double(0, 0, tunnelLength, 0));
        g.draw(new Line2D.Double(tunnelLength, -tunnelWidth, tunnelLength,
                0));
    } else {
        g.draw(new Arc2D.Double(0, -tunnelWidth * 3, tunnelLength,
                tunnelWidth * 3, 180, 180, Arc2D.OPEN));
    }
}
 
Example 53
Project: OpenJSharp   File: LoopPipe.java   Source Code and License 5 votes vote down vote up
public void drawArc(SunGraphics2D sg2d,
                    int x, int y, int width, int height,
                    int startAngle, int arcAngle)
{
    sg2d.shapepipe.draw(sg2d, new Arc2D.Float(x, y, width, height,
                                              startAngle, arcAngle,
                                              Arc2D.OPEN));
}
 
Example 54
Project: OpenJSharp   File: LoopPipe.java   Source Code and License 5 votes vote down vote up
public void fillArc(SunGraphics2D sg2d,
                    int x, int y, int width, int height,
                    int startAngle, int arcAngle)
{
    sg2d.shapepipe.fill(sg2d, new Arc2D.Float(x, y, width, height,
                                              startAngle, arcAngle,
                                              Arc2D.PIE));
}
 
Example 55
Project: OpenJSharp   File: BufferedRenderPipe.java   Source Code and License 5 votes vote down vote up
public void drawArc(SunGraphics2D sg2d,
                    int x, int y, int width, int height,
                    int startAngle, int arcAngle)
{
    draw(sg2d, new Arc2D.Float(x, y, width, height,
                               startAngle, arcAngle,
                               Arc2D.OPEN));
}
 
Example 56
Project: OpenJSharp   File: BufferedRenderPipe.java   Source Code and License 5 votes vote down vote up
public void fillArc(SunGraphics2D sg2d,
                    int x, int y, int width, int height,
                    int startAngle, int arcAngle)
{
    fill(sg2d, new Arc2D.Float(x, y, width, height,
                               startAngle, arcAngle,
                               Arc2D.PIE));
}
 
Example 57
Project: parabuild-ci   File: MinMaxCategoryRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the input stream.
 *
 * @throws IOException  if there is an I/O error.
 * @throws ClassNotFoundException  if there is a classpath problem.
 */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    this.groupStroke = SerialUtilities.readStroke(stream);
    this.groupPaint = SerialUtilities.readPaint(stream);
      
    this.minIcon = getIcon(
        new Arc2D.Double(-4, -4, 8, 8, 0, 360, Arc2D.OPEN), null, Color.black
    );
    this.maxIcon = getIcon(
        new Arc2D.Double(-4, -4, 8, 8, 0, 360, Arc2D.OPEN), null, Color.black
    );
    this.objectIcon = getIcon(new Line2D.Double(-4, 0, 4, 0), false, true);
}
 
Example 58
Project: parabuild-ci   File: DialTextAnnotation.java   Source Code and License 5 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been 
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted). 
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, 
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(this.label, g2, (float) pt.getX(), 
            (float) pt.getY(), this.anchor);
    
}
 
Example 59
Project: parabuild-ci   File: MinMaxCategoryRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the input stream.
 *
 * @throws IOException  if there is an I/O error.
 * @throws ClassNotFoundException  if there is a classpath problem.
 */
private void readObject(ObjectInputStream stream) 
    throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    this.groupStroke = SerialUtilities.readStroke(stream);
    this.groupPaint = SerialUtilities.readPaint(stream);
      
    this.minIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0, 360, 
            Arc2D.OPEN), null, Color.black);
    this.maxIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0, 360, 
            Arc2D.OPEN), null, Color.black);
    this.objectIcon = getIcon(new Line2D.Double(-4, 0, 4, 0), false, true);
}
 
Example 60
Project: parabuild-ci   File: SpiderWebPlot.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the location for a label
 * 
 * @param labelBounds the label bounds.
 * @param ascent the ascent (height of font).
 * @param plotArea the plot area
 * @param startAngle the start angle for the pie series.
 * 
 * @return The location for a label.
 */
protected Point2D calculateLabelLocation(Rectangle2D labelBounds, 
                                         double ascent,
                                         Rectangle2D plotArea, 
                                         double startAngle)
{
    Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();

    double deltaX = -(point1.getX() - plotArea.getCenterX()) 
                    * this.axisLabelGap;
    double deltaY = -(point1.getY() - plotArea.getCenterY()) 
                    * this.axisLabelGap;

    double labelX = point1.getX() - deltaX;
    double labelY = point1.getY() - deltaY;

    if (labelX < plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth();
    }

    if (labelX == plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth() / 2;
    }

    if (labelY > plotArea.getCenterY()) {
        labelY += ascent;
    }

    return new Point2D.Double(labelX, labelY);
}