1 Clazz.declarePackage ("javax.swing.tree");
2 Clazz.load (["java.util.Enumeration", "javax.swing.tree.MutableTreeNode", "java.util.NoSuchElementException"], "javax.swing.tree.DefaultMutableTreeNode", ["java.lang.ArrayIndexOutOfBoundsException", "$.Error", "$.IllegalArgumentException", "$.IllegalStateException", "java.util.Stack", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
6 this.userObject = null;
7 this.allowsChildren = false;
8 if (!Clazz.isClassDefined ("javax.swing.tree.DefaultMutableTreeNode.PreorderEnumeration")) {
9 javax.swing.tree.DefaultMutableTreeNode.$DefaultMutableTreeNode$PreorderEnumeration$ ();
11 if (!Clazz.isClassDefined ("javax.swing.tree.DefaultMutableTreeNode.PostorderEnumeration")) {
12 javax.swing.tree.DefaultMutableTreeNode.$DefaultMutableTreeNode$PostorderEnumeration$ ();
14 if (!Clazz.isClassDefined ("javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration")) {
15 javax.swing.tree.DefaultMutableTreeNode.$DefaultMutableTreeNode$BreadthFirstEnumeration$ ();
17 if (!Clazz.isClassDefined ("javax.swing.tree.DefaultMutableTreeNode.PathBetweenNodesEnumeration")) {
18 javax.swing.tree.DefaultMutableTreeNode.$DefaultMutableTreeNode$PathBetweenNodesEnumeration$ ();
20 Clazz.instantialize (this, arguments);
21 }, javax.swing.tree, "DefaultMutableTreeNode", null, [Cloneable, javax.swing.tree.MutableTreeNode]);
22 Clazz.makeConstructor (c$,
24 this.construct (null);
26 Clazz.makeConstructor (c$,
27 function (userObject) {
28 this.construct (userObject, true);
30 Clazz.makeConstructor (c$,
31 function (userObject, allowsChildren) {
33 this.allowsChildren = allowsChildren;
34 this.userObject = userObject;
36 Clazz.overrideMethod (c$, "insert",
37 function (newChild, childIndex) {
38 if (!this.allowsChildren) {
39 throw new IllegalStateException ("node does not allow children");
40 } else if (newChild == null) {
41 throw new IllegalArgumentException ("new child is null");
42 } else if (this.isNodeAncestor (newChild)) {
43 throw new IllegalArgumentException ("new child is an ancestor");
44 }var oldParent = newChild.getParent ();
45 if (oldParent != null) {
46 oldParent.remove (newChild);
47 }newChild.setParent (this);
48 if (this.$children == null) {
49 this.$children = new java.util.Vector ();
50 }this.$children.insertElementAt (newChild, childIndex);
51 }, "javax.swing.tree.MutableTreeNode,~N");
52 Clazz.defineMethod (c$, "remove",
53 function (childIndex) {
54 var child = this.getChildAt (childIndex);
55 this.$children.removeElementAt (childIndex);
56 child.setParent (null);
58 Clazz.defineMethod (c$, "setParent",
59 function (newParent) {
60 this.parent = newParent;
61 }, "javax.swing.tree.MutableTreeNode");
62 Clazz.defineMethod (c$, "getParent",
66 Clazz.overrideMethod (c$, "getChildAt",
68 if (this.$children == null) {
69 throw new ArrayIndexOutOfBoundsException ("node has no children");
70 }return this.$children.elementAt (index);
72 Clazz.defineMethod (c$, "getChildCount",
74 if (this.$children == null) {
77 return this.$children.size ();
79 Clazz.overrideMethod (c$, "getIndex",
82 throw new IllegalArgumentException ("argument is null");
83 }if (!this.isNodeChild (aChild)) {
85 }return this.$children.indexOf (aChild);
86 }, "javax.swing.tree.TreeNode");
87 Clazz.defineMethod (c$, "children",
89 if (this.$children == null) {
90 return javax.swing.tree.DefaultMutableTreeNode.EMPTY_ENUMERATION;
92 return this.$children.elements ();
94 Clazz.defineMethod (c$, "setAllowsChildren",
96 if (allows != this.allowsChildren) {
97 this.allowsChildren = allows;
98 if (!this.allowsChildren) {
99 this.removeAllChildren ();
101 Clazz.overrideMethod (c$, "getAllowsChildren",
103 return this.allowsChildren;
105 Clazz.overrideMethod (c$, "setUserObject",
106 function (userObject) {
107 this.userObject = userObject;
109 Clazz.defineMethod (c$, "getUserObject",
111 return this.userObject;
113 Clazz.overrideMethod (c$, "removeFromParent",
115 var parent = this.getParent ();
116 if (parent != null) {
117 parent.remove (this);
119 Clazz.defineMethod (c$, "remove",
121 if (aChild == null) {
122 throw new IllegalArgumentException ("argument is null");
123 }if (!this.isNodeChild (aChild)) {
124 throw new IllegalArgumentException ("argument is not a child");
125 }this.remove (this.getIndex (aChild));
126 }, "javax.swing.tree.MutableTreeNode");
127 Clazz.defineMethod (c$, "removeAllChildren",
129 for (var i = this.getChildCount () - 1; i >= 0; i--) {
133 Clazz.defineMethod (c$, "add",
134 function (newChild) {
135 if (newChild != null && newChild.getParent () === this) this.insert (newChild, this.getChildCount () - 1);
136 else this.insert (newChild, this.getChildCount ());
137 }, "javax.swing.tree.MutableTreeNode");
138 Clazz.defineMethod (c$, "isNodeAncestor",
139 function (anotherNode) {
140 if (anotherNode == null) {
142 }var ancestor = this;
144 if (ancestor === anotherNode) {
146 }} while ((ancestor = ancestor.getParent ()) != null);
148 }, "javax.swing.tree.TreeNode");
149 Clazz.defineMethod (c$, "isNodeDescendant",
150 function (anotherNode) {
151 if (anotherNode == null) return false;
152 return anotherNode.isNodeAncestor (this);
153 }, "javax.swing.tree.DefaultMutableTreeNode");
154 Clazz.defineMethod (c$, "getSharedAncestor",
156 if (aNode === this) {
158 } else if (aNode == null) {
165 level1 = this.getLevel ();
166 level2 = aNode.getLevel ();
167 if (level2 > level1) {
168 diff = level2 - level1;
172 diff = level1 - level2;
176 node1 = node1.getParent ();
180 if (node1 === node2) {
182 }node1 = node1.getParent ();
183 node2 = node2.getParent ();
184 } while (node1 != null);
185 if (node1 != null || node2 != null) {
186 throw new Error ("nodes should be null");
188 }, "javax.swing.tree.DefaultMutableTreeNode");
189 Clazz.defineMethod (c$, "isNodeRelated",
191 return (aNode != null) && (this.getRoot () === aNode.getRoot ());
192 }, "javax.swing.tree.DefaultMutableTreeNode");
193 Clazz.defineMethod (c$, "getDepth",
196 var enum_ = this.breadthFirstEnumeration ();
197 while (enum_.hasMoreElements ()) {
198 last = enum_.nextElement ();
201 throw new Error ("nodes should be null");
202 }return (last).getLevel () - this.getLevel ();
204 Clazz.defineMethod (c$, "getLevel",
209 while ((ancestor = ancestor.getParent ()) != null) {
214 Clazz.defineMethod (c$, "getPath",
216 return this.getPathToRoot (this, 0);
218 Clazz.defineMethod (c$, "getPathToRoot",
219 function (aNode, depth) {
222 if (depth == 0) return null;
223 else retNodes = new Array (depth);
226 retNodes = this.getPathToRoot (aNode.getParent (), depth);
227 retNodes[retNodes.length - depth] = aNode;
229 }, "javax.swing.tree.TreeNode,~N");
230 Clazz.defineMethod (c$, "getUserObjectPath",
232 var realPath = this.getPath ();
233 var retPath = new Array (realPath.length);
234 for (var counter = 0; counter < realPath.length; counter++) retPath[counter] = (realPath[counter]).getUserObject ();
238 Clazz.defineMethod (c$, "getRoot",
244 ancestor = ancestor.getParent ();
245 } while (ancestor != null);
248 Clazz.defineMethod (c$, "isRoot",
250 return this.getParent () == null;
252 Clazz.defineMethod (c$, "getNextNode",
254 if (this.getChildCount () == 0) {
255 var nextSibling = this.getNextSibling ();
256 if (nextSibling == null) {
257 var aNode = this.getParent ();
261 }nextSibling = aNode.getNextSibling ();
262 if (nextSibling != null) {
264 }aNode = aNode.getParent ();
269 return this.getChildAt (0);
271 Clazz.defineMethod (c$, "getPreviousNode",
274 var myParent = this.getParent ();
275 if (myParent == null) {
277 }previousSibling = this.getPreviousSibling ();
278 if (previousSibling != null) {
279 if (previousSibling.getChildCount () == 0) return previousSibling;
280 else return previousSibling.getLastLeaf ();
284 Clazz.defineMethod (c$, "preorderEnumeration",
286 return Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode.PreorderEnumeration, this, null, this);
288 Clazz.defineMethod (c$, "postorderEnumeration",
290 return Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode.PostorderEnumeration, this, null, this);
292 Clazz.defineMethod (c$, "breadthFirstEnumeration",
294 return Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration, this, null, this);
296 Clazz.defineMethod (c$, "depthFirstEnumeration",
298 return this.postorderEnumeration ();
300 Clazz.defineMethod (c$, "pathFromAncestorEnumeration",
301 function (ancestor) {
302 return Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode.PathBetweenNodesEnumeration, this, null, ancestor, this);
303 }, "javax.swing.tree.TreeNode");
304 Clazz.defineMethod (c$, "isNodeChild",
310 if (this.getChildCount () == 0) {
313 retval = (aNode.getParent () === this);
315 }, "javax.swing.tree.TreeNode");
316 Clazz.defineMethod (c$, "getFirstChild",
318 if (this.getChildCount () == 0) {
319 throw new java.util.NoSuchElementException ("node has no children");
320 }return this.getChildAt (0);
322 Clazz.defineMethod (c$, "getLastChild",
324 if (this.getChildCount () == 0) {
325 throw new java.util.NoSuchElementException ("node has no children");
326 }return this.getChildAt (this.getChildCount () - 1);
328 Clazz.defineMethod (c$, "getChildAfter",
330 if (aChild == null) {
331 throw new IllegalArgumentException ("argument is null");
332 }var index = this.getIndex (aChild);
334 throw new IllegalArgumentException ("node is not a child");
335 }if (index < this.getChildCount () - 1) {
336 return this.getChildAt (index + 1);
339 }}, "javax.swing.tree.TreeNode");
340 Clazz.defineMethod (c$, "getChildBefore",
342 if (aChild == null) {
343 throw new IllegalArgumentException ("argument is null");
344 }var index = this.getIndex (aChild);
346 throw new IllegalArgumentException ("argument is not a child");
348 return this.getChildAt (index - 1);
351 }}, "javax.swing.tree.TreeNode");
352 Clazz.defineMethod (c$, "isNodeSibling",
353 function (anotherNode) {
355 if (anotherNode == null) {
357 } else if (anotherNode === this) {
360 var myParent = this.getParent ();
361 retval = (myParent != null && myParent === anotherNode.getParent ());
362 if (retval && !(this.getParent ()).isNodeChild (anotherNode)) {
363 throw new Error ("sibling has different parent");
365 }, "javax.swing.tree.TreeNode");
366 Clazz.defineMethod (c$, "getSiblingCount",
368 var myParent = this.getParent ();
369 if (myParent == null) {
372 return myParent.getChildCount ();
374 Clazz.defineMethod (c$, "getNextSibling",
377 var myParent = this.getParent ();
378 if (myParent == null) {
381 retval = myParent.getChildAfter (this);
382 }if (retval != null && !this.isNodeSibling (retval)) {
383 throw new Error ("child of parent is not a sibling");
386 Clazz.defineMethod (c$, "getPreviousSibling",
389 var myParent = this.getParent ();
390 if (myParent == null) {
393 retval = myParent.getChildBefore (this);
394 }if (retval != null && !this.isNodeSibling (retval)) {
395 throw new Error ("child of parent is not a sibling");
398 Clazz.defineMethod (c$, "isLeaf",
400 return (this.getChildCount () == 0);
402 Clazz.defineMethod (c$, "getFirstLeaf",
405 while (!node.isLeaf ()) {
406 node = node.getFirstChild ();
410 Clazz.defineMethod (c$, "getLastLeaf",
413 while (!node.isLeaf ()) {
414 node = node.getLastChild ();
418 Clazz.defineMethod (c$, "getNextLeaf",
421 var myParent = this.getParent ();
422 if (myParent == null) return null;
423 nextSibling = this.getNextSibling ();
424 if (nextSibling != null) return nextSibling.getFirstLeaf ();
425 return myParent.getNextLeaf ();
427 Clazz.defineMethod (c$, "getPreviousLeaf",
430 var myParent = this.getParent ();
431 if (myParent == null) return null;
432 previousSibling = this.getPreviousSibling ();
433 if (previousSibling != null) return previousSibling.getLastLeaf ();
434 return myParent.getPreviousLeaf ();
436 Clazz.defineMethod (c$, "getLeafCount",
440 var enum_ = this.breadthFirstEnumeration ();
441 while (enum_.hasMoreElements ()) {
442 node = enum_.nextElement ();
443 if (node.isLeaf ()) {
447 throw new Error ("tree has zero leaves");
450 Clazz.defineMethod (c$, "toString",
452 if (this.userObject == null) {
455 return this.userObject.toString ();
457 Clazz.defineMethod (c$, "clone",
461 newNode = Clazz.superCall (this, javax.swing.tree.DefaultMutableTreeNode, "clone", []);
462 newNode.$children = null;
463 newNode.parent = null;
465 if (Clazz.exceptionOf (e, CloneNotSupportedException)) {
466 throw new Error (e.toString ());
473 c$.$DefaultMutableTreeNode$PreorderEnumeration$ = function () {
475 c$ = Clazz.decorateAsClass (function () {
476 Clazz.prepareCallback (this, arguments);
478 Clazz.instantialize (this, arguments);
479 }, javax.swing.tree.DefaultMutableTreeNode, "PreorderEnumeration", null, java.util.Enumeration);
480 Clazz.makeConstructor (c$,
482 var b = new java.util.Vector (1);
484 this.stack = new java.util.Stack ();
485 this.stack.push (b.elements ());
486 }, "javax.swing.tree.TreeNode");
487 Clazz.overrideMethod (c$, "hasMoreElements",
489 return (!this.stack.empty () && (this.stack.peek ()).hasMoreElements ());
491 Clazz.overrideMethod (c$, "nextElement",
493 var a = this.stack.peek ();
494 var b = a.nextElement ();
495 var c = b.children ();
496 if (!a.hasMoreElements ()) {
498 }if (c.hasMoreElements ()) {
504 c$.$DefaultMutableTreeNode$PostorderEnumeration$ = function () {
506 c$ = Clazz.decorateAsClass (function () {
507 Clazz.prepareCallback (this, arguments);
509 this.children = null;
511 Clazz.instantialize (this, arguments);
512 }, javax.swing.tree.DefaultMutableTreeNode, "PostorderEnumeration", null, java.util.Enumeration);
513 Clazz.makeConstructor (c$,
516 this.children = this.root.children ();
517 this.subtree = javax.swing.tree.DefaultMutableTreeNode.EMPTY_ENUMERATION;
518 }, "javax.swing.tree.TreeNode");
519 Clazz.defineMethod (c$, "hasMoreElements",
521 return this.root != null;
523 Clazz.defineMethod (c$, "nextElement",
526 if (this.subtree.hasMoreElements ()) {
527 a = this.subtree.nextElement ();
528 } else if (this.children.hasMoreElements ()) {
529 this.subtree = Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode.PostorderEnumeration, this, null, this.children.nextElement ());
530 a = this.subtree.nextElement ();
538 c$.$DefaultMutableTreeNode$BreadthFirstEnumeration$ = function () {
540 c$ = Clazz.decorateAsClass (function () {
541 Clazz.prepareCallback (this, arguments);
543 if (!Clazz.isClassDefined ("javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.Queue")) {
544 javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.$DefaultMutableTreeNode$BreadthFirstEnumeration$Queue$ ();
546 Clazz.instantialize (this, arguments);
547 }, javax.swing.tree.DefaultMutableTreeNode, "BreadthFirstEnumeration", null, java.util.Enumeration);
548 Clazz.makeConstructor (c$,
550 var b = new java.util.Vector (1);
552 this.queue = Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.Queue, this, null);
553 this.queue.enqueue (b.elements ());
554 }, "javax.swing.tree.TreeNode");
555 Clazz.overrideMethod (c$, "hasMoreElements",
557 return (!this.queue.isEmpty () && (this.queue.firstObject ()).hasMoreElements ());
559 Clazz.overrideMethod (c$, "nextElement",
561 var a = this.queue.firstObject ();
562 var b = a.nextElement ();
563 var c = b.children ();
564 if (!a.hasMoreElements ()) {
565 this.queue.dequeue ();
566 }if (c.hasMoreElements ()) {
567 this.queue.enqueue (c);
570 c$.$DefaultMutableTreeNode$BreadthFirstEnumeration$Queue$ = function () {
572 c$ = Clazz.decorateAsClass (function () {
573 Clazz.prepareCallback (this, arguments);
576 if (!Clazz.isClassDefined ("javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.Queue.QNode")) {
577 javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.Queue.$DefaultMutableTreeNode$BreadthFirstEnumeration$Queue$QNode$ ();
579 Clazz.instantialize (this, arguments);
580 }, javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration, "Queue");
581 Clazz.defineMethod (c$, "enqueue",
583 if (this.head == null) {
584 this.head = this.tail = Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.Queue.QNode, this, null, a, null);
586 this.tail.next = Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.Queue.QNode, this, null, a, null);
587 this.tail = this.tail.next;
589 Clazz.defineMethod (c$, "dequeue",
591 if (this.head == null) {
592 throw new java.util.NoSuchElementException ("No more elements");
593 }var a = this.head.object;
595 this.head = this.head.next;
596 if (this.head == null) {
602 Clazz.defineMethod (c$, "firstObject",
604 if (this.head == null) {
605 throw new java.util.NoSuchElementException ("No more elements");
606 }return this.head.object;
608 Clazz.defineMethod (c$, "isEmpty",
610 return this.head == null;
612 c$.$DefaultMutableTreeNode$BreadthFirstEnumeration$Queue$QNode$ = function () {
614 c$ = Clazz.decorateAsClass (function () {
615 Clazz.prepareCallback (this, arguments);
618 Clazz.instantialize (this, arguments);
619 }, javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.Queue, "QNode");
620 Clazz.makeConstructor (c$,
624 }, "~O,javax.swing.tree.DefaultMutableTreeNode.BreadthFirstEnumeration.Queue.QNode");
631 c$.$DefaultMutableTreeNode$PathBetweenNodesEnumeration$ = function () {
633 c$ = Clazz.decorateAsClass (function () {
634 Clazz.prepareCallback (this, arguments);
636 Clazz.instantialize (this, arguments);
637 }, javax.swing.tree.DefaultMutableTreeNode, "PathBetweenNodesEnumeration", null, java.util.Enumeration);
638 Clazz.makeConstructor (c$,
640 if (a == null || b == null) {
641 throw new IllegalArgumentException ("argument is null");
643 this.stack = new java.util.Stack ();
648 if (c == null && b !== a) {
649 throw new IllegalArgumentException ("node " + a + " is not an ancestor of " + b);
650 }this.stack.push (c);
652 }, "javax.swing.tree.TreeNode,javax.swing.tree.TreeNode");
653 Clazz.overrideMethod (c$, "hasMoreElements",
655 return this.stack.size () > 0;
657 Clazz.overrideMethod (c$, "nextElement",
660 return this.stack.pop ();
662 if (Clazz.exceptionOf (e, java.util.EmptyStackException)) {
663 throw new java.util.NoSuchElementException ("No more elements");
671 c$.$DefaultMutableTreeNode$1$ = function () {
673 c$ = Clazz.declareAnonymous (javax.swing.tree, "DefaultMutableTreeNode$1", null, java.util.Enumeration);
674 Clazz.defineMethod (c$, "hasMoreElements",
678 Clazz.defineMethod (c$, "nextElement",
680 throw new java.util.NoSuchElementException ("No more elements");
684 c$.EMPTY_ENUMERATION = c$.prototype.EMPTY_ENUMERATION = ((Clazz.isClassDefined ("javax.swing.tree.DefaultMutableTreeNode$1") ? 0 : javax.swing.tree.DefaultMutableTreeNode.$DefaultMutableTreeNode$1$ ()), Clazz.innerTypeInstance (javax.swing.tree.DefaultMutableTreeNode$1, this, null));