Java Code Examples for java.awt.geom.Arc2D#Double
The following examples show how to use
java.awt.geom.Arc2D#Double .
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: DialPointer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 2
Source File: ProjectileManager.java From epic-inventor with GNU General Public License v2.0 | 6 votes |
public void weaponSwing(Arc2D.Double arc, Point p) { boolean projectileHit = false; Projectile projectile = null; try { for (String key : projectiles.keySet()) { projectile = (Projectile) projectiles.get(key); if (projectile != null) { if (arc.intersects(projectile.getRect())) { projectile.setIsDirty(true); projectileHit = true; } } } } catch (ConcurrentModificationException concEx) { //another thread was trying to modify projectiles while iterating //we'll continue and the new item can be grabbed on the next update } if (projectileHit) { SoundClip cl = new SoundClip(registry, "Player/HitProjectile", p); } }
Example 3
Source File: CompositionGuide.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
private static void drawSpiral1(Rectangle2D rect, Shape[] arc2D, double arcWidth, double arcHeight) { double angle; Point2D.Double center; angle = 180; center = new Point2D.Double(rect.getX() + arcWidth, rect.getY()); for (int i = 0; i < NUM_SPIRAL_SEGMENTS; i++) { arc2D[i] = new Arc2D.Double( center.getX() - arcWidth, center.getY() - arcHeight, arcWidth * 2, arcHeight * 2, angle, 90, Arc2D.OPEN); angle += 90; arcWidth = arcWidth / GOLDEN_RATIO; arcHeight = arcHeight / GOLDEN_RATIO; center.setLocation( center.getX() - Math.sin(Math.toRadians(-90 + angle)) * arcWidth / GOLDEN_RATIO, center.getY() + Math.sin(Math.toRadians(-180 + angle)) * arcHeight / GOLDEN_RATIO ); } }
Example 4
Source File: PlumNeedle.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 5
Source File: ArcDialFrame.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 6
Source File: CompositionGuide.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
private static void drawSpiral3(Rectangle2D rect, Shape[] arc2D, double arcWidth, double arcHeight) { double angle; Point2D.Double center; angle = 0; center = new Point2D.Double(rect.getX() + (rect.getWidth() - arcWidth), rect.getY()); for (int i = 0; i < NUM_SPIRAL_SEGMENTS; i++) { arc2D[i] = new Arc2D.Double( center.getX() - arcWidth, center.getY() - arcHeight, arcWidth * 2, arcHeight * 2, angle, -90, Arc2D.OPEN); angle -= 90; arcWidth = arcWidth / GOLDEN_RATIO; arcHeight = arcHeight / GOLDEN_RATIO; center.setLocation( center.getX() + Math.sin(Math.toRadians(90 - angle)) * arcWidth / GOLDEN_RATIO, center.getY() + Math.sin(Math.toRadians(0 - angle)) * arcHeight / GOLDEN_RATIO ); } }
Example 7
Source File: Chart_15_PiePlot_s.java From coming with MIT License | 6 votes |
/** * 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
Source File: DialTextAnnotation.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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 9
Source File: StandardDialRange.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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 10
Source File: StandardDialScale.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Draws the scale on the dial plot. * * @param g2 the graphics target (<code>null</code> not permitted). * @param plot the dial plot (<code>null</code> not permitted). * @param frame the reference frame that is used to construct the * geometry of the plot (<code>null</code> not permitted). * @param view the visible part of the plot (<code>null</code> not * permitted). */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.tickRadius, this.tickRadius); Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame, this.tickRadius - this.majorTickLength, this.tickRadius - this.majorTickLength); Rectangle2D arcRectMinor = arcRect; if (this.minorTickCount > 0 && this.minorTickLength > 0.0) { arcRectMinor = DialPlot.rectangleByRadius(frame, this.tickRadius - this.minorTickLength, this.tickRadius - this.minorTickLength); } Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame, this.tickRadius - this.tickLabelOffset, this.tickRadius - this.tickLabelOffset); boolean firstLabel = true; Arc2D arc = new Arc2D.Double(); Line2D workingLine = new Line2D.Double(); for (double v = this.lowerBound; v <= this.upperBound; v += this.majorTickIncrement) { arc.setArc(arcRect, this.startAngle, valueToAngle(v) - this.startAngle, Arc2D.OPEN); Point2D pt0 = arc.getEndPoint(); arc.setArc(arcRectMajor, this.startAngle, valueToAngle(v) - this.startAngle, Arc2D.OPEN); Point2D pt1 = arc.getEndPoint(); g2.setPaint(this.majorTickPaint); g2.setStroke(this.majorTickStroke); workingLine.setLine(pt0, pt1); g2.draw(workingLine); arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v) - this.startAngle, Arc2D.OPEN); Point2D pt2 = arc.getEndPoint(); if (this.tickLabelsVisible) { if (!firstLabel || this.firstTickLabelVisible) { g2.setFont(this.tickLabelFont); g2.setPaint(this.tickLabelPaint); TextUtilities.drawAlignedString( this.tickLabelFormatter.format(v), g2, (float) pt2.getX(), (float) pt2.getY(), TextAnchor.CENTER); } } firstLabel = false; // now do the minor tick marks if (this.minorTickCount > 0 && this.minorTickLength > 0.0) { double minorTickIncrement = this.majorTickIncrement / (this.minorTickCount + 1); for (int i = 0; i < this.minorTickCount; i++) { double vv = v + ((i + 1) * minorTickIncrement); if (vv >= this.upperBound) { break; } double angle = valueToAngle(vv); arc.setArc(arcRect, this.startAngle, angle - this.startAngle, Arc2D.OPEN); pt0 = arc.getEndPoint(); arc.setArc(arcRectMinor, this.startAngle, angle - this.startAngle, Arc2D.OPEN); Point2D pt3 = arc.getEndPoint(); g2.setStroke(this.minorTickStroke); g2.setPaint(this.minorTickPaint); workingLine.setLine(pt0, pt3); g2.draw(workingLine); } } } }
Example 11
Source File: SVGPathSegArc.java From latexdraw with GNU General Public License v3.0 | 4 votes |
/** * 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 12
Source File: PiePlot.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * 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 13
Source File: DialValueIndicator.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * 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(); // the indicator bounds is calculated from the templateValue (which // determines the minimum size), the maxTemplateValue (which, if // specified, provides a maximum size) and the actual value FontMetrics fm = g2.getFontMetrics(this.font); double value = plot.getValue(this.datasetIndex); String valueStr = this.formatter.format(value); Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm); // calculate the bounds of the template value String s = this.formatter.format(this.templateValue); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); double minW = tb.getWidth(); double minH = tb.getHeight(); double maxW = Double.MAX_VALUE; double maxH = Double.MAX_VALUE; if (this.maxTemplateValue != null) { s = this.formatter.format(this.maxTemplateValue); tb = TextUtilities.getTextBounds(s, g2, fm); maxW = Math.max(tb.getWidth(), minW); maxH = Math.max(tb.getHeight(), minH); } double w = fixToRange(valueBounds.getWidth(), minW, maxW); double h = fixToRange(valueBounds.getHeight(), minH, maxH); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); // draw the background g2.setPaint(this.backgroundPaint); g2.fill(fb); // draw the border g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(fb); // now find the text anchor point Shape savedClip = g2.getClip(); g2.clip(fb); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); g2.setClip(savedClip); }
Example 14
Source File: DialPointer.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * 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(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 15
Source File: PiePlot.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Draws a single data item. * * @param g2 the graphics device (<code>null</code> not permitted). * @param section the section index. * @param dataArea the data plot area. * @param state state information for one chart. * @param currentPass the current pass index. */ protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) { Number n = this.dataset.getValue(section); if (n == null) { return; } double value = n.doubleValue(); double angle1 = 0.0; double angle2 = 0.0; 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); if (Math.abs(angle) > getMinimumArcAngleToDraw()) { double ep = 0.0; double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = getExplodePercent(section) / mep; } Rectangle2D arcBounds = getArcBounds(state.getPieArea(), state.getExplodedPieArea(), angle1, angle, ep); Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.PIE); if (currentPass == 0) { if (this.shadowPaint != null && this.shadowGenerator == null) { Shape shadowArc = ShapeUtilities.createTranslatedShape( arc, (float) this.shadowXOffset, (float) this.shadowYOffset); g2.setPaint(this.shadowPaint); g2.fill(shadowArc); } } else if (currentPass == 1) { Comparable key = getSectionKey(section); Paint paint = lookupSectionPaint(key, state); g2.setPaint(paint); g2.fill(arc); Paint outlinePaint = lookupSectionOutlinePaint(key); Stroke outlineStroke = lookupSectionOutlineStroke(key); if (this.sectionOutlinesVisible) { g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(arc); } // update the linking line target for later // add an entity for the pie section if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip( this.dataset, key); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, key, this.pieIndex); } PieSectionEntity entity = new PieSectionEntity( arc, this.dataset, this.pieIndex, section, key, tip, url); entities.add(entity); } } } } state.setLatestAngle(angle2); }
Example 16
Source File: Chart_15_PiePlot_s.java From coming with MIT License | 4 votes |
/** * Draws a single data item. * * @param g2 the graphics device (<code>null</code> not permitted). * @param section the section index. * @param dataArea the data plot area. * @param state state information for one chart. * @param currentPass the current pass index. */ protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) { Number n = this.dataset.getValue(section); if (n == null) { return; } double value = n.doubleValue(); double angle1 = 0.0; double angle2 = 0.0; 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); if (Math.abs(angle) > getMinimumArcAngleToDraw()) { double ep = 0.0; double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = getExplodePercent(getSectionKey(section)) / mep; } Rectangle2D arcBounds = getArcBounds(state.getPieArea(), state.getExplodedPieArea(), angle1, angle, ep); Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.PIE); if (currentPass == 0) { if (this.shadowPaint != null) { Shape shadowArc = ShapeUtilities.createTranslatedShape( arc, (float) this.shadowXOffset, (float) this.shadowYOffset); g2.setPaint(this.shadowPaint); g2.fill(shadowArc); } } else if (currentPass == 1) { Comparable key = getSectionKey(section); Paint paint = lookupSectionPaint(key, true); g2.setPaint(paint); g2.fill(arc); Paint outlinePaint = lookupSectionOutlinePaint(key); Stroke outlineStroke = lookupSectionOutlineStroke(key); if (this.sectionOutlinesVisible) { g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(arc); } // update the linking line target for later // add an entity for the pie section if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip( this.dataset, key); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, key, this.pieIndex); } PieSectionEntity entity = new PieSectionEntity( arc, this.dataset, this.pieIndex, section, key, tip, url); entities.add(entity); } } } } state.setLatestAngle(angle2); }
Example 17
Source File: BorderRenderer.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public BorderRenderer() { reusableArc = new Arc2D.Double(); }
Example 18
Source File: MeterPlot.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Fills an arc on the dial between the given values. * * @param g2 the graphics device. * @param area the plot area. * @param minValue the minimum data value. * @param maxValue the maximum data value. * @param paint the background paint (<code>null</code> not permitted). * @param dial a flag that indicates whether the arc represents the whole * dial. */ protected void fillArc(Graphics2D g2, Rectangle2D area, double minValue, double maxValue, Paint paint, boolean dial) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument"); } 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(); int joinType = Arc2D.OPEN; if (this.shape == DialShape.PIE) { joinType = Arc2D.PIE; } else if (this.shape == DialShape.CHORD) { if (dial && this.meterAngle > 180) { joinType = Arc2D.CHORD; } else { joinType = Arc2D.PIE; } } else if (this.shape == DialShape.CIRCLE) { joinType = Arc2D.PIE; if (dial) { extent = 360; } } else { throw new IllegalStateException("DialShape not recognised."); } g2.setPaint(paint); Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent, joinType); g2.fill(arc); }
Example 19
Source File: StandardDialScale.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws the scale on the dial plot. * * @param g2 the graphics target (<code>null</code> not permitted). * @param plot the dial plot (<code>null</code> not permitted). * @param frame the reference frame that is used to construct the * geometry of the plot (<code>null</code> not permitted). * @param view the visible part of the plot (<code>null</code> not * permitted). */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.tickRadius, this.tickRadius); Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame, this.tickRadius - this.majorTickLength, this.tickRadius - this.majorTickLength); Rectangle2D arcRectMinor = arcRect; if (this.minorTickCount > 0 && this.minorTickLength > 0.0) { arcRectMinor = DialPlot.rectangleByRadius(frame, this.tickRadius - this.minorTickLength, this.tickRadius - this.minorTickLength); } Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame, this.tickRadius - this.tickLabelOffset, this.tickRadius - this.tickLabelOffset); boolean firstLabel = true; Arc2D arc = new Arc2D.Double(); Line2D workingLine = new Line2D.Double(); for (double v = this.lowerBound; v <= this.upperBound; v += this.majorTickIncrement) { arc.setArc(arcRect, this.startAngle, valueToAngle(v) - this.startAngle, Arc2D.OPEN); Point2D pt0 = arc.getEndPoint(); arc.setArc(arcRectMajor, this.startAngle, valueToAngle(v) - this.startAngle, Arc2D.OPEN); Point2D pt1 = arc.getEndPoint(); g2.setPaint(this.majorTickPaint); g2.setStroke(this.majorTickStroke); workingLine.setLine(pt0, pt1); g2.draw(workingLine); arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v) - this.startAngle, Arc2D.OPEN); Point2D pt2 = arc.getEndPoint(); if (this.tickLabelsVisible) { if (!firstLabel || this.firstTickLabelVisible) { g2.setFont(this.tickLabelFont); g2.setPaint(this.tickLabelPaint); TextUtilities.drawAlignedString( this.tickLabelFormatter.format(v), g2, (float) pt2.getX(), (float) pt2.getY(), TextAnchor.CENTER); } } firstLabel = false; // now do the minor tick marks if (this.minorTickCount > 0 && this.minorTickLength > 0.0) { double minorTickIncrement = this.majorTickIncrement / (this.minorTickCount + 1); for (int i = 0; i < this.minorTickCount; i++) { double vv = v + ((i + 1) * minorTickIncrement); if (vv >= this.upperBound) { break; } double angle = valueToAngle(vv); arc.setArc(arcRect, this.startAngle, angle - this.startAngle, Arc2D.OPEN); pt0 = arc.getEndPoint(); arc.setArc(arcRectMinor, this.startAngle, angle - this.startAngle, Arc2D.OPEN); Point2D pt3 = arc.getEndPoint(); g2.setStroke(this.minorTickStroke); g2.setPaint(this.minorTickPaint); workingLine.setLine(pt0, pt3); g2.draw(workingLine); } } } }
Example 20
Source File: FXGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 3 votes |
/** * 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); } }