本文整理汇总了Java中java.awt.geom.GeneralPath类的典型用法代码示例。如果您正苦于以下问题:Java GeneralPath类的具体用法?Java GeneralPath怎么用?Java GeneralPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GeneralPath类属于java.awt.geom包,在下文中一共展示了GeneralPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConnectionSpline
import java.awt.geom.GeneralPath; //导入依赖的package包/类
/**
* Creates a spline connector shape from one {@link Point2D} to another.
*
* @param from
* the starting point
* @param to
* the end point
* @return the shape representing the connection, never {@code null}
*/
public static Shape createConnectionSpline(final Point2D from, final Point2D to) {
if (from == null || to == null) {
throw new IllegalArgumentException("from and to must not be null!");
}
int delta = 10;
GeneralPath connector = new GeneralPath();
connector.moveTo(from.getX() + 1, from.getY());
double cx = (from.getX() + to.getX()) / 2;
double cy = (from.getY() + to.getY()) / 2;
if (to.getX() >= from.getX() + 2 * delta) {
connector.curveTo(cx, from.getY(), cx, from.getY(), cx, cy);
connector.curveTo(cx, to.getY(), cx, to.getY(), to.getX() - 1, to.getY());
} else {
connector.curveTo(from.getX() + delta, from.getY(), from.getX() + delta, cy, cx, cy);
connector.curveTo(to.getX() - delta, cy, to.getX() - delta, to.getY(), to.getX() - 1, to.getY());
}
return connector;
}
示例2: paintComponent
import java.awt.geom.GeneralPath; //导入依赖的package包/类
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
GeneralPath arrow = new GeneralPath();
int w, h;
h = (int) (2 * sizeFactor);
w = (int) (4 * sizeFactor);
arrow.moveTo(getWidth() / 2 - w, getHeight() / 2);
arrow.lineTo(getWidth() / 2 + w, getHeight() / 2);
arrow.lineTo(getWidth() / 2, getHeight() / 2 + 2 * h);
arrow.closePath();
if (isEnabled()) {
g.setColor(Color.BLACK);
} else {
g.setColor(Color.GRAY);
}
((Graphics2D) g).fill(arrow);
}
示例3: createHexagonShape
import java.awt.geom.GeneralPath; //导入依赖的package包/类
/** Creates a hexagonal shape inscribed in the bounds given in the parameters. */
private Shape createHexagonShape(double x, double y, double width, double height) {
GeneralPath result = new GeneralPath(Path2D.WIND_NON_ZERO, 5);
double extend = height * NodeShape.HEX_EXTEND_RATIO;
// stat at top left corner
result.moveTo(x + extend, y);
// to top right
result.lineTo(x + width - extend, y);
// to right
result.lineTo(x + width, y + height / 2);
// to bottom right
result.lineTo(x + width - extend, y + height);
// to bottom left
result.lineTo(x + extend, y + height);
// to left
result.lineTo(x, y + height / 2);
result.closePath();
return result;
}
示例4: paintMatcher
import java.awt.geom.GeneralPath; //导入依赖的package包/类
private void paintMatcher(Graphics2D g, Color fillClr,
int leftX, int rightX, int upL, int upR, int doR, int doL) {
int topY = Math.min(upL, upR), bottomY = Math.max(doL, doR);
// try rendering only curves in viewable area
if (!g.hitClip(leftX, topY, rightX - leftX, bottomY - topY)) {
return;
}
CubicCurve2D upper = new CubicCurve2D.Float(leftX, upL,
(rightX -leftX)*.3f, upL,
(rightX -leftX)*.7f, upR,
rightX, upR);
CubicCurve2D bottom = new CubicCurve2D.Float(rightX, doR,
(rightX - leftX)*.7f, doR,
(rightX -leftX)*.3f, doL,
leftX, doL);
GeneralPath path = new GeneralPath();
path.append(upper, false);
path.append(bottom, true);
path.closePath();
g.setColor(fillClr);
g.fill(path);
g.setColor(master.getColorLines());
g.draw(upper);
g.draw(bottom);
}
示例5: mapShape
import java.awt.geom.GeneralPath; //导入依赖的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;
}
示例6: getCircleOfStars
import java.awt.geom.GeneralPath; //导入依赖的package包/类
/**
* Returns either a single star, or a circle of stars with the
* given radius, centered at the origin.
*
* @param radius The radius of the circle.
* @return The circle of stars.
*/
private GeneralPath getCircleOfStars(double radius) {
double phi = Math.PI * 2 / stars;
GeneralPath unionPath = new GeneralPath();
if (stars == 0) {
// nothing to do
} else if (stars == 1) {
// one double sized star
unionPath = getStar(2, 0, 0);
} else if (stars == 2) {
// two larger stars, on the x axis
unionPath.append(getStar(1.5, -radius, 0), false);
unionPath.append(getStar(1.5, radius, 0), false);
} else {
// a general circle of stars
for (int i = 0; i < stars; i++) {
double x = -radius - radius * Math.sin(i * phi);
double y = -radius * Math.cos(i * phi);
unionPath.append(getStar(x, y), false);
}
}
return unionPath;
}
示例7: getUnderlineShape
import java.awt.geom.GeneralPath; //导入依赖的package包/类
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
GeneralPath gp = new GeneralPath();
Line2D.Float line = new Line2D.Float(x1, y, x2, y);
gp.append(stroke.createStrokedShape(line), false);
line.y1 += DEFAULT_THICKNESS;
line.y2 += DEFAULT_THICKNESS;
line.x1 += DEFAULT_THICKNESS;
gp.append(stroke.createStrokedShape(line), false);
return gp;
}
示例8: polygon
import java.awt.geom.GeneralPath; //导入依赖的package包/类
/**
* Draws a polygon with the vertices
* (<em>x</em><sub>0</sub>, <em>y</em><sub>0</sub>),
* (<em>x</em><sub>1</sub>, <em>y</em><sub>1</sub>), ...,
* (<em>x</em><sub><em>n</em>–1</sub>, <em>y</em><sub><em>n</em>–1</sub>).
*
* @param x an array of all the <em>x</em>-coordinates of the polygon
* @param y an array of all the <em>y</em>-coordinates of the polygon
* @throws IllegalArgumentException unless {@code x[]} and {@code y[]}
* are of the same length
*/
public static void polygon(double[] x, double[] y) {
if (x == null) throw new IllegalArgumentException("x-coordinate array is null");
if (y == null) throw new IllegalArgumentException("y-coordinate array is null");
int n1 = x.length;
int n2 = y.length;
if (n1 != n2) throw new IllegalArgumentException("arrays must be of the same length");
int n = n1;
if (n == 0) return;
GeneralPath path = new GeneralPath();
path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0]));
for (int i = 0; i < n; i++)
path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i]));
path.closePath();
offscreen.draw(path);
draw();
}
示例9: drawPerSaltire
import java.awt.geom.GeneralPath; //导入依赖的package包/类
private void drawPerSaltire(Graphics2D g) {
int colors = backgroundColors.size();
GeneralPath path = new GeneralPath();
int[] x = { 0, WIDTH, WIDTH, 0 };
int[] y = { 0, 0, HEIGHT, HEIGHT };
double halfWidth = WIDTH / 2;
double halfHeight = HEIGHT / 2;
for (int index = 0; index < 4; index++) {
path.moveTo(x[index], y[index]);
path.lineTo(halfWidth, halfHeight);
int nextIndex = (index + 1) % 4;
path.lineTo(x[nextIndex], y[nextIndex]);
g.setColor(backgroundColors.get(index % colors));
g.fill(path);
path.reset();
}
}
示例10: getStar
import java.awt.geom.GeneralPath; //导入依赖的package包/类
/**
* Return the basic five-point star.
*
* @return the basic star shape
*/
private static GeneralPath getStar() {
GeneralPath star = new GeneralPath(GeneralPath.WIND_NON_ZERO);
double angle = 2 * Math.PI / 5;
double radius = STAR_SIZE / 2;
double x = 0;
double y = -radius;
star.moveTo(x, y);
int[] vertex = { 2, 4, 1, 3 };
for (int i : vertex) {
double phi = i * angle;
x = radius * Math.sin(phi);
y = -radius * Math.cos(phi);
star.lineTo(x, y);
}
star.closePath();
return star;
}
示例11: createDiamondShape
import java.awt.geom.GeneralPath; //导入依赖的package包/类
/** Creates a diamond shape inscribed in the bounds given in the parameters. */
private Shape createDiamondShape(double x, double y, double width, double height) {
GeneralPath result = new GeneralPath(Path2D.WIND_NON_ZERO, 5);
result.moveTo(x + width / 2, y);
result.lineTo(x + width, y + height / 2);
result.lineTo(x + width / 2, y + height);
result.lineTo(x, y + height / 2);
result.closePath();
return result;
}
示例12: getGlyphOutlineBounds
import java.awt.geom.GeneralPath; //导入依赖的package包/类
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
Rectangle2D result = null;
if (sgv.invdtx == null) {
result = new Rectangle2D.Float();
result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
} else {
GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
gp.transform(sgv.invdtx);
result = gp.getBounds2D();
}
/* Since x is the logical advance of the glyph to this point.
* Because of the way that Rectangle.union is specified, this
* means that subsequent unioning of a rect including that
* will be affected, even if the glyph is empty. So skip such
* cases. This alone isn't a complete solution since x==0
* may also not be what is wanted. The code that does the
* unioning also needs to be aware to ignore empty glyphs.
*/
if (!result.isEmpty()) {
result.setRect(result.getMinX() + x + dx,
result.getMinY() + y + dy,
result.getWidth(), result.getHeight());
}
return result;
}
示例13: paintYPin
import java.awt.geom.GeneralPath; //导入依赖的package包/类
private void paintYPin(Graphics2D g, int number) {
double y = top;
for (int i = 0; i < number; i++) {
y += yBounds[i].getSize().getHeight();
}
g.setColor(Color.black);
double max = 6;
g.setPaint(new GradientPaint(new Point2D.Double(LEFT - max, y - max),
Color.green, new Point2D.Double(LEFT + max, y + max),
Color.black));
GeneralPath path1 = new GeneralPath(Path2D.WIND_EVEN_ODD, 4);
GeneralPath path2 = new GeneralPath(Path2D.WIND_EVEN_ODD, 4);
path1.moveTo(LEFT - 5, y);
path1.lineTo(LEFT - 5 - max, y + max / 2);
path1.lineTo(LEFT - 5 - max, y - max / 2);
path1.lineTo(LEFT - 5, y);
path2.moveTo(5 + LEFT + width, y);
path2.lineTo(5 + LEFT + width + max, y + max / 2);
path2.lineTo(5 + LEFT + width + max, y - max / 2);
path2.lineTo(5 + LEFT + width, y);
g.fill(path1);
g.setPaint(new GradientPaint(new Point2D.Double(LEFT + width - max, y
- max), Color.black, new Point2D.Double(LEFT + max + width, y
+ max), Color.green));
g.fill(path2);
g.setColor(Color.gray);
g.draw(path1);
g.draw(path2);
}
示例14: getTriangle
import java.awt.geom.GeneralPath; //导入依赖的package包/类
protected int getTriangle(final FloatPoint point) {
int res = -1;
FloatPoint l = getLocation();
for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) {
GeneralPath gp = getTrianglePath(type);
double y = point.getY() + l.getY();
double x = point.getX() + l.getX();
if (gp.contains(new Point2D.Double(x, y))) {
res = type;
break;
}
}
return res;
}
示例15: drawGlassEffect
import java.awt.geom.GeneralPath; //导入依赖的package包/类
/**
* Draws the glass effect
*/
public static void drawGlassEffect(mxGraphics2DCanvas canvas, mxCellState state) {
double size = 0.4;
canvas.getGraphics()
.setPaint(new GradientPaint((float) state.getX(), (float) state.getY(),
new Color(1, 1, 1, 0.9f), (float) (state.getX()),
(float) (state.getY() + state.getHeight() * size), new Color(1, 1, 1, 0.3f)));
float sw = (float) (mxUtils.getFloat(state.getStyle(), mxConstants.STYLE_STROKEWIDTH, 1)
* canvas.getScale() / 2);
GeneralPath path = new GeneralPath();
path.moveTo((float) state.getX() - sw, (float) state.getY() - sw);
path.lineTo((float) state.getX() - sw, (float) (state.getY() + state.getHeight() * size));
path.quadTo((float) (state.getX() + state.getWidth() * 0.5),
(float) (state.getY() + state.getHeight() * 0.7),
(float) (state.getX() + state.getWidth() + sw),
(float) (state.getY() + state.getHeight() * size));
path.lineTo((float) (state.getX() + state.getWidth() + sw), (float) state.getY() - sw);
path.closePath();
canvas.getGraphics().fill(path);
}