1 | /* |
---|
2 | * $Id: JClassTree.java,v 1.17 2003/08/22 23:02:39 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt.swing; |
---|
14 | |
---|
15 | import javax.swing.*; |
---|
16 | import javax.swing.tree.*; |
---|
17 | import java.awt.*; |
---|
18 | import java.awt.event.MouseListener; |
---|
19 | import java.awt.event.MouseAdapter; |
---|
20 | import java.awt.event.MouseEvent; |
---|
21 | import java.awt.event.InputEvent; |
---|
22 | import java.util.Enumeration; |
---|
23 | import java.util.List; |
---|
24 | |
---|
25 | import gov.noaa.pmel.util.Debug; |
---|
26 | |
---|
27 | import gov.noaa.pmel.sgt.JPane; |
---|
28 | import gov.noaa.pmel.sgt.Layer; |
---|
29 | import gov.noaa.pmel.sgt.LayerChild; |
---|
30 | import gov.noaa.pmel.sgt.SGLabel; |
---|
31 | import gov.noaa.pmel.sgt.Graph; |
---|
32 | import gov.noaa.pmel.sgt.CartesianGraph; |
---|
33 | import gov.noaa.pmel.sgt.CartesianRenderer; |
---|
34 | import gov.noaa.pmel.sgt.PointCartesianRenderer; |
---|
35 | import gov.noaa.pmel.sgt.LineCartesianRenderer; |
---|
36 | import gov.noaa.pmel.sgt.GridCartesianRenderer; |
---|
37 | import gov.noaa.pmel.sgt.VectorCartesianRenderer; |
---|
38 | import gov.noaa.pmel.sgt.Axis; |
---|
39 | import gov.noaa.pmel.sgt.SpaceAxis; |
---|
40 | import gov.noaa.pmel.sgt.PlainAxis; |
---|
41 | import gov.noaa.pmel.sgt.TimeAxis; |
---|
42 | import gov.noaa.pmel.sgt.Transform; |
---|
43 | import gov.noaa.pmel.sgt.PointAttribute; |
---|
44 | import gov.noaa.pmel.sgt.LineAttribute; |
---|
45 | import gov.noaa.pmel.sgt.GridAttribute; |
---|
46 | import gov.noaa.pmel.sgt.VectorAttribute; |
---|
47 | import gov.noaa.pmel.sgt.Logo; |
---|
48 | |
---|
49 | import gov.noaa.pmel.sgt.beans.Panel; |
---|
50 | import gov.noaa.pmel.sgt.beans.DataGroupLayer; |
---|
51 | |
---|
52 | import gov.noaa.pmel.sgt.swing.prop.LineAttributeDialog; |
---|
53 | import gov.noaa.pmel.sgt.swing.prop.GridAttributeDialog; |
---|
54 | import gov.noaa.pmel.sgt.swing.prop.SGLabelDialog; |
---|
55 | import gov.noaa.pmel.sgt.swing.prop.TimeAxisDialog; |
---|
56 | import gov.noaa.pmel.sgt.swing.prop.SpaceAxisDialog; |
---|
57 | import gov.noaa.pmel.sgt.swing.prop.PointAttributeDialog; |
---|
58 | import gov.noaa.pmel.sgt.swing.prop.LogoDialog; |
---|
59 | import gov.noaa.pmel.sgt.swing.prop.VectorAttributeDialog; |
---|
60 | |
---|
61 | /** |
---|
62 | * <code>JClassTree</code> displays the <code>sgt</code> object tree |
---|
63 | * in a <code>JDialog</code> using a <code>JTree</code>. Many |
---|
64 | * <code>sgt</code> classes can be selected from the |
---|
65 | * <code>JTree</code> to edit their properties. They include: |
---|
66 | * {@link gov.noaa.pmel.sgt.SGLabel SGLabel}, |
---|
67 | * {@link gov.noaa.pmel.sgt.LineAttribute LineAttribute}, |
---|
68 | * {@link gov.noaa.pmel.sgt.GridAttribute GridAttribute}, |
---|
69 | * {@link gov.noaa.pmel.sgt.CartesianGraph CartesianGraph}, |
---|
70 | * {@link gov.noaa.pmel.sgt.TimeAxis TimeAxis}, |
---|
71 | * {@link gov.noaa.pmel.sgt.SpaceAxis SpaceAxis}, |
---|
72 | * {@link gov.noaa.pmel.sgt.PointAttribute PointAttribute}, and |
---|
73 | * {@link gov.noaa.pmel.sgt.Logo Logo}. |
---|
74 | * |
---|
75 | * @author Donald Denbo |
---|
76 | * @version $Revision: 1.17 $, $Date: 2003/08/22 23:02:39 $ |
---|
77 | * @since 2.0 |
---|
78 | * @see SGLabelDialog |
---|
79 | * @see LineAttributeDialog |
---|
80 | * @see GridAttributeDialog |
---|
81 | * @see TimeAxisDialog |
---|
82 | * @see SpaceAxisDialog |
---|
83 | * @see PointAttributeDialog |
---|
84 | * @see LogoDialog |
---|
85 | */ |
---|
86 | public class JClassTree extends javax.swing.JDialog { |
---|
87 | private JPane pane_; |
---|
88 | |
---|
89 | private static SGLabelDialog sg_; |
---|
90 | private static LineAttributeDialog la_; |
---|
91 | private static GridAttributeDialog ga_; |
---|
92 | private static VectorAttributeDialog va_; |
---|
93 | private static TimeAxisDialog ta_; |
---|
94 | private static SpaceAxisDialog pa_; |
---|
95 | private static PointAttributeDialog pta_; |
---|
96 | private static LogoDialog lg_; |
---|
97 | /** |
---|
98 | * Default constructor. |
---|
99 | */ |
---|
100 | public JClassTree() { |
---|
101 | getContentPane().setLayout(new BorderLayout(0,0)); |
---|
102 | setVisible(false); |
---|
103 | setSize(405,362); |
---|
104 | jScrollPane1 = new javax.swing.JScrollPane(); |
---|
105 | jScrollPane1.setOpaque(true); |
---|
106 | getContentPane().add(BorderLayout.CENTER, jScrollPane1); |
---|
107 | treeView_ = new javax.swing.JTree(); |
---|
108 | treeView_.setBounds(0,0,402,324); |
---|
109 | treeView_.setFont(new Font("Dialog", Font.PLAIN, 12)); |
---|
110 | treeView_.setBackground(java.awt.Color.white); |
---|
111 | jScrollPane1.getViewport().add(treeView_); |
---|
112 | treeControlsPanel = new javax.swing.JPanel(); |
---|
113 | treeControlsPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,5)); |
---|
114 | treeControlsPanel.setFont(new Font("Dialog", Font.PLAIN, 12)); |
---|
115 | treeControlsPanel.setForeground(java.awt.Color.black); |
---|
116 | treeControlsPanel.setBackground(new java.awt.Color(204,204,204)); |
---|
117 | getContentPane().add(BorderLayout.SOUTH, treeControlsPanel); |
---|
118 | expandButton = new javax.swing.JButton(); |
---|
119 | expandButton.setText("Expand All"); |
---|
120 | expandButton.setActionCommand("Expand All"); |
---|
121 | expandButton.setFont(new Font("Dialog", Font.BOLD, 12)); |
---|
122 | expandButton.setBackground(new java.awt.Color(204,204,204)); |
---|
123 | treeControlsPanel.add(expandButton); |
---|
124 | collapseButton = new javax.swing.JButton(); |
---|
125 | collapseButton.setText("Collapse All"); |
---|
126 | collapseButton.setActionCommand("Collapse All"); |
---|
127 | collapseButton.setFont(new Font("Dialog", Font.BOLD, 12)); |
---|
128 | collapseButton.setBackground(new java.awt.Color(204,204,204)); |
---|
129 | treeControlsPanel.add(collapseButton); |
---|
130 | editButton = new javax.swing.JButton(); |
---|
131 | editButton.setText("Edit Selected"); |
---|
132 | editButton.setActionCommand("Edit Selected"); |
---|
133 | editButton.setFont(new Font("Dialog", Font.BOLD, 12)); |
---|
134 | editButton.setBackground(new java.awt.Color(204,204,204)); |
---|
135 | treeControlsPanel.add(editButton); |
---|
136 | cancelButton = new javax.swing.JButton(); |
---|
137 | cancelButton.setText("Close"); |
---|
138 | cancelButton.setActionCommand("Close"); |
---|
139 | cancelButton.setFont(new Font("Dialog", Font.BOLD, 12)); |
---|
140 | cancelButton.setBackground(new java.awt.Color(204,204,204)); |
---|
141 | treeControlsPanel.add(cancelButton); |
---|
142 | setTitle("Class View"); |
---|
143 | |
---|
144 | SymWindow aSymWindow = new SymWindow(); |
---|
145 | this.addWindowListener(aSymWindow); |
---|
146 | SymAction lSymAction = new SymAction(); |
---|
147 | expandButton.addActionListener(lSymAction); |
---|
148 | collapseButton.addActionListener(lSymAction); |
---|
149 | editButton.addActionListener(lSymAction); |
---|
150 | cancelButton.addActionListener(lSymAction); |
---|
151 | |
---|
152 | MouseListener ml = new MouseAdapter() { |
---|
153 | public void mouseClicked(MouseEvent e) { |
---|
154 | int selRow = treeView_.getRowForLocation(e.getX(), |
---|
155 | e.getY()); |
---|
156 | TreePath selPath = treeView_.getPathForLocation(e.getX(), |
---|
157 | e.getY()); |
---|
158 | if(selRow != -1) { |
---|
159 | if((e.getClickCount() == 2) || |
---|
160 | ((e.getModifiers()&InputEvent.BUTTON3_MASK) != 0)) { |
---|
161 | doubleClick(selRow, selPath); |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | }; |
---|
166 | treeView_.addMouseListener(ml); |
---|
167 | // |
---|
168 | |
---|
169 | if(System.getProperty("mrj.version") == null || |
---|
170 | !UIManager.getSystemLookAndFeelClassName().equals(UIManager.getLookAndFeel().getClass().getName())) { |
---|
171 | Insets inset = new Insets(0,5,0,5); |
---|
172 | expandButton.setMargin(inset); |
---|
173 | collapseButton.setMargin(inset); |
---|
174 | editButton.setMargin(inset); |
---|
175 | cancelButton.setMargin(inset); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | void doubleClick(int selRow, TreePath selPath) { |
---|
180 | if(Debug.DEBUG) System.out.println("row " + selRow + " selected"); |
---|
181 | Object[] objs = selPath.getPath(); |
---|
182 | Object thing = ((DefaultMutableTreeNode)objs[objs.length-1]).getUserObject(); |
---|
183 | showProperties(thing); |
---|
184 | } |
---|
185 | |
---|
186 | public JClassTree(String sTitle) { |
---|
187 | this(); |
---|
188 | setTitle(sTitle); |
---|
189 | } |
---|
190 | /** |
---|
191 | * Make the dialog visible. |
---|
192 | */ |
---|
193 | public void setVisible(boolean b) { |
---|
194 | if (b) |
---|
195 | setLocation(50, 50); |
---|
196 | super.setVisible(b); |
---|
197 | } |
---|
198 | |
---|
199 | static public void main(String[] args) { |
---|
200 | (new JClassTree()).setVisible(true); |
---|
201 | } |
---|
202 | |
---|
203 | public void addNotify() { |
---|
204 | // Record the size of the window prior to calling parents addNotify. |
---|
205 | Dimension d = getSize(); |
---|
206 | Insets in = getInsets(); |
---|
207 | |
---|
208 | super.addNotify(); |
---|
209 | |
---|
210 | if (fComponentsAdjusted) |
---|
211 | return; |
---|
212 | // Adjust components according to the insets |
---|
213 | setSize(in.left + in.right + d.width, in.top + in.bottom + d.height); |
---|
214 | Component components[] = getContentPane().getComponents(); |
---|
215 | for (int i = 0; i < components.length; i++) |
---|
216 | { |
---|
217 | Point p = components[i].getLocation(); |
---|
218 | p.translate(in.left, in.top); |
---|
219 | components[i].setLocation(p); |
---|
220 | } |
---|
221 | fComponentsAdjusted = true; |
---|
222 | } |
---|
223 | |
---|
224 | // Used for addNotify check. |
---|
225 | private boolean fComponentsAdjusted = false; |
---|
226 | |
---|
227 | javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane(); |
---|
228 | javax.swing.JTree treeView_ = new javax.swing.JTree(); |
---|
229 | javax.swing.JPanel treeControlsPanel = new javax.swing.JPanel(); |
---|
230 | javax.swing.JButton expandButton = new javax.swing.JButton(); |
---|
231 | javax.swing.JButton collapseButton = new javax.swing.JButton(); |
---|
232 | javax.swing.JButton editButton = new javax.swing.JButton(); |
---|
233 | javax.swing.JButton cancelButton = new javax.swing.JButton(); |
---|
234 | |
---|
235 | class SymWindow extends java.awt.event.WindowAdapter { |
---|
236 | public void windowClosing(java.awt.event.WindowEvent event) { |
---|
237 | Object object = event.getSource(); |
---|
238 | if (object == JClassTree.this) |
---|
239 | JClassTree_WindowClosing(event); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | void JClassTree_WindowClosing(java.awt.event.WindowEvent event) { |
---|
244 | setVisible(false); // hide the Frame |
---|
245 | // dispose(); // free the system resources |
---|
246 | // System.exit(0); // close the application |
---|
247 | } |
---|
248 | |
---|
249 | class SymAction implements java.awt.event.ActionListener { |
---|
250 | public void actionPerformed(java.awt.event.ActionEvent event) { |
---|
251 | Object object = event.getSource(); |
---|
252 | if (object == expandButton) |
---|
253 | expandButton_actionPerformed(event); |
---|
254 | else if (object == collapseButton) |
---|
255 | collapseButton_actionPerformed(event); |
---|
256 | else if (object == editButton) |
---|
257 | editButton_actionPerformed(event); |
---|
258 | else if (object == cancelButton) |
---|
259 | cancelButton_actionPerformed(event); |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | void expandButton_actionPerformed(java.awt.event.ActionEvent event) { |
---|
264 | expandTree(); |
---|
265 | } |
---|
266 | /** |
---|
267 | * Expand the tree to show all nodes. |
---|
268 | */ |
---|
269 | public void expandTree() { |
---|
270 | int row=0; |
---|
271 | while(row < treeView_.getRowCount()) { |
---|
272 | if(treeView_.isCollapsed(row)) { |
---|
273 | treeView_.expandRow(row); |
---|
274 | } |
---|
275 | row++; |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | void collapseButton_actionPerformed(java.awt.event.ActionEvent event) { |
---|
280 | treeView_.collapseRow(0); |
---|
281 | } |
---|
282 | |
---|
283 | void editButton_actionPerformed(java.awt.event.ActionEvent event) { |
---|
284 | Object[] objs = treeView_.getSelectionPath().getPath(); |
---|
285 | showProperties(((DefaultMutableTreeNode)objs[objs.length-1]).getUserObject()); |
---|
286 | } |
---|
287 | |
---|
288 | void cancelButton_actionPerformed(java.awt.event.ActionEvent event) { |
---|
289 | setVisible(false); |
---|
290 | } |
---|
291 | /** |
---|
292 | * Set the <code>JPane</code> for which the <code>JTree</code> is to |
---|
293 | * be built. |
---|
294 | */ |
---|
295 | public void setJPane(JPane pane) { |
---|
296 | Layer ly; |
---|
297 | // |
---|
298 | DefaultTreeModel treeModel; |
---|
299 | DefaultMutableTreeNode paneNode; |
---|
300 | DefaultMutableTreeNode panelNode; |
---|
301 | DefaultMutableTreeNode layerNode; |
---|
302 | DefaultMutableTreeNode dataGroupNode; |
---|
303 | |
---|
304 | pane_ = pane; |
---|
305 | paneNode = new DefaultMutableTreeNode(pane_); |
---|
306 | treeModel = new DefaultTreeModel(paneNode); |
---|
307 | treeView_.setModel(treeModel); |
---|
308 | // |
---|
309 | Component[] comps = pane_.getComponents(); |
---|
310 | for(int il=0; il < comps.length; il++) { |
---|
311 | if(comps[il] instanceof DataGroupLayer) { |
---|
312 | ly = (Layer)comps[il]; |
---|
313 | dataGroupNode = new DefaultMutableTreeNode(ly); |
---|
314 | treeModel.insertNodeInto(dataGroupNode, |
---|
315 | paneNode, |
---|
316 | treeModel.getChildCount(paneNode)); |
---|
317 | List lyList = ((DataGroupLayer)ly).getLayerList(); |
---|
318 | for(int i=1; i < lyList.size(); i++) { |
---|
319 | ly = (Layer)lyList.get(i); |
---|
320 | layerNode = new DefaultMutableTreeNode(ly); |
---|
321 | treeModel.insertNodeInto(layerNode, |
---|
322 | dataGroupNode, |
---|
323 | treeModel.getChildCount(dataGroupNode)); |
---|
324 | expandLayer(ly, dataGroupNode, treeModel); |
---|
325 | } |
---|
326 | } else if(comps[il] instanceof Layer) { |
---|
327 | ly = (Layer)comps[il]; |
---|
328 | layerNode = new DefaultMutableTreeNode(ly); |
---|
329 | treeModel.insertNodeInto(layerNode, |
---|
330 | paneNode, |
---|
331 | treeModel.getChildCount(paneNode)); |
---|
332 | expandLayer(ly, layerNode, treeModel); |
---|
333 | } else if(comps[il] instanceof Panel) { |
---|
334 | panelNode = new DefaultMutableTreeNode(comps[il]); |
---|
335 | treeModel.insertNodeInto(panelNode, |
---|
336 | paneNode, |
---|
337 | treeModel.getChildCount(paneNode)); |
---|
338 | Component[] pcomps = ((Panel)comps[il]).getComponents(); |
---|
339 | for(int pl=0; pl < pcomps.length; pl++) { |
---|
340 | if(pcomps[pl] instanceof DataGroupLayer) { |
---|
341 | ly = (Layer)pcomps[pl]; |
---|
342 | dataGroupNode = new DefaultMutableTreeNode(ly); |
---|
343 | treeModel.insertNodeInto(dataGroupNode, |
---|
344 | paneNode, |
---|
345 | treeModel.getChildCount(paneNode)); |
---|
346 | expandLayer(ly, dataGroupNode, treeModel); |
---|
347 | List lyList = ((DataGroupLayer)ly).getLayerList(); |
---|
348 | for(int i=1; i < lyList.size(); i++) { |
---|
349 | ly = (Layer)lyList.get(i); |
---|
350 | layerNode = new DefaultMutableTreeNode(ly); |
---|
351 | treeModel.insertNodeInto(layerNode, |
---|
352 | dataGroupNode, |
---|
353 | treeModel.getChildCount(dataGroupNode)); |
---|
354 | expandLayer(ly, layerNode, treeModel); |
---|
355 | } |
---|
356 | } else if(pcomps[pl] instanceof Layer) { |
---|
357 | ly = (Layer)pcomps[pl]; |
---|
358 | layerNode = new DefaultMutableTreeNode(ly); |
---|
359 | treeModel.insertNodeInto(layerNode, |
---|
360 | panelNode, |
---|
361 | treeModel.getChildCount(panelNode)); |
---|
362 | expandLayer(ly, layerNode, treeModel); |
---|
363 | } |
---|
364 | } |
---|
365 | } else { |
---|
366 | continue; |
---|
367 | } |
---|
368 | |
---|
369 | int row=0; |
---|
370 | while(row < treeView_.getRowCount()) { |
---|
371 | if(treeView_.isCollapsed(row)) { |
---|
372 | treeView_.expandRow(row); |
---|
373 | } |
---|
374 | row++; |
---|
375 | } |
---|
376 | } |
---|
377 | } |
---|
378 | |
---|
379 | private void expandLayer(Layer ly, |
---|
380 | DefaultMutableTreeNode layerNode, |
---|
381 | DefaultTreeModel treeModel) { |
---|
382 | LayerChild child; |
---|
383 | Graph graph; |
---|
384 | Axis axis; |
---|
385 | CartesianRenderer rend; |
---|
386 | LineAttribute attr; |
---|
387 | GridAttribute gattr; |
---|
388 | PointAttribute pattr; |
---|
389 | VectorAttribute vattr; |
---|
390 | // |
---|
391 | DefaultMutableTreeNode node; |
---|
392 | DefaultMutableTreeNode paneNode; |
---|
393 | DefaultMutableTreeNode childNode; |
---|
394 | DefaultMutableTreeNode graphNode; |
---|
395 | DefaultMutableTreeNode attrNode; |
---|
396 | DefaultMutableTreeNode gattrNode; |
---|
397 | DefaultMutableTreeNode pattrNode; |
---|
398 | DefaultMutableTreeNode axisNode; |
---|
399 | DefaultMutableTreeNode titleNode; |
---|
400 | |
---|
401 | String name, className; |
---|
402 | for(Enumeration childs = ly.childElements(); childs.hasMoreElements();) { |
---|
403 | child = (LayerChild)childs.nextElement(); |
---|
404 | className = child.getClass().getName(); |
---|
405 | name = className.substring(className.lastIndexOf(".")+1); |
---|
406 | childNode = new DefaultMutableTreeNode(child); |
---|
407 | treeModel.insertNodeInto(childNode, |
---|
408 | layerNode, |
---|
409 | treeModel.getChildCount(layerNode)); |
---|
410 | } |
---|
411 | graph = ly.getGraph(); |
---|
412 | if(graph == null) return; |
---|
413 | className = graph.getClass().getName(); |
---|
414 | name = className.substring(className.lastIndexOf(".")+1); |
---|
415 | if(graph instanceof CartesianGraph) { |
---|
416 | graphNode = new DefaultMutableTreeNode(graph); |
---|
417 | treeModel.insertNodeInto(graphNode, |
---|
418 | layerNode, |
---|
419 | treeModel.getChildCount(layerNode)); |
---|
420 | rend = ((CartesianGraph)graph).getRenderer(); |
---|
421 | if(rend instanceof LineCartesianRenderer) { |
---|
422 | attr = (LineAttribute)((LineCartesianRenderer)rend).getAttribute(); |
---|
423 | if(attr != null) { |
---|
424 | className = attr.getClass().getName(); |
---|
425 | name = className.substring(className.lastIndexOf(".")+1); |
---|
426 | attrNode = new DefaultMutableTreeNode(attr); |
---|
427 | treeModel.insertNodeInto(attrNode, |
---|
428 | graphNode, |
---|
429 | treeModel.getChildCount(graphNode)); |
---|
430 | } |
---|
431 | } else if(rend instanceof VectorCartesianRenderer) { |
---|
432 | vattr = (VectorAttribute)((VectorCartesianRenderer)rend).getAttribute(); |
---|
433 | if(vattr != null) { |
---|
434 | className = vattr.getClass().getName(); |
---|
435 | name = className.substring(className.lastIndexOf(".")+1); |
---|
436 | attrNode = new DefaultMutableTreeNode(vattr); |
---|
437 | treeModel.insertNodeInto(attrNode, |
---|
438 | graphNode, |
---|
439 | treeModel.getChildCount(graphNode)); |
---|
440 | } |
---|
441 | } else if(rend instanceof GridCartesianRenderer) { |
---|
442 | gattr = (GridAttribute)((GridCartesianRenderer)rend).getAttribute(); |
---|
443 | if(gattr != null) { |
---|
444 | className = gattr.getClass().getName(); |
---|
445 | name = className.substring(className.lastIndexOf(".")+1); |
---|
446 | gattrNode = new DefaultMutableTreeNode(gattr); |
---|
447 | treeModel.insertNodeInto(gattrNode, |
---|
448 | graphNode, |
---|
449 | treeModel.getChildCount(graphNode)); |
---|
450 | } |
---|
451 | } else if(rend instanceof PointCartesianRenderer) { |
---|
452 | pattr = (PointAttribute)((PointCartesianRenderer)rend).getAttribute(); |
---|
453 | if(pattr != null) { |
---|
454 | className = pattr.getClass().getName(); |
---|
455 | name = className.substring(className.lastIndexOf(".")+1); |
---|
456 | pattrNode = new DefaultMutableTreeNode(pattr); |
---|
457 | treeModel.insertNodeInto(pattrNode, |
---|
458 | graphNode, |
---|
459 | treeModel.getChildCount(graphNode)); |
---|
460 | } |
---|
461 | } |
---|
462 | for(Enumeration axes = ((CartesianGraph)graph).xAxisElements(); |
---|
463 | axes.hasMoreElements();) { |
---|
464 | axis = (Axis)axes.nextElement(); |
---|
465 | className = axis.getClass().getName(); |
---|
466 | name = className.substring(className.lastIndexOf(".")+1); |
---|
467 | if(axis instanceof SpaceAxis) { |
---|
468 | axisNode = new DefaultMutableTreeNode(axis); |
---|
469 | treeModel.insertNodeInto(axisNode, |
---|
470 | graphNode, |
---|
471 | treeModel.getChildCount(graphNode)); |
---|
472 | SGLabel title = axis.getTitle(); |
---|
473 | if(title != null) { |
---|
474 | titleNode = new DefaultMutableTreeNode(title); |
---|
475 | treeModel.insertNodeInto(titleNode, |
---|
476 | axisNode, |
---|
477 | treeModel.getChildCount(axisNode)); |
---|
478 | } |
---|
479 | } else { // not a SpaceAxis |
---|
480 | axisNode = new DefaultMutableTreeNode(axis); |
---|
481 | treeModel.insertNodeInto(axisNode, |
---|
482 | graphNode, |
---|
483 | treeModel.getChildCount(graphNode)); |
---|
484 | } |
---|
485 | } |
---|
486 | for(Enumeration axes = ((CartesianGraph)graph).yAxisElements(); |
---|
487 | axes.hasMoreElements();) { |
---|
488 | axis = (Axis)axes.nextElement(); |
---|
489 | className = axis.getClass().getName(); |
---|
490 | name = className.substring(className.lastIndexOf(".")+1); |
---|
491 | if(axis instanceof SpaceAxis) { |
---|
492 | axisNode = new DefaultMutableTreeNode(axis); |
---|
493 | treeModel.insertNodeInto(axisNode, |
---|
494 | graphNode, |
---|
495 | treeModel.getChildCount(graphNode)); |
---|
496 | SGLabel title = axis.getTitle(); |
---|
497 | if(title != null) { |
---|
498 | titleNode = new DefaultMutableTreeNode(title); |
---|
499 | treeModel.insertNodeInto(titleNode, |
---|
500 | axisNode, |
---|
501 | treeModel.getChildCount(axisNode)); |
---|
502 | } |
---|
503 | } else { // not a SpaceAxis |
---|
504 | axisNode = new DefaultMutableTreeNode(axis); |
---|
505 | treeModel.insertNodeInto(axisNode, |
---|
506 | graphNode, |
---|
507 | treeModel.getChildCount(graphNode)); |
---|
508 | } |
---|
509 | } |
---|
510 | } else { // not a CartesianGraph |
---|
511 | graphNode = new DefaultMutableTreeNode(graph); |
---|
512 | treeModel.insertNodeInto(graphNode, |
---|
513 | layerNode, |
---|
514 | treeModel.getChildCount(layerNode)); |
---|
515 | } |
---|
516 | } |
---|
517 | |
---|
518 | void showProperties(Object obj) { |
---|
519 | if(obj instanceof SGLabel) { |
---|
520 | if(sg_ == (SGLabelDialog) null) { |
---|
521 | // |
---|
522 | // create the SGLabel dialog |
---|
523 | // |
---|
524 | sg_ = new SGLabelDialog(); |
---|
525 | } |
---|
526 | sg_.setSGLabel((SGLabel) obj, pane_); |
---|
527 | if(!sg_.isShowing()) |
---|
528 | sg_.setVisible(true); |
---|
529 | } else if(obj instanceof Logo) { |
---|
530 | if(lg_ == null) { |
---|
531 | // |
---|
532 | // create logo dialog |
---|
533 | // |
---|
534 | lg_ = new LogoDialog(); |
---|
535 | } |
---|
536 | lg_.setLogo((Logo) obj, pane_); |
---|
537 | if(!lg_.isShowing()) |
---|
538 | lg_.setVisible(true); |
---|
539 | } else if(obj instanceof PlainAxis) { |
---|
540 | if(pa_ == (SpaceAxisDialog) null) { |
---|
541 | // |
---|
542 | // create the PlainAxis dialog |
---|
543 | // |
---|
544 | pa_ = new SpaceAxisDialog(); |
---|
545 | } |
---|
546 | pa_.setSpaceAxis((PlainAxis) obj, pane_); |
---|
547 | if(!pa_.isShowing()) |
---|
548 | pa_.show(); |
---|
549 | } else if(obj instanceof TimeAxis) { |
---|
550 | if(ta_ == (TimeAxisDialog) null) { |
---|
551 | // |
---|
552 | // create the TimeAxis dialog |
---|
553 | // |
---|
554 | ta_ = new TimeAxisDialog(); |
---|
555 | } |
---|
556 | ta_.setTimeAxis((TimeAxis) obj, pane_); |
---|
557 | if(!ta_.isShowing()) |
---|
558 | ta_.show(); |
---|
559 | } else if(obj instanceof LineAttribute) { |
---|
560 | if(la_ == (LineAttributeDialog) null) { |
---|
561 | // |
---|
562 | // create the LineAttr dialog |
---|
563 | // |
---|
564 | la_ = new LineAttributeDialog(); |
---|
565 | la_.setJPane(pane_); |
---|
566 | } |
---|
567 | la_.setLineAttribute((LineAttribute)obj); |
---|
568 | if(!la_.isShowing()) |
---|
569 | la_.setVisible(true); |
---|
570 | } else if(obj instanceof VectorAttribute) { |
---|
571 | if(va_ == (VectorAttributeDialog) null) { |
---|
572 | // |
---|
573 | // create the LineAttr dialog |
---|
574 | // |
---|
575 | va_ = new VectorAttributeDialog(); |
---|
576 | va_.setJPane(pane_); |
---|
577 | } |
---|
578 | va_.setVectorAttribute((VectorAttribute)obj); |
---|
579 | if(!va_.isShowing()) |
---|
580 | va_.setVisible(true); |
---|
581 | } else if (obj instanceof GridAttribute) { |
---|
582 | if(ga_ == null) { |
---|
583 | // |
---|
584 | // create a new dialog |
---|
585 | // |
---|
586 | ga_ = new GridAttributeDialog(); |
---|
587 | } |
---|
588 | ga_.setGridAttribute((GridAttribute)obj); |
---|
589 | if(!ga_.isShowing()) |
---|
590 | ga_.setVisible(true); |
---|
591 | } else if (obj instanceof CartesianGraph) { |
---|
592 | CartesianRenderer rend = ((CartesianGraph)obj).getRenderer(); |
---|
593 | if( rend instanceof GridCartesianRenderer) { |
---|
594 | if(ga_ == null) { |
---|
595 | ga_ = new GridAttributeDialog(); |
---|
596 | } |
---|
597 | ga_.setGridCartesianRenderer((GridCartesianRenderer)rend); |
---|
598 | if(!ga_.isShowing()) |
---|
599 | ga_.setVisible(true); |
---|
600 | } |
---|
601 | } else if (obj instanceof PointAttribute) { |
---|
602 | if(pta_ == (PointAttributeDialog) null) { |
---|
603 | pta_ = new PointAttributeDialog(); |
---|
604 | } |
---|
605 | pta_.setPointAttribute((PointAttribute) obj, pane_); |
---|
606 | if(!pta_.isShowing()) |
---|
607 | pta_.show(); |
---|
608 | } |
---|
609 | } |
---|
610 | private Frame getFrame() { |
---|
611 | Container theFrame = this; |
---|
612 | do { |
---|
613 | theFrame = theFrame.getParent(); |
---|
614 | } while ((theFrame != null) && !(theFrame instanceof Frame)); |
---|
615 | if (theFrame == null) |
---|
616 | theFrame = new Frame(); |
---|
617 | return (Frame)theFrame; |
---|
618 | } |
---|
619 | } |
---|