下面列出了java.awt.geom.Path2D#transform ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected Shape calculateTriangleShape(final double x, final double y, final int size, final int outerSize,
final AffineTransform transform) {
double diameter = (size - 2 * outerSize);
double radius = diameter / 2.0;
double sideLength = Math.cos(Math.PI / 6.0) * diameter;
double height = (SQRT3 / 2.0) * sideLength;
double upperX = radius + x + outerSize;
double upperY = y + outerSize;
Path2D trianglePath = new Path2D.Float(Path2D.WIND_EVEN_ODD);
trianglePath.moveTo(upperX, upperY);
trianglePath.lineTo(upperX - sideLength / 2.0, upperY + height);
trianglePath.lineTo(upperX + sideLength / 2.0, upperY + height);
trianglePath.closePath();
trianglePath.transform(transform);
return trianglePath;
}
protected Path2D createPath2D() {
float r1 = getRadius1();
float r2 = getRadius2();
int k = getNumberOfPoints();
Point2D[] points = new Point2D[2 * k];
for (int a = 0; a < k; a++) {
double theta1 = 2 * Math.PI / k * a - Math.PI / 2;
double theta2 = 2 * Math.PI / k * (a + .5) - Math.PI / 2;
points[2 * a + 0] = new Point2D.Double(r1 * Math.cos(theta1),
r1 * Math.sin(theta1));
points[2 * a + 1] = new Point2D.Double(r2 * Math.cos(theta2),
r2 * Math.sin(theta2));
}
Path2D p = new Path2D.Float();
p.moveTo(points[0].getX(), points[0].getY());
for (int a = 1; a < points.length; a++) {
p.lineTo(points[a].getX(), points[a].getY());
}
p.closePath();
p.transform(AffineTransform.getTranslateInstance(getCenterX(),
getCenterY()));
return p;
}
@Override
public Shape getOutline(float x, float y) {
Path2D sum = new Path2D.Float();
for (GlyphElement e : glyphs) {
Shape s = e.outline.create();
sum.append(s, false);
}
sum.transform(AffineTransform.getTranslateInstance(x, y));
return sum;
}
public static Path2D enlargeSlightlyInPlace(Path2D path2d) {
AffineTransform aLittleLarger = new AffineTransform();
double centerX = path2d.getBounds2D().getCenterX();
double centerY = path2d.getBounds2D().getCenterY();
aLittleLarger.translate(centerX, centerY);
aLittleLarger.scale(1.01, 1.01);
aLittleLarger.translate(-centerX, -centerY);
path2d.transform(aLittleLarger);
return path2d;
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
static void testTransform(Path2D pathA) {
pathA.transform(at);
log("testTransform: passed.");
}
@Override
public void paintArrowButtonForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(SELECTED);
switch (direction) {
case SwingConstants.NORTH:
g2.fillRoundRect(x, y, w, h + 4, 5, 5);
g2.setColor(Color.BLACK);
g2.fillRect(x, y + h, w, 4);
break;
case SwingConstants.SOUTH:
g2.fillRoundRect(x, y - 4, w, h + 4, 5, 5);
g2.setColor(Color.BLACK);
g2.fillRect(x, y - 4, w, 4);
break;
case SwingConstants.WEST:
g2.fillRoundRect(x, y, w + 4, h, 5, 5);
g2.setColor(Color.BLACK);
g2.fillRect(x + w, y, 4, h);
break;
case SwingConstants.EAST:
g2.fillRoundRect(x - 4, y, w + 4, h, 5, 5);
g2.setColor(Color.BLACK);
g2.fillRect(x - 4, y, 4, h);
break;
}
g2.setColor(ACCENT);
Path2D p = new Path2D.Double();
p.moveTo(4, 0);
p.lineTo(8, 6);
p.lineTo(0, 6);
p.closePath();
switch (direction) {
case SwingConstants.NORTH:
// no transform
break;
case SwingConstants.SOUTH:
p.transform(AffineTransform.getRotateInstance(Math.PI, 4, 4));
break;
case SwingConstants.WEST:
p.transform(AffineTransform.getRotateInstance(-Math.PI / 2, 4, 4));
break;
case SwingConstants.EAST:
p.transform(AffineTransform.getRotateInstance(Math.PI / 2, 4, 4));
break;
}
p.transform(AffineTransform.getTranslateInstance((w - 8) / 2.0, (h - 7) / 2.0));
g2.fill(p);
}
private ShapeInfo CreateFeintDummyIndicator(String symbolID, Rectangle2D symbolBounds, Rectangle2D echelonBounds )
{
Path2D sFeint = new Path2D.Double();
ShapeInfo siFeint = null;
//float dash[] = {5.0f};
float dash[] = {6.0f, 4.0f};
//Shape sFeint = null;
//dashed stroke
float width = 2.0f;
try
{
if(symbolBounds != null && symbolBounds.getWidth()<20)
{
width = 1.0f;
dash[0] = 5.0f;
dash[1] = 3.0f;
}
Stroke stroke = new BasicStroke(width,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
Point2D left = new Point2D.Double(symbolBounds.getX(), symbolBounds.getY());
Point2D top = null;//new Point2D.Double(symbolBounds.getCenterX(), symbolBounds.getY() - (symbolBounds.getHeight() * .75));
Point2D right = new Point2D.Double(symbolBounds.getX() + symbolBounds.getWidth(), symbolBounds.getY());
String affiliation = symbolID.substring(1, 2);
if(affiliation.equals("F") ||
affiliation.equals("A") ||
affiliation.equals("D") ||
affiliation.equals("M") ||
affiliation.equals("J") ||
affiliation.equals("K"))
{
top = new Point2D.Double(symbolBounds.getCenterX(), symbolBounds.getY() - (symbolBounds.getHeight() * .75));
}
else
{
top = new Point2D.Double(symbolBounds.getCenterX(), symbolBounds.getY() - (symbolBounds.getHeight() * .54));
}
Line2D leftLine = new Line2D.Double(left, top);
Line2D rightLine = new Line2D.Double(top, right);
sFeint.append(leftLine, false);
sFeint.append(rightLine, false);
if(echelonBounds != null && sFeint.intersects(echelonBounds))
{
//move it above echelon and add some breathing room
sFeint.transform(AffineTransform.getTranslateInstance(0, -echelonBounds.getHeight()-2));
}
siFeint = new ShapeInfo(sFeint);
siFeint.setLineColor(Color.BLACK);
siFeint.setStroke(stroke);
siFeint.setShapeType(ShapeInfo.SHAPE_TYPE_UNIT_DISPLAY_MODIFIER);
}
catch(Exception exc)
{
ErrorLogger.LogException(_className, "CreateFeintDummyIndicator()", exc);
}
return siFeint;
}