.. | .. |
---|
5 | 5 | import java.awt.*; |
---|
6 | 6 | import java.util.ArrayList; |
---|
7 | 7 | |
---|
8 | | -public class Mouseover extends Rectangle { |
---|
9 | | - public Object thing; |
---|
10 | | - public Mouseover(Object thing, int x, int y, int w, int h) |
---|
11 | | - { |
---|
12 | | - super(x,y,w,h); |
---|
13 | | - this.thing=thing; |
---|
14 | | - } |
---|
15 | | - |
---|
16 | | - public void draw(Graphics2D g, int maxW, int maxH, Display display) |
---|
17 | | - { |
---|
18 | | - g.setColor(new Color(0,53,153)); |
---|
19 | | - g.setColor(new Color(255,255,0,100)); |
---|
20 | | - g.fill(this); |
---|
21 | | - } |
---|
22 | | - |
---|
23 | | - protected void draw(Graphics2D g, int maxW, int maxH, Display display, ArrayList labels, int numLines) |
---|
24 | | - { |
---|
25 | | - if (labels==null || labels.size()==0) |
---|
26 | | - return; |
---|
27 | | - |
---|
28 | | - // draw a background box. |
---|
29 | | - |
---|
30 | | - // find max number of chars, very very roughly! |
---|
31 | | - int boxW=50; |
---|
32 | | - for (int i=0; i<labels.size(); i+=2) |
---|
33 | | - { |
---|
34 | | - if (labels.get(i) instanceof String[]) |
---|
35 | | - boxW=300; |
---|
36 | | - else if (labels.get(i) instanceof String) |
---|
37 | | - { |
---|
38 | | - boxW=Math.max(boxW, 50+50*((String)labels.get(i)).length()); |
---|
39 | | - } |
---|
40 | | - } |
---|
41 | | - |
---|
42 | | - |
---|
43 | | - boxW=Math.min(350, boxW); |
---|
44 | | - int boxH=18*numLines+10; |
---|
45 | | - int mx=this.x+this.width+5; |
---|
46 | | - int my=this.y+this.height+35; |
---|
47 | | - |
---|
48 | | - // put box in a place where it does not obscure the data |
---|
49 | | - // or go off screen. |
---|
50 | | - if (my+boxH>maxH-10) |
---|
51 | | - { |
---|
52 | | - my=Math.max(10,this.y-boxH-5); |
---|
53 | | - } |
---|
54 | | - if (mx+boxW>maxW-10) |
---|
55 | | - { |
---|
56 | | - mx=Math.max(10,this.x-boxW-10); |
---|
57 | | - } |
---|
58 | | - int ty=my; |
---|
59 | | - g.setColor(new Color(0,0,0,70)); |
---|
60 | | - g.fillRoundRect(mx-11, my-16, boxW, boxH,12,12); |
---|
61 | | - g.setColor(Color.white); |
---|
62 | | - g.fillRoundRect(mx-15, my-20, boxW, boxH,12,12); |
---|
63 | | - g.setColor(Color.darkGray); |
---|
64 | | - g.drawRoundRect(mx-15, my-20, boxW, boxH,12,12); |
---|
65 | | - |
---|
66 | | - // finally, draw the darn labels. |
---|
67 | | - for (int i=0; i<labels.size(); i+=2) |
---|
68 | | - { |
---|
69 | | - g.setFont(display.bold()); |
---|
70 | | - String field=(String)labels.get(i); |
---|
71 | | - g.drawString(field,mx,ty); |
---|
72 | | - int sw=display.boldFontMetrics().stringWidth(field); |
---|
73 | | - g.setFont(display.plain()); |
---|
74 | | - Object o=labels.get(i+1); |
---|
75 | | - if (o instanceof String) |
---|
76 | | - { |
---|
77 | | - g.drawString((String)o,mx+sw+9,ty); |
---|
78 | | - ty+=18; |
---|
79 | | - } |
---|
80 | | - else |
---|
81 | | - { |
---|
82 | | - ArrayList<String> lines=(ArrayList<String>)o; |
---|
83 | | - int dx=sw+9; |
---|
84 | | - for (String line: lines) |
---|
85 | | - { |
---|
86 | | - g.drawString((String)line,mx+dx,ty); |
---|
87 | | - ty+=18; |
---|
88 | | - dx=0; |
---|
89 | | - } |
---|
90 | | - ty+=5; |
---|
91 | | - } |
---|
92 | | - } |
---|
93 | | - } |
---|
| 8 | +public class Mouseover extends Rectangle |
---|
| 9 | +{ |
---|
| 10 | + public Object thing; |
---|
| 11 | + |
---|
| 12 | + public Mouseover(Object thing, int x, int y, int w, int h) |
---|
| 13 | + { |
---|
| 14 | + super(x, y, w, h); |
---|
| 15 | + this.thing = thing; |
---|
| 16 | + } |
---|
| 17 | + |
---|
| 18 | + public void draw(Graphics2D g, int maxW, int maxH, Display display) |
---|
| 19 | + { |
---|
| 20 | + g.setColor(new Color(0, 53, 153)); |
---|
| 21 | + g.setColor(new Color(255, 255, 0, 100)); |
---|
| 22 | + g.fill(this); |
---|
| 23 | + } |
---|
| 24 | + |
---|
| 25 | + protected void draw(Graphics2D g, int maxW, int maxH, Display display, ArrayList labels, int numLines) |
---|
| 26 | + { |
---|
| 27 | + if (labels == null || labels.size() == 0) |
---|
| 28 | + { |
---|
| 29 | + return; |
---|
| 30 | + } |
---|
| 31 | + |
---|
| 32 | + // draw a background box. |
---|
| 33 | + |
---|
| 34 | + // find max number of chars, very very roughly! |
---|
| 35 | + int boxW = 50; |
---|
| 36 | + for (int i = 0; i < labels.size(); i += 2) |
---|
| 37 | + { |
---|
| 38 | + if (labels.get(i) instanceof String[]) |
---|
| 39 | + { |
---|
| 40 | + boxW = 300; |
---|
| 41 | + } else if (labels.get(i) instanceof String) |
---|
| 42 | + { |
---|
| 43 | + boxW = Math.max(boxW, 50 + 50 * ((String) labels.get(i)).length()); |
---|
| 44 | + } |
---|
| 45 | + } |
---|
| 46 | + |
---|
| 47 | + |
---|
| 48 | + //boxW = Math.min(350, boxW); |
---|
| 49 | + int boxH = 18 * numLines; // + 10; |
---|
| 50 | + int mx = this.x + this.width; // + 5; |
---|
| 51 | + int my = this.y + this.height; // + 35; |
---|
| 52 | + |
---|
| 53 | + // put box in a place where it does not obscure the data |
---|
| 54 | + // or go off screen. |
---|
| 55 | + if (my + boxH > maxH) // - 10) |
---|
| 56 | + { |
---|
| 57 | +// my = Math.max(10, this.y - boxH - 5); |
---|
| 58 | + } |
---|
| 59 | + if (mx + boxW > maxW) // - 10) |
---|
| 60 | + { |
---|
| 61 | +// mx = Math.max(10, this.x - boxW - 10); |
---|
| 62 | + } |
---|
| 63 | + |
---|
| 64 | + int ty = my; |
---|
| 65 | + g.setColor(new Color(0, 0, 0, 70)); |
---|
| 66 | + g.fillRoundRect(mx - 11, my - 16, boxW, boxH, 12, 12); |
---|
| 67 | + g.setColor(Color.white); |
---|
| 68 | + g.fillRoundRect(mx - 15, my - 20, boxW, boxH, 12, 12); |
---|
| 69 | + g.setColor(Color.darkGray); |
---|
| 70 | + g.drawRoundRect(mx - 15, my - 20, boxW, boxH, 12, 12); |
---|
| 71 | + |
---|
| 72 | + // finally, draw the darn labels. |
---|
| 73 | + for (int i = 0; i < labels.size(); i += 2) |
---|
| 74 | + { |
---|
| 75 | + g.setFont(display.bold()); |
---|
| 76 | + String field = (String) labels.get(i); |
---|
| 77 | + g.drawString(field, mx, ty); |
---|
| 78 | + int sw = display.boldFontMetrics().stringWidth(field); |
---|
| 79 | + g.setFont(display.plain()); |
---|
| 80 | + Object o = labels.get(i + 1); |
---|
| 81 | + if (o instanceof String) |
---|
| 82 | + { |
---|
| 83 | + g.drawString((String) o, mx + sw + 9, ty); |
---|
| 84 | + ty += 18; |
---|
| 85 | + } else |
---|
| 86 | + { |
---|
| 87 | + ArrayList<String> lines = (ArrayList<String>) o; |
---|
| 88 | + int dx = sw + 9; |
---|
| 89 | + for (String line : lines) |
---|
| 90 | + { |
---|
| 91 | + g.drawString((String) line, mx + dx, ty); |
---|
| 92 | + ty += 18; |
---|
| 93 | + dx = 0; |
---|
| 94 | + } |
---|
| 95 | + ty += 5; |
---|
| 96 | + } |
---|
| 97 | + } |
---|
| 98 | + } |
---|
94 | 99 | } |
---|