Enable Node selection in Preview Applet

Screenshots, Vectorial Preview and printable exports
ckapop
Posts:2
Joined:06 Sep 2013 21:27
[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 ckapop » 10 Sep 2013 19:01

Is there a tutorial or complete example in existence on how to do this?

I am struggling on how to get a PreviewMouseListener along with the needed Renderer working/used by my PreviewController.

lapanoid
Posts:6
Joined:13 Sep 2013 17:17
[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 lapanoid » 23 Sep 2013 13:02

I am strugling to make gephi PApplet sensible to mouse events. I made MyRenderer and MyPreviewMouseListener but still no reaction on mouse.
If somebody managed with that, please help me!
My code is hosted here https://github.com/lapanoid/GephiVisApp, any comments would be highly appreciated.

veraptor
Posts:2
Joined:22 Nov 2013 06:17
[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 veraptor » 26 Nov 2013 06:43

I have successfully plugged the mouse listener into the preview applet. The trick was to register the MouseResponsiveRenderer as one of the ManagedRenderers on the PreviewModel.

Code: Select all

        ManagedRenderer [] mr = previewModel.getManagedRenderers();
        ManagedRenderer [] mr2 = Arrays.copyOf(mr, mr.length+1);
        mr2[mr.length] = new ManagedRenderer(new MyPreviewMouseResponsiveRenderer(), true);
        previewModel.setManagedRenderers(mr2);
        previewController.refreshPreview();
Next, when I tried to figure out which node should be selected based on its coordinates, I found that there was a bug: the Y position in the event was negative with respect to the actual node position. Surprisingly, a simple sign reversal (marked in bold below) was enough to fix the problem.

Code: Select all

public class MyPreviewMouseListener implements PreviewMouseListener{
        @Override
        public void mouseClicked(PreviewMouseEvent event, PreviewProperties properties, Workspace workspace) {
                System.out.println("I'm clicked!!: x:" + event.x + ", y:" + event.y);     
                float x = event.x;
                [b]float y = -event.y;[/b]
  
                float minDist = Float.MAX_VALUE;
                Node nnNode = null;
                for (Node n : Lookup.getDefault().lookup(GraphController.class).getModel().getGraph.getNodes()) {
                    float sqdist = (n.getNodeData().x()-x)*(n.getNodeData().x()-x);
                    sqdist+=  (n.getNodeData().y()- y)*(n.getNodeData().y()- y);
                    sqdist = (float)Math.sqrt(sqdist);
                   if(sqdist<minDist){
                       nnNode = n;
                       minDist = sqdist;
                       break;
                   }
                }
                  
                System.err.println("Nearest node: " + nnNode.getNodeData().getId()+ ", "+ nnNode.getNodeData().getLabel()+" minDist " + minDist);
                properties.putValue("display-label.node.id", nnNode.getNodeData().getId());
   }
}

imenMegd
Posts:6
Joined:07 Oct 2013 10:09
[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 imenMegd » 13 Dec 2013 09:38

Hi,

Does not work for me , can you join your code please.
Thank you !

ph0123
Posts:8
Joined:05 Dec 2013 04:07
Location:Việt Nam
[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 ph0123 » 19 Dec 2013 08:17

hi,
how to add mouse listener in "template.zip" in to project layout with gephi toolkit?
tks so much!

girlss
Posts:3
Joined:19 Dec 2013 12:00
[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 girlss » 19 Dec 2013 14:21

hello :) ,
I ran the tutorial provided in the forum, but I could not solve the problem. I have defined a PreviewMouseListener and a RendererMouseListener and added the latter to render the applet that contains the graph.
The execution result is an error message, as defined in preprocess method.
So how do I aggiundere the mouse listener having taken as a reference the "template.zip" layout for the project with the Gephi toolkit?
thank you!

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 » 08 Jan 2014 21:22

Hi,
Just by using the ServiceProvider annotation, the renderer should be automatically added to gephi runtime.
Though you probably need to build a jar dist file before running it.

Can you provide the error you get?
And the code you use?

Eduardo

girlss
Posts:3
Joined:19 Dec 2013 12:00
[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 girlss » 15 Jan 2014 16:59

Hi,
I have written a class MyPreviewMouseListener:

Code: Select all

import org.gephi.preview.api.PreviewMouseEvent;
import org.gephi.preview.api.PreviewProperties;
import org.gephi.preview.spi.PreviewMouseListener;
import org.gephi.project.api.Workspace;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = PreviewMouseListener.class)    
public class MyPreviewMouseListener implements PreviewMouseListener{
        @Override
        public void mouseClicked(PreviewMouseEvent event,
                        PreviewProperties properties, Workspace workspace) {
                System.out.println("I'm clicked!!: x:" + event.x + ", y:" + event.y);
        }
        @Override
        public void mousePressed(PreviewMouseEvent event,
                        PreviewProperties properties, Workspace workspace) {System.out.println("I'm pressed!!: x:" + event.x + ", y:" + event.y);}
        @Override
        public void mouseDragged(PreviewMouseEvent event,
                        PreviewProperties properties, Workspace workspace) {}
        @Override
        public void mouseReleased(PreviewMouseEvent event,
                        PreviewProperties properties, Workspace workspace) {}
}
I also written a class MyPreviewMouseResponsiveRenderer:

Code: Select all

import org.gephi.preview.api.Item;
import org.gephi.preview.api.PreviewModel;
import org.gephi.preview.api.PreviewProperties;
import org.gephi.preview.api.PreviewProperty;
import org.gephi.preview.api.RenderTarget;
import org.gephi.preview.spi.ItemBuilder;
import org.gephi.preview.spi.MouseResponsiveRenderer;
import org.gephi.preview.spi.PreviewMouseListener;
import org.gephi.preview.spi.Renderer;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = Renderer.class)
public class MyPreviewMouseResponsiveRenderer implements MouseResponsiveRenderer, Renderer{

	@Override
	public boolean needsPreviewMouseListener(
			PreviewMouseListener previewMouseListener) {
		return previewMouseListener instanceof MyPreviewMouseListener;
	}

	public boolean needsItemBuilder(ItemBuilder itemBuilder, PreviewProperties properties) {
		return true;
	}

	public boolean isRendererForitem(Item item, PreviewProperties properties) {
		return false;
	}


	public void render(Item item, RenderTarget target, PreviewProperties properties) {
		System.err.println("render Called");
		
	}

	public void preProcess(PreviewModel previewModel) {
		System.err.println("preProcess Called");
	}

	public PreviewProperty[] getProperties() {
		return new PreviewProperty[0];
	}

	public String getDisplayName() {
		return "My renderer";
	}
}
I, finally, written a class in whitch I have added an object MyPreviewMouseResponsiveRenderer to the preview model:

Code: Select all

ManagedRenderer [] mr = previewModel.getManagedRenderers();
		ManagedRenderer [] mr2 = Arrays.copyOf(mr, mr.length+1);
		mr2[mr.length] = new ManagedRenderer(new MyPreviewMouseResponsiveRenderer(), true);
		previewModel.setManagedRenderers(mr2);
If I click on any area of the applet does not show the coordinates of the point, and on the console, it shows the message "preProcess called".

Probably the problem is the association of the MouseListener to the graph. How can I do that?

PS: Sorry for a delay in the response! :)


girlss
_______________________________

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 » 21 Feb 2014 19:19

Hi,
Sorry for late response.

You are only seeing preProcess called message and not clicked message because Netbeans Platform applications ignore System.out for some reason.
So you should use System.err for debugging, or other kinds of output like a dialog.

I attach an updated, tested, template.zip file that shows a message when a node is clicked. It also marks the clicked node in the graph canvas until other node, or no node is clicked.
While doing these example, I noticed and remembered that Y axis coordinates are inverted in relation to node coordinates. Pay attention to this.

Eduardo
Attachments
template-updated.zip
(2.76KiB)Downloaded 197 times

DengpanXue
Posts:1
Joined:23 Apr 2014 07:54
[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 DengpanXue » 23 Apr 2014 08:24

Can anybody give me a main function,when I use these template's function,I don't known how to use these ,when I write a main function by myself,it doesn't work at all!Thanks a lot

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