KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jag > template > TemplateTreeItemViewer


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.template;
19
20
21 import com.finalist.jag.util.*;
22
23 import java.io.*;
24
25 import java.util.*;
26
27 import javax.swing.*;
28 import javax.swing.event.*;
29 import javax.swing.tree.*;
30
31
32 /**
33  * Class TemplateTreeItemViewer
34  *
35  *
36  * @author Wendel D. de Witte
37  * @version %I%, %G%
38  */

39 public class TemplateTreeItemViewer {
40
41    /**
42     * Method show
43     *
44     *
45     * @param dataObj
46     *
47     */

48    public static void show(TemplateTreeItem dataObj) {
49       show(dataObj, "TemplateTreeItemViewer");
50    }
51
52
53    /**
54     * Method show
55     *
56     *
57     * @param dataObj
58     * @param title
59     *
60     */

61    public static void show(TemplateTreeItem dataObj, String JavaDoc title) {
62
63       javax.swing.JFrame JavaDoc frame = new javax.swing.JFrame JavaDoc();
64
65       frame.getContentPane().add(createSwingTree(dataObj),
66          java.awt.BorderLayout.CENTER);
67       frame.setSize(400, 400);
68       frame.setTitle(title);
69       frame.setVisible(true);
70    }
71
72
73    /**
74     * Method createSwingTree
75     *
76     *
77     * @param dataObj
78     *
79     * @return
80     *
81     */

82    private static JScrollPane createSwingTree(TemplateTreeItem dataObj) {
83
84       DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
85
86       createSwingTree(root, dataObj);
87
88       JTree tree = new JTree(root) {
89
90          public java.awt.Insets JavaDoc getInsets() {
91             return new java.awt.Insets JavaDoc(5, 5, 5, 5);
92          }
93       };
94
95       return new JScrollPane(tree);
96    }
97
98
99    /**
100     * Method createSwingTree
101     *
102     *
103     * @param parent
104     * @param dataObj
105     *
106     */

107    private static void createSwingTree(DefaultMutableTreeNode parent,
108       TemplateTreeItem dataObj) {
109
110       TemplateTreeItem childItem =
111          (TemplateTreeItem) dataObj.getFirstChild();
112
113       while (childItem != null) {
114          String JavaDoc sText = (childItem.getTag() == null)
115             ? "[TextBlock] "
116             : "[TextBlock][TAG] ";
117
118          sText += childItem.getTextBlock().getText();
119
120          DefaultMutableTreeNode child = new DefaultMutableTreeNode(sText);
121
122          parent.add(child);
123          createSwingTree(child, childItem);
124
125          childItem = (TemplateTreeItem) childItem.getNextSibling();
126       }
127    }
128 }
129
Popular Tags