Package diva.util.java2d

Examples of diva.util.java2d.Polyline2D


        path.quadTo(180, 120, 120, 240);
        path.closePath();
        _shape = new BasicFigure(path, Color.red);
        layer.add(_shape);

        Polyline2D poly = new Polyline2D.Double();
        poly.moveTo(240, 120);
        poly.lineTo(280, 140);
        poly.lineTo(240, 160);
        poly.lineTo(280, 180);
        poly.lineTo(240, 200);
        poly.lineTo(280, 220);
        poly.lineTo(240, 240);
        _line = new BasicFigure(poly);
        layer.add(_line);
    }
View Full Code Here


            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

            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

     * current positions of the head and tail sites.
     */
    public void route() {
        repaint();

        Polyline2D poly = (Polyline2D) _router.route(this);
        int count = poly.getVertexCount();

        if (count > 1) {
            // pick a location for the label in the middle of the connector.
            _labelLocation = new Point2D.Double((poly.getX(count / 2) + poly
                    .getX((count / 2) - 1)) / 2, (poly.getY(count / 2) + poly
                    .getY((count / 2) - 1)) / 2);
        } else {
            // attach the label to the only point of the connector.
            _labelLocation = new Point2D.Double(poly.getX(0), poly.getY(0));
        }

        if (_bendRadius == 0) {
            setShape(poly);
        } else {
            GeneralPath path = new GeneralPath();
            path.moveTo((float) poly.getX(0), (float) poly.getY(0));

            double prevX = poly.getX(0);
            double prevY = poly.getY(0);

            for (int i = 2; i < poly.getVertexCount(); i++) {
                //consider triplets of coordinates
                double x0 = prevX; //poly.getX(i-2);
                double y0 = prevY; //poly.getY(i-2);
                double x1 = poly.getX(i - 1);
                double y1 = poly.getY(i - 1);
                double x2 = poly.getX(i);
                double y2 = poly.getY(i);

                //midpoints
                x2 = (x1 + x2) / 2;
                y2 = (y1 + y2) / 2;

                //first make sure that the radius is not
                //bigger than half one of the arms of the triplets
                double d0 = Math.sqrt(((x1 - x0) * (x1 - x0))
                        + ((y1 - y0) * (y1 - y0)));
                double d1 = Math.sqrt(((x2 - x1) * (x2 - x1))
                        + ((y2 - y1) * (y2 - y1)));
                double r = Math.min(_bendRadius, d0);
                r = Math.min(r, d1);

                // The degenerate case of a direct line.
                if ((d0 == 0.0) || (d1 == 0.0)) {
                    path.lineTo((float) x1, (float) y1);
                } else {
                    //next calculate the intermediate points
                    //that define the bend.
                    double intX0 = x1 + ((r / d0) * (x0 - x1));
                    double intY0 = y1 + ((r / d0) * (y0 - y1));
                    double intX1 = x1 + ((r / d1) * (x2 - x1));
                    double intY1 = y1 + ((r / d1) * (y2 - y1));

                    //next draw the line from the previous
                    //coord to the intermediate coord, and
                    //curve around the corner
                    path.lineTo((float) intX0, (float) intY0);
                    path.curveTo((float) x1, (float) y1, (float) x1,
                            (float) y1, (float) intX1, (float) intY1);
                    prevX = x2;
                    prevY = y2;
                }
            }

            //finally close the last segment with a line.
            path.lineTo((float) poly.getX(poly.getVertexCount() - 1),
                    (float) poly.getY(poly.getVertexCount() - 1));

            //now set the shape
            setShape(path);
        }

View Full Code Here

     * sites at both ends are moved the same distance.
     */
    public void translate(double x, double y) {
        repaint();

        Polyline2D line = (Polyline2D) getShape();
        line.translate(x, y);
        repaint();
    }
View Full Code Here

            c.getTailEnd().setNormal(tailAngle);
            c.getTailEnd().setOrigin(tailPt.getX(), tailPt.getY());
            c.getTailEnd().getConnection(tailPt);
        }

        Polyline2D route = _route(headPt, headDir, tailPt, tailDir);
        return route;

        // FIXME Adjust for decorations on the ends

        /*
 
View Full Code Here

        Point2D point;
        int dir;

        // System.out.println("routing, diff=(" + xDiff + ", " + yDiff + ")");
        if (((xDiff * xDiff) < (TOL * TOL)) && ((yDiff * yDiff) < (TOL * TOL))) {
            Polyline2D route = new Polyline2D.Double();
            route.moveTo(tail.getX(), tail.getY());
            return route;
        }

        //System.out.println("headDir = " + headDir);
        if (headDir == SwingConstants.WEST) {
            //System.out.println("head is east");
            if ((xDiff > 0) && ((yDiff * yDiff) < TOL)
                    && (tailDir == SwingConstants.EAST)) {
                //System.out.println("completing straight");
                point = tail;
                dir = tailDir;
            } else {
                if (xDiff < 0) {
                    //System.out.println("routing backwards");
                    point = new Point2D.Double(head.getX() - MINDIST, head
                            .getY());
                } else if (((yDiff > 0) && (tailDir == SwingConstants.SOUTH))
                        || ((yDiff < 0) && (tailDir == SwingConstants.NORTH))) {
                    //System.out.println("completing 90");
                    point = new Point2D.Double(tail.getX(), head.getY());
                } else if (headDir == tailDir) {
                    double pos = Math.min(head.getX(), tail.getX()) - MINDIST;
                    point = new Point2D.Double(pos, head.getY());
                } else {
                    point = new Point2D.Double(head.getX() - (xDiff / 2), head
                            .getY());
                }

                if (yDiff > 0) {
                    dir = SwingConstants.NORTH;
                } else {
                    dir = SwingConstants.SOUTH;
                }
            }
        } else if (headDir == SwingConstants.EAST) {
            //System.out.println("head is west");
            if ((xDiff < 0) && ((yDiff * yDiff) < TOL)
                    && (tailDir == SwingConstants.WEST)) {
                //System.out.println("completing");
                point = tail;
                dir = tailDir;
            } else {
                if (xDiff > 0) {
                    //System.out.println("routing backwards");
                    point = new Point2D.Double(head.getX() + MINDIST, head
                            .getY());
                } else if (((yDiff > 0) && (tailDir == SwingConstants.SOUTH))
                        || ((yDiff < 0) && (tailDir == SwingConstants.NORTH))) {
                    //System.out.println("completing 90");
                    point = new Point2D.Double(tail.getX(), head.getY());
                } else if (headDir == tailDir) {
                    double pos = Math.max(head.getX(), tail.getX()) + MINDIST;
                    point = new Point2D.Double(pos, head.getY());
                } else {
                    point = new Point2D.Double(head.getX() - (xDiff / 2), head
                            .getY());
                }

                if (yDiff > 0) {
                    dir = SwingConstants.NORTH;
                } else {
                    dir = SwingConstants.SOUTH;
                }
            }
        } else if (headDir == SwingConstants.SOUTH) {
            //System.out.println("head is north");
            if (((xDiff * xDiff) < TOL) && (yDiff < 0)
                    && (tailDir == SwingConstants.NORTH)) {
                //System.out.println("completing");
                point = tail;
                dir = tailDir;
            } else {
                if (yDiff > 0) {
                    //System.out.println("routing backwards");
                    point = new Point2D.Double(head.getX(), head.getY()
                            + MINDIST);
                } else if (((xDiff > 0) && (tailDir == SwingConstants.EAST))
                        || ((xDiff < 0) && (tailDir == SwingConstants.WEST))) {
                    //System.out.println("completing 90");
                    point = new Point2D.Double(head.getX(), tail.getY());
                } else if (headDir == tailDir) {
                    double pos = Math.max(head.getY(), tail.getY()) + MINDIST;
                    point = new Point2D.Double(head.getX(), pos);
                } else {
                    point = new Point2D.Double(head.getX(), head.getY()
                            - (yDiff / 2));
                }

                if (xDiff > 0) {
                    dir = SwingConstants.WEST;
                } else {
                    dir = SwingConstants.EAST;
                }
            }
        } else if (headDir == SwingConstants.NORTH) {
            //System.out.println("head is south");
            if (((xDiff * xDiff) < TOL) && (yDiff > 0)
                    && (tailDir == SwingConstants.SOUTH)) {
                //System.out.println("completing");
                point = tail;
                dir = tailDir;
            } else {
                if (yDiff < 0) {
                    //System.out.println("routing backwards");
                    point = new Point2D.Double(head.getX(), head.getY()
                            - MINDIST);
                } else if (((xDiff > 0) && (tailDir == SwingConstants.EAST))
                        || ((xDiff < 0) && (tailDir == SwingConstants.WEST))) {
                    //System.out.println("completing 90");
                    point = new Point2D.Double(head.getX(), tail.getY());
                } else if (headDir == tailDir) {
                    double pos = Math.min(head.getY(), tail.getY()) - MINDIST;
                    point = new Point2D.Double(head.getX(), pos);
                } else {
                    point = new Point2D.Double(head.getX(), head.getY()
                            - (yDiff / 2));
                }

                if (xDiff > 0) {
                    dir = SwingConstants.WEST;
                } else {
                    dir = SwingConstants.EAST;
                }
            }
        } else {
            throw new RuntimeException("unknown dir");
        }

        Polyline2D route = _route(point, dir, tail, tailDir);
        route.lineTo(head.getX(), head.getY());

        //System.out.println("route = " + route);
        return route;
    }
View Full Code Here

    /**
     * Reroute the given Shape, given that the head site moved.
     */
    public void rerouteHead(Connector c, Shape s) {
        Polyline2D line = (Polyline2D) s;

        line.setX(1, c.getHeadSite().getX());
        line.setY(1, c.getHeadSite().getY());
    }
View Full Code Here

    /**
     * Reroute the given Shape, given that the tail site moved.
     */
    public void rerouteTail(Connector c, Shape s) {
        Polyline2D line = (Polyline2D) s;
        line.setX(0, c.getHeadSite().getX());
        line.setY(0, c.getHeadSite().getY());
    }
View Full Code Here

    /** Create a polyline. Again, this uses the BasicFigure class,
     * but this time the shape is an instance of <b>diva.util.Polyline2D</b>.
     */
    public void createPolyline() {
        FigureLayer layer = graphicsPane.getForegroundLayer();
        Polyline2D path = new Polyline2D.Double();
        path.moveTo(240, 120);
        path.lineTo(280, 140);
        path.lineTo(240, 160);
        path.lineTo(280, 180);
        path.lineTo(240, 200);
        path.lineTo(280, 220);
        path.lineTo(240, 240);

        Figure line = new BasicFigure(path);
        layer.add(line);
    }
View Full Code Here

TOP

Related Classes of diva.util.java2d.Polyline2D

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.