edu.uci.ics.jung.visualization.control.SimpleVertexSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jung-visualization Show documentation
Show all versions of jung-visualization Show documentation
Core visualization support for the JUNG project
The newest version!
package edu.uci.ics.jung.visualization.control;
import java.awt.geom.Point2D;
import com.google.common.base.Supplier;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
/**
* sample implementation showing how to use the VertexSupport interface member of the
* EditingGraphMousePlugin.
* override midVertexCreate and endVertexCreate for more elaborate implementations
* @author tanelso
*
* @param the vertex type
* @param the edge type
*/
public class SimpleVertexSupport implements VertexSupport {
protected Supplier vertexFactory;
public SimpleVertexSupport(Supplier vertexFactory) {
this.vertexFactory = vertexFactory;
}
public void startVertexCreate(BasicVisualizationServer vv,
Point2D point) {
V newVertex = vertexFactory.get();
Layout layout = vv.getGraphLayout();
Graph graph = layout.getGraph();
graph.addVertex(newVertex);
layout.setLocation(newVertex, vv.getRenderContext().getMultiLayerTransformer().inverseTransform(point));
vv.repaint();
}
public void midVertexCreate(BasicVisualizationServer vv,
Point2D point) {
// noop
}
public void endVertexCreate(BasicVisualizationServer vv,
Point2D point) {
//noop
}
public Supplier getVertexFactory() {
return vertexFactory;
}
public void setVertexFactory(Supplier vertexFactory) {
this.vertexFactory = vertexFactory;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy