Java Code Examples for java.awt.geom.Path2D#Double

The following examples show how to use java.awt.geom.Path2D#Double . 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: TrafficSimulatorGUI.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void drawAreas(Graphics2D g) {
	areas.clear();
	for (TrafficArea area : manager.getAreas()) {
		Path2D shape = new Path2D.Double();
		List<Edge> edges = area.getArea().getEdges();
		Edge e = edges.get(0);
		shape.moveTo(transform.xToScreen(e.getStartX()), transform.yToScreen(e.getStartY()));
		for (Edge edge : edges) {
			shape.lineTo(transform.xToScreen(edge.getEndX()), transform.yToScreen(edge.getEndY()));
		}
		if (area == selectedArea) {
			g.setColor(SELECTED_AREA_COLOUR);
			g.fill(shape);
			g.setColor(AREA_OUTLINE_COLOUR);
			paintEdges(edges, g);
			int[][] graph = area.getGraph();
			List<Line2D> oLines = area.getOpenLines();
			g.setColor(Color.green);
			paintLines(oLines, g);
			g.setColor(Color.yellow);
			for (int i = 0; i < graph.length; i++) {
				for (int j = 0; j < graph.length; j++) {
					if (graph[i][j] > 10000)
						continue;
					Line2D line = new Line2D(TrafficSimulator.getMidPoint(oLines.get(i).getOrigin(), oLines.get(i).getEndPoint()),
							TrafficSimulator.getMidPoint(oLines.get(j).getOrigin(), oLines.get(j).getEndPoint()));
					paintLine(line, g);
				}
			}
		} else {
			g.setColor(AREA_OUTLINE_COLOUR);
			paintEdges(edges, g);
		}
		areas.put(shape, area);
	}
}
 
Example 2
Source File: Graph2DRenderer.java    From diirt with MIT License 6 votes vote down vote up
private static Path2D.Double nearestNeighbour(ScaledData scaledData) {
    double[] scaledX = scaledData.scaledX;
    double[] scaledY = scaledData.scaledY;
    int start = scaledData.start;
    int end = scaledData.end;
    Path2D.Double line = new Path2D.Double();
    line.moveTo(scaledX[start], scaledY[start]);
    for (int i = 1; i < end; i++) {
        double halfX = scaledX[i - 1] + (scaledX[i] - scaledX[i - 1]) / 2;
        if (!java.lang.Double.isNaN(scaledY[i-1])) {
            line.lineTo(halfX, scaledY[i - 1]);
            if (!java.lang.Double.isNaN(scaledY[i]))
                line.lineTo(halfX, scaledY[i]);
        } else {
            line.moveTo(halfX, scaledY[i]);
        }
    }
    line.lineTo(scaledX[end - 1], scaledY[end - 1]);
    return line;
}
 
Example 3
Source File: VisualQueueComponent.java    From workcraft with MIT License 6 votes vote down vote up
@Override
public Shape getShape() {
    Path2D shape = new Path2D.Double();
    QueueComponent ref = getReferencedComponent();
    if (ref != null) {
        int capacity = ref.getCapacity();
        double contactOffset = 0.5 * capacity * SLOT_WIDTH;

        shape.moveTo(+contactOffset, 0.0);
        shape.lineTo(+contactOffset + CONTACT_LENGTH, 0.0);

        shape.moveTo(-contactOffset, 0.0);
        shape.lineTo(-contactOffset - CONTACT_LENGTH, 0.0);

        for (int i = 0; i < capacity; i++) {
            shape.append(getSlotShape(i), false);
        }
    }
    return shape;
}
 
Example 4
Source File: DividerPolygon.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void paint(Graphics2D g, int width) {
  GraphicsUtil.setupAntialiasing(g);


  if (!myApplied) {
    Shape upperCurve = makeCurve(width, myStart1, myStart2, true);
    Shape lowerCurve = makeCurve(width, myEnd1, myEnd2, false);

    Path2D path = new Path2D.Double();
    path.append(upperCurve, true);
    path.append(lowerCurve, true);
    g.setColor(myColor);
    g.fill(path);

    g.setColor(DiffUtil.getFramingColor(myColor));
    g.draw(upperCurve);
    g.draw(lowerCurve);
  }
  else {
    g.setColor(myColor);
    g.draw(makeCurve(width, myStart1 + 1, myStart2 + 1, true));
    g.draw(makeCurve(width, myStart1 + 2, myStart2 + 2, true));
    g.draw(makeCurve(width, myEnd1 + 1, myEnd2 + 1, false));
    g.draw(makeCurve(width, myEnd1 + 2, myEnd2 + 2, false));
  }
}
 
Example 5
Source File: ConnectionTool.java    From workcraft with MIT License 5 votes vote down vote up
@Override
public void drawInUserSpace(GraphEditor editor, Graphics2D g) {
    if ((firstNode != null) && (currentPoint != null)) {
        g.setStroke(new BasicStroke((float) editor.getViewport().pixelSizeInUserSpace().getX()));
        Path2D path = new Path2D.Double();
        path.moveTo(firstPoint.getX(), firstPoint.getY());
        for (Point2D point : controlPoints) {
            path.lineTo(point.getX(), point.getY());
        }
        path.lineTo(currentPoint.getX(), currentPoint.getY());
        if (currentNode == null) {
            g.setColor(incompleteConnectionColor);
            g.draw(path);
        } else {
            try {
                VisualModel model = editor.getModel();
                if (directedArcs) {
                    model.validateConnection(firstNode, currentNode);
                } else {
                    model.validateUndirectedConnection(firstNode, currentNode);
                }
                g.setColor(validConnectionColor);
                g.draw(path);
            } catch (InvalidConnectionException e) {
                showIssue(editor, e.getMessage());
                g.setColor(invalidConnectionColor);
                g.draw(path);
            }
        }
    }
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private static Area getOuterShape(Shape shape) {
  Area area = new Area();
  Path2D path = new Path2D.Double();
  PathIterator pi = shape.getPathIterator(null);
  double[] coords = new double[6];
  while (!pi.isDone()) {
    int pathSegmentType = pi.currentSegment(coords);
    switch (pathSegmentType) {
      case PathIterator.SEG_MOVETO:
        path.moveTo(coords[0], coords[1]);
        break;
      case PathIterator.SEG_LINETO:
        path.lineTo(coords[0], coords[1]);
        break;
      case PathIterator.SEG_QUADTO:
        path.quadTo(coords[0], coords[1], coords[2], coords[3]);
        break;
      case PathIterator.SEG_CUBICTO:
        path.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
        break;
      case PathIterator.SEG_CLOSE:
        path.closePath();
        area.add(createArea(path));
        path.reset();
        break;
      default:
        System.err.println("Unexpected value! " + pathSegmentType);
        break;
    }
    pi.next();
  }
  return area;
}
 
Example 7
Source File: EmptyCapacity.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    final Path2D path1 = new Path2D.Double(Path2D.WIND_EVEN_ODD, 0);
    path1.moveTo(10, 10);
    path1.lineTo(20, 20);
    final Path2D path2 = new Path2D.Float(Path2D.WIND_EVEN_ODD, 0);
    path2.moveTo(10, 10);
    path2.lineTo(20, 20);
}
 
Example 8
Source File: AwtRenderingBackend.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void moveTo(final double x, final double y) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("[" + id_ + "] moveTo(" + x + ", " + y + ")");
    }

    final Path2D subPath = new Path2D.Double();
    final Point2D p = transformation_.transform(new Point2D.Double(x, y), null);
    subPath.moveTo(p.getX(), p.getY());
    subPaths_.add(subPath);
}
 
Example 9
Source File: DocGraphics.java    From Geom_Kisrhombille with GNU General Public License v3.0 5 votes vote down vote up
void fillPolygon(KPolygon polygon,Color c){
Path2D path=new Path2D.Double();
int s=polygon.size();
DPoint p=polygon.get(0).getBasicPoint2D();
path.moveTo(p.x,p.y);
for(int i=1;i<s;i++){
  p=polygon.get(i).getBasicPoint2D();
  path.lineTo(p.x,p.y);}
path.closePath();
graphics.setPaint(c);
graphics.fill(path); }
 
Example 10
Source File: EMGridOverlayPainter.java    From Forsythia with GNU General Public License v3.0 5 votes vote down vote up
private void strokeGraphEdges_EditGeometry(Graphics2D graphics){
graphics.setStroke(UI.GRID_DRAWINGSTROKE);
graphics.setPaint(UI.EDITJIG_EDITGEOMETRY_STROKECOLOR);
Iterator<GEdge> i=GE.ge.editor_metagon.editedmetagon.getGraph().edges.iterator();
GEdge e;
double[] p0,p1;
Path2D path=new Path2D.Double();
while(i.hasNext()){
  e=i.next();
  p0=GE.ge.editor_metagon.editedmetagon.getMetagonEditorGeometryCache().getPoint(e.v0.kvertex);
  p1=GE.ge.editor_metagon.editedmetagon.getMetagonEditorGeometryCache().getPoint(e.v1.kvertex);
  path.reset();
  path.moveTo(p0[0],p0[1]);
  path.lineTo(p1[0],p1[1]);
  graphics.draw(path);}}
 
Example 11
Source File: DocGraphics.java    From Geom_Kisrhombille with GNU General Public License v3.0 5 votes vote down vote up
void fillPolygon(DPolygon polygon,Color c){
Path2D path=new Path2D.Double();
int s=polygon.size();
DPoint p=polygon.get(0);
path.moveTo(p.x,p.y);
for(int i=1;i<s;i++){
  p=polygon.get(i);
  path.lineTo(p.x,p.y);}
path.closePath();
graphics.setPaint(c);
graphics.fill(path); }
 
Example 12
Source File: VisualQueueComponent.java    From workcraft with MIT License 5 votes vote down vote up
public Shape getSlotShape(int index) {
    Path2D shape = new Path2D.Double();
    if (isInitialised()) {
        double w2 = 0.5 * SLOT_WIDTH;
        double h2 = 0.5 * SLOT_HEIGHT;
        double slotOffset = getSlotOffset(index);
        shape.moveTo(slotOffset - w2, -h2);
        shape.lineTo(slotOffset - w2, +h2);
        shape.lineTo(slotOffset + w2, +h2);
        shape.lineTo(slotOffset + w2, -h2);
        shape.closePath();
    }
    return shape;
}
 
Example 13
Source File: EmptyCapacity.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    final Path2D path1 = new Path2D.Double(Path2D.WIND_EVEN_ODD, 0);
    path1.moveTo(10, 10);
    path1.lineTo(20, 20);
    final Path2D path2 = new Path2D.Float(Path2D.WIND_EVEN_ODD, 0);
    path2.moveTo(10, 10);
    path2.lineTo(20, 20);
}
 
Example 14
Source File: StemsBuilder.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Define the lookup area on given corner, knowing the reference point of the
 * entity (head).
 * Global slope is used (plus and minus slopeMargin).
 *
 * @return the lookup area
 */
private Area getLuArea ()
{
    final double slope = skew.getSlope();
    final double dSlope = -xDir * yDir * params.slopeMargin;

    final Point2D outPt = getOutPoint();
    final Point2D inPt = getInPoint();

    // Look Up path, start by head horizontal segment
    final Path2D lu = new Path2D.Double();
    lu.moveTo(outPt.getX(), outPt.getY());
    lu.lineTo(inPt.getX(), inPt.getY());

    // Then segment away from head (system limit)
    final Rectangle systemBox = system.getBounds();
    final double yLimit = (yDir > 0) ? systemBox.getMaxY() : systemBox.getMinY();
    final double dy = yLimit - outPt.getY();
    lu.lineTo(inPt.getX() + ((slope + dSlope) * dy), yLimit);
    lu.lineTo(outPt.getX() + ((slope - dSlope) * dy), yLimit);
    lu.closePath();

    // Attachment
    StringBuilder sb = new StringBuilder();
    sb.append((corner.vSide == TOP) ? "T" : "B");
    sb.append((corner.hSide == LEFT) ? "L" : "R");
    head.addAttachment(sb.toString(), lu);

    return new Area(lu);
}
 
Example 15
Source File: CorrectedCountsDataViewForShrimp.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param g2d
 */
@Override
public void paint(Graphics2D g2d) {
    super.paint(g2d);

    Path2D pointTrace = new Path2D.Double(Path2D.WIND_NON_ZERO);
    pointTrace.moveTo(mapX(myOnPeakNormalizedAquireTimes[0]), mapY(myOnPeakData[0]));
    for (int i = 0; i < myOnPeakData.length; i++) {
        // line tracing through points
        pointTrace.lineTo(mapX(myOnPeakNormalizedAquireTimes[i]), mapY(myOnPeakData[i]));
        g2d.setStroke(new BasicStroke(0.5f));
        g2d.setPaint(determineDataColor(i, Color.GRAY));
        g2d.draw(pointTrace);

        Shape intensity = new java.awt.geom.Ellipse2D.Double( //
                mapX(myOnPeakNormalizedAquireTimes[i]) - 1, mapY(myOnPeakData[i]) - 1, 2, 2);
        g2d.setStroke(new BasicStroke(1.5f));
        g2d.setPaint(determineDataColor(i, Color.black));
        g2d.draw(intensity);

        // uncertainty
        Shape plusMinusOneSigma = new Line2D.Double(//
                mapX(myOnPeakNormalizedAquireTimes[i]),// 
                mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]),//
                mapX(myOnPeakNormalizedAquireTimes[i]),// 
                mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]));
        g2d.setStroke(new BasicStroke(1.0f));
        g2d.draw(plusMinusOneSigma);

        // tips of uncertainty
        Shape plusOneSigmaTip = new Line2D.Double(//
                mapX(myOnPeakNormalizedAquireTimes[i]) - 1,// 
                mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]),//
                mapX(myOnPeakNormalizedAquireTimes[i]) + 1,// 
                mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]));

        Shape minusOneSigmaTip = new Line2D.Double(//
                mapX(myOnPeakNormalizedAquireTimes[i]) - 1,// 
                mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]),//
                mapX(myOnPeakNormalizedAquireTimes[i]) + 1,// 
                mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]));

        g2d.setStroke(new BasicStroke(1.0f));
        g2d.draw(plusOneSigmaTip);
        g2d.draw(minusOneSigmaTip);

    }
}
 
Example 16
Source File: WorldMapPanelWrapper.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
public void highlightPolygons(Path2D.Double[] polygonPaths) {
    this.polygonsLayerModel.highlightPolygons(polygonPaths);
    if (this.currentWorldMap != null) {
        this.currentWorldMap.refresh();
    }
}
 
Example 17
Source File: ProductLibraryToolViewV2.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void leftMouseButtonClicked(List<Path2D.Double> polygonPaths) {
    this.repositoryOutputProductListPanel.getProductListPanel().selectProductsByPolygonPath(polygonPaths);
}
 
Example 18
Source File: Java2D.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
     * Merges a sequence of points or paths if the first instance is an implementation of this library.
     *
     * @throws ClassCastException if an element in the iterator is not a {@link Shape} or a {@link Point2D}.
     */
    @Override
    final Shape tryMergePolylines(Object next, final Iterator<?> polylines) {
        if (!(next instanceof Shape || next instanceof Point2D)) {
            return null;
        }
        boolean isFloat = ShapeUtilities.isFloat(next);
        Path2D path = isFloat ? new Path2D.Float() : new Path2D.Double();
        boolean lineTo = false;
add:    for (;;) {
            if (next instanceof Point2D) {
                final double x = ((Point2D) next).getX();
                final double y = ((Point2D) next).getY();
                if (Double.isNaN(x) || Double.isNaN(y)) {
                    lineTo = false;
                } else if (lineTo) {
                    path.lineTo(x, y);
                } else {
                    path.moveTo(x, y);
                    lineTo = true;
                }
            } else {
                path.append((Shape) next, false);
                lineTo = false;
            }
            /*
             * 'polylines.hasNext()' check is conceptually part of 'for' instruction,
             * except that we need to skip this condition during the first iteration.
             */
            do if (!polylines.hasNext()) break add;
            while ((next = polylines.next()) == null);
            /*
             * Convert the path from single-precision to double-precision if needed.
             */
            if (isFloat && !ShapeUtilities.isFloat(next)) {
                path = new Path2D.Double(path);
                isFloat = false;
            }
        }
        return ShapeUtilities.toPrimitive(path);
    }
 
Example 19
Source File: ConcordiaLine.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param aspectRatio
 * @param minX
 * @param minY
 * @param maxX
 * @param maxY
 */
public void calcLowerUnctEnvelopeC(double aspectRatio, double minX, double minY, double maxX, double maxY) {

    // parameters represent viewport
    constructLowerEnvelopeAtRightEnd(endSeg, aspectRatio, minX, minY, maxX, maxY);
    constructLowerEnvelopeAtLeftEnd(startSeg, aspectRatio, minX, minY, maxX, maxY);

    lowerUnctEnvelope = new Path2D.Double (Path2D.WIND_NON_ZERO);

    // start at top right of concordia
    lowerUnctEnvelope.moveTo(
            (float) mapX(endSeg.maxX()),
            (float) mapY(endSeg.maxY()));

    ParametricCurveSegmentI myWorkingSeg = startLowerUncertSeg;

    // decide whether to include upper right corner of viewport
    if (myWorkingSeg != null) {
        if (myWorkingSeg.maxPlusSigmaY(aspectRatio) < endSeg.maxY()) {
            lowerUnctEnvelope.lineTo(
                    (float) mapX(maxX),
                    (float) mapY(maxY));
        }
    } else {
        // paint the lower right corner
        lowerUnctEnvelope.lineTo(
                (float) mapX(maxX),
                (float) mapY(minY));
    }

    while (myWorkingSeg != null) {
        // check for out of bounds
        double tempX = myWorkingSeg.maxPlusSigmaX(aspectRatio);
        double tempY = myWorkingSeg.maxPlusSigmaY(aspectRatio);
        double tempXc = myWorkingSeg.controlLowerX(aspectRatio);
        double tempYc = myWorkingSeg.controlLowerY(aspectRatio);
        double tempXl = myWorkingSeg.minPlusSigmaX(aspectRatio);
        double tempYl = myWorkingSeg.minPlusSigmaY(aspectRatio);

        lowerUnctEnvelope.lineTo(
                (float) mapX(tempX),
                (float) mapY(tempY));

        if (pointInViewPort(tempX, tempY, minX, minY, maxX, maxY) //
                ||//
                ((determineAxisIntersectedByLowerEnvelopeRight(maxX, maxY, tempXl, tempYl, tempX, tempY) == 1) //
                && pointInViewPort(tempXl, tempYl, minX, minY, maxX, maxY))) {

            lowerUnctEnvelope.curveTo(//
                    (float) mapX(tempX),
                    (float) mapY(tempY),
                    (float) mapX(tempXc),
                    (float) mapY(tempYc),
                    (float) mapX(tempXl),
                    (float) mapY(tempYl));
        } else if ((tempX < maxX) && (tempY < maxY) && !pointInViewPort(tempX, tempY, minX, minY, maxX, maxY)//
                && (!pointInViewPort(tempXl, tempYl, minX, minY, maxX, maxY))) { //
            if (determineAxisIntersectedByConcordiaLeft(minX, minY) == -1) {
                lowerUnctEnvelope.lineTo(
                        (float) mapX(tempXl),
                        (float) mapY(tempYl));
            }
            lowerUnctEnvelope.lineTo(
                    (float) mapX(minX),
                    (float) mapY(minY));
            // get rid of the rest
            while (myWorkingSeg.getLeftSeg() != null) {
                myWorkingSeg = myWorkingSeg.getLeftSeg();
            }
        }
        myWorkingSeg = myWorkingSeg.getLeftSeg();
    }
}
 
Example 20
Source File: SLGraphics.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Fills the interior of a <code>Shape</code> using the settings of the
 * <code>Graphics2D</code> context. The rendering attributes applied
 * include the <code>Clip</code>, <code>Transform</code>,
 * <code>Paint</code>, and <code>Composite</code>.
 * @param shape the <code>Shape</code> to be filled
 * @see #setPaint
 * @see java.awt.Graphics#setColor
 * @see #_transform
 * @see #setTransform
 * @see #setComposite
 * @see #clip
 * @see #setClip
 */
public void fill(Shape shape){
    Path2D.Double path = new Path2D.Double(_transform.createTransformedShape(shape));
    FreeformShape<?,?> p = _group.createFreeform();
    p.setPath(path);
    applyPaint(p);
    p.setStrokeStyle();   //Fills must be "No Line"
}