下面列出了怎么用java.awt.geom.Line2D的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Utility method for drawing a line perpendicular to the range axis (used
* for crosshairs).
*
* @param g2 the graphics device.
* @param dataArea the area defined by the axes.
* @param value the data value.
* @param stroke the line stroke (<code>null</code> not permitted).
* @param paint the line paint (<code>null</code> not permitted).
*/
protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea,
double value, Stroke stroke, Paint paint) {
double java2D = getRangeAxis().valueToJava2D(value, dataArea,
getRangeAxisEdge());
Line2D line = null;
if (this.orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(java2D, dataArea.getMinY(), java2D,
dataArea.getMaxY());
}
else if (this.orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(dataArea.getMinX(), java2D,
dataArea.getMaxX(), java2D);
}
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
public static Shape getArrowShape(Line2D line, Point2D intersectionPoint) {
final double deltaY = line.getP2().getY() - line.getP1().getY();
final double length = Math.sqrt(Math.pow(deltaY, 2) + Math.pow(line.getP2().getX() - line.getP1().getX(), 2));
double theta = Math.asin(deltaY / length);
if (line.getP1().getX() > line.getP2().getX()) {
theta = Math.PI - theta;
}
AffineTransform rotate = AffineTransform.getRotateInstance(theta, myArrowSize, myArrowSize / 2);
Shape polygon = rotate.createTransformedShape(myArrowPolygon);
AffineTransform move = AffineTransform.getTranslateInstance(intersectionPoint.getX() - myArrowSize, intersectionPoint.getY() - myArrowSize /2);
polygon = move.createTransformedShape(polygon);
return polygon;
}
@Override
protected void paintBottomDivider(Graphics g, int x, int y, int width, int height) {
Color borderColor = SubstanceCoreUtilities.getSkin(this.colorSelectorPanel).getOverlayColor(
SubstanceSlices.ColorOverlayType.LINE,
DecorationPainterUtils.getDecorationType(this.colorSelectorPanel), ComponentState.ENABLED);
if (borderColor == null) {
SubstanceColorScheme bgBorderScheme = SubstanceColorSchemeUtilities.getColorScheme(
this.colorSelectorPanel, ColorSchemeAssociationKind.HIGHLIGHT_BORDER,
ComponentState.ENABLED);
borderColor = bgBorderScheme.getLineColor();
}
float lineThickness = SubstanceSizeUtils.getBorderStrokeWidth();
Graphics2D g2d = (Graphics2D) g.create();
g2d.setStroke(new BasicStroke(lineThickness));
g2d.setColor(borderColor);
float lineY = y + height - lineThickness;
g2d.draw(new Line2D.Float(x, lineY, x + width, lineY));
g2d.dispose();
}
/**
* Draws an axis line at the current cursor position and edge.
*
* @param g2 the graphics device.
* @param cursor the cursor position.
* @param dataArea the data area.
* @param edge the edge.
*/
protected void drawAxisLine(Graphics2D g2, double cursor,
Rectangle2D dataArea, RectangleEdge edge) {
Line2D axisLine = null;
if (edge == RectangleEdge.TOP) {
axisLine = new Line2D.Double(dataArea.getX(), cursor,
dataArea.getMaxX(), cursor);
}
else if (edge == RectangleEdge.BOTTOM) {
axisLine = new Line2D.Double(dataArea.getX(), cursor,
dataArea.getMaxX(), cursor);
}
else if (edge == RectangleEdge.LEFT) {
axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor,
dataArea.getMaxY());
}
else if (edge == RectangleEdge.RIGHT) {
axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor,
dataArea.getMaxY());
}
g2.setPaint(this.axisLinePaint);
g2.setStroke(this.axisLineStroke);
g2.draw(axisLine);
}
/**
* Draws a grid of short lines indicating local illumination directions into
* displayImage.
*/
private void renderLightDirections() {
if (showLocalLightDirection && model.isLocalLightDirection()) {
Graphics2D g2d = (Graphics2D) displayImage.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.BLACK);
int scale = displayImage.getWidth() / model.getGrid().getCols();
g2d.setStroke(new BasicStroke(LOCAL_DIRECTION_LINES_STROKE_WIDTH_PX * scale));
int width = model.getGrid().getCols();
int height = model.getGrid().getRows();
for (int row = LOCAL_DIRECTION_LINES_SPACING_PX / 2; row < height; row += LOCAL_DIRECTION_LINES_SPACING_PX) {
for (int col = LOCAL_DIRECTION_LINES_SPACING_PX / 2; col < width; col += LOCAL_DIRECTION_LINES_SPACING_PX) {
double dirX = model.getLocalLightDirectionX(col, row);
double dirY = model.getLocalLightDirectionY(col, row);
double dx = dirX * LOCAL_DIRECTION_LINES_LENGTH_PX / 2;
double dy = -dirY * LOCAL_DIRECTION_LINES_LENGTH_PX / 2;
Line2D line = new Line2D.Double((col - dx) * scale, (row - dy) * scale,
(col + dx) * scale, (row + dy) * scale);
g2d.draw(line);
}
}
}
}
/**
* Replays the command on the given WmfFile.
*
* @param file the meta file.
*/
public void replay( final WmfFile file ) {
final Graphics2D graph = file.getGraphics2D();
final MfDcState state = file.getCurrentState();
final int cx = state.getCurPosX();
final int cy = state.getCurPosY();
final Point destP = getScaledDestination();
if ( state.getLogPen().isVisible() ) {
state.prepareDraw();
graph.draw( new Line2D.Double( cx, cy, destP.x, destP.y ) );
state.postDraw();
}
state.setCurPos( destP.x, destP.y );
}
/**
* Draws a range crosshair.
*
* @param g2 the graphics target.
* @param dataArea the data area.
* @param orientation the plot orientation.
* @param value the crosshair value.
* @param axis the axis against which the value is measured.
* @param stroke the stroke used to draw the crosshair line.
* @param paint the paint used to draw the crosshair line.
*
* @since 1.0.5
*/
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea,
PlotOrientation orientation, double value, ValueAxis axis,
Stroke stroke, Paint paint) {
if (!axis.getRange().contains(value)) {
return;
}
Line2D line = null;
if (orientation == PlotOrientation.HORIZONTAL) {
double xx = axis.valueToJava2D(value, dataArea,
RectangleEdge.BOTTOM);
line = new Line2D.Double(xx, dataArea.getMinY(), xx,
dataArea.getMaxY());
}
else {
double yy = axis.valueToJava2D(value, dataArea,
RectangleEdge.LEFT);
line = new Line2D.Double(dataArea.getMinX(), yy,
dataArea.getMaxX(), yy);
}
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
/**
* Draws a range crosshair.
*
* @param g2 the graphics target.
* @param dataArea the data area.
* @param orientation the plot orientation.
* @param value the crosshair value.
* @param axis the axis against which the value is measured.
* @param stroke the stroke used to draw the crosshair line.
* @param paint the paint used to draw the crosshair line.
*
* @since 1.0.5
*/
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea,
PlotOrientation orientation, double value, ValueAxis axis,
Stroke stroke, Paint paint) {
if (!axis.getRange().contains(value)) {
return;
}
Line2D line = null;
if (orientation == PlotOrientation.HORIZONTAL) {
double xx = axis.valueToJava2D(value, dataArea,
RectangleEdge.BOTTOM);
line = new Line2D.Double(xx, dataArea.getMinY(), xx,
dataArea.getMaxY());
}
else {
double yy = axis.valueToJava2D(value, dataArea,
RectangleEdge.LEFT);
line = new Line2D.Double(dataArea.getMinX(), yy,
dataArea.getMaxX(), yy);
}
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
/**
* Draws a range crosshair.
*
* @param g2 the graphics target.
* @param dataArea the data area.
* @param orientation the plot orientation.
* @param value the crosshair value.
* @param axis the axis against which the value is measured.
* @param stroke the stroke used to draw the crosshair line.
* @param paint the paint used to draw the crosshair line.
*
* @since 1.0.5
*/
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea,
PlotOrientation orientation, double value, ValueAxis axis,
Stroke stroke, Paint paint) {
if (!axis.getRange().contains(value)) {
return;
}
Line2D line = null;
if (orientation == PlotOrientation.HORIZONTAL) {
double xx = axis.valueToJava2D(value, dataArea,
RectangleEdge.BOTTOM);
line = new Line2D.Double(xx, dataArea.getMinY(), xx,
dataArea.getMaxY());
}
else {
double yy = axis.valueToJava2D(value, dataArea,
RectangleEdge.LEFT);
line = new Line2D.Double(dataArea.getMinX(), yy,
dataArea.getMaxX(), yy);
}
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
/**
* Draws a line perpendicular to the range axis.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the value axis.
* @param dataArea the area for plotting data (not yet adjusted for any 3D
* effect).
* @param value the value at which the grid line should be drawn.
* @param paint the paint (<code>null</code> not permitted).
* @param stroke the stroke (<code>null</code> not permitted).
*
* @see #drawRangeGridline
*
* @since 1.0.13
*/
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {
Range range = axis.getRange();
if (!range.contains(value)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
Line2D line = null;
double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(v, dataArea.getMinY(), v,
dataArea.getMaxY());
}
else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(dataArea.getMinX(), v,
dataArea.getMaxX(), v);
}
g2.setPaint(paint);
g2.setStroke(stroke);
g2.draw(line);
}
private void drawGrid(Rectangle2D rect) {
int gridSize = 50;
int gridCountH = 1 + 2 * (int) (rect.getHeight() / 2 / gridSize);
int gridCountV = 1 + 2 * (int) (rect.getWidth() / 2 / gridSize);
double gridOffsetH = (rect.getHeight() - (gridCountH + 1) * gridSize) / 2;
double gridOffsetV = (rect.getWidth() - (gridCountV + 1) * gridSize) / 2;
Line2D[] lines = new Line2D.Double[gridCountH + gridCountV];
// horizontal lines (change only y position)
double x1 = rect.getX();
double x2 = rect.getX() + rect.getWidth();
for (int i = 0; i < gridCountH; i++) {
double yh = rect.getY() + (i + 1) * gridSize + gridOffsetH;
lines[i] = new Line2D.Double(x1, yh, x2, yh);
}
// vertical lines (change only x position)
double y1 = rect.getY();
double y2 = rect.getY() + rect.getHeight();
for (int i = 0; i < gridCountV; i++) {
double xv = rect.getX() + (i + 1) * gridSize + gridOffsetV;
lines[gridCountH + i] = new Line2D.Double(xv, y1, xv, y2);
}
drawShapes(lines);
}
/**
* Adds or removes a control point on a specified location
* @param widget the connection widget
* @param localLocation the local location
*/
private void addRemoveControlPoint (ConnectionWidget widget, Point localLocation) {
ArrayList<Point> list = new ArrayList<Point> (widget.getControlPoints ());
if (!removeControlPoint (localLocation, list, deleteSensitivity)) {
Point exPoint = null;
int index = 0;
for (Point elem : list) {
if (exPoint != null) {
Line2D l2d = new Line2D.Double (exPoint, elem);
if (l2d.ptSegDist (localLocation) < createSensitivity) {
list.add (index, localLocation);
break;
}
}
exPoint = elem;
index++;
}
}
if (routingPolicy != null)
widget.setRoutingPolicy (routingPolicy);
widget.setControlPoints (list, false);
}
/**
* Draws a sequence of connected lines defined by
* arrays of <i>x</i> and <i>y</i> coordinates.
* Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
* The figure is not closed if the first point
* differs from the last point.
* @param xPoints an array of <i>x</i> points
* @param yPoints an array of <i>y</i> points
* @param nPoints the total number of points
* @see java.awt.Graphics#drawPolygon(int[], int[], int)
* @since JDK1.1
*/
public void drawPolyline(int xPoints[], int yPoints[],
int nPoints) {
float fromX;
float fromY;
float toX;
float toY;
if (nPoints > 0) {
fromX = xPoints[0];
fromY = yPoints[0];
for(int i = 1; i < nPoints; i++) {
toX = xPoints[i];
toY = yPoints[i];
draw(new Line2D.Float(fromX, fromY, toX, toY));
fromX = toX;
fromY = toY;
}
}
}
@Test
@DisplayName("golden sections")
void draw_Type_GOLDEN_SECTIONS() {
var rect = new Rectangle2D.Double(0, 0, 90, 12);
compositionGuide.setType(GOLDEN_SECTIONS);
compositionGuide.draw(rect, g2);
double phi = 1.618;
double sectionWidth = rect.getWidth() / phi;
double sectionHeight = rect.getHeight() / phi;
Line2D[] lines = new Line2D[4];
lines[0] = new Line2D.Double(sectionWidth, 0, sectionWidth, 12);
lines[1] = new Line2D.Double(90 - sectionWidth, 0, 90 - sectionWidth, 12);
lines[2] = new Line2D.Double(0, sectionHeight, 90, sectionHeight);
lines[3] = new Line2D.Double(0, 12 - sectionHeight, 90, 12 - sectionHeight);
verify(guidesRenderer).draw(refEq(g2), argThat(new DrawMatcherLine2D(Arrays.asList(lines))));
}
/**
* Draws the arrow.
*
* @param panel the drawing panel in which the arrow is viewed
* @param g the graphics context upon which to draw
*/
public void draw(DrawingPanel panel, Graphics g) {
Graphics2D g2 = (Graphics2D) g;
AffineTransform toPixels = panel.getPixelTransform();
g2.setPaint(color);
// draw the shaft
g2.draw(toPixels.createTransformedShape(new Line2D.Double(x, y, x+a, y+b)));
Point2D pt = new Point2D.Double(x+a, y+b);
pt = toPixels.transform(pt, pt);
double aspect = panel.isSquareAspect() ? 1 : -toPixels.getScaleX()/toPixels.getScaleY();
Shape head = getHead(Math.atan2(b, aspect*a));
Shape temp = AffineTransform.getTranslateInstance(pt.getX(), pt.getY()).createTransformedShape(head);
// draw the head
g2.fill(temp);
g2.setPaint(Color.BLACK);
}
public void paint(Graphics2D g2d) {
g2d.setStroke(new BasicStroke(0.16f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
// Greedily gather segments into polyline paths.
List<Line2D> polyLine = new ArrayList<>();
Point2D lastPoint = null;
for (Color color : collector.getColors()) {
g2d.setPaint(color);
List<Line2D> sortedSegments = quadraticSort(collector.getSegments(color));
for (Line2D seg : sortedSegments) {
if (lastPoint == null || lastPoint.distance(seg.getP1()) > COLLAPSE_THRESH) {
polyLine = emitCurrentPolyLine(g2d, polyLine);
}
polyLine.add(seg);
lastPoint = seg.getP2();
}
polyLine = emitCurrentPolyLine(g2d, polyLine);
}
}
/**
* Draws a line perpendicular to the range axis.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the value axis.
* @param dataArea the area for plotting data (not yet adjusted for any 3D
* effect).
* @param value the value at which the grid line should be drawn.
* @param paint the paint (<code>null</code> not permitted).
* @param stroke the stroke (<code>null</code> not permitted).
*
* @see #drawRangeGridline
*
* @since 1.0.13
*/
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {
Range range = axis.getRange();
if (!range.contains(value)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
Line2D line = null;
double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(v, dataArea.getMinY(), v,
dataArea.getMaxY());
}
else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(dataArea.getMinX(), v,
dataArea.getMaxX(), v);
}
g2.setPaint(paint);
g2.setStroke(stroke);
g2.draw(line);
}
@Override
public void show(RealSignal signal, String title, Imager.Type type, int z, ArrayList<Line2D.Double> overlayLines) {
ImagePlus imp = build(signal, type);
if (imp != null) {
imp.setTitle(title);
int nz = imp.getStackSize();
imp.show();
imp.setSlice(Math.max(1, Math.min(nz, z)));
imp.getProcessor().resetMinAndMax();
}
if (imp != null) {
Overlay overlay = imp.getOverlay() == null ? new Overlay() : imp.getOverlay();
for(Line2D.Double line : overlayLines) {
ij.gui.Line roi = new ij.gui.Line(round(line.x1), round(line.y1), round(line.x2), round(line.y2));
overlay.add(roi);
}
imp.setOverlay(overlay);
}
}
void drawArrow(Graphics2D g2, double angle, float startX, float startY, float endX, float endY) {
if (enabled) {
g2.setColor(ENABLED_ARROW_COLOR);
} else {
g2.setColor(DISABLED_ARROW_COLOR);
}
g2.setStroke(ARROW_STROKE);
g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE);
g2.draw(new Line2D.Float(startX, startY, endX, endY));
double backAngle1 = 2.8797926 + angle;
double backAngle2 = 3.4033926 + angle;
int arrowRadius = 10;
float arrowEnd1X = (float) (endX + arrowRadius * Math.cos(backAngle1));
float arrowEnd1Y = (float) (endY + arrowRadius * Math.sin(backAngle1));
float arrowEnd2X = (float) (endX + arrowRadius * Math.cos(backAngle2));
float arrowEnd2Y = (float) (endY + arrowRadius * Math.sin(backAngle2));
g2.draw(new Line2D.Float(endX, endY, arrowEnd1X, arrowEnd1Y));
g2.draw(new Line2D.Float(endX, endY, arrowEnd2X, arrowEnd2Y));
}
/**
* Utility method for drawing a line perpendicular to the range axis (used
* for crosshairs).
*
* @param g2 the graphics device.
* @param dataArea the area defined by the axes.
* @param value the data value.
* @param stroke the line stroke (<code>null</code> not permitted).
* @param paint the line paint (<code>null</code> not permitted).
*/
protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea,
double value, Stroke stroke, Paint paint) {
double java2D = getRangeAxis().valueToJava2D(value, dataArea,
getRangeAxisEdge());
Line2D line = null;
if (this.orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(java2D, dataArea.getMinY(), java2D,
dataArea.getMaxY());
}
else if (this.orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(dataArea.getMinX(), java2D,
dataArea.getMaxX(), java2D);
}
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
/**
*
*/
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
Stroke stroke = g2.getStroke();
g2.setStroke(getSelectionStroke());
g.setColor(getSelectionColor());
Point last = state.getAbsolutePoint(0).getPoint();
for (int i = 1; i < state.getAbsolutePointCount(); i++) {
Point current = state.getAbsolutePoint(i).getPoint();
Line2D line = new Line2D.Float(last.x, last.y, current.x, current.y);
Rectangle bounds = g2.getStroke().createStrokedShape(line).getBounds();
if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) {
g2.draw(line);
}
last = current;
}
g2.setStroke(stroke);
super.paint(g);
}
/**
* Draws a line from {@code (x1, y1)} to {@code (x2, y2)} using
* the current {@code paint} and {@code stroke}.
*
* @param x1 the x-coordinate of the start point.
* @param y1 the y-coordinate of the start point.
* @param x2 the x-coordinate of the end point.
* @param y2 the x-coordinate of the end point.
*/
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
if (this.line == null) {
this.line = new Line2D.Double(x1, y1, x2, y2);
} else {
this.line.setLine(x1, y1, x2, y2);
}
draw(this.line);
}
@Override
public double getMeanCurvature ()
{
Point2D prevPoint = null;
Line2D prevBisector = null;
Line2D bisector = null;
Population curvatures = new Population();
if (spline == null) {
computeLine();
}
for (Point2D point : points) {
if (prevPoint != null) {
bisector = LineUtil.bisector(new Line2D.Double(prevPoint, point));
}
if (prevBisector != null) {
Point2D inter = LineUtil.intersection(
prevBisector.getP1(),
prevBisector.getP2(),
bisector.getP1(),
bisector.getP2());
double radius = Math.hypot(
inter.getX() - point.getX(),
inter.getY() - point.getY());
curvatures.includeValue(1 / radius);
}
prevBisector = bisector;
prevPoint = point;
}
if (curvatures.getCardinality() > 0) {
return 1 / curvatures.getMeanValue();
} else {
return Double.POSITIVE_INFINITY;
}
}
@Override
protected void drawHorizontalReferenceLines() {
g.setColor(referenceLineColor);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
ListNumber yTicks = yReferenceCoords.get(0);
for (int b = 0; b < yTicks.size(); b++) {
Shape line = new Line2D.Double(xAreaCoordStart, yTicks.getDouble(b), xAreaCoordEnd - 1, yTicks.getDouble(b));
g.draw(line);
}
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
@Override
public void visit (HeadInter head)
{
final Line2D midLine = head.getMidLine();
if (midLine != null) {
if (splitMirrors()) {
// Draw head proper half
int width = head.getBounds().width;
int xDir = midLine.getY2() > midLine.getY1() ? -1 : +1;
Path2D p = new Path2D.Double();
p.append(midLine, false);
p.lineTo(midLine.getX2() + xDir * width, midLine.getY2());
p.lineTo(midLine.getX1() + xDir * width, midLine.getY1());
p.closePath();
java.awt.Shape oldClip = g.getClip();
g.clip(p);
visit((Inter) head);
g.setClip(oldClip);
} else {
visit((Inter) head);
}
// Draw midLine using complementary color of head
Color compColor = UIUtil.complementaryColor(g.getColor());
Stroke oldStroke = UIUtil.setAbsoluteStroke(g, 1f);
g.setColor(compColor);
g.draw(midLine);
g.setStroke(oldStroke);
} else {
visit((Inter) head);
}
}
private void drawCrosshair(Graphics2D graphics, AffineTransform i2vTransform, Point centerPixel,
Rectangle2D pixelViewRect) {
Rectangle surroundImageRect = new Rectangle(centerPixel.x - 1, centerPixel.y - 1, 3, 3);
Rectangle2D surroundViewRect = i2vTransform.createTransformedShape(surroundImageRect).getBounds2D();
double scale = MAX_CROSSHAIR_SIZE / surroundViewRect.getBounds2D().getWidth();
if (scale > 1) {
double newWidth = surroundViewRect.getWidth() * scale;
double newHeight = surroundViewRect.getHeight() * scale;
double newX = surroundViewRect.getCenterX() - newWidth / 2;
double newY = surroundViewRect.getCenterY() - newHeight / 2;
surroundViewRect.setRect(newX, newY, newWidth, newHeight);
}
graphics.draw(surroundViewRect);
Line2D.Double northLine = new Line2D.Double(surroundViewRect.getCenterX(), surroundViewRect.getMinY(),
surroundViewRect.getCenterX(), pixelViewRect.getMinY());
Line2D.Double eastLine = new Line2D.Double(surroundViewRect.getMaxX(), surroundViewRect.getCenterY(),
pixelViewRect.getMaxX(), surroundViewRect.getCenterY());
Line2D.Double southLine = new Line2D.Double(surroundViewRect.getCenterX(), surroundViewRect.getMaxY(),
surroundViewRect.getCenterX(), pixelViewRect.getMaxY());
Line2D.Double westLine = new Line2D.Double(surroundViewRect.getMinX(), surroundViewRect.getCenterY(),
pixelViewRect.getMinX(), surroundViewRect.getCenterY());
graphics.draw(northLine);
graphics.draw(eastLine);
graphics.draw(southLine);
graphics.draw(westLine);
}
/**
* Draws a line perpendicular to the range axis.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the value axis.
* @param dataArea the area for plotting data (not yet adjusted for any 3D
* effect).
* @param value the value at which the grid line should be drawn.
* @param paint the paint.
* @param stroke the stroke.
*/
@Override
public void drawRangeLine(Graphics2D g2, XYPlot plot, ValueAxis axis,
Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {
Range range = axis.getRange();
if (!range.contains(value)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
Line2D line = null;
double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(v, dataArea.getMinY(), v,
dataArea.getMaxY());
} else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(dataArea.getMinX(), v,
dataArea.getMaxX(), v);
}
g2.setPaint(paint);
g2.setStroke(stroke);
Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE);
g2.draw(line);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
/**
* Draws a grid line against the domain axis.
* <P>
* Note that this default implementation assumes that the horizontal axis
* is the domain axis. If this is not the case, you will need to override
* this method.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the area for plotting data (not yet adjusted for any
* 3D effect).
* @param value the Java2D value at which the grid line should be drawn.
*
* @see #drawRangeGridline(Graphics2D, CategoryPlot, ValueAxis,
* Rectangle2D, double)
*/
@Override
public void drawDomainGridline(Graphics2D g2, CategoryPlot plot,
Rectangle2D dataArea, double value) {
Line2D line = null;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(dataArea.getMinX(), value,
dataArea.getMaxX(), value);
}
else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(value, dataArea.getMinY(), value,
dataArea.getMaxY());
}
Paint paint = plot.getDomainGridlinePaint();
if (paint == null) {
paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
}
g2.setPaint(paint);
Stroke stroke = plot.getDomainGridlineStroke();
if (stroke == null) {
stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
}
g2.setStroke(stroke);
g2.draw(line);
}
protected void drawBar(Graphics2D g2d, HexPoint start, HexPoint end) {
Color oldColor = g2d.getColor();
Stroke oldStroke = g2d.getStroke();
g2d.setColor(BAR_COLOUR);
g2d.setStroke(new BasicStroke(BAR_WIDTH));
g2d.draw(new Line2D.Double(start.get2D(),end.get2D()));
g2d.setColor(oldColor);
g2d.setStroke(oldStroke);
}