summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/gui/lifecycle/desc/ActivitySlotDefRenderer.java
blob: 56cb44d8917c6e7433ad5e0851f25ed5b7758258 (plain)
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
package com.c2kernel.gui.lifecycle.desc;

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.gui.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;


    @Override
	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 );
        }
    }
}