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