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;
}
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();
}
Aggregations