本文整理汇总了Java中java.awt.geom.GeneralPath.createTransformedShape方法的典型用法代码示例。如果您正苦于以下问题:Java GeneralPath.createTransformedShape方法的具体用法?Java GeneralPath.createTransformedShape怎么用?Java GeneralPath.createTransformedShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.GeneralPath
的用法示例。
在下文中一共展示了GeneralPath.createTransformedShape方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createArrow
import java.awt.geom.GeneralPath; //导入方法依赖的package包/类
protected Shape createArrow(float fx, float fy, float tx, float ty) {
float dx = tx - fx;
float dy = ty - fy;
float D = (float) Math.sqrt(dx * dx + dy * dy);
float z = (dx <= 0) ? fx - D : fx + D;
double alpha = (dx > 0) ? Math.asin(dy / D) : -Math.asin(dy / D);
float h = arrowHeight;
int n = (int) (D / h);
h = D / (float) (n + 1);
float dec = (dx <= 0) ? h : -h;
GeneralPath gp = new GeneralPath();
for (int i = 0; i <= n; i++) {
gp.moveTo(z + dec, fy - arrowWidth);
gp.lineTo(z, fy);
gp.lineTo(z + dec, fy + arrowWidth);
z += dec;
}
gp.closePath();
AffineTransform affineTransform = new AffineTransform();
affineTransform.rotate(alpha, fx, fy);
return gp.createTransformedShape(affineTransform);
}
示例2: createArrow
import java.awt.geom.GeneralPath; //导入方法依赖的package包/类
protected Shape createArrow(float fx, float fy, float tx, float ty) {
float dx = tx - fx;
float dy = ty - fy;
float D = (float) Math.sqrt(dx * dx + dy * dy);
float z = (dx <= 0) ? fx - D : fx + D;
double alpha = (dx > 0) ? Math.asin(dy / D) : -Math.asin(dy / D);
float h = arrowWidth * 2;
int n = (int) (D / h);
h = D / (float) (n + 1);
if (n < 0)
n = 0;
float dec = (dx <= 0) ? h : -h;
GeneralPath gp = new GeneralPath();
for (int i = 0; i <= n; i++) {
gp.moveTo(z + dec, fy - arrowWidth);
gp.lineTo(z + dec / 2f, fy - arrowWidth);
gp.lineTo(z, fy);
gp.lineTo(z + dec / 2f, fy + arrowWidth);
gp.lineTo(z + dec, fy + arrowWidth);
gp.lineTo(z + dec / 2f, fy);
z += dec;
}
gp.closePath();
AffineTransform affineTransform = new AffineTransform();
affineTransform.rotate(alpha, fx, fy);
return gp.createTransformedShape(affineTransform);
}
示例3: drawNeedle
import java.awt.geom.GeneralPath; //导入方法依赖的package包/类
/**
* Draws the needle.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param rotate the rotation point.
* @param angle the angle.
*/
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {
GeneralPath shape1 = new GeneralPath();
GeneralPath shape2 = new GeneralPath();
GeneralPath shape3 = new GeneralPath();
float minX = (float) plotArea.getMinX();
float minY = (float) plotArea.getMinY();
float maxX = (float) plotArea.getMaxX();
float maxY = (float) plotArea.getMaxY();
//float midX = (float) (minX + (plotArea.getWidth() * getRotateX()));
//float midY = (float) (minY + (plotArea.getHeight() * getRotateY()));
float midX = (float) (minX + (plotArea.getWidth() * 0.5));
float midY = (float) (minY + (plotArea.getHeight() * 0.8));
float y = maxY - (2 * (maxY - midY));
if (y < minY) {
y = minY;
}
shape1.moveTo(minX, midY);
shape1.lineTo(midX, minY);
shape1.lineTo(midX, y);
shape1.closePath();
shape2.moveTo(maxX, midY);
shape2.lineTo(midX, minY);
shape2.lineTo(midX, y);
shape2.closePath();
shape3.moveTo(minX, midY);
shape3.lineTo(midX, maxY);
shape3.lineTo(maxX, midY);
shape3.lineTo(midX, y);
shape3.closePath();
Shape s1 = shape1;
Shape s2 = shape2;
Shape s3 = shape3;
if ((rotate != null) && (angle != 0)) {
/// we have rotation huston, please spin me
getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
s1 = shape1.createTransformedShape(transform);
s2 = shape2.createTransformedShape(transform);
s3 = shape3.createTransformedShape(transform);
}
if (getHighlightPaint() != null) {
g2.setPaint(getHighlightPaint());
g2.fill(s3);
}
if (getFillPaint() != null) {
g2.setPaint(getFillPaint());
g2.fill(s1);
g2.fill(s2);
}
if (getOutlinePaint() != null) {
g2.setStroke(getOutlineStroke());
g2.setPaint(getOutlinePaint());
g2.draw(s1);
g2.draw(s2);
g2.draw(s3);
}
}
示例4: drawNeedle
import java.awt.geom.GeneralPath; //导入方法依赖的package包/类
/**
* Draws the needle.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param rotate the rotation point.
* @param angle the angle.
*/
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
Point2D rotate, double angle) {
GeneralPath shape1 = new GeneralPath();
GeneralPath shape2 = new GeneralPath();
GeneralPath shape3 = new GeneralPath();
float minX = (float) plotArea.getMinX();
float minY = (float) plotArea.getMinY();
float maxX = (float) plotArea.getMaxX();
float maxY = (float) plotArea.getMaxY();
//float midX = (float) (minX + (plotArea.getWidth() * getRotateX()));
//float midY = (float) (minY + (plotArea.getHeight() * getRotateY()));
float midX = (float) (minX + (plotArea.getWidth() * 0.5));
float midY = (float) (minY + (plotArea.getHeight() * 0.8));
float y = maxY - (2 * (maxY - midY));
if (y < minY) {
y = minY;
}
shape1.moveTo(minX, midY);
shape1.lineTo(midX, minY);
shape1.lineTo(midX, y);
shape1.closePath();
shape2.moveTo(maxX, midY);
shape2.lineTo(midX, minY);
shape2.lineTo(midX, y);
shape2.closePath();
shape3.moveTo(minX, midY);
shape3.lineTo(midX, maxY);
shape3.lineTo(maxX, midY);
shape3.lineTo(midX, y);
shape3.closePath();
Shape s1 = shape1;
Shape s2 = shape2;
Shape s3 = shape3;
if ((rotate != null) && (angle != 0)) {
/// we have rotation huston, please spin me
getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
s1 = shape1.createTransformedShape(transform);
s2 = shape2.createTransformedShape(transform);
s3 = shape3.createTransformedShape(transform);
}
if (getHighlightPaint() != null) {
g2.setPaint(getHighlightPaint());
g2.fill(s3);
}
if (getFillPaint() != null) {
g2.setPaint(getFillPaint());
g2.fill(s1);
g2.fill(s2);
}
if (getOutlinePaint() != null) {
g2.setStroke(getOutlineStroke());
g2.setPaint(getOutlinePaint());
g2.draw(s1);
g2.draw(s2);
g2.draw(s3);
}
}