use of org.gephi.tools.spi.ToolEventListener in project gephi-plugins-bootcamp by gephi.
the class AddNodesTool method getListeners.
@Override
public ToolEventListener[] getListeners() {
return new ToolEventListener[] { new MouseClickEventListener() {
@Override
public void mouseClick(int[] positionViewport, float[] position3d) {
//Get current graph
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
Graph graph = gc.getGraphModel().getGraph();
GraphFactory factory = gc.getGraphModel().factory();
//Add node
Node node = factory.newNode();
node.setX(position3d[0]);
node.setY(position3d[1]);
node.setSize(10f);
graph.addNode(node);
}
}, new NodeClickEventListener() {
@Override
public void clickNodes(Node[] nodes) {
//Get mouse position
float[] position3d = VizController.getInstance().getGraphIO().getMousePosition3d();
//Get current graph
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
Graph graph = gc.getGraphModel().getGraph();
GraphFactory factory = gc.getGraphModel().factory();
//Add node
Node node = factory.newNode();
node.setX(position3d[0]);
node.setY(position3d[1]);
node.setSize(10f);
graph.addNode(node);
//Add edges with the clicked nodes
for (Node n : nodes) {
Edge edge = factory.newEdge(node, n);
graph.addEdge(edge);
}
}
} };
}
use of org.gephi.tools.spi.ToolEventListener in project gephi by gephi.
the class DesktopToolController method select.
@Override
public void select(Tool tool) {
unselect();
if (tool == null) {
return;
}
//Connect events
ArrayList<ToolEventHandler> handlers = new ArrayList<>();
for (ToolEventListener toolListener : tool.getListeners()) {
if (toolListener instanceof NodeClickEventListener) {
NodeClickEventHandler h = new NodeClickEventHandler(toolListener);
h.select();
handlers.add(h);
} else if (toolListener instanceof NodePressingEventListener) {
NodePressingEventHandler h = new NodePressingEventHandler(toolListener);
h.select();
handlers.add(h);
} else if (toolListener instanceof MouseClickEventListener) {
MouseClickEventHandler h = new MouseClickEventHandler(toolListener);
h.select();
handlers.add(h);
} else if (toolListener instanceof NodePressAndDraggingEventListener) {
NodePressAndDraggingEventHandler h = new NodePressAndDraggingEventHandler(toolListener);
h.select();
handlers.add(h);
} else {
throw new RuntimeException("The ToolEventListener " + toolListener.getClass().getSimpleName() + " cannot be recognized");
}
}
currentHandlers = handlers.toArray(new ToolEventHandler[0]);
switch(tool.getSelectionType()) {
case NONE:
VizController.getInstance().getSelectionManager().disableSelection();
break;
case SELECTION:
VizController.getInstance().getSelectionManager().blockSelection(true);
VizController.getInstance().getSelectionManager().setDraggingEnable(false);
break;
case SELECTION_AND_DRAGGING:
VizController.getInstance().getSelectionManager().blockSelection(true);
VizController.getInstance().getSelectionManager().setDraggingEnable(true);
break;
}
currentTool = tool;
currentTool.select();
}
Aggregations