org.jgrapht.ext.JGraphXAdapter Java Examples

The following examples show how to use org.jgrapht.ext.JGraphXAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NetworkGraph.java    From Rails with GNU General Public License v2.0 6 votes vote down vote up
public JFrame visualize(String title) {
    // show network mapGraph
    if (graph.vertexSet().size() > 0) {
        JGraphXAdapter<NetworkVertex, NetworkEdge> jGraphXAdapter = new JGraphXAdapter<>(graph);

        jGraphXAdapter.getModel().beginUpdate();

        mxIGraphLayout layout = new mxFastOrganicLayout(jGraphXAdapter);
        layout.execute(jGraphXAdapter.getDefaultParent());

        jGraphXAdapter.getModel().endUpdate();

        mxGraphComponent graphComponent = new mxGraphComponent(jGraphXAdapter);

        JFrame frame = new JFrame();
        frame.setTitle(String.format("%s(V=%d,E=%d)", title, graph.vertexSet().size(), graph.edgeSet().size()));
        frame.setSize(new Dimension(800, 600));
        frame.getContentPane().add(new JScrollPane(graphComponent));
        frame.pack();
        frame.setVisible(true);
        return frame;
    }
    return null;
}
 
Example #2
Source File: ComputeInstanceSimilarityBlock.java    From BART with MIT License 5 votes vote down vote up
private void saveGraph(UndirectedGraph<TupleWithTable, DefaultEdge> instancesGraph) {
        JGraphXAdapter<TupleWithTable, DefaultEdge> jgxAdapterContext = new JGraphXAdapter<TupleWithTable, DefaultEdge>(instancesGraph);
        jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
        jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_ENDARROW, "0");
        jgxAdapterContext.setCellsEditable(false);
        jgxAdapterContext.setCellsMovable(false);
        jgxAdapterContext.setEdgeLabelsMovable(false);
        jgxAdapterContext.setCellsDeletable(false);
        jgxAdapterContext.setCellsDisconnectable(false);
        jgxAdapterContext.setCellsResizable(false);
        jgxAdapterContext.setCellsBendable(false);
        JFrame frame = new JFrame();
        mxGraphComponent mxGraphComponent = new mxGraphComponent(jgxAdapterContext);
        frame.getContentPane().add(mxGraphComponent, BorderLayout.CENTER);
        mxHierarchicalLayout layout = new mxHierarchicalLayout(jgxAdapterContext);
        layout.execute(jgxAdapterContext.getDefaultParent());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("Graph");
        frame.pack();
        frame.setLocationRelativeTo(null);
//        frame.setVisible(true);
//        try {
//            while (true) {
//                Thread.sleep(500);
//            }
//        } catch (InterruptedException ex) {
//            java.util.logging.Logger.getLogger(ComputeInstanceSimilarityBlock.class.getName()).log(Level.SEVERE, null, ex);
//        }
        try {
            BufferedImage image = mxCellRenderer.createBufferedImage(jgxAdapterContext, null, 1, Color.WHITE, true, null);
            File file = new File("/Users/Shared/Temp/bart/similarity/instances-graph.png");
            file.getParentFile().mkdirs();
            ImageIO.write(image, "PNG", file);
        } catch (IOException ex) {
            logger.error("Unable to save graph image: " + ex.getLocalizedMessage());
        }
    }
 
Example #3
Source File: TTGDStratification.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
private void showTGDGraph(DirectedGraph<TGDStratum, DefaultEdge> strataGraph) {
        JGraphXAdapter<TGDStratum, DefaultEdge> jgxAdapterContext = new JGraphXAdapter<TGDStratum, DefaultEdge>(strataGraph);
        jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
//        jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_ENDARROW, "0");
        jgxAdapterContext.setCellsEditable(false);
        jgxAdapterContext.setCellsMovable(false);
        jgxAdapterContext.setEdgeLabelsMovable(false);
        jgxAdapterContext.setCellsDeletable(false);
        jgxAdapterContext.setCellsDisconnectable(false);
        jgxAdapterContext.setCellsResizable(false);
        jgxAdapterContext.setCellsBendable(false);
        JFrame frame = new JFrame();
        mxGraphComponent mxGraphComponent = new mxGraphComponent(jgxAdapterContext);
        frame.getContentPane().add(mxGraphComponent, BorderLayout.CENTER);
        mxHierarchicalLayout layout = new mxHierarchicalLayout(jgxAdapterContext);
        layout.execute(jgxAdapterContext.getDefaultParent());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("Graph");
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        try {
            BufferedImage image = mxCellRenderer.createBufferedImage(jgxAdapterContext, null, 1, Color.WHITE, true, null);
            ImageIO.write(image, "PNG", new File("/Temp/llunatic/tgd-graph.png"));
        } catch (IOException ex) {
            logger.error("Unable to save graph image: " + ex.getLocalizedMessage());
        }
    }
 
Example #4
Source File: TTGDStratification.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
private void showEGDGraph(DirectedGraph<EGDStratum, DefaultEdge> strataGraph) {
        JGraphXAdapter<EGDStratum, DefaultEdge> jgxAdapterContext = new JGraphXAdapter<EGDStratum, DefaultEdge>(strataGraph);
        jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
//        jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_ENDARROW, "0");
        jgxAdapterContext.setCellsEditable(false);
        jgxAdapterContext.setCellsMovable(false);
        jgxAdapterContext.setEdgeLabelsMovable(false);
        jgxAdapterContext.setCellsDeletable(false);
        jgxAdapterContext.setCellsDisconnectable(false);
        jgxAdapterContext.setCellsResizable(false);
        jgxAdapterContext.setCellsBendable(false);
        JFrame frame = new JFrame();
        mxGraphComponent mxGraphComponent = new mxGraphComponent(jgxAdapterContext);
        frame.getContentPane().add(mxGraphComponent, BorderLayout.CENTER);
        mxHierarchicalLayout layout = new mxHierarchicalLayout(jgxAdapterContext);
        layout.execute(jgxAdapterContext.getDefaultParent());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("Graph");
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        try {
            BufferedImage image = mxCellRenderer.createBufferedImage(jgxAdapterContext, null, 1, Color.WHITE, true, null);
            ImageIO.write(image, "PNG", new File("/Temp/llunatic/egd-graph.png"));
        } catch (IOException ex) {
            logger.error("Unable to save graph image: " + ex.getLocalizedMessage());
        }
    }
 
Example #5
Source File: GraphImageGenerationUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenAdaptedGraph_whenWriteBufferedImage_ThenFileShouldExist() throws IOException {
    JGraphXAdapter<String, DefaultEdge> graphAdapter = new JGraphXAdapter<String, DefaultEdge>(g);
    mxIGraphLayout layout = new mxCircleLayout(graphAdapter);
    layout.execute(graphAdapter.getDefaultParent());
    File imgFile = new File("src/test/resources/graph.png");
    BufferedImage image = mxCellRenderer.createBufferedImage(graphAdapter, null, 2, Color.WHITE, true, null);
    ImageIO.write(image, "PNG", imgFile);
    assertTrue(imgFile.exists());
}