Enable Node selection in Preview Applet

Screenshots, Vectorial Preview and printable exports
onsmidou
Posts:5
Joined:09 Dec 2012 11:33
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Enable Node selection in Preview Applet

Post by onsmidou » 10 Dec 2012 20:57

Hi,

I am new to Gephi and i would like to use Gephi toolkit in my Java application. I am trying to use the Preview Applet in my application , however, i didn't find how to handle node selection events. I need to add interaction like to display additional informations when clicking or hovering a node.

Is there any way to do this with gephi toolkit ?

Thank you in advance.
Best regards.

User avatar
eduramiba
Gephi Code Manager
Posts:1064
Joined:22 Mar 2010 15:30
Location:Madrid, Spain
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by eduramiba » 11 Dec 2012 00:04

Hi,
Mouse events support for preview was recently added and will be included in the next release soon.
You can obtain the nightly build for toolkit or gephi desktop application and try it.


I have not tested it in the toolkit yet, though.
It has been used only for Legend project only. Example here => https://github.com/edubecks/gephi/blob/ ... tener.java

So if you try to create your own mouse listener in preview and give feedback about the API, it will be great.
I suggest using desktop first, and note that you will probably need to create a preview renderer depending on what you want to do.

Eduardo

onsmidou
Posts:5
Joined:09 Dec 2012 11:33
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by onsmidou » 11 Dec 2012 19:11

Hello Eduardo,

Thank you very much for your response.
So if i really understand, i have to implement my own PreviewMouseListener and then send mouse events handled by the PreviewController to my mouse listener like you did in the PreviewControllerImpl class in the code below :

Code: Select all

  
        
        //Avoid drag events arriving to listeners if they did not consume previous press event.
        if ((event.type != PreviewMouseEvent.Type.DRAGGED && event.type != PreviewMouseEvent.Type.RELEASED) || mousePressed) {
            for (PreviewMouseListener listener : previewModel.getEnabledMouseListeners()) {
                switch (event.type) {
                    case CLICKED:
                        listener.mouseClicked(event, previewModel.getProperties(), workspace);
                        break;
                   }
            }
    }
However, i didn't understand how to enable my own Mouse Listener that PreviewController send mouse events to it or how to add it in the EnaledMouseListeners returned by this method.

Code: Select all

previewModel.getEnabledMouseListeners()
If there is an easiyer way to do it please tell me.

Many Thanks.

User avatar
eduramiba
Gephi Code Manager
Posts:1064
Joined:22 Mar 2010 15:30
Location:Madrid, Spain
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by eduramiba » 11 Dec 2012 20:17

Hi,
It's simpler than that.
ProcessingApplet (as obtained here with target.getApplet()) takes care to send mouse events to preview controller.

So all you need to do is implement the mouse listener and optionally a MouseResponsiveRenderer that is affected by your listener behaviour.

Remember to annotate both with ServiceProvider as plugins.

Eduardo.

onsmidou
Posts:5
Joined:09 Dec 2012 11:33
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by onsmidou » 12 Dec 2012 17:50

Hi,

i tried to implement the PreviewMouseListener, i annotated it with ServiceProvider annotation and implemented MouseResponsiveRenderer

Code: Select all

@ServiceProvider(service = MouseResponsiveRenderer.class)
public class MouseResponsiveRendererImpl implements MouseResponsiveRenderer {

    @Override
    public boolean needsPreviewMouseListener(PreviewMouseListener pl) {
       return true;
    }
    
}
but it seems that it doesn't work. what i really want to do is to display node label when a user moves the mouse over a node and when a user select a node that neighbors of that node are also selected or highlighted. I guess that previewModel.getEnabledMouseListeners() returns an empty array of PreviewMouseListeners instances. I nee your help.

Thank you in advance.

User avatar
eduramiba
Gephi Code Manager
Posts:1064
Joined:22 Mar 2010 15:30
Location:Madrid, Spain
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by eduramiba » 12 Dec 2012 21:55

Hi,
Well, first, there is no mouse motion events support. That's because preview displays high quality vector graphics that can't be rendered several times per second, so graphics need to be limited.
OpenGL visualization can be more real-time responsive but we don't have an API for it yet, and is not included in the toolkit.

Current mouse events are click, press, drag and release.

MouseResponsiveRenderer is just for avoiding to draw the graph while drag events happen until mouse is released.
Also, MouseResponsiveRenderer has to be implemented in a renderer, and only annotated with Renderer.class service as always.
Please also read the javadoc carefully. More info here http://wiki.gephi.org/index.php/HowTo_w ... w_renderer



For your purposes, here's what I would do:

Create a listener that reacts to click events and saves in previewProperties wether a node has been clicked.
Then, with a custom renderer, draw labels if necessary, checking your data in previewProperties.
So you won't need to implement the MouseResponsiveRenderer in your renderer at all.
Also, I forgot that you need an item builder, so preview knows how many times your renderer has to be called (once per each label item for example, which will be 0 or 1 in this case).

It can get a little tricky to correctly use the API, so I attached template classes for you to use.
I didn't test them but they should be correct.

Edit: Updated template for better example here http://forum.gephi.org/viewtopic.php?f= ... =10#p10050

Eduardo
Attachments
template.zip
(2.25KiB)Downloaded 416 times

onsmidou
Posts:5
Joined:09 Dec 2012 11:33
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by onsmidou » 13 Dec 2012 20:52

Hi Eduardo,

Thank you so much for the detailed information and for the template, I think I can accomplish what I need with that.

Thanks again.

ankit.gupta2109
Posts:9
Joined:26 Feb 2013 13:33
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by ankit.gupta2109 » 15 Apr 2013 09:42

Hiiii ,,,
if u have accomplished what u were saying about then plz do help me also because i also want the same thing to be done in my application.....

Waiting for ur positive response.................

aco-aco
Posts:1
Joined:16 Apr 2013 22:10
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by aco-aco » 16 Apr 2013 22:16

Hi, i also created my own mouse listener, but i can't add it to my previewModel, can anyone explain it how to add?

Code: Select all

@ServiceProvider(service = PreviewMouseListener.class)
public class MyMouseListener implements PreviewMouseListener {

    @Override
    public void mouseClicked(PreviewMouseEvent event, PreviewProperties properties, Workspace workspace) {
        System.out.println("Mouse clicked!");
    }
Thanks for help

User avatar
eduramiba
Gephi Code Manager
Posts:1064
Joined:22 Mar 2010 15:30
Location:Madrid, Spain
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Enable Node selection in Preview Applet

Post by eduramiba » 25 Apr 2013 22:41

Hi,
You also need to create an associated Renderer. This is a limitation of the current state of the API.
Check this thread for more info https://forum.gephi.org/viewtopic.php?f=27&t=2473

Eduardo

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable