diff options
Diffstat (limited to 'source/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java')
| -rwxr-xr-x | source/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/source/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java b/source/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java new file mode 100755 index 0000000..a67b4fd --- /dev/null +++ b/source/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java @@ -0,0 +1,116 @@ +package com.c2kernel.lifecycle.instance.gui.view;
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Polygon;
+
+import com.c2kernel.common.GTimeStamp;
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.graph.view.VertexRenderer;
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lifecycle.instance.stateMachine.States;
+import com.c2kernel.utils.DateUtility;
+import com.c2kernel.utils.Language;
+public class ActivityRenderer implements VertexRenderer
+{
+ private Paint mActivePaint = new Color(100, 255, 100);
+ private Paint mActiveCompPaint = new Color(100, 255, 255);
+ private Paint mInactivePaint = new Color(255, 255, 255);
+ private Paint mInactiveCompPaint = new Color(200, 200, 255);
+ private Paint mErrorPaint = new Color(255, 50, 0);
+ private Paint mTextPaint = Color.black;
+ public void draw(Graphics2D g2d, Vertex vertex)
+ {
+ Activity activity = (Activity) vertex;
+ boolean active = activity.getActive();
+ boolean hasError = !activity.verify();
+ boolean isComposite = activity.getIsComposite();
+ GraphPoint centrePoint = activity.getCentrePoint();
+ String description = activity.getDescription();
+ String[] linesOfText = new String[3];
+ linesOfText[0] = "(" + activity.getType() + ")";
+ linesOfText[1] = activity.getName();
+ if (hasError)
+ linesOfText[2] = Language.translate(activity.getErrors());
+ else
+ {
+ int cs = activity.getCurrentState();
+ if (cs == States.WAITING && activity.getActive())
+ linesOfText[2] =
+ Language.translate(States.getStateName(cs))
+ + (((Boolean) activity.getProperties().get("Show time")).booleanValue()
+ ? " " + getWaitTime(activity.getActiveDate())
+ : "");
+ else if (cs == States.STARTED)
+ linesOfText[2] =
+ Language.translate(States.getStateName(cs))
+ + (((Boolean) activity.getProperties().get("Show time")).booleanValue()
+ ? " " + getWaitTime(activity.getStartDate())
+ : "");
+ else
+ linesOfText[2] = Language.translate(States.getStateName(cs));
+ }
+
+ FontMetrics metrics = g2d.getFontMetrics();
+ int lineWidth = 0;
+ int lineHeight = metrics.getHeight();
+ int linesHeight = lineHeight * linesOfText.length;
+ int linesStartY = centrePoint.y - linesHeight / 2 + lineHeight * 2 / 3;
+ int x = 0;
+ int y = 0;
+ int i = 0;
+ GraphPoint[] outline = vertex.getOutlinePoints();
+ Paint actColour;
+ if (hasError)
+ actColour = mErrorPaint;
+ else if (active)
+ if (isComposite)
+ actColour = mActiveCompPaint;
+ else
+ actColour = mActivePaint;
+ else if (isComposite)
+ actColour = mInactiveCompPaint;
+ else
+ actColour = mInactivePaint;
+ g2d.setPaint(actColour);
+ //g2d.fill3DRect( centrePoint.x - mSize.width / 2, centrePoint.y - mSize.height / 2, mSize.width, mSize.height, true );
+ g2d.fill(graphPointsToPolygon(outline));
+ g2d.setPaint(mTextPaint);
+ for (i = 0; i < linesOfText.length; i++)
+ {
+ lineWidth = metrics.stringWidth(linesOfText[i]);
+ x = centrePoint.x - lineWidth / 2;
+ y = linesStartY + i * lineHeight;
+ g2d.drawString(linesOfText[i], x, y);
+ }
+ }
+ private Polygon graphPointsToPolygon(GraphPoint[] points)
+ {
+ Polygon polygon = new Polygon();
+ int i = 0;
+ for (i = 0; i < points.length; i++)
+ {
+ polygon.addPoint(points[i].x, points[i].y);
+ }
+ return polygon;
+ }
+ private String getWaitTime(GTimeStamp date)
+ {
+ GTimeStamp now = new GTimeStamp();
+ DateUtility.setToNow(now);
+ long diff = DateUtility.diff(now, date);
+ long secondes = diff % 60;
+ long minutes = (diff / 60) % 60;
+ long hours = (diff / 3600) % 24;
+ long days = (diff / 3600 / 24);
+ if (days > 0)
+ return days + " " + Language.translate("d") + " " + hours + " " + Language.translate("h");
+ if (hours > 0)
+ return hours + " " + Language.translate("h") + " " + minutes + " " + Language.translate("min");
+ if (minutes > 0)
+ return minutes + " " + Language.translate("min");
+ return secondes + " " + Language.translate("sec");
+ }
+}
|
