use of org.antlr.works.visualization.graphics.primitive.GDimension in project antlrworks by antlr.
the class GRenderer method recursiveRenderPositionAlternative.
public FAState recursiveRenderPositionAlternative(FAState state, GPoint basePoint) {
FAState alternativeEndState = alternativeEndState(state);
// This point is used to position each transition
GPoint point = new GPoint(basePoint);
point.addX(GContext.NODE_WIDTH + GContext.EPSILON_WIDTH);
GDimension firstAlternativeDimension = null;
for (int t = 0; t < state.getNumberOfTransitions(); t++) {
FATransition transition = state.transition(t);
GLink link = getNode(state).getLink(transition);
if (t == 0) {
// We remember here the size of the first transition because if we find later
// a "loop" transition, we will have to offset this "loop" by the size of the first
// transition (because the "loop" is always drawed above the first transition).
firstAlternativeDimension = link.branchDim;
}
if (t > 0 && !transition.loop) {
// Offset the current point for each transition (except for a "loop" because it is
// displayed above the first transition)
point.addY(GContext.LINE_SPACE);
point.addY(link.branchDim.up);
}
if (transition.target == alternativeEndState) {
// The transition is simply a single transition (epsilon normally).
if (transition.loop) {
// If this is a "loop", draw it above the first transition
GPoint vp = new GPoint(basePoint);
vp.subY(firstAlternativeDimension.up);
vp.subY(link.branchDim.down);
// The "virtual position" is used by the link to know where to display itself
// when it has to "curve" (because both start and end point are on the same y-axis value)
getNode(state).getLink(transition).setVirtualPosition(vp);
} else {
getNode(state).getLink(transition).setVirtualPosition(point);
point.addY(link.branchDim.down);
}
} else {
// The transition is more than a single transition, continue recursively...
recursiveRenderPositionNode(transition.target, alternativeEndState, new GPoint(point));
point.addY(link.branchDim.down);
}
}
return alternativeEndState;
}
use of org.antlr.works.visualization.graphics.primitive.GDimension in project antlrworks by antlr.
the class GRenderer method recursiveRenderSizeSingle.
public GDimension recursiveRenderSizeSingle(FAState state, FAState endState) {
GDimension dimension = new GDimension();
dimension.addUp(GContext.NODE_UP);
dimension.addDown(GContext.NODE_DOWN);
while (state != endState && state != null) {
if (state.isAlternative()) {
GDimension altDim = recursiveRenderSizeAlternative(state);
dimension.addWidth(GContext.NODE_WIDTH + altDim.width);
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;
n1.addLink(link);
if (state == endState) {
// If we have reached the end of an alternative, we must set the "last" flag
// to the SDLink in order for it to be correctly rendered on screen.
EOAInfo eoa = endOfAlternativeInfoMap.get(state);
if (eoa != null) {
link.setLast(eoa.last);
}
}
} else {
dimension.addWidth(GContext.NODE_WIDTH);
state = null;
}
}
return dimension;
}
use of org.antlr.works.visualization.graphics.primitive.GDimension in project antlrworks by antlr.
the class GGraphGroup method ensureDimension.
private void ensureDimension() {
if (dimensionComputed)
return;
GDimension d = getDimension();
for (int i = 0; i < graphs.size(); i++) {
GGraph graph = graphs.get(i);
d.maxWidth(graph.getDimension().width);
d.addUp(graph.getDimension().up);
d.addDown(graph.getDimension().down);
if (i > 0) {
d.addDown(GContext.LINE_SPACE);
}
}
dimensionComputed = true;
}
use of org.antlr.works.visualization.graphics.primitive.GDimension 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;
}
use of org.antlr.works.visualization.graphics.primitive.GDimension in project antlrworks by antlr.
the class GNode method cacheGlobalDimension.
private void cacheGlobalDimension(GContext context) {
globalDimension = new GDimension();
globalDimension.addWidth(nodeDimension.width + linkDimension.width);
globalDimension.addUp(GLiteral.max(nodeDimension.up, linkDimension.up));
globalDimension.addDown(GLiteral.max(nodeDimension.down, linkDimension.down));
globalDimension.cache(context);
}
Aggregations