java.awt.geom.Path2D#reset ( )源码实例Demo

下面列出了java.awt.geom.Path2D#reset ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: java-swing-tips   文件: ReorderbleList.java
@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();
}
 
源代码2 项目: java-swing-tips   文件: MainPanel.java
@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();
}
 
源代码3 项目: java-swing-tips   文件: MainPanel.java
@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();
}
 
源代码4 项目: java-swing-tips   文件: MainPanel.java
@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();
}
 
源代码5 项目: MesquiteCore   文件: ContainedAssociates.java
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);
		}
	}
}
 
源代码6 项目: MesquiteCore   文件: DiagonalDrawTree.java
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]);
	}
}
 
源代码7 项目: Forsythia   文件: GridOverlayPainter.java
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);}}
 
源代码8 项目: Forsythia   文件: EMGridOverlayPainter.java
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);}}
 
源代码9 项目: java-swing-tips   文件: MainPanel.java
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;
}
 
源代码10 项目: sis   文件: ShapeUtilitiesTest.java
/**
 * 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());
}
 
源代码11 项目: SVG-Android   文件: VdPath.java
private void toPath(Path2D path) {
    path.reset();
    if (mNodeList != null) {
        VdNodeRender.createPath(mNodeList, path);
    }
}
 
源代码12 项目: mil-sym-java   文件: Ellipse.java
@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;
}
 
源代码13 项目: mil-sym-java   文件: Ellipse.java
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;            
      }
 
源代码14 项目: MesquiteCore   文件: ContainedAssociates.java
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);
			}
		}
	}
}