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


Java GeneralPath.createTransformedShape方法代碼示例

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


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

示例1: createArrow

import java.awt.geom.GeneralPath; //導入方法依賴的package包/類
protected Shape createArrow(float fx, float fy, float tx, float ty) {
    float dx = tx - fx;
    float dy = ty - fy;
    float D = (float) Math.sqrt(dx * dx + dy * dy);
    float z = (dx <= 0) ? fx - D : fx + D;
    double alpha = (dx > 0) ? Math.asin(dy / D) : -Math.asin(dy / D);
    float h = arrowHeight;

    int n = (int) (D / h);
    h = D / (float) (n + 1);

    float dec = (dx <= 0) ? h : -h;

    GeneralPath gp = new GeneralPath();
    for (int i = 0; i <= n; i++) {
        gp.moveTo(z + dec, fy - arrowWidth);
        gp.lineTo(z, fy);
        gp.lineTo(z + dec, fy + arrowWidth);
        z += dec;
    }
    gp.closePath();
    AffineTransform affineTransform = new AffineTransform();
    affineTransform.rotate(alpha, fx, fy);
    return gp.createTransformedShape(affineTransform);
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:26,代碼來源:ArrowedStroke.java

示例2: createArrow

import java.awt.geom.GeneralPath; //導入方法依賴的package包/類
protected Shape createArrow(float fx, float fy, float tx, float ty) {
    float dx = tx - fx;
    float dy = ty - fy;
    float D = (float) Math.sqrt(dx * dx + dy * dy);
    float z = (dx <= 0) ? fx - D : fx + D;
    double alpha = (dx > 0) ? Math.asin(dy / D) : -Math.asin(dy / D);
    float h = arrowWidth * 2;

    int n = (int) (D / h);
    h = D / (float) (n + 1);
    if (n < 0)
        n = 0;

    float dec = (dx <= 0) ? h : -h;
    GeneralPath gp = new GeneralPath();
    for (int i = 0; i <= n; i++) {
        gp.moveTo(z + dec, fy - arrowWidth);
        gp.lineTo(z + dec / 2f, fy - arrowWidth);
        gp.lineTo(z, fy);
        gp.lineTo(z + dec / 2f, fy + arrowWidth);
        gp.lineTo(z + dec, fy + arrowWidth);
        gp.lineTo(z + dec / 2f, fy);
        z += dec;
    }
    gp.closePath();
    AffineTransform affineTransform = new AffineTransform();
    affineTransform.rotate(alpha, fx, fy);
    return gp.createTransformedShape(affineTransform);
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:30,代碼來源:WayStroke.java

示例3: drawNeedle

import java.awt.geom.GeneralPath; //導入方法依賴的package包/類
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    GeneralPath shape1 = new GeneralPath();
    GeneralPath shape2 = new GeneralPath();
    GeneralPath shape3 = new GeneralPath();

    float minX = (float) plotArea.getMinX();
    float minY = (float) plotArea.getMinY();
    float maxX = (float) plotArea.getMaxX();
    float maxY = (float) plotArea.getMaxY();
    //float midX = (float) (minX + (plotArea.getWidth() * getRotateX()));
    //float midY = (float) (minY + (plotArea.getHeight() * getRotateY()));
    float midX = (float) (minX + (plotArea.getWidth() * 0.5));
    float midY = (float) (minY + (plotArea.getHeight() * 0.8));
    float y = maxY - (2 * (maxY - midY));
    if (y < minY) {
        y = minY;
    }
    shape1.moveTo(minX, midY);
    shape1.lineTo(midX, minY);
    shape1.lineTo(midX, y);
    shape1.closePath();

    shape2.moveTo(maxX, midY);
    shape2.lineTo(midX, minY);
    shape2.lineTo(midX, y);
    shape2.closePath();

    shape3.moveTo(minX, midY);
    shape3.lineTo(midX, maxY);
    shape3.lineTo(maxX, midY);
    shape3.lineTo(midX, y);
    shape3.closePath();

    Shape s1 = shape1;
    Shape s2 = shape2;
    Shape s3 = shape3;

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation huston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s1 = shape1.createTransformedShape(transform);
        s2 = shape2.createTransformedShape(transform);
        s3 = shape3.createTransformedShape(transform);
    }


    if (getHighlightPaint() != null) {
        g2.setPaint(getHighlightPaint());
        g2.fill(s3);
    }

    if (getFillPaint() != null) {
        g2.setPaint(getFillPaint());
        g2.fill(s1);
        g2.fill(s2);
    }


    if (getOutlinePaint() != null) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(s1);
        g2.draw(s2);
        g2.draw(s3);
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:76,代碼來源:LongNeedle.java

示例4: drawNeedle

import java.awt.geom.GeneralPath; //導入方法依賴的package包/類
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 
                          Point2D rotate, double angle) {

    GeneralPath shape1 = new GeneralPath();
    GeneralPath shape2 = new GeneralPath();
    GeneralPath shape3 = new GeneralPath();

    float minX = (float) plotArea.getMinX();
    float minY = (float) plotArea.getMinY();
    float maxX = (float) plotArea.getMaxX();
    float maxY = (float) plotArea.getMaxY();
    //float midX = (float) (minX + (plotArea.getWidth() * getRotateX()));
    //float midY = (float) (minY + (plotArea.getHeight() * getRotateY()));
    float midX = (float) (minX + (plotArea.getWidth() * 0.5));
    float midY = (float) (minY + (plotArea.getHeight() * 0.8));
    float y = maxY - (2 * (maxY - midY));
    if (y < minY) {
        y = minY;
    }
    shape1.moveTo(minX, midY);
    shape1.lineTo(midX, minY);
    shape1.lineTo(midX, y);
    shape1.closePath();

    shape2.moveTo(maxX, midY);
    shape2.lineTo(midX, minY);
    shape2.lineTo(midX, y);
    shape2.closePath();

    shape3.moveTo(minX, midY);
    shape3.lineTo(midX, maxY);
    shape3.lineTo(maxX, midY);
    shape3.lineTo(midX, y);
    shape3.closePath();

    Shape s1 = shape1;
    Shape s2 = shape2;
    Shape s3 = shape3;

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation huston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s1 = shape1.createTransformedShape(transform);
        s2 = shape2.createTransformedShape(transform);
        s3 = shape3.createTransformedShape(transform);
    }


    if (getHighlightPaint() != null) {
        g2.setPaint(getHighlightPaint());
        g2.fill(s3);
    }

    if (getFillPaint() != null) {
        g2.setPaint(getFillPaint());
        g2.fill(s1);
        g2.fill(s2);
    }


    if (getOutlinePaint() != null) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(s1);
        g2.draw(s2);
        g2.draw(s3);
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:77,代碼來源:LongNeedle.java


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