use of java.awt.geom.Path2D in project triplea by triplea-game.
the class MapRouteDrawer method drawCurvedPath.
/**
* Draws a smooth curve through the given array of points
*
* <p>
* This algorithm is called Spline-Interpolation
* because the Apache-commons-math library we are using here does not accept
* values but {@code f(x)=y} with x having to increase all the time
* the idea behind this is to use a parameter array - the so called index
* as x array and splitting the points into a x and y coordinates array.
* </p>
*
* <p>
* Finally those 2 interpolated arrays get unified into a single {@linkplain Point2D} array and drawn to the Map
* </p>
*
* @param graphics The {@linkplain Graphics2D} Object to be drawn on
* @param points The Knot Points for the Spline-Interpolator aka the joints
*/
private void drawCurvedPath(final Graphics2D graphics, final Point2D[] points) {
final double[] index = createParameterizedIndex(points);
final PolynomialSplineFunction xcurve = splineInterpolator.interpolate(index, getValues(points, Point2D::getX));
final double[] xcoords = getCoords(xcurve, index);
final PolynomialSplineFunction ycurve = splineInterpolator.interpolate(index, getValues(points, Point2D::getY));
final double[] ycoords = getCoords(ycurve, index);
final List<Path2D> paths = routeCalculator.getAllNormalizedLines(xcoords, ycoords);
for (final Path2D path : paths) {
drawTransformedShape(graphics, path);
}
// draws the Line to the Cursor on every possible screen, so that the line ends at the cursor no matter what...
final List<Point2D[]> finishingPoints = routeCalculator.getAllPoints(new Point2D.Double(xcoords[xcoords.length - 1], ycoords[ycoords.length - 1]), points[points.length - 1]);
final boolean hasArrowEnoughSpace = points[points.length - 2].distance(points[points.length - 1]) > ARROW_LENGTH;
for (final Point2D[] finishingPointArray : finishingPoints) {
drawTransformedShape(graphics, new Line2D.Double(finishingPointArray[0], finishingPointArray[1]));
if (hasArrowEnoughSpace) {
drawArrow(graphics, finishingPointArray[0], finishingPointArray[1]);
}
}
}
use of java.awt.geom.Path2D in project Digital by hneemann.
the class GraphicSwing method drawPolygon.
@Override
public void drawPolygon(Polygon p, Style style) {
applyStyle(style);
Path2D path = new GeneralPath();
// CHECKSTYLE.OFF: ModifiedControlVariable
for (int i = 0; i < p.size(); i++) {
if (i == 0) {
path.moveTo(p.get(i).getXFloat(), p.get(i).getYFloat());
} else {
if (p.isBezierStart(i)) {
path.curveTo(p.get(i).getXFloat(), p.get(i).getYFloat(), p.get(i + 1).getXFloat(), p.get(i + 1).getYFloat(), p.get(i + 2).getXFloat(), p.get(i + 2).getYFloat());
i += 2;
} else
path.lineTo(p.get(i).getXFloat(), p.get(i).getYFloat());
}
}
if (p.isClosed())
path.closePath();
if (style.isFilled() && p.isClosed())
gr.fill(path);
if (style.getThickness() > 0)
gr.draw(path);
}
use of java.awt.geom.Path2D in project Activiti by Activiti.
the class DefaultProcessDiagramCanvas method drawTextAnnotation.
public void drawTextAnnotation(String id, String text, GraphicInfo graphicInfo) {
int x = (int) graphicInfo.getX();
int y = (int) graphicInfo.getY();
int width = (int) graphicInfo.getWidth();
int height = (int) graphicInfo.getHeight();
Font originalFont = g.getFont();
Stroke originalStroke = g.getStroke();
g.setFont(ANNOTATION_FONT);
Path2D path = new Path2D.Double();
x += .5;
int lineLength = 18;
path.moveTo(x + lineLength, y);
path.lineTo(x, y);
path.lineTo(x, y + height);
path.lineTo(x + lineLength, y + height);
path.lineTo(x + lineLength, y + height - 1);
path.lineTo(x + 1, y + height - 1);
path.lineTo(x + 1, y + 1);
path.lineTo(x + lineLength, y + 1);
path.closePath();
g.draw(path);
int boxWidth = width - (2 * ANNOTATION_TEXT_PADDING);
int boxHeight = height - (2 * ANNOTATION_TEXT_PADDING);
int boxX = x + width / 2 - boxWidth / 2;
int boxY = y + height / 2 - boxHeight / 2;
if (text != null && !text.isEmpty()) {
drawMultilineAnnotationText(text, boxX, boxY, boxWidth, boxHeight);
}
// restore originals
g.setFont(originalFont);
g.setStroke(originalStroke);
// set element's id
g.setCurrentGroupId(id);
}
use of java.awt.geom.Path2D in project java-swing-tips by aterai.
the class ArrowToggleButtonBarCellIcon method makeShape.
protected Shape makeShape(Container parent, Component c, int x, int y) {
int w = c.getWidth() - 1;
int h = c.getHeight() - 1;
double h2 = Math.round(h * .5);
double w2 = TH;
Path2D p = new Path2D.Double();
p.moveTo(0d, 0d);
p.lineTo(w - w2, 0d);
p.lineTo(w, h2);
p.lineTo(w - w2, h);
p.lineTo(0d, h);
if (!Objects.equals(c, parent.getComponent(0))) {
p.lineTo(w2, h2);
}
p.closePath();
return AffineTransform.getTranslateInstance(x, y).createTransformedShape(p);
}
use of java.awt.geom.Path2D in project java-swing-tips by aterai.
the class Arrow method makeArrowHead.
protected Path2D makeArrowHead(Dimension size) {
Path2D path = new Path2D.Double();
double t = size.height;
double w = size.width * .5;
path.moveTo(0d, -w);
path.lineTo(t, 0d);
path.lineTo(0d, w);
path.closePath();
return path;
}
Aggregations