Package diva.util.java2d

Examples of diva.util.java2d.Polygon2D


        FigureLayer layer = graphicsPane.getForegroundLayer();

        // Create the graphic
        PaintedList graphic = new PaintedList();

        Polygon2D polygon = new Polygon2D.Double();
        polygon.moveTo(30, 50);
        polygon.lineTo(70, 80);
        polygon.lineTo(70, 20);
        graphic.add(new PaintedShape(polygon, Color.red, 1.0f));

        Line2D line1 = new Line2D.Double(10, 50, 30, 50);
        graphic.add(new PaintedPath(line1));
View Full Code Here


            PaintedShape ps = new PaintedShape(new Ellipse2D.Double(coords[0],
                    coords[1], coords[2], coords[3]));
            processPaintedShapeAttributes(ps, attributes);
            return ps;
        } else if (type.equals("polygon")) {
            Polygon2D poly = new Polygon2D.Double();
            poly.moveTo(coords[0], coords[1]);

            for (int i = 2; i < coords.length; i += 2) {
                poly.lineTo(coords[i], coords[i + 1]);
            }

            poly.closePath();

            PaintedShape ps = new PaintedShape(poly);
            processPaintedShapeAttributes(ps, attributes);
            return ps;
        } else if (type.equals("line")) {
            Shape s;

            if (coords.length == 4) {
                s = new Line2D.Double(coords[0], coords[1], coords[2],
                        coords[3]);
            } else {
                Polyline2D poly = new Polyline2D.Double();
                poly.moveTo(coords[0], coords[1]);

                for (int i = 2; i < coords.length; i += 2) {
                    poly.lineTo(coords[i], coords[i + 1]);
                }

                s = poly;
            }
View Full Code Here

            PaintedShape ps = new PaintedShape(new Ellipse2D.Double(coords[0],
                    coords[1], coords[2], coords[3]));
            processPaintedShapeAttributes(ps, attributes);
            return ps;
        } else if (type.equals("polygon")) {
            Polygon2D poly = new Polygon2D.Double();
            poly.moveTo(coords[0], coords[1]);

            for (int i = 2; i < coords.length; i += 2) {
                poly.lineTo(coords[i], coords[i + 1]);
            }

            poly.closePath();

            PaintedShape ps = new PaintedShape(poly);
            processPaintedShapeAttributes(ps, attributes);
            return ps;
        } else if (type.equals("line")) {
            Shape s;

            if (coords.length == 4) {
                s = new Line2D.Double(coords[0], coords[1], coords[2],
                        coords[3]);
            } else {
                Polyline2D poly = new Polyline2D.Double();
                poly.moveTo(coords[0], coords[1]);

                for (int i = 2; i < coords.length; i += 2) {
                    poly.lineTo(coords[i], coords[i + 1]);
                }

                s = poly;
            }
View Full Code Here

            }

            xout = x + rx + dx;
            yout = y + ry + dy;
        } else if (shape instanceof Polygon2D) {
            Polygon2D polygon = (Polygon2D) shape;
            double pointx = xCenter;
            double pointy = yCenter;
            double max_r = 0;
            int vertexes = polygon.getVertexCount();

            if (vertexes > 1) {
                // compute the intersection of the line segment passing through
                // (x0,y0) and (x1,y1) with the ray passing through
                // (xCenter, yCenter) and (px,py)
                double x0;

                // compute the intersection of the line segment passing through
                // (x0,y0) and (x1,y1) with the ray passing through
                // (xCenter, yCenter) and (px,py)
                double x1;

                // compute the intersection of the line segment passing through
                // (x0,y0) and (x1,y1) with the ray passing through
                // (xCenter, yCenter) and (px,py)
                double y0;

                // compute the intersection of the line segment passing through
                // (x0,y0) and (x1,y1) with the ray passing through
                // (xCenter, yCenter) and (px,py)
                double y1;
                double px = xCenter + Math.cos(alpha);
                double py = yCenter + Math.sin(alpha);

                // Assume the polygon is closed, so do the "closing stroke"
                // first
                x1 = polygon.getX(vertexes - 1);
                y1 = polygon.getY(vertexes - 1);

                for (int vertexPair = 0; vertexPair < vertexes; vertexPair++) {
                    x0 = x1;
                    y0 = y1;
                    x1 = polygon.getX(vertexPair);
                    y1 = polygon.getY(vertexPair);

                    double A = ((x0 - xCenter) * (py - yCenter))
                            - ((y0 - yCenter) * (px - xCenter));
                    double B = ((y1 - y0) * (px - xCenter))
                            - ((x1 - x0) * (py - yCenter));
View Full Code Here

                    2 * _unit, 2 * _unit);
            break;

        case BLOB_DIAMOND:

            Polygon2D polygon = new Polygon2D.Float();
            polygon.moveTo(_originX, _originY);
            polygon.lineTo(_originX + (1.5 * _unit), _originY - _unit);
            polygon.lineTo(_originX + (3.0 * _unit), _originY);
            polygon.lineTo(_originX + (1.5 * _unit), _originY + _unit);
            polygon.lineTo(_originX, _originY);
            polygon.closePath();
            _shape = polygon;
            break;
        }

        _shape = at.createTransformedShape(_shape);
View Full Code Here

        public Figure createFigure() {
            // Create the graphic
            PaintedList graphic = new PaintedList();

            Polygon2D polygon = new Polygon2D.Double();
            polygon.moveTo(30, 50);
            polygon.lineTo(70, 80);
            polygon.lineTo(70, 20);
            graphic.add(new PaintedShape(polygon, Color.red, 1.0f));

            Line2D line1 = new Line2D.Double(10, 50, 30, 50);
            graphic.add(new PaintedPath(line1));
View Full Code Here

                Polyline2D polyline = new Polyline2D.Double(10, 20, 30, 40);
                polyline.lineTo(50, 60);
                polyline.lineTo(50, 60);

                Polygon2D polygon = new Polygon2D.Double(10, 20);
                polygon.lineTo(20, 30);
                polygon.lineTo(40, 50);
                polygon.lineTo(60, 70);

                shapes[3] = polyline;
                shapes[4] = polygon;
                shapes[5] = new GeneralPath(ShapeUtilities.createSwatchShape());
View Full Code Here

                Polyline2D polyline = new Polyline2D.Double(10, 20, 30, 40);
                polyline.lineTo(50, 60);
                polyline.lineTo(50, 60);

                Polygon2D polygon = new Polygon2D.Double(10, 20);
                polygon.lineTo(20, 30);
                polygon.lineTo(40, 50);
                polygon.lineTo(60, 70);

                shapes[3] = polyline;
                shapes[4] = polygon;
                shapes[5] = new GeneralPath(ShapeUtilities.createSwatchShape());
            }
View Full Code Here

        oval.setFillPaint(Color.magenta);
        figureLayer.add(oval);
        oval.setInteractor(selectionInteractor);

        // Create a star using a general path object
        Polygon2D p = new Polygon2D.Double();
        p.moveTo(-100.0f, -25.0f);
        p.lineTo(+100.0f, -25.0f);
        p.lineTo(-50.0f, +100.0f);
        p.lineTo(+0.0f, -100.0f);
        p.lineTo(+50.0f, +100.0f);
        p.closePath();

        // translate origin towards center of canvas
        AffineTransform at = new AffineTransform();
        at.translate(200.0f, 200.0f);
        p.transform(at);

        BasicFigure star = new BasicFigure(p);
        star.setLineWidth(2);
        star.setStrokePaint(Color.blue);
        figureLayer.add(star);
View Full Code Here

            processPaintedPathAttributes(pp, attributes);
            return pp;
        } else if (type.equals("polygon")) {
            double[] coords = parseCoordString((String) attributes
                    .get("points"));
            Polygon2D poly = new Polygon2D.Double();
            poly.moveTo(coords[0], coords[1]);

            for (int i = 2; i < coords.length; i += 2) {
                poly.lineTo(coords[i], coords[i + 1]);
            }

            poly.closePath();

            PaintedShape ps = new PaintedShape(poly);
            processPaintedShapeAttributes(ps, attributes);
            return ps;
        } else if (type.equals("text")) {
View Full Code Here

TOP

Related Classes of diva.util.java2d.Polygon2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.