70bfcd746ac4c3b71630a75c3ab35f71be6ba8fe
[jalviewjs.git] / site / swingjs / j2s / javax / swing / text / CompositeView.js
1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.text.View"], "javax.swing.text.CompositeView", ["java.lang.IllegalArgumentException", "java.awt.Rectangle", "javax.swing.text.BadLocationException", "$.Position", "$.StyleConstants", "$.Utilities"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.children = null;
5 this.nchildren = 0;
6 this.left = 0;
7 this.right = 0;
8 this.top = 0;
9 this.bottom = 0;
10 this.childAlloc = null;
11 Clazz.instantialize (this, arguments);
12 }, javax.swing.text, "CompositeView", javax.swing.text.View);
13 Clazz.makeConstructor (c$, 
14 function (elem) {
15 Clazz.superConstructor (this, javax.swing.text.CompositeView, [elem]);
16 this.children =  new Array (1);
17 this.nchildren = 0;
18 this.childAlloc =  new java.awt.Rectangle ();
19 }, "javax.swing.text.Element");
20 Clazz.defineMethod (c$, "loadChildren", 
21 function (f) {
22 if (f == null) {
23 return;
24 }var e = this.getElement ();
25 var n = e.getElementCount ();
26 if (n > 0) {
27 var added =  new Array (n);
28 for (var i = 0; i < n; i++) {
29 added[i] = f.create (e.getElement (i));
30 }
31 this.replace (0, 0, added);
32 }}, "javax.swing.text.ViewFactory");
33 Clazz.defineMethod (c$, "setParent", 
34 function (parent) {
35 Clazz.superCall (this, javax.swing.text.CompositeView, "setParent", [parent]);
36 if ((parent != null) && (this.nchildren == 0)) {
37 var f = this.getViewFactory ();
38 this.loadChildren (f);
39 }}, "javax.swing.text.View");
40 Clazz.overrideMethod (c$, "getViewCount", 
41 function () {
42 return this.nchildren;
43 });
44 Clazz.overrideMethod (c$, "getView", 
45 function (n) {
46 return this.children[n];
47 }, "~N");
48 Clazz.overrideMethod (c$, "replace", 
49 function (offset, length, views) {
50 if (views == null) {
51 views = javax.swing.text.CompositeView.ZERO;
52 }for (var i = offset; i < offset + length; i++) {
53 if (this.children[i].getParent () === this) {
54 this.children[i].setParent (null);
55 }this.children[i] = null;
56 }
57 var delta = views.length - length;
58 var src = offset + length;
59 var nmove = this.nchildren - src;
60 var dest = src + delta;
61 if ((this.nchildren + delta) >= this.children.length) {
62 var newLength = Math.max (2 * this.children.length, this.nchildren + delta);
63 var newChildren =  new Array (newLength);
64 System.arraycopy (this.children, 0, newChildren, 0, offset);
65 System.arraycopy (views, 0, newChildren, offset, views.length);
66 System.arraycopy (this.children, src, newChildren, dest, nmove);
67 this.children = newChildren;
68 } else {
69 System.arraycopy (this.children, src, this.children, dest, nmove);
70 System.arraycopy (views, 0, this.children, offset, views.length);
71 }this.nchildren = this.nchildren + delta;
72 for (var i = 0; i < views.length; i++) {
73 views[i].setParent (this);
74 }
75 }, "~N,~N,~A");
76 Clazz.overrideMethod (c$, "getChildAllocation", 
77 function (index, a) {
78 var alloc = this.getInsideAllocation (a);
79 this.childAllocation (index, alloc);
80 return alloc;
81 }, "~N,java.awt.Shape");
82 Clazz.defineMethod (c$, "modelToView", 
83 function (pos, a, b) {
84 var isBackward = (b === javax.swing.text.Position.Bias.Backward);
85 var testPos = (isBackward) ? Math.max (0, pos - 1) : pos;
86 if (isBackward && testPos < this.getStartOffset ()) {
87 return null;
88 }var vIndex = this.getViewIndexAtPosition (testPos);
89 if ((vIndex != -1) && (vIndex < this.getViewCount ())) {
90 var v = this.getView (vIndex);
91 if (v != null && testPos >= v.getStartOffset () && testPos < v.getEndOffset ()) {
92 var childShape = this.getChildAllocation (vIndex, a);
93 if (childShape == null) {
94 return null;
95 }var retShape = v.modelToView (pos, childShape, b);
96 if (retShape == null && v.getEndOffset () == pos) {
97 if (++vIndex < this.getViewCount ()) {
98 v = this.getView (vIndex);
99 retShape = v.modelToView (pos, this.getChildAllocation (vIndex, a), b);
100 }}return retShape;
101 }}throw  new javax.swing.text.BadLocationException ("Position not represented by view", pos);
102 }, "~N,java.awt.Shape,javax.swing.text.Position.Bias");
103 Clazz.defineMethod (c$, "modelToView", 
104 function (p0, b0, p1, b1, a) {
105 if (p0 == this.getStartOffset () && p1 == this.getEndOffset ()) {
106 return a;
107 }var alloc = this.getInsideAllocation (a);
108 var r0 =  new java.awt.Rectangle (alloc);
109 var v0 = this.getViewAtPosition ((b0 === javax.swing.text.Position.Bias.Backward) ? Math.max (0, p0 - 1) : p0, r0);
110 var r1 =  new java.awt.Rectangle (alloc);
111 var v1 = this.getViewAtPosition ((b1 === javax.swing.text.Position.Bias.Backward) ? Math.max (0, p1 - 1) : p1, r1);
112 if (v0 === v1) {
113 if (v0 == null) {
114 return a;
115 }return v0.modelToView (p0, b0, p1, b1, r0);
116 }var viewCount = this.getViewCount ();
117 var counter = 0;
118 while (counter < viewCount) {
119 var v;
120 if ((v = this.getView (counter)) === v0 || v === v1) {
121 var endView;
122 var retRect;
123 var tempRect =  new java.awt.Rectangle ();
124 if (v === v0) {
125 retRect = v0.modelToView (p0, b0, v0.getEndOffset (), javax.swing.text.Position.Bias.Backward, r0).getBounds ();
126 endView = v1;
127 } else {
128 retRect = v1.modelToView (v1.getStartOffset (), javax.swing.text.Position.Bias.Forward, p1, b1, r1).getBounds ();
129 endView = v0;
130 }while (++counter < viewCount && (v = this.getView (counter)) !== endView) {
131 tempRect.setBounds (alloc);
132 this.childAllocation (counter, tempRect);
133 retRect.add (tempRect);
134 }
135 if (endView != null) {
136 var endShape;
137 if (endView === v1) {
138 endShape = v1.modelToView (v1.getStartOffset (), javax.swing.text.Position.Bias.Forward, p1, b1, r1);
139 } else {
140 endShape = v0.modelToView (p0, b0, v0.getEndOffset (), javax.swing.text.Position.Bias.Backward, r0);
141 }if (Clazz.instanceOf (endShape, java.awt.Rectangle)) {
142 retRect.add (endShape);
143 } else {
144 retRect.add (endShape.getBounds ());
145 }}return retRect;
146 }counter++;
147 }
148 throw  new javax.swing.text.BadLocationException ("Position not represented by view", p0);
149 }, "~N,javax.swing.text.Position.Bias,~N,javax.swing.text.Position.Bias,java.awt.Shape");
150 Clazz.defineMethod (c$, "viewToModel", 
151 function (x, y, a, bias) {
152 var alloc = this.getInsideAllocation (a);
153 if (this.isBefore (Clazz.floatToInt (x), Clazz.floatToInt (y), alloc)) {
154 var retValue = -1;
155 try {
156 retValue = this.getNextVisualPositionFrom (-1, javax.swing.text.Position.Bias.Forward, a, 3, bias);
157 } catch (e$$) {
158 if (Clazz.exceptionOf (e$$, javax.swing.text.BadLocationException)) {
159 var ble = e$$;
160 {
161 }
162 } else if (Clazz.exceptionOf (e$$, IllegalArgumentException)) {
163 var iae = e$$;
164 {
165 }
166 } else {
167 throw e$$;
168 }
169 }
170 if (retValue == -1) {
171 retValue = this.getStartOffset ();
172 bias[0] = javax.swing.text.Position.Bias.Forward;
173 }return retValue;
174 } else if (this.isAfter (Clazz.floatToInt (x), Clazz.floatToInt (y), alloc)) {
175 var retValue = -1;
176 try {
177 retValue = this.getNextVisualPositionFrom (-1, javax.swing.text.Position.Bias.Forward, a, 7, bias);
178 } catch (e$$) {
179 if (Clazz.exceptionOf (e$$, javax.swing.text.BadLocationException)) {
180 var ble = e$$;
181 {
182 }
183 } else if (Clazz.exceptionOf (e$$, IllegalArgumentException)) {
184 var iae = e$$;
185 {
186 }
187 } else {
188 throw e$$;
189 }
190 }
191 if (retValue == -1) {
192 retValue = this.getEndOffset () - 1;
193 bias[0] = javax.swing.text.Position.Bias.Forward;
194 }return retValue;
195 } else {
196 var v = this.getViewAtPoint (Clazz.floatToInt (x), Clazz.floatToInt (y), alloc);
197 if (v != null) {
198 return v.viewToModel (x, y, alloc, bias);
199 }}return -1;
200 }, "~N,~N,java.awt.Shape,~A");
201 Clazz.overrideMethod (c$, "getNextVisualPositionFrom", 
202 function (pos, b, a, direction, biasRet) {
203 switch (direction) {
204 case 1:
205 return this.getNextNorthSouthVisualPositionFrom (pos, b, a, direction, biasRet);
206 case 5:
207 return this.getNextNorthSouthVisualPositionFrom (pos, b, a, direction, biasRet);
208 case 3:
209 return this.getNextEastWestVisualPositionFrom (pos, b, a, direction, biasRet);
210 case 7:
211 return this.getNextEastWestVisualPositionFrom (pos, b, a, direction, biasRet);
212 default:
213 throw  new IllegalArgumentException ("Bad direction: " + direction);
214 }
215 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
216 Clazz.defineMethod (c$, "getViewIndex", 
217 function (pos, b) {
218 if (b === javax.swing.text.Position.Bias.Backward) {
219 pos -= 1;
220 }if ((pos >= this.getStartOffset ()) && (pos < this.getEndOffset ())) {
221 return this.getViewIndexAtPosition (pos);
222 }return -1;
223 }, "~N,javax.swing.text.Position.Bias");
224 Clazz.defineMethod (c$, "getViewAtPosition", 
225 function (pos, a) {
226 var index = this.getViewIndexAtPosition (pos);
227 if ((index >= 0) && (index < this.getViewCount ())) {
228 var v = this.getView (index);
229 if (a != null) {
230 this.childAllocation (index, a);
231 }return v;
232 }return null;
233 }, "~N,java.awt.Rectangle");
234 Clazz.defineMethod (c$, "getViewIndexAtPosition", 
235 function (pos) {
236 var elem = this.getElement ();
237 return elem.getElementIndex (pos);
238 }, "~N");
239 Clazz.defineMethod (c$, "getInsideAllocation", 
240 function (a) {
241 if (a != null) {
242 var alloc;
243 if (Clazz.instanceOf (a, java.awt.Rectangle)) {
244 alloc = a;
245 } else {
246 alloc = a.getBounds ();
247 }this.childAlloc.setBounds (alloc);
248 this.childAlloc.x += this.getLeftInset ();
249 this.childAlloc.y += this.getTopInset ();
250 this.childAlloc.width -= this.getLeftInset () + this.getRightInset ();
251 this.childAlloc.height -= this.getTopInset () + this.getBottomInset ();
252 return this.childAlloc;
253 }return null;
254 }, "java.awt.Shape");
255 Clazz.defineMethod (c$, "setParagraphInsets", 
256 function (attr) {
257 this.top = Clazz.floatToShort (javax.swing.text.StyleConstants.getSpaceAbove (attr));
258 this.left = Clazz.floatToShort (javax.swing.text.StyleConstants.getLeftIndent (attr));
259 this.bottom = Clazz.floatToShort (javax.swing.text.StyleConstants.getSpaceBelow (attr));
260 this.right = Clazz.floatToShort (javax.swing.text.StyleConstants.getRightIndent (attr));
261 }, "javax.swing.text.AttributeSet");
262 Clazz.defineMethod (c$, "setInsets", 
263 function (top, left, bottom, right) {
264 this.top = top;
265 this.left = left;
266 this.right = right;
267 this.bottom = bottom;
268 }, "~N,~N,~N,~N");
269 Clazz.defineMethod (c$, "getLeftInset", 
270 function () {
271 return this.left;
272 });
273 Clazz.defineMethod (c$, "getRightInset", 
274 function () {
275 return this.right;
276 });
277 Clazz.defineMethod (c$, "getTopInset", 
278 function () {
279 return this.top;
280 });
281 Clazz.defineMethod (c$, "getBottomInset", 
282 function () {
283 return this.bottom;
284 });
285 Clazz.defineMethod (c$, "getNextNorthSouthVisualPositionFrom", 
286 function (pos, b, a, direction, biasRet) {
287 return javax.swing.text.Utilities.getNextVisualPositionFrom (this, pos, b, a, direction, biasRet);
288 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
289 Clazz.defineMethod (c$, "getNextEastWestVisualPositionFrom", 
290 function (pos, b, a, direction, biasRet) {
291 return javax.swing.text.Utilities.getNextVisualPositionFrom (this, pos, b, a, direction, biasRet);
292 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
293 Clazz.defineMethod (c$, "flipEastAndWestAtEnds", 
294 function (position, bias) {
295 return false;
296 }, "~N,javax.swing.text.Position.Bias");
297 c$.ZERO = c$.prototype.ZERO =  new Array (0);
298 });