Java Code Examples for java.awt.geom.AffineTransform#clone()

The following examples show how to use java.awt.geom.AffineTransform#clone() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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 2
Source Project: hottub   File: Font2D.java    License: GNU General Public License v2.0 5 votes vote down vote up
public FontStrike getStrike(Font font, AffineTransform devTx,
                            int aa, int fm) {

    /* Create the descriptor which is used to identify a strike
     * in the strike cache/map. A strike is fully described by
     * the attributes of this descriptor.
     */
    /* REMIND: generating garbage and doing computation here in order
     * to include pt size in the tx just for a lookup! Figure out a
     * better way.
     */
    double ptSize = font.getSize2D();
    AffineTransform glyphTx = (AffineTransform)devTx.clone();
    glyphTx.scale(ptSize, ptSize);
    if (font.isTransformed()) {
        glyphTx.concatenate(font.getTransform());
    }
    if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) {
        glyphTx.setTransform(glyphTx.getScaleX(),
                             glyphTx.getShearY(),
                             glyphTx.getShearX(),
                             glyphTx.getScaleY(),
                             0.0, 0.0);
    }
    FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx,
                                             font.getStyle(), aa, fm);
    return getStrike(desc, false);
}
 
Example 3
Source Project: jdk8u-jdk   File: Font2D.java    License: GNU General Public License v2.0 5 votes vote down vote up
public FontStrike getStrike(Font font, AffineTransform devTx,
                            int aa, int fm) {

    /* Create the descriptor which is used to identify a strike
     * in the strike cache/map. A strike is fully described by
     * the attributes of this descriptor.
     */
    /* REMIND: generating garbage and doing computation here in order
     * to include pt size in the tx just for a lookup! Figure out a
     * better way.
     */
    double ptSize = font.getSize2D();
    AffineTransform glyphTx = (AffineTransform)devTx.clone();
    glyphTx.scale(ptSize, ptSize);
    if (font.isTransformed()) {
        glyphTx.concatenate(font.getTransform());
    }
    if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) {
        glyphTx.setTransform(glyphTx.getScaleX(),
                             glyphTx.getShearY(),
                             glyphTx.getShearX(),
                             glyphTx.getScaleY(),
                             0.0, 0.0);
    }
    FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx,
                                             font.getStyle(), aa, fm);
    return getStrike(desc, false);
}
 
Example 4
/**
 * 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;
}
 
Example 5
private void outString_bak(Graphics2D g, int x, int y, String s, XAlign x_align, YAlign y_align, float angle) {
        switch (y_align) {
            case TOP:
                y += g.getFontMetrics(g.getFont()).getAscent();
                break;
            case CENTER:
                y += g.getFontMetrics(g.getFont()).getAscent() / 2;
                break;
        }
        Dimension labSize = Draw.getStringDimension(s, g);
        switch (x_align) {
            case RIGHT:
                x = x - labSize.width;
                break;
            case CENTER:
                x = x - labSize.width / 2;
                break;
        }

        AffineTransform tempTrans = g.getTransform();
        //AffineTransform myTrans = new AffineTransform();
        AffineTransform myTrans = (AffineTransform)tempTrans.clone();
        myTrans.translate(x, y);
        myTrans.rotate(-angle * Math.PI / 180);
        g.setTransform(myTrans);
        x = 0; y = 0;
//        if (angle == 90) {
//            x = -(int) (labSize.getWidth() - 10);
//            y = (int) (labSize.getHeight() / 3);
//        } else {
//            x = -(int) (labSize.getWidth() - 5);
//            y = 0;
//        }
        Draw.drawString(g, s, x, y);
        g.setTransform(tempTrans);
    }
 
Example 6
Source Project: lams   File: FcscoreBox.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void draw(Graphics2D g2, float x, float y) {
    AffineTransform transf = g2.getTransform();
    Stroke oldStroke = g2.getStroke();

    final double sx = transf.getScaleX();
    final double sy = transf.getScaleY();
    double s = 1;
    if (sx == sy) {
        // There are rounding problems due to scale factor: lines could have different
        // spacing...
        // So the increment (space+thickness) is done in using integer.
        s = sx;
        AffineTransform t = (AffineTransform) transf.clone();
        t.scale(1 / sx, 1 / sy);
        g2.setTransform(t);
    }

    g2.setStroke(new BasicStroke((float) (s * thickness), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    float th = thickness / 2.f;
    final Line2D.Float line = new Line2D.Float();
    float xx = x + space;
    xx = (float) (xx * s + (space / 2.f) * s);
    final int inc = (int) Math.round((space + thickness) * s);

    for (int i = 0; i < N; i++) {
        line.setLine(xx + th * s, (y - height) * s, xx + th * s, y * s);
        g2.draw(line);
        xx += inc;
    }

    if (strike) {

        line.setLine((x + space) * s, (y - height / 2.f) * s, xx - s * space / 2, (y - height / 2.f) * s);
        g2.draw(line);
    }

    g2.setTransform(transf);
    g2.setStroke(oldStroke);
}
 
Example 7
Source Project: JDKSourceCode1.8   File: AffineTransformOp.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
/**
 * Constructs an <CODE>AffineTransformOp</CODE> given an affine transform.
 * The interpolation type is determined from the
 * <CODE>RenderingHints</CODE> object.  If the interpolation hint is
 * defined, it will be used. Otherwise, if the rendering quality hint is
 * defined, the interpolation type is determined from its value.  If no
 * hints are specified (<CODE>hints</CODE> is null),
 * the interpolation type is {@link #TYPE_NEAREST_NEIGHBOR
 * TYPE_NEAREST_NEIGHBOR}.
 *
 * @param xform The <CODE>AffineTransform</CODE> to use for the
 * operation.
 *
 * @param hints The <CODE>RenderingHints</CODE> object used to specify
 * the interpolation type for the operation.
 *
 * @throws ImagingOpException if the transform is non-invertible.
 * @see java.awt.RenderingHints#KEY_INTERPOLATION
 * @see java.awt.RenderingHints#KEY_RENDERING
 */
public AffineTransformOp(AffineTransform xform, RenderingHints hints){
    validateTransform(xform);
    this.xform = (AffineTransform) xform.clone();
    this.hints = hints;

    if (hints != null) {
        Object value = hints.get(hints.KEY_INTERPOLATION);
        if (value == null) {
            value = hints.get(hints.KEY_RENDERING);
            if (value == hints.VALUE_RENDER_SPEED) {
                interpolationType = TYPE_NEAREST_NEIGHBOR;
            }
            else if (value == hints.VALUE_RENDER_QUALITY) {
                interpolationType = TYPE_BILINEAR;
            }
        }
        else if (value == hints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) {
            interpolationType = TYPE_NEAREST_NEIGHBOR;
        }
        else if (value == hints.VALUE_INTERPOLATION_BILINEAR) {
            interpolationType = TYPE_BILINEAR;
        }
        else if (value == hints.VALUE_INTERPOLATION_BICUBIC) {
            interpolationType = TYPE_BICUBIC;
        }
    }
    else {
        interpolationType = TYPE_NEAREST_NEIGHBOR;
    }
}
 
Example 9
private static void drawPoint_Character(PointF aP, PointBreak aPB, Graphics2D g) {
    AffineTransform tempTrans = g.getTransform();
    if (aPB.getAngle() != 0) {
        //AffineTransform myTrans = new AffineTransform();
        AffineTransform myTrans = (AffineTransform) tempTrans.clone();
        myTrans.translate(aP.X, aP.Y);
        myTrans.rotate(aPB.getAngle() * Math.PI / 180);
        g.setTransform(myTrans);
        aP.X = 0;
        aP.Y = 0;
    }

    String text = String.valueOf((char) aPB.getCharIndex());
    Font wFont = new Font(aPB.getFontName(), Font.PLAIN, (int) aPB.getSize());
    g.setFont(wFont);
    FontMetrics metrics = g.getFontMetrics();
    PointF sPoint = (PointF) aP.clone();
    sPoint.X = sPoint.X - metrics.stringWidth(text) / 2;
    sPoint.Y = sPoint.Y + metrics.getHeight() / 4;
    //sPoint.X = sPoint.X - aPB.getSize() / 2;
    //sPoint.Y = sPoint.Y + aPB.getSize() / 2;        

    g.setColor(aPB.getColor());
    g.drawString(text, sPoint.X, sPoint.Y);

    if (aPB.getAngle() != 0) {
        g.setTransform(tempTrans);
    }
}
 
Example 10
/**
 * Constructs an {@code AffineTransformOp} given an affine transform
 * and the interpolation type.
 *
 * @param xform The {@code AffineTransform} 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;
}
 
Example 11
Source Project: Java8CN   File: AffineTransformOp.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source Project: jdk8u_jdk   File: Font2D.java    License: GNU General Public License v2.0 5 votes vote down vote up
public FontStrike getStrike(Font font, AffineTransform devTx,
                            int aa, int fm) {

    /* Create the descriptor which is used to identify a strike
     * in the strike cache/map. A strike is fully described by
     * the attributes of this descriptor.
     */
    /* REMIND: generating garbage and doing computation here in order
     * to include pt size in the tx just for a lookup! Figure out a
     * better way.
     */
    double ptSize = font.getSize2D();
    AffineTransform glyphTx = (AffineTransform)devTx.clone();
    glyphTx.scale(ptSize, ptSize);
    if (font.isTransformed()) {
        glyphTx.concatenate(font.getTransform());
    }
    if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) {
        glyphTx.setTransform(glyphTx.getScaleX(),
                             glyphTx.getShearY(),
                             glyphTx.getShearX(),
                             glyphTx.getScaleY(),
                             0.0, 0.0);
    }
    FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx,
                                             font.getStyle(), aa, fm);
    return getStrike(desc, false);
}
 
Example 13
/**
 * 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;
}
 
Example 14
Source Project: JDKSourceCode1.8   File: AffineTransformOp.java    License: MIT License 5 votes vote down vote up
/**
 * Constructs an <CODE>AffineTransformOp</CODE> given an affine transform.
 * The interpolation type is determined from the
 * <CODE>RenderingHints</CODE> object.  If the interpolation hint is
 * defined, it will be used. Otherwise, if the rendering quality hint is
 * defined, the interpolation type is determined from its value.  If no
 * hints are specified (<CODE>hints</CODE> is null),
 * the interpolation type is {@link #TYPE_NEAREST_NEIGHBOR
 * TYPE_NEAREST_NEIGHBOR}.
 *
 * @param xform The <CODE>AffineTransform</CODE> to use for the
 * operation.
 *
 * @param hints The <CODE>RenderingHints</CODE> object used to specify
 * the interpolation type for the operation.
 *
 * @throws ImagingOpException if the transform is non-invertible.
 * @see java.awt.RenderingHints#KEY_INTERPOLATION
 * @see java.awt.RenderingHints#KEY_RENDERING
 */
public AffineTransformOp(AffineTransform xform, RenderingHints hints){
    validateTransform(xform);
    this.xform = (AffineTransform) xform.clone();
    this.hints = hints;

    if (hints != null) {
        Object value = hints.get(hints.KEY_INTERPOLATION);
        if (value == null) {
            value = hints.get(hints.KEY_RENDERING);
            if (value == hints.VALUE_RENDER_SPEED) {
                interpolationType = TYPE_NEAREST_NEIGHBOR;
            }
            else if (value == hints.VALUE_RENDER_QUALITY) {
                interpolationType = TYPE_BILINEAR;
            }
        }
        else if (value == hints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) {
            interpolationType = TYPE_NEAREST_NEIGHBOR;
        }
        else if (value == hints.VALUE_INTERPOLATION_BILINEAR) {
            interpolationType = TYPE_BILINEAR;
        }
        else if (value == hints.VALUE_INTERPOLATION_BICUBIC) {
            interpolationType = TYPE_BICUBIC;
        }
    }
    else {
        interpolationType = TYPE_NEAREST_NEIGHBOR;
    }
}
 
Example 15
Source Project: pumpernickel   File: MutablePath.java    License: MIT License 5 votes vote down vote up
public MutablePathIterator(List<List<MutablePathSegment>> pathList,
		int windingRule, AffineTransform transform, Object syncLock) {
	winding = windingRule;
	if (transform != null) {
		t = (AffineTransform) transform.clone();
	} else {
		t = null;
	}
	synchronizeAgainst = syncLock;
	paths = pathList;
}
 
Example 16
/**
 * Draw text
 *
 * @param g Graphics2D
 * @param x X
 * @param y Y
 */
public void draw(Graphics2D g, float x, float y) {
    Dimension dim = this.getDimension(g);
    x += this.xShift;
    y += this.yShift;

    AffineTransform tempTrans = g.getTransform();
    if (this.angle != 0) {
        //AffineTransform myTrans = new AffineTransform();
        AffineTransform myTrans = (AffineTransform) tempTrans.clone();
        myTrans.translate(x, y);
        //myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
        myTrans.rotate(-angle * Math.PI / 180);
        g.setTransform(myTrans);
        x = 0;
        y = 0;
    }

    Rectangle.Double rect = new Rectangle.Double(x, y - dim.getHeight(), dim.getWidth(), dim.getHeight());
    rect.setRect(rect.x - gap, rect.y - gap, rect.width + gap * 2,
            rect.height + gap * 2);
    if (this.drawBackground) {
        g.setColor(this.background);
        g.fill(rect);
    }
    if (this.drawNeatline) {
        g.setColor(this.neatLineColor);
        Stroke oldStroke = g.getStroke();
        g.setStroke(new BasicStroke(neatLineSize));
        g.draw(rect);
        g.setStroke(oldStroke);
    }

    g.setColor(this.color);
    g.setFont(font);
    switch (this.yAlign) {
        case BOTTOM:
            y = y - dim.height;
            break;
        case CENTER:
            y = y - dim.height * 0.5f;
            break;
    }

    for (String str : this.text) {
        dim = Draw.getStringDimension(str, g);
        Draw.drawString(g, x, y, str, xAlign, YAlign.TOP, useExternalFont);
        y += dim.height;
        y += this.lineSpace;
    }

    if (this.angle != 0) {
        g.setTransform(tempTrans);
    }
}
 
Example 17
Source Project: sambox   File: RadialShadingContext.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Constructor creates an instance to be used for fill operations.
 *
 * @param shading the shading type to be used
 * @param colorModel the color model to be used
 * @param xform transformation for user to device space
 * @param matrix the pattern matrix concatenated with that of the parent content stream
 * @param deviceBounds the bounds of the area to paint, in device units
 * @throws IOException if there is an error getting the color space or doing color conversion.
 */
public RadialShadingContext(PDShadingType3 shading, ColorModel colorModel,
        AffineTransform xform, Matrix matrix, Rectangle deviceBounds)
                            throws IOException
{
    super(shading, colorModel, xform, matrix);
    this.radialShadingType = shading;
    coords = shading.getCoords().toFloatArray();

    // domain values
    if (this.radialShadingType.getDomain() != null)
    {
        domain = shading.getDomain().toFloatArray();
    }
    else
    {
        // set default values
        domain = new float[] { 0, 1 };
    }

    // extend values
    COSArray extendValues = shading.getExtend();
    if (extendValues != null)
    {
        extend = new boolean[2];
        extend[0] = ((COSBoolean) extendValues.getObject(0)).getValue();
        extend[1] = ((COSBoolean) extendValues.getObject(1)).getValue();
    }
    else
    {
        // set default values
        extend = new boolean[] { false, false };
    }
    // calculate some constants to be used in getRaster
    x1x0 = coords[3] - coords[0];
    y1y0 = coords[4] - coords[1];
    r1r0 = coords[5] - coords[2];
    r0pow2 = Math.pow(coords[2], 2);
    denom = Math.pow(x1x0, 2) + Math.pow(y1y0, 2) - Math.pow(r1r0, 2);
    d1d0 = domain[1] - domain[0];

    try
    {
        // get inverse transform to be independent of current user / device space 
        // when handling actual pixels in getRaster()
        rat = matrix.createAffineTransform().createInverse();
        rat.concatenate(xform.createInverse());
    }
    catch (NoninvertibleTransformException ex)
    {
        LOG.error(ex.getMessage() + ", matrix: " + matrix, ex);
        LOG.error(ex.getMessage(), ex);
    }

    // shading space -> device space
    AffineTransform shadingToDevice = (AffineTransform) xform.clone();
    shadingToDevice.concatenate(matrix.createAffineTransform());

    // worst case for the number of steps is opposite diagonal corners, so use that
    double dist = Math.sqrt(Math.pow(deviceBounds.getMaxX() - deviceBounds.getMinX(), 2)
            + Math.pow(deviceBounds.getMaxY() - deviceBounds.getMinY(), 2));
    factor = (int) Math.ceil(dist);

    // build the color table for the given number of steps
    colorTable = calcColorTable();
}
 
Example 18
/**
 * Draw arraw
 *
 * @param g Graphics2D
 * @param sP Start point
 * @param angle Angle
 * @param length Arrow length
 * @param width Arrow width
 * @param overhang Overhang
 * @param fillColor Arrow fill color
 * @param outlineColor Arrow outline color
 */
public static void drawArraw(Graphics2D g, PointF sP, double angle, float length, float width,
        float overhang, Color fillColor, Color outlineColor) {
    PointF[] pt;
    float x = -length;
    float y = -width * 0.5f;
    //Rectangle.Float rect = new Rectangle.Float(x, y, length, width);
    if (overhang == 1) {
        pt = new PointF[3];
        pt[0] = new PointF(x, y);
        pt[1] = new PointF(x + length, 0);
        pt[2] = new PointF(x, y + width);
    } else {
        pt = new PointF[5];
        pt[0] = new PointF(x, y);
        pt[1] = new PointF(x + length, 0);
        pt[2] = new PointF(x, y + width);
        pt[3] = new PointF(x + length * overhang, pt[1].Y);
        pt[4] = pt[0];
    }
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, pt.length);
    path.moveTo(pt[0].X, pt[0].Y);
    for (int i = 1; i < pt.length; i++) {
        path.lineTo(pt[i].X, pt[i].Y);
    }

    AffineTransform tempTrans = g.getTransform();
    //AffineTransform myTrans = new AffineTransform();
    AffineTransform myTrans = (AffineTransform) tempTrans.clone();
    //myTrans.translate(tempTrans.getTranslateX() + sP.X, tempTrans.getTranslateY() + sP.Y);
    myTrans.translate(sP.X, sP.Y);
    double angle1 = angle - 90;
    if (angle1 != 0) {
        myTrans.rotate(angle1 * Math.PI / 180);
    }
    g.setTransform(myTrans);
    if (overhang == 1) {
        g.setColor(fillColor);
        g.draw(path);
    } else {
        if (fillColor != null) {
            path.closePath();
            g.setColor(fillColor);
            g.fill(path);
        }
        if (outlineColor != null) {
            g.setColor(outlineColor);
            g.draw(path);
        }
    }

    g.setTransform(tempTrans);
}
 
Example 19
/**
 * Graphics transform
 *
 * @param g Graphics2D
 * @param x X location
 * @param y Y location
 * @param s String
 * @param x_align X align
 * @param y_align Y align
 * @param angle Angle
 * @return AffineTransform
 */
public static AffineTransform transform(Graphics2D g, float x, float y, String s, XAlign x_align, YAlign y_align, float angle) {
    Dimension dim = getStringDimension(s, g);
    AffineTransform tempTrans = g.getTransform();
    //AffineTransform myTrans = new AffineTransform();
    AffineTransform myTrans = (AffineTransform) tempTrans.clone();
    switch (x_align) {
        case LEFT:
            switch (y_align) {
                case CENTER:
                    if (angle == 90) {
                        x += (float) (dim.getHeight());
                        y += (float) (dim.getWidth() * 0.5);
                    } else if (angle == -90) {
                        y -= (float) (dim.getWidth() * 0.5);
                    } else if (angle > 0) {
                        x += (float) (dim.getHeight() * Math.abs(Math.sin(Math.toRadians(angle))));
                        y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
                    } else {
                        y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
                    }
                    break;
            }
            break;
        case CENTER:
            switch (y_align) {
                case TOP:
                    if (angle == 90) {
                        x += (float) (dim.getHeight() * 0.5);
                        y += (float) (dim.getWidth());
                    } else if (angle == -90) {
                        x -= (float) (dim.getHeight() * 0.5);
                    } else if (angle > 0) {
                        //x -= (float) (dim.getWidth() * Math.abs(Math.cos(Math.toRadians(angle))));
                        //y += (float) (dim.getWidth() * Math.sin(Math.toRadians(angle))) + dim.getHeight();
                        x -= (float) (dim.getWidth() * Math.abs(Math.cos(Math.toRadians(angle))));
                        y += (float) (dim.getWidth() * Math.sin(Math.toRadians(angle))) + dim.getHeight() * 0.5 * Math.cos(Math.toRadians(angle));
                    } else {
                        //y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
                        y += (float) (dim.getHeight() * Math.abs(Math.cos(Math.toRadians(angle))));
                    }
                    break;
            }
            break;
        case RIGHT:
            switch (y_align) {
                case CENTER:
                    if (angle == 90) {
                        x -= (float) (dim.getHeight());
                        y += (float) (dim.getWidth() * 0.5);
                    } else if (angle == -90) {
                        x -= (float) (dim.getHeight());
                        y -= (float) (dim.getWidth() * 0.5);
                    } else if (angle > 0) {
                        x -= (float) (dim.getWidth() * Math.abs(Math.cos(Math.toRadians(angle))));
                        y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
                    } else {
                        y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
                    }
                    break;
            }
            break;
    }
    //myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
    myTrans.translate(x, y);
    myTrans.rotate(-angle * Math.PI / 180);

    return myTrans;
}
 
Example 20
/**
 * Draw label point
 *
 * @param x X
 * @param y Y
 * @param font Font
 * @param text Text
 * @param color Color
 * @param g Graphics2D
 * @param rect The extent rectangle
 * @param angle Angle
 * @param useExternalFont If use external font
 */
public static void drawLabelPoint(float x, float y, Font font, String text, Color color, float angle,
        Graphics2D g, Rectangle rect, boolean useExternalFont) {
    g.setColor(color);
    g.setFont(font);
    Dimension labSize = Draw.getStringDimension(text, g);
    //FontMetrics metrics = g.getFontMetrics(font);
    //Dimension labSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
    x = x - (float) labSize.getWidth() / 2;
    y -= (float) labSize.getHeight() / 2;

    float inx = x;
    float iny = y;

    AffineTransform tempTrans = g.getTransform();
    if (angle != 0) {
        //AffineTransform myTrans = new AffineTransform();
        AffineTransform myTrans = (AffineTransform) tempTrans.clone();
        myTrans.translate(x, y);
        myTrans.rotate(angle * Math.PI / 180);
        g.setTransform(myTrans);
        x = 0;
        y = 0;
    }

    //g.drawString(text, x, y + metrics.getHeight() / 2);
    Draw.drawString(g, text, x, y + labSize.height / 2, useExternalFont);

    if (rect != null) {
        rect.x = (int) x;
        rect.y = (int) y - labSize.height / 2;
        rect.width = (int) labSize.getWidth();
        rect.height = (int) labSize.getHeight();
    }

    if (angle != 0) {
        g.setTransform(tempTrans);
        if (rect != null) {
            rect.x = (int) inx;
            rect.y = (int) iny;
        }
    }
}