001: /*
002: * $RCSfile: RoutePrinter.java,v $
003: *
004: * @(#)RoutePrinter.java 1.6 98/11/05 20:34:59
005: *
006: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * $Revision: 1.2 $
033: * $Date: 2005/02/03 23:07:00 $
034: * $State: Exp $
035: */
036: /*
037: * @Author: Rick Goldberg
038: * @Author: Doug Gehringer
039: *
040: */
041: package org.jdesktop.j3d.loaders.vrml97.impl;
042:
043: import java.util.Enumeration;
044: import java.util.Hashtable;
045: import java.util.Vector;
046:
047: /** Description of the Class */
048: class RoutePrinter {
049: Vector fieldsVisited = new Vector();
050: Vector fieldsToVisit = new Vector();
051: Vector nodesVisited = new Vector();
052: Vector nodesToVisit = new Vector();
053: String indent;
054:
055: /**
056: * Description of the Method
057: *
058: *@param in Description of the Parameter
059: *@param length Description of the Parameter
060: *@return Description of the Return Value
061: */
062: String fixedLengthString(String in, int length) {
063: while (in.length() < length) {
064: in = in + " ";
065: }
066: return in;
067: }
068:
069: /**
070: * Description of the Method
071: *
072: *@param curField Description of the Parameter
073: */
074: private void printRoutesField(Field curField) {
075: if (fieldsVisited.contains(curField)) {
076: return;
077: }
078: fieldsVisited.addElement(curField);
079: fieldsToVisit.removeElement(curField);
080: if ((curField.connections != null)
081: && (curField.connections.size() != 0)) {
082: System.out.println("Field " + curField.fieldName + ": "
083: + curField);
084: System.out.println(" owned by " + curField.ownerNode);
085: System.out.println(" connects to "
086: + curField.connections.size() + " field(s):");
087: for (Enumeration e = curField.connections.elements(); e
088: .hasMoreElements();) {
089: Field newField = (Field) e.nextElement();
090: System.out.println(" "
091: + fixedLengthString(newField.fieldName, 20)
092: + " " + newField + "\n owned by "
093: + newField.ownerNode.defName + " "
094: + newField.ownerNode);
095: if (!fieldsVisited.contains(newField)
096: && !fieldsToVisit.contains(newField)) {
097: fieldsToVisit.addElement(newField);
098: }
099: }
100: } else {
101: //System.out.println("Field " + curField.fieldName + ": " +
102: // curField);
103: //System.out.println(" owned by " + curField.ownerNode);
104: //System.out.println(" has no connections");
105: }
106: if (curField.ownerNode != null) {
107: printRoutesNode(curField.ownerNode);
108: }
109: }
110:
111: /**
112: * Description of the Method
113: *
114: *@param curNode Description of the Parameter
115: */
116: private void printRoutesNode(BaseNode curNode) {
117: if (nodesVisited.contains(curNode)) {
118: return;
119: }
120: nodesVisited.addElement(curNode);
121: nodesToVisit.removeElement(curNode);
122: System.out.println("Node " + curNode + " named "
123: + curNode.defName + "\n has fields: ");
124: Hashtable fieldSpec = null;
125: if (curNode instanceof Node) {
126: fieldSpec = ((Node) curNode).FieldSpec;
127: } else if (curNode instanceof Script) {
128: fieldSpec = ((Node) curNode).FieldSpec;
129: }
130: Vector printedFields = new Vector();
131: for (Enumeration e = fieldSpec.elements(); e.hasMoreElements();) {
132: Field newField = (Field) e.nextElement();
133: if (newField instanceof ConstField) {
134: newField = ((ConstField) newField).ownerField;
135: }
136: if (!printedFields.contains(newField)) {
137: printedFields.addElement(newField);
138: System.out.println(" "
139: + fixedLengthString(newField.fieldName, 20)
140: + " " + newField);
141: if (!fieldsVisited.contains(newField)
142: && !fieldsToVisit.contains(newField)) {
143: fieldsToVisit.addElement(newField);
144: }
145: }
146: }
147: }
148:
149: /** Description of the Method */
150: private void reset() {
151: fieldsVisited.removeAllElements();
152: nodesVisited.removeAllElements();
153: nodesToVisit.removeAllElements();
154: fieldsToVisit.removeAllElements();
155: }
156:
157: /**
158: * Description of the Method
159: *
160: *@param startField Description of the Parameter
161: */
162: void printRoutes(Field startField) {
163: fieldsToVisit.addElement(startField);
164: doIt();
165: }
166:
167: /**
168: * Description of the Method
169: *
170: *@param startNode Description of the Parameter
171: */
172: void printRoutes(BaseNode startNode) {
173: nodesToVisit.addElement(startNode);
174: doIt();
175: }
176:
177: /** Description of the Method */
178: private void doIt() {
179: while ((fieldsToVisit.size() > 0) || (nodesToVisit.size() > 0)) {
180: for (Enumeration e = fieldsToVisit.elements(); e
181: .hasMoreElements();) {
182: Field newField = (Field) e.nextElement();
183: printRoutesField(newField);
184: }
185: for (Enumeration e = nodesToVisit.elements(); e
186: .hasMoreElements();) {
187: BaseNode newNode = (BaseNode) e.nextElement();
188: printRoutesNode(newNode);
189: }
190: }
191: }
192:
193: }
|