use of org.antlr.works.visualization.graphics.graph.GGraphGroup in project antlrworks by antlr.
the class GFactory method buildGraphGroup.
private GGraphGroup buildGraphGroup(Grammar grammar, GrammarError error) {
// Create one GGraph for each error rules
List<GGraph> graphs = new ArrayList<GGraph>();
FAFactory factory = new FAFactory(grammar);
for (String rule : error.rules) {
NFAState startState = grammar.getRuleStartState(rule);
FAState state = factory.buildNFA(startState, optimize);
GGraph graph = renderer.render(state);
graph.setName(rule);
graphs.add(graph);
}
// Add only graphs that are referenced by at least one error path.
// For example, the statement rule of the java.g grammar produces
// states that do not exist in the graph (they are after the accepted state
// and are ignored by the FAFactory)
GGraphGroup gg = new GGraphGroup();
for (GGraph graph : graphs) {
if (graph.containsAtLeastOneState(error.states))
gg.add(graph);
}
// Attach all error paths to the GGraphGroup
for (int i = 0; i < error.paths.size(); i++) {
List states = error.paths.get(i);
Boolean disabled = error.pathsDisabled.get(i);
try {
gg.addPath(states, disabled, factory.getSkippedStatesMap());
} catch (Exception e) {
if (console == null)
e.printStackTrace();
else
console.println(e);
}
}
// Attach all unreacheable alts to the GGraphGroup
for (Object[] unreachableAlt : error.unreachableAlts) {
gg.addUnreachableAlt((NFAState) unreachableAlt[0], (Integer) unreachableAlt[1]);
}
if (error.paths.size() > 0)
gg.getPathGroup().setPathVisible(0, true);
return gg;
}
use of org.antlr.works.visualization.graphics.graph.GGraphGroup in project antlrworks by antlr.
the class GPanel method createPathSelectionButtons.
private void createPathSelectionButtons() {
pathButtonSelectionBox.removeAll();
if (!(view.getCurrentGraph() instanceof GGraphGroup))
return;
GGraphGroup gg = (GGraphGroup) view.getCurrentGraph();
int count = gg.getPathGroup().getNumberOfPaths();
if (count <= 1)
pathButtonSelectionBox.add(new JLabel("Alternative:"));
else
pathButtonSelectionBox.add(new JLabel("Alternatives:"));
for (int i = 0; i < count; i++) {
pathButtonSelectionBox.add(createPathSelectionButton(i));
}
}
use of org.antlr.works.visualization.graphics.graph.GGraphGroup in project antlrworks by antlr.
the class GView method paintComponent.
public void paintComponent(Graphics g) {
super.paintComponent(g);
ATEUtilities.prepareForText(g);
if (!canDraw()) {
paintPlaceholder(g);
return;
}
int width = getPaintWidth();
int height = getPaintHeight();
if (useCachedImage) {
boolean sizeChanged = cachedImage != null && (cachedImage.getWidth() != width || cachedImage.getHeight() != height);
if (sizeChanged) {
// instead of re-creating a new one (useful for fast live resize).
if (!cachedImageResize && cachedImage != null) {
cachedImage.flush();
cachedImage = null;
}
}
if (cachedImage == null) {
// Create a new cache image.
cachedImage = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D gCache = (Graphics2D) cachedImage.getGraphics();
ATEUtilities.prepareForText(gCache);
gCache.setColor(Color.white);
gCache.fillRect(0, 0, width, height);
render(gCache);
gCache.dispose();
} else if (cachedImageRerender) {
// Only render the cachedImage without re-creating it again
Graphics2D gCache = (Graphics2D) cachedImage.getGraphics();
ATEUtilities.prepareForText(gCache);
gCache.setColor(Color.white);
gCache.fillRect(0, 0, width, height);
render(gCache);
gCache.dispose();
cachedImageRerender = false;
}
}
if (cachedImage == null)
render((Graphics2D) g);
else
g.drawImage(cachedImage, 0, 0, width, height, null);
if (!cachedImageResize && getCurrentGraph() instanceof GGraphGroup) {
// Draw the selected segment of a path (and only if we are not resizing using only the cached image)
Graphics2D g2d = (Graphics2D) g;
context.offsetX = offset_x;
context.offsetY = offset_y;
context.setGraphics2D(g2d);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
getCurrentPathGroup().drawSelectedElement();
}
}
use of org.antlr.works.visualization.graphics.graph.GGraphGroup in project antlrworks by antlr.
the class GPanel method createPathSelectionButton.
private JCheckBox createPathSelectionButton(int pathIndex) {
JCheckBox button = new JCheckBox(String.valueOf(pathIndex + 1));
button.setName(String.valueOf(pathIndex));
button.setFocusable(false);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
JCheckBox button = (JCheckBox) event.getSource();
GGraphGroup gg = (GGraphGroup) view.getCurrentGraph();
gg.getPathGroup().setPathVisible(Integer.parseInt(button.getName()), button.isSelected());
gg.getPathGroup().makeSureCurrentPathIsVisible();
view.cacheRerender();
view.repaint();
}
});
GGraphGroup gg = (GGraphGroup) view.getCurrentGraph();
button.setSelected(gg.getPathGroup().isPathVisible(pathIndex));
return button;
}
use of org.antlr.works.visualization.graphics.graph.GGraphGroup in project antlrworks by antlr.
the class GPanel method createShowCrossLinksButton.
private JToggleButton createShowCrossLinksButton() {
XJRollOverButtonToggle button = XJRollOverButtonToggle.createMediumButton(IconManager.shared().getIconShowLinks());
button.setSelected(true);
button.setFocusable(false);
button.setToolTipText("Show links between rules");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
for (Object o : view.getGraphs()) {
GGraphGroup gg = (GGraphGroup) o;
gg.getPathGroup().toggleShowRuleLinks();
}
view.cacheRerender();
view.repaint();
}
});
return button;
}
Aggregations