KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jag > skelet > JagSkeletViewer


1 /* Copyright (C) 2003 Finalist IT Group
2  *
3  * This file is part of JAG - the Java J2EE Application Generator
4  *
5  * JAG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * JAG is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with JAG; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */

17
18 package com.finalist.jag.skelet;
19
20
21 import java.io.*;
22
23 import java.util.*;
24
25 import javax.swing.*;
26 import javax.swing.event.*;
27 import javax.swing.tree.*;
28
29
30 /**
31  * Class JagSkeletViewer
32  *
33  *
34  * @author Wendel D. de Witte
35  * @version %I%, %G%
36  */

37 public class JagSkeletViewer {
38
39    /**
40     * Method show
41     *
42     *
43     * @param dataObj
44     *
45     */

46    public static void show(ModuleData dataObj) {
47
48       javax.swing.JFrame JavaDoc frame = new javax.swing.JFrame JavaDoc();
49
50       frame.getContentPane().add(createSwingTree(dataObj),
51          java.awt.BorderLayout.CENTER);
52       frame.setSize(400, 400);
53       frame.setVisible(true);
54    }
55
56
57    /**
58     * Method createSwingTree
59     *
60     *
61     * @param dataObj
62     *
63     * @return
64     *
65     */

66    private static JScrollPane createSwingTree(ModuleData dataObj) {
67
68       DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
69
70       createSwingTree(root, dataObj);
71
72       JTree tree = new JTree(root) {
73
74          public java.awt.Insets JavaDoc getInsets() {
75             return new java.awt.Insets JavaDoc(5, 5, 5, 5);
76          }
77       };
78
79       return new JScrollPane(tree);
80    }
81
82
83    /**
84     * Method createSwingTree
85     *
86     *
87     * @param parent
88     * @param dataObj
89     *
90     */

91    private static void createSwingTree(DefaultMutableTreeNode parent,
92       ModuleData dataObj) {
93
94       if (dataObj instanceof SkeletModule) {
95          String JavaDoc label =
96             ((SkeletModule) dataObj).getRefname();
97          DefaultMutableTreeNode child =
98             new DefaultMutableTreeNode("ref-name > " + label);
99
100          parent.add(child);
101       }
102
103       if (dataObj.isValueCollection()) {
104          Collection col = (Collection) dataObj.getValue();
105          Iterator iterator = col.iterator();
106
107          while (iterator.hasNext()) {
108             ModuleData dataChild =
109                (ModuleData) iterator.next();
110             DefaultMutableTreeNode child =
111                new DefaultMutableTreeNode(dataChild.getName());
112
113             parent.add(child);
114             createSwingTree(child, dataChild);
115          }
116       }
117       else if (dataObj.isValueString()) {
118          String JavaDoc name = dataObj.getName();
119          String JavaDoc value = (String JavaDoc) dataObj.getValue();
120          DefaultMutableTreeNode child = new DefaultMutableTreeNode(name
121             + " > " + value);
122
123          parent.add(child);
124       }
125    }
126 }
127
Popular Tags