Menu

Need a Jung 2 Edge Selection example

foobarius
2008-10-28
2013-05-29
  • foobarius

    foobarius - 2008-10-28

    I've been looking through the demos and reading the Javadocs but I'm a little confused on how to do something when a user clicks on an edge.
    The demos are very clear on how to accomplish this for vertices and I've sucessfully mimicked them in my programs.  However, I have not been able to do the same with clicking on the edges.

    My program loads a graph from a graphml file.  That graphml file has data items for both edges and vertices.  A user can click on an vertex and and I will print the data items associated with that vertex.  Now I wish to do the same for edges.  The data is there, just can't figure out the right listener stuff to get at the edge data.

    Any pointers to examples, or documentation I've missed will be greatly appreciated.

    Thanks,
    TB

     
    • Joshua O'Madadhain

      TB:

      I think that most of the samples support edge picking; I know that PluggableRendererDemo does.  It's been a while since I used picking, but I think that edge picking is handled by the same classes and data structures that handle vertex picking, just with different methods.  That might be a good place to start looking.

      Joshua

       
      • foobarius

        foobarius - 2008-10-29

        Joshua:

        here is what I've tried (everything ripped off from the demos...)

        in my app I  set

        vv.addGraphMouseListener(new MyGraphMouseListener<Number>());

        where an inner class is defined as:

        class MyGraphMouseListener<VE> implements GraphMouseListener<VE> {

         
        • foobarius

          foobarius - 2008-10-29

          Sorry, .... continuing on....

          class MyGraphMouseListener<VE> implements GraphMouseListener<VE> {
               public void graphClicked(VE ve, MouseEvent me) {
                     System.out.println("ve = " + ve );
               }
          }

          This will produce output when I click on a vertex, but nothing when I click on an edge.

          Thanks in advance and sorry about the split in the posts.

           
          • Tom Nelson

            Tom Nelson - 2008-10-30

            Assuming you are using our standard GraphMouse, you can just do this:

                    vv.getPickedEdgeState().addItemListener(new ItemListener() {

                        public void itemStateChanged(ItemEvent e) {
                            System.err.println("edge "+e.getItem()+" was "+
                                    (e.getStateChange() == ItemEvent.SELECTED ? "Picked":"Unpicked"));
                           
                        }});

            Tom Nelson

             
            • foobarius

              foobarius - 2008-10-30

              Thank you very much for the help.  That was what I needed.
              And thank you and the rest of the Jung team for developing this excellent software!

              TB

               
    • João Gomes

      João Gomes - 2008-12-03

      Hello,

      See if this helps; once your mouse is in picking mode, you can easily use JUNG's classes to achieve that behaviour:

      MultiPickedState<MyCustomEdgeObject> pickedEdges = new MultiPickedState<MyCustomEdgeObject>();
      vViewer.setPickedEdgeState(pickedEdges); //vViewer is a VisualizationViewer object
      System.out.println(pickedEdges.getPicked());

      Also, I'd like to ask you if you can share how you are reading and writing vertex and edge data from GraphML? This has been a major struggle for me :|

      Thanks in advance!

       
    • Mircea

      Mircea - 2009-08-14

      Regarding the solution on Tom Nelson, my question is if it can be added an similar edge listener and in other modes (for example TRANSFORMING), not only for PICKING mode.
      Thanks

       
  • zensur

    zensur - 2010-10-15

    Hello again,
    First thanks for the very fast answer of my last (and first) question.
    I hope you can help me again. I have a similar problem. I build an animated Graph with Tree- and RadialtreeLayout (It was tricky but its ok :D). My Graph is a DirectedSparseGraph with the type Link for the Edges and the type Node for the vertices. Now I need the data of nodes and links by Mouseclick. I changed a GraphMousePlugin and print the data of the Nodes, but i can't print the data of the Links.
    First I try to look, what holds the graph. And when I print out  I got always "timeout".
    Collection<Link> edges = g.getEdges();

    for (Link link : edges)
    {
    System.out.println(link.getTransition().toString());
    }

    Then I tried to set Labels with a transformer instead of printing :

    private final class EdgeString implements Transformer<Link, String>
    {
    @Override
    public String transform(Link link)
    {
    return link.getTransition().toString();
    }

    }
    But the result is the same: I get "timeout" as label.

    I don't understand why I get the data of my Nodes, but not of my Links. And  I don't understand the answer of the question above. I didn't find a GraphMouse where I have the method "addGraphMouseListener". .. :(

    Thanks in advance

    Claudia

     
  • Joshua O'Madadhain

    Claudia:

    If you're getting the literal string "timeout" as a label, then I'm pretty sure that that's what link.getTransition().toString() is returning.  You can confirm this easily enough.

    As for addGraphMouseListener: if you look again at the posts above, you'll see that it's a method on VisualizationViewer.

    Joshua

     
  • zensur

    zensur - 2010-10-15

    Joshua:

    I'm pretty sure, there is no String in my whole code, which calls "timeout". Anyway I will check this again.
    But can you get my another explanation? You seems to be an expert :D

    Thanks for the advice@visualisationviewer

    Claudia

     
  • zensur

    zensur - 2010-10-15

    fuck, Joshua, you get right.

    Sorry, my mistake (what a mess!)!

    Claudia

     

Log in to post a comment.