Skip to content

Commit c57450a

Browse files
committed
Removal of SmartGraphEdgeBase interface. No longer needed as we now have a single generic SmartGraphEdgeNode implementation.
1 parent 0946da5 commit c57450a

4 files changed

Lines changed: 59 additions & 116 deletions

File tree

src/main/java/com/brunomnsilva/smartgraph/graphview/SmartGraphEdge.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ public interface SmartGraphEdge<E, V> extends SmartStylableNode {
5050
* @see SmartGraphPanel
5151
*/
5252
Edge<E, V> getUnderlyingEdge();
53-
53+
54+
/**
55+
* Returns the inbound vertex of the edge.
56+
* @return the inbound vertex of the edge.
57+
*/
58+
SmartGraphVertex<V> getInbound();
59+
60+
/**
61+
* Returns the outbound vertex of the edge.
62+
* @return the outbound vertex of the edge.
63+
*/
64+
SmartGraphVertex<V> getOutbound();
65+
5466
/**
5567
* Returns the attached arrow of the edge, for styling purposes.
5668
* <br/>

src/main/java/com/brunomnsilva/smartgraph/graphview/SmartGraphEdgeBase.java

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/main/java/com/brunomnsilva/smartgraph/graphview/SmartGraphEdgeNode.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
*
5353
* @author brunomnsilva
5454
*/
55-
public class SmartGraphEdgeNode<E, V> extends CubicCurve implements SmartGraphEdgeBase<E, V> {
55+
public class SmartGraphEdgeNode<E, V> extends CubicCurve implements SmartGraphEdge<E, V>, SmartLabelledNode {
5656

5757
// For self-loops
5858
public static final int LOOP_RADIUS_FACTOR = 4;
@@ -140,12 +140,18 @@ public SmartGraphEdgeNode(Edge<E, V> edge, SmartGraphVertexNode<V> inbound, Smar
140140
propagateHoverEffectToArrow();
141141
}
142142

143-
@Override
143+
/**
144+
* Returns the current multiplicity index of the edge.
145+
* @return the current multiplicity index of the edge.
146+
*/
144147
public int getMultiplicityIndex() {
145148
return multiplicityIndex;
146149
}
147150

148-
@Override
151+
/**
152+
* Sets the multiplicity index of the edge. This impacts the curve of the edge.
153+
* @param multiplicityIndex the new multiplicity index.
154+
*/
149155
public void setMultiplicityIndex(int multiplicityIndex) {
150156
Args.requireNonNegative(multiplicityIndex, "multiplicityIndex");
151157

@@ -156,12 +162,12 @@ public void setMultiplicityIndex(int multiplicityIndex) {
156162
}
157163

158164
@Override
159-
public SmartGraphVertexNode<V> getInbound() {
165+
public SmartGraphVertex<V> getInbound() {
160166
return inbound;
161167
}
162168

163169
@Override
164-
public SmartGraphVertexNode<V> getOutbound() {
170+
public SmartGraphVertex<V> getOutbound() {
165171
return outbound;
166172
}
167173

@@ -406,7 +412,11 @@ public Edge<E, V> getUnderlyingEdge() {
406412
return underlyingEdge;
407413
}
408414

409-
@Override
415+
/**
416+
* Attaches a {@link SmartArrow} to this edge, binding its position/rotation.
417+
*
418+
* @param arrow arrow to attach
419+
*/
410420
public void attachArrow(SmartArrow arrow) {
411421
this.attachedArrow = arrow;
412422

@@ -437,7 +447,11 @@ public void attachArrow(SmartArrow arrow) {
437447
arrow.getTransforms().add(pullbackTranslation);
438448
}
439449

440-
@Override
450+
/**
451+
* Returns the attached {@link SmartArrow}, if any.
452+
*
453+
* @return reference of the attached arrow; null if none.
454+
*/
441455
public SmartArrow getAttachedArrow() {
442456
return this.attachedArrow;
443457
}

src/main/java/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class SmartGraphPanel<V, E> extends Pane {
9090
private final Graph<V, E> theGraph;
9191
private final SmartPlacementStrategy placementStrategy;
9292
private final Map<Vertex<V>, SmartGraphVertexNode<V>> vertexNodes;
93-
private final Map<Edge<E, V>, SmartGraphEdgeBase<E, V>> edgeNodes;
93+
private final Map<Edge<E, V>, SmartGraphEdgeNode<E, V>> edgeNodes;
9494
private final Map<Edge<E,V>, Tuple<Vertex<V>>> connections;
9595
private boolean initialized = false;
9696
private final boolean edgesWithArrows;
@@ -631,7 +631,7 @@ private void initNodes() {
631631
graphVertexIn.addAdjacentVertex(graphVertexOppositeOut);
632632
graphVertexOppositeOut.addAdjacentVertex(graphVertexIn);
633633

634-
SmartGraphEdgeBase<E,V> graphEdge = createEdge(edge, graphVertexIn, graphVertexOppositeOut);
634+
SmartGraphEdgeNode<E,V> graphEdge = createEdge(edge, graphVertexIn, graphVertexOppositeOut);
635635

636636
/* Track Edges already placed */
637637
connections.put(edge, new Tuple<>(vertex, oppositeVertex));
@@ -660,7 +660,7 @@ private SmartGraphVertexNode<V> createVertex(Vertex<V> v, double x, double y) {
660660
return new SmartGraphVertexNode<>(this, v, x, y, shapeRadius, shapeType, graphProperties.getVertexAllowUserMove());
661661
}
662662

663-
private SmartGraphEdgeBase<E,V> createEdge(Edge<E, V> edge, SmartGraphVertexNode<V> graphVertexInbound, SmartGraphVertexNode<V> graphVertexOutbound) {
663+
private SmartGraphEdgeNode<E,V> createEdge(Edge<E, V> edge, SmartGraphVertexNode<V> graphVertexInbound, SmartGraphVertexNode<V> graphVertexOutbound) {
664664
/*
665665
Edges will be placed with 'multiplicityIndex' starting at 0 for a single edge between a pair of vertices. This represents a straight edge.
666666
When more than an edge exists, the 'multiplicityIndex' will start at 1, forcing the edges to be curved.
@@ -695,16 +695,16 @@ private void addVertex(SmartGraphVertexNode<V> v) {
695695
}
696696
}
697697

698-
private void addEdge(SmartGraphEdgeBase<E,V> e, Edge<E, V> edge) {
698+
private void addEdge(SmartGraphEdgeNode<E,V> e, Edge<E, V> edge) {
699699
// Edges to the back
700-
this.getChildren().add(0, (Node) e);
700+
this.getChildren().add(0, e);
701701
edgeNodes.put(edge, e);
702702

703703
String labelText = getEdgeLabelFor(edge.element());
704704

705705
if (graphProperties.getUseEdgeTooltip()) {
706706
Tooltip t = new Tooltip(labelText);
707-
Tooltip.install((Node) e, t);
707+
Tooltip.install(e, t);
708708
}
709709

710710
if (graphProperties.getUseEdgeLabel()) {
@@ -804,7 +804,7 @@ The opposite vertex exists in the (di)graph, but we have not yet
804804
graphVertexOut.addAdjacentVertex(graphVertexIn);
805805
graphVertexIn.addAdjacentVertex(graphVertexOut);
806806

807-
SmartGraphEdgeBase<E,V> graphEdge = createEdge(edge, graphVertexIn, graphVertexOut);
807+
SmartGraphEdgeNode<E,V> graphEdge = createEdge(edge, graphVertexIn, graphVertexOut);
808808

809809
/* Track edges */
810810
connections.put(edge, new Tuple<>(u, v));
@@ -825,7 +825,7 @@ private void removeNodes() {
825825
//remove edges (graphical elements) that were removed from the underlying graph
826826
Collection<Edge<E, V>> removedEdges = removedEdges();
827827
for (Edge<E, V> e : removedEdges) {
828-
SmartGraphEdgeBase<E,V> edgeToRemove = edgeNodes.get(e);
828+
SmartGraphEdgeNode<E,V> edgeToRemove = edgeNodes.get(e);
829829
edgeNodes.remove(e);
830830
removeEdge(edgeToRemove); //remove from panel
831831

@@ -856,8 +856,8 @@ private void removeNodes() {
856856

857857
}
858858

859-
private void removeEdge(SmartGraphEdgeBase<E,V> e) {
860-
getChildren().remove((Node) e);
859+
private void removeEdge(SmartGraphEdgeNode<E,V> e) {
860+
getChildren().remove(e);
861861

862862
SmartArrow attachedArrow = e.getAttachedArrow();
863863
if (attachedArrow != null) {
@@ -878,13 +878,13 @@ private void removeEdge(SmartGraphEdgeBase<E,V> e) {
878878
*
879879
* This work
880880
*/
881-
private void updateParallelEdgesOf(SmartGraphEdgeBase<E,V> e) {
881+
private void updateParallelEdgesOf(SmartGraphEdgeNode<E,V> e) {
882882

883-
SmartGraphVertexNode<V> v = e.getInbound();
884-
SmartGraphVertexNode<V> w = e.getOutbound();
883+
SmartGraphVertexNode<V> v = (SmartGraphVertexNode<V>)e.getInbound();
884+
SmartGraphVertexNode<V> w = (SmartGraphVertexNode<V>)e.getOutbound();
885885

886886
// 'getEdgesBetween' returns a collection of ages, ordered by their "age".
887-
List<SmartGraphEdgeBase<E, V>> parallelEdges = getEdgesBetween(v, w);
887+
List<SmartGraphEdgeNode<E, V>> parallelEdges = getEdgesBetween(v, w);
888888

889889
int numEdges = parallelEdges.size();
890890
if(numEdges > 0) {
@@ -941,7 +941,7 @@ private void updateNodes() {
941941
});
942942

943943
theGraph.edges().forEach((e) -> {
944-
SmartGraphEdgeBase<E,V> edgeNode = edgeNodes.get(e);
944+
SmartGraphEdgeNode<E,V> edgeNode = edgeNodes.get(e);
945945
if (edgeNode != null) {
946946
SmartLabel label = edgeNode.getAttachedLabel();
947947
if (label != null) {
@@ -1048,7 +1048,7 @@ protected final double getVertexShapeRadiusFor(V vertexElement) {
10481048
return graphProperties.getVertexRadius();
10491049
}
10501050

1051-
/*protected final List<SmartGraphEdgeBase> getConnectedEdgesFor(SmartGraphVertexNode<V> node) {
1051+
/*protected final List<SmartGraphEdgeNode> getConnectedEdgesFor(SmartGraphVertexNode<V> node) {
10521052
if(node == null) throw new IllegalArgumentException("node cannot be null."); // defensive
10531053
10541054
Vertex<V> underlyingVertex = node.getUnderlyingVertex();
@@ -1063,7 +1063,7 @@ protected final double getVertexShapeRadiusFor(V vertexElement) {
10631063
}
10641064
10651065
// Get the corresponding smart edges
1066-
List<SmartGraphEdgeBase> connected = new ArrayList<>();
1066+
List<SmartGraphEdgeNode> connected = new ArrayList<>();
10671067
10681068
for (Edge<E, V> edge : edges) {
10691069
connected.add ( edgeNodes.get(edge) );
@@ -1135,11 +1135,11 @@ private int getTotalEdgesBetweenInModel(Vertex<V> v, Vertex<V> u) {
11351135
* @param u second vertex
11361136
* @return an ordered (by age) list of edges that exist between 'u' and 'v'
11371137
*/
1138-
private List<SmartGraphEdgeBase<E, V>> getEdgesBetween(SmartGraphVertexNode<V> v, SmartGraphVertexNode<V> u) {
1138+
private List<SmartGraphEdgeNode<E, V>> getEdgesBetween(SmartGraphVertexNode<V> v, SmartGraphVertexNode<V> u) {
11391139
Vertex<V> V = v.getUnderlyingVertex();
11401140
Vertex<V> U = u.getUnderlyingVertex();
11411141

1142-
List<SmartGraphEdgeBase<E, V>> parallelEdges = new ArrayList<>();
1142+
List<SmartGraphEdgeNode<E, V>> parallelEdges = new ArrayList<>();
11431143

11441144
for (Map.Entry<Edge<E, V>, Tuple<Vertex<V>>> edgeTupleEntry : this.connections.entrySet()) {
11451145
Edge<E, V> edge = edgeTupleEntry.getKey();
@@ -1162,9 +1162,9 @@ private List<SmartGraphEdgeBase<E, V>> getEdgesBetween(SmartGraphVertexNode<V> v
11621162
*/
11631163
private int getMaxMultiplicityIndexBetween(SmartGraphVertexNode<V> v, SmartGraphVertexNode<V> u) {
11641164
int max = -1;
1165-
for (SmartGraphEdgeBase<E, V> edge : edgeNodes.values()) {
1166-
SmartGraphVertexNode<V> in = edge.getInbound();
1167-
SmartGraphVertexNode<V> out = edge.getOutbound();
1165+
for (SmartGraphEdgeNode<E, V> edge : edgeNodes.values()) {
1166+
SmartGraphVertexNode<V> in = (SmartGraphVertexNode<V>)edge.getInbound();
1167+
SmartGraphVertexNode<V> out = (SmartGraphVertexNode<V>)edge.getOutbound();
11681168

11691169
if(in == v && out == u || in == u && out == v) {
11701170
int cur = edge.getMultiplicityIndex();
@@ -1233,9 +1233,9 @@ private Collection<Edge<E, V>> removedEdges() {
12331233
List<Edge<E, V>> removed = new LinkedList<>();
12341234

12351235
Collection<Edge<E, V>> graphEdges = theGraph.edges();
1236-
Collection<SmartGraphEdgeBase<E,V>> plotted = edgeNodes.values();
1236+
Collection<SmartGraphEdgeNode<E,V>> plotted = edgeNodes.values();
12371237

1238-
for (SmartGraphEdgeBase<E,V> e : plotted) {
1238+
for (SmartGraphEdgeNode<E,V> e : plotted) {
12391239
if (!graphEdges.contains(e.getUnderlyingEdge())) {
12401240
removed.add(e.getUnderlyingEdge());
12411241
}
@@ -1376,7 +1376,7 @@ public SmartStylableNode getStylableLabel(Vertex<V> v) {
13761376
* @return stylable element (label)
13771377
*/
13781378
public SmartStylableNode getStylableLabel(Edge<E,V> e) {
1379-
SmartGraphEdgeBase<E,V> edge = edgeNodes.get(e);
1379+
SmartGraphEdgeNode<E,V> edge = edgeNodes.get(e);
13801380

13811381
return edge != null ? edge.getStylableLabel() : null;
13821382
}

0 commit comments

Comments
 (0)