Enable Node selection in Preview Applet
-
- 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
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.
I am struggling on how to get a PreviewMouseListener along with the needed Renderer working/used by my PreviewController.
-
- 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
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.
If somebody managed with that, please help me!
My code is hosted here https://github.com/lapanoid/GephiVisApp, any comments would be highly appreciated.
-
- 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
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.
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
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();
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());
}
}
-
- 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
Hi,
Does not work for me , can you join your code please.
Thank you !
Does not work for me , can you join your code please.
Thank you !
-
- 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
hi,
how to add mouse listener in "template.zip" in to project layout with gephi toolkit?
tks so much!
how to add mouse listener in "template.zip" in to project layout with gephi toolkit?
tks so much!
-
- 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
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!

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!
- 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
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
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
-
- 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
Hi,
I have written a class MyPreviewMouseListener:
I also written a class MyPreviewMouseResponsiveRenderer:
I, finally, written a class in whitch I have added an object MyPreviewMouseResponsiveRenderer to the preview model:
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
_______________________________
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) {}
}
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";
}
}
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);
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
_______________________________
- 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
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
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 432 times
-
- 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
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