001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * Trace.java
044: *
045: * Created on January 11, 2007, 2:02 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.test.umllib.util;
052:
053: import java.awt.Component;
054: import java.awt.Container;
055: import javax.swing.JList;
056: import javax.swing.JTabbedPane;
057: import javax.swing.JTable;
058: import javax.swing.JTree;
059: import javax.swing.tree.TreeModel;
060: import javax.swing.tree.TreePath;
061: import org.netbeans.jellytools.MainWindowOperator;
062: import org.netbeans.jellytools.nodes.Node;
063: import org.netbeans.jemmy.operators.JTreeOperator;
064: import org.netbeans.junit.NbTestCase;
065:
066: /**
067: *
068: * @author Alexandr Scherbatiy
069: */
070:
071: public class Debug {
072:
073: public static final String BLANK = " ";
074:
075: public static final boolean HIERARCHY_FLAG = false;
076:
077: public static void showLog(NbTestCase testCase) {
078: System.setOut(testCase.getLog());
079: }
080:
081: public static void showNode(Node node) {
082: System.out.println("[Node]");
083: showTreePath(node.tree(), node.getTreePath());
084: }
085:
086: public static void showTreePath(JTreeOperator treeOperator,
087: TreePath path) {
088: showTreePath("", treeOperator, path);
089: }
090:
091: public static void showTreePath(String blank,
092: JTreeOperator treeOperator, TreePath path) {
093: System.out.println(blank + "[path] " + "\"" + path + "\"");
094:
095: for (int i = 0; i < treeOperator.getChildCount(path); i++) {
096: showTreePath(blank + BLANK, treeOperator, treeOperator
097: .getChildPath(path, i));
098: }
099:
100: }
101:
102: public static void showTree(JTreeOperator treeOperator) {
103:
104: TreeModel model = treeOperator.getModel();
105: System.out.println("[Tree]");
106: showTree("", model, model.getRoot());
107: }
108:
109: public static void showTree(String blank, TreeModel model,
110: Object node) {
111: System.out.println(blank + "\"" + node + "\"");
112:
113: for (int i = 0; i < model.getChildCount(node); i++) {
114: showTree(blank + BLANK, model, model.getChild(node, i));
115: }
116:
117: }
118:
119: //================== Show Components ==============================================
120:
121: public static void show() {
122: out("======================= Show Dump ======================= ");
123: show(MainWindowOperator.getDefault().getSource());
124: out("========================================================= ");
125: }
126:
127: public static void show(Component component) {
128: show(component, "", 0);
129: }
130:
131: private static void show(Component component, String indent,
132: int index) {
133:
134: System.out.println(indent + index + ": " + component);
135: componentDescription(indent, component);
136:
137: if (HIERARCHY_FLAG) {
138: showClassHierarchy(component);
139: }
140:
141: if (component instanceof Container) {
142: Component[] components = ((Container) component)
143: .getComponents();
144:
145: for (int i = 0; i < components.length; i++) {
146: show(components[i], " " + indent, i);
147: }
148: }
149: }
150:
151: private static void componentDescription(String blank,
152: Component component) {
153:
154: String name = component.getName();
155:
156: //if (name!=null){
157: System.out.println(blank + " component name = \""
158: + component.getName() + "\"");
159: //}
160:
161: if (component instanceof JTabbedPane) {
162: System.out.println(blank + " [JTabbedPane]");
163: } else if (component instanceof JTree) {
164: System.out.println(blank + " [JTree]");
165: //JTestTree.show(blank, ( JTree) component);
166: } else if (component instanceof JList) {
167: System.out.println(blank + " [JList]");
168: } else if (component instanceof JTable) {
169: System.out.println(blank + " [JTable]");
170: }
171:
172: }
173:
174: public static void showClassHierarchy(Object obj) {
175:
176: System.out
177: .print("==================================================================");
178: System.out
179: .println("==================================================================");
180: System.out.println("Class Hierarchy:");
181: showClassHierarchy("", obj.getClass());
182: System.out.println("String: " + obj.toString());
183: System.out
184: .print("==================================================================");
185: System.out
186: .println("==================================================================");
187:
188: }
189:
190: private static void showClassHierarchy(String blank, Class cls) {
191: if (!cls.getName().equals("java.lang.Object")) {
192: System.out.println(blank + "class: " + cls.getName());
193: Class[] inter = cls.getInterfaces();
194:
195: for (int i = 0; i < inter.length; i++) {
196: showInterfaceHierarchy(blank, inter[i]);
197: }
198:
199: showClassHierarchy(blank + " ", cls.getSuperclass());
200: }
201: }
202:
203: private static void showInterfaceHierarchy(String blank, Class inter) {
204: System.out.println(blank + "interface: " + inter.getName());
205: Class[] interf = inter.getInterfaces();
206:
207: for (int i = 0; i < interf.length; i++) {
208: showInterfaceHierarchy(blank + " ", interf[i]);
209: }
210: }
211:
212: //================== Out Procedure ==============================================
213:
214: private static void out(String text) {
215: System.out.println("[main]: " + text);
216: }
217:
218: }
|