Search in sources :

Example 1 with VertexLabelAsShapeRenderer

use of edu.uci.ics.jung.visualization.renderers.VertexLabelAsShapeRenderer in project abstools by abstools.

the class JungObjectGraph method begin.

@Override
public void begin() {
    graph = new DirectedSparseGraph<String, Integer>();
    layout = new FRLayout<String, Integer>(graph);
    layout.setSize(new Dimension(600, 600));
    vv = new VisualizationViewer<String, Integer>(layout, new Dimension(600, 600));
    vv.setBackground(Color.white);
    startAnimator();
    VertexLabelAsShapeRenderer<String, Integer> vlasr = new VertexLabelAsShapeRenderer<String, Integer>(vv.getRenderContext());
    // vv.getRenderContext().setVertexShapeTransformer(arg0)
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setVertexShapeTransformer(vlasr);
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JFrame frame = new JFrame("Simple Graph View");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JPanel pane = new JPanel();
                pane.setLayout(new BorderLayout());
                pane.add(vv, BorderLayout.CENTER);
                frame.getContentPane().add(pane);
                pane.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
                frame.pack();
                frame.setVisible(true);
            }
        });
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
Also used : JPanel(javax.swing.JPanel) Dimension(java.awt.Dimension) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) InvocationTargetException(java.lang.reflect.InvocationTargetException) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) VertexLabelAsShapeRenderer(edu.uci.ics.jung.visualization.renderers.VertexLabelAsShapeRenderer)

Aggregations

ToStringLabeller (edu.uci.ics.jung.visualization.decorators.ToStringLabeller)1 VertexLabelAsShapeRenderer (edu.uci.ics.jung.visualization.renderers.VertexLabelAsShapeRenderer)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 JFrame (javax.swing.JFrame)1 JPanel (javax.swing.JPanel)1