1
|
package eu.dnetlib.functionality.modular.ui.workflows.sarasvati.icons;
|
2
|
|
3
|
import java.awt.BasicStroke;
|
4
|
import java.awt.Color;
|
5
|
import java.awt.Graphics2D;
|
6
|
|
7
|
import com.googlecode.sarasvati.Node;
|
8
|
import com.googlecode.sarasvati.NodeToken;
|
9
|
import com.googlecode.sarasvati.visual.common.NodeDrawConfig;
|
10
|
import com.googlecode.sarasvati.visual.util.FontUtil;
|
11
|
|
12
|
import eu.dnetlib.msro.workflows.util.ProgressProvider;
|
13
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
14
|
|
15
|
public class ProcessJobIcon extends AbstractIcon {
|
16
|
/**
|
17
|
* node token.
|
18
|
*/
|
19
|
private NodeToken token;
|
20
|
|
21
|
/**
|
22
|
* Progress Bar color.
|
23
|
*/
|
24
|
private Color progressBarColor = Color.decode("#205fbc");
|
25
|
|
26
|
/**
|
27
|
* Inaccurate Progress Bar color.
|
28
|
*/
|
29
|
private Color inaccurateProgressBarColor = Color.DARK_GRAY;
|
30
|
|
31
|
/**
|
32
|
* Progress Bar background color.
|
33
|
*/
|
34
|
private Color progressBarBGColor = Color.LIGHT_GRAY;
|
35
|
|
36
|
/**
|
37
|
* A progress provider to display
|
38
|
*/
|
39
|
private ProgressProvider progressProvider;
|
40
|
|
41
|
/**
|
42
|
* constructs a blackboard node icon for a given runtime node.
|
43
|
*
|
44
|
* @param node
|
45
|
* node
|
46
|
* @param token
|
47
|
* node token
|
48
|
*/
|
49
|
public ProcessJobIcon(final Node node, final NodeToken token, final ProgressProvider progressProvider) {
|
50
|
super(node);
|
51
|
|
52
|
this.token = token;
|
53
|
this.progressProvider = progressProvider;
|
54
|
|
55
|
setColor(NodeDrawConfig.getColor(token));
|
56
|
|
57
|
if (token != null && token.getEnv() != null && "true".equals(token.getEnv().getAttribute(WorkflowsConstants.SYSTEM_HAS_FAILED))) {
|
58
|
setFailed(true);
|
59
|
setColor(Color.RED);
|
60
|
}
|
61
|
|
62
|
if (isJoin()) {
|
63
|
setDashes(new float[] { DASH_FULL, DASH_EMPTY });
|
64
|
}
|
65
|
|
66
|
setTerminal(node.getGraph().getOutputArcs(node).size() == 0);
|
67
|
|
68
|
redrawImage();
|
69
|
}
|
70
|
|
71
|
|
72
|
@Override
|
73
|
public void redrawImage(final Graphics2D gfx) {
|
74
|
super.resetGfx(gfx);
|
75
|
|
76
|
gfx.fillRoundRect(0, 0, WIDTH - 1, HEIGHT - 1, ROUND_CORNER, ROUND_CORNER);
|
77
|
|
78
|
gfx.setColor(NodeDrawConfig.NODE_BORDER);
|
79
|
final BasicStroke stroke = new BasicStroke(2, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10, getDashes(), 0);
|
80
|
gfx.setStroke(stroke);
|
81
|
gfx.drawRoundRect(0, 0, WIDTH - 1, HEIGHT - 1, ROUND_CORNER, ROUND_CORNER);
|
82
|
|
83
|
gfx.setColor(Color.white);
|
84
|
final int padding = 6;
|
85
|
final int startX = padding;
|
86
|
final int maxWidth = getIconWidth() - (padding << 1);
|
87
|
FontUtil.setSizedFont(gfx, getLabel(), FONT_SIZE, maxWidth);
|
88
|
final int strWidth = (int) Math.ceil(gfx.getFontMetrics().getStringBounds(getLabel(), gfx).getWidth());
|
89
|
final int strHeight = gfx.getFontMetrics().getAscent();
|
90
|
final int left = startX + ((maxWidth - strWidth) >> 1);
|
91
|
final int top = ((getIconHeight() + strHeight) >> 1);
|
92
|
gfx.drawString(getLabel(), left, top);
|
93
|
|
94
|
if (progressProvider != null && !token.isComplete()) {
|
95
|
drawProgressBar(gfx);
|
96
|
}
|
97
|
|
98
|
super.resetGfx(gfx);
|
99
|
}
|
100
|
|
101
|
private void drawProgressBar(Graphics2D gfx) {
|
102
|
int total = progressProvider.getTotalValue();
|
103
|
int current = progressProvider.getCurrentValue();
|
104
|
|
105
|
if (current > total) {
|
106
|
return;
|
107
|
}
|
108
|
|
109
|
int x = 6;
|
110
|
int y = getIconHeight() - 6;
|
111
|
|
112
|
int widthTot = getIconWidth() - x - x;
|
113
|
|
114
|
int height = 2;
|
115
|
gfx.setColor(progressBarBGColor);
|
116
|
gfx.fillRect(x, y, widthTot, height);
|
117
|
|
118
|
if (progressProvider.isInaccurate()) {
|
119
|
|
120
|
gfx.setColor(inaccurateProgressBarColor);
|
121
|
for (int i = (int) Math.round(Math.random() * 10); i < widthTot - 10; i += 20) {
|
122
|
gfx.fillRect(x + i, y, 10, height);
|
123
|
}
|
124
|
} else {
|
125
|
gfx.setColor(progressBarColor);
|
126
|
int widthCurr = 0;
|
127
|
if (total > 0) {
|
128
|
widthCurr = Math.round((widthTot * current) / total);
|
129
|
}
|
130
|
gfx.fillRect(x, y, widthCurr, height);
|
131
|
}
|
132
|
}
|
133
|
|
134
|
public NodeToken getToken() {
|
135
|
return token;
|
136
|
}
|
137
|
|
138
|
public void setToken(final NodeToken token) {
|
139
|
this.token = token;
|
140
|
}
|
141
|
|
142
|
public Color getProgressBarColor() {
|
143
|
return progressBarColor;
|
144
|
}
|
145
|
|
146
|
public void setProgressBarColor(Color progressBarColor) {
|
147
|
this.progressBarColor = progressBarColor;
|
148
|
}
|
149
|
|
150
|
public Color getProgressBarBGColor() {
|
151
|
return progressBarBGColor;
|
152
|
}
|
153
|
|
154
|
public void setProgressBarBGColor(Color progressBarBGColor) {
|
155
|
this.progressBarBGColor = progressBarBGColor;
|
156
|
}
|
157
|
|
158
|
public Color getInaccurateProgressBarColor() {
|
159
|
return inaccurateProgressBarColor;
|
160
|
}
|
161
|
|
162
|
public void setInaccurateProgressBarColor(Color inaccurateProgressBarColor) {
|
163
|
this.inaccurateProgressBarColor = inaccurateProgressBarColor;
|
164
|
}
|
165
|
|
166
|
public ProgressProvider getProgressProvider() {
|
167
|
return progressProvider;
|
168
|
}
|
169
|
|
170
|
public void setProgressProvider(ProgressProvider progressProvider) {
|
171
|
this.progressProvider = progressProvider;
|
172
|
}
|
173
|
}
|