edu.uci.ics.jung.visualization.control.SimpleEdgeSupport 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 java.awt.geom.Point2D;
import java.util.function.Supplier;
public class SimpleEdgeSupport implements EdgeSupport {
protected Point2D down;
protected EdgeEffects edgeEffects;
protected Supplier edgeFactory;
protected N startNode;
public SimpleEdgeSupport(Supplier edgeFactory) {
this.edgeFactory = edgeFactory;
this.edgeEffects = new CubicCurveEdgeEffects();
}
@Override
public void startEdgeCreate(BasicVisualizationServer vv, N startNode, Point2D startPoint) {
this.startNode = startNode;
this.down = startPoint;
this.edgeEffects.startEdgeEffects(vv, startPoint, startPoint);
if (vv.getModel().getNetwork().isDirected()) {
this.edgeEffects.startArrowEffects(vv, startPoint, startPoint);
}
vv.repaint();
}
@Override
public void midEdgeCreate(BasicVisualizationServer vv, Point2D midPoint) {
if (startNode != null) {
this.edgeEffects.midEdgeEffects(vv, down, midPoint);
if (vv.getModel().getNetwork().isDirected()) {
this.edgeEffects.midArrowEffects(vv, down, midPoint);
}
vv.repaint();
}
}
@Override
public void endEdgeCreate(BasicVisualizationServer vv, N endNode) {
Preconditions.checkState(
vv.getModel().getNetwork() instanceof MutableNetwork, ?>, "graph must be mutable");
if (startNode != null) {
MutableNetwork graph = (MutableNetwork) vv.getModel().getNetwork();
graph.addEdge(startNode, endNode, edgeFactory.get());
vv.getEdgeSpatial().recalculate();
vv.repaint();
}
startNode = null;
edgeEffects.endEdgeEffects(vv);
edgeEffects.endArrowEffects(vv);
}
@Override
public void abort(BasicVisualizationServer vv) {
startNode = null;
edgeEffects.endEdgeEffects(vv);
edgeEffects.endArrowEffects(vv);
vv.repaint();
}
public EdgeEffects getEdgeEffects() {
return edgeEffects;
}
public void setEdgeEffects(EdgeEffects edgeEffects) {
this.edgeEffects = edgeEffects;
}
public Supplier getEdgeFactory() {
return edgeFactory;
}
public void setEdgeFactory(Supplier edgeFactory) {
this.edgeFactory = edgeFactory;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy