本文整理汇总了Java中java.awt.geom.PathIterator.isDone方法的典型用法代码示例。如果您正苦于以下问题:Java PathIterator.isDone方法的具体用法?Java PathIterator.isDone怎么用?Java PathIterator.isDone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.PathIterator
的用法示例。
在下文中一共展示了PathIterator.isDone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPolyCoords
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
/**
* Returns a string containing the coordinates for a given shape. This
* string is intended for use in an image map.
*
* @param shape the shape (<code>null</code> not permitted).
*
* @return The coordinates for a given shape as string.
*/
private String getPolyCoords(Shape shape) {
if (shape == null) {
throw new IllegalArgumentException("Null 'shape' argument.");
}
StringBuffer result = new StringBuffer();
boolean first = true;
float[] coords = new float[6];
PathIterator pi = shape.getPathIterator(null, 1.0);
while (!pi.isDone()) {
pi.currentSegment(coords);
if (first) {
first = false;
result.append((int) coords[0]);
result.append(",").append((int) coords[1]);
}
else {
result.append(",");
result.append((int) coords[0]);
result.append(",");
result.append((int) coords[1]);
}
pi.next();
}
return result.toString();
}
示例2: checkEmptyPath
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
private static void checkEmptyPath(final Shape s) {
final float[] coords = new float[6];
final PathIterator it = s.getPathIterator(null);
int n = 0;
for (; !it.isDone(); it.next()) {
int type = it.currentSegment(coords);
System.out.println("unexpected segment type= " + type
+ " with coords: " + Arrays.toString(coords));
n++;
}
if (n != 0) {
System.out.println("path elements = " + n);
throw new IllegalStateException("Not empty path: "
+ n + " path elements !");
}
}
示例3: mapShape
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
public Shape mapShape(Shape s) {
if (LOGMAP) LOG.format("mapshape on path: %s\n", LayoutPathImpl.SegmentPath.this);
PathIterator pi = s.getPathIterator(null, 1); // cheap way to handle curves.
if (LOGMAP) LOG.format("start\n");
init();
final double[] coords = new double[2];
while (!pi.isDone()) {
switch (pi.currentSegment(coords)) {
case SEG_CLOSE: close(); break;
case SEG_MOVETO: moveTo(coords[0], coords[1]); break;
case SEG_LINETO: lineTo(coords[0], coords[1]); break;
default: break;
}
pi.next();
}
if (LOGMAP) LOG.format("finish\n\n");
GeneralPath gp = new GeneralPath();
for (Segment seg: segments) {
gp.append(seg.gp, false);
}
return gp;
}
示例4: appendPath
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
public void appendPath(PathIterator pi) {
float coords[] = new float[6];
setRule(pi.getWindingRule());
while (!pi.isDone()) {
addSegment(pi.currentSegment(coords), coords);
pi.next();
}
pathDone();
}
示例5: setCurrentSegment
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
protected void setCurrentSegment(GeneralPath path) {
if (currentSegment != null)
trackLayer.removeRenderable( currentSegment );
if (path == null)
{
currentSegment = null;
return;
}
PathIterator pi =
path.getPathIterator(new AffineTransform());
List<LatLon> pos = new LinkedList<LatLon>();
float [] coords = new float[6];
int t = pi.currentSegment(coords);
pos.add( LatLon.fromDegrees(coords[1], coords[0]));
while (!pi.isDone())
{
t = pi.currentSegment(coords);
if (t == PathIterator.SEG_LINETO &&
!(coords[1] == 0 && coords[0]==0))
pos.add( LatLon.fromDegrees(coords[1], coords[0]));
pi.next();
}
Polyline line = new Polyline(pos, 0);
line.setLineWidth(4);
line.setFollowTerrain(true);
line.setColor( Color.red );
trackLayer.addRenderable(line);
currentSegment = line;
}
示例6: feedConsumer
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
/**
* Utility method to feed a {@link PathConsumer2D} object from a
* given {@link PathIterator}.
* This method deals with the details of running the iterator and
* feeding the consumer a segment at a time.
*/
public static void feedConsumer(PathIterator pi, PathConsumer2D consumer) {
float coords[] = new float[6];
while (!pi.isDone()) {
switch (pi.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
consumer.moveTo(coords[0], coords[1]);
break;
case PathIterator.SEG_LINETO:
consumer.lineTo(coords[0], coords[1]);
break;
case PathIterator.SEG_QUADTO:
consumer.quadTo(coords[0], coords[1],
coords[2], coords[3]);
break;
case PathIterator.SEG_CUBICTO:
consumer.curveTo(coords[0], coords[1],
coords[2], coords[3],
coords[4], coords[5]);
break;
case PathIterator.SEG_CLOSE:
consumer.closePath();
break;
}
pi.next();
}
}
示例7: getType
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
public String getType() {
final StringBuilder buffer = new StringBuilder();
if (shape != null) {
final PathIterator it = shape.getPathIterator(new AffineTransform());
final float[] pts = new float[6];
while (!it.isDone()) {
switch (it.currentSegment(pts)) {
case PathIterator.SEG_MOVETO:
buffer.append('m')
.append(',')
.append(Math.round(pts[0]))
.append(',')
.append(Math.round(pts[1]));
break;
case PathIterator.SEG_LINETO:
case PathIterator.SEG_CUBICTO:
case PathIterator.SEG_QUADTO:
buffer.append('l')
.append(',')
.append(Math.round(pts[0]))
.append(',')
.append(Math.round(pts[1]));
break;
case PathIterator.SEG_CLOSE:
buffer.append('c');
break;
}
it.next();
if (!it.isDone()) {
buffer.append(',');
}
}
}
return ID + buffer.toString();
}
示例8: toSwtPath
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
/**
* Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
*
* @param shape the shape.
*
* @return The path.
*/
private Path toSwtPath(Shape shape) {
int type;
float[] coords = new float[6];
Path path = new Path(this.gc.getDevice());
PathIterator pit = shape.getPathIterator(null);
while (!pit.isDone()) {
type = pit.currentSegment(coords);
switch (type) {
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.cubicTo(coords[0], coords[1], coords[2],
coords[3], coords[4], coords[5]);
break;
case (PathIterator.SEG_CLOSE):
path.close();
break;
default:
break;
}
pit.next();
}
return path;
}
示例9: testEqual
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
static void testEqual(Path2D pathA, Path2D pathB) {
final PathIterator itA = pathA.getPathIterator(null);
final PathIterator itB = pathB.getPathIterator(null);
float[] coordsA = new float[6];
float[] coordsB = new float[6];
int n = 0;
for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
int typeA = itA.currentSegment(coordsA);
int typeB = itB.currentSegment(coordsB);
if (typeA != typeB) {
throw new IllegalStateException("Path-segment[" + n + "] "
+ " type are not equals [" + typeA + "|" + typeB + "] !");
}
if (!equalsArray(coordsA, coordsB, getLength(typeA))) {
throw new IllegalStateException("Path-segment[" + n + "] coords"
+ " are not equals [" + Arrays.toString(coordsA) + "|"
+ Arrays.toString(coordsB) + "] !");
}
}
if (!itA.isDone() || !itB.isDone()) {
throw new IllegalStateException("Paths do not have same lengths !");
}
log("testEqual: " + n + " segments.");
}
示例10: createStrokedShape
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
public Shape createStrokedShape(Shape shape) {
// We are flattening the path iterator to only get line segments.
PathIterator path = shape.getPathIterator(null, 1);
float points[] = new float[6];
GeneralPath strokepath = new GeneralPath();
float ix = 0, iy = 0;
float px = 0, py = 0;
while (!path.isDone()) {
int type = path.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
ix = px = points[0];
iy = py = points[1];
strokepath.moveTo(ix, iy);
break;
case PathIterator.SEG_LINETO:
strokepath.append(createArrow(px, py, points[0], points[1]),
false);
px = points[0];
py = points[1];
break;
case PathIterator.SEG_CLOSE:
if (px != ix && py != ix)
strokepath.append(createArrow(px, py, ix, iy), false);
break;
default:
strokepath.append(createArrow(px, py, points[0], points[1]),
false);
px = points[0];
py = points[1];
// never appear.
}
path.next();
}
return strokepath;
}
示例11: createStrokedShape
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
/**
* @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
*/
public Shape createStrokedShape (Shape shape) {
GeneralPath result = new GeneralPath();
PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
float points[] = new float[6];
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX = 0, thisY = 0;
int type = 0;
float next = 0;
int phase = 0;
while (!it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
moveX = lastX = points[0];
moveY = lastY = points[1];
result.moveTo(moveX, moveY);
next = wavelength / 2;
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = points[0];
thisY = points[1];
float dx = thisX - lastX;
float dy = thisY - lastY;
float distance = (float)Math.sqrt(dx * dx + dy * dy);
if (distance >= next) {
float r = 1.0f / distance;
while (distance >= next) {
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
if ((phase & 1) == 0)
result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r);
else
result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r);
next += wavelength;
phase++;
}
}
next -= distance;
lastX = thisX;
lastY = thisY;
if (type == PathIterator.SEG_CLOSE) result.closePath();
break;
}
it.next();
}
return new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(result);
}
示例12: createStrokedShape
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
/**
* @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
*/
public Shape createStrokedShape (Shape shape) {
GeneralPath result = new GeneralPath();
shape = new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(shape);
PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
float points[] = new float[6];
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX = 0, thisY = 0;
int type = 0;
float next = 0;
while (!it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
moveX = lastX = randomize(points[0]);
moveY = lastY = randomize(points[1]);
result.moveTo(moveX, moveY);
next = 0;
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = randomize(points[0]);
thisY = randomize(points[1]);
float dx = thisX - lastX;
float dy = thisY - lastY;
float distance = (float)Math.sqrt(dx * dx + dy * dy);
if (distance >= next) {
float r = 1.0f / distance;
while (distance >= next) {
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
result.lineTo(randomize(x), randomize(y));
next += detail;
}
}
next -= distance;
lastX = thisX;
lastY = thisY;
break;
}
it.next();
}
return result;
}
示例13: update
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
@Override
public void update() {
if (!this.isNavigating()) {
return;
}
if (this.path == null) {
return;
}
for (final Predicate<IMovableEntity> pred : this.cancelNavigationConditions) {
if (pred.test(this.getEntity())) {
this.stop();
return;
}
}
final PathIterator pi = this.path.getPath().getPathIterator(null);
if (pi.isDone()) {
this.stop();
return;
}
// although at max 6 elements are returned, sometimes the path
// implementation tries to access index 20 ... don't know why, but this
// prevents it
final double[] startCoordinates = new double[22];
final double[] coordinates = new double[22];
for (int i = 0; i <= this.currentSegment; i++) {
if (pi.isDone()) {
this.stop();
return;
}
pi.currentSegment(startCoordinates);
pi.next();
}
if (pi.isDone()) {
this.stop();
return;
}
pi.currentSegment(coordinates);
final double distance = GeometricUtilities.distance(this.entity.getCollisionBox().getCenterX(), this.entity.getCollisionBox().getCenterY(), coordinates[0], coordinates[1]);
if (distance < ACCEPTABLE_ERROR) {
++this.currentSegment;
return;
}
final double angle = GeometricUtilities.calcRotationAngleInDegrees(this.entity.getCollisionBox().getCenterX(), this.entity.getCollisionBox().getCenterY(), coordinates[0], coordinates[1]);
final float pixelsPerTick = Game.getLoop().getDeltaTime() * 0.001f * this.entity.getVelocity() * Game.getLoop().getTimeScale();
Game.getPhysicsEngine().move(this.entity, (float) angle, (float) (distance < pixelsPerTick ? distance : pixelsPerTick));
}
示例14: append
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
/**
* Delegates to the enclosed <code>GeneralPath</code>.
*/
public void append(PathIterator pi, boolean connect)
{
double[] vals = new double[6];
while (!pi.isDone())
{
Arrays.fill(vals, 0);
int type = pi.currentSegment(vals);
pi.next();
if (connect && (numVals != 0))
{
if (type == PathIterator.SEG_MOVETO)
{
double x = vals[0];
double y = vals[1];
if ((x != cx) || (y != cy))
{
// Change MOVETO to LINETO.
type = PathIterator.SEG_LINETO;
}
else
{
// Redundent segment (move to current loc) drop it...
if (pi.isDone())
break; // Nothing interesting
type = pi.currentSegment(vals);
pi.next();
}
}
connect = false;
}
switch (type)
{
case PathIterator.SEG_CLOSE:
closePath();
break;
case PathIterator.SEG_MOVETO:
moveTo((float) vals[0], (float) vals[1]);
break;
case PathIterator.SEG_LINETO:
lineTo((float) vals[0], (float) vals[1]);
break;
case PathIterator.SEG_QUADTO:
quadTo((float) vals[0], (float) vals[1], (float) vals[2],
(float) vals[3]);
break;
case PathIterator.SEG_CUBICTO:
curveTo((float) vals[0], (float) vals[1], (float) vals[2],
(float) vals[3], (float) vals[4], (float) vals[5]);
break;
}
}
}
示例15: convertToPSPath
import java.awt.geom.PathIterator; //导入方法依赖的package包/类
/**
* Given a Java2D <code>PathIterator</code> instance,
* this method translates that into a PostScript path..
*/
void convertToPSPath(PathIterator pathIter) {
float[] segment = new float[6];
int segmentType;
/* Map the PathIterator's fill rule into the PostScript
* fill rule.
*/
int fillRule;
if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
fillRule = FILL_EVEN_ODD;
} else {
fillRule = FILL_WINDING;
}
beginPath();
setFillMode(fillRule);
while (pathIter.isDone() == false) {
segmentType = pathIter.currentSegment(segment);
switch (segmentType) {
case PathIterator.SEG_MOVETO:
moveTo(segment[0], segment[1]);
break;
case PathIterator.SEG_LINETO:
lineTo(segment[0], segment[1]);
break;
/* Convert the quad path to a bezier.
*/
case PathIterator.SEG_QUADTO:
float lastX = getPenX();
float lastY = getPenY();
float c1x = lastX + (segment[0] - lastX) * 2 / 3;
float c1y = lastY + (segment[1] - lastY) * 2 / 3;
float c2x = segment[2] - (segment[2] - segment[0]) * 2/ 3;
float c2y = segment[3] - (segment[3] - segment[1]) * 2/ 3;
bezierTo(c1x, c1y,
c2x, c2y,
segment[2], segment[3]);
break;
case PathIterator.SEG_CUBICTO:
bezierTo(segment[0], segment[1],
segment[2], segment[3],
segment[4], segment[5]);
break;
case PathIterator.SEG_CLOSE:
closeSubpath();
break;
}
pathIter.next();
}
}