类java.awt.geom.AffineTransform源码实例Demo

下面列出了怎么用java.awt.geom.AffineTransform的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * Creates an BufferedImage and draws a text, using two transformations,
 * one for graphics and one for font.
 */
private static BufferedImage createImage(final boolean aa,
                                         final AffineTransform gtx,
                                         final AffineTransform ftx) {
    final BufferedImage bi = new BufferedImage(SIZE, SIZE, TYPE_INT_RGB);
    final Graphics2D bg = bi.createGraphics();
    bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        aa ? RenderingHints.VALUE_ANTIALIAS_ON
                           : RenderingHints.VALUE_ANTIALIAS_OFF);
    bg.setColor(Color.RED);
    bg.fillRect(0, 0, SIZE, SIZE);
    bg.translate(100, 100);
    bg.transform(gtx);
    bg.setColor(Color.BLACK);
    bg.setFont(bg.getFont().deriveFont(20.0f).deriveFont(ftx));
    bg.drawString(STR, 0, 0);
    bg.dispose();
    return bi;
}
 
源代码2 项目: openjdk-jdk8u   文件: Font2D.java
public float getItalicAngle(Font font, AffineTransform at,
                            Object aaHint, Object fmHint) {
    /* hardwire psz=12 as that's typical and AA vs non-AA for 'gasp' mode
     * isn't important for the caret slope of this rarely used API.
     */
    int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, 12);
    int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
    FontStrike strike = getStrike(font, at, aa, fm);
    StrikeMetrics metrics = strike.getFontMetrics();
    if (metrics.ascentY == 0 || metrics.ascentX == 0) {
        return 0f;
    } else {
        /* ascent is "up" from the baseline so its typically
         * a negative value, so we need to compensate
         */
        return metrics.ascentX/-metrics.ascentY;
    }
}
 
源代码3 项目: workcraft   文件: TouchableTransformerTests.java
@Test
public void testTranslateHitTest() {
    TouchableTransformer toucher = new TouchableTransformer(
            new Dummy() {
                @Override
                public boolean hitTest(Point2D point) {
                    return point.distanceSq(0, 0) < 1.0;
                }
            }, AffineTransform.getTranslateInstance(10, 1));

    Assertions.assertTrue(toucher.hitTest(new Point2D.Double(10, 1)));
    Assertions.assertTrue(toucher.hitTest(new Point2D.Double(10.9, 1)));
    Assertions.assertTrue(toucher.hitTest(new Point2D.Double(9.1, 1)));
    Assertions.assertFalse(toucher.hitTest(new Point2D.Double(11.1, 1)));
    Assertions.assertFalse(toucher.hitTest(new Point2D.Double(8.9, 1)));
    Assertions.assertTrue(toucher.hitTest(new Point2D.Double(10.6, 1.6)));
    Assertions.assertFalse(toucher.hitTest(new Point2D.Double(10.8, 1.8)));
    Assertions.assertTrue(toucher.hitTest(new Point2D.Double(9.4, 0.4)));
    Assertions.assertFalse(toucher.hitTest(new Point2D.Double(9.2, 0.2)));
}
 
源代码4 项目: coming   文件: NPEfix_00174_t.java
/** Build an affine line transform from a n {@code AffineTransform}.
 * @param transform transform to use (must be invertible otherwise
 * the {@link LineTransform#apply(Hyperplane)} method would work
 * only for some lines, and fail for other ones)
 * @exception MathIllegalArgumentException if the transform is non invertible
 */
public LineTransform(final AffineTransform transform) throws MathIllegalArgumentException {

    final double[] m = new double[6];
    transform.getMatrix(m);
    cXX = m[0];
    cXY = m[2];
    cX1 = m[4];
    cYX = m[1];
    cYY = m[3];
    cY1 = m[5];

    c1Y = cXY * cY1 - cYY * cX1;
    c1X = cXX * cY1 - cYX * cX1;
    c11 = cXX * cYY - cYX * cXY;

    if (FastMath.abs(c11) < 1.0e-20) {
        throw new MathIllegalArgumentException(LocalizedFormats.NON_INVERTIBLE_TRANSFORM);
    }

}
 
源代码5 项目: rapidminer-studio   文件: SurfacePlot3D.java
@Override
public JComponent getPlotter() {
	DataTable table = getDataTable();
	if (table != null && table.getNumberOfRows() > MAX_NUMBER_OF_ROWS) {
		LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.mathplot.SurfacePlot2D.too_many_examples",
				new Object[] { table.getNumberOfRows(), MAX_NUMBER_OF_ROWS });
		// Display Label with error message because Plot3DPanel can not handle such a lot of
		// data points
		JLabel label = new JLabel(I18N.getGUILabel("surface3DPlot.too_many_examples", MAX_NUMBER_OF_ROWS));
		label.setHorizontalAlignment(SwingConstants.CENTER);
		Font originalFont = label.getFont();
		label.setFont(originalFont.deriveFont((float) (originalFont.getSize() * 1.25)));
		originalFont.deriveFont(new AffineTransform());

		return label;
	} else {
		return super.getPlotter();
	}
}
 
public static PathConsumer2D
    deltaTransformConsumer(PathConsumer2D out,
                           AffineTransform at)
{
    if (at == null) {
        return out;
    }
    float Mxx = (float) at.getScaleX();
    float Mxy = (float) at.getShearX();
    float Myx = (float) at.getShearY();
    float Myy = (float) at.getScaleY();
    if (Mxy == 0f && Myx == 0f) {
        if (Mxx == 1f && Myy == 1f) {
            return out;
        } else {
            return new DeltaScaleFilter(out, Mxx, Myy);
        }
    } else {
        return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
    }
}
 
源代码7 项目: openjdk-jdk9   文件: PathGraphics.java
/**
 * Draws the outline of the specified rectangle.
 * The left and right edges of the rectangle are at
 * {@code x} and <code>x&nbsp;+&nbsp;width</code>.
 * The top and bottom edges are at
 * {@code y} and <code>y&nbsp;+&nbsp;height</code>.
 * The rectangle is drawn using the graphics context's current color.
 * @param         x   the <i>x</i> coordinate
 *                         of the rectangle to be drawn.
 * @param         y   the <i>y</i> coordinate
 *                         of the rectangle to be drawn.
 * @param         width   the width of the rectangle to be drawn.
 * @param         height   the height of the rectangle to be drawn.
 * @see          java.awt.Graphics#fillRect
 * @see          java.awt.Graphics#clearRect
 */
public void drawRect(int x, int y, int width, int height) {

    Paint paint = getPaint();

    try {
        AffineTransform deviceTransform = getTransform();
        if (getClip() != null) {
            deviceClip(getClip().getPathIterator(deviceTransform));
        }

        deviceFrameRect(x, y, width, height, (Color) paint);

    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Expected a Color instance");
    }

}
 
源代码8 项目: jdk8u-jdk   文件: GraphicComponent.java
/**
 * Create a new GraphicComponent.  start and limit are indices
 * into charLtoV and levels.  charsLtoV and levels may be adopted.
 */
public GraphicComponent(GraphicAttribute graphic,
                        Decoration decorator,
                        int[] charsLtoV,
                        byte[] levels,
                        int start,
                        int limit,
                        AffineTransform baseTx) {

    if (limit <= start) {
        throw new IllegalArgumentException("0 or negative length in GraphicComponent");
    }
    this.graphic = graphic;
    this.graphicAdvance = graphic.getAdvance();
    this.decorator = decorator;
    this.cm = createCoreMetrics(graphic);
    this.baseTx = baseTx;

    initLocalOrdering(charsLtoV, levels, start, limit);
}
 
源代码9 项目: jdk8u-jdk   文件: StandardGlyphVector.java
public void setGlyphTransform(int ix, AffineTransform newTX) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    if (gti == null) {
        if (newTX == null || newTX.isIdentity()) {
            return;
        }
        gti = new GlyphTransformInfo(this);
    }
    gti.setGlyphTransform(ix, newTX); // sets flags
    if (gti.transformCount() == 0) {
        gti = null;
    }
}
 
源代码10 项目: jdk8u-jdk   文件: AttributeValues.java
private static AffineTransform extractRotation(Point2D.Double pt,
    AffineTransform tx, boolean andTranslation) {

    tx.deltaTransform(pt, pt);
    AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);

    try {
        AffineTransform rtxi = rtx.createInverse();
        double dx = tx.getTranslateX();
        double dy = tx.getTranslateY();
        tx.preConcatenate(rtxi);
        if (andTranslation) {
            if (dx != 0 || dy != 0) {
                tx.setTransform(tx.getScaleX(), tx.getShearY(),
                                tx.getShearX(), tx.getScaleY(), 0, 0);
                rtx.setTransform(rtx.getScaleX(), rtx.getShearY(),
                                 rtx.getShearX(), rtx.getScaleY(), dx, dy);
            }
        }
    }
    catch (NoninvertibleTransformException e) {
        return null;
    }
    return rtx;
}
 
源代码11 项目: nordpos   文件: PrintItemBarcode.java
@Override
public void draw(Graphics2D g, int x, int y, int width) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform oldt = g2d.getTransform();
    g2d.translate(x - 10 + (width - (int) (m_iWidth * scale)) / 2, y + 10);
    g2d.scale(scale, scale);

    try {
        if (m_qrMatrix != null) {
            com.google.zxing.Writer writer = new QRCodeWriter();
            m_qrMatrix = writer.encode(m_sCode, com.google.zxing.BarcodeFormat.QR_CODE, m_iWidth, m_iHeight);
            g2d.drawImage(MatrixToImageWriter.toBufferedImage(m_qrMatrix), null, 0, 0);
        } else if (m_barcode != null) {
            m_barcode.generateBarcode(new Java2DCanvasProvider(g2d, 0), m_sCode);
        }
    } catch (IllegalArgumentException | WriterException ex) {
        g2d.drawRect(0, 0, m_iWidth, m_iHeight);
        g2d.drawLine(0, 0, m_iWidth, m_iHeight);
        g2d.drawLine(m_iWidth, 0, 0, m_iHeight);
    }

    g2d.setTransform(oldt);
}
 
源代码12 项目: jdk8u-jdk   文件: SynthPainterImpl.java
/**
 * Paints the border of a text field.
 *
 * @param context SynthContext identifying the <code>JComponent</code> and
 *        <code>Region</code> to paint to
 * @param g <code>Graphics</code> to paint to
 * @param x X coordinate of the area to paint to
 * @param y Y coordinate of the area to paint to
 * @param w Width of the area to paint to
 * @param h Height of the area to paint to
 */
public void paintTextFieldBorder(SynthContext context,
                                  Graphics g, int x, int y,
                                  int w, int h) {
    if (context.getComponent().getComponentOrientation().isLeftToRight()){
        paintBorder(context, g, x, y, w, h, null);
    } else {
        AffineTransform transform = new AffineTransform();
        transform.translate(x,y);
        transform.scale(-1, 1);
        transform.translate(-w,0);
        paintBorder(context, g, 0, 0, w, h, transform);
    }
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: SunGraphics2D.java
/**
 * Sets the Transform in the current graphics state.
 * @param Tx The Transform object to be used in the rendering process.
 * @see #transform
 * @see TransformChain
 * @see AffineTransform
 */
@Override
public void setTransform(AffineTransform Tx) {
    if ((constrainX | constrainY) == 0 && devScale == 1) {
        transform.setTransform(Tx);
    } else {
        transform.setTransform(devScale, 0, 0, devScale, constrainX,
                               constrainY);
        transform.concatenate(Tx);
    }
    invalidateTransform();
}
 
源代码14 项目: jdk8u-jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    AffineTransform tx;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            tx = gv.getGlyphTransform(i);
        }
    } while (--numReps >= 0);
}
 
源代码15 项目: dragonwell8_jdk   文件: AffineTransformOp.java
/**
 * Constructs an <CODE>AffineTransformOp</CODE> given an affine transform
 * and the interpolation type.
 *
 * @param xform The <CODE>AffineTransform</CODE> to use for the operation.
 * @param interpolationType One of the integer
 * interpolation type constants defined by this class:
 * {@link #TYPE_NEAREST_NEIGHBOR TYPE_NEAREST_NEIGHBOR},
 * {@link #TYPE_BILINEAR TYPE_BILINEAR},
 * {@link #TYPE_BICUBIC TYPE_BICUBIC}.
 * @throws ImagingOpException if the transform is non-invertible.
 */
public AffineTransformOp(AffineTransform xform, int interpolationType) {
    validateTransform(xform);
    this.xform = (AffineTransform)xform.clone();
    switch(interpolationType) {
        case TYPE_NEAREST_NEIGHBOR:
        case TYPE_BILINEAR:
        case TYPE_BICUBIC:
            break;
    default:
        throw new IllegalArgumentException("Unknown interpolation type: "+
                                           interpolationType);
    }
    this.interpolationType = interpolationType;
}
 
源代码16 项目: openjdk-8   文件: SynthPainterImpl.java
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
                             int w, int h, AffineTransform transform) {
    // if the background color of the component is 100% transparent
    // then we should not paint any background graphics. This is a solution
    // for there being no way of turning off Nimbus background painting as
    // basic components are all non-opaque by default.
    Component c = ctx.getComponent();
    Color bg = (c != null) ? c.getBackground() : null;
    if (bg == null || bg.getAlpha() > 0){
        Painter backgroundPainter = style.getBackgroundPainter(ctx);
        if (backgroundPainter != null) {
            paint(backgroundPainter, ctx, g, x, y, w, h,transform);
        }
    }
}
 
源代码17 项目: Pixelitor   文件: CloneBrush.java
/**
 * Recalculates the brush stamp image before each dab
 */
@Override
void setupBrushStamp(PPoint p) {
    Graphics2D g = brushImage.createGraphics();

    type.beforeDrawImage(g);

    // the current sampling coordinates relative to the source image
    double currSrcX = dx - p.getImX();
    double currSrcY = dy - p.getImY();

    // Now calculate the transformation from the source to the brush image.
    // Concatenated transformations have a last-specified-first-applied
    // order, so start with the last transformation
    // that works when there is no scaling/rotating
    var transform = AffineTransform.getTranslateInstance(
            currSrcX + radius, currSrcY + radius);

    if (scaleX != 1.0 || scaleY != 1.0 || rotate != 0.0) {
        g.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BILINEAR);
        // we need to scale/rotate the image
        // around the source point, so translate first
        transform.translate(origSrcX, origSrcY);
        transform.scale(scaleX, scaleY);
        transform.rotate(rotate);
        transform.translate(-origSrcX, -origSrcY);
    }

    g.drawImage(sourceImage, transform, null);
    type.afterDrawImage(g);

    g.dispose();

    debugImage();
}
 
源代码18 项目: netcdf-java   文件: ScaledPanel.java
/**
 * map world coords to screen coords.
 *
 * @param world world coordinate rectangle
 * @param screen screen coordinate rectangle
 * @return AffineTransform for converting world to screen.
 */
private AffineTransform calcTransform(Rectangle2D screen, Bounds world) {
  // scale to limiting dimension
  double xs = screen.getWidth() / (world.getRight() - world.getLeft());
  double ys = screen.getHeight() / (world.getLower() - world.getUpper());

  AffineTransform cat = new AffineTransform();
  cat.setToScale(xs, ys);
  cat.translate(-world.getLeft(), -world.getUpper());

  if (debugTransform) {
    System.out.println("TPanel calcTransform = ");
    System.out.println("  screen = " + screen);
    System.out.println("  world = " + world);

    System.out.println("  transform = " + cat.getScaleX() + " " + cat.getShearX() + " " + cat.getTranslateX());
    System.out.println("              " + cat.getShearY() + " " + cat.getScaleY() + " " + cat.getTranslateY());

    Point2D src = new Point2D.Double(world.getLeft(), world.getUpper());
    Point2D dst = new Point2D.Double(0.0, 0.0);

    System.out.println("  upper left pt = " + src);
    System.out.println("  transform = " + cat.transform(src, dst));

    src = new Point2D.Double(world.getRight(), world.getLower());
    System.out.println("  lower right pt = " + src);
    System.out.println("  transform = " + cat.transform(src, dst));
  }
  return cat;
}
 
源代码19 项目: gama   文件: SVGElement.java
static protected AffineTransform parseTransform(final String val) throws SVGException {
	final Matcher matchExpression = Pattern.compile("\\w+\\([^)]*\\)").matcher("");

	final AffineTransform retXform = new AffineTransform();

	matchExpression.reset(val);
	while (matchExpression.find()) {
		retXform.concatenate(parseSingleTransform(matchExpression.group()));
	}

	return retXform;
}
 
源代码20 项目: openjdk-jdk8u   文件: DrawImage.java
protected void transformImage(SunGraphics2D sg, Image img,
                              AffineTransform tx, int interpType,
                              int sx1, int sy1, int sx2, int sy2,
                              Color bgColor)
{
    // Transform 3 source corners by tx and analyze them
    // for simplified operations (Copy or Scale).  Using
    // 3 points lets us analyze any kind of transform,
    // even transforms that involve very tiny amounts of
    // rotation or skew to see if they degenerate to a
    // simple scale or copy operation within the allowable
    // error bounds.
    // Note that we use (0,0,w,h) instead of (sx1,sy1,sx2,sy2)
    // because the transform is already translated such that
    // the origin is where sx1, sy1 should go.
    double coords[] = new double[6];
    /* index:  0  1    2  3    4  5  */
    /* coord: (0, 0), (w, h), (0, h) */
    coords[2] = sx2 - sx1;
    coords[3] = coords[5] = sy2 - sy1;
    tx.transform(coords, 0, coords, 0, 3);
    // First test if the X coords of the transformed UL
    // and LL points match and that the Y coords of the
    // transformed LR and LL points also match.
    // If they do then it is a "rectilinear" transform and
    // tryCopyOrScale will make sure it is upright and
    // integer-based.
    if (Math.abs(coords[0] - coords[4]) < MAX_TX_ERROR &&
        Math.abs(coords[3] - coords[5]) < MAX_TX_ERROR &&
        tryCopyOrScale(sg, img, sx1, sy1, sx2, sy2,
                       bgColor, interpType, coords))
    {
        return;
    }

    renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor);
}
 
源代码21 项目: birt   文件: SwingGraphicsUtil.java
private static BufferedImage renderRotatedObject( Object src, double angle,
		int width, int height, double tx, double ty )
{
	BufferedImage dest = new BufferedImage( width,
			height,
			BufferedImage.TYPE_INT_ARGB );

	Graphics2D g2d = (Graphics2D) dest.getGraphics( );
	g2d.setColor( Color.black );
	g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING,
			RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
	g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON );

	AffineTransform at = AffineTransform.getRotateInstance( angle );
	at.translate( tx, ty );
	g2d.setTransform( at );

	if ( src instanceof TextLayout )
	{
		TextLayout tl = (TextLayout) src;
		tl.draw( g2d, 0, tl.getAscent( ) );
	}
	else if ( src instanceof Image )
	{
		g2d.drawImage( (Image) src, 0, 0, null );
	}
	g2d.dispose( );

	return dest;
}
 
源代码22 项目: openjdk-8-source   文件: TexturePaintContext.java
public static PaintContext getContext(BufferedImage bufImg,
                                      AffineTransform xform,
                                      RenderingHints hints,
                                      Rectangle devBounds) {
    WritableRaster raster = bufImg.getRaster();
    ColorModel cm = bufImg.getColorModel();
    int maxw = devBounds.width;
    Object val = hints.get(RenderingHints.KEY_INTERPOLATION);
    boolean filter =
        (val == null
         ? (hints.get(RenderingHints.KEY_RENDERING) == RenderingHints.VALUE_RENDER_QUALITY)
         : (val != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
    if (raster instanceof IntegerInterleavedRaster &&
        (!filter || isFilterableDCM(cm)))
    {
        IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster;
        if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) {
            return new Int(iir, cm, xform, maxw, filter);
        }
    } else if (raster instanceof ByteInterleavedRaster) {
        ByteInterleavedRaster bir = (ByteInterleavedRaster) raster;
        if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) {
            if (filter) {
                if (isFilterableICM(cm)) {
                    return new ByteFilter(bir, cm, xform, maxw);
                }
            } else {
                return new Byte(bir, cm, xform, maxw);
            }
        }
    }
    return new Any(raster, cm, xform, maxw, filter);
}
 
源代码23 项目: dragonwell8_jdk   文件: TexturePaintContext.java
public Byte(ByteInterleavedRaster srcRas, ColorModel cm,
            AffineTransform xform, int maxw)
{
    super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.srcRas = srcRas;
    this.inData = srcRas.getDataStorage();
    this.inSpan = srcRas.getScanlineStride();
    this.inOff = srcRas.getDataOffset(0);
}
 
源代码24 项目: jdk8u-jdk   文件: GraphicsTests.java
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(1.5, 1.5);
    g2d.transform(at);
    dim.setSize(w-3, h-3);
}
 
源代码25 项目: jdk8u-jdk   文件: TextSourceLabel.java
public AffineTransform getBaselineTransform() {
    Font font = source.getFont();
    if (font.hasLayoutAttributes()) {
        return AttributeValues.getBaselineTransform(font.getAttributes());
    }
    return null;
}
 
源代码26 项目: Java8CN   文件: BasicProgressBarUI.java
/**
 * Paints the progress string.
 *
 * @param g Graphics used for drawing.
 * @param x x location of bounding box
 * @param y y location of bounding box
 * @param width width of bounding box
 * @param height height of bounding box
 * @param fillStart start location, in x or y depending on orientation,
 *        of the filled portion of the progress bar.
 * @param amountFull size of the fill region, either width or height
 *        depending upon orientation.
 * @param b Insets of the progress bar.
 */
private void paintString(Graphics g, int x, int y, int width, int height,
                         int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    Graphics2D g2 = (Graphics2D)g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        g2.setColor(getSelectionBackground());
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(fillStart, y, amountFull, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    } else { // VERTICAL
        g2.setColor(getSelectionBackground());
        AffineTransform rotate =
                AffineTransform.getRotateInstance(Math.PI/2);
        g2.setFont(progressBar.getFont().deriveFont(rotate));
        renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(x, fillStart, width, amountFull);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
}
 
源代码27 项目: TencentKona-8   文件: GlyphRotationTest.java
public static void main(String[] args) {
    font = new Font(fontName, Font.PLAIN, 15);
    if (!font.getFamily(java.util.Locale.ENGLISH).equals(fontName)) {
        return;
    }
    BufferedImage bi = new BufferedImage(SZ,SZ,BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, SZ, SZ);
    g2d.setColor(Color.black);
    g2d.setFont(font);
    g2d.drawString("1", SZ/2, SZ/2);
    int pixCnt1 = countPixels(bi);
    AffineTransform at = AffineTransform.getRotateInstance(Math.PI/2);
    font = font.deriveFont(Font.PLAIN, at);
    g2d.setFont(font);
    g2d.drawString("1", SZ/2, SZ/2);
    int pixCnt2 = countPixels(bi);
    if (args.length > 0) {
        try {
           ImageIO.write(bi, "png", new java.io.File("im.png"));
        }  catch (Exception e) {}
    }
    if (pixCnt1 == pixCnt2) {
        String msg = "cnt 1 = " + pixCnt1 + " cnt 2 = " + pixCnt2;
        throw new RuntimeException(msg);
    }
}
 
源代码28 项目: lams   文件: DrawShape.java
public static Rectangle2D getAnchor(Graphics2D graphics, Rectangle2D anchor) {
    if(graphics == null)  {
        return anchor;
    }

    AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
    if(tx != null && !tx.isIdentity()) {
        anchor = tx.createTransformedShape(anchor).getBounds2D();
    }
    return anchor;
}
 
源代码29 项目: openjdk-8   文件: DrawImage.java
protected void transformImage(SunGraphics2D sg, Image img,
                              AffineTransform tx, int interpType,
                              int sx1, int sy1, int sx2, int sy2,
                              Color bgColor)
{
    // Transform 3 source corners by tx and analyze them
    // for simplified operations (Copy or Scale).  Using
    // 3 points lets us analyze any kind of transform,
    // even transforms that involve very tiny amounts of
    // rotation or skew to see if they degenerate to a
    // simple scale or copy operation within the allowable
    // error bounds.
    // Note that we use (0,0,w,h) instead of (sx1,sy1,sx2,sy2)
    // because the transform is already translated such that
    // the origin is where sx1, sy1 should go.
    double coords[] = new double[6];
    /* index:  0  1    2  3    4  5  */
    /* coord: (0, 0), (w, h), (0, h) */
    coords[2] = sx2 - sx1;
    coords[3] = coords[5] = sy2 - sy1;
    tx.transform(coords, 0, coords, 0, 3);
    // First test if the X coords of the transformed UL
    // and LL points match and that the Y coords of the
    // transformed LR and LL points also match.
    // If they do then it is a "rectilinear" transform and
    // tryCopyOrScale will make sure it is upright and
    // integer-based.
    if (Math.abs(coords[0] - coords[4]) < MAX_TX_ERROR &&
        Math.abs(coords[3] - coords[5]) < MAX_TX_ERROR &&
        tryCopyOrScale(sg, img, sx1, sy1, sx2, sy2,
                       bgColor, interpType, coords))
    {
        return;
    }

    renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor);
}
 
源代码30 项目: osp   文件: BoundedImage.java
/**
 * Draws the bounds around the image.
 *
 * @param panel the drawing panel
 * @param g  the graphics context
 */
private void drawFixedBounds(DrawingPanel panel, Graphics g) {
  Point2D pt = new Point2D.Double(x, y);
  pt = toPixels.transform(pt, pt);
  Shape temp = new Rectangle2D.Double(pt.getX()-width/2, pt.getY()-height/2, width, height);
  computeFixedHotSpots(temp.getBounds2D());
  pixelBounds = temp.getBounds2D();
  if(theta!=0) {
    pixelBounds = AffineTransform.getRotateInstance(-theta, pt.getX(), pt.getY()).createTransformedShape(pixelBounds);
  }
  if(!selected) {
    return;
  }
  Graphics2D g2 = ((Graphics2D) g);
  g2.setPaint(boundsColor);
  g2.draw(pixelBounds);
  if(xyDrag) {
    g2.fillRect((int) hotSpots[CENTER].getX()-delta, (int) hotSpots[CENTER].getY()-delta, d2, d2);
    g2.setColor(edgeColor);
    g2.fillOval((int) hotSpots[CENTER].getX()-1, (int) hotSpots[CENTER].getY()-1, 3, 3);
    g2.setPaint(boundsColor);
  }
  if(rotateDrag) {
    g2.fillOval((int) hotSpots[CORNER].getX()-delta, (int) hotSpots[CORNER].getY()-delta, d2, d2);
  }
  if(heightDrag) {
    g2.fillRect((int) hotSpots[TOP].getX()-delta, (int) hotSpots[TOP].getY()-delta, d2, d2);
    g2.fillRect((int) hotSpots[BOTTOM].getX()-delta, (int) hotSpots[BOTTOM].getY()-delta, d2, d2);
  }
  if(widthDrag) {
    g2.fillRect((int) hotSpots[LEFT].getX()-delta, (int) hotSpots[LEFT].getY()-delta, d2, d2);
    g2.fillRect((int) hotSpots[RIGHT].getX()-delta, (int) hotSpots[RIGHT].getY()-delta, d2, d2);
  }
  g.setColor(Color.BLACK);
}
 
 类所在包
 同包方法