01: /*
02: ** Copyright (c) 1998 by Timothy Gerard Endres
03: ** <mailto:time@ice.com> <http://www.ice.com>
04: **
05: ** This program is free software.
06: **
07: ** You may redistribute it and/or modify it under the terms of the GNU
08: ** General Public License as published by the Free Software Foundation.
09: ** Version 2 of the license should be included with this distribution in
10: ** the file LICENSE, as well as License.html. If the license is not
11: ** included with this distribution, you may find a copy at the FSF web
12: ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
13: ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
14: **
15: ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
16: ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
17: ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
18: ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
19: ** REDISTRIBUTION OF THIS SOFTWARE.
20: **
21: */
22:
23: package com.ice.util;
24:
25: import java.io.*;
26:
27: public class DebugUtilities {
28: public static void printClassHierarchy(Class aClass,
29: PrintWriter writer, String prefix) {
30: String subPrefix = "-->";
31:
32: for (int i = 0;; ++i) {
33: writer.println(prefix + " " + subPrefix + " "
34: + aClass.getName());
35:
36: aClass = aClass.getSuperclass();
37:
38: if (aClass == Object.class)
39: break;
40:
41: subPrefix = "--" + subPrefix;
42: }
43: }
44:
45: public static void printContainerComponents(
46: java.awt.Container cont, PrintWriter writer, String prefix,
47: boolean recurse) {
48: java.awt.Component[] comps = cont.getComponents();
49:
50: if (comps.length < 1) {
51: writer.println(prefix + "Contains no components.");
52: }
53:
54: for (int i = 0; i < comps.length; ++i) {
55: DebugUtilities.printClassHierarchy(comps[i].getClass(),
56: writer, prefix + "[" + i + "]");
57:
58: if (recurse) {
59: Class c = java.awt.Container.class;
60: if (c.isAssignableFrom(comps[i].getClass())) {
61: DebugUtilities.printContainerComponents(
62: (java.awt.Container) comps[i], writer,
63: (prefix + "[" + i + "] "), recurse);
64: }
65: }
66: }
67: }
68:
69: }
|