Package org.antlr.xjlib.appkit.gview.base

Examples of org.antlr.xjlib.appkit.gview.base.Vector2D


//  edge start n1 7 1.153 8.556 1.125 8.417 1.097 8.236 1.111 8.083 1.111 8.042 1.125 8.014 1.125 7.972
//  g 1.194 8.194 solid black
//  edge rule foo 4 0.375 1.000 0.375 0.889 0.375 0.764 0.375 0.639 solid black

        int controlCount = (int) Float.parseFloat(tokens[3]);
        Vector2D points[] = new Vector2D[controlCount];
        for(int index=0; index<controlCount; index++) {
            points[index] = new Vector2D(Float.parseFloat(tokens[4+index*2])*factor,
                    (height-Float.parseFloat(tokens[4+index*2+1]))*factor);
        }

        int labelIndex = 3+2*controlCount+1;
        String label = null;
        Vector2D labelPosition = null;
        if(isFloatString(tokens[labelIndex+1])) {
            // Apparently there is a label because there is a float coordinate
            label = tokens[labelIndex];
            labelPosition = new Vector2D(Float.parseFloat(tokens[labelIndex+1])*factor,
                                (height-Float.parseFloat(tokens[labelIndex+2]))*factor);
        }

        GElement source = graph.findElementWithLabel(tokens[1]);
        GElement target = graph.findElementWithLabel(tokens[2]);
View Full Code Here


        String sourceName = tokens[0];
        String targetName = tokens[3];

        String labelName = null;
        Vector2D labelPosition = null;
        Vector2D points[] = null;

        int index = 4;
        while(index < tokens.length-1) {
            index++;

            if(tokens[index].equals("label")) {
                // Label name
                labelName = tokens[index+=2];
            } else if(tokens[index].equals("lp")) {
                // Label position
                String[] lpos = parseTokens(tokens[index+=2]);
                labelPosition = new Vector2D(Float.parseFloat(lpos[0]), height-Float.parseFloat(lpos[2]));
            } else if(tokens[index].equals("pos")) {
                // Edge control points
                points = parseControlPoints(tokens[index+=2]);
            } else if(tokens[index].equals(";"))
                break;
View Full Code Here

    }

    public Vector2D[] parseControlPoints(String s) throws IOException {
        // e,56,216 51,34 43,44 33,58 29,72 15,118 20,134 36,180 39,190 45,199 50,208
        List<Vector2D> points = new ArrayList<Vector2D>();
        Vector2D endPoint = null;

        String[] pts = parseTokens(s);
        int index = -1;
        while(++index < pts.length) {
            if(pts[index].equals("e")) {
                // Arrow at the end
                if(index+2 >= pts.length) {
                    System.err.println(String.format("Expected x arrow position at %d but reached the end at %d", index+2, pts.length));
                    continue;
                }
                if(index+4 >= pts.length) {
                    System.err.println(String.format("Expected y arrow position at %d but reached the end at %d", index+4, pts.length));
                    continue;
                }
                String x = pts[index+=2];
                String y = pts[index+=2];
                endPoint = new Vector2D(Float.parseFloat(x), height-Float.parseFloat(y));
            } else if(isFloatString(pts[index]) && index+2 < pts.length && isFloatString(pts[index+2])) {
                // Assume pair of numbers
                if(index+2 >= pts.length) {
                    System.err.println(String.format("Expected y position at %d but reached the end at %d", index+2, pts.length));
                    continue;
                }
                String x = pts[index];
                String y = pts[index+=2];
                points.add(new Vector2D(Float.parseFloat(x), height-Float.parseFloat(y)));
            }
        }

        if(endPoint != null)
            points.add(endPoint);

        Vector2D p[] = new Vector2D[points.size()];
        for(int i=0; i<points.size(); i++) {
            p[i] = points.get(i);
        }
        return p;
    }
View Full Code Here

        }
    }


    public void buildHorizontalPath() {
        Vector2D start_ = link.getStartWithOffset();
        Vector2D end_ = link.getEndWithOffset();

        Vector2D ab = end_.sub(start_);
        Vector2D p1 = start_.add(new Vector2D(ab.getX()*0.5, 0));
        Vector2D p2 = p1.add(new Vector2D(0, ab.getY()));
        Vector2D p3 = p2.add(new Vector2D(ab.getX()*0.5, 0));

        path.clear();
        if(ab.getY()==0) {
            path.add(link.start);
            path.add(link.end);
View Full Code Here

        link.label.setPosition(p2.copy().shift(-LABEL_OFFSET, -LABEL_OFFSET));
    }

    public void buildVerticalPath() {
        Vector2D start_ = link.getStartWithOffset();
        Vector2D end_ = link.getEndWithOffset();

        Vector2D ab = end_.sub(start_);
        Vector2D p1 = start_.add(new Vector2D(0, ab.getY()*0.5));
        Vector2D p2 = p1.add(new Vector2D(ab.getX(), 0));
        Vector2D p3 = p2.add(new Vector2D(0, ab.getY()*0.5));

        path.clear();
        path.add(link.start);
        if(ab.getX()!=0) {
            path.add(start_);
View Full Code Here

        link.label.setPosition(p2.copy().shift(-LABEL_OFFSET, -LABEL_OFFSET));
    }

    public void buildVerticalBottomPath(int direction) {
        Vector2D start_ = link.getStartWithOffset();
        Vector2D end_ = link.getEndWithOffset();

        Vector2D start = link.start;
        Vector2D end = link.end;

        double farest_y = Math.max(start_.y, end_.y)+40;

        if(direction == LEFT_RIGHT) {
            if(start_.x > end.x-GElementRect.DEFAULT_HEIGHT-link.outOffsetLength) {

                // Extend start out offset only if the end box is on the RIGHT
                double end_box_bottom_edge = end.y+GElementRect.DEFAULT_WIDTH*0.5;
                if(start_.y<=end_box_bottom_edge+5)
                    start_.x = end.x-GElementRect.DEFAULT_HEIGHT-link.outOffsetLength;
            }

            if(end_.x < start.x+GElementRect.DEFAULT_HEIGHT+link.outOffsetLength) {

                // Extend end out offset only if the start box is on the RIGHT
                double start_box_bottom_edge = start.y+GElementRect.DEFAULT_WIDTH*0.5;
                if(end_.y<=start_box_bottom_edge+5)
                    end_.x = start.x+GElementRect.DEFAULT_HEIGHT+link.outOffsetLength;
            }
        } else {
            if(start_.x < end.x+GElementRect.DEFAULT_HEIGHT+link.outOffsetLength) {

                // Extend start out offset only if the end box is on the RIGHT
                double end_box_bottom_edge = end.y+GElementRect.DEFAULT_WIDTH*0.5;
                if(start_.y<=end_box_bottom_edge+5)
                    start_.x = end.x+GElementRect.DEFAULT_HEIGHT+link.outOffsetLength;
            }

            if(end_.x > start.x-GElementRect.DEFAULT_HEIGHT-link.outOffsetLength) {

                // Extend end out offset only if the start box is on the RIGHT
                double start_box_bottom_edge = start.y+GElementRect.DEFAULT_WIDTH*0.5;
                if(end_.y<=start_box_bottom_edge+5)
                    end_.x = start.x-GElementRect.DEFAULT_HEIGHT-link.outOffsetLength;
            }
        }

        // Extend the link to the RIGHT

        Vector2D p1 = start_.add(new Vector2D(0, farest_y-start.y));
        Vector2D p2 = end_.add(new Vector2D(0, farest_y-end.y));

        path.clear();
        path.add(start);
        path.add(start_);
        path.add(p1);
        path.add(p2);
        path.add(end_);
        path.add(end);

        Vector2D labelv = start_.sub(p2);
        labelv.stretch(0.5);
        link.label.setPosition(p2.add(labelv).shift(0, LABEL_OFFSET));
    }
View Full Code Here

    public Vector2D absToRel(Vector2D p) {
        if(selfLoop) {
            return p.sub(start);
        } else {
            Vector2D z = end.sub(start);
            Vector2D a = p.sub(start);

            double lb = a.dot(z)/z.length();
            Vector2D b = z.normalize().setLength(lb);

            Vector2D c = a.sub(b);
            double lc = c.length()*(a.crossSign(z));

            return new Vector2D(lb, lc);
        }
    }
View Full Code Here

    public Vector2D relToAbs(Vector2D p, int mode) {
        if(selfLoop) {
            return start.add(p);
        } else {
            Vector2D nz = end.sub(start);
            double f = nz.length()/originalZLength;
            double lb = p.getX();
            double lc = p.getY();
            if(mode == MODE_END) {
                // End-point is always at the same relative position
                return end.add(originalEndPointOffset);
            } else {
                if(mode == MODE_NOSTRETCH)
                    f = 1;
                Vector2D nb = nz.normalize().setLength(f*lb);
                Vector2D nc = nz.copy().rotate(-90).normalize().setLength(lc);
                return start.add(nb.add(nc));
            }
        }
    }
View Full Code Here

    public void lines(Graphics g) {

        g.setColor(color);

        for (int i = 0; i < controlPointsAbs.length; i++) {
            Vector2D pt = controlPointsAbs[i];
            double x = pt.x;
            double y = pt.y;
            g.fillRect((int)(x-2), (int)(y-2), 4, 4);
        }
    }
View Full Code Here

        boolean first = true;
        double fx = 0, fy = 0;

        for (int i = 1; i < n - 2; i++) {  // Loop Through Control Points

            Vector2D p0 = controlPointsAbs[i - 1];
            Vector2D p1 = controlPointsAbs[i];
            Vector2D p2 = controlPointsAbs[i + 1];
            Vector2D p3 = controlPointsAbs[i + 2];

            xA = p0.x;
            xB = p1.x;
            xC = p2.x;
            xD = p3.x;

            yA = p0.y;
            yB = p1.y;
            yC = p2.y;
            yD = p3.y;

            a3 = (-xA + 3 * (xB - xC) + xD) / 6;
            b3 = (-yA + 3 * (yB - yC) + yD) / 6;
            a2 = (xA - 2 * xB + xC) / 2;
            b2 = (yA - 2 * yB + yC) / 2;
            a1 = (xC - xA) / 2;
            b1 = (yC - yA) / 2;
            a0 = (xA + 4 * xB + xC) / 6;
            b0 = (yA + 4 * yB + yC) / 6;


            for (double t = 0; t <=1.0; t += time_delta) {
                x0 = x;
                y0 = y;

                double x1 = ((a3 * t + a2) * t + a1) * t + a0;
                double y1 = ((b3 * t + b2) * t + b1) * t + b0;

                x = (int) Math.round(x1);
                y = (int) Math.round(y1);

                if (first) {
                    first = false;
                    fx = x;
                    fy = y;
                } else {
                    g.drawLine((int) x0, (int) y0, (int) x, (int) y);
                }

                //g.setColor(Color.red);
                //g.fillRect((int)(x-2), (int)(y-2), 4, 4);
            }
        }

        // Perimeter of the source to the first point of the bezier curve
        Vector2D p0 = controlPointsAbs[0];
        g.drawLine((int) p0.getX(), (int) p0.getY(), (int) fx, (int) fy);

        // Last point of the bezier curve to the perimeter of the target
        Vector2D p1 = controlPointsAbs[n-1];
        g.drawLine((int) x, (int) y, (int) p1.getX(), (int) p1.getY());

        arrow.setAnchor(p1.getX(), p1.getY());
        arrow.setDirection(new Vector2D(x-p1.getX(), y-p1.getY()));
        arrow.draw(g);
    }
View Full Code Here

TOP

Related Classes of org.antlr.xjlib.appkit.gview.base.Vector2D

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.