1 | package vishnu.testvis.visual;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import javax.swing.*;
|
---|
5 | import javax.swing.border.*;
|
---|
6 | import java.awt.event.*;
|
---|
7 |
|
---|
8 | public class RadVizPanel extends JPanel
|
---|
9 | {
|
---|
10 | protected CvManyPoints canvas1;
|
---|
11 | public java.awt.Label docLabel;
|
---|
12 | protected KeywordPanel keyWordPanel;
|
---|
13 | protected Panel south = new Panel();
|
---|
14 |
|
---|
15 | protected Border border1;
|
---|
16 |
|
---|
17 | protected JPanel buttonPanel = new JPanel();
|
---|
18 | protected JPanel buttonBasePanel = new JPanel();
|
---|
19 | protected JPanel labelPanel = new JPanel();
|
---|
20 | protected JLabel buttonLabel = new JLabel();
|
---|
21 | protected JButton zoomInButton = new JButton();
|
---|
22 | protected JButton zoomOutButton = new JButton();
|
---|
23 | protected JButton resetButton = new JButton();
|
---|
24 | protected JButton clusterButton = new JButton();
|
---|
25 |
|
---|
26 | protected JCheckBox showGridCheckBox = new JCheckBox();
|
---|
27 | protected JCheckBox lockCheckBox = new JCheckBox();
|
---|
28 | protected JCheckBox showRimCheckBox = new JCheckBox();
|
---|
29 | protected JCheckBox projectCheckBox = new JCheckBox();
|
---|
30 |
|
---|
31 | protected int smallFont = 14;
|
---|
32 | protected int largeFont = 16;
|
---|
33 | protected Border border3;
|
---|
34 | protected BorderLayout borderLayout1 = new BorderLayout(10,0);
|
---|
35 | protected Vishnu parent;
|
---|
36 |
|
---|
37 | public RadVizPanel(Vishnu p)
|
---|
38 | {
|
---|
39 | parent = p;
|
---|
40 | try
|
---|
41 | {
|
---|
42 | jbInit();
|
---|
43 | }
|
---|
44 | catch(Exception e)
|
---|
45 | {
|
---|
46 | e.printStackTrace();
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | private void jbInit() throws Exception
|
---|
52 | {
|
---|
53 | border1 = BorderFactory.createEmptyBorder(5,5,5,5);
|
---|
54 | border3 = BorderFactory.createEmptyBorder(10,10,10,10);
|
---|
55 | this.setLayout(borderLayout1);
|
---|
56 | this.setBorder(border3);
|
---|
57 | this.setPreferredSize(new Dimension(600, 400));
|
---|
58 | canvas1 = new CvManyPoints (parent);
|
---|
59 |
|
---|
60 | // This is used as a balloon by the canvas1
|
---|
61 | docLabel = new java.awt.Label(" ");
|
---|
62 | docLabel.setVisible(false);
|
---|
63 |
|
---|
64 | // place it out of view if does become visible
|
---|
65 | docLabel.setBounds(12,-20,10,10);
|
---|
66 | docLabel.setBackground(new Color(16776895));
|
---|
67 | docLabel.setFont(new Font("Dialog", Font.PLAIN, largeFont));
|
---|
68 |
|
---|
69 | add(docLabel);
|
---|
70 | add(canvas1, "Center");
|
---|
71 |
|
---|
72 | keyWordPanel = new KeywordPanel(canvas1, this);
|
---|
73 | keyWordPanel.setVisible(false);
|
---|
74 |
|
---|
75 | buttonBasePanel.setLayout(new BorderLayout(10,10));
|
---|
76 | buttonPanel.setLayout(new GridLayout(0,2,10,10));
|
---|
77 | buttonLabel.setText("Settings");
|
---|
78 | buttonLabel.setForeground(Color.black);
|
---|
79 | buttonLabel.setFont(new java.awt.Font("Monospaced", 0, largeFont));
|
---|
80 |
|
---|
81 | zoomInButton.setText("Zoom in");
|
---|
82 | zoomInButton.setFont(new java.awt.Font("Monospaced", 0, largeFont));
|
---|
83 | zoomInButton.setBorder(BorderFactory.createEtchedBorder());
|
---|
84 | zoomInButton.addMouseListener(new java.awt.event.MouseAdapter()
|
---|
85 | {
|
---|
86 | public void mouseClicked(MouseEvent e)
|
---|
87 | {
|
---|
88 | zoomInButton_mouseClicked(e);
|
---|
89 | }
|
---|
90 | });
|
---|
91 | zoomOutButton.setText("Zoom Out");
|
---|
92 | zoomOutButton.setFont(new java.awt.Font("Monospaced", 0,largeFont));
|
---|
93 | zoomOutButton.setBorder(BorderFactory.createEtchedBorder());
|
---|
94 | zoomOutButton.addMouseListener(new java.awt.event.MouseAdapter()
|
---|
95 | {
|
---|
96 | public void mouseClicked(MouseEvent e)
|
---|
97 | {
|
---|
98 | zoomOutButton_mouseClicked(e);
|
---|
99 | }
|
---|
100 | });
|
---|
101 | resetButton.setText("Reset");
|
---|
102 | resetButton.setFont(new java.awt.Font("Monospaced", 0, largeFont));
|
---|
103 | resetButton.setBorder(BorderFactory.createEtchedBorder());
|
---|
104 | resetButton.addMouseListener(new java.awt.event.MouseAdapter()
|
---|
105 | {
|
---|
106 | public void mouseClicked(MouseEvent e)
|
---|
107 | {
|
---|
108 | resetButton_mouseClicked(e);
|
---|
109 | }
|
---|
110 | });
|
---|
111 | clusterButton.setText("Cluster");
|
---|
112 | clusterButton.setFont(new java.awt.Font("Monospaced", 0, largeFont));
|
---|
113 | clusterButton.setBorder(BorderFactory.createEtchedBorder());
|
---|
114 | clusterButton.addMouseListener(new java.awt.event.MouseAdapter()
|
---|
115 | {
|
---|
116 | public void mouseClicked(MouseEvent e)
|
---|
117 | {
|
---|
118 | clusterButton_mouseClicked(e);
|
---|
119 | }
|
---|
120 | });
|
---|
121 |
|
---|
122 | showGridCheckBox.setText("Show Grid");
|
---|
123 | showGridCheckBox.setFont(new java.awt.Font("Monospaced", 0, largeFont));
|
---|
124 | showGridCheckBox.setSelected(false);
|
---|
125 | showGridCheckBox.setBorder(BorderFactory.createEtchedBorder());
|
---|
126 | showGridCheckBox.addItemListener(new java.awt.event.ItemListener()
|
---|
127 | {
|
---|
128 | public void itemStateChanged(ItemEvent e)
|
---|
129 | {
|
---|
130 | showGridCheckBox_itemStateChanged(e);
|
---|
131 | }
|
---|
132 | });
|
---|
133 | showRimCheckBox.setText("Show Rim");
|
---|
134 | showRimCheckBox.setFont(new java.awt.Font("Monospaced", 0, largeFont));
|
---|
135 | showRimCheckBox.setSelected(true);
|
---|
136 | showRimCheckBox.setBorder(BorderFactory.createEtchedBorder());
|
---|
137 | showRimCheckBox.addItemListener(new java.awt.event.ItemListener()
|
---|
138 | {
|
---|
139 | public void itemStateChanged(ItemEvent e)
|
---|
140 | {
|
---|
141 | showRimCheckBox_itemStateChanged(e);
|
---|
142 | }
|
---|
143 | });
|
---|
144 |
|
---|
145 | projectCheckBox.setText("Projection");
|
---|
146 | projectCheckBox.setFont(new java.awt.Font("Monospaced", 0, largeFont));
|
---|
147 | projectCheckBox.setSelected(true);
|
---|
148 | projectCheckBox.setBorder(BorderFactory.createEtchedBorder());
|
---|
149 | projectCheckBox.addItemListener(new java.awt.event.ItemListener()
|
---|
150 | {
|
---|
151 | public void itemStateChanged(ItemEvent e)
|
---|
152 | {
|
---|
153 | projectCheckBox_itemStateChanged(e);
|
---|
154 | }
|
---|
155 | });
|
---|
156 | lockCheckBox.setText("Lock Radius");
|
---|
157 | lockCheckBox.setFont(new java.awt.Font("Monospaced", 0, largeFont));
|
---|
158 | lockCheckBox.setSelected(false);
|
---|
159 | lockCheckBox.setBorder(BorderFactory.createEtchedBorder());
|
---|
160 | lockCheckBox.addItemListener(new java.awt.event.ItemListener()
|
---|
161 | {
|
---|
162 | public void itemStateChanged(ItemEvent e)
|
---|
163 | {
|
---|
164 | lockCheckBox_itemStateChanged(e);
|
---|
165 | }
|
---|
166 | });
|
---|
167 |
|
---|
168 |
|
---|
169 | buttonPanel.add(zoomInButton);
|
---|
170 | buttonPanel.add(zoomOutButton);
|
---|
171 | buttonPanel.add(resetButton);
|
---|
172 | buttonPanel.add(clusterButton);
|
---|
173 | buttonPanel.add(showGridCheckBox);
|
---|
174 | buttonPanel.add(showRimCheckBox);
|
---|
175 | buttonPanel.add(projectCheckBox);
|
---|
176 | buttonPanel.add(lockCheckBox);
|
---|
177 |
|
---|
178 | labelPanel.add(buttonLabel);
|
---|
179 | buttonBasePanel.add(buttonPanel,"Center");
|
---|
180 | buttonBasePanel.add(labelPanel,"North");
|
---|
181 | south.setLayout(new BorderLayout(10,0));
|
---|
182 | south.add(keyWordPanel,"West");
|
---|
183 | south.add(buttonBasePanel,"East");
|
---|
184 | south.setVisible(false);
|
---|
185 | add(south,"South");
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|
189 | public void setBothVisible(boolean f)
|
---|
190 | {
|
---|
191 | keyWordPanel.setVisible(f);
|
---|
192 | canvas1.setVisible(f);
|
---|
193 | south.setVisible(f);
|
---|
194 | }
|
---|
195 |
|
---|
196 |
|
---|
197 | public void addNotify()
|
---|
198 | {
|
---|
199 | //Record the size of the window prior to calling parents addNotify.
|
---|
200 | Dimension d = getSize();
|
---|
201 |
|
---|
202 | super.addNotify();
|
---|
203 |
|
---|
204 | if (fComponentsAdjusted)
|
---|
205 | return;
|
---|
206 |
|
---|
207 | // Adjust components according to the insets
|
---|
208 | setSize(getInsets().left + getInsets().right + d.width,
|
---|
209 | getInsets().top + getInsets().bottom + d.height);
|
---|
210 | Component components[] = getComponents();
|
---|
211 | for (int i = 0; i < components.length; i++)
|
---|
212 | {
|
---|
213 | Point p = components[i].getLocation();
|
---|
214 | p.translate(getInsets().left, getInsets().top);
|
---|
215 | components[i].setLocation(p);
|
---|
216 | }
|
---|
217 | fComponentsAdjusted = true;
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | void zoomOutButton_mouseClicked(MouseEvent e)
|
---|
222 | {
|
---|
223 | canvas1.higher();
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | void zoomInButton_mouseClicked(MouseEvent e)
|
---|
228 | {
|
---|
229 | canvas1.flatter();
|
---|
230 | }
|
---|
231 |
|
---|
232 |
|
---|
233 | void resetButton_mouseClicked(MouseEvent e)
|
---|
234 | {
|
---|
235 | canvas1.recalc();
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | void clusterButton_mouseClicked(MouseEvent e)
|
---|
240 | {
|
---|
241 | canvas1.cluster();
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | void showGridCheckBox_itemStateChanged(ItemEvent e)
|
---|
246 | {
|
---|
247 | canvas1.grid(showGridCheckBox.isSelected());
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | void showRimCheckBox_itemStateChanged(ItemEvent e)
|
---|
252 | {
|
---|
253 | canvas1.rim(showRimCheckBox.isSelected());
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | void projectCheckBox_itemStateChanged(ItemEvent e)
|
---|
258 | {
|
---|
259 | canvas1.projection(projectCheckBox.isSelected());
|
---|
260 | }
|
---|
261 |
|
---|
262 |
|
---|
263 | void lockCheckBox_itemStateChanged(ItemEvent e)
|
---|
264 | {
|
---|
265 | canvas1.lock(lockCheckBox.isSelected());
|
---|
266 | }
|
---|
267 |
|
---|
268 |
|
---|
269 | public void update()
|
---|
270 | {
|
---|
271 | canvas1.update();
|
---|
272 | keyWordPanel.update();
|
---|
273 | }
|
---|
274 |
|
---|
275 |
|
---|
276 | public void setVisible(boolean f)
|
---|
277 | {
|
---|
278 | super.setVisible(f);
|
---|
279 | setBothVisible(f);
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 | public void paint(Graphics g)
|
---|
284 | {
|
---|
285 | System.out.println("Updating RadVizPanel");
|
---|
286 | //canvas1.update();
|
---|
287 | keyWordPanel.update();
|
---|
288 | }
|
---|
289 |
|
---|
290 | protected boolean fComponentsAdjusted = false;
|
---|
291 | }
|
---|
292 |
|
---|
293 |
|
---|
294 |
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 |
|
---|
299 |
|
---|
300 |
|
---|