本文整理汇总了Java中java.awt.geom.PathIterator.SEG_CLOSE属性的典型用法代码示例。如果您正苦于以下问题:Java PathIterator.SEG_CLOSE属性的具体用法?Java PathIterator.SEG_CLOSE怎么用?Java PathIterator.SEG_CLOSE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.geom.PathIterator
的用法示例。
在下文中一共展示了PathIterator.SEG_CLOSE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closePath
/**
* Delegates to the enclosed <code>GeneralPath</code>.
*/
public synchronized void closePath()
{
// Don't double close path.
if ((numSeg != 0) && (types[numSeg - 1] == PathIterator.SEG_CLOSE))
return;
// Only close path if the previous command wasn't a moveto
if ((numSeg != 0) && (types[numSeg - 1] != PathIterator.SEG_MOVETO))
path.closePath();
makeRoom(0);
types[numSeg++] = PathIterator.SEG_CLOSE;
cx = mx;
cy = my;
}
示例2: appendPath
private static StringBuilder appendPath(StringBuilder sb, int indent, PathIterator pathIterator) {
double[] coords = new double[6];
while (!pathIterator.isDone()) {
int type = pathIterator.currentSegment(coords);
String typeStr;
int endIndex;
switch (type) {
case PathIterator.SEG_CLOSE:
typeStr = "SEG_CLOSE";
endIndex = 0;
break;
case PathIterator.SEG_CUBICTO:
typeStr = "SEG_CUBICTO";
endIndex = 6;
break;
case PathIterator.SEG_LINETO:
typeStr = "SEG_LINETO";
endIndex = 2;
break;
case PathIterator.SEG_MOVETO:
typeStr = "SEG_MOVETO";
endIndex = 2;
break;
case PathIterator.SEG_QUADTO:
typeStr = "SEG_QUADTO";
endIndex = 4;
break;
default:
throw new IllegalStateException("Invalid type=" + type);
}
ArrayUtilities.appendSpaces(sb, indent);
sb.append(typeStr).append(": ");
for (int i = 0; i < endIndex;) {
sb.append("[").append(coords[i++]).append(",").append(coords[i++]).append("] ");
}
sb.append('\n');
pathIterator.next();
}
return sb;
}
示例3: feedConsumer
/**
* 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();
}
}
示例4: shapeToSVG
private static String shapeToSVG(Shape sh) {
StringBuffer s = new StringBuffer();
double[] pts = new double[6];
for (PathIterator p = sh.getPathIterator(null); !p.isDone(); p.next()) {
switch (p.currentSegment(pts)) {
case PathIterator.SEG_MOVETO:
s.append('M'); s.append(' ');
s.append(svgRound(pts[0])); s.append(' ');
s.append(svgRound(pts[1])); s.append(' ');
break;
case PathIterator.SEG_LINETO:
s.append('L'); s.append(' ');
s.append(svgRound(pts[0])); s.append(' ');
s.append(svgRound(pts[1])); s.append(' ');
break;
case PathIterator.SEG_QUADTO:
s.append('Q'); s.append(' ');
s.append(svgRound(pts[0])); s.append(' ');
s.append(svgRound(pts[1])); s.append(' ');
s.append(svgRound(pts[2])); s.append(' ');
s.append(svgRound(pts[3])); s.append(' ');
break;
case PathIterator.SEG_CUBICTO:
s.append('C'); s.append(' ');
s.append(svgRound(pts[0])); s.append(' ');
s.append(svgRound(pts[1])); s.append(' ');
s.append(svgRound(pts[2])); s.append(' ');
s.append(svgRound(pts[3])); s.append(' ');
s.append(svgRound(pts[4])); s.append(' ');
s.append(svgRound(pts[5])); s.append(' ');
break;
case PathIterator.SEG_CLOSE:
s.append('Z'); s.append(' ');
break;
}
}
return s.toString().trim();
}
示例5: createStrokedShape
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;
}
示例6: drawShape
/** Draws a shape. */
public OurPDFWriter drawShape(Shape shape, boolean fillOrNot) {
if (shape instanceof Polygon) {
Polygon obj = (Polygon)shape;
for(int i = 0; i < obj.npoints; i++) buf.writes(obj.xpoints[i]).writes(obj.ypoints[i]).write(i==0 ? "m\n" : "l\n");
buf.write("h\n");
} else {
double moveX = 0, moveY = 0, nowX = 0, nowY = 0, pt[] = new double[6];
for(PathIterator it = shape.getPathIterator(null); !it.isDone(); it.next()) switch(it.currentSegment(pt)) {
case PathIterator.SEG_MOVETO:
nowX = moveX = pt[0]; nowY = moveY = pt[1]; buf.writes(nowX).writes(nowY).write("m\n"); break;
case PathIterator.SEG_CLOSE:
nowX = moveX; nowY = moveY; buf.write("h\n"); break;
case PathIterator.SEG_LINETO:
nowX = pt[0]; nowY = pt[1]; buf.writes(nowX).writes(nowY).write("l\n"); break;
case PathIterator.SEG_CUBICTO:
nowX = pt[4]; nowY = pt[5];
buf.writes(pt[0]).writes(pt[1]).writes(pt[2]).writes(pt[3]).writes(nowX).writes(nowY).write("c\n"); break;
case PathIterator.SEG_QUADTO: // Convert quadratic bezier into cubic bezier using de Casteljau algorithm
double px = nowX + (pt[0] - nowX)*(2.0/3.0), qx = px + (pt[2] - nowX)/3.0;
double py = nowY + (pt[1] - nowY)*(2.0/3.0), qy = py + (pt[3] - nowY)/3.0;
nowX = pt[2]; nowY = pt[3];
buf.writes(px).writes(py).writes(qx).writes(qy).writes(nowX).writes(nowY).write("c\n"); break;
}
}
buf.write(fillOrNot ? "f\n" : "S\n");
return this;
}
示例7: addGeneralPath
private void addGeneralPath(GeneralPath path) {
PathIterator itr = path.getPathIterator(null, 0.1);
ArrayList<Point2D.Float> pathList = new ArrayList();
Point2D.Float pathStart = null, lastPoint = null;
boolean closed = false;
while (!itr.isDone()) {
float[] coords = new float[6];
int segtype = itr.currentSegment(coords);
switch (segtype) {
case PathIterator.SEG_MOVETO:
pathStart = new Point2D.Float(coords[0], coords[1]); // save start point
case PathIterator.SEG_LINETO:
case PathIterator.SEG_QUADTO:
case PathIterator.SEG_CUBICTO:
pathList.add((lastPoint = new Point2D.Float(coords[0], coords[1]))); // TODO store quads/cubes as well as linesSVG
break;
case PathIterator.SEG_CLOSE:
closed = true;
// if (pathStart != null) {
// pathList.add(pathStart);
// }
break;
default:
log.info("found other element " + segtype);
}
itr.next();
}
if (closed && lastPoint != null) {
pathList.remove(lastPoint);
}
if (pathList.size() > longestPath) {
ballPathSVG = pathList;
longestPath = ballPathSVG.size();
}
pathsSVG.add(pathList);
}
示例8: toSwtPath
/**
* 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: createStrokedShape
/**
* @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);
}
示例10: createStrokedShape
/**
* @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;
}
示例11: convertToWPath
/**
* Given a Java2D {@code PathIterator} instance,
* this method translates that into a Window's path
* in the printer device context.
*/
private void convertToWPath(PathIterator pathIter) {
float[] segment = new float[6];
int segmentType;
WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();
/* Map the PathIterator's fill rule into the Window's
* polygon fill rule.
*/
int polyFillRule;
if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
polyFillRule = WPrinterJob.POLYFILL_ALTERNATE;
} else {
polyFillRule = WPrinterJob.POLYFILL_WINDING;
}
wPrinterJob.setPolyFillMode(polyFillRule);
wPrinterJob.beginPath();
while (pathIter.isDone() == false) {
segmentType = pathIter.currentSegment(segment);
switch (segmentType) {
case PathIterator.SEG_MOVETO:
wPrinterJob.moveTo(segment[0], segment[1]);
break;
case PathIterator.SEG_LINETO:
wPrinterJob.lineTo(segment[0], segment[1]);
break;
/* Convert the quad path to a bezier.
*/
case PathIterator.SEG_QUADTO:
int lastX = wPrinterJob.getPenX();
int lastY = wPrinterJob.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;
wPrinterJob.polyBezierTo(c1x, c1y,
c2x, c2y,
segment[2], segment[3]);
break;
case PathIterator.SEG_CUBICTO:
wPrinterJob.polyBezierTo(segment[0], segment[1],
segment[2], segment[3],
segment[4], segment[5]);
break;
case PathIterator.SEG_CLOSE:
wPrinterJob.closeFigure();
break;
}
pathIter.next();
}
wPrinterJob.endPath();
}
示例12: currentSegment
public int currentSegment(float[] coords) {
int type = src.currentSegment(coords);
int lastCoord;
switch(type) {
case PathIterator.SEG_CUBICTO:
lastCoord = 4;
break;
case PathIterator.SEG_QUADTO:
lastCoord = 2;
break;
case PathIterator.SEG_LINETO:
case PathIterator.SEG_MOVETO:
lastCoord = 0;
break;
case PathIterator.SEG_CLOSE:
// we don't want to deal with this case later. We just exit now
curx_adjust = movx_adjust;
cury_adjust = movy_adjust;
return type;
default:
throw new InternalError("Unrecognized curve type");
}
// normalize endpoint
float x_adjust = (float)Math.floor(coords[lastCoord] + lval) +
rval - coords[lastCoord];
float y_adjust = (float)Math.floor(coords[lastCoord+1] + lval) +
rval - coords[lastCoord + 1];
coords[lastCoord ] += x_adjust;
coords[lastCoord + 1] += y_adjust;
// now that the end points are done, normalize the control points
switch(type) {
case PathIterator.SEG_CUBICTO:
coords[0] += curx_adjust;
coords[1] += cury_adjust;
coords[2] += x_adjust;
coords[3] += y_adjust;
break;
case PathIterator.SEG_QUADTO:
coords[0] += (curx_adjust + x_adjust) / 2;
coords[1] += (cury_adjust + y_adjust) / 2;
break;
case PathIterator.SEG_LINETO:
break;
case PathIterator.SEG_MOVETO:
movx_adjust = x_adjust;
movy_adjust = y_adjust;
break;
case PathIterator.SEG_CLOSE:
throw new InternalError("This should be handled earlier.");
}
curx_adjust = x_adjust;
cury_adjust = y_adjust;
return type;
}
示例13: append
/**
* Delegates to the enclosed <code>GeneralPath</code>.
*/
public void append(ExtendedPathIterator epi, boolean connect)
{
float[] vals = new float[7];
while (!epi.isDone())
{
Arrays.fill(vals, 0);
int type = epi.currentSegment(vals);
epi.next();
if (connect && (numVals != 0))
{
if (type == PathIterator.SEG_MOVETO)
{
float x = vals[0];
float y = vals[1];
if ((x != cx) || (y != cy))
{
// Change MOVETO to LINETO.
type = PathIterator.SEG_LINETO;
}
else
{
// Redundant segment (move to current loc) drop it...
if (epi.isDone())
break; // Nothing interesting
type = epi.currentSegment(vals);
epi.next();
}
}
connect = false;
}
switch (type)
{
case PathIterator.SEG_CLOSE:
closePath();
break;
case PathIterator.SEG_MOVETO:
moveTo(vals[0], vals[1]);
break;
case PathIterator.SEG_LINETO:
lineTo(vals[0], vals[1]);
break;
case PathIterator.SEG_QUADTO:
quadTo(vals[0], vals[1], vals[2], vals[3]);
break;
case PathIterator.SEG_CUBICTO:
curveTo(vals[0], vals[1], vals[2], vals[3], vals[4],
vals[5]);
break;
case ExtendedPathIterator.SEG_ARCTO:
arcTo(vals[0], vals[1], vals[2], (vals[3] != 0),
(vals[4] != 0), vals[5], vals[6]);
break;
}
}
}
示例14: append
/**
* 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: feedConsumer
private void feedConsumer(PathConsumer consumer, PathIterator pi) {
try {
consumer.beginPath();
boolean pathClosed = false;
float mx = 0.0f;
float my = 0.0f;
float point[] = new float[6];
while (!pi.isDone()) {
int type = pi.currentSegment(point);
if (pathClosed == true) {
pathClosed = false;
if (type != PathIterator.SEG_MOVETO) {
// Force current point back to last moveto point
consumer.beginSubpath(mx, my);
}
}
switch (type) {
case PathIterator.SEG_MOVETO:
mx = point[0];
my = point[1];
consumer.beginSubpath(point[0], point[1]);
break;
case PathIterator.SEG_LINETO:
consumer.appendLine(point[0], point[1]);
break;
case PathIterator.SEG_QUADTO:
consumer.appendQuadratic(point[0], point[1],
point[2], point[3]);
break;
case PathIterator.SEG_CUBICTO:
consumer.appendCubic(point[0], point[1],
point[2], point[3],
point[4], point[5]);
break;
case PathIterator.SEG_CLOSE:
consumer.closedSubpath();
pathClosed = true;
break;
}
pi.next();
}
consumer.endPath();
} catch (PathException e) {
throw new InternalError("Unable to Stroke shape ("+
e.getMessage()+")", e);
}
}