Java Code Examples for java.awt.geom.Arc2D#OPEN

The following examples show how to use java.awt.geom.Arc2D#OPEN . 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: MeterPlot.java    From buffer_bci with GNU General Public License v3.0 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 2
Source File: Chart_15_PiePlot_s.java    From coming with MIT 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 3
Source File: DialPointer.java    From openstock with GNU General Public License v3.0 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 4
Source File: ArcDialFrame.java    From openstock with GNU General Public License v3.0 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 5
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 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 6
Source File: DialTextAnnotation.java    From ECG-Viewer with GNU General Public License v2.0 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 7
Source File: FXGraphics2D.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
private ArcType intToArcType(int t) {
    if (t == Arc2D.CHORD) {
        return ArcType.CHORD;
    } else if (t == Arc2D.OPEN) {
        return ArcType.OPEN;
    } else if (t == Arc2D.PIE) {
        return ArcType.ROUND;
    }
    throw new IllegalArgumentException("Unrecognised t: " + t);
}
 
Example 8
Source File: Symbol.java    From energy2d with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {
	super.paintIcon(c, g, x, y);
	Graphics2D g2 = (Graphics2D) g;
	Rectangle2D.Float s = new Rectangle2D.Float(xSymbol + wSymbol * 0.4f, ySymbol + hSymbol * 0.3f, wSymbol * 0.4f, hSymbol * 0.4f);
	Arc2D.Float a = new Arc2D.Float(s, -90, 180, Arc2D.OPEN);
	g2.draw(a);
	int x0 = Math.round(xSymbol + wSymbol * 0.3f);
	int y0 = Math.round(ySymbol + hSymbol * 0.28f);
	g2.drawLine(Math.round(xSymbol + wSymbol * 0.55f), y0, x0, y0);
	g2.drawLine(x0, y0, x0 + 2, y0 - 2);
	g2.drawLine(x0, y0, x0 + 2, y0 + 2);
	y0 += Math.round(hSymbol * 0.4f);
	g2.drawLine(Math.round(xSymbol + wSymbol * 0.55f), y0, x0, y0);
}
 
Example 9
Source File: Symbol.java    From energy2d with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {
	super.paintIcon(c, g, x, y);
	Graphics2D g2 = (Graphics2D) g;
	float thickness = ((BasicStroke) stroke).getLineWidth();
	Rectangle2D.Float s = new Rectangle2D.Float(xSymbol + wSymbol * 0.2f, ySymbol + hSymbol * 0.2f, wSymbol * 0.6f, hSymbol * 0.6f);
	Arc2D.Float a = new Arc2D.Float(s, 80 - thickness * 10, thickness * 20 - 340, Arc2D.OPEN);
	g2.draw(a);
	g2.drawLine((int) (xSymbol + wSymbol * 0.5f), (int) (ySymbol + hSymbol * 0.1f), (int) (xSymbol + wSymbol * 0.5f), (int) (ySymbol + hSymbol * 0.4f));
}
 
Example 10
Source File: RegenMeterOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderRegen(Graphics2D g, WidgetInfo widgetInfo, double percent, Color color)
{
	Widget widget = client.getWidget(widgetInfo);
	if (widget == null || widget.isHidden())
	{
		return;
	}
	Rectangle bounds = widget.getBounds();

	Arc2D.Double arc = new Arc2D.Double(bounds.x + OFFSET, bounds.y + (bounds.height / 2 - DIAMETER / 2), DIAMETER, DIAMETER, 90.d, -360.d * percent, Arc2D.OPEN);
	final Stroke STROKE = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
	g.setStroke(STROKE);
	g.setColor(color);
	g.draw(arc);
}
 
Example 11
Source File: StandardDialRange.java    From astor with GNU General Public License v2.0 5 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);
    
    DialScale scale = plot.getScale(this.scaleIndex);
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " 
                + this.scaleIndex);
    }
    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 12
Source File: FXGraphics2D.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
private ArcType intToArcType(int t) {
    if (t == Arc2D.CHORD) {
        return ArcType.CHORD;
    } else if (t == Arc2D.OPEN) {
        return ArcType.OPEN;
    } else if (t == Arc2D.PIE) {
        return ArcType.ROUND;
    }
    throw new IllegalArgumentException("Unrecognised t: " + t);
}
 
Example 13
Source File: ScaledDialValueIndicator.java    From jasperreports with GNU Lesser General Public License v3.0 4 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, getRadius(),
			this.getRadius());
	Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN);
	Point2D pt = arc.getStartPoint();

	// calculate the bounds of the template value
	FontMetrics fm = g2.getFontMetrics(this.getFont());
	String s = this.getNumberFormat().format(this.getTemplateValue());
	Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);

	// align this rectangle to the frameAnchor
	Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(
			tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(),
			this.getFrameAnchor());

	// add the insets
	Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds);

	// draw the background
	g2.setPaint(this.getBackgroundPaint());
	g2.fill(fb);

	// draw the border
	g2.setStroke(this.getOutlineStroke());
	g2.setPaint(this.getOutlinePaint());
	g2.draw(fb);


	// now find the text anchor point
	String valueStr = this.getNumberFormat().format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale));
	Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor());
	g2.setPaint(this.getPaint());
	g2.setFont(this.getFont());
	TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(),
			(float) pt2.getY(), this.getTextAnchor());

}
 
Example 14
Source File: SVGPathSegArc.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a Java Arc2D corresponding to the position and the angles of the arc segment (computations based on the SVG
 * specification instructions concerning the build of an arc, p. 643-649).
 * @param x0 The X-coordinate of the initial position.
 * @param y0 The Y-coordinate of the initial position.
 * @return An Java Arc2D with double values.
 */
public Arc2D getArc2D(final double x0, final double y0) {
	double a = getAngle();
	double rx2 = getRX();
	double ry2 = getRY();
	final double x2 = getX();
	final double y2 = getY();
	final boolean laf = isLargeArcFlag();
	final boolean sf = isSweepFlag();

	final double dx2 = (x0 - x2) / 2.;
	final double dy2 = (y0 - y2) / 2.;
	a = Math.toRadians(a % 360.);

	// Step 1: Compute (x1', y1')
	final double x1 = Math.cos(a) * dx2 + Math.sin(a) * dy2;
	final double y1 = -Math.sin(a) * dx2 + Math.cos(a) * dy2;

	// Ensure radii are large enough
	rx2 = Math.abs(rx2);
	ry2 = Math.abs(ry2);
	double prx = rx2 * rx2;
	double pry = ry2 * ry2;
	final double px1 = x1 * x1;
	final double py1 = y1 * y1;
	final double radiiCheck = px1 / prx + py1 / pry;

	if(radiiCheck > 1) {
		rx2 = Math.sqrt(radiiCheck) * rx2;
		ry2 = Math.sqrt(radiiCheck) * ry2;
		prx = rx2 * rx2;
		pry = ry2 * ry2;
	}

	// Step 2: Compute (cx1, cy1)
	double sign = laf == sf ? -1 : 1;
	double sq = (prx * pry - prx * py1 - pry * px1) / (prx * py1 + pry * px1);
	sq = sq < 0 ? 0 : sq;
	final double coef = sign * Math.sqrt(sq);
	final double cx1 = coef * (rx2 * y1 / ry2);
	final double cy1 = coef * -(ry2 * x1 / rx2);

	// Step 3: Compute (cx, cy) from (cx1, cy1)
	final double sx2 = (x0 + x2) / 2.;
	final double sy2 = (y0 + y2) / 2.;
	final double cx = sx2 + (Math.cos(a) * cx1 - Math.sin(a) * cy1);
	final double cy = sy2 + (Math.sin(a) * cx1 + Math.cos(a) * cy1);

	// Step 4: Compute the angleStart (angle1) and the angleExtent (dangle)
	final double ux = (x1 - cx1) / rx2;
	final double uy = (y1 - cy1) / ry2;
	final double vx = (-x1 - cx1) / rx2;
	final double vy = (-y1 - cy1) / ry2;
	double p = ux;
	double n = Math.hypot(ux, uy);

	sign = uy < 0 ? -1. : 1.;
	final double angleStart = Math.toDegrees(sign * Math.acos(p / n));

	// Compute the angle extent
	n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
	p = ux * vx + uy * vy;
	sign = ux * vy - uy * vx < 0 ? -1. : 1.;

	double angleExtent = Math.toDegrees(sign * Math.acos(p / n));

	if(!sf && angleExtent > 0) {
		angleExtent -= 360.;
	}else {
		if(sf && angleExtent < 0) {
			angleExtent += 360.;
		}
	}

	return new Arc2D.Double(cx - rx2, cy - ry2, rx2 * 2., ry2 * 2., -angleStart % 360., -angleExtent % 360., Arc2D.OPEN);
}
 
Example 15
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        if (this.direction == Rotation.CLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 - value / state.getTotal() * 360.0;
        } else if (this.direction == Rotation.ANTICLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 + value / state.getTotal() * 360.0;
        } else {
            throw new IllegalStateException("Rotation type not recognised.");
        }
        double angle = (angle2 - angle1);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example 16
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
            if (myLabelGenerator == null) {
                continue;
            }
            String label = myLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(label, g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example 17
Source File: DialPointer.java    From astor with GNU General Public License v2.0 4 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(Color.blue);
    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, 
            this.radius, this.radius);
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, 
            this.widthRadius, this.widthRadius);
    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, 
            Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, 
            Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.outlinePaint);
    Line2D line = new Line2D.Double(frame.getCenterX(), 
            frame.getCenterY(), pt1.getX(), pt1.getY());
    g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}
 
Example 18
Source File: SerializationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Arc() {
    super(Arc2D.OPEN);
}
 
Example 19
Source File: PdfGraphics2D.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see Graphics#drawArc(int, int, int, int, int, int)
 */
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
    Arc2D arc = new Arc2D.Double(x,y,width,height,startAngle, arcAngle, Arc2D.OPEN);
    draw(arc);

}
 
Example 20
Source File: FXGraphics2D.java    From ECG-Viewer with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the attributes of the reusable {@link Arc2D} object that is used by
 * {@link #drawArc(int, int, int, int, int, int)} and 
 * {@link #fillArc(int, int, int, int, int, int)} methods.
 * 
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param width  the width.
 * @param height  the height.
 * @param startAngle  the start angle in degrees, 0 = 3 o'clock.
 * @param arcAngle  the angle (anticlockwise) in degrees.
 */
private void setArc(int x, int y, int width, int height, int startAngle, 
        int arcAngle) {
    if (this.arc == null) {
        this.arc = new Arc2D.Double(x, y, width, height, startAngle, 
                arcAngle, Arc2D.OPEN);
    } else {
        this.arc.setArc(x, y, width, height, startAngle, arcAngle, 
                Arc2D.OPEN);
    }        
}