1 Clazz.declarePackage ("javax.swing.text");
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 () {
3 c$ = Clazz.decorateAsClass (function () {
6 Clazz.instantialize (this, arguments);
7 }, javax.swing.text, "View", null, javax.swing.SwingConstants);
8 Clazz.makeConstructor (c$,
11 }, "javax.swing.text.Element");
12 Clazz.defineMethod (c$, "getParent",
16 Clazz.defineMethod (c$, "isVisible",
20 Clazz.defineMethod (c$, "getMinimumSpan",
22 var w = this.getResizeWeight (axis);
24 return this.getPreferredSpan (axis);
27 Clazz.defineMethod (c$, "getMaximumSpan",
29 var w = this.getResizeWeight (axis);
31 return this.getPreferredSpan (axis);
34 Clazz.defineMethod (c$, "preferenceChanged",
35 function (child, width, height) {
36 var parent = this.getParent ();
38 parent.preferenceChanged (this, width, height);
39 }}, "javax.swing.text.View,~B,~B");
40 Clazz.defineMethod (c$, "getAlignment",
44 Clazz.defineMethod (c$, "setParent",
47 for (var i = 0; i < this.getViewCount (); i++) {
48 if (this.getView (i).getParent () === this) {
49 this.getView (i).setParent (null);
51 }this.parent = parent;
52 }, "javax.swing.text.View");
53 Clazz.defineMethod (c$, "getViewCount",
57 Clazz.defineMethod (c$, "getView",
61 Clazz.defineMethod (c$, "removeAll",
63 this.replace (0, this.getViewCount (), null);
65 Clazz.defineMethod (c$, "remove",
67 this.replace (i, 1, null);
69 Clazz.defineMethod (c$, "insert",
71 var one = new Array (1);
73 this.replace (offs, 0, one);
74 }, "~N,javax.swing.text.View");
75 Clazz.defineMethod (c$, "append",
77 var one = new Array (1);
79 this.replace (this.getViewCount (), 0, one);
80 }, "javax.swing.text.View");
81 Clazz.defineMethod (c$, "replace",
82 function (offset, length, views) {
84 Clazz.defineMethod (c$, "getViewIndex",
87 }, "~N,javax.swing.text.Position.Bias");
88 Clazz.defineMethod (c$, "getChildAllocation",
91 }, "~N,java.awt.Shape");
92 Clazz.defineMethod (c$, "getNextVisualPositionFrom",
93 function (pos, b, a, direction, biasRet) {
94 biasRet[0] = javax.swing.text.Position.Bias.Forward;
100 pos = (direction == 1) ? Math.max (0, this.getEndOffset () - 1) : this.getStartOffset ();
102 }var target = this.getContainer ();
103 var c = (target != null) ? target.getCaret () : null;
106 mcp = c.getMagicCaretPosition ();
111 var loc = target.modelToView (pos);
112 x = (loc == null) ? 0 : loc.x;
115 }if (direction == 1) {
116 pos = javax.swing.text.Utilities.getPositionAbove (target, pos, x);
118 pos = javax.swing.text.Utilities.getPositionBelow (target, pos, x);
122 pos = Math.max (0, this.getEndOffset () - 1);
124 pos = Math.max (0, pos - 1);
128 pos = this.getStartOffset ();
130 pos = Math.min (pos + 1, this.getDocument ().getLength ());
133 throw new IllegalArgumentException ("Bad direction: " + direction);
136 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
137 Clazz.defineMethod (c$, "modelToView",
138 function (p0, b0, p1, b1, a) {
139 var s0 = this.modelToView (p0, a, b0);
141 if (p1 == this.getEndOffset ()) {
143 s1 = this.modelToView (p1, a, b1);
145 if (Clazz.exceptionOf (ble, javax.swing.text.BadLocationException)) {
152 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();
153 s1 = new java.awt.Rectangle (alloc.x + alloc.width - 1, alloc.y, 1, alloc.height);
155 s1 = this.modelToView (p1, a, b1);
156 }var r0 = s0.getBounds ();
157 var r1 = (Clazz.instanceOf (s1, java.awt.Rectangle)) ? s1 : s1.getBounds ();
159 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();
161 r0.width = alloc.width;
164 }, "~N,javax.swing.text.Position.Bias,~N,javax.swing.text.Position.Bias,java.awt.Shape");
165 Clazz.defineMethod (c$, "insertUpdate",
167 if (this.getViewCount () > 0) {
168 var elem = this.getElement ();
169 var ec = e.getChange (elem);
171 if (!this.updateChildren (ec, e, f)) {
173 }}this.forwardUpdate (ec, e, a, f);
174 this.updateLayout (ec, e, a);
175 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
176 Clazz.defineMethod (c$, "removeUpdate",
178 if (this.getViewCount () > 0) {
179 var elem = this.getElement ();
180 var ec = e.getChange (elem);
182 if (!this.updateChildren (ec, e, f)) {
184 }}this.forwardUpdate (ec, e, a, f);
185 this.updateLayout (ec, e, a);
186 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
187 Clazz.defineMethod (c$, "changedUpdate",
189 if (this.getViewCount () > 0) {
190 var elem = this.getElement ();
191 var ec = e.getChange (elem);
193 if (!this.updateChildren (ec, e, f)) {
195 }}this.forwardUpdate (ec, e, a, f);
196 this.updateLayout (ec, e, a);
197 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
198 Clazz.defineMethod (c$, "getDocument",
200 return this.elem.getDocument ();
202 Clazz.defineMethod (c$, "getStartOffset",
204 return this.elem.getStartOffset ();
206 Clazz.defineMethod (c$, "getEndOffset",
208 return this.elem.getEndOffset ();
210 Clazz.defineMethod (c$, "getElement",
214 Clazz.defineMethod (c$, "getGraphics",
216 var c = this.getContainer ();
217 return c.getGraphics ();
219 Clazz.defineMethod (c$, "getAttributes",
221 return this.elem.getAttributes ();
223 Clazz.defineMethod (c$, "breakView",
224 function (axis, offset, pos, len) {
227 Clazz.defineMethod (c$, "createFragment",
231 Clazz.defineMethod (c$, "getBreakWeight",
232 function (axis, pos, len) {
233 if (len > this.getPreferredSpan (axis)) {
237 Clazz.defineMethod (c$, "getResizeWeight",
241 Clazz.defineMethod (c$, "setSize",
242 function (width, height) {
244 Clazz.defineMethod (c$, "getContainer",
246 var v = this.getParent ();
247 return (v != null) ? v.getContainer () : null;
249 Clazz.defineMethod (c$, "getViewFactory",
251 var v = this.getParent ();
252 return (v != null) ? v.getViewFactory () : null;
254 Clazz.defineMethod (c$, "getToolTipText",
255 function (x, y, allocation) {
256 var viewIndex = this.getViewIndex (x, y, allocation);
257 if (viewIndex >= 0) {
258 allocation = this.getChildAllocation (viewIndex, allocation);
259 var rect = (Clazz.instanceOf (allocation, java.awt.Rectangle)) ? allocation : allocation.getBounds ();
260 if (rect.contains (x, y)) {
261 return this.getView (viewIndex).getToolTipText (x, y, allocation);
263 }, "~N,~N,java.awt.Shape");
264 Clazz.defineMethod (c$, "getViewIndex",
265 function (x, y, allocation) {
266 for (var counter = this.getViewCount () - 1; counter >= 0; counter--) {
267 var childAllocation = this.getChildAllocation (counter, allocation);
268 if (childAllocation != null) {
269 var rect = (Clazz.instanceOf (childAllocation, java.awt.Rectangle)) ? childAllocation : childAllocation.getBounds ();
270 if (rect.contains (x, y)) {
274 }, "~N,~N,java.awt.Shape");
275 Clazz.defineMethod (c$, "updateChildren",
276 function (ec, e, f) {
277 var removedElems = ec.getChildrenRemoved ();
278 var addedElems = ec.getChildrenAdded ();
280 if (addedElems != null) {
281 added = new Array (addedElems.length);
282 for (var i = 0; i < addedElems.length; i++) {
283 added[i] = f.create (addedElems[i]);
286 var index = ec.getIndex ();
287 if (removedElems != null) {
288 nremoved = removedElems.length;
289 }this.replace (index, nremoved, added);
291 }, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,javax.swing.text.ViewFactory");
292 Clazz.defineMethod (c$, "forwardUpdate",
293 function (ec, e, a, f) {
294 var elem = this.getElement ();
295 var pos = e.getOffset ();
296 var index0 = this.getViewIndex (pos, javax.swing.text.Position.Bias.Forward);
297 if (index0 == -1 && e.getType () === javax.swing.event.DocumentEvent.EventType.REMOVE && pos >= this.getEndOffset ()) {
298 index0 = this.getViewCount () - 1;
299 }var index1 = index0;
300 var v = (index0 >= 0) ? this.getView (index0) : null;
302 if ((v.getStartOffset () == pos) && (pos > 0)) {
303 index0 = Math.max (index0 - 1, 0);
304 }}if (e.getType () !== javax.swing.event.DocumentEvent.EventType.REMOVE) {
305 index1 = this.getViewIndex (pos + e.getLength (), javax.swing.text.Position.Bias.Forward);
307 index1 = this.getViewCount () - 1;
308 }}var hole0 = index1 + 1;
310 var addedElems = (ec != null) ? ec.getChildrenAdded () : null;
311 if ((addedElems != null) && (addedElems.length > 0)) {
312 hole0 = ec.getIndex ();
313 hole1 = hole0 + addedElems.length - 1;
314 }index0 = Math.max (index0, 0);
315 for (var i = index0; i <= index1; i++) {
316 if (!((i >= hole0) && (i <= hole1))) {
317 v = this.getView (i);
319 var childAlloc = this.getChildAllocation (i, a);
320 this.forwardUpdateToView (v, e, childAlloc, f);
322 }, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
323 Clazz.defineMethod (c$, "forwardUpdateToView",
324 function (v, e, a, f) {
325 var type = e.getType ();
326 if (type === javax.swing.event.DocumentEvent.EventType.INSERT) {
327 v.insertUpdate (e, a, f);
328 } else if (type === javax.swing.event.DocumentEvent.EventType.REMOVE) {
329 v.removeUpdate (e, a, f);
331 v.changedUpdate (e, a, f);
332 }}, "javax.swing.text.View,javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
333 Clazz.defineMethod (c$, "updateLayout",
334 function (ec, e, a) {
335 if ((ec != null) && (a != null)) {
336 this.preferenceChanged (null, true, true);
337 var host = this.getContainer ();
340 }}}, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,java.awt.Shape");
341 Clazz.defineMethod (c$, "modelToView",
343 return this.modelToView (pos, a, javax.swing.text.Position.Bias.Forward);
344 }, "~N,java.awt.Shape");
345 Clazz.defineMethod (c$, "viewToModel",
347 javax.swing.text.View.sharedBiasReturn[0] = javax.swing.text.Position.Bias.Forward;
348 return this.viewToModel (x, y, a, javax.swing.text.View.sharedBiasReturn);
349 }, "~N,~N,java.awt.Shape");
350 Clazz.defineStatics (c$,
352 "GoodBreakWeight", 1000,
353 "ExcellentBreakWeight", 2000,
354 "ForcedBreakWeight", 3000,
357 c$.sharedBiasReturn = c$.prototype.sharedBiasReturn = new Array (1);