Search in sources :

Example 66 with GeneralPath

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

the class Path2DGrow method testGeneralPath.

static void testGeneralPath() {
    echo("\n - Test(GeneralPath) ---");
    test(() -> new GeneralPath());
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 67 with GeneralPath

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

the class Path2DCopyConstructor method testGeneralPath.

static void testGeneralPath() {
    log("\n - Test(GeneralPath) ---");
    test(() -> new GeneralPath());
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 68 with GeneralPath

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

the class TextLayout method getBlackBoxBounds.

/**
     * Returns the black box bounds of the characters in the specified range.
     * The black box bounds is an area consisting of the union of the bounding
     * boxes of all the glyphs corresponding to the characters between start
     * and limit.  This area can be disjoint.
     * @param firstEndpoint one end of the character range
     * @param secondEndpoint the other end of the character range.  Can be
     * less than <code>firstEndpoint</code>.
     * @return a <code>Shape</code> enclosing the black box bounds.  This is
     *     in standard coordinates.
     */
public Shape getBlackBoxBounds(int firstEndpoint, int secondEndpoint) {
    ensureCache();
    if (firstEndpoint > secondEndpoint) {
        int t = firstEndpoint;
        firstEndpoint = secondEndpoint;
        secondEndpoint = t;
    }
    if (firstEndpoint < 0 || secondEndpoint > characterCount) {
        throw new IllegalArgumentException("Invalid range passed to TextLayout.getBlackBoxBounds()");
    }
    /*
         * return an area that consists of the bounding boxes of all the
         * characters from firstEndpoint to limit
         */
    GeneralPath result = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    if (firstEndpoint < characterCount) {
        for (int logIndex = firstEndpoint; logIndex < secondEndpoint; logIndex++) {
            Rectangle2D r = textLine.getCharBounds(logIndex);
            if (!r.isEmpty()) {
                result.append(r, false);
            }
        }
    }
    if (dx != 0 || dy != 0) {
        AffineTransform tx = AffineTransform.getTranslateInstance(dx, dy);
        result = (GeneralPath) tx.createTransformedShape(result);
    }
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = (GeneralPath) lp.mapShape(result);
    }
    //return new Highlight(result, false);
    return result;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) LayoutPathImpl(sun.font.LayoutPathImpl) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform)

Example 69 with GeneralPath

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

the class TextLayout method pathToShape.

private static GeneralPath pathToShape(double[] path, boolean close, LayoutPathImpl lp) {
    GeneralPath result = new GeneralPath(GeneralPath.WIND_EVEN_ODD, path.length);
    result.moveTo((float) path[0], (float) path[1]);
    for (int i = 2; i < path.length; i += 2) {
        result.lineTo((float) path[i], (float) path[i + 1]);
    }
    if (close) {
        result.closePath();
    }
    if (lp != null) {
        result = (GeneralPath) lp.mapShape(result);
    }
    return result;
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 70 with GeneralPath

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

the class PositionablePolygon method doHandleMove.

@Override
protected boolean doHandleMove(MouseEvent event) {
    if (_hitIndex >= 0 && _editor.isEditable()) {
        if (_editing) {
            Point pt = new Point(event.getX() - _lastX, event.getY() - _lastY);
            Rectangle rect = _vertexHandles.get(_hitIndex);
            rect.x += pt.x;
            rect.y += pt.y;
            if (_editFrame != null) {
                if (event.getX() - getX() < 0) {
                    _editor.moveItem(this, event.getX() - getX(), 0);
                } else if (isLeftMost(rect.x)) {
                    _editor.moveItem(this, event.getX() - _lastX, 0);
                }
                if (event.getY() - getY() < 0) {
                    _editor.moveItem(this, 0, event.getY() - getY());
                } else if (isTopMost(rect.y)) {
                    _editor.moveItem(this, 0, event.getY() - _lastY);
                }
                ((DrawPolygon) _editFrame).doHandleMove(_hitIndex, pt);
            }
            _lastX = event.getX();
            _lastY = event.getY();
        } else {
            float deltaX = event.getX() - _lastX;
            float deltaY = event.getY() - _lastY;
            float width = _width;
            float height = _height;
            if (_height < SIZE || _width < SIZE) {
                log.error("Bad size _width= " + _width + ", _height= " + _height);
            }
            GeneralPath path = null;
            switch(_hitIndex) {
                case TOP:
                    if (height - deltaY > SIZE) {
                        path = scale(1, (height - deltaY) / height);
                        _editor.moveItem(this, 0, (int) deltaY);
                    } else {
                        path = scale(1, SIZE / height);
                        _editor.moveItem(this, 0, _height - SIZE);
                    }
                    break;
                case RIGHT:
                    path = scale(Math.max(SIZE / width, (width + deltaX) / width), 1);
                    break;
                case BOTTOM:
                    path = scale(1, Math.max(SIZE / height, (height + deltaY) / height));
                    break;
                case LEFT:
                    if (_width - deltaX > SIZE) {
                        path = scale((width - deltaX) / width, 1);
                        _editor.moveItem(this, (int) deltaX, 0);
                    } else {
                        path = scale(SIZE / width, 1);
                        _editor.moveItem(this, _width - SIZE, 0);
                    }
                    break;
                default:
                    log.warn("Unhandled direction code: {}", _hitIndex);
            }
            if (path != null) {
                setShape(path);
            }
        }
        drawHandles();
        repaint();
        updateSize();
        _lastX = event.getX();
        _lastY = event.getY();
        return true;
    }
    return false;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Rectangle(java.awt.Rectangle) Point(java.awt.Point)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)96 Point (java.awt.Point)14 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Graphics2D (java.awt.Graphics2D)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)6 Point2D (java.awt.geom.Point2D)6 Stroke (java.awt.Stroke)5 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 CubicCurve2D (java.awt.geom.CubicCurve2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 GradientPaint (java.awt.GradientPaint)2 Rectangle (java.awt.Rectangle)2 Line2D (java.awt.geom.Line2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1