Search in sources :

Example 6 with FAState

use of org.antlr.works.visualization.fa.FAState in project antlrworks by antlr.

the class GRenderer method recursiveRenderSizeAlternative.

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
            // from the other transition(s).
            last = true;
        }
        link.setLast(last);
        if (transition.target == alternativeEndState) {
            GDimension transitionDimension = new GDimension();
            transitionDimension.addUp(GContext.EPSILON_UP);
            transitionDimension.addDown(GContext.EPSILON_DOWN);
            if (transition.loop)
                transitionDimension.addDown(GContext.LINE_SPACE);
            if (transition.loop) {
                link.setBranchDimension(transitionDimension);
                dimension.maxUp(firstTransitionDimension.up + transitionDimension.up + transitionDimension.down);
            } else {
                link.setBranchDimension(transitionDimension);
                if (t == 0) {
                    firstTransitionDimension = transitionDimension;
                }
                dimension.addDown(transitionDimension.up);
                dimension.addDown(transitionDimension.down);
            }
        } else {
            endOfAlternativeInfoMap.put(alternativeEndState, new EOAInfo(last));
            GDimension transitionDimension = recursiveRenderSizeSingle(transition.target, alternativeEndState);
            if (((t > 0) || (t == 0 && !state.transition(1).loop)) && !last)
                dimension.addDown(GContext.LINE_SPACE);
            link.setBranchDimension(transitionDimension);
            transitionDimension.addWidth(GContext.EPSILON_WIDTH);
            dimension.maxWidth(transitionDimension.width);
            if (t == 0) {
                // Remember the size of the first transition
                firstTransitionDimension = transitionDimension;
                // Add its "up" size to the transition "up" size
                dimension.maxUp(transitionDimension.up);
                dimension.addDown(transitionDimension.down);
            } else {
                dimension.addDown(transitionDimension.up);
                dimension.addDown(transitionDimension.down);
            }
        }
    }
    return dimension;
}
Also used : FAState(org.antlr.works.visualization.fa.FAState) FATransition(org.antlr.works.visualization.fa.FATransition) GNode(org.antlr.works.visualization.graphics.shape.GNode) GDimension(org.antlr.works.visualization.graphics.primitive.GDimension) GLink(org.antlr.works.visualization.graphics.shape.GLink) GPoint(org.antlr.works.visualization.graphics.primitive.GPoint)

Aggregations

FAState (org.antlr.works.visualization.fa.FAState)6 FATransition (org.antlr.works.visualization.fa.FATransition)4 NFAState (org.antlr.analysis.NFAState)3 GPoint (org.antlr.works.visualization.graphics.primitive.GPoint)3 ArrayList (java.util.ArrayList)2 FAFactory (org.antlr.works.visualization.fa.FAFactory)2 GGraph (org.antlr.works.visualization.graphics.graph.GGraph)2 GDimension (org.antlr.works.visualization.graphics.primitive.GDimension)2 GLink (org.antlr.works.visualization.graphics.shape.GLink)2 GNode (org.antlr.works.visualization.graphics.shape.GNode)2 List (java.util.List)1 GGraphGroup (org.antlr.works.visualization.graphics.graph.GGraphGroup)1 GPath (org.antlr.works.visualization.graphics.path.GPath)1 GPathElement (org.antlr.works.visualization.graphics.path.GPathElement)1