edu.uci.ics.jung.visualization.control.SimpleNodeSupport Maven / Gradle / Ivy
package edu.uci.ics.jung.visualization.control;
import com.google.common.base.Preconditions;
import com.google.common.graph.MutableNetwork;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.VisualizationModel;
import java.awt.geom.Point2D;
import java.util.function.Supplier;
/**
* sample implementation showing how to use the NodeSupport interface member of the
* EditingGraphMousePlugin. override midNodeCreate and endNodeCreate for more elaborate
* implementations
*
* @author Tom Nelson
* @param the node type
* @param the edge type
*/
public class SimpleNodeSupport implements NodeSupport {
protected Supplier nodeFactory;
public SimpleNodeSupport(Supplier nodeFactory) {
this.nodeFactory = nodeFactory;
}
public void startNodeCreate(BasicVisualizationServer vv, Point2D point) {
Preconditions.checkState(
vv.getModel().getNetwork() instanceof MutableNetwork, ?>, "graph must be mutable");
N newNode = nodeFactory.get();
VisualizationModel visualizationModel = vv.getModel();
MutableNetwork graph = (MutableNetwork) visualizationModel.getNetwork();
graph.addNode(newNode);
Point2D p2d = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(point);
visualizationModel.getLayoutModel().set(newNode, p2d.getX(), p2d.getY());
vv.repaint();
}
public void midNodeCreate(BasicVisualizationServer vv, Point2D point) {
// noop
}
public void endNodeCreate(BasicVisualizationServer vv, Point2D point) {
// noop
}
public Supplier getNodeFactory() {
return nodeFactory;
}
public void setNodeFactory(Supplier nodeFactory) {
this.nodeFactory = nodeFactory;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy