Search in sources :

Example 1 with NodePressAndDraggingEventListener

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

the class Sizer method getListeners.

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

        @Override
        public void pressNodes(Node[] nodes) {
            Sizer.this.nodes = nodes;
            sizes = new float[nodes.length];
            for (int i = 0; i < nodes.length; i++) {
                Node n = nodes[i];
                sizes[i] = n.size();
            }
        }

        @Override
        public void released() {
            nodes = null;
            sizerPanel.setAvgSize(-1);
        }

        @Override
        public void drag(float displacementX, float displacementY) {
            if (nodes != null) {
                float averageSize = 0f;
                for (int i = 0; i < nodes.length; i++) {
                    Node n = nodes[i];
                    float size = sizes[i];
                    size += displacementY * INTENSITY;
                    if (size < LIMIT) {
                        size = LIMIT;
                    }
                    averageSize += size;
                    n.setSize(size);
                }
                averageSize /= nodes.length;
                sizerPanel.setAvgSize(averageSize);
            }
        }
    };
    return listeners;
}
Also used : NodePressAndDraggingEventListener(org.gephi.tools.spi.NodePressAndDraggingEventListener) Node(org.gephi.graph.api.Node)

Example 2 with NodePressAndDraggingEventListener

use of org.gephi.tools.spi.NodePressAndDraggingEventListener 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

NodePressAndDraggingEventListener (org.gephi.tools.spi.NodePressAndDraggingEventListener)2 ArrayList (java.util.ArrayList)1 Node (org.gephi.graph.api.Node)1 MouseClickEventListener (org.gephi.tools.spi.MouseClickEventListener)1 NodeClickEventListener (org.gephi.tools.spi.NodeClickEventListener)1 NodePressingEventListener (org.gephi.tools.spi.NodePressingEventListener)1 ToolEventListener (org.gephi.tools.spi.ToolEventListener)1