Menu

Problem with graph display

Loic
2006-09-29
2013-05-29
  • Loic

    Loic - 2006-09-29

    Hi,

    I've no display when I try to load a graph from a graphML file, after having initialized the display even if I repaint the VizualizationViewer.

    This is the code I use, maybe you'll find something wrong :

    //The initialization method (pGraph is a panel in my Frame)
    public void init(){
        g = new UndirectedSparseGraph();
        l = new FRLayout(g);
        PluggableRenderer r = new PluggableRenderer();
        r.setVertexStringer(new VertexStringerShowID());
        vv = new VisualizationViewer(l,r, new Dimension(800, 800));
        vv.setGraphMouse(new DefaultModalGraphMouse());
        GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(vv);
        pGraph.add(scrollPane);
    }

    Then I do this :

    g = loadFile("foo.xml");
    l.update();
    if (!vv.isVisRunnerRunning()){
        vv.init();
    }
    vv.repaint();

    The loadFile function is here :

    private Graph loadFile(String fileName){
        GraphMLFile f;
        Graph g = null;
        FileReader fr;
        f = new GraphMLFile();
        fr = null;
        try{
            fr = new FileReader(fileName);
            g = f.load(fr);
            fr.close();
        }catch(Exception e){
            System.out.println("Exception : " + e);
            e.printStackTrace();
        }
        return g;
    }

    If I initialize the display after having loaded the file (except the initialization of 'g')it's all right, but my aim is to load many files one after one and I'd like not to re-initialize the display at each time.

    I also tried to put vv.suspend() before I load the graph and vv.unsuspend after the layout update but it doesn't change anything.

    Thanks for your help

     
    • Tom Nelson

      Tom Nelson - 2006-09-29

      In your code, your layout (and thus your VisualizationViewer)
      knows nothing about the brand new graph that you create and
      return from your 'loadFile' method. That's why your
      VisualizationViewer continues to show the first graph
      you created 'new UndirectedSparseGraph()', which is
      empty.

      Other than creating graphs from files, what you want is
      very simiar to our ShowLayouts demo, which, in addition
      to changing layouts, also lets you change the graph that
      is being rendered. The source code for ShowLayouts is
      what you should follow to do what you want.

      Tom Nelson

       
    • Loic

      Loic - 2006-09-29

      I have watched the ShowLayouts source but in it the layout is re-created each time the graph changes. If I do this way it works. But why couldn't I use the update method of the layout (from LayoutMutable) ? If I understant well, it is designed for this purpose only. And most important, why doesn't it work when I do use it ?

       
      • Tom Nelson

        Tom Nelson - 2006-09-29

        >By: loicdvi
        >
        >I have watched the ShowLayouts source but in it
        >the layout is re-created each
        >time the graph changes. If I do this way it
        >works.

        That is the correct way to do what you want.

        > But why couldn't I use the
        >update method of the layout (from LayoutMutable)
        >? If I understant well, it
        >is designed for this purpose only. And most
        >important, why doesn't it work when
        >I do use it ?

        See my previous email.
        Jung (and Java) do not work the way you are
        trying to use them.

        Tom

         
    • Nobody/Anonymous

      i have downloaded commons-codec-1.3.jar, colt-1.2.0.zip, xerces.jar, jung-1.7.5.jar
      and i tried to run one sample file
      can u tell why iam getting following Error ?

      C:\Documents and Settings\praveen.bora>java samples.graph.ShowLayouts
      Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/co
      llections/functors/InstanceofPredicate
              at edu.uci.ics.jung.graph.Graph.<clinit>(Graph.java:35)
              at edu.uci.ics.jung.graph.impl.UndirectedSparseGraph.<init>(UndirectedSp
      arseGraph.java:46)
              at edu.uci.ics.jung.utils.TestGraphs.createTestGraph(TestGraphs.java:77)

              at samples.graph.ShowLayouts.getGraphPanel(ShowLayouts.java:120)
              at samples.graph.ShowLayouts.main(ShowLayouts.java:213)

      C:\Documents and Settings\praveen.bora>

       
      • Joshua O'Madadhain

        I don't know what commons-codec is, but it's not commons-collections, which is what you need.  Take a look at the downloads page on the JUNG website.

        Joshua

         

Log in to post a comment.