Java Code Examples for java.awt.geom.AffineTransform

The following are top voted examples for showing how to use java.awt.geom.AffineTransform. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: litiengine   File: CombatEntityVision.java   View source code 6 votes vote down vote up
@Override
public void renderFogOfWar(final Graphics2D g) {
  if (this.fogOfWar == null) {
    return;
  }

  final AffineTransform oldTransform = g.getTransform();
  final AffineTransform at = new AffineTransform();
  at.scale(Game.getCamera().getRenderScale(), Game.getCamera().getRenderScale());
  at.translate(Game.getCamera().getPixelOffsetX(), Game.getCamera().getPixelOffsetY());

  g.setTransform(at);
  g.setColor(FogOfWarColor);
  g.fill(this.fogOfWar);
  g.setTransform(oldTransform);
}
 
Example 2
Project: OpenJSharp   File: PSPrinterJob.java   View source code 6 votes vote down vote up
protected void deviceFill(PathIterator pathIter, Color color,
                          AffineTransform tx, Shape clip) {

    setTransform(tx);
    setClip(clip);
    setColor(color);
    convertToPSPath(pathIter);
    /* Specify the path to fill as the clip, this ensures that only
     * pixels which are inside the path will be filled, which is
     * what the Java 2D APIs specify
     */
    mPSStream.println(GSAVE_STR);
    selectClipPath();
    fillPath();
    mPSStream.println(GRESTORE_STR + " " + NEWPATH_STR);
}
 
Example 3
Project: openjdk-jdk10   File: TestInvertMethods.java   View source code 6 votes vote down vote up
public static boolean compare(AffineTransform at1, AffineTransform at2) {
    maxulps = Math.max(maxulps, ulps(at1.getScaleX(), at2.getScaleX()));
    maxulps = Math.max(maxulps, ulps(at1.getScaleY(), at2.getScaleY()));
    maxulps = Math.max(maxulps, ulps(at1.getShearX(), at2.getShearX()));
    maxulps = Math.max(maxulps, ulps(at1.getShearY(), at2.getShearY()));
    maxtxulps = Math.max(maxtxulps,
                         ulps(at1.getTranslateX(), at2.getTranslateX()));
    maxtxulps = Math.max(maxtxulps,
                         ulps(at1.getTranslateY(), at2.getTranslateY()));
    return (getModifiedType(at1) == getModifiedType(at2) &&
            (compare(at1.getScaleX(), at2.getScaleX(), MAX_ULPS)) &&
            (compare(at1.getScaleY(), at2.getScaleY(), MAX_ULPS)) &&
            (compare(at1.getShearX(), at2.getShearX(), MAX_ULPS)) &&
            (compare(at1.getShearY(), at2.getShearY(), MAX_ULPS)) &&
            (compare(at1.getTranslateX(),
                     at2.getTranslateX(), MAX_TX_ULPS)) &&
            (compare(at1.getTranslateY(),
                     at2.getTranslateY(), MAX_TX_ULPS)));
}
 
Example 4
Project: OpenJSharp   File: AffineTransformOp.java   View source code 6 votes vote down vote up
/**
 * Construct AffineTransformOp with the given xform and rendering hints.
 * 
 * @param xform AffineTransform that will applied to the source image
 * @param hints rendering hints that will be used during transformation
 * @throws ImagingOpException if the transform matrix is noninvertible
 */
public AffineTransformOp (AffineTransform xform, RenderingHints hints)
{
  this.transform = xform;
  this.hints = hints;
  if (xform.getDeterminant() == 0)
    throw new ImagingOpException(null);
}
 
Example 5
Project: WordnetLoom   File: ViwnVertexRenderer.java   View source code 6 votes vote down vote up
private void drawFrame(GraphicsDecorator g, Shape shape, Color color, Point2D.Float pos) {
    Shape old_clip = g.getClip();
    AffineTransform old = g.getTransform();
    AffineTransform t = g.getTransform();
    t.concatenate(AffineTransform.getTranslateInstance(pos.x, pos.y));
    g.setTransform(t);
    g.setColor(color);
    Stroke old_stroke = g.getStroke();
    g.setStroke(new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    Area a = new Area(g.getClip());
    a.subtract(new Area(shape));
    g.setClip(a);
    g.draw(shape);
    g.setTransform(old);
    g.setStroke(old_stroke);
    g.setClip(old_clip);
}
 
Example 6
Project: sumo   File: GeometryImage.java   View source code 6 votes vote down vote up
/**
 * Modify the GeometricLayer so the layer coordinate system matches the image coordinate system ("pixel" projection).
 */
public static GeometryImage createImageProjected(GeometryImage layer, AffineTransform geoTransform) {
    for(Geometry geom:layer.geoms){
        for(Coordinate pos:geom.getCoordinates()){
            Point2D.Double temp=new Point2D.Double();
            try {
	geoTransform.inverseTransform(new Point2D.Double(pos.x, pos.y),temp);
} catch (NoninvertibleTransformException e) {
	e.printStackTrace();
}
            pos.x=temp.x;
            pos.y=temp.y;
        }
    }
    return layer;
}
 
Example 7
Project: defense-solutions-proofs-of-concept   File: RotatableImagePanel.java   View source code 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    //center of rotation is center of the panel
    int xRot = this.getWidth() / 2;
    int yRot = this.getHeight() / 2;
    newXform.rotate((2 * Math.PI) - currentAngle, xRot, yRot);
    g2d.setTransform(newXform);
    //draw image centered in panel
    int x = (getWidth() - image.getWidth(this)) / 2;
    int y = (getHeight() - image.getHeight(this)) / 2;
    g2d.drawImage(image, x, y, this);
    g2d.setTransform(origXform);
}
 
Example 8
Project: jdk8u-jdk   File: RenderingEngine.java   View source code 6 votes vote down vote up
public AATileGenerator getAATileGenerator(Shape s,
                                          AffineTransform at,
                                          Region clip,
                                          BasicStroke bs,
                                          boolean thin,
                                          boolean normalize,
                                          int bbox[])
{
    System.out.println(name+".getAATileGenerator("+
                       s.getClass().getName()+", "+
                       at+", "+
                       clip+", "+
                       bs+", "+
                       (thin ? "thin" : "wide")+", "+
                       (normalize ? "normalized" : "pure")+")");
    return target.getAATileGenerator(s, at, clip,
                                     bs, thin, normalize,
                                     bbox);
}
 
Example 9
Project: geomapapp   File: GMAProfile.java   View source code 6 votes vote down vote up
public void draw(Graphics2D g) {
	arc = null;;
	arc2 = null;;
	if( path==null)return;
	AffineTransform at = g.getTransform();
	if( !enabled || line==null) return;
	g.setStroke( new BasicStroke(4.f/(float)map.getZoom()) );
	g.setColor(Color.white);
	g.draw( path );
	double wrap = map.getWrap();
	if( wrap>0.) {
		g.translate(wrap, 0.);
		g.draw( path );
	}
	g.setTransform(at);
}
 
Example 10
Project: jdk8u-jdk   File: RenderingEngine.java   View source code 6 votes vote down vote up
public void strokeTo(Shape src,
                     AffineTransform at,
                     BasicStroke bs,
                     boolean thin,
                     boolean normalize,
                     boolean antialias,
                     PathConsumer2D consumer)
{
    System.out.println(name+".strokeTo("+
                       src.getClass().getName()+", "+
                       at+", "+
                       bs+", "+
                       (thin ? "thin" : "wide")+", "+
                       (normalize ? "normalized" : "pure")+", "+
                       (antialias ? "AA" : "non-AA")+", "+
                       consumer.getClass().getName()+")");
    target.strokeTo(src, at, bs, thin, normalize, antialias, consumer);
}
 
Example 11
Project: hearthstone   File: Custo.java   View source code 6 votes vote down vote up
@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);
}
 
Example 12
Project: VASSAL-src   File: FreeRotator.java   View source code 6 votes vote down vote up
public void draw(Graphics g, Map map) {
  if (drawGhost) {
    final Point p = map.componentCoordinates(getGhostPosition());

    final Graphics2D g2d = (Graphics2D) g.create();
    g2d.transform(
       AffineTransform.getRotateInstance(-PI_180 * tempAngle,
                                         p.x + centerX(),
                                         p.y + centerY()));
    g2d.setComposite(
       AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                         RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);
    piece.draw(g2d, p.x, p.y, map.getView(), map.getZoom());
    g2d.dispose();
  }
}
 
Example 13
Project: VASSAL-src   File: Hideable.java   View source code 6 votes vote down vote up
public void draw(Graphics g, int x, int y, Component obs, double zoom) {
  if (invisibleToMe()) {
    return;
  }
  else if (invisibleToOthers()) {
    final Graphics2D g2d = (Graphics2D) g;

    if (bgColor != null) {
      g.setColor(bgColor);
      final AffineTransform t = AffineTransform.getScaleInstance(zoom, zoom);
      t.translate(x / zoom, y / zoom);
      g2d.fill(t.createTransformedShape(piece.getShape()));
    }

    final Composite oldComposite = g2d.getComposite();
    g2d.setComposite(
      AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency)
    );
    piece.draw(g, x, y, obs, zoom);
    g2d.setComposite(oldComposite);
  }
  else {
    piece.draw(g, x, y, obs, zoom);
  }
}
 
Example 14
Project: GazePlay   File: HeatChart.java   View source code 6 votes vote down vote up
private void drawYLabel(Graphics2D chartGraphics) {
    if (yAxisLabel != null) {
        // Strings are drawn from the baseline position of the leftmost char.
        int yPosYAxisLabel = heatMapC.y + (yAxisLabelSize.width / 2);
        int xPosYAxisLabel = (margin / 2) + yAxisLabelAscent;

        chartGraphics.setFont(axisLabelsFont);
        chartGraphics.setColor(axisLabelColour);

        // Create 270 degree rotated transform.
        AffineTransform transform = chartGraphics.getTransform();
        AffineTransform originalTransform = (AffineTransform) transform.clone();
        transform.rotate(Math.toRadians(270), xPosYAxisLabel, yPosYAxisLabel);
        chartGraphics.setTransform(transform);

        // Draw string.
        chartGraphics.drawString(yAxisLabel, xPosYAxisLabel, yPosYAxisLabel);

        // Revert to original transform before rotation.
        chartGraphics.setTransform(originalTransform);
    }
}
 
Example 15
Project: jdk8u-jdk   File: Font2D.java   View source code 6 votes vote down vote up
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;
    }
}
 
Example 16
Project: opencron   File: ImageUtils.java   View source code 6 votes vote down vote up
public ImageUtils reverse(boolean isVertical){
    int width = this.dealedImage.getWidth();
    int height = this.dealedImage.getHeight();
    double[] matrix;
    if(isVertical){
        matrix = new double[]{1, 0, 0, -1, 0,height};
    }else {
        matrix = new double[]{-1, 0, 0, 1,width,0};
    }
    AffineTransform affineTransform = new AffineTransform(matrix);
    BufferedImage newImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = newImg.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawRenderedImage(this.dealedImage, affineTransform);
    g.dispose();
    this.dealedImage = newImg;

    return this;
}
 
Example 17
Project: jmonet   File: TransformableSelection.java   View source code 6 votes vote down vote up
/**
 * Applies an AffineTransform the current image.
 * @param transform The transform to apply.
 */
default void applyTransform(AffineTransform transform) {
    if (hasSelection()) {
        setDirty();

        // Get the original location of the selection
        Point originalLocation = getSelectionLocation();

        // Transform the selected image
        setSelectedImage(Transform.transform(getSelectedImage(), transform));

        // Relocate the image to its original location
        Rectangle newBounds = getSelectedImage().getRaster().getBounds();
        newBounds.setLocation(originalLocation);
        setSelectionOutline(newBounds);

        redrawSelection();
    }
}
 
Example 18
Project: openjdk-jdk10   File: TransformBlit.java   View source code 5 votes vote down vote up
public void Transform(SurfaceData src, SurfaceData dst,
                      Composite comp, Region clip,
                      AffineTransform at, int hint,
                      int srcx, int srcy, int dstx, int dsty,
                      int width, int height)
{
    tracePrimitive(target);
    target.Transform(src, dst, comp, clip, at, hint,
                     srcx, srcy, dstx, dsty, width, height);
}
 
Example 19
Project: openjdk-jdk10   File: SynthPainterImpl.java   View source code 5 votes vote down vote up
/**
 * Paints the background of an arrow button. Arrow buttons are created by
 * some components, such as <code>JScrollBar</code>.
 *
 * @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 paintArrowButtonBackground(SynthContext context,
                                       Graphics g, int x, int y,
                                       int w, int h) {
    if (context.getComponent().getComponentOrientation().isLeftToRight()){
        paintBackground(context, g, x, y, w, h, null);
    } else {
        AffineTransform transform = new AffineTransform();
        transform.translate(x,y);
        transform.scale(-1, 1);
        transform.translate(-w,0);
        paintBackground(context, g, 0, 0, w, h, transform);
    }
}
 
Example 20
Project: OpenJSharp   File: OGLBlitLoops.java   View source code 5 votes vote down vote up
public void Transform(SurfaceData src, SurfaceData dst,
                      Composite comp, Region clip,
                      AffineTransform at, int hint,
                      int sx, int sy, int dx, int dy, int w, int h)
{
    OGLBlitLoops.Blit(src, dst,
                      comp, clip, at, hint,
                      sx, sy, sx+w, sy+h,
                      dx, dy, dx+w, dy+h,
                      typeval, false);
}
 
Example 21
Project: jdk8u-jdk   File: AttributeValues.java   View source code 5 votes vote down vote up
public static AffineTransform getCharTransform(Map<?, ?> map) {
    if (map != null) {
        AttributeValues av = null;
        if (map instanceof AttributeMap &&
            ((AttributeMap) map).getValues() != null) {
            av = ((AttributeMap)map).getValues();
        } else if (map.get(TextAttribute.TRANSFORM) != null) {
            av = AttributeValues.fromMap((Map<Attribute, ?>)map); // yuck
        }
        if (av != null) {
            return av.charTransform;
        }
    }
    return null;
}
 
Example 22
Project: openaudible   File: StandardImageHandler.java   View source code 5 votes vote down vote up
/**
 * Resize image using Java 2D
 *
 * @param artwork
 * @param size
 * @throws java.io.IOException
 */
public void makeSmaller(Artwork artwork, int size) throws IOException {
    Image srcImage = (Image) artwork.getImage();

    int w = srcImage.getWidth(null);
    int h = srcImage.getHeight(null);

    // Determine the scaling required to get desired result.
    float scaleW = (float) size / (float) w;
    float scaleH = (float) size / (float) h;

    //Create an image buffer in which to paint on, create as an opaque Rgb type image, it doesnt matter what type
    //the original image is we want to convert to the best type for displaying on screen regardless
    BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);

    // Set the scale.
    AffineTransform tx = new AffineTransform();
    tx.scale(scaleW, scaleH);

    // Paint image.
    Graphics2D g2d = bi.createGraphics();
    g2d.drawImage(srcImage, tx, null);
    g2d.dispose();


    if (artwork.getMimeType() != null && isMimeTypeWritable(artwork.getMimeType())) {
        artwork.setBinaryData(writeImage(bi, artwork.getMimeType()));
    } else {
        artwork.setBinaryData(writeImageAsPng(bi));
    }
}
 
Example 23
Project: jdk8u-jdk   File: D3DBlitLoops.java   View source code 5 votes vote down vote up
public void Transform(SurfaceData src, SurfaceData dst,
                      Composite comp, Region clip,
                      AffineTransform at, int hint,
                      int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.Blit(src, dst,
                      comp, clip, at, hint,
                      sx, sy, sx+w, sy+h,
                      dx, dy, dx+w, dy+h,
                      typeval, false);
}
 
Example 24
Project: OpenJSharp   File: StandardGlyphVector.java   View source code 5 votes vote down vote up
AffineTransform getGlyphTransform(int ix) {
    int index = indices[ix];
    if (index == 0) {
        return null;
    }

    int x = (index - 1) * 6;
    return new AffineTransform(transforms[x + 0],
                               transforms[x + 1],
                               transforms[x + 2],
                               transforms[x + 3],
                               transforms[x + 4],
                               transforms[x + 5]);
}
 
Example 25
Project: jdk8u-jdk   File: NormalizingTransformTest.java   View source code 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();
    AffineTransform normTransform = gc.getNormalizingTransform();
    int dpiX = Toolkit.getDefaultToolkit().getScreenResolution();
    int normDpiX = (int)(normTransform.getScaleX() * 72.0);
    if (dpiX != normDpiX) {
        throw new RuntimeException(
            "Test FAILED. Toolkit.getScreenResolution()=" + dpiX +
            " GraphicsConfiguration.getNormalizingTransform()="+normDpiX);
    }
    System.out.println("Test PASSED. DPI="+normDpiX);
}
 
Example 26
Project: openjdk-jdk10   File: SwingUtilities2.java   View source code 5 votes vote down vote up
private static FontRenderContext getFRCFromCache(AffineTransform tx,
                                                 Object aaHint) {
    if (tx == null && aaHint == null) {
        return null;
    }

    @SuppressWarnings("unchecked")
    Map<Object, FontRenderContext> cache = (Map<Object, FontRenderContext>)
            AppContext.getAppContext().get(APP_CONTEXT_FRC_CACHE_KEY);

    if (cache == null) {
        cache = new HashMap<>();
        AppContext.getAppContext().put(APP_CONTEXT_FRC_CACHE_KEY, cache);
    }

    Object key = (tx == null)
            ? aaHint
            : (aaHint == null ? tx : new KeyPair(tx, aaHint));

    FontRenderContext frc = cache.get(key);
    if (frc == null) {
        aaHint = (aaHint == null) ? VALUE_TEXT_ANTIALIAS_OFF : aaHint;
        frc = new FontRenderContext(tx, aaHint,
                                    VALUE_FRACTIONALMETRICS_DEFAULT);
        cache.put(key, frc);
    }
    return frc;
}
 
Example 27
Project: openjdk-jdk10   File: WTrayIconPeer.java   View source code 5 votes vote down vote up
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();
    AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            getDefaultTransform();
    int w = Region.clipScale(TRAY_ICON_WIDTH, tx.getScaleX());
    int h = Region.clipScale(TRAY_ICON_HEIGHT, tx.getScaleY());
    int imgWidth = Region.clipScale(image.getWidth(observer), tx.getScaleX());
    int imgHeight = Region.clipScale(image.getHeight(observer), tx.getScaleY());
    BufferedImage bufImage = new BufferedImage(w,
            h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? w : imgWidth),
                         (autosize ? h : imgHeight), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
Example 28
Project: OpenJSharp   File: DrawImage.java   View source code 5 votes vote down vote up
public boolean transformImage(SunGraphics2D sg, Image img,
                              AffineTransform atfm,
                              ImageObserver observer) {
    if (!(img instanceof ToolkitImage)) {
        transformImage(sg, img, 0, 0, atfm, sg.interpolationType);
        return true;
    } else {
        ToolkitImage sunimg = (ToolkitImage)img;
        if (!imageReady(sunimg, observer)) {
            return false;
        }
        ImageRepresentation ir = sunimg.getImageRep();
        return ir.drawToBufImage(sg, sunimg, atfm, observer);
    }
}
 
Example 29
Project: openjdk-jdk10   File: TextLine.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 30
Project: OpenJSharp   File: SunGraphics2D.java   View source code 5 votes vote down vote up
public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) {
    surfaceData = sd;
    foregroundColor = fg;
    backgroundColor = bg;

    transform = new AffineTransform();
    stroke = defaultStroke;
    composite = defaultComposite;
    paint = foregroundColor;

    imageComp = CompositeType.SrcOverNoEa;

    renderHint = SunHints.INTVAL_RENDER_DEFAULT;
    antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
    textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
    fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
    lcdTextContrast = lcdTextContrastDefaultValue;
    interpolationHint = -1;
    strokeHint = SunHints.INTVAL_STROKE_DEFAULT;
    resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT;

    interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;

    validateColor();

    devScale = sd.getDefaultScale();
    if (devScale != 1) {
        transform.setToScale(devScale, devScale);
        invalidateTransform();
    }

    font = f;
    if (font == null) {
        font = defaultFont;
    }

    setDevClip(sd.getBounds());
    invalidatePipe();
}
 
Example 31
Project: Pogamut3   File: ShedWidget.java   View source code 5 votes vote down vote up
private void drawFittingString(int x, int y, String text, Graphics2D gr, FontMetrics fm) {
    AffineTransform originalTransform = gr.getTransform();
    gr.translate(x, y);
    String fittingText = getFittingString(text, fm, ShedWidget.width);
    gr.drawString(fittingText, 0, 0);
    gr.setTransform(originalTransform);
}
 
Example 32
Project: geomapapp   File: WWMGG.java   View source code 5 votes vote down vote up
protected void setCurrentSegment(GeneralPath path) {
	if (currentSegment != null)
		trackLayer.removeRenderable( currentSegment );
	
	if (path == null)
	{
		currentSegment = null;
		return;
	}
	
	PathIterator pi =
		path.getPathIterator(new AffineTransform());
	List<LatLon> pos = new LinkedList<LatLon>();

	float [] coords = new float[6];
	int t = pi.currentSegment(coords);
	pos.add( LatLon.fromDegrees(coords[1], coords[0]));
	while (!pi.isDone())
	{
		t = pi.currentSegment(coords);
		if (t == PathIterator.SEG_LINETO && 
				!(coords[1] == 0 && coords[0]==0))
			pos.add( LatLon.fromDegrees(coords[1], coords[0]));
		
		pi.next();
	}
	
	Polyline line = new Polyline(pos, 0);
	line.setLineWidth(4);
	line.setFollowTerrain(true);
	line.setColor( Color.red );
	trackLayer.addRenderable(line);
	currentSegment = line;
	
}
 
Example 33
Project: jdk8u-jdk   File: PeekGraphics.java   View source code 5 votes vote down vote up
public void drawRenderableImage(RenderableImage img,
                                AffineTransform xform) {

    if (img == null) {
        return;
    }

    mPrintMetrics.drawImage(this, img);
    mDrawingArea.addInfinite();
}
 
Example 34
Project: jdk8u-jdk   File: TextSourceLabel.java   View source code 5 votes vote down vote up
public AffineTransform getBaselineTransform() {
    Font font = source.getFont();
    if (font.hasLayoutAttributes()) {
        return AttributeValues.getBaselineTransform(font.getAttributes());
    }
    return null;
}
 
Example 35
Project: openjdk-jdk10   File: PeekGraphics.java   View source code 5 votes vote down vote up
public void drawRenderableImage(RenderableImage img,
                                AffineTransform xform) {

    if (img == null) {
        return;
    }

    mPrintMetrics.drawImage(this, img);
    mDrawingArea.addInfinite();
}
 
Example 36
Project: jdk8u-jdk   File: TransformHelper.java   View source code 5 votes vote down vote up
public native void Transform(MaskBlit output,
SurfaceData src, SurfaceData dst,
Composite comp, Region clip,
AffineTransform itx, int txtype,
int sx1, int sy1, int sx2, int sy2,
int dx1, int dy1, int dx2, int dy2,
int edges[], int dxoff, int dyoff);
 
Example 37
Project: openjdk-jdk10   File: DrawRotatedStringUsingRotatedFont.java   View source code 5 votes vote down vote up
public static void main(final String[] args) throws IOException {
    for (final AffineTransform tx2 : txs) {
        for (final AffineTransform tx1 : txs) {
            for (final boolean aa : new boolean[]{true, false}) {
                final BufferedImage bi1 = createImage(aa, tx1, tx2);
                final BufferedImage bi2 = createImage(aa, tx2, tx1);
                compareImage(bi1, bi2);
                fillTextArea(bi1, tx1, tx2);
                fillTextArea(bi2, tx2, tx1);
                checkColors(bi1, bi2);
            }
        }
    }
    System.out.println("Passed");
}
 
Example 38
Project: OpenJSharp   File: SynthPainterImpl.java   View source code 5 votes vote down vote up
/**
 * Paints the background 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 paintTextFieldBackground(SynthContext context,
                                      Graphics g, int x, int y,
                                      int w, int h) {
    if (context.getComponent().getComponentOrientation().isLeftToRight()){
        paintBackground(context, g, x, y, w, h, null);
    } else {
        AffineTransform transform = new AffineTransform();
        transform.translate(x,y);
        transform.scale(-1, 1);
        transform.translate(-w,0);
        paintBackground(context, g, 0, 0, w, h, transform);
    }
}
 
Example 39
Project: OpenJSharp   File: WPathGraphics.java   View source code 5 votes vote down vote up
@Override
protected int platformFontCount(Font font, String str) {

    AffineTransform deviceTransform = getTransform();
    AffineTransform fontTransform = new AffineTransform(deviceTransform);
    fontTransform.concatenate(getFont().getTransform());
    int transformType = fontTransform.getType();

    /* Test if GDI can handle the transform */
    boolean directToGDI = ((transformType !=
                           AffineTransform.TYPE_GENERAL_TRANSFORM)
                           && ((transformType & AffineTransform.TYPE_FLIP)
                               == 0));

    if (!directToGDI) {
        return 0;
    }

    /* Since all windows fonts are available, and the JRE fonts
     * are also registered. Only the Font.createFont() case is presently
     * unknown to GDI. Those can be registered too, although that
     * code does not exist yet, it can be added too, so we should not
     * fail that case. Just do a quick check whether its a TrueTypeFont
     * - ie not a Type1 font etc, and let drawString() resolve the rest.
     */
    Font2D font2D = FontUtilities.getFont2D(font);
    if (font2D instanceof CompositeFont ||
        font2D instanceof TrueTypeFont) {
        return 1;
    } else {
        return 0;
    }
}
 
Example 40
Project: geomapapp   File: ImageComponent.java   View source code 5 votes vote down vote up
public void rotate( Point2D center, double angle ) {
	BufferedImage im = new BufferedImage( width, height, image.TYPE_INT_RGB);
	Graphics2D g = im.createGraphics();
	AffineTransform at = new AffineTransform();
	at.rotate( -angle, center.getX(), center.getY() );
	g.drawRenderedImage( image, at);
	image = im;
	repaint();
}