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;
}
Aggregations