本文整理匯總了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);
}
}