source: trunk/greenstone3-extensions/vishnu/src/vishnu/testvis/treemap/rectangle/ClusterRect.java@ 8189

Last change on this file since 8189 was 8189, checked in by kjdon, 20 years ago

first version of Imperial College's Visualiser code

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/**
2 * @(#)ClusterRect.java 12/12/99
3 * @author Peter Au
4 * All rights reserved.
5 */
6
7package vishnu.testvis.treemap.rectangle;
8
9import vishnu.testvis.object.ClusterObj;
10import java.awt.*;
11
12
13public class ClusterRect extends ZRect
14{
15 private ClusterObj _data;
16 public ClusterRect(float x1, float y1, float x2, float y2, Color c, ClusterObj o)
17 {
18 super(x1,y1,x2,y2,c,o.getDocsSize());
19 _data = o;
20 }
21
22 public void paint(Graphics oldg){
23 Graphics2D g = (Graphics2D) oldg;
24 g.setColor(getColor());
25 g.fill(getBounds2D());
26 g.setColor(Color.white);
27 g.draw(getBounds2D());
28 }
29
30 public ClusterObj getClusterObj(){return _data;}
31
32 public String getInfo(){return _data.getInfo();}
33
34
35 //------------------------------------------------------------------
36 private int _xRef=0, _yRef=0; // used in paintLabels and createTipBox
37
38 /**
39 * paint the cluster's labels on the graphical pane
40 * @param oldg is the graphics to be pained
41 * @param w is the max width of the graphic
42 * @param h is the max heigth of the graphic
43 */
44 public void paintLabels(Graphics oldg, float w, float h){
45 Color tipBoxColor = new Color(255,255,180);
46 Graphics2D g = (Graphics2D) oldg;
47 Font f = new Font("TimesRoman",Font.PLAIN,12);
48 FontMetrics fm = g.getFontMetrics(f);
49 int ascent = fm.getAscent();
50 int height = fm.getHeight();
51 int boxWidth = 4 + Math.max(fm.stringWidth(_data.getLabel1()),
52 fm.stringWidth(_data.getLabel2()) );
53 int boxHeight = 0 + height * 2;
54 Polygon poly;
55
56 g.setFont(f);
57
58 //-- setup the position of the tipbox
59 poly = createTipBox(boxWidth, boxHeight, w, h);
60
61 //-- paint the box
62 g.setColor(tipBoxColor);
63 g.fillPolygon(poly);
64 g.setColor(Color.black);
65 g.drawPolygon(poly);
66 //-- paint the text
67 g.drawString(_data.getLabel1(), _xRef+3F,
68 _yRef + (boxHeight-(height*2F))/2F + ascent);
69 g.drawString(_data.getLabel2(), _xRef+3F,
70 _yRef + (boxHeight-(height*2F))/2F + ascent + height);
71
72 }
73
74
75 private Polygon createTipBox(int boxW, int boxH, float maxW, float maxH){
76 int[] xs = new int[8];
77 int[] ys = new int[8];
78 int x=0, y=0,
79 arrowH=10,
80 arrowW=8,
81 arrowOffset=8,
82 gap=5; //-- gap is the space between the tipbox and the rectangle
83 float position=0.2F; //-- set the box position
84
85 try{
86
87 //-- try RHS
88 x = (int) getLowerRightX() + gap;
89 y = (int) (getUpperLeftY() + getHeight()*position);
90 if ((x+boxW<=maxW) && (y+boxH<=maxH)){
91 xs[0]=xs[6]=xs[4]=xs[3]=xs[7] = x;
92 xs[1]=xs[2] = x + boxW;
93 xs[5] = x - arrowH;
94 ys[5]=ys[0]=ys[1]=ys[7] = y;
95 ys[3]=ys[2] = y + boxH;
96 ys[6] = y + arrowOffset;
97 ys[4] = y + arrowOffset + arrowW;
98 throw new Exception();
99 }
100
101 //-- try LHS
102 x = (int) getUpperLeftX() - gap - boxW;
103 if ((x>=0) && (y+boxH<=maxH)){
104 xs[0]=xs[7]=xs[6] = x;
105 xs[1]=xs[2]=xs[4]=xs[5] = x + boxW;
106 xs[3] = x + boxW + arrowH;
107 ys[7]=ys[0]=ys[1]=ys[3] = y;
108 ys[6]=ys[5] = y + boxH;
109 ys[2] = y + arrowOffset;
110 ys[4] = y + arrowOffset + arrowW;
111 throw new Exception();
112 }
113
114 //-- try top
115 x = (int) (getUpperLeftX() + getWidth()*position);
116 y = (int) getUpperLeftY() - boxH - gap;
117 if ((y>=0) && (x+boxW<=maxW)){
118 xs[0]=xs[7]=xs[6]=xs[4] = x;
119 xs[1]=xs[2] = x + boxW;
120 xs[5] = x + arrowOffset;
121 xs[3] = x + arrowOffset + arrowW;
122 ys[7]=ys[0]=ys[1] = y;
123 ys[6]=ys[5]=ys[3]=ys[2] = y + boxH;
124 ys[4] = y + boxH + arrowH;
125 throw new Exception();
126 }
127
128 //-- try bottom
129 y = (int) getLowerRightY() + gap;
130 if ((y+boxH<=maxH) && (x+boxW<=maxW)){
131 xs[7]=xs[0]=xs[6]=xs[2] = x;
132 xs[4]=xs[5] = x + boxW;
133 xs[1] = x + arrowOffset;
134 xs[3] = x + arrowOffset + arrowW;
135 ys[7]=ys[0]=ys[1]=ys[3]=ys[4]= y;
136 ys[6]=ys[5] = y + boxH;
137 ys[2] = y - arrowH;
138 throw new Exception();
139 }
140
141 //-- try inside the rectangle
142 x = (int) getUpperLeftX() + 5;
143 y = (int) getUpperLeftY() + 5 + 5;
144 xs[7]=xs[0]=xs[6]=xs[2] = x;
145 xs[4]=xs[5] = x + boxW;
146 xs[1] = x + 3;
147 xs[3] = x + 3 + 5;
148 ys[7]= ys[0]=ys[1]=ys[3]=ys[4] = y;
149 ys[6]= ys[5] = y + boxH;
150 ys[2] = y - 5;
151
152 }
153 catch(Exception e){
154 }
155
156 _xRef = x;
157 _yRef = y;
158 return (new Polygon(xs,ys,xs.length));
159 }
160
161
162}
163
Note: See TracBrowser for help on using the repository browser.