Java Code Examples for java.awt.geom.Path2D#reset()

The following examples show how to use java.awt.geom.Path2D#reset() . 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: ContainedAssociates.java    From MesquiteCore with GNU Lesser General Public License v3.0 7 votes vote down vote up
private void UPdefinePoly(int node, Path2D poly, boolean internalNode, double Nx, double Ny, double mNx, double mNy) {
	if (poly!=null) {
		poly.reset();
		if (internalNode&& false) 
		{
			poly.moveTo(Nx, Ny);
			poly.lineTo(Nx+branchEdgeWidth(node)/2, Ny-branchEdgeWidth(node)/2);
			poly.lineTo(Nx+branchEdgeWidth(node), Ny);
			poly.lineTo(mNx+branchEdgeWidth(node), mNy);
			poly.lineTo(mNx, mNy);
			poly.lineTo(Nx, Ny);
		}
		else
		{
			poly.moveTo(Nx, Ny);
			poly.lineTo(Nx+branchEdgeWidth(node), Ny);
			poly.lineTo(mNx+branchEdgeWidth(node), mNy);
			poly.lineTo(mNx, mNy);
			poly.lineTo(Nx, Ny);
		}
	}
}
 
Example 2
Source File: ReorderbleList.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseDragged(MouseEvent e) {
  JList<?> l = (JList<?>) e.getComponent();
  if (l.getDragEnabled()) {
    return;
  }
  Point destPoint = e.getPoint();
  Path2D rb = getRubberBand();
  rb.reset();
  rb.moveTo(srcPoint.x, srcPoint.y);
  rb.lineTo(destPoint.x, srcPoint.y);
  rb.lineTo(destPoint.x, destPoint.y);
  rb.lineTo(srcPoint.x, destPoint.y);
  rb.closePath();

  // JDK 1.7.0: l.setSelectedIndices(getIntersectsIcons(l, rubberBand));
  int[] indices = IntStream.range(0, l.getModel().getSize())
      .filter(i -> rb.intersects(l.getCellBounds(i, i))).toArray();
  l.setSelectedIndices(indices);
  l.repaint();
}
 
Example 3
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseDragged(MouseEvent e) {
  JList<?> l = (JList<?>) e.getComponent();
  if (l.getDragEnabled()) {
    return;
  }
  Point destPoint = e.getPoint();
  Path2D rb = getRubberBand();
  rb.reset();
  rb.moveTo(srcPoint.x, srcPoint.y);
  rb.lineTo(destPoint.x, srcPoint.y);
  rb.lineTo(destPoint.x, destPoint.y);
  rb.lineTo(srcPoint.x, destPoint.y);
  rb.closePath();

  // JDK 1.7.0: l.setSelectedIndices(getIntersectsIcons(l, rubberBand));
  int[] indices = IntStream.range(0, l.getModel().getSize())
      .filter(i -> rb.intersects(l.getCellBounds(i, i))).toArray();
  l.setSelectedIndices(indices);
  l.repaint();
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseDragged(MouseEvent e) {
  JList<?> l = (JList<?>) e.getComponent();
  l.setFocusable(true);
  Point destPoint = e.getPoint();
  Path2D rb = getRubberBand();
  rb.reset();
  rb.moveTo(srcPoint.x, srcPoint.y);
  rb.lineTo(destPoint.x, srcPoint.y);
  rb.lineTo(destPoint.x, destPoint.y);
  rb.lineTo(srcPoint.x, destPoint.y);
  rb.closePath();

  // JDK 1.7.0: l.setSelectedIndices(getIntersectsIcons(l, rubberBand));
  int[] indices = IntStream.range(0, l.getModel().getSize())
      .filter(i -> rb.intersects(l.getCellBounds(i, i))).toArray();
  l.setSelectedIndices(indices);
  l.repaint();
}
 
Example 5
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseDragged(MouseEvent e) {
  JList<?> l = (JList<?>) e.getComponent();
  l.setFocusable(true);
  Point destPoint = e.getPoint();
  Path2D rb = getRubberBand();
  rb.reset();
  rb.moveTo(srcPoint.x, srcPoint.y);
  rb.lineTo(destPoint.x, srcPoint.y);
  rb.lineTo(destPoint.x, destPoint.y);
  rb.lineTo(srcPoint.x, destPoint.y);
  rb.closePath();

  int[] indices = IntStream.range(0, l.getModel().getSize())
      .filter(i -> rb.intersects(l.getCellBounds(i, i))).toArray();
  l.setSelectedIndices(indices);
  l.repaint();
}
 
Example 6
Source File: DiagonalDrawTree.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void LEFTCalcBranchPolys(Tree tree, int node, Path2D.Double[] polys, boolean isTouch)
{
	if (!tree.getAssociatedBit(triangleNameRef,node)) {
		for (int d = tree.firstDaughterOfNode(node); tree.nodeExists(d); d = tree.nextSisterOfNode(d))
			LEFTCalcBranchPolys(tree, d, polys, isTouch);
		LEFTdefinePoly(node, polys[node], isTouch, tree.nodeIsInternal(node),x[node],y[node], x[tree.motherOfNode(node)], y[tree.motherOfNode(node)]);
	}
	else {
		Path2D poly = polys[node];
		int mN = tree.motherOfNode(node);
		int leftN = tree.leftmostTerminalOfNode(node);
		int rightN = tree.rightmostTerminalOfNode(node);
		poly.reset();
		poly.moveTo(x[node], y[node]);
		poly.lineTo(x[leftN], y[leftN]);
		poly.lineTo(x[rightN], y[rightN]+branchEdgeWidth(node, isTouch));
		poly.lineTo(x[node], y[node]+branchEdgeWidth(node, isTouch));
		poly.lineTo(x[mN], y[mN]+branchEdgeWidth(node, isTouch));
		poly.lineTo(x[mN], y[mN]);
		poly.lineTo(x[node], y[node]);
	}
}
 
Example 7
Source File: GridOverlayPainter.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_jig.editedjig.getGraph().edges.iterator();
GEdge e;
double[] p0,p1;
Path2D path=new Path2D.Double();
while(i.hasNext()){
  e=i.next();
  p0=GE.ge.editor_jig.editedjig.getJigEditorGeometryCache().getPoint(e.v0.kvertex);
  p1=GE.ge.editor_jig.editedjig.getJigEditorGeometryCache().getPoint(e.v1.kvertex);
  path.reset();
  path.moveTo(p0[0],p0[1]);
  path.lineTo(p1[0],p1[1]);
  graphics.draw(path);}}
 
Example 8
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 9
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 10
Source File: ShapeUtilitiesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link ShapeUtilities#toPrimitive(Shape)}.
 */
@Test
public void testToPrimitive() {
    final Path2D path = new Path2D.Double();
    path.moveTo(4, 5);
    path.lineTo(7, 9);
    Shape p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", Line2D.class, p);
    assertEquals("P1", new Point2D.Double(4, 5), ((Line2D) p).getP1());
    assertEquals("P2", new Point2D.Double(7, 9), ((Line2D) p).getP2());

    path.reset();
    path.moveTo(4, 5);
    path.quadTo(6, 7, 8, 5);
    p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", QuadCurve2D.class, p);
    assertEquals("P1",     new Point2D.Double(4, 5), ((QuadCurve2D) p).getP1());
    assertEquals("CtrlPt", new Point2D.Double(6, 7), ((QuadCurve2D) p).getCtrlPt());
    assertEquals("P2",     new Point2D.Double(8, 5), ((QuadCurve2D) p).getP2());

    path.reset();
    path.moveTo(4, 5);
    path.curveTo(6, 7, 8, 6, 9, 4);
    p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", CubicCurve2D.class, p);
    assertEquals("P1",     new Point2D.Double(4, 5), ((CubicCurve2D) p).getP1());
    assertEquals("CtrlP1", new Point2D.Double(6, 7), ((CubicCurve2D) p).getCtrlP1());
    assertEquals("CtrlP2", new Point2D.Double(8, 6), ((CubicCurve2D) p).getCtrlP2());
    assertEquals("P2",     new Point2D.Double(9, 4), ((CubicCurve2D) p).getP2());
}
 
Example 11
Source File: VdPath.java    From SVG-Android with Apache License 2.0 4 votes vote down vote up
private void toPath(Path2D path) {
    path.reset();
    if (mNodeList != null) {
        VdNodeRender.createPath(mNodeList, path);
    }
}
 
Example 12
Source File: Ellipse.java    From mil-sym-java with Apache License 2.0 4 votes vote down vote up
@Override
public Shape createShape() {
	//GeoEllipse e = new GeoEllipse(pivot, radiusMeters * 2, radiusMeters * 2, maxDistanceMeters,
	//		flatnessDistanceMeters, limit);
	GeoEllipse e = new GeoEllipse(pivot, _semiMajor * 2, _semiMinor * 2, maxDistanceMeters,
			flatnessDistanceMeters, limit);
               
               float[] coords = new float[2];
               int type=0;
               POINT2 pt0=new POINT2(pivot.x,pivot.y),pt=null;
               POINT2 pt1=null;
               double R=0;
               ref<double[]> a12 = new ref(), a21 = new ref();
               double x=0,y=0,x1=0,y1=0;
               //test arbitray rotation angle                
               double rotation=_rotation;
               //navigation is clockwise from 0. 0 is true north
               rotation=90-rotation;
               if(rotation == 0 || _semiMajor==_semiMinor)
                   return e;                
               ArrayList<POINT2>pts=new ArrayList();
               for (PathIterator i = e.getPathIterator(null); !i.isDone(); i.next()) {
                   type = i.currentSegment(coords);
                   pt1=new POINT2(coords[0],coords[1]);
                   R=mdlGeodesic.geodesic_distance(pt0, pt1, a12, a21);
                   //x=R*Math.cos(a12.value[0]*Math.PI/180d);
                   //y=R*Math.sin(a12.value[0]*Math.PI/180d);                  
                   //rotate the points
                   //x1=x*Math.cos(rotation*Math.PI/180d)-y*Math.sin(rotation*Math.PI/180d);
                   //y1=x*Math.sin(rotation*Math.PI/180d)+y*Math.cos(rotation*Math.PI/180d);
                   pt=mdlGeodesic.geodesic_coordinate(pt0, R, a12.value[0]-rotation);
                   pts.add(pt);                    
               }
               //clear the path
               Path2D path=e.getPath();
               path.reset();
               //rebuild the path with the rotated points
               for(int j=0;j<pts.size();j++)
               {
                   x=pts.get(j).x;
                   y=pts.get(j).y;
                   if(j==0)
                       path.moveTo(x, y);
                   else
                       path.lineTo(x, y);
               }
	return e;
}
 
Example 13
Source File: Ellipse.java    From mil-sym-java with Apache License 2.0 4 votes vote down vote up
public ArrayList<GeoPoint>getEllipsePoints()
      {
GeoEllipse e = new GeoEllipse(pivot, _semiMajor * 2, _semiMinor * 2, maxDistanceMeters,
		flatnessDistanceMeters, limit);
              
              float[] coords = new float[2];
              int type=0;
              POINT2 pt0=new POINT2(pivot.x,pivot.y),pt=null;
              POINT2 pt1=null;
              double R=0;
              ref<double[]> a12 = new ref(), a21 = new ref();
              double x=0,y=0,x1=0,y1=0;
              //test arbitray rotation angle                
              double rotation=_rotation;
              //navigation is clockwise from 0. 0 is true north
              rotation=90-rotation;
              //if(rotation == 0 || _semiMajor==_semiMinor)
                  //return e;                
              ArrayList<GeoPoint>pts=new ArrayList();
              for (PathIterator i = e.getPathIterator(null); !i.isDone(); i.next()) {
                  type = i.currentSegment(coords);
                  pt1=new POINT2(coords[0],coords[1]);
                  R=mdlGeodesic.geodesic_distance(pt0, pt1, a12, a21);
                  //x=R*Math.cos(a12.value[0]*Math.PI/180d);
                  //y=R*Math.sin(a12.value[0]*Math.PI/180d);                  
                  //rotate the points
                  //x1=x*Math.cos(rotation*Math.PI/180d)-y*Math.sin(rotation*Math.PI/180d);
                  //y1=x*Math.sin(rotation*Math.PI/180d)+y*Math.cos(rotation*Math.PI/180d);
                  if(!(_semiMajor == _semiMinor))
                      pt=mdlGeodesic.geodesic_coordinate(pt0, R, a12.value[0]-rotation);
                  else
                      pt=pt1;
                  pts.add(new GeoPoint(pt.x,pt.y));                    
              }
              //clear the path
              Path2D path=e.getPath();
              path.reset();
              //rebuild the path with the rotated points
              for(int j=0;j<pts.size();j++)
              {
                  x=pts.get(j).x;
                  y=pts.get(j).y;
                  if(j==0)
                      path.moveTo(x, y);
                  else
                      path.lineTo(x, y);
              }
return pts;            
      }
 
Example 14
Source File: ContainedAssociates.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void UPdefineFillPoly(int node, Path2D poly, boolean internalNode, double Nx, double Ny, double mNx, double mNy, int sliceNumber, int numSlices) {
	if (poly!=null) {
		poly.reset();
		int sliceWidth=branchEdgeWidth(node);
		if (numSlices>1) {
			Nx+= (sliceNumber-1)*(branchEdgeWidth(node)-inset)/numSlices;
			mNx+= (sliceNumber-1)*(branchEdgeWidth(node)-inset)/numSlices;
			sliceWidth=(branchEdgeWidth(node)-inset)-((sliceNumber-1)*(branchEdgeWidth(node)-inset)/numSlices);
		}
		if ((internalNode) && (numSlices==1)){ 
			poly.moveTo(Nx+inset, Ny);
			poly.lineTo(Nx+sliceWidth/2, Ny-sliceWidth/2-inset);
			poly.lineTo(Nx+sliceWidth-inset, Ny);
			poly.lineTo(mNx+sliceWidth-inset, mNy);
			poly.lineTo(mNx+inset, mNy);
			poly.lineTo(Nx+inset, Ny);
		}
		else {
			if (Nx==mNx) {
				if ((internalNode) && (numSlices>1)) {
					Ny-=(branchEdgeWidth(node)-inset)/4;
				}
				poly.moveTo(Nx+inset, Ny+inset);
				poly.lineTo(Nx+sliceWidth-inset, Ny+inset);
				poly.lineTo(mNx+sliceWidth-inset, mNy);
				poly.lineTo(mNx+inset, mNy);
				poly.lineTo(Nx+inset, Ny+inset);
			}
			else if (Nx>mNx) {
				if ((internalNode) && (numSlices>1)) {
					Nx+=(branchEdgeWidth(node)-inset)/4;
					Ny-=(branchEdgeWidth(node)-inset)/4;
				}
				poly.moveTo(Nx, Ny+inset);
				poly.lineTo(Nx+sliceWidth-inset-inset, Ny+inset);
				poly.lineTo(mNx+sliceWidth-inset, mNy);
				poly.lineTo(mNx+inset, mNy);
				poly.lineTo(Nx, Ny+inset);
			}
			else if (Nx<mNx) {
				if ((internalNode) && (numSlices>1)) {
					Nx-=(branchEdgeWidth(node)-inset)/4;
					Ny-=(branchEdgeWidth(node)-inset)/4;
				}
				poly.moveTo(Nx+inset+inset, Ny+inset);
				poly.lineTo(Nx+sliceWidth, Ny+inset);
				poly.lineTo(mNx+sliceWidth-inset, mNy);
				poly.lineTo(mNx+inset, mNy);
				poly.lineTo(Nx+inset+inset, Ny+inset);
			}
		}
	}
}