1
|
package eu.dnetlib.functionality.modular.ui.workflows.sarasvati.icons;
|
2
|
|
3
|
import java.awt.Color;
|
4
|
import java.awt.Font;
|
5
|
import java.awt.Graphics2D;
|
6
|
import java.awt.RenderingHints;
|
7
|
|
8
|
import com.googlecode.sarasvati.JoinType;
|
9
|
import com.googlecode.sarasvati.Node;
|
10
|
import com.googlecode.sarasvati.visual.icon.AbstractNodeIcon;
|
11
|
|
12
|
public abstract class AbstractIcon extends AbstractNodeIcon {
|
13
|
|
14
|
/**
|
15
|
* corner radius.
|
16
|
*/
|
17
|
protected static final int ROUND_CORNER = 10;
|
18
|
|
19
|
/**
|
20
|
* length of the space between dashes.
|
21
|
*/
|
22
|
protected static final int DASH_EMPTY = 4;
|
23
|
|
24
|
/**
|
25
|
* length of the dash.
|
26
|
*/
|
27
|
protected static final int DASH_FULL = 8;
|
28
|
|
29
|
/**
|
30
|
* font size.
|
31
|
*/
|
32
|
protected static final int FONT_SIZE = 10;
|
33
|
|
34
|
/**
|
35
|
* node.
|
36
|
*/
|
37
|
private Node node;
|
38
|
|
39
|
/**
|
40
|
* is join.
|
41
|
*
|
42
|
*/
|
43
|
private boolean join;
|
44
|
|
45
|
/**
|
46
|
* node label.
|
47
|
*/
|
48
|
private String label;
|
49
|
|
50
|
/**
|
51
|
* node color.
|
52
|
*/
|
53
|
private Color color;
|
54
|
|
55
|
/**
|
56
|
* dashes.
|
57
|
*/
|
58
|
private float[] dashes;
|
59
|
|
60
|
/**
|
61
|
* true if terminal node.
|
62
|
*/
|
63
|
private boolean terminal;
|
64
|
|
65
|
private boolean failed;
|
66
|
|
67
|
/**
|
68
|
* constructs a blackboard node icon for a given runtime node.
|
69
|
*
|
70
|
* @param node
|
71
|
* node
|
72
|
* @param token
|
73
|
* node token
|
74
|
*/
|
75
|
public AbstractIcon(final Node node) {
|
76
|
super();
|
77
|
|
78
|
this.node = node;
|
79
|
|
80
|
this.label = node.getAdaptor(String.class);
|
81
|
if (label == null)
|
82
|
label = node.getName();
|
83
|
|
84
|
this.join = node.getJoinType() == null ? false : node.getJoinType() != JoinType.OR;
|
85
|
this.color = Color.lightGray;
|
86
|
|
87
|
if (join)
|
88
|
dashes = new float[] { DASH_FULL, DASH_EMPTY };
|
89
|
|
90
|
this.terminal = node.getGraph().getOutputArcs(node).size() == 0;
|
91
|
}
|
92
|
|
93
|
|
94
|
public void resetGfx(final Graphics2D gfx) {
|
95
|
gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
96
|
gfx.setFont(Font.getFont(Font.MONOSPACED));
|
97
|
|
98
|
if (isTerminal()) {
|
99
|
gfx.setFont(gfx.getFont().deriveFont(Font.BOLD));
|
100
|
}
|
101
|
|
102
|
gfx.setColor(color);
|
103
|
}
|
104
|
|
105
|
public boolean isJoin() {
|
106
|
return join;
|
107
|
}
|
108
|
|
109
|
public void setJoin(final boolean join) {
|
110
|
this.join = join;
|
111
|
}
|
112
|
|
113
|
public String getLabel() {
|
114
|
return label;
|
115
|
}
|
116
|
|
117
|
public void setLabel(final String label) {
|
118
|
this.label = label;
|
119
|
}
|
120
|
|
121
|
public Color getColor() {
|
122
|
return color;
|
123
|
}
|
124
|
|
125
|
public void setColor(final Color color) {
|
126
|
this.color = color;
|
127
|
}
|
128
|
|
129
|
public float[] getDashes() {
|
130
|
return dashes; // NOPMD
|
131
|
}
|
132
|
|
133
|
public void setDashes(final float[] dashes) { // NOPMD
|
134
|
this.dashes = dashes;
|
135
|
}
|
136
|
|
137
|
public Node getNode() {
|
138
|
return node;
|
139
|
}
|
140
|
|
141
|
public void setNode(final Node node) {
|
142
|
this.node = node;
|
143
|
}
|
144
|
|
145
|
public boolean isTerminal() {
|
146
|
return terminal;
|
147
|
}
|
148
|
|
149
|
public void setTerminal(final boolean terminal) {
|
150
|
this.terminal = terminal;
|
151
|
}
|
152
|
|
153
|
public boolean isFailed() {
|
154
|
return failed;
|
155
|
}
|
156
|
|
157
|
public void setFailed(boolean failed) {
|
158
|
this.failed = failed;
|
159
|
}
|
160
|
|
161
|
}
|