22b8dd7c31579a66d209137fb06a7036726852a3
[jalviewjs.git] / site / j2s / javax / swing / tree / TreePath.js
1 Clazz.declarePackage ("javax.swing.tree");
2 Clazz.load (null, "javax.swing.tree.TreePath", ["java.lang.IllegalArgumentException", "$.NullPointerException", "$.StringBuffer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.parentPath = null;
5 this.lastPathComponent = null;
6 Clazz.instantialize (this, arguments);
7 }, javax.swing.tree, "TreePath");
8 Clazz.makeConstructor (c$, 
9 function (path) {
10 if (path == null || path.length == 0) throw  new IllegalArgumentException ("path in TreePath must be non null and not empty.");
11 this.lastPathComponent = path[path.length - 1];
12 if (path.length > 1) this.parentPath =  new javax.swing.tree.TreePath (path, path.length - 1);
13 }, "~A");
14 Clazz.makeConstructor (c$, 
15 function (singlePath) {
16 if (singlePath == null) throw  new IllegalArgumentException ("path in TreePath must be non null.");
17 this.lastPathComponent = singlePath;
18 this.parentPath = null;
19 }, "~O");
20 Clazz.makeConstructor (c$, 
21 function (parent, lastElement) {
22 if (lastElement == null) throw  new IllegalArgumentException ("path in TreePath must be non null.");
23 this.parentPath = parent;
24 this.lastPathComponent = lastElement;
25 }, "javax.swing.tree.TreePath,~O");
26 Clazz.makeConstructor (c$, 
27 function (path, length) {
28 this.lastPathComponent = path[length - 1];
29 if (length > 1) this.parentPath =  new javax.swing.tree.TreePath (path, length - 1);
30 }, "~A,~N");
31 Clazz.makeConstructor (c$, 
32 function () {
33 });
34 Clazz.defineMethod (c$, "getPath", 
35 function () {
36 var i = this.getPathCount ();
37 var result =  new Array (i--);
38 for (var path = this; path != null; path = path.parentPath) {
39 result[i--] = path.lastPathComponent;
40 }
41 return result;
42 });
43 Clazz.defineMethod (c$, "getLastPathComponent", 
44 function () {
45 return this.lastPathComponent;
46 });
47 Clazz.defineMethod (c$, "getPathCount", 
48 function () {
49 var result = 0;
50 for (var path = this; path != null; path = path.parentPath) {
51 result++;
52 }
53 return result;
54 });
55 Clazz.defineMethod (c$, "getPathComponent", 
56 function (element) {
57 var pathLength = this.getPathCount ();
58 if (element < 0 || element >= pathLength) throw  new IllegalArgumentException ("Index " + element + " is out of the specified range");
59 var path = this;
60 for (var i = pathLength - 1; i != element; i--) {
61 path = path.parentPath;
62 }
63 return path.lastPathComponent;
64 }, "~N");
65 Clazz.defineMethod (c$, "equals", 
66 function (o) {
67 if (o === this) return true;
68 if (Clazz.instanceOf (o, javax.swing.tree.TreePath)) {
69 var oTreePath = o;
70 if (this.getPathCount () != oTreePath.getPathCount ()) return false;
71 for (var path = this; path != null; path = path.parentPath) {
72 if (!(path.lastPathComponent.equals (oTreePath.lastPathComponent))) {
73 return false;
74 }oTreePath = oTreePath.parentPath;
75 }
76 return true;
77 }return false;
78 }, "~O");
79 Clazz.defineMethod (c$, "hashCode", 
80 function () {
81 return this.lastPathComponent.hashCode ();
82 });
83 Clazz.defineMethod (c$, "isDescendant", 
84 function (aTreePath) {
85 if (aTreePath === this) return true;
86 if (aTreePath != null) {
87 var pathLength = this.getPathCount ();
88 var oPathLength = aTreePath.getPathCount ();
89 if (oPathLength < pathLength) return false;
90 while (oPathLength-- > pathLength) aTreePath = aTreePath.getParentPath ();
91
92 return this.equals (aTreePath);
93 }return false;
94 }, "javax.swing.tree.TreePath");
95 Clazz.defineMethod (c$, "pathByAddingChild", 
96 function (child) {
97 if (child == null) throw  new NullPointerException ("Null child not allowed");
98 return  new javax.swing.tree.TreePath (this, child);
99 }, "~O");
100 Clazz.defineMethod (c$, "getParentPath", 
101 function () {
102 return this.parentPath;
103 });
104 Clazz.overrideMethod (c$, "toString", 
105 function () {
106 var tempSpot =  new StringBuffer ("[");
107 for (var counter = 0, maxCounter = this.getPathCount (); counter < maxCounter; counter++) {
108 if (counter > 0) tempSpot.append (", ");
109 tempSpot.append (this.getPathComponent (counter));
110 }
111 tempSpot.append ("]");
112 return tempSpot.toString ();
113 });
114 });