Examples of Path2D


Examples of java.awt.geom.Path2D

public class DrawingUtils {
 
  //Helper class to transform from a FreedomPolygon to a Path
  public static Path2D freedomPolygonToPath(FreedomPolygon fp)
  {
    Path2D mP = new Path2D.Double();
    for (int j = 0; j < fp.getPoints().size(); j++) {
      FreedomPoint point= fp.getPoints().get(j);
      if (j== 0)
        mP.moveTo(point.getX(), point.getY());
      else
        mP.lineTo(point.getX(), point.getY());           
    }           
    //closing the path
    mP.closePath();
 
    return mP;
  }
View Full Code Here

Examples of java.awt.geom.Path2D

            }
            else {
                outer = new Rectangle2D.Float(x, y, width, height);
                inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
            }
            Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
            path.append(outer, false);
            path.append(inner, false);
            g2d.fill(path);
            g2d.setColor(oldColor);
        }
    }
View Full Code Here

Examples of java.awt.geom.Path2D

                }
                else {
                    Graphics g2 = g.create();
                    if (g2 instanceof Graphics2D) {
                        Graphics2D g2d = (Graphics2D) g2;
                        Path2D path = new Path2D.Float();
                        path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false);
                        path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false);
                        path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false);
                        path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false);
                        g2d.clip(path);
                    }
                    border.paintBorder(c, g2, borderX, borderY, borderW, borderH);
                    g2.dispose();
                }
View Full Code Here

Examples of java.awt.geom.Path2D

            return convertCoords(coords, coords.length);
        }

        // For Path2D, the integer path type is inserted before the coordinates of each segment
        if (shape instanceof Path2D) {
            Path2D p = (Path2D) shape;
            StringBuffer buf = new StringBuffer();
            coords = new double[6];
            PathIterator pathIter = p.getPathIterator(null);
            while (!pathIter.isDone()) {
                int subPathType = pathIter.currentSegment(coords);
                buf.append(subPathType).append(" ");
                if (subPathType == PathIterator.SEG_MOVETO || subPathType == PathIterator.SEG_LINETO) {
                    buf.append(convertCoords(coords, 2)).append(" ");
View Full Code Here

Examples of java.awt.geom.Path2D

                yPoints[i] = (int) graphicInfo.getY() - minY;
            }

            int radius = 15;

            Path2D path = new Path2D.Double();

            for (int i = 0; i < xPoints.length; i++) {
                Integer anchorX = xPoints[i];
                Integer anchorY = yPoints[i];

                double targetX = anchorX;
                double targetY = anchorY;

                double ax = 0;
                double ay = 0;
                double bx = 0;
                double by = 0;
                double zx = 0;
                double zy = 0;

                if ((i > 0) && (i < (xPoints.length - 1))) {
                    Integer cx = anchorX;
                    Integer cy = anchorY;

                    // pivot point of prev line
                    double lineLengthY = yPoints[i] - yPoints[i - 1];

                    // pivot point of prev line
                    double lineLengthX = xPoints[i] - xPoints[i - 1];
                    double lineLength = Math.sqrt(Math.pow(lineLengthY, 2)
                            + Math.pow(lineLengthX, 2));
                    double dx = (lineLengthX * radius) / lineLength;
                    double dy = (lineLengthY * radius) / lineLength;
                    targetX = targetX - dx;
                    targetY = targetY - dy;

                    // isDefaultConditionAvailable = isDefault && i == 1 && lineLength > 10;
                    if ((lineLength < (2 * radius)) && (i > 1)) {
                        targetX = xPoints[i] - (lineLengthX / 2);
                        targetY = yPoints[i] - (lineLengthY / 2);
                    }

                    // pivot point of next line
                    lineLengthY = yPoints[i + 1] - yPoints[i];
                    lineLengthX = xPoints[i + 1] - xPoints[i];
                    lineLength = Math.sqrt(Math.pow(lineLengthY, 2)
                            + Math.pow(lineLengthX, 2));

                    if (lineLength < radius) {
                        lineLength = radius;
                    }

                    dx = (lineLengthX * radius) / lineLength;
                    dy = (lineLengthY * radius) / lineLength;

                    double nextSrcX = xPoints[i] + dx;
                    double nextSrcY = yPoints[i] + dy;

                    if ((lineLength < (2 * radius))
                            && (i < (xPoints.length - 2))) {
                        nextSrcX = xPoints[i] + (lineLengthX / 2);
                        nextSrcY = yPoints[i] + (lineLengthY / 2);
                    }

                    double dx0 = (cx - targetX) / 3;
                    double dy0 = (cy - targetY) / 3;
                    ax = cx - dx0;
                    ay = cy - dy0;

                    double dx1 = (cx - nextSrcX) / 3;
                    double dy1 = (cy - nextSrcY) / 3;
                    bx = cx - dx1;
                    by = cy - dy1;

                    zx = nextSrcX;
                    zy = nextSrcY;
                }

                if (i == 0) {
                    path.moveTo(targetX, targetY);
                } else {
                    path.lineTo(targetX, targetY);
                }

                if ((i > 0) && (i < (xPoints.length - 1))) {
                    // add curve
                    path.curveTo(ax, ay, bx, by, zx, zy);
                }
            }

            graphics.draw(path);

View Full Code Here

Examples of java.awt.geom.Path2D

    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);
 
View Full Code Here

Examples of java.awt.geom.Path2D

                                    int join,
                                    float miterlimit,
                                    float dashes[],
                                    float dashphase)
    {
        final Path2D p2d = new Path2D.Float();

        strokeTo(src,
                 null,
                 width,
                 caps,
                 join,
                 miterlimit,
                 dashes,
                 dashphase,
                 new LineSink() {
                     public void moveTo(int x0, int y0) {
                         p2d.moveTo(S15_16ToFloat(x0), S15_16ToFloat(y0));
                     }
                     public void lineJoin() {}
                     public void lineTo(int x1, int y1) {
                         p2d.lineTo(S15_16ToFloat(x1), S15_16ToFloat(y1));
                     }
                     public void close() {
                         p2d.closePath();
                     }
                     public void end() {}
                 });

        return p2d;
View Full Code Here

Examples of java.awt.geom.Path2D

                        if (lassoPath.size() > 2) {

                            Axis xAxis = scatterPlot.xAxis;
                            Axis yAxis = scatterPlot.yAxis;

                            Path2D path = new Path2D.Double(java.awt.geom.Path2D.WIND_NON_ZERO, lassoPath.size());
                            Iterator<Point> iter = lassoPath.getPoints().iterator();
                            Point p = iter.next();
                            double x = xAxis.getDataValueForPixel(p.x);
                            double y = yAxis.getDataValueForPixel(p.y);
                            path.moveTo(x, y);
                            while (iter.hasNext()) {
                                p = iter.next();
                                x = xAxis.getDataValueForPixel(p.x);
                                y = yAxis.getDataValueForPixel(p.y);
                                path.lineTo(x, y);
                            }
                            path.closePath();
                            scatterPlot.selectPointsInPath(path);
                            Rectangle damageRect = lassoPath.getBounds();
                            lassoPath = null;
                            repaint(damageRect);
View Full Code Here

Examples of java.awt.geom.Path2D

            Shape outer, inner;

            outer = new RoundRectangle2D.Float(insets.left, insets.top, width - insets.left - insets.right, height - insets.top - insets.bottom, arc, arc);
            inner = new Rectangle2D.Float(insets.left + dr, insets.top + dr, width - insets.left - insets.right - 2 * dr, height - insets.top - insets.bottom - 2 * dr);

            Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);

            path.append(outer, false);
            path.append(inner, false);

            g2d.fill(path);

            g2d.setColor(oldColor);
        }
View Full Code Here

Examples of java.awt.geom.Path2D

    if (radius >= DistanceUtils.HALF_EARTH_CIRCUMFERENCE) {
      return new Rectangle2D.Double(0.0, 0.0, 360.0, 180.0);
    }
    int numberOfCrossOvers = 0;

    Path2D path = new Path2D.Double();
    DirectPosition2D initPT = DistanceUtils.getPointOnGreatCircle(center.getOrdinate(1),
        center.getOrdinate(0), radius, 0);
    path.moveTo(initPT.x + 180.0, initPT.y + 90.0);

    DirectPosition2D currPT = initPT;

    for (int i = 1; i < 360; i++) {

      DirectPosition2D pt = DistanceUtils.getPointOnGreatCircle(center.getOrdinate(1),
          center.getOrdinate(0), radius, i);
      path.lineTo(pt.x + 180.0, pt.y + 90.0);

      if (dateLineCrossOver(Longitude.normalize(currPT.x), Longitude.normalize(pt.x))) {
        numberOfCrossOvers++;
      }
      currPT = pt;
    }
    if (dateLineCrossOver(Longitude.normalize(initPT.x), Longitude.normalize(currPT.x))) {
      numberOfCrossOvers++;
    }

    /**
     * If the path crosses the dateline once, it's a special case, so take care
     * of it differently. It will need to include areas around the pole.
     */
    if (numberOfCrossOvers == 1) {
      Rectangle2D r = path.getBounds2D();
      Rectangle2D lowerHalf = new Rectangle2D.Double(0.0, 0.0, 360.0, r.getMaxY());
      if (lowerHalf.contains(center.getOrdinate(0) + 180.0, center.getOrdinate(1) + 90.0)) {
        return lowerHalf;
      } else {
        return new Rectangle2D.Double(0.0, r.getMinY(), 360.0, 180.0 - r.getMinY());
      }
    }

    if (path.contains(center.getOrdinate(0) + 180.0, center.getOrdinate(1) + 90.0)) {
      Rectangle2D r = path.getBounds2D();
      if ((r.getMaxX() - r.getMinX()) > 359.0) {
        return new Rectangle2D.Double(0.0, 0.0, 360.0, 180.0);
      } else if (r.getMinX() < 0 || r.getMaxX() > 360.0) {
        /**
         * For circles that crosses the dateline instead of splitting in half
         * and having to go down the tree twice, for first version span
         * longitude 360.0 and use the exact height of the box
         */
        return new Rectangle2D.Double(0.0, r.getY(), 360.0, r.getHeight());
      } else {
        return path.getBounds2D();
      }
    } else {
      Area pathArea = new Area(path);
      Area wholeMap = new Area(new Rectangle2D.Double(0.0, 0.0, 360.0, 180.0));
      wholeMap.subtract(pathArea);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.