7a25c402e236e3179674e405cd6ad6bc5bac202d
[jalviewjs.git] / site / swingjs / j2s / javax / swing / text / View.js
1 Clazz.declarePackage ("javax.swing.text");\r
2 Clazz.load (["javax.swing.SwingConstants"], "javax.swing.text.View", ["java.lang.IllegalArgumentException", "java.awt.Rectangle", "javax.swing.event.DocumentEvent", "javax.swing.text.Position", "$.Utilities"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.parent = null;\r
5 this.elem = null;\r
6 Clazz.instantialize (this, arguments);\r
7 }, javax.swing.text, "View", null, javax.swing.SwingConstants);\r
8 Clazz.makeConstructor (c$, \r
9 function (elem) {\r
10 this.elem = elem;\r
11 }, "javax.swing.text.Element");\r
12 Clazz.defineMethod (c$, "getParent", \r
13 function () {\r
14 return this.parent;\r
15 });\r
16 Clazz.defineMethod (c$, "isVisible", \r
17 function () {\r
18 return true;\r
19 });\r
20 Clazz.defineMethod (c$, "getMinimumSpan", \r
21 function (axis) {\r
22 var w = this.getResizeWeight (axis);\r
23 if (w == 0) {\r
24 return this.getPreferredSpan (axis);\r
25 }return 0;\r
26 }, "~N");\r
27 Clazz.defineMethod (c$, "getMaximumSpan", \r
28 function (axis) {\r
29 var w = this.getResizeWeight (axis);\r
30 if (w == 0) {\r
31 return this.getPreferredSpan (axis);\r
32 }return 2147483647;\r
33 }, "~N");\r
34 Clazz.defineMethod (c$, "preferenceChanged", \r
35 function (child, width, height) {\r
36 var parent = this.getParent ();\r
37 if (parent != null) {\r
38 parent.preferenceChanged (this, width, height);\r
39 }}, "javax.swing.text.View,~B,~B");\r
40 Clazz.defineMethod (c$, "getAlignment", \r
41 function (axis) {\r
42 return 0.5;\r
43 }, "~N");\r
44 Clazz.defineMethod (c$, "setParent", \r
45 function (parent) {\r
46 if (parent == null) {\r
47 for (var i = 0; i < this.getViewCount (); i++) {\r
48 if (this.getView (i).getParent () === this) {\r
49 this.getView (i).setParent (null);\r
50 }}\r
51 }this.parent = parent;\r
52 }, "javax.swing.text.View");\r
53 Clazz.defineMethod (c$, "getViewCount", \r
54 function () {\r
55 return 0;\r
56 });\r
57 Clazz.defineMethod (c$, "getView", \r
58 function (n) {\r
59 return null;\r
60 }, "~N");\r
61 Clazz.defineMethod (c$, "removeAll", \r
62 function () {\r
63 this.replace (0, this.getViewCount (), null);\r
64 });\r
65 Clazz.defineMethod (c$, "remove", \r
66 function (i) {\r
67 this.replace (i, 1, null);\r
68 }, "~N");\r
69 Clazz.defineMethod (c$, "insert", \r
70 function (offs, v) {\r
71 var one =  new Array (1);\r
72 one[0] = v;\r
73 this.replace (offs, 0, one);\r
74 }, "~N,javax.swing.text.View");\r
75 Clazz.defineMethod (c$, "append", \r
76 function (v) {\r
77 var one =  new Array (1);\r
78 one[0] = v;\r
79 this.replace (this.getViewCount (), 0, one);\r
80 }, "javax.swing.text.View");\r
81 Clazz.defineMethod (c$, "replace", \r
82 function (offset, length, views) {\r
83 }, "~N,~N,~A");\r
84 Clazz.defineMethod (c$, "getViewIndex", \r
85 function (pos, b) {\r
86 return -1;\r
87 }, "~N,javax.swing.text.Position.Bias");\r
88 Clazz.defineMethod (c$, "getChildAllocation", \r
89 function (index, a) {\r
90 return null;\r
91 }, "~N,java.awt.Shape");\r
92 Clazz.defineMethod (c$, "getNextVisualPositionFrom", \r
93 function (pos, b, a, direction, biasRet) {\r
94 biasRet[0] = javax.swing.text.Position.Bias.Forward;\r
95 switch (direction) {\r
96 case 1:\r
97 case 5:\r
98 {\r
99 if (pos == -1) {\r
100 pos = (direction == 1) ? Math.max (0, this.getEndOffset () - 1) : this.getStartOffset ();\r
101 break;\r
102 }var target = this.getContainer ();\r
103 var c = (target != null) ? target.getCaret () : null;\r
104 var mcp;\r
105 if (c != null) {\r
106 mcp = c.getMagicCaretPosition ();\r
107 } else {\r
108 mcp = null;\r
109 }var x;\r
110 if (mcp == null) {\r
111 var loc = target.modelToView (pos);\r
112 x = (loc == null) ? 0 : loc.x;\r
113 } else {\r
114 x = mcp.x;\r
115 }if (direction == 1) {\r
116 pos = javax.swing.text.Utilities.getPositionAbove (target, pos, x);\r
117 } else {\r
118 pos = javax.swing.text.Utilities.getPositionBelow (target, pos, x);\r
119 }}break;\r
120 case 7:\r
121 if (pos == -1) {\r
122 pos = Math.max (0, this.getEndOffset () - 1);\r
123 } else {\r
124 pos = Math.max (0, pos - 1);\r
125 }break;\r
126 case 3:\r
127 if (pos == -1) {\r
128 pos = this.getStartOffset ();\r
129 } else {\r
130 pos = Math.min (pos + 1, this.getDocument ().getLength ());\r
131 }break;\r
132 default:\r
133 throw  new IllegalArgumentException ("Bad direction: " + direction);\r
134 }\r
135 return pos;\r
136 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");\r
137 Clazz.defineMethod (c$, "modelToView", \r
138 function (p0, b0, p1, b1, a) {\r
139 var s0 = this.modelToView (p0, a, b0);\r
140 var s1;\r
141 if (p1 == this.getEndOffset ()) {\r
142 try {\r
143 s1 = this.modelToView (p1, a, b1);\r
144 } catch (ble) {\r
145 if (Clazz.exceptionOf (ble, javax.swing.text.BadLocationException)) {\r
146 s1 = null;\r
147 } else {\r
148 throw ble;\r
149 }\r
150 }\r
151 if (s1 == null) {\r
152 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();\r
153 s1 =  new java.awt.Rectangle (alloc.x + alloc.width - 1, alloc.y, 1, alloc.height);\r
154 }} else {\r
155 s1 = this.modelToView (p1, a, b1);\r
156 }var r0 = s0.getBounds ();\r
157 var r1 = (Clazz.instanceOf (s1, java.awt.Rectangle)) ? s1 : s1.getBounds ();\r
158 if (r0.y != r1.y) {\r
159 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();\r
160 r0.x = alloc.x;\r
161 r0.width = alloc.width;\r
162 }r0.add (r1);\r
163 return r0;\r
164 }, "~N,javax.swing.text.Position.Bias,~N,javax.swing.text.Position.Bias,java.awt.Shape");\r
165 Clazz.defineMethod (c$, "insertUpdate", \r
166 function (e, a, f) {\r
167 if (this.getViewCount () > 0) {\r
168 var elem = this.getElement ();\r
169 var ec = e.getChange (elem);\r
170 if (ec != null) {\r
171 if (!this.updateChildren (ec, e, f)) {\r
172 ec = null;\r
173 }}this.forwardUpdate (ec, e, a, f);\r
174 this.updateLayout (ec, e, a);\r
175 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");\r
176 Clazz.defineMethod (c$, "removeUpdate", \r
177 function (e, a, f) {\r
178 if (this.getViewCount () > 0) {\r
179 var elem = this.getElement ();\r
180 var ec = e.getChange (elem);\r
181 if (ec != null) {\r
182 if (!this.updateChildren (ec, e, f)) {\r
183 ec = null;\r
184 }}this.forwardUpdate (ec, e, a, f);\r
185 this.updateLayout (ec, e, a);\r
186 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");\r
187 Clazz.defineMethod (c$, "changedUpdate", \r
188 function (e, a, f) {\r
189 if (this.getViewCount () > 0) {\r
190 var elem = this.getElement ();\r
191 var ec = e.getChange (elem);\r
192 if (ec != null) {\r
193 if (!this.updateChildren (ec, e, f)) {\r
194 ec = null;\r
195 }}this.forwardUpdate (ec, e, a, f);\r
196 this.updateLayout (ec, e, a);\r
197 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");\r
198 Clazz.defineMethod (c$, "getDocument", \r
199 function () {\r
200 return this.elem.getDocument ();\r
201 });\r
202 Clazz.defineMethod (c$, "getStartOffset", \r
203 function () {\r
204 return this.elem.getStartOffset ();\r
205 });\r
206 Clazz.defineMethod (c$, "getEndOffset", \r
207 function () {\r
208 return this.elem.getEndOffset ();\r
209 });\r
210 Clazz.defineMethod (c$, "getElement", \r
211 function () {\r
212 return this.elem;\r
213 });\r
214 Clazz.defineMethod (c$, "getGraphics", \r
215 function () {\r
216 var c = this.getContainer ();\r
217 return c.getGraphics ();\r
218 });\r
219 Clazz.defineMethod (c$, "getAttributes", \r
220 function () {\r
221 return this.elem.getAttributes ();\r
222 });\r
223 Clazz.defineMethod (c$, "breakView", \r
224 function (axis, offset, pos, len) {\r
225 return this;\r
226 }, "~N,~N,~N,~N");\r
227 Clazz.defineMethod (c$, "createFragment", \r
228 function (p0, p1) {\r
229 return this;\r
230 }, "~N,~N");\r
231 Clazz.defineMethod (c$, "getBreakWeight", \r
232 function (axis, pos, len) {\r
233 if (len > this.getPreferredSpan (axis)) {\r
234 return 1000;\r
235 }return 0;\r
236 }, "~N,~N,~N");\r
237 Clazz.defineMethod (c$, "getResizeWeight", \r
238 function (axis) {\r
239 return 0;\r
240 }, "~N");\r
241 Clazz.defineMethod (c$, "setSize", \r
242 function (width, height) {\r
243 }, "~N,~N");\r
244 Clazz.defineMethod (c$, "getContainer", \r
245 function () {\r
246 var v = this.getParent ();\r
247 return (v != null) ? v.getContainer () : null;\r
248 });\r
249 Clazz.defineMethod (c$, "getViewFactory", \r
250 function () {\r
251 var v = this.getParent ();\r
252 return (v != null) ? v.getViewFactory () : null;\r
253 });\r
254 Clazz.defineMethod (c$, "getToolTipText", \r
255 function (x, y, allocation) {\r
256 var viewIndex = this.getViewIndex (x, y, allocation);\r
257 if (viewIndex >= 0) {\r
258 allocation = this.getChildAllocation (viewIndex, allocation);\r
259 var rect = (Clazz.instanceOf (allocation, java.awt.Rectangle)) ? allocation : allocation.getBounds ();\r
260 if (rect.contains (x, y)) {\r
261 return this.getView (viewIndex).getToolTipText (x, y, allocation);\r
262 }}return null;\r
263 }, "~N,~N,java.awt.Shape");\r
264 Clazz.defineMethod (c$, "getViewIndex", \r
265 function (x, y, allocation) {\r
266 for (var counter = this.getViewCount () - 1; counter >= 0; counter--) {\r
267 var childAllocation = this.getChildAllocation (counter, allocation);\r
268 if (childAllocation != null) {\r
269 var rect = (Clazz.instanceOf (childAllocation, java.awt.Rectangle)) ? childAllocation : childAllocation.getBounds ();\r
270 if (rect.contains (x, y)) {\r
271 return counter;\r
272 }}}\r
273 return -1;\r
274 }, "~N,~N,java.awt.Shape");\r
275 Clazz.defineMethod (c$, "updateChildren", \r
276 function (ec, e, f) {\r
277 var removedElems = ec.getChildrenRemoved ();\r
278 var addedElems = ec.getChildrenAdded ();\r
279 var added = null;\r
280 if (addedElems != null) {\r
281 added =  new Array (addedElems.length);\r
282 for (var i = 0; i < addedElems.length; i++) {\r
283 added[i] = f.create (addedElems[i]);\r
284 }\r
285 }var nremoved = 0;\r
286 var index = ec.getIndex ();\r
287 if (removedElems != null) {\r
288 nremoved = removedElems.length;\r
289 }this.replace (index, nremoved, added);\r
290 return true;\r
291 }, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,javax.swing.text.ViewFactory");\r
292 Clazz.defineMethod (c$, "forwardUpdate", \r
293 function (ec, e, a, f) {\r
294 var elem = this.getElement ();\r
295 var pos = e.getOffset ();\r
296 var index0 = this.getViewIndex (pos, javax.swing.text.Position.Bias.Forward);\r
297 if (index0 == -1 && e.getType () === javax.swing.event.DocumentEvent.EventType.REMOVE && pos >= this.getEndOffset ()) {\r
298 index0 = this.getViewCount () - 1;\r
299 }var index1 = index0;\r
300 var v = (index0 >= 0) ? this.getView (index0) : null;\r
301 if (v != null) {\r
302 if ((v.getStartOffset () == pos) && (pos > 0)) {\r
303 index0 = Math.max (index0 - 1, 0);\r
304 }}if (e.getType () !== javax.swing.event.DocumentEvent.EventType.REMOVE) {\r
305 index1 = this.getViewIndex (pos + e.getLength (), javax.swing.text.Position.Bias.Forward);\r
306 if (index1 < 0) {\r
307 index1 = this.getViewCount () - 1;\r
308 }}var hole0 = index1 + 1;\r
309 var hole1 = hole0;\r
310 var addedElems = (ec != null) ? ec.getChildrenAdded () : null;\r
311 if ((addedElems != null) && (addedElems.length > 0)) {\r
312 hole0 = ec.getIndex ();\r
313 hole1 = hole0 + addedElems.length - 1;\r
314 }index0 = Math.max (index0, 0);\r
315 for (var i = index0; i <= index1; i++) {\r
316 if (!((i >= hole0) && (i <= hole1))) {\r
317 v = this.getView (i);\r
318 if (v != null) {\r
319 var childAlloc = this.getChildAllocation (i, a);\r
320 this.forwardUpdateToView (v, e, childAlloc, f);\r
321 }}}\r
322 }, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");\r
323 Clazz.defineMethod (c$, "forwardUpdateToView", \r
324 function (v, e, a, f) {\r
325 var type = e.getType ();\r
326 if (type === javax.swing.event.DocumentEvent.EventType.INSERT) {\r
327 v.insertUpdate (e, a, f);\r
328 } else if (type === javax.swing.event.DocumentEvent.EventType.REMOVE) {\r
329 v.removeUpdate (e, a, f);\r
330 } else {\r
331 v.changedUpdate (e, a, f);\r
332 }}, "javax.swing.text.View,javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");\r
333 Clazz.defineMethod (c$, "updateLayout", \r
334 function (ec, e, a) {\r
335 if ((ec != null) && (a != null)) {\r
336 this.preferenceChanged (null, true, true);\r
337 var host = this.getContainer ();\r
338 if (host != null) {\r
339 host.repaint ();\r
340 }}}, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,java.awt.Shape");\r
341 Clazz.defineMethod (c$, "modelToView", \r
342 function (pos, a) {\r
343 return this.modelToView (pos, a, javax.swing.text.Position.Bias.Forward);\r
344 }, "~N,java.awt.Shape");\r
345 Clazz.defineMethod (c$, "viewToModel", \r
346 function (x, y, a) {\r
347 javax.swing.text.View.sharedBiasReturn[0] = javax.swing.text.Position.Bias.Forward;\r
348 return this.viewToModel (x, y, a, javax.swing.text.View.sharedBiasReturn);\r
349 }, "~N,~N,java.awt.Shape");\r
350 Clazz.defineStatics (c$,\r
351 "BadBreakWeight", 0,\r
352 "GoodBreakWeight", 1000,\r
353 "ExcellentBreakWeight", 2000,\r
354 "ForcedBreakWeight", 3000,\r
355 "X_AXIS", 0,\r
356 "Y_AXIS", 1);\r
357 c$.sharedBiasReturn = c$.prototype.sharedBiasReturn =  new Array (1);\r
358 });\r