forked from qupath/qupath-extension-training
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCssHighlight.java
More file actions
73 lines (59 loc) · 1.69 KB
/
CssHighlight.java
File metadata and controls
73 lines (59 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package qupath.fx.controls.tour;
import javafx.scene.Node;
import javafx.stage.Window;
import qupath.fx.utils.FXUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Highlight nodes using CSS.
*/
class CssHighlight implements TourHighlight {
private static final String HIGHLIGHT_CLASS = "tour-highlight-node";
private static final String stylesheet = CssHighlight.class.getClassLoader().getResource("css/tour.css").toExternalForm();
private final List<Node> currentNodes = new ArrayList<>();
/**
* Create a new highlighter.
*/
public CssHighlight() {}
/**
* Show the highlight window.
*/
@Override
public void show() {
for (var node : currentNodes) {
if (!node.getStyleClass().contains(HIGHLIGHT_CLASS)) {
ensureStylesheet(FXUtils.getWindow(node));
node.getStyleClass().add(HIGHLIGHT_CLASS);
}
}
}
/**
* Hide the highlight window.
*/
@Override
public void hide() {
for (var node : currentNodes) {
node.getStyleClass().remove(HIGHLIGHT_CLASS);
}
}
private boolean ensureStylesheet(Window owner) {
if (owner == null)
return false;
if (!owner.getScene().getStylesheets().contains(stylesheet)) {
owner.getScene().getStylesheets().add(stylesheet);
}
return true;
}
@Override
public void highlightNodes(List<? extends Node> nodes) {
if (currentNodes.equals(nodes))
return;
hide();
currentNodes.clear();
if (nodes.isEmpty()) {
return;
}
currentNodes.addAll(nodes);
show();
}
}