Normand Briere
2018-07-21 c1af17fab4c8cd519f54f572851fc93e7ee8f84a
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package timeflow.vis;
 
import timeflow.model.*;
 
import java.awt.*;
import java.util.ArrayList;
 
public class Mouseover extends Rectangle
{
        public Object thing;
 
        public Mouseover(Object thing, int x, int y, int w, int h)
        {
                super(x, y, w, h);
                this.thing = thing;
        }
 
        public void draw(Graphics2D g, int maxW, int maxH, Display display)
        {
                g.setColor(new Color(0, 53, 153));
                g.setColor(new Color(255, 255, 0, 100));
                g.fill(this);
        }
 
        protected void draw(Graphics2D g, int maxW, int maxH, Display display, ArrayList labels, int numLines)
        {
                if (labels == null || labels.size() == 0)
                {
                        return;
                }
 
                // draw a background box.
 
                // find max number of chars, very very roughly!
                int boxW = 50;
                for (int i = 0; i < labels.size(); i += 2)
                {
                        if (labels.get(i) instanceof String[])
                        {
                                boxW = 300;
                        } else if (labels.get(i) instanceof String)
                        {
                                boxW = Math.max(boxW, 50 + 50 * ((String) labels.get(i)).length());
                        }
                }
 
 
                //boxW = Math.min(350, boxW);
                int boxH = 18 * numLines; // + 10;
                int mx = this.x + this.width; // + 5;
                int my = this.y + this.height; // + 35;
 
                // put box in a place where it does not obscure the data
                // or go off screen.
                if (my + boxH > maxH) // - 10)
                {
//                        my = Math.max(10, this.y - boxH - 5);
                }
                if (mx + boxW > maxW) // - 10)
                {
//                        mx = Math.max(10, this.x - boxW - 10);
                }
                
                int ty = my;
                g.setColor(new Color(0, 0, 0, 70));
                g.fillRoundRect(mx - 11, my - 16, boxW, boxH, 12, 12);
                g.setColor(Color.white);
                g.fillRoundRect(mx - 15, my - 20, boxW, boxH, 12, 12);
                g.setColor(Color.darkGray);
                g.drawRoundRect(mx - 15, my - 20, boxW, boxH, 12, 12);
 
                // finally, draw the darn labels.
                for (int i = 0; i < labels.size(); i += 2)
                {
                        g.setFont(display.bold());
                        String field = (String) labels.get(i);
                        g.drawString(field, mx, ty);
                        int sw = display.boldFontMetrics().stringWidth(field);
                        g.setFont(display.plain());
                        Object o = labels.get(i + 1);
                        if (o instanceof String)
                        {
                                g.drawString((String) o, mx + sw + 9, ty);
                                ty += 18;
                        } else
                        {
                                ArrayList<String> lines = (ArrayList<String>) o;
                                int dx = sw + 9;
                                for (String line : lines)
                                {
                                        g.drawString((String) line, mx + dx, ty);
                                        ty += 18;
                                        dx = 0;
                                }
                                ty += 5;
                        }
                }
        }
}