Java Code Examples for java.awt.geom.Arc2D#setArc()
The following examples show how to use
java.awt.geom.Arc2D#setArc() .
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: StandardDialScale.java From openstock 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 2
Source File: StandardDialScale.java From ccu-historian 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 3
Source File: ScaledDialScale.java From jasperreports with GNU Lesser 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.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); } } } }
Example 4
Source File: StandardDialScale.java From SIMVA-SoS with Apache License 2.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 5
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 6
Source File: StandardDialScale.java From astor 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). */ 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 7
Source File: StandardDialScale.java From astor 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). */ 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); 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 8
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 9
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); } } } }