1 package edu.uci.ics.jung.visualization.control;
2
3 import java.awt.geom.Point2D;
4
5 import com.google.common.base.Supplier;
6
7 import edu.uci.ics.jung.graph.Graph;
8 import edu.uci.ics.jung.graph.util.EdgeType;
9 import edu.uci.ics.jung.visualization.BasicVisualizationServer;
10
11 public class SimpleEdgeSupport<V,E> implements EdgeSupport<V,E> {
12
13 protected Point2D down;
14 protected EdgeEffects<V,E> edgeEffects;
15 protected EdgeType edgeType;
16 protected Supplier<E> edgeFactory;
17 protected V startVertex;
18
19 public SimpleEdgeSupport(Supplier<E> edgeFactory) {
20 this.edgeFactory = edgeFactory;
21 this.edgeEffects = new CubicCurveEdgeEffects<V,E>();
22 }
23
24
25 public void startEdgeCreate(BasicVisualizationServer<V, E> vv,
26 V startVertex, Point2D startPoint, EdgeType edgeType) {
27 this.startVertex = startVertex;
28 this.down = startPoint;
29 this.edgeType = edgeType;
30 this.edgeEffects.startEdgeEffects(vv, startPoint, startPoint);
31 if(edgeType == EdgeType.DIRECTED) {
32 this.edgeEffects.startArrowEffects(vv, startPoint, startPoint);
33 }
34 vv.repaint();
35 }
36
37
38 public void midEdgeCreate(BasicVisualizationServer<V, E> vv,
39 Point2D midPoint) {
40 if(startVertex != null) {
41 this.edgeEffects.midEdgeEffects(vv, down, midPoint);
42 if(this.edgeType == EdgeType.DIRECTED) {
43 this.edgeEffects.midArrowEffects(vv, down, midPoint);
44 }
45 vv.repaint();
46 }
47 }
48
49
50 public void endEdgeCreate(BasicVisualizationServer<V, E> vv, V endVertex) {
51 if(startVertex != null) {
52 Graph<V,E> graph = vv.getGraphLayout().getGraph();
53 graph.addEdge(edgeFactory.get(), startVertex, endVertex, edgeType);
54 vv.repaint();
55 }
56 startVertex = null;
57 edgeType = EdgeType.UNDIRECTED;
58 edgeEffects.endEdgeEffects(vv);
59 edgeEffects.endArrowEffects(vv);
60 }
61
62 public EdgeEffects<V, E> getEdgeEffects() {
63 return edgeEffects;
64 }
65
66 public void setEdgeEffects(EdgeEffects<V, E> edgeEffects) {
67 this.edgeEffects = edgeEffects;
68 }
69
70 public EdgeType getEdgeType() {
71 return edgeType;
72 }
73
74 public void setEdgeType(EdgeType edgeType) {
75 this.edgeType = edgeType;
76 }
77
78 public Supplier<E> getEdgeFactory() {
79 return edgeFactory;
80 }
81
82 public void setEdgeFactory(Supplier<E> edgeFactory) {
83 this.edgeFactory = edgeFactory;
84 }
85
86 }