Search in sources :

Example 1 with MouseClickEventListener

use of org.gephi.tools.spi.MouseClickEventListener in project gephi by gephi.

the class NodePencil method getListeners.

@Override
public ToolEventListener[] getListeners() {
    listeners = new ToolEventListener[1];
    listeners[0] = new MouseClickEventListener() {

        @Override
        public void mouseClick(int[] positionViewport, float[] position3d) {
            color = nodePencilPanel.getColor();
            size = nodePencilPanel.getNodeSize();
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            GraphModel gm = gc.getGraphModel();
            Graph graph = gm.getGraph();
            Node node = gm.factory().newNode();
            node.setX(position3d[0]);
            node.setY(position3d[1]);
            node.setSize(size);
            node.setColor(color);
            graph.addNode(node);
        }
    };
    return listeners;
}
Also used : MouseClickEventListener(org.gephi.tools.spi.MouseClickEventListener) Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) GraphController(org.gephi.graph.api.GraphController)

Example 2 with MouseClickEventListener

use of org.gephi.tools.spi.MouseClickEventListener in project gephi by gephi.

the class ShortestPath method getListeners.

@Override
public ToolEventListener[] getListeners() {
    listeners = new ToolEventListener[2];
    listeners[0] = new NodeClickEventListener() {

        @Override
        public void clickNodes(Node[] nodes) {
            Node n = nodes[0];
            if (sourceNode == null) {
                sourceNode = n;
                shortestPathPanel.setResult("");
                shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status2"));
            } else if (n != sourceNode) {
                color = shortestPathPanel.getColor();
                Node targetNode = n;
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                GraphModel gm = gc.getGraphModel();
                AbstractShortestPathAlgorithm algorithm;
                if (gm.isDirected()) {
                    algorithm = new BellmanFordShortestPathAlgorithm(gm.getDirectedGraphVisible(), sourceNode);
                } else {
                    algorithm = new DijkstraShortestPathAlgorithm(gm.getGraphVisible(), sourceNode);
                }
                algorithm.compute();
                double distance;
                if ((distance = algorithm.getDistances().get(targetNode)) != Double.POSITIVE_INFINITY) {
                    targetNode.setColor(color);
                    VizController.getInstance().selectNode(targetNode);
                    Edge predecessorEdge = algorithm.getPredecessorIncoming(targetNode);
                    Node predecessor = algorithm.getPredecessor(targetNode);
                    while (predecessorEdge != null && predecessor != sourceNode) {
                        predecessorEdge.setColor(color);
                        VizController.getInstance().selectEdge(predecessorEdge);
                        predecessor.setColor(color);
                        VizController.getInstance().selectNode(predecessor);
                        predecessorEdge = algorithm.getPredecessorIncoming(predecessor);
                        predecessor = algorithm.getPredecessor(predecessor);
                    }
                    predecessorEdge.setColor(color);
                    VizController.getInstance().selectEdge(predecessorEdge);
                    sourceNode.setColor(color);
                    VizController.getInstance().selectNode(sourceNode);
                    shortestPathPanel.setResult(NbBundle.getMessage(ShortestPath.class, "ShortestPath.result", distance));
                } else {
                    // No path
                    shortestPathPanel.setResult(NbBundle.getMessage(ShortestPath.class, "ShortestPath.noresult"));
                }
                sourceNode = null;
                shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status1"));
            }
        }
    };
    listeners[1] = new MouseClickEventListener() {

        @Override
        public void mouseClick(int[] positionViewport, float[] position3d) {
            if (sourceNode != null) {
                // Cancel
                shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status1"));
                sourceNode = null;
            } else {
                VizController.getInstance().resetSelection();
            }
        }
    };
    return listeners;
}
Also used : MouseClickEventListener(org.gephi.tools.spi.MouseClickEventListener) Node(org.gephi.graph.api.Node) DijkstraShortestPathAlgorithm(org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm) AbstractShortestPathAlgorithm(org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm) BellmanFordShortestPathAlgorithm(org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm) GraphModel(org.gephi.graph.api.GraphModel) NodeClickEventListener(org.gephi.tools.spi.NodeClickEventListener) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 3 with MouseClickEventListener

use of org.gephi.tools.spi.MouseClickEventListener in project gephi by gephi.

the class EdgePencil method getListeners.

@Override
public ToolEventListener[] getListeners() {
    listeners = new ToolEventListener[2];
    listeners[0] = new NodeClickEventListener() {

        @Override
        public void clickNodes(Node[] nodes) {
            Node n = nodes[0];
            if (sourceNode == null) {
                sourceNode = n;
                edgePencilPanel.setStatus(NbBundle.getMessage(EdgePencil.class, "EdgePencil.status2"));
            } else {
                color = edgePencilPanel.getColor();
                weight = edgePencilPanel.getWeight();
                boolean directed = edgePencilPanel.isDirected;
                Edge edge = Lookup.getDefault().lookup(GraphElementsController.class).createEdge(sourceNode, n, directed);
                edge.setColor(color);
                sourceNode = null;
                edgePencilPanel.setStatus(NbBundle.getMessage(EdgePencil.class, "EdgePencil.status1"));
            }
        }
    };
    listeners[1] = new MouseClickEventListener() {

        @Override
        public void mouseClick(int[] positionViewport, float[] position3d) {
            if (sourceNode != null) {
                // Cancel
                edgePencilPanel.setStatus(NbBundle.getMessage(EdgePencil.class, "EdgePencil.status1"));
                sourceNode = null;
            }
        }
    };
    return listeners;
}
Also used : MouseClickEventListener(org.gephi.tools.spi.MouseClickEventListener) Node(org.gephi.graph.api.Node) NodeClickEventListener(org.gephi.tools.spi.NodeClickEventListener) Edge(org.gephi.graph.api.Edge)

Example 4 with MouseClickEventListener

use of org.gephi.tools.spi.MouseClickEventListener 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);
            }
        }
    } };
}
Also used : MouseClickEventListener(org.gephi.tools.spi.MouseClickEventListener) GraphFactory(org.gephi.graph.api.GraphFactory) ToolEventListener(org.gephi.tools.spi.ToolEventListener) Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node) NodeClickEventListener(org.gephi.tools.spi.NodeClickEventListener) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 5 with MouseClickEventListener

use of org.gephi.tools.spi.MouseClickEventListener 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();
}
Also used : MouseClickEventListener(org.gephi.tools.spi.MouseClickEventListener) ArrayList(java.util.ArrayList) NodePressingEventListener(org.gephi.tools.spi.NodePressingEventListener) NodePressAndDraggingEventListener(org.gephi.tools.spi.NodePressAndDraggingEventListener) ToolEventListener(org.gephi.tools.spi.ToolEventListener) NodeClickEventListener(org.gephi.tools.spi.NodeClickEventListener)

Aggregations

MouseClickEventListener (org.gephi.tools.spi.MouseClickEventListener)5 Node (org.gephi.graph.api.Node)4 NodeClickEventListener (org.gephi.tools.spi.NodeClickEventListener)4 Edge (org.gephi.graph.api.Edge)3 GraphController (org.gephi.graph.api.GraphController)3 Graph (org.gephi.graph.api.Graph)2 GraphModel (org.gephi.graph.api.GraphModel)2 ToolEventListener (org.gephi.tools.spi.ToolEventListener)2 ArrayList (java.util.ArrayList)1 AbstractShortestPathAlgorithm (org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm)1 BellmanFordShortestPathAlgorithm (org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm)1 DijkstraShortestPathAlgorithm (org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm)1 GraphFactory (org.gephi.graph.api.GraphFactory)1 NodePressAndDraggingEventListener (org.gephi.tools.spi.NodePressAndDraggingEventListener)1 NodePressingEventListener (org.gephi.tools.spi.NodePressingEventListener)1