Search in sources :

Example 41 with Point2D

use of java.awt.geom.Point2D in project jdk8u_jdk by JetBrains.

the class CWarningWindow method reposition.

/**
     * @param x,y,w,h coordinates of the untrusted window
     */
public void reposition(int x, int y, int w, int h) {
    final Point2D point = AWTAccessor.getWindowAccessor().calculateSecurityWarningPosition(ownerWindow, x, y, w, h);
    setBounds((int) point.getX(), (int) point.getY(), getWidth(), getHeight());
}
Also used : Point2D(java.awt.geom.Point2D)

Example 42 with Point2D

use of java.awt.geom.Point2D in project jdk8u_jdk by JetBrains.

the class BufferedPaints method setLinearGradientPaint.

/********************** LinearGradientPaint support *************************/
/**
     * This method uses techniques that are nearly identical to those
     * employed in setGradientPaint() above.  The primary difference
     * is that at the native level we use a fragment shader to manually
     * apply the plane equation constants to the current fragment position
     * to calculate the gradient position in the range [0,1] (the native
     * code for GradientPaint does the same, except that it uses OpenGL's
     * automatic texture coordinate generation facilities).
     *
     * One other minor difference worth mentioning is that
     * setGradientPaint() calculates the plane equation constants
     * such that the gradient end points are positioned at 0.25 and 0.75
     * (for reasons discussed in the comments for that method).  In
     * contrast, for LinearGradientPaint we setup the equation constants
     * such that the gradient end points fall at 0.0 and 1.0.  The
     * reason for this difference is that in the fragment shader we
     * have more control over how the gradient values are interpreted
     * (depending on the paint's CycleMethod).
     */
private static void setLinearGradientPaint(RenderQueue rq, SunGraphics2D sg2d, LinearGradientPaint paint, boolean useMask) {
    boolean linear = (paint.getColorSpace() == ColorSpaceType.LINEAR_RGB);
    Color[] colors = paint.getColors();
    int numStops = colors.length;
    Point2D pt1 = paint.getStartPoint();
    Point2D pt2 = paint.getEndPoint();
    AffineTransform at = paint.getTransform();
    at.preConcatenate(sg2d.transform);
    if (!linear && numStops == 2 && paint.getCycleMethod() != CycleMethod.REPEAT) {
        // delegate to the optimized two-color gradient codepath
        boolean isCyclic = (paint.getCycleMethod() != CycleMethod.NO_CYCLE);
        setGradientPaint(rq, at, colors[0], colors[1], pt1, pt2, isCyclic, useMask);
        return;
    }
    int cycleMethod = paint.getCycleMethod().ordinal();
    float[] fractions = paint.getFractions();
    int[] pixels = convertToIntArgbPrePixels(colors, linear);
    // calculate plane equation constants
    double x = pt1.getX();
    double y = pt1.getY();
    at.translate(x, y);
    // now gradient point 1 is at the origin
    x = pt2.getX() - x;
    y = pt2.getY() - y;
    double len = Math.sqrt(x * x + y * y);
    at.rotate(x, y);
    // now gradient point 2 is on the positive x-axis
    at.scale(len, 1);
    // now gradient point 1 is at (0.0, 0), point 2 is at (1.0, 0)
    float p0, p1, p3;
    try {
        at.invert();
        p0 = (float) at.getScaleX();
        p1 = (float) at.getShearX();
        p3 = (float) at.getTranslateX();
    } catch (java.awt.geom.NoninvertibleTransformException e) {
        p0 = p1 = p3 = 0.0f;
    }
    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacity(20 + 12 + (numStops * 4 * 2));
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_LINEAR_GRADIENT_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(linear ? 1 : 0);
    buf.putInt(cycleMethod);
    buf.putInt(numStops);
    buf.putFloat(p0);
    buf.putFloat(p1);
    buf.putFloat(p3);
    buf.put(fractions);
    buf.put(pixels);
}
Also used : Color(java.awt.Color) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) MultipleGradientPaint(java.awt.MultipleGradientPaint) GradientPaint(java.awt.GradientPaint) Point2D(java.awt.geom.Point2D) AffineTransform(java.awt.geom.AffineTransform)

Example 43 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class MathUtil method drawBezier.

// recursive routine to draw a cubic Bezier...
// (also returns distance!)
private static double drawBezier(Graphics2D g2, Point2D p0, Point2D p1, Point2D p2, Point2D p3, int depth) {
    double result = 0;
    // calculate flatness to determine if we need to recurse...
    double l01 = distance(p0, p1);
    double l12 = distance(p1, p2);
    double l23 = distance(p2, p3);
    double l03 = distance(p0, p3);
    double flatness = (l01 + l12 + l23) / l03;
    // (I just kept moving it closer to 1 until I got good results. ;-)
    if ((depth > 12) || (flatness <= 1.001)) {
        g2.draw(new Line2D.Double(p0, p3));
        result = l03;
    } else {
        // first order midpoints
        Point2D q0 = midPoint(p0, p1);
        Point2D q1 = midPoint(p1, p2);
        Point2D q2 = midPoint(p2, p3);
        // second order midpoints
        Point2D r0 = midPoint(q0, q1);
        Point2D r1 = midPoint(q1, q2);
        // oneThirdPoint order midPoint
        Point2D s = midPoint(r0, r1);
        // draw left side Bezier
        result = drawBezier(g2, p0, q0, r0, s, depth + 1);
        // draw right side Bezier
        result += drawBezier(g2, s, r1, q2, p3, depth + 1);
    }
    return result;
}
Also used : Point2D(java.awt.geom.Point2D) Line2D(java.awt.geom.Line2D)

Example 44 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class MathUtil method drawBezier.

// recursive routine to draw a Bezier curve...
// (also returns distance!)
private static double drawBezier(Graphics2D g2, Point2D[] points, int depth) {
    int len = points.length, idx, jdx;
    double result = 0;
    // calculate flatness to determine if we need to recurse...
    double outer_distance = 0;
    for (idx = 1; idx < len; idx++) {
        outer_distance += MathUtil.distance(points[idx - 1], points[idx]);
    }
    double inner_distance = MathUtil.distance(points[0], points[len - 1]);
    double flatness = outer_distance / inner_distance;
    // (I just kept moving it closer to 1 until I got good results. ;-)
    if ((depth > 12) || (flatness <= 1.001)) {
        g2.draw(new Line2D.Double(points[0], points[len - 1]));
        result = inner_distance;
    } else {
        // calculate (len - 1) order of points
        // (zero'th order are the input points)
        Point2D[][] nthOrderPoints = new Point2D[len - 1][];
        for (idx = 0; idx < len - 1; idx++) {
            nthOrderPoints[idx] = new Point2D[len - 1 - idx];
            for (jdx = 0; jdx < len - 1 - idx; jdx++) {
                if (idx == 0) {
                    nthOrderPoints[idx][jdx] = midPoint(points[jdx], points[jdx + 1]);
                } else {
                    nthOrderPoints[idx][jdx] = midPoint(nthOrderPoints[idx - 1][jdx], nthOrderPoints[idx - 1][jdx + 1]);
                }
            }
        }
        // collect left points
        Point2D[] leftPoints = new Point2D[len];
        leftPoints[0] = points[0];
        for (idx = 0; idx < len - 1; idx++) {
            leftPoints[idx + 1] = nthOrderPoints[idx][0];
        }
        // draw left side Bezier
        result = drawBezier(g2, leftPoints, depth + 1);
        // collect right points
        Point2D[] rightPoints = new Point2D[len];
        for (idx = 0; idx < len - 1; idx++) {
            rightPoints[idx] = nthOrderPoints[len - 2 - idx][idx];
        }
        rightPoints[idx] = points[len - 1];
        // draw right side Bezier
        result += drawBezier(g2, rightPoints, depth + 1);
    }
    return result;
}
Also used : Point2D(java.awt.geom.Point2D) Line2D(java.awt.geom.Line2D) Point(java.awt.Point)

Example 45 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class MathUtil method scale.

/**
     * scale a rectangle
     * @param r the rectangle
     * @param s the scale
     * @return the scaled rectangle
     */
public static Rectangle2D scale(Rectangle2D r, double s) {
    Point2D c = center(r);
    double w = r.getWidth() * s, h = r.getHeight() * s;
    return new Rectangle2D.Double(c.getX() - (w / 2), c.getY() - (h / 2), w, h);
}
Also used : Point2D(java.awt.geom.Point2D)

Aggregations

Point2D (java.awt.geom.Point2D)193 Color (java.awt.Color)22 Rectangle2D (java.awt.geom.Rectangle2D)20 RadialGradientPaint (java.awt.RadialGradientPaint)19 Graphics2D (java.awt.Graphics2D)18 Point (java.awt.Point)18 Paint (java.awt.Paint)17 Line2D (java.awt.geom.Line2D)12 AffineTransform (java.awt.geom.AffineTransform)11 Rectangle (java.awt.Rectangle)9 BasicStroke (java.awt.BasicStroke)8 Stroke (java.awt.Stroke)8 Ellipse2D (java.awt.geom.Ellipse2D)8 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Element (org.jdom2.Element)6 GradientPaint (java.awt.GradientPaint)5 Arc2D (java.awt.geom.Arc2D)5 GeneralPath (java.awt.geom.GeneralPath)5