From 254ee6f47eebfc00462c10756a92066e82cc1a96 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jun 2011 15:46:02 +0200 Subject: Initial commit --- .../gui/view/ActivitySlotDefRenderer.java | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 source/com/c2kernel/lifecycle/gui/view/ActivitySlotDefRenderer.java (limited to 'source/com/c2kernel/lifecycle/gui/view/ActivitySlotDefRenderer.java') diff --git a/source/com/c2kernel/lifecycle/gui/view/ActivitySlotDefRenderer.java b/source/com/c2kernel/lifecycle/gui/view/ActivitySlotDefRenderer.java new file mode 100755 index 0000000..5746673 --- /dev/null +++ b/source/com/c2kernel/lifecycle/gui/view/ActivitySlotDefRenderer.java @@ -0,0 +1,70 @@ +package com.c2kernel.lifecycle.gui.view; + +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.Paint; + +import com.c2kernel.graph.model.GraphPoint; +import com.c2kernel.graph.model.Vertex; +import com.c2kernel.graph.view.VertexRenderer; +import com.c2kernel.lifecycle.ActivitySlotDef; +import com.c2kernel.utils.Language; + +public class ActivitySlotDefRenderer implements VertexRenderer +{ + private Paint mInactivePaint = new Color(255, 255, 255); + private Paint mErrorPaint = new Color( 255, 50, 0 ); + private Paint mCompositePaint= new Color(200, 200, 255); + private Paint mTextPaint = Color.black; + + + public void draw( Graphics2D g2d, Vertex vertex) + { + ActivitySlotDef activitySlotDef = ( ActivitySlotDef )vertex; + boolean hasError = activitySlotDef.verify(); + boolean isComposite = false; + isComposite = activitySlotDef.getIsComposite(); + GraphPoint centrePoint = activitySlotDef.getCentrePoint(); + int vertexHeight = activitySlotDef.getHeight(); + int vertexWidth = activitySlotDef.getWidth(); + + String[] linesOfText = new String[2+(hasError?0:1)]; + 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; + + linesOfText[0]="("+activitySlotDef.getActivityDef()+")"; + linesOfText[1]=(String)activitySlotDef.getProperties().get("Name"); + + if (!hasError)linesOfText[2]=Language.translate(activitySlotDef.getErrors()); + + g2d.setPaint( !hasError ? mErrorPaint : isComposite ? mCompositePaint : mInactivePaint ); + g2d.fill3DRect + ( + centrePoint.x - vertexWidth / 2, + centrePoint.y - vertexHeight / 2, + vertexWidth, + vertexHeight, + true + ); + + g2d.setPaint( mTextPaint ); + + // Draw the lines of text + for ( i = 0; i < linesOfText.length; i++ ) + { + if (linesOfText[i] == null) linesOfText[i] = ""; + lineWidth = metrics.stringWidth( linesOfText[ i ] ); + x = centrePoint.x - lineWidth / 2; + y = linesStartY + i * lineHeight; + g2d.drawString( linesOfText[ i ], x, y ); + } + } +} + -- cgit v1.2.3