/** * 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); }
/** * 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); }
public void update() { if (skill == null) { rep.setAngleExtent(0); return; } rep.setAngleExtent( 360 - 360 * ((double) (Clocks.masterClock.currentTime() - skill.startTime()) / skill.coolDown())); if (rep.getAngleExtent() <= 0) rep.setAngleExtent(0); }
public boolean contains(double x, double y) { setArc(); double narrow = Math.abs(angle.extent) * 0.2; if (arc == null) arc = new Arc2D.Double(); arc.setArc( atom3.rx - 0.5 * angle.width, atom3.ry - 0.5 * angle.height, angle.width, angle.height, angle.extent > 0 ? angle.start + narrow : angle.start - narrow, angle.extent > 0 ? angle.extent - narrow - narrow : angle.extent + narrow + narrow, Arc2D.PIE); return arc.contains(x, y); }
private void setIndicators() { if (ellipseIndicator == null) ellipseIndicator = new Ellipse2D.Double(); if (arcIndicator == null) arcIndicator = new Arc2D.Double(); ellipseIndicator.setFrame(angle.x, angle.y, angle.width, angle.height); arcIndicator.setArc( angle.x, angle.y, angle.width, angle.height, angle.start, angle.extent, Arc2D.PIE); }
private void paintGenome(Graphics2D g) { g.setColor(Color.WHITE); g.fillRect(0, 0, viewRect.width, viewRect.height); g.setColor(new Color(0.9f, 0.9f, 1f)); g.fill( new Ellipse2D.Double( context.getCenterX() - getRadiusInt(), context.getCenterY() - getRadiusInt(), getRadiusInt() * 2, getRadiusInt() * 2)); for (int i = 0; i < this.context.getDictionary().getSequences().size(); ++i) { SAMSequenceRecord rec = this.context.getDictionary().getSequence(i); Arc2D outer = context.getArc(rec, 0, rec.getSequenceLength(), getRadiusExt(), Arc2D.PIE); if (outer.getAngleExtent() == 0) continue; Area area = new Area(outer); Ellipse2D.Double ed = new Ellipse2D.Double( context.getCenter().getX() - getRadiusInt(), context.getCenter().getY() - getRadiusInt(), getRadiusInt() * 2, getRadiusInt() * 2); area.subtract(new Area(ed)); g.setColor(i % 2 == 0 ? Color.LIGHT_GRAY : Color.WHITE); g.fill(area); g.setColor(Color.BLACK); g.draw(area); if ((rec.getSequenceLength() / (double) this.context.getDictionary().getReferenceLength()) < 0.01) continue; String title = rec.getSequenceName(); double midangle = context.convertPositionToRadian(rec, rec.getSequenceLength() / 2); AffineTransform old = g.getTransform(); AffineTransform tr = new AffineTransform(old); g.translate(context.getCenterX(), context.getCenterY()); g.rotate(midangle); g.translate(getRadiusExt(), 0); g.drawString(title, 0, 0); g.setTransform(tr); g.setTransform(old); } }
private void addArc( AffineTransform at, ArrayList<PathSegment> segments, double[] coords, Arc2D arc) { PathIterator iterator; iterator = arc.getPathIterator(at); iterator.currentSegment(coords); segments.add(new LinePathSegment(coords)); iterator.next(); iterator.currentSegment(coords); segments.add(new CubicPathSegment(coords)); }
@Override public void paintComponent(Graphics g) { if (slices != null && !slices.isEmpty()) { Arc2D arc2D = null; double start = 0; int size = Math.min(getWidth(), getHeight()) - 10; int x = getWidth() / 2 - size / 2; int y = getHeight() / 2 - size / 2; if (g instanceof Graphics2D) { arc2D = new Arc2D.Double(Arc2D.PIE); arc2D.setFrame(x, y, size, size); ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } for (PieSlice slice : slices) { double arc = (slice.cost / total) * 360.0; if (g instanceof Graphics2D) { arc2D.setAngleStart(start); arc2D.setAngleExtent(arc); Color c = ScenarioColorPalette.getColor(slice.toString()); g.setColor(slice.equals(highlighted) ? c.brighter() : c); ((Graphics2D) g).fill(arc2D); g.setColor(Color.BLACK); ((Graphics2D) g).draw(arc2D); } else { g.setColor(ScenarioColorPalette.getColor(slice.toString())); g.fillArc(x, y, size, size, (int) start, (int) arc); g.setColor(Color.BLACK); g.drawArc(x, y, size, size, (int) start, (int) arc); } start += arc; } g.setColor(ScenarioColorPalette.getColor("Untagged")); g.fillArc(x, y, size, size, (int) start, (int) (360.0 - start)); } }
@Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setPaint(Color.blue); g2.setStroke(this.outlineStroke); Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, getRadius(), getRadius()); Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, getWidthRadius(), getWidthRadius()); double value = plot.getValue(getDatasetIndex()); DialScale scale = plot.getScaleForDataset(getDatasetIndex()); 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(getFillPaint()); g2.fill(gp); g2.setPaint(getOutlinePaint()); 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); }
/** * Compares two arcs and returns <code>true</code> if they are equal or both <code>null</code>. * * @param a1 the first arc (<code>null</code> permitted). * @param a2 the second arc (<code>null</code> permitted). * @return A boolean. */ public static boolean equal(final Arc2D a1, final 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; }
/** @param arc the Arc2D object to be converted */ public Element toSVG(Arc2D arc) { double ext = arc.getAngleExtent(); double width = arc.getWidth(); double height = arc.getHeight(); if (width == 0 || height == 0) { Line2D line = new Line2D.Double(arc.getX(), arc.getY(), arc.getX() + width, arc.getY() + height); if (svgLine == null) { svgLine = new SVGLine(generatorContext); } return svgLine.toSVG(line); } if (ext >= 360 || ext <= -360) { Ellipse2D ellipse = new Ellipse2D.Double(arc.getX(), arc.getY(), width, height); if (svgEllipse == null) { svgEllipse = new SVGEllipse(generatorContext); } return svgEllipse.toSVG(ellipse); } Element svgPath = generatorContext.domFactory.createElementNS(SVG_NAMESPACE_URI, SVG_PATH_TAG); StringBuffer d = new StringBuffer(""); Point2D startPt = arc.getStartPoint(); Point2D endPt = arc.getEndPoint(); int type = arc.getArcType(); d.append(PATH_MOVE); d.append(doubleString(startPt.getX())); d.append(SPACE); d.append(doubleString(startPt.getY())); d.append(SPACE); d.append(PATH_ARC); d.append(doubleString(width / 2)); d.append(SPACE); d.append(doubleString(height / 2)); d.append(SPACE); d.append("0"); // no rotation with J2D arc. d.append(SPACE); if (ext > 0) { // CCW sweep case, ext > 0 if (ext > 180) d.append("1"); // use large arc. else d.append("0"); // use small arc. d.append(SPACE); d.append("0"); // sweep ccw } else { // CW sweep case, ext < 0 if (ext < -180) d.append("1"); // use large arc. else d.append("0"); // use small arc. d.append(SPACE); d.append("1"); // sweep cw } d.append(SPACE); d.append(doubleString(endPt.getX())); d.append(SPACE); d.append(doubleString(endPt.getY())); if (type == Arc2D.CHORD) { d.append(PATH_CLOSE); } else if (type == Arc2D.PIE) { double cx = arc.getX() + width / 2; double cy = arc.getY() + height / 2; d.append(PATH_LINE_TO); d.append(SPACE); d.append(doubleString(cx)); d.append(SPACE); d.append(doubleString(cy)); d.append(SPACE); d.append(PATH_CLOSE); } svgPath.setAttributeNS(null, SVG_D_ATTRIBUTE, d.toString()); return svgPath; }
/** * Returns the bargraph track image with the given with and height. * * @param WIDTH * @param START_ANGLE * @param ANGLE_EXTEND * @param APEX_ANGLE * @param BARGRAPH_OFFSET * @param image * @return buffered image containing the bargraph track image */ protected BufferedImage create_BARGRAPH_TRACK_Image( final int WIDTH, final double START_ANGLE, final double ANGLE_EXTEND, final double APEX_ANGLE, final double BARGRAPH_OFFSET, BufferedImage image) { if (WIDTH <= 0) { return null; } if (image == null) { image = UTIL.createImage(WIDTH, WIDTH, Transparency.TRANSLUCENT); } final Graphics2D G2 = image.createGraphics(); G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // G2.setRenderingHint(RenderingHints.KEY_RENDERING, // RenderingHints.VALUE_RENDER_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); // G2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, // RenderingHints.VALUE_COLOR_RENDER_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, // RenderingHints.VALUE_STROKE_NORMALIZE); final int IMAGE_WIDTH = image.getWidth(); final int IMAGE_HEIGHT = image.getHeight(); // Create led track final java.awt.geom.Arc2D BACK = new java.awt.geom.Arc2D.Double(java.awt.geom.Arc2D.PIE); BACK.setFrame( IMAGE_WIDTH * 0.1074766355, IMAGE_HEIGHT * 0.1074766355, IMAGE_WIDTH * 0.785046729, IMAGE_HEIGHT * 0.785046729); BACK.setAngleStart(START_ANGLE + 2); BACK.setAngleExtent(ANGLE_EXTEND - 5); final Ellipse2D BACK_SUB = new Ellipse2D.Double( IMAGE_WIDTH * 0.1822429907, IMAGE_HEIGHT * 0.1822429907, IMAGE_WIDTH * 0.6355140187, IMAGE_HEIGHT * 0.6355140187); final java.awt.geom.Area LED_TRACK_FRAME = new java.awt.geom.Area(BACK); LED_TRACK_FRAME.subtract(new java.awt.geom.Area(BACK_SUB)); final Point2D LED_TRACK_FRAME_START = new Point2D.Double(0, LED_TRACK_FRAME.getBounds2D().getMinY()); final Point2D LED_TRACK_FRAME_STOP = new Point2D.Double(0, LED_TRACK_FRAME.getBounds2D().getMaxY()); final float[] LED_TRACK_FRAME_FRACTIONS = {0.0f, 0.22f, 0.76f, 1.0f}; final Color[] LED_TRACK_FRAME_COLORS = { new Color(0, 0, 0, 255), new Color(51, 51, 51, 255), new Color(51, 51, 51, 255), new Color(100, 100, 100, 255) }; final LinearGradientPaint LED_TRACK_FRAME_GRADIENT = new LinearGradientPaint( LED_TRACK_FRAME_START, LED_TRACK_FRAME_STOP, LED_TRACK_FRAME_FRACTIONS, LED_TRACK_FRAME_COLORS); G2.setPaint(LED_TRACK_FRAME_GRADIENT); G2.fill(LED_TRACK_FRAME); final java.awt.geom.Arc2D FRONT = new java.awt.geom.Arc2D.Double(java.awt.geom.Arc2D.PIE); FRONT.setFrame( IMAGE_WIDTH * 0.1121495327, IMAGE_HEIGHT * 0.1121495327, IMAGE_WIDTH * 0.7803738318, IMAGE_HEIGHT * 0.7803738318); FRONT.setAngleStart(START_ANGLE); FRONT.setAngleExtent(ANGLE_EXTEND); final Ellipse2D FRONT_SUB = new Ellipse2D.Double( IMAGE_WIDTH * 0.1822429907, IMAGE_HEIGHT * 0.1822429907, IMAGE_WIDTH * 0.6448598131, IMAGE_HEIGHT * 0.6448598131); final java.awt.geom.Area LED_TRACK_MAIN = new java.awt.geom.Area(BACK); LED_TRACK_MAIN.subtract(new java.awt.geom.Area(FRONT_SUB)); final Point2D LED_TRACK_MAIN_START = new Point2D.Double(0, LED_TRACK_MAIN.getBounds2D().getMinY()); final Point2D LED_TRACK_MAIN_STOP = new Point2D.Double(0, LED_TRACK_MAIN.getBounds2D().getMaxY()); final float[] LED_TRACK_MAIN_FRACTIONS = {0.0f, 1.0f}; final Color[] LED_TRACK_MAIN_COLORS = {new Color(17, 17, 17, 255), new Color(51, 51, 51, 255)}; final LinearGradientPaint LED_TRACK_MAIN_GRADIENT = new LinearGradientPaint( LED_TRACK_MAIN_START, LED_TRACK_MAIN_STOP, LED_TRACK_MAIN_FRACTIONS, LED_TRACK_MAIN_COLORS); G2.setPaint(LED_TRACK_MAIN_GRADIENT); G2.fill(LED_TRACK_MAIN); // Draw the inactive leds final Point2D CENTER = new Point2D.Double(WIDTH / 2.0, WIDTH / 2.0); final Rectangle2D LED = new Rectangle2D.Double( WIDTH * 0.1168224299, WIDTH * 0.4859813084, WIDTH * 0.06074766355140187, WIDTH * 0.023364486); final Point2D LED_CENTER = new Point2D.Double(LED.getCenterX(), LED.getCenterY()); final Color[] LED_COLORS = new Color[] {new Color(60, 60, 60, 255), new Color(50, 50, 50, 255)}; final RadialGradientPaint LED_GRADIENT = new RadialGradientPaint( LED_CENTER, (float) (0.030373831775700934 * IMAGE_WIDTH), LED_FRACTIONS, LED_COLORS); G2.setPaint(LED_GRADIENT); final AffineTransform OLD_TRANSFORM = G2.getTransform(); for (double angle = 0; angle <= APEX_ANGLE; angle += 5.0) { G2.rotate(Math.toRadians(angle + BARGRAPH_OFFSET), CENTER.getX(), CENTER.getY()); G2.fill(LED); G2.setTransform(OLD_TRANSFORM); } G2.dispose(); return image; }
/** * 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). */ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.getTickRadius(), this.getTickRadius()); Rectangle2D arcRectMajor = DialPlot.rectangleByRadius( frame, this.getTickRadius() - this.getMajorTickLength(), this.getTickRadius() - this.getMajorTickLength()); Rectangle2D arcRectMinor = arcRect; if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) { arcRectMinor = DialPlot.rectangleByRadius( frame, this.getTickRadius() - this.getMinorTickLength(), this.getTickRadius() - this.getMinorTickLength()); } Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius( frame, this.getTickRadius() - this.getTickLabelOffset(), this.getTickRadius() - this.getTickLabelOffset()); boolean firstLabel = true; Arc2D arc = new Arc2D.Double(); Line2D workingLine = new Line2D.Double(); Stroke arcStroke = new BasicStroke(0.75f); for (double v = this.getLowerBound(); v <= this.getUpperBound(); v += this.getMajorTickIncrement()) { arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); g2.setPaint(this.getMajorTickPaint()); g2.setStroke(arcStroke); g2.draw(arc); Point2D pt0 = arc.getEndPoint(); arc.setArc( arcRectMajor, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); Point2D pt1 = arc.getEndPoint(); g2.setPaint(this.getMajorTickPaint()); g2.setStroke(this.getMajorTickStroke()); workingLine.setLine(pt0, pt1); g2.draw(workingLine); arc.setArc( arcRectForLabels, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); Point2D pt2 = arc.getEndPoint(); if (this.getTickLabelsVisible()) { if (!firstLabel || this.getFirstTickLabelVisible()) { g2.setFont(this.getTickLabelFont()); TextUtilities.drawAlignedString( this.getTickLabelFormatter().format(v), g2, (float) pt2.getX(), (float) pt2.getY(), TextAnchor.CENTER); } } firstLabel = false; // now do the minor tick marks if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) { double minorTickIncrement = this.getMajorTickIncrement() / (this.getMinorTickCount() + 1); for (int i = 0; i < this.getMinorTickCount(); i++) { double vv = v + ((i + 1) * minorTickIncrement); if (vv >= this.getUpperBound()) { break; } double angle = valueToAngle(vv); arc.setArc(arcRect, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN); pt0 = arc.getEndPoint(); arc.setArc(arcRectMinor, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN); Point2D pt3 = arc.getEndPoint(); g2.setStroke(this.getMinorTickStroke()); g2.setPaint(this.getMinorTickPaint()); workingLine.setLine(pt0, pt3); g2.draw(workingLine); } } } }
public Arc2D evaluate(Arc2D v0, Arc2D v1, float fraction) { double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction); double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction); double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction); double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction); double start = v0.getAngleStart() + ((v1.getAngleStart() - v0.getAngleStart()) * fraction); double extent = v0.getAngleExtent() + ((v1.getAngleExtent() - v0.getAngleExtent()) * fraction); Arc2D value = (Arc2D) v0.clone(); value.setArc(x, y, w, h, start, extent, v0.getArcType()); return value; }