Package org.antlr.works.visualization.graphics.graph

Examples of org.antlr.works.visualization.graphics.graph.GGraph


     * displaying the syntax diagram.
     *
     */
    @SuppressWarnings("unchecked")
    public synchronized GGraph render(FAState state) {
        GGraph graph = new GGraph();
        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


        ImageIO.write(image, imageFormat, new File(file));
    }

    private GGraph createGraph(String ruleName) throws Exception {
        GGraph graph = new GFactory().buildGraphsForRule(engine.getANTLRGrammarEngine(), ruleName);
        graph.setContext(context);
        graph.render(0,0);
        return graph;
    }
View Full Code Here

        NFAState startState = antlrEngineGrammar.getRuleStartState(rule);
        if(startState == null)
            return null;

        FAState state = new FAFactory(antlrEngineGrammar.getGrammarForRule(rule)).buildNFA(startState, optimize);
        GGraph graph = renderer.render(state);
        graph.setName(rule);

        return graph;
    }
View Full Code Here

        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++) {
View Full Code Here

        context.setSkin(new SDSkin());
        context.setProvider(this);
    }

    public void serializeRule(String name, SEncoder encoder) throws Exception {
        GGraph graph = createGraph(name);
        encoder.write(graph);
    }
View Full Code Here

        GGraph graph = createGraph(name);
        encoder.write(graph);
    }

    public void renderRuleToEPSFile(String ruleName, String file) throws Exception {
        GGraph graph = createGraph(ruleName);
        GEnginePS engine = new GEnginePS();
        context.setEngine(engine);
        graph.draw();
        XJUtils.writeStringToFile(engine.getPSText(), file);
    }
View Full Code Here

        graph.draw();
        XJUtils.writeStringToFile(engine.getPSText(), file);
    }

    public void renderRuleToBitmapFile(String ruleName, String imageFormat, String file) throws Exception {
        GGraph graph = createGraph(ruleName);

        int width = (int)(graph.getWidth()+1);
        int height = (int)(graph.getHeight()+1);

        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        Graphics2D g2d = (Graphics2D)image.getGraphics();

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);

        context.setEngine(new GEngineGraphics());
        context.setGraphics2D(g2d);

        g2d.setColor(Color.white);
        g2d.fillRect(0, 0, width, height);
        graph.draw();
        g2d.dispose();

        ImageIO.write(image, imageFormat, new File(file));
    }
View Full Code Here

TOP

Related Classes of org.antlr.works.visualization.graphics.graph.GGraph

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.