當前位置: 首頁>>代碼示例>>Java>>正文


Java AffineTransform.getTranslateInstance方法代碼示例

本文整理匯總了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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:SunGraphics2D.java

示例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());
}
 
開發者ID:limagiran,項目名稱:hearthstone,代碼行數:21,代碼來源:TextoComBorda.java

示例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);
}
 
開發者ID:limagiran,項目名稱:hearthstone,代碼行數:19,代碼來源:Custo.java

示例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;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:19,代碼來源:Zone.java

示例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 );
}
 
開發者ID:lauriholmas,項目名稱:batmapper,代碼行數:17,代碼來源:MapperEditingGraphMousePlugin.java

示例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;
	}
 
開發者ID:jugglemaster,項目名稱:JuggleMasterPro,代碼行數:26,代碼來源:ImagesPrinter.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:RadialGradientPaint.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:45,代碼來源:TextLine.java

示例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);
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:36,代碼來源:ColoredBorder.java

示例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);
}
 
開發者ID:defano,項目名稱:jmonet,代碼行數:12,代碼來源:Transform.java

示例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);
}
 
開發者ID:CatherineHa,項目名稱:Proj4,代碼行數:13,代碼來源:StarGraphics.java

示例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);
}
 
開發者ID:kevingilboy,項目名稱:COE1186,代碼行數:15,代碼來源:TrackRenderWindow.java

示例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);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:52,代碼來源:TreeModelNodeLabelRenderer.java

示例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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:RegionOps.java

示例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;
}
 
開發者ID:defano,項目名稱:jmonet,代碼行數:7,代碼來源:Transform.java


注:本文中的java.awt.geom.AffineTransform.getTranslateInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。