edu.uci.ics.jung.visualization.control.SimpleEdgeSupport 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.graph.Graph;
import edu.uci.ics.jung.graph.util.EdgeType;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
public class SimpleEdgeSupport implements EdgeSupport {
protected Point2D down;
protected EdgeEffects edgeEffects;
protected EdgeType edgeType;
protected Supplier edgeFactory;
protected V startVertex;
public SimpleEdgeSupport(Supplier edgeFactory) {
this.edgeFactory = edgeFactory;
this.edgeEffects = new CubicCurveEdgeEffects();
}
// @Override
public void startEdgeCreate(BasicVisualizationServer vv,
V startVertex, Point2D startPoint, EdgeType edgeType) {
this.startVertex = startVertex;
this.down = startPoint;
this.edgeType = edgeType;
this.edgeEffects.startEdgeEffects(vv, startPoint, startPoint);
if(edgeType == EdgeType.DIRECTED) {
this.edgeEffects.startArrowEffects(vv, startPoint, startPoint);
}
vv.repaint();
}
// @Override
public void midEdgeCreate(BasicVisualizationServer vv,
Point2D midPoint) {
if(startVertex != null) {
this.edgeEffects.midEdgeEffects(vv, down, midPoint);
if(this.edgeType == EdgeType.DIRECTED) {
this.edgeEffects.midArrowEffects(vv, down, midPoint);
}
vv.repaint();
}
}
// @Override
public void endEdgeCreate(BasicVisualizationServer vv, V endVertex) {
if(startVertex != null) {
Graph graph = vv.getGraphLayout().getGraph();
graph.addEdge(edgeFactory.get(), startVertex, endVertex, edgeType);
vv.repaint();
}
startVertex = null;
edgeType = EdgeType.UNDIRECTED;
edgeEffects.endEdgeEffects(vv);
edgeEffects.endArrowEffects(vv);
}
public EdgeEffects getEdgeEffects() {
return edgeEffects;
}
public void setEdgeEffects(EdgeEffects edgeEffects) {
this.edgeEffects = edgeEffects;
}
public EdgeType getEdgeType() {
return edgeType;
}
public void setEdgeType(EdgeType edgeType) {
this.edgeType = edgeType;
}
public Supplier getEdgeFactory() {
return edgeFactory;
}
public void setEdgeFactory(Supplier edgeFactory) {
this.edgeFactory = edgeFactory;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy