3ce99f74eefe1a53d164aca44b02b5aea4cee90e
[jalviewjs.git] / site / j2s / javax / swing / text / ElementIterator.js
1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (null, "javax.swing.text.ElementIterator", ["java.lang.CloneNotSupportedException", "$.InternalError", "java.util.Stack"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.root = null;
5 this.elementStack = null;
6 if (!Clazz.isClassDefined ("javax.swing.text.ElementIterator.StackItem")) {
7 javax.swing.text.ElementIterator.$ElementIterator$StackItem$ ();
8 }
9 Clazz.instantialize (this, arguments);
10 }, javax.swing.text, "ElementIterator", null, Cloneable);
11 Clazz.makeConstructor (c$, 
12 function (document) {
13 this.root = document.getDefaultRootElement ();
14 }, "javax.swing.text.Document");
15 Clazz.makeConstructor (c$, 
16 function (root) {
17 this.root = root;
18 }, "javax.swing.text.Element");
19 Clazz.defineMethod (c$, "clone", 
20 function () {
21 try {
22 var it =  new javax.swing.text.ElementIterator (this.root);
23 if (this.elementStack != null) {
24 it.elementStack =  new java.util.Stack ();
25 for (var i = 0; i < this.elementStack.size (); i++) {
26 var item = this.elementStack.elementAt (i);
27 var clonee = item.clone ();
28 it.elementStack.push (clonee);
29 }
30 }return it;
31 } catch (e) {
32 if (Clazz.exceptionOf (e, CloneNotSupportedException)) {
33 throw  new InternalError ();
34 } else {
35 throw e;
36 }
37 }
38 });
39 Clazz.defineMethod (c$, "first", 
40 function () {
41 if (this.root == null) {
42 return null;
43 }this.elementStack =  new java.util.Stack ();
44 if (this.root.getElementCount () != 0) {
45 this.elementStack.push (Clazz.innerTypeInstance (javax.swing.text.ElementIterator.StackItem, this, null, this.root));
46 }return this.root;
47 });
48 Clazz.defineMethod (c$, "depth", 
49 function () {
50 if (this.elementStack == null) {
51 return 0;
52 }return this.elementStack.size ();
53 });
54 Clazz.defineMethod (c$, "current", 
55 function () {
56 if (this.elementStack == null) {
57 return this.first ();
58 }if (!this.elementStack.empty ()) {
59 var item = this.elementStack.peek ();
60 var elem = item.getElement ();
61 var index = item.getIndex ();
62 if (index == -1) {
63 return elem;
64 }return elem.getElement (index);
65 }return null;
66 });
67 Clazz.defineMethod (c$, "next", 
68 function () {
69 if (this.elementStack == null) {
70 return this.first ();
71 }if (this.elementStack.isEmpty ()) {
72 return null;
73 }var item = this.elementStack.peek ();
74 var elem = item.getElement ();
75 var index = item.getIndex ();
76 if (index + 1 < elem.getElementCount ()) {
77 var child = elem.getElement (index + 1);
78 if (child.isLeaf ()) {
79 item.incrementIndex ();
80 } else {
81 this.elementStack.push (Clazz.innerTypeInstance (javax.swing.text.ElementIterator.StackItem, this, null, child));
82 }return child;
83 } else {
84 this.elementStack.pop ();
85 if (!this.elementStack.isEmpty ()) {
86 var top = this.elementStack.peek ();
87 top.incrementIndex ();
88 return this.next ();
89 }}return null;
90 });
91 Clazz.defineMethod (c$, "previous", 
92 function () {
93 var stackSize;
94 if (this.elementStack == null || (stackSize = this.elementStack.size ()) == 0) {
95 return null;
96 }var item = this.elementStack.peek ();
97 var elem = item.getElement ();
98 var index = item.getIndex ();
99 if (index > 0) {
100 return this.getDeepestLeaf (elem.getElement (--index));
101 } else if (index == 0) {
102 return elem;
103 } else if (index == -1) {
104 if (stackSize == 1) {
105 return null;
106 }var top = this.elementStack.pop ();
107 item = this.elementStack.peek ();
108 this.elementStack.push (top);
109 elem = item.getElement ();
110 index = item.getIndex ();
111 return ((index == -1) ? elem : this.getDeepestLeaf (elem.getElement (index)));
112 }return null;
113 });
114 Clazz.defineMethod (c$, "getDeepestLeaf", 
115  function (parent) {
116 if (parent.isLeaf ()) {
117 return parent;
118 }var childCount = parent.getElementCount ();
119 if (childCount == 0) {
120 return parent;
121 }return this.getDeepestLeaf (parent.getElement (childCount - 1));
122 }, "javax.swing.text.Element");
123 c$.$ElementIterator$StackItem$ = function () {
124 Clazz.pu$h(self.c$);
125 c$ = Clazz.decorateAsClass (function () {
126 Clazz.prepareCallback (this, arguments);
127 this.item = null;
128 this.childIndex = 0;
129 Clazz.instantialize (this, arguments);
130 }, javax.swing.text.ElementIterator, "StackItem", null, Cloneable);
131 Clazz.makeConstructor (c$, 
132  function (a) {
133 this.item = a;
134 this.childIndex = -1;
135 }, "javax.swing.text.Element");
136 Clazz.defineMethod (c$, "incrementIndex", 
137  function () {
138 this.childIndex++;
139 });
140 Clazz.defineMethod (c$, "getElement", 
141  function () {
142 return this.item;
143 });
144 Clazz.defineMethod (c$, "getIndex", 
145  function () {
146 return this.childIndex;
147 });
148 c$ = Clazz.p0p ();
149 };
150 });