Skip to content

Commit 6eb123f

Browse files
committed
Propagate hover effect on edges to arrows.
1 parent 3ec5e31 commit 6eb123f

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.brunomnsilva.smartgraph.graph.Edge;
2727
import javafx.beans.binding.Bindings;
2828
import javafx.geometry.Point2D;
29+
import javafx.scene.input.MouseButton;
30+
import javafx.scene.input.MouseEvent;
2931
import javafx.scene.shape.CubicCurve;
3032
import javafx.scene.transform.Rotate;
3133
import javafx.scene.transform.Translate;
@@ -112,6 +114,8 @@ public SmartGraphEdgeCurve(Edge<E, V> edge, SmartGraphVertexNode<V> inbound, Sma
112114

113115
//update();
114116
enableListeners();
117+
118+
propagateHoverEffectToArrow();
115119
}
116120

117121
public void setStyleInline(String css) {
@@ -277,4 +281,18 @@ public SmartStylableNode getStylableArrow() {
277281
public SmartStylableNode getStylableLabel() {
278282
return this.attachedLabel;
279283
}
284+
285+
private void propagateHoverEffectToArrow() {
286+
this.hoverProperty().addListener((observable, oldValue, newValue) -> {
287+
if(attachedArrow != null && newValue) {
288+
289+
attachedArrow.fireEvent(new MouseEvent(MouseEvent.MOUSE_ENTERED, 0, 0, 0, 0, MouseButton.NONE, 0, true, true, true, true, true, true, true, true, true, true, null));
290+
291+
} else if(attachedArrow != null) { //newValue is false, hover ended
292+
293+
attachedArrow.fireEvent(new MouseEvent(MouseEvent.MOUSE_EXITED, 0, 0, 0, 0, MouseButton.NONE, 0, true, true, true, true, true, true, true, true, true, true, null));
294+
295+
}
296+
});
297+
}
280298
}

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import com.brunomnsilva.smartgraph.graph.Edge;
2727
import javafx.beans.binding.Bindings;
28+
import javafx.scene.input.MouseButton;
29+
import javafx.scene.input.MouseEvent;
2830
import javafx.scene.shape.Line;
2931
import javafx.scene.transform.Rotate;
3032
import javafx.scene.transform.Translate;
@@ -76,6 +78,8 @@ public SmartGraphEdgeLine(Edge<E, V> edge, SmartGraphVertexNode<V> inbound, Smar
7678
this.startYProperty().bind(outbound.centerYProperty());
7779
this.endXProperty().bind(inbound.centerXProperty());
7880
this.endYProperty().bind(inbound.centerYProperty());
81+
82+
propagateHoverEffectToArrow();
7983
}
8084

8185
@Override
@@ -110,7 +114,6 @@ public boolean removeStyleClass(String cssClass) {
110114
}
111115
return result;
112116
}
113-
114117

115118
@Override
116119
public void attachLabel(SmartLabel label) {
@@ -129,8 +132,6 @@ public SmartLabel getAttachedLabel() {
129132
public Edge<E, V> getUnderlyingEdge() {
130133
return underlyingEdge;
131134
}
132-
133-
134135

135136
@Override
136137
public void attachArrow(SmartArrow arrow) {
@@ -172,5 +173,19 @@ public SmartStylableNode getStylableArrow() {
172173
public SmartStylableNode getStylableLabel() {
173174
return this.attachedLabel;
174175
}
175-
176+
177+
private void propagateHoverEffectToArrow() {
178+
this.hoverProperty().addListener((observable, oldValue, newValue) -> {
179+
if(attachedArrow != null && newValue) {
180+
181+
attachedArrow.fireEvent(new MouseEvent(MouseEvent.MOUSE_ENTERED, 0, 0, 0, 0, MouseButton.NONE, 0, true, true, true, true, true, true, true, true, true, true, null));
182+
183+
} else if(attachedArrow != null) { //newValue is false, hover ended
184+
185+
attachedArrow.fireEvent(new MouseEvent(MouseEvent.MOUSE_EXITED, 0, 0, 0, 0, MouseButton.NONE, 0, true, true, true, true, true, true, true, true, true, true, null));
186+
187+
}
188+
});
189+
}
190+
176191
}

0 commit comments

Comments
 (0)