本文整理汇总了Java中java.awt.geom.AffineTransform.getTranslateInstance方法的典型用法代码示例。如果您正苦于以下问题:Java AffineTransform.getTranslateInstance方法的具体用法?Java AffineTransform.getTranslateInstance怎么用?Java AffineTransform.getTranslateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.AffineTransform
的用法示例。
在下文中一共展示了AffineTransform.getTranslateInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformShape
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
protected static Shape transformShape(int tx, int ty, Shape s) {
if (s == null) {
return null;
}
if (s instanceof Rectangle) {
Rectangle r = s.getBounds();
r.translate(tx, ty);
return r;
}
if (s instanceof Rectangle2D) {
Rectangle2D rect = (Rectangle2D) s;
return new Rectangle2D.Double(rect.getX() + tx,
rect.getY() + ty,
rect.getWidth(),
rect.getHeight());
}
if (tx == 0 && ty == 0) {
return cloneShape(s);
}
AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty);
return mat.createTransformedShape(s);
}
示例2: paintComponent
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
//super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setFont(font);
FontRenderContext frc = g2.getFontRenderContext();
TextLayout textLayout = new TextLayout(text, font, frc);
g2.setPaint(color);
g2.setStroke(new BasicStroke(((float) font.getSize()) * (font.getStyle() == Font.BOLD ? 0.05f : 0.025f), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
AffineTransform at = AffineTransform.getTranslateInstance(5, font.getSize());
Shape outline = textLayout.getOutline(at);
g2.fill(outline);
g2.setPaint(border);
g2.draw(outline);
g2.dispose();
setSize(getFontMetrics(font).stringWidth(text) + 10, font.getSize() + 5);
setPreferredSize(getSize());
}
示例3: paintComponent
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
atualizar();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setFont(FONT);
FontRenderContext frc = g2.getFontRenderContext();
TextLayout textLayout = new TextLayout(Integer.toString(value), FONT, frc);
g2.setPaint(textColor);
AffineTransform at = AffineTransform.getTranslateInstance(20, 30);
Shape outline = textLayout.getOutline(at);
g2.fill(outline);
g2.setPaint(BLACK);
g2.draw(outline);
}
示例4: getCachedShape
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
protected Shape getCachedShape(Polygon poly, int x, int y, double scale) {
if (poly.equals(lastPolygon) &&
x == lastBoundsX &&
y == lastBoundsY &&
scale == lastScale) {
return lastTransformedShape;
}
final Shape scaled = getScaledShape(myPolygon, scale);
final AffineTransform transform =
AffineTransform.getTranslateInstance(x, y);
lastTransformedShape = transform.createTransformedShape(scaled);
lastPolygon = myPolygon;
lastBoundsX = x;
lastBoundsY = y;
lastScale = scale;
return lastTransformedShape;
}
示例5: transformEdgeShape
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private void transformEdgeShape( Point2D down, Point2D out ) {
float x1 = (float) down.getX();
float y1 = (float) down.getY();
float x2 = (float) out.getX();
float y2 = (float) out.getY();
AffineTransform xform = AffineTransform.getTranslateInstance( x1, y1 );
float dx = x2 - x1;
float dy = y2 - y1;
float thetaRadians = (float) Math.atan2( dy, dx );
xform.rotate( thetaRadians );
float dist = (float) Math.sqrt( dx * dx + dy * dy );
xform.scale( dist / rawEdge.getBounds().getWidth(), 1.0 );
edgeShape = xform.createTransformedShape( rawEdge );
}
示例6: print
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
final public int print(Graphics objPgraphics, PageFormat objPpageFormat, int intPpageIndex) {
if (this.objGimageAL != null && intPpageIndex < this.objGimageAL.size()) {
final RenderedImage imgLrendered = (RenderedImage) this.objGimageAL.get(intPpageIndex);
if (imgLrendered != null) {
final Graphics2D objLgraphics2D = (Graphics2D) objPgraphics;
objLgraphics2D.translate(objPpageFormat.getImageableX(), objPpageFormat.getImageableY());
final double dblLxRatio = objPpageFormat.getImageableWidth() / imgLrendered.getWidth();
final double dblLyRatio = objPpageFormat.getImageableHeight() / imgLrendered.getHeight();
objLgraphics2D.scale(dblLxRatio, dblLyRatio);
final AffineTransform objLaffineTransform =
AffineTransform.getTranslateInstance( objPpageFormat.getImageableX(),
objPpageFormat.getImageableY());
objLgraphics2D.drawRenderedImage(imgLrendered, objLaffineTransform);
return Printable.PAGE_EXISTS;
}
}
return Printable.NO_SUCH_PAGE;
}
示例7: createGradientTransform
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private static AffineTransform createGradientTransform(Rectangle2D r) {
double cx = r.getCenterX();
double cy = r.getCenterY();
AffineTransform xform = AffineTransform.getTranslateInstance(cx, cy);
xform.scale(r.getWidth()/2, r.getHeight()/2);
xform.translate(-cx, -cy);
return xform;
}
示例8: getVisualBounds
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
* Return the union of the visual bounds of all the components.
* This incorporates the path. It does not include logical
* bounds (used by carets).
*/
public Rectangle2D getVisualBounds() {
Rectangle2D result = null;
for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
Rectangle2D r = tlc.getVisualBounds();
Point2D.Float pt = new Point2D.Float(locs[n], locs[n+1]);
if (lp == null) {
r.setRect(r.getMinX() + pt.x, r.getMinY() + pt.y,
r.getWidth(), r.getHeight());
} else {
lp.pathToPoint(pt, false, pt);
AffineTransform at = tlc.getBaselineTransform();
if (at != null) {
AffineTransform tx = AffineTransform.getTranslateInstance
(pt.x - at.getTranslateX(), pt.y - at.getTranslateY());
tx.concatenate(at);
r = tx.createTransformedShape(r).getBounds2D();
} else {
r.setRect(r.getMinX() + pt.x, r.getMinY() + pt.y,
r.getWidth(), r.getHeight());
}
}
if (result == null) {
result = r;
} else {
result.add(r);
}
}
if (result == null) {
result = new Rectangle2D.Float(Float.MAX_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
}
return result;
}
示例9: draw
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void draw(GamePiece p, Graphics g, int x, int y,
Component obs, double zoom) {
if (thickness > 0) {
if (c != null) {
// Find the border by outsetting the bounding box, and then scaling
// the shape to fill the outset.
final Shape s = p.getShape();
final Rectangle br = s.getBounds();
// Don't bother if the shape is empty.
if (!br.isEmpty()) {
final double xzoom = (br.getWidth()+1) / br.getWidth();
final double yzoom = (br.getHeight()+1) / br.getHeight();
final AffineTransform t = AffineTransform.getTranslateInstance(x,y);
t.scale(xzoom*zoom, yzoom*zoom);
final Graphics2D g2d = (Graphics2D) g;
final Stroke str = g2d.getStroke();
g2d.setStroke(
new BasicStroke(Math.max(1, Math.round(zoom*thickness))));
g2d.setColor(c);
g2d.draw(t.createTransformedShape(s));
g2d.setStroke(str);
}
}
else {
highlightSelectionBounds(p, g, x, y, obs, zoom);
}
}
// Draw any additional highlighters
for (Highlighter h : highlighters) {
h.draw(p, g, x, y, obs, zoom);
}
}
示例10: slant
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static BufferedImage slant(BufferedImage image, FlexQuadrilateral quadrilateral, int xTranslation) {
Point p = new Point(quadrilateral.getBottomLeft().x, quadrilateral.getTopLeft().y);
double theta = Geometry.theta(quadrilateral.getBottomLeft(), p, quadrilateral.getTopLeft());
AffineTransform transform = AffineTransform.getTranslateInstance(xTranslation, 0);
transform.shear(Math.tan(theta), 0);
transform.translate(xTranslation, 0);
AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
return op.filter(image, null);
}
示例11: draw
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
* Draws a star shape after translating it to the current location where it should appear
*/
public void draw(Graphics2D graphics) {
final AffineTransform transform =
AffineTransform.getTranslateInstance(drawLocation.getX(), drawLocation.getY());
transform.scale(.6, .6);
Shape newStarShape = transform.createTransformedShape(STAR_SHAPE);
graphics.setColor(color);
graphics.fill(newStarShape);
}
示例12: drawArrow
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) {
Graphics2D g = (Graphics2D) g1.create();
double dx = x2 - x1, dy = y2 - y1;
double angle = Math.atan2(dy, dx);
int len = (int) Math.sqrt(dx*dx + dy*dy);
AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
at.concatenate(AffineTransform.getRotateInstance(angle));
g.transform(at);
g.drawLine(0, 0, len, 0);
g.fillPolygon(new int[] {len+2, len-(ARR_SIZE*2+1), len-(ARR_SIZE*2+1), len+2},
new int[] {0, -(ARR_SIZE-1), ARR_SIZE-1, 0}, 4);
}
示例13: labelVertex
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
* Labels the specified vertex with the specified label. Uses the font specified by this
* instance's <code>VertexFontFunction</code>. (If the font is unspecified, the existing font
* for the graphics context is used.) If vertex label centering is active, the label is centered
* on the position of the vertex; otherwise the label is offset slightly.
*/
@Override
public void labelVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v, String label) {
Graph<V, E> graph = layout.getGraph();
if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v)) == false) {
return;
}
Point2D pt = layout.transform(v);
pt = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, pt);
float x = (float) pt.getX();
float y = (float) pt.getY();
Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v),
v);
GraphicsDecorator g = rc.getGraphicsContext();
Dimension d = component.getPreferredSize();
AffineTransform xform = AffineTransform.getTranslateInstance(x, y);
Shape shape = rc.getVertexShapeTransformer().transform(v);
shape = xform.createTransformedShape(shape);
if (rc.getGraphicsContext() instanceof TransformingGraphics) {
BidirectionalTransformer transformer = ((TransformingGraphics) rc.getGraphicsContext()).getTransformer();
if (transformer instanceof ShapeTransformer) {
ShapeTransformer shapeTransformer = (ShapeTransformer) transformer;
shape = shapeTransformer.transform(shape);
}
}
Rectangle2D bounds = shape.getBounds2D();
Point p = null;
if (position == Position.AUTO) {
Dimension vvd = rc.getScreenDevice().getSize();
if (vvd.width == 0 || vvd.height == 0) {
vvd = rc.getScreenDevice().getPreferredSize();
}
p = getAnchorPoint(bounds, d, positioner.getPosition(x, y, vvd));
} else {
p = getAnchorPoint(bounds, d, position);
}
if (graphCreator.isLeaf((String) v)) {
p.setLocation(p.x, p.y + LABEL_OFFSET_Y);
}
g.draw(component, rc.getRendererPane(), p.x, p.y, d.width, d.height, true);
}
示例14: getTranslation
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public RectListImpl getTranslation(int dx, int dy) {
AffineTransform at = AffineTransform.getTranslateInstance(dx, dy);
return new AreaImpl(theArea.createTransformedArea(at));
}
示例15: rotateLeft
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static AffineTransform rotateLeft(int width, int height) {
AffineTransform transform = AffineTransform.getTranslateInstance(height / 2, width / 2);
transform.quadrantRotate(3);
transform.translate(-width / 2, -height / 2);
return transform;
}