Package org.antlr.works.visualization.graphics.shape

Examples of org.antlr.works.visualization.graphics.shape.GNode


        graph.setDimension(renderSize(state));
        renderPosition(state);

        /** Mark the last node in order to draw an arrow at the end of the syntax diagram
         */
        GNode lastNode = graphicNodes.get(graphicNodes.size()-1);
        if(lastNode != null)
            lastNode.lastNodeOfRule = true;

        graph.setNodes((ArrayList<GNode>)((ArrayList)graphicNodes).clone());
        return graph;
View Full Code Here


        recursiveRenderPositionNode(state, null, new GPoint());
    }

    public void recursiveRenderPositionNode(FAState state, FAState endState, GPoint basePoint) {
        while(state != endState) {
            GNode node = getNode(state);
            if(node == null) {
                System.err.println("Cannot find SDNode associated with state \""+state+"\"");
                return;
            }

            node.setPosition(basePoint);

            if(state != null && state.isAlternative()) {
                state = recursiveRenderPositionAlternative(state, basePoint);
                basePoint.addX(node.nodeDimension.width+node.linkDimension.width);
            } else if(state != null && state.isSingle()) {
View Full Code Here

                dimension.maxUp(altDim.up);
                dimension.maxDown(altDim.down);
                state = alternativeEndState(state);
            } else if(state.isSingle()) {
                // Create the first node...
                GNode n1 = createNode(state);

                // ... and compute the size of the transition...
                FATransition transition = state.getFirstTransition();
                if(transition.isEpsilon()) {
                    n1.linkDimension.width = GContext.EPSILON_WIDTH;
                    n1.linkDimension.up = GContext.EPSILON_UP;
                    n1.linkDimension.down = GContext.EPSILON_DOWN;
                } else {
                    n1.linkDimension.width = GContext.getBoxWidth(transition.label);
                    n1.linkDimension.up = GContext.BOX_UP;
                    n1.linkDimension.down = GContext.BOX_DOWN;
                }

                dimension.addWidth(GContext.NODE_WIDTH+n1.linkDimension.width);
                dimension.maxUp(n1.linkDimension.up);
                dimension.maxDown(n1.linkDimension.down);

                // ... then create the target node...
                state = transition.target;
                GNode n2 = createNode(state);

                // ... and create the link between these two states
                GLink link = new GLink();
                link.transition = transition;
                link.target = n2;
View Full Code Here

    }

    public GDimension recursiveRenderSizeAlternative(FAState state) {
        FAState alternativeEndState = alternativeEndState(state);

        GNode norigin = createNode(state);

        GDimension dimension = norigin.linkDimension;
        dimension.addWidth(GContext.EPSILON_WIDTH);

        GDimension firstTransitionDimension = null;

        for(int t=0; t<state.getNumberOfTransitions(); t++) {
            FATransition transition = state.transition(t);

            GLink link = new GLink();
            link.transition = transition;
            link.target = createNode(transition.target);
            norigin.addLink(link);

            boolean last = t == state.getNumberOfTransitions()-1;
            if(t == state.getNumberOfTransitions()-2 && state.transition(t+1).loop) {
                // If the last alternative is a loop, consider the last-1 alternative as the last one:
                // the loop will be displayed above the first transition (up) in order to see it easily
View Full Code Here

        }
        return dimension;
    }

    public GNode createNode(FAState state) {
        GNode node = getNode(state);
        if(node == null) {
            node = new GNode();
            node.setState(state);
            graphicNodes.add(node);
            nodes.put(state, node);
        }
        return node;
    }
View Full Code Here

    protected Point2D getBeginPoint() {
        float x0;
        float y0;
        if(source instanceof GNode) {
            GNode node = (GNode)source;
            x0 = node.getCenterX();
            y0 = node.getCenterY();
        } else {
            GLink link = (GLink)source;
            x0 = link.target.getBeginX();
            y0 = link.target.getBeginY();
        }
View Full Code Here

         * graphical representation to figure out exactly which graphical node corresponds
         * to the path.
         */

        NFAState state;
        GNode node;
        NFAState nextState = null;
        GNode nextNode = null;
        for(pathIndex = 0; getPathIndex() < path.size(); pathIndex = getPathIndex() + 1) {
            if(getPathIndex() == 0) {
                nextState = (NFAState)path.get(getPathIndex());
                nextNode = findNodeForStateNumber(nextState.stateNumber);
                if(nextNode == null) {
                    // A path can start from anywhere in the graph. It might happen
                    // that the starting state of the path has been skipped by
                    // the optimization in FAFactory. We use the skippedStates mapping
                    // to find out what is the parent state of the skipped state.
                    FAState parentState = skippedStates.get(nextState.stateNumber);
                    if(parentState == null) {
                        System.err.println("[GGraphGroup] Starting path state "+nextState.stateNumber+"["+nextState.enclosingRule.name+"] cannot be found in the graph");
                        return;
                    } else {
                        nextNode = findNodeForStateNumber(parentState.stateNumber);
                    }
                }
                continue;
            } else {
                state = nextState;
                node = nextNode;
            }

            nextState = (NFAState)path.get(getPathIndex());
            nextNode = findNodeForStateNumber(nextState.stateNumber);

            GNode externalNode = null;

            if(nextNode == null) {
                // The state has probably been skipped during the graphical rendering.
                // Find the next non-skipped state.
                FATransition t = getNodeTransitionToNextNonSkippedState(node, path);
View Full Code Here

    }

    public void addUnreachableAlt(NFAState state, Integer alt) {
        List<GPathElement> elements = new ArrayList<GPathElement>();

        GNode node = findNodeForStateNumber(state.stateNumber);
        if(node == null) {
            System.err.println("[GGraphGroup] Decision state "+state.stateNumber+"["+state.enclosingRule.name+"] cannot be found in the graph");
            return;
        }
        List<FATransition> transitions = node.state.transitions;
        int altNum = alt -1;

        if(altNum >= transitions.size()) {
            System.err.println("[GGraphGroup] Unreachable alt "+altNum+"["+state.enclosingRule.name+"] is out of bounds: "+transitions.size());
            return;
        }

        FATransition t = transitions.get(altNum);

        elements.add(GPathElement.createElement(node));
        elements.add(GPathElement.createElement(node.getLink(t)));

        /** This path has to be visible but not selectable */
        GPath path = new GPath(elements, true);
        path.setVisible(true);
        path.setSelectable(false);
View Full Code Here

        getPathGroup().addPath(path);
    }

    public GNode findNodeForStateNumber(int stateNumber) {
        for (GGraph graph : getGraphs()) {
            GNode node = graph.findNodeForStateNumber(stateNumber);
            if (node != null) {
                return node;
            }
        }
        return null;
View Full Code Here

TOP

Related Classes of org.antlr.works.visualization.graphics.shape.GNode

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.