1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.text.CompositeView"], "javax.swing.text.BoxView", ["java.lang.IllegalArgumentException", "java.awt.Rectangle", "javax.swing.SizeRequirements", "javax.swing.text.Position"], function () {
3 c$ = Clazz.decorateAsClass (function () {
7 this.majorReqValid = false;
8 this.minorReqValid = false;
9 this.majorRequest = null;
10 this.minorRequest = null;
11 this.majorAllocValid = false;
12 this.majorOffsets = null;
13 this.majorSpans = null;
14 this.minorAllocValid = false;
15 this.minorOffsets = null;
16 this.minorSpans = null;
18 Clazz.instantialize (this, arguments);
19 }, javax.swing.text, "BoxView", javax.swing.text.CompositeView);
20 Clazz.makeConstructor (c$,
21 function (elem, axis) {
22 Clazz.superConstructor (this, javax.swing.text.BoxView, [elem]);
23 this.tempRect = new java.awt.Rectangle ();
24 this.majorAxis = axis;
25 this.majorOffsets = Clazz.newIntArray (0, 0);
26 this.majorSpans = Clazz.newIntArray (0, 0);
27 this.majorReqValid = false;
28 this.majorAllocValid = false;
29 this.minorOffsets = Clazz.newIntArray (0, 0);
30 this.minorSpans = Clazz.newIntArray (0, 0);
31 this.minorReqValid = false;
32 this.minorAllocValid = false;
33 }, "javax.swing.text.Element,~N");
34 Clazz.defineMethod (c$, "getAxis",
36 return this.majorAxis;
38 Clazz.defineMethod (c$, "setAxis",
40 var axisChanged = (axis != this.majorAxis);
41 this.majorAxis = axis;
43 this.preferenceChanged (null, true, true);
45 Clazz.defineMethod (c$, "layoutChanged",
47 if (axis == this.majorAxis) {
48 this.majorAllocValid = false;
50 this.minorAllocValid = false;
52 Clazz.defineMethod (c$, "isLayoutValid",
54 if (axis == this.majorAxis) {
55 return this.majorAllocValid;
57 return this.minorAllocValid;
59 Clazz.defineMethod (c$, "paintChild",
60 function (g, alloc, index) {
61 var child = this.getView (index);
62 child.paint (g, alloc);
63 }, "java.awt.Graphics,java.awt.Rectangle,~N");
64 Clazz.defineMethod (c$, "replace",
65 function (index, length, elems) {
66 Clazz.superCall (this, javax.swing.text.BoxView, "replace", [index, length, elems]);
67 var nInserted = (elems != null) ? elems.length : 0;
68 this.majorOffsets = this.updateLayoutArray (this.majorOffsets, index, nInserted);
69 this.majorSpans = this.updateLayoutArray (this.majorSpans, index, nInserted);
70 this.majorReqValid = false;
71 this.majorAllocValid = false;
72 this.minorOffsets = this.updateLayoutArray (this.minorOffsets, index, nInserted);
73 this.minorSpans = this.updateLayoutArray (this.minorSpans, index, nInserted);
74 this.minorReqValid = false;
75 this.minorAllocValid = false;
77 Clazz.defineMethod (c$, "updateLayoutArray",
78 function (oldArray, offset, nInserted) {
79 var n = this.getViewCount ();
80 var newArray = Clazz.newIntArray (n, 0);
81 System.arraycopy (oldArray, 0, newArray, 0, offset);
82 System.arraycopy (oldArray, offset, newArray, offset + nInserted, n - nInserted - offset);
85 Clazz.defineMethod (c$, "forwardUpdate",
86 function (ec, e, a, f) {
87 var wasValid = this.isLayoutValid (this.majorAxis);
88 Clazz.superCall (this, javax.swing.text.BoxView, "forwardUpdate", [ec, e, a, f]);
89 if (wasValid && (!this.isLayoutValid (this.majorAxis))) {
90 var c = this.getContainer ();
91 if ((a != null) && (c != null)) {
92 var pos = e.getOffset ();
93 var index = this.getViewIndexAtPosition (pos);
94 var alloc = this.getInsideAllocation (a);
95 if (this.majorAxis == 0) {
96 alloc.x += this.majorOffsets[index];
97 alloc.width -= this.majorOffsets[index];
99 alloc.y += this.minorOffsets[index];
100 alloc.height -= this.minorOffsets[index];
101 }c.repaint (alloc.x, alloc.y, alloc.width, alloc.height);
102 }}}, "javax.swing.event.DocumentEvent.ElementChange,javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
103 Clazz.defineMethod (c$, "preferenceChanged",
104 function (child, width, height) {
105 var majorChanged = (this.majorAxis == 0) ? width : height;
106 var minorChanged = (this.majorAxis == 0) ? height : width;
108 this.majorReqValid = false;
109 this.majorAllocValid = false;
111 this.minorReqValid = false;
112 this.minorAllocValid = false;
113 }Clazz.superCall (this, javax.swing.text.BoxView, "preferenceChanged", [child, width, height]);
114 }, "javax.swing.text.View,~B,~B");
115 Clazz.defineMethod (c$, "getResizeWeight",
117 this.checkRequests (axis);
118 if (axis == this.majorAxis) {
119 if ((this.majorRequest.preferred != this.majorRequest.minimum) || (this.majorRequest.preferred != this.majorRequest.maximum)) {
122 if ((this.minorRequest.preferred != this.minorRequest.minimum) || (this.minorRequest.preferred != this.minorRequest.maximum)) {
126 Clazz.defineMethod (c$, "setSpanOnAxis",
127 function (axis, span) {
128 if (axis == this.majorAxis) {
129 if (this.majorSpan != Clazz.floatToInt (span)) {
130 this.majorAllocValid = false;
131 }if (!this.majorAllocValid) {
132 this.majorSpan = Clazz.floatToInt (span);
133 this.checkRequests (this.majorAxis);
134 this.layoutMajorAxis (this.majorSpan, axis, this.majorOffsets, this.majorSpans);
135 this.majorAllocValid = true;
136 this.updateChildSizes ();
138 if ((Clazz.floatToInt (span)) != this.minorSpan) {
139 this.minorAllocValid = false;
140 }if (!this.minorAllocValid) {
141 this.minorSpan = Clazz.floatToInt (span);
142 this.checkRequests (axis);
143 this.layoutMinorAxis (this.minorSpan, axis, this.minorOffsets, this.minorSpans);
144 this.minorAllocValid = true;
145 this.updateChildSizes ();
147 Clazz.defineMethod (c$, "updateChildSizes",
149 var n = this.getViewCount ();
150 if (this.majorAxis == 0) {
151 for (var i = 0; i < n; i++) {
152 var v = this.getView (i);
153 v.setSize (this.majorSpans[i], this.minorSpans[i]);
156 for (var i = 0; i < n; i++) {
157 var v = this.getView (i);
158 v.setSize (this.minorSpans[i], this.majorSpans[i]);
161 Clazz.defineMethod (c$, "getSpanOnAxis",
163 if (axis == this.majorAxis) {
164 return this.majorSpan;
166 return this.minorSpan;
168 Clazz.defineMethod (c$, "setSize",
169 function (width, height) {
170 this.layout (Math.max (0, Clazz.floatToInt (width - this.getLeftInset () - this.getRightInset ())), Math.max (0, Clazz.floatToInt (height - this.getTopInset () - this.getBottomInset ())));
172 Clazz.defineMethod (c$, "paint",
173 function (g, allocation) {
174 var alloc = (Clazz.instanceOf (allocation, java.awt.Rectangle)) ? allocation : allocation.getBounds ();
175 var n = this.getViewCount ();
176 var x = alloc.x + this.getLeftInset ();
177 var y = alloc.y + this.getTopInset ();
178 var clip = g.getClipBounds ();
179 for (var i = 0; i < n; i++) {
180 this.tempRect.x = x + this.getOffset (0, i);
181 this.tempRect.y = y + this.getOffset (1, i);
182 this.tempRect.width = this.getSpan (0, i);
183 this.tempRect.height = this.getSpan (1, i);
184 var trx0 = this.tempRect.x;
185 var trx1 = trx0 + this.tempRect.width;
186 var try0 = this.tempRect.y;
187 var try1 = try0 + this.tempRect.height;
189 var crx1 = crx0 + clip.width;
191 var cry1 = cry0 + clip.height;
192 if ((trx1 >= crx0) && (try1 >= cry0) && (crx1 >= trx0) && (cry1 >= try0)) {
193 this.paintChild (g, this.tempRect, i);
195 }, "java.awt.Graphics,java.awt.Shape");
196 Clazz.defineMethod (c$, "getChildAllocation",
197 function (index, a) {
199 var ca = Clazz.superCall (this, javax.swing.text.BoxView, "getChildAllocation", [index, a]);
200 if ((ca != null) && (!this.isAllocationValid ())) {
201 var r = (Clazz.instanceOf (ca, java.awt.Rectangle)) ? ca : ca.getBounds ();
202 if ((r.width == 0) && (r.height == 0)) {
206 }, "~N,java.awt.Shape");
207 Clazz.defineMethod (c$, "modelToView",
208 function (pos, a, b) {
209 if (!this.isAllocationValid ()) {
210 var alloc = a.getBounds ();
211 this.setSize (alloc.width, alloc.height);
212 }return Clazz.superCall (this, javax.swing.text.BoxView, "modelToView", [pos, a, b]);
213 }, "~N,java.awt.Shape,javax.swing.text.Position.Bias");
214 Clazz.defineMethod (c$, "viewToModel",
215 function (x, y, a, bias) {
216 if (!this.isAllocationValid ()) {
217 var alloc = a.getBounds ();
218 this.setSize (alloc.width, alloc.height);
219 }return Clazz.superCall (this, javax.swing.text.BoxView, "viewToModel", [x, y, a, bias]);
220 }, "~N,~N,java.awt.Shape,~A");
221 Clazz.defineMethod (c$, "getAlignment",
223 this.checkRequests (axis);
224 if (axis == this.majorAxis) {
225 return this.majorRequest.alignment;
227 return this.minorRequest.alignment;
229 Clazz.defineMethod (c$, "getPreferredSpan",
231 this.checkRequests (axis);
232 var marginSpan = (axis == 0) ? this.getLeftInset () + this.getRightInset () : this.getTopInset () + this.getBottomInset ();
233 if (axis == this.majorAxis) {
234 return (this.majorRequest.preferred) + marginSpan;
236 return (this.minorRequest.preferred) + marginSpan;
238 Clazz.defineMethod (c$, "getMinimumSpan",
240 this.checkRequests (axis);
241 var marginSpan = (axis == 0) ? this.getLeftInset () + this.getRightInset () : this.getTopInset () + this.getBottomInset ();
242 if (axis == this.majorAxis) {
243 return (this.majorRequest.minimum) + marginSpan;
245 return (this.minorRequest.minimum) + marginSpan;
247 Clazz.defineMethod (c$, "getMaximumSpan",
249 this.checkRequests (axis);
250 var marginSpan = (axis == 0) ? this.getLeftInset () + this.getRightInset () : this.getTopInset () + this.getBottomInset ();
251 if (axis == this.majorAxis) {
252 return (this.majorRequest.maximum) + marginSpan;
254 return (this.minorRequest.maximum) + marginSpan;
256 Clazz.defineMethod (c$, "isAllocationValid",
258 return (this.majorAllocValid && this.minorAllocValid);
260 Clazz.overrideMethod (c$, "isBefore",
261 function (x, y, innerAlloc) {
262 if (this.majorAxis == 0) {
263 return (x < innerAlloc.x);
265 return (y < innerAlloc.y);
266 }}, "~N,~N,java.awt.Rectangle");
267 Clazz.overrideMethod (c$, "isAfter",
268 function (x, y, innerAlloc) {
269 if (this.majorAxis == 0) {
270 return (x > (innerAlloc.width + innerAlloc.x));
272 return (y > (innerAlloc.height + innerAlloc.y));
273 }}, "~N,~N,java.awt.Rectangle");
274 Clazz.overrideMethod (c$, "getViewAtPoint",
275 function (x, y, alloc) {
276 var n = this.getViewCount ();
277 if (this.majorAxis == 0) {
278 if (x < (alloc.x + this.majorOffsets[0])) {
279 this.childAllocation (0, alloc);
280 return this.getView (0);
281 }for (var i = 0; i < n; i++) {
282 if (x < (alloc.x + this.majorOffsets[i])) {
283 this.childAllocation (i - 1, alloc);
284 return this.getView (i - 1);
286 this.childAllocation (n - 1, alloc);
287 return this.getView (n - 1);
289 if (y < (alloc.y + this.majorOffsets[0])) {
290 this.childAllocation (0, alloc);
291 return this.getView (0);
292 }for (var i = 0; i < n; i++) {
293 if (y < (alloc.y + this.majorOffsets[i])) {
294 this.childAllocation (i - 1, alloc);
295 return this.getView (i - 1);
297 this.childAllocation (n - 1, alloc);
298 return this.getView (n - 1);
299 }}, "~N,~N,java.awt.Rectangle");
300 Clazz.overrideMethod (c$, "childAllocation",
301 function (index, alloc) {
302 alloc.x += this.getOffset (0, index);
303 alloc.y += this.getOffset (1, index);
304 alloc.width = this.getSpan (0, index);
305 alloc.height = this.getSpan (1, index);
306 }, "~N,java.awt.Rectangle");
307 Clazz.defineMethod (c$, "layout",
308 function (width, height) {
309 this.setSpanOnAxis (0, width);
310 this.setSpanOnAxis (1, height);
312 Clazz.defineMethod (c$, "getWidth",
315 if (this.majorAxis == 0) {
316 span = this.majorSpan;
318 span = this.minorSpan;
319 }span += this.getLeftInset () - this.getRightInset ();
322 Clazz.defineMethod (c$, "getHeight",
325 if (this.majorAxis == 1) {
326 span = this.majorSpan;
328 span = this.minorSpan;
329 }span += this.getTopInset () - this.getBottomInset ();
332 Clazz.defineMethod (c$, "layoutMajorAxis",
333 function (targetSpan, axis, offsets, spans) {
335 var n = this.getViewCount ();
336 for (var i = 0; i < n; i++) {
337 var v = this.getView (i);
338 spans[i] = Clazz.floatToInt (v.getPreferredSpan (axis));
339 preferred += spans[i];
341 var desiredAdjustment = targetSpan - preferred;
342 var adjustmentFactor = 0.0;
344 if (desiredAdjustment != 0) {
346 diffs = Clazz.newIntArray (n, 0);
347 for (var i = 0; i < n; i++) {
348 var v = this.getView (i);
350 if (desiredAdjustment < 0) {
351 tmp = Clazz.floatToInt (v.getMinimumSpan (axis));
352 diffs[i] = spans[i] - tmp;
354 tmp = Clazz.floatToInt (v.getMaximumSpan (axis));
355 diffs[i] = tmp - spans[i];
358 var maximumAdjustment = Math.abs (totalSpan - preferred);
359 adjustmentFactor = desiredAdjustment / maximumAdjustment;
360 adjustmentFactor = Math.min (adjustmentFactor, 1.0);
361 adjustmentFactor = Math.max (adjustmentFactor, -1.0);
362 }var totalOffset = 0;
363 for (var i = 0; i < n; i++) {
364 offsets[i] = totalOffset;
365 if (desiredAdjustment != 0) {
366 var adjF = adjustmentFactor * diffs[i];
367 spans[i] += Math.round (adjF);
368 }totalOffset = Math.min (totalOffset + spans[i], 2147483647);
371 Clazz.defineMethod (c$, "layoutMinorAxis",
372 function (targetSpan, axis, offsets, spans) {
373 var n = this.getViewCount ();
374 for (var i = 0; i < n; i++) {
375 var v = this.getView (i);
376 var max = Clazz.floatToInt (v.getMaximumSpan (axis));
377 if (max < targetSpan) {
378 var align = v.getAlignment (axis);
379 offsets[i] = Clazz.floatToInt ((targetSpan - max) * align);
382 var min = Clazz.floatToInt (v.getMinimumSpan (axis));
384 spans[i] = Math.max (min, targetSpan);
387 Clazz.defineMethod (c$, "calculateMajorAxisRequirements",
392 var n = this.getViewCount ();
393 for (var i = 0; i < n; i++) {
394 var v = this.getView (i);
395 min += v.getMinimumSpan (axis);
396 pref += v.getPreferredSpan (axis);
397 max += v.getMaximumSpan (axis);
400 r = new javax.swing.SizeRequirements ();
402 r.minimum = Clazz.floatToInt (min);
403 r.preferred = Clazz.floatToInt (pref);
404 r.maximum = Clazz.floatToInt (max);
406 }, "~N,javax.swing.SizeRequirements");
407 Clazz.defineMethod (c$, "calculateMinorAxisRequirements",
411 var max = 2147483647;
412 var n = this.getViewCount ();
413 for (var i = 0; i < n; i++) {
414 var v = this.getView (i);
415 min = Math.max (Clazz.floatToInt (v.getMinimumSpan (axis)), min);
416 pref = Math.max (Clazz.floatToInt (v.getPreferredSpan (axis)), pref);
417 max = Math.max (Clazz.floatToInt (v.getMaximumSpan (axis)), max);
420 r = new javax.swing.SizeRequirements ();
426 }, "~N,javax.swing.SizeRequirements");
427 Clazz.defineMethod (c$, "checkRequests",
429 if ((axis != 0) && (axis != 1)) {
430 throw new IllegalArgumentException ("Invalid axis: " + axis);
431 }if (axis == this.majorAxis) {
432 if (!this.majorReqValid) {
433 this.majorRequest = this.calculateMajorAxisRequirements (axis, this.majorRequest);
434 this.majorReqValid = true;
435 }} else if (!this.minorReqValid) {
436 this.minorRequest = this.calculateMinorAxisRequirements (axis, this.minorRequest);
437 this.minorReqValid = true;
439 Clazz.defineMethod (c$, "baselineLayout",
440 function (targetSpan, axis, offsets, spans) {
441 var totalAscent = Clazz.floatToInt (targetSpan * this.getAlignment (axis));
442 var totalDescent = targetSpan - totalAscent;
443 var n = this.getViewCount ();
444 for (var i = 0; i < n; i++) {
445 var v = this.getView (i);
446 var align = v.getAlignment (axis);
448 if (v.getResizeWeight (axis) > 0) {
449 var minSpan = v.getMinimumSpan (axis);
450 var maxSpan = v.getMaximumSpan (axis);
452 viewSpan = Math.max (Math.min (maxSpan, totalDescent), minSpan);
453 } else if (align == 1.0) {
454 viewSpan = Math.max (Math.min (maxSpan, totalAscent), minSpan);
456 var fitSpan = Math.min (totalAscent / align, totalDescent / (1.0 - align));
457 viewSpan = Math.max (Math.min (maxSpan, fitSpan), minSpan);
459 viewSpan = v.getPreferredSpan (axis);
460 }offsets[i] = totalAscent - Clazz.floatToInt (viewSpan * align);
461 spans[i] = Clazz.floatToInt (viewSpan);
464 Clazz.defineMethod (c$, "baselineRequirements",
466 var totalAscent = new javax.swing.SizeRequirements ();
467 var totalDescent = new javax.swing.SizeRequirements ();
469 r = new javax.swing.SizeRequirements ();
471 var n = this.getViewCount ();
472 for (var i = 0; i < n; i++) {
473 var v = this.getView (i);
474 var align = v.getAlignment (axis);
478 span = v.getPreferredSpan (axis);
479 ascent = Clazz.floatToInt (align * span);
480 descent = Clazz.floatToInt (span - ascent);
481 totalAscent.preferred = Math.max (ascent, totalAscent.preferred);
482 totalDescent.preferred = Math.max (descent, totalDescent.preferred);
483 if (v.getResizeWeight (axis) > 0) {
484 span = v.getMinimumSpan (axis);
485 ascent = Clazz.floatToInt (align * span);
486 descent = Clazz.floatToInt (span - ascent);
487 totalAscent.minimum = Math.max (ascent, totalAscent.minimum);
488 totalDescent.minimum = Math.max (descent, totalDescent.minimum);
489 span = v.getMaximumSpan (axis);
490 ascent = Clazz.floatToInt (align * span);
491 descent = Clazz.floatToInt (span - ascent);
492 totalAscent.maximum = Math.max (ascent, totalAscent.maximum);
493 totalDescent.maximum = Math.max (descent, totalDescent.maximum);
495 totalAscent.minimum = Math.max (ascent, totalAscent.minimum);
496 totalDescent.minimum = Math.max (descent, totalDescent.minimum);
497 totalAscent.maximum = Math.max (ascent, totalAscent.maximum);
498 totalDescent.maximum = Math.max (descent, totalDescent.maximum);
500 r.preferred = Math.min (totalAscent.preferred + totalDescent.preferred, 2147483647);
501 if (r.preferred > 0) {
502 r.alignment = totalAscent.preferred / r.preferred;
503 }if (r.alignment == 0.0) {
504 r.minimum = totalDescent.minimum;
505 r.maximum = totalDescent.maximum;
506 } else if (r.alignment == 1.0) {
507 r.minimum = totalAscent.minimum;
508 r.maximum = totalAscent.maximum;
510 r.minimum = Math.round (Math.max (totalAscent.minimum / r.alignment, totalDescent.minimum / (1.0 - r.alignment)));
511 r.maximum = Math.round (Math.min (totalAscent.maximum / r.alignment, totalDescent.maximum / (1.0 - r.alignment)));
513 }, "~N,javax.swing.SizeRequirements");
514 Clazz.defineMethod (c$, "getOffset",
515 function (axis, childIndex) {
516 var offsets = (axis == this.majorAxis) ? this.majorOffsets : this.minorOffsets;
517 return offsets[childIndex];
519 Clazz.defineMethod (c$, "getSpan",
520 function (axis, childIndex) {
521 var spans = (axis == this.majorAxis) ? this.majorSpans : this.minorSpans;
522 return spans[childIndex];
524 Clazz.defineMethod (c$, "flipEastAndWestAtEnds",
525 function (position, bias) {
526 if (this.majorAxis == 1) {
527 var testPos = (bias === javax.swing.text.Position.Bias.Backward) ? Math.max (0, position - 1) : position;
528 var index = this.getViewIndexAtPosition (testPos);
530 var v = this.getView (index);
531 if (v != null && Clazz.instanceOf (v, javax.swing.text.CompositeView)) {
532 return (v).flipEastAndWestAtEnds (position, bias);
534 }, "~N,javax.swing.text.Position.Bias");