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


Java AffineTransform.createTransformedShape方法代碼示例

本文整理匯總了Java中java.awt.geom.AffineTransform.createTransformedShape方法的典型用法代碼示例。如果您正苦於以下問題:Java AffineTransform.createTransformedShape方法的具體用法?Java AffineTransform.createTransformedShape怎麽用?Java AffineTransform.createTransformedShape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.geom.AffineTransform的用法示例。


在下文中一共展示了AffineTransform.createTransformedShape方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: draw

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
@Override
public void draw(Graphics2D graphics) {
	graphics.setStroke(JSpaceSettlersComponent.THIN_STROKE);
	
       final AffineTransform transform =
               AffineTransform.getTranslateInstance(drawLocation.getX(), drawLocation.getY());
       transform.rotate(-Math.PI / 2.0);

   	transform.scale(scale, scale);

       Shape newFlagShape = transform.createTransformedShape(FLAG_SHAPE);

       // color the flag to match the team
       graphics.setPaint(flagColor);
       graphics.fill(newFlagShape);
}
 
開發者ID:amymcgovern,項目名稱:spacesettlers,代碼行數:17,代碼來源:FlagGraphics.java

示例2: 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

示例3: drawUnexpanded

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
/**
 * Draw a {@link GamePiece} that is not the top piece in an unexpanded {@link Stack}
 *
 * Default implementation is a white square with a black border
 */
protected void drawUnexpanded(GamePiece p, Graphics g,
                              int x, int y, Component obs, double zoom) {
  if (blankColor == null) {
    p.draw(g, x, y, obs, zoom);
  }
  else {
    Graphics2D g2d = (Graphics2D) g;
    g.setColor(blankColor);
    Shape s = p.getShape();
    AffineTransform t = AffineTransform.getScaleInstance(zoom,zoom);
    t.translate(x/zoom,y/zoom);
    s = t.createTransformedShape(s);
    g2d.fill(s);
    g.setColor(Color.black);
    g2d.draw(s);
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:23,代碼來源:StackMetrics.java

示例4: getLabelEnclosure

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:34,代碼來源:Axis.java

示例5: scaleRect

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
public static Shape scaleRect(final Rectangle2D shape, final int max) {
  Vector2D newDimension = scaleWithRatio(shape.getWidth(), shape.getHeight(), max);
  if (newDimension == null) {
    return shape;
  }

  final AffineTransform transform = AffineTransform.getScaleInstance(newDimension.getX(), newDimension.getY());
  return transform.createTransformedShape(shape);
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:10,代碼來源:GeometricUtilities.java

示例6: scaleShape

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
/**
 * Scales a shape according to the scaling factor for value (given by the sizeProvider if one
 * such exists). If no sizeProvider exists, the shape is returned unmodified.
 */
private Shape scaleShape(Shape shape, double scalingFactor) {
	// scale shape if necessary
	if (scalingFactor != 1) {
		AffineTransform t = new AffineTransform();
		t.scale(scalingFactor, scalingFactor);
		shape = t.createTransformedShape(shape);
	}
	return shape;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:14,代碼來源:RenderFormatDelegate.java

示例7: paintIconForVertex

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
/**
 * Paint <code>v</code>'s icon on <code>g</code> at <code>(x,y)</code>.
 */
protected void paintIconForVertex(RenderContext<V, E> rc, V v, Layout<V, E> layout) {
	GraphicsDecorator g = rc.getGraphicsContext();
	boolean vertexHit = true;
	// get the shape to be rendered
	Shape shape = rc.getVertexShapeTransformer().transform(v);

	Point2D p = layout.transform(v);
	p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);
	float x = (float) p.getX();
	float y = (float) p.getY();
	// create a transform that translates to the location of
	// the vertex to be rendered
	AffineTransform xform = AffineTransform.getTranslateInstance(x, y);
	// transform the vertex shape with xtransform
	shape = xform.createTransformedShape(shape);

	vertexHit = vertexHit(rc, shape);
	// rc.getViewTransformer().transform(shape).intersects(deviceRectangle);

	if (vertexHit) {
		if (rc.getVertexIconTransformer() != null) {
			Icon icon = rc.getVertexIconTransformer().transform(v);
			if (icon != null) {

				g.draw(icon, rc.getScreenDevice(), shape, (int) x, (int) y);

			} else {
				paintShapeForVertex(rc, v, shape);
			}
		} else {
			paintShapeForVertex(rc, v, shape);
		}
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:38,代碼來源:TreeModelNodeRenderer.java

示例8: getScaledShape

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
protected Shape getScaledShape(Polygon myPolygon, double scale) {
  if (scale == lastScale && lastPolygon == myPolygon && lastScaledShape != null) {
    return lastScaledShape;
  }
  final AffineTransform transform =
    AffineTransform.getScaleInstance(scale, scale);
  lastScaledShape = transform.createTransformedShape(myPolygon);
  lastScale = scale;
  lastPolygon = myPolygon;
  return lastScaledShape;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:12,代碼來源:Zone.java

示例9: draw

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
/**
* Draws the annotation.  This method is usually called by the {@link XYPlot} class, you 
* shouldn't need to call it directly.
*
* @param g2  the graphics device.
* @param plot  the plot.
* @param dataArea  the data area.
* @param domainAxis  the domain axis.
* @param rangeAxis  the range axis.
*/
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
        plot.getDomainAxisLocation(), orientation
    );
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
        plot.getRangeAxisLocation(), orientation
    );

    //compute transform matrix elements via sample points. Assume no rotation or shear.
    // x-axis translation
    double m02 = domainAxis.valueToJava2D(0, dataArea, domainEdge); 
    // y-axis translation
    double m12 = rangeAxis.valueToJava2D(0, dataArea, rangeEdge);
    // x-axis scale 
    double m00 = domainAxis.valueToJava2D(1, dataArea, domainEdge) - m02; 
    // y-axis scale
    double m11 = rangeAxis.valueToJava2D(1, dataArea, rangeEdge) - m12; 

    //create transform & transform shape
    Shape s = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
        AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02);
        s = t1.createTransformedShape(this.shape);
        s = t2.createTransformedShape(s);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
        s = t.createTransformedShape(this.shape);
    }

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    g2.draw(s);
    
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:50,代碼來源:XYShapeAnnotation.java

示例10: transformShape

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
protected static Shape transformShape(AffineTransform tx, Shape clip) {
    if (clip == null) {
        return null;
    }

    if (clip instanceof Rectangle2D &&
        (tx.getType() & NON_RECTILINEAR_TRANSFORM_MASK) == 0)
    {
        Rectangle2D rect = (Rectangle2D) clip;
        double matrix[] = new double[4];
        matrix[0] = rect.getX();
        matrix[1] = rect.getY();
        matrix[2] = matrix[0] + rect.getWidth();
        matrix[3] = matrix[1] + rect.getHeight();
        tx.transform(matrix, 0, matrix, 0, 2);
        fixRectangleOrientation(matrix, rect);
        return new Rectangle2D.Double(matrix[0], matrix[1],
                                      matrix[2] - matrix[0],
                                      matrix[3] - matrix[1]);
    }

    if (tx.isIdentity()) {
        return cloneShape(clip);
    }

    return tx.createTransformedShape(clip);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:SunGraphics2D.java

示例11: getShape

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
public Shape getShape(Vertex v) {
	Icon icon = (Icon) iconMap.get(v);

	if (icon != null && icon instanceof ImageIcon) {

		Image image = ((ImageIcon) icon).getImage();

		Shape shape = (Shape) shapeMap.get(image);
		if (shape == null) {
			if (shapeImages) {
				shape = FourPassImageShaper.getShape(image, 30);
			} else {
				shape = new Rectangle2D.Float(0, 0, 
						image.getWidth(null), image.getHeight(null));
			}
                  if(shape.getBounds().getWidth() > 0 && 
                          shape.getBounds().getHeight() > 0) {
                      int width = image.getWidth(null);
                      int height = image.getHeight(null);
                      AffineTransform transform = 
                          AffineTransform.getTranslateInstance(-width / 2, -height / 2);
                      shape = transform.createTransformedShape(shape);
                      shapeMap.put(image, shape);
                  }
		}
		return shape;
	} else {
		return delegate.getShape(v);
	}
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:31,代碼來源:VertexImageShaperDemo.java

示例12: main

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    AffineTransform at;
    for (final int size : SIZES) {
        for (final int scale : SCALES) {
            final int sw = size * scale;
            at = AffineTransform.getScaleInstance(sw, sw);
            for (Shape clip : SHAPES) {
                clip = at.createTransformedShape(clip);
                for (Shape to : SHAPES) {
                    to = at.createTransformedShape(to);
                    // Prepare test images
                    VolatileImage vi = getVolatileImage(gc, size);
                    BufferedImage bi = getBufferedImage(sw);
                    // Prepare gold images
                    BufferedImage goldvi = getCompatibleImage(gc, size);
                    BufferedImage goldbi = getBufferedImage(sw);
                    draw(clip, to, vi, bi, scale);
                    draw(clip, to, goldvi, goldbi, scale);
                    validate(bi, goldbi);
                }
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:IncorrectClipSurface2SW.java

示例13: addDrawingRect

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
/**
 * Add the rectangle 'rect' to the area representing
 * the part of the page which is drawn into.
 */
private void addDrawingRect(Rectangle2D rect) {

    /*  For testing purposes the following line can be uncommented.
        When uncommented it causes the entire page to be rasterized
        thus eliminating errors caused by a faulty bounding box
        calculation.
    */
    //mDrawingArea.addInfinite();



    AffineTransform matrix = getTransform();

    Shape transShape = matrix.createTransformedShape(rect);

    Rectangle2D transRect = transShape.getBounds2D();

    mDrawingArea.add((float) transRect.getMinY(),
                     (float) transRect.getMaxY());


}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:PeekGraphics.java

示例14: 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

示例15: main

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
public static void main(String[] args) {
    Locale.setDefault(Locale.US);

    // initialize j.u.l Looger:
    final Logger log = Logger.getLogger("sun.java2d.marlin");
    log.addHandler(new Handler() {
        @Override
        public void publish(LogRecord record) {
            Throwable th = record.getThrown();
            // detect any Throwable:
            if (th != null) {
                System.out.println("Test failed:\n" + record.getMessage());
                th.printStackTrace(System.out);

                throw new RuntimeException("Test failed: ", th);
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });

    log.info("TextClipErrorTest: start");

    // enable Marlin logging & internal checks:
    System.setProperty("sun.java2d.renderer.log", "true");
    System.setProperty("sun.java2d.renderer.useLogger", "true");
    System.setProperty("sun.java2d.renderer.doChecks", "true");

    BufferedImage image = new BufferedImage(256, 256,
                                            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2d = image.createGraphics();
    g2d.setColor(Color.red);
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);

        Font font = g2d.getFont();
        FontRenderContext frc = new FontRenderContext(
            new AffineTransform(), true, true);

        g2d.setStroke(new BasicStroke(4.0f,
                                      BasicStroke.CAP_ROUND,
                                      BasicStroke.JOIN_ROUND));

        final Shape badShape;
        if (SERIALIZE) {
            final GlyphVector gv1 = font.createGlyphVector(frc, "\u00d6");
            final Shape textShape = gv1.getOutline();

            final AffineTransform at1 = AffineTransform.getTranslateInstance(
                -2091202.554154681, 5548.601436981691);
            badShape = at1.createTransformedShape(textShape);
            serializeShape(badShape);
        } else {
            badShape = deserializeShape();
        }

        g2d.draw(badShape);

        // Draw anything within bounds and it fails:
        g2d.draw(new Line2D.Double(10, 20, 30, 40));

        if (SAVE_IMAGE) {
            final File file = new File("TextClipErrorTest.png");
            System.out.println("Writing file: " + file.getAbsolutePath());
            ImageIO.write(image, "PNG", file);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        g2d.dispose();
        log.info("TextClipErrorTest: end");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:82,代碼來源:TextClipErrorTest.java


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