1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.text.BoxView", "$.FlowView", "$.TabExpander"], "javax.swing.text.ParagraphView", ["java.lang.Boolean", "$.IllegalArgumentException", "java.util.Arrays", "java.awt.Rectangle", "java.awt.font.TextAttribute", "javax.swing.text.AbstractDocument", "javax.swing.text.FlowView.FlowStrategy", "javax.swing.text.GlyphView", "$.Position", "$.Segment", "$.StateInvariantError", "$.StyleConstants", "$.TabableView"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.justification = 0;
6 this.firstLineIndent = 0;
8 if (!Clazz.isClassDefined ("javax.swing.text.ParagraphView.Row")) {
9 javax.swing.text.ParagraphView.$ParagraphView$Row$ ();
11 Clazz.instantialize (this, arguments);
12 }, javax.swing.text, "ParagraphView", javax.swing.text.FlowView, javax.swing.text.TabExpander);
13 Clazz.makeConstructor (c$,
15 Clazz.superConstructor (this, javax.swing.text.ParagraphView, [elem, 1]);
16 this.setPropertiesFromAttributes ();
17 var doc = elem.getDocument ();
18 var i18nFlag = doc.getProperty ("i18n");
19 if ((i18nFlag != null) && i18nFlag.equals (Boolean.TRUE)) {
21 if (javax.swing.text.ParagraphView.i18nStrategy == null) {
22 var classname = "javax.swing.text.TextLayoutStrategy";
23 var loader = this.getClass ().getClassLoader ();
25 javax.swing.text.ParagraphView.i18nStrategy = loader.loadClass (classname);
27 javax.swing.text.ParagraphView.i18nStrategy = Clazz._4Name (classname);
28 }}var o = javax.swing.text.ParagraphView.i18nStrategy.newInstance ();
29 if (Clazz.instanceOf (o, javax.swing.text.FlowView.FlowStrategy)) {
32 throw new javax.swing.text.StateInvariantError ("ParagraphView: Can't create i18n strategy: " + e.getMessage ());
34 }}, "javax.swing.text.Element");
35 Clazz.defineMethod (c$, "setJustification",
37 this.justification = j;
39 Clazz.defineMethod (c$, "setLineSpacing",
41 this.lineSpacing = ls;
43 Clazz.defineMethod (c$, "setFirstLineIndent",
45 this.firstLineIndent = Clazz.floatToInt (fi);
47 Clazz.defineMethod (c$, "setPropertiesFromAttributes",
49 var attr = this.getAttributes ();
51 this.setParagraphInsets (attr);
52 var a = attr.getAttribute (javax.swing.text.StyleConstants.Alignment);
55 var doc = this.getElement ().getDocument ();
56 var o = doc.getProperty (java.awt.font.TextAttribute.RUN_DIRECTION);
57 if ((o != null) && o.equals (java.awt.font.TextAttribute.RUN_DIRECTION_RTL)) {
62 alignment = a.intValue ();
63 }this.setJustification (alignment);
64 this.setLineSpacing (javax.swing.text.StyleConstants.getLineSpacing (attr));
65 this.setFirstLineIndent (javax.swing.text.StyleConstants.getFirstLineIndent (attr));
67 Clazz.defineMethod (c$, "getLayoutViewCount",
69 return this.layoutPool.getViewCount ();
71 Clazz.defineMethod (c$, "getLayoutView",
73 return this.layoutPool.getView (index);
75 Clazz.defineMethod (c$, "adjustRow",
76 function (r, desiredSpan, x) {
77 }, "javax.swing.text.ParagraphView.Row,~N,~N");
78 Clazz.overrideMethod (c$, "getNextNorthSouthVisualPositionFrom",
79 function (pos, b, a, direction, biasRet) {
82 vIndex = (direction == 1) ? this.getViewCount () - 1 : 0;
84 if (b === javax.swing.text.Position.Bias.Backward && pos > 0) {
85 vIndex = this.getViewIndexAtPosition (pos - 1);
87 vIndex = this.getViewIndexAtPosition (pos);
88 }if (direction == 1) {
92 } else if (++vIndex >= this.getViewCount ()) {
94 }}var text = this.getContainer ();
95 var c = text.getCaret ();
97 magicPoint = (c != null) ? c.getMagicCaretPosition () : null;
99 if (magicPoint == null) {
102 posBounds = text.getUI ().modelToView (text, pos, b);
104 if (Clazz.exceptionOf (exc, javax.swing.text.BadLocationException)) {
110 if (posBounds == null) {
113 x = posBounds.getBounds ().x;
116 }return this.getClosestPositionTo (pos, b, a, direction, biasRet, vIndex, x);
117 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A");
118 Clazz.defineMethod (c$, "getClosestPositionTo",
119 function (pos, b, a, direction, biasRet, rowIndex, x) {
120 var text = this.getContainer ();
121 var doc = this.getDocument ();
122 var aDoc = (Clazz.instanceOf (doc, javax.swing.text.AbstractDocument)) ? doc : null;
123 var row = this.getView (rowIndex);
125 biasRet[0] = javax.swing.text.Position.Bias.Forward;
126 for (var vc = 0, numViews = row.getViewCount (); vc < numViews; vc++) {
127 var v = row.getView (vc);
128 var start = v.getStartOffset ();
129 var ltr = (aDoc != null) ? aDoc.isLeftToRight (start, start + 1) : true;
132 for (var end = v.getEndOffset (); lastPos < end; lastPos++) {
133 var xx = text.modelToView (lastPos).getBounds ().x;
135 while (++lastPos < end && text.modelToView (lastPos).getBounds ().x == xx) {
141 for (lastPos = v.getEndOffset () - 1; lastPos >= start; lastPos--) {
142 var xx = text.modelToView (lastPos).getBounds ().x;
144 while (--lastPos >= start && text.modelToView (lastPos).getBounds ().x == xx) {
151 return this.getStartOffset ();
153 }, "~N,javax.swing.text.Position.Bias,java.awt.Shape,~N,~A,~N,~N");
154 Clazz.overrideMethod (c$, "flipEastAndWestAtEnds",
155 function (position, bias) {
156 var doc = this.getDocument ();
157 if (Clazz.instanceOf (doc, javax.swing.text.AbstractDocument) && !(doc).isLeftToRight (this.getStartOffset (), this.getStartOffset () + 1)) {
160 }, "~N,javax.swing.text.Position.Bias");
161 Clazz.overrideMethod (c$, "getFlowSpan",
163 var child = this.getView (index);
165 if (Clazz.instanceOf (child, javax.swing.text.ParagraphView.Row)) {
167 adjust = row.getLeftInset () + row.getRightInset ();
168 }return (this.layoutSpan == 2147483647) ? this.layoutSpan : (this.layoutSpan - adjust);
170 Clazz.overrideMethod (c$, "getFlowStart",
172 var child = this.getView (index);
174 if (Clazz.instanceOf (child, javax.swing.text.ParagraphView.Row)) {
176 adjust = row.getLeftInset ();
177 }return this.tabBase + adjust;
179 Clazz.overrideMethod (c$, "createRow",
181 return Clazz.innerTypeInstance (javax.swing.text.ParagraphView.Row, this, null, this.getElement ());
183 Clazz.overrideMethod (c$, "nextTabStop",
184 function (x, tabOffset) {
185 if (this.justification != 0) return x + 10.0;
187 var tabs = this.getTabSet ();
189 return (this.tabBase + ((Clazz.doubleToInt (Clazz.floatToInt (x) / 72) + 1) * 72));
190 }var tab = tabs.getTabAfter (x + .01);
192 return this.tabBase + x + 5.0;
193 }var alignment = tab.getAlignment ();
198 return this.tabBase + tab.getPosition ();
200 return this.tabBase + tab.getPosition ();
203 offset = this.findOffsetToCharactersInString (javax.swing.text.ParagraphView.tabChars, tabOffset + 1);
206 offset = this.findOffsetToCharactersInString (javax.swing.text.ParagraphView.tabDecimalChars, tabOffset + 1);
210 offset = this.getEndOffset ();
211 }var charsSize = this.getPartialSize (tabOffset + 1, offset);
215 return this.tabBase + Math.max (x, tab.getPosition () - charsSize);
217 return this.tabBase + Math.max (x, tab.getPosition () - charsSize / 2.0);
221 Clazz.defineMethod (c$, "getTabSet",
223 return javax.swing.text.StyleConstants.getTabSet (this.getElement ().getAttributes ());
225 Clazz.defineMethod (c$, "getPartialSize",
226 function (startOffset, endOffset) {
229 var numViews = this.getViewCount ();
233 viewIndex = this.getElement ().getElementIndex (startOffset);
234 numViews = this.layoutPool.getViewCount ();
235 while (startOffset < endOffset && viewIndex < numViews) {
236 view = this.layoutPool.getView (viewIndex++);
237 viewEnd = view.getEndOffset ();
238 tempEnd = Math.min (endOffset, viewEnd);
239 if (Clazz.instanceOf (view, javax.swing.text.TabableView)) size += (view).getPartialSpan (startOffset, tempEnd);
240 else if (startOffset == view.getStartOffset () && tempEnd == view.getEndOffset ()) size += view.getPreferredSpan (0);
242 startOffset = viewEnd;
246 Clazz.defineMethod (c$, "findOffsetToCharactersInString",
247 function (string, start) {
248 var stringLength = string.length;
249 var end = this.getEndOffset ();
250 var seg = new javax.swing.text.Segment ();
252 this.getDocument ().getText (start, end - start, seg);
254 if (Clazz.exceptionOf (ble, javax.swing.text.BadLocationException)) {
260 for (var counter = seg.offset, maxCounter = seg.offset + seg.count; counter < maxCounter; counter++) {
261 var currentChar = seg.array[counter];
262 for (var subCounter = 0; subCounter < stringLength; subCounter++) {
263 if (currentChar == string[subCounter]) return counter - seg.offset + start;
268 Clazz.defineMethod (c$, "getTabBase",
272 Clazz.defineMethod (c$, "paint",
274 var alloc = (Clazz.instanceOf (a, java.awt.Rectangle)) ? a : a.getBounds ();
275 this.tabBase = alloc.x + this.getLeftInset ();
276 Clazz.superCall (this, javax.swing.text.ParagraphView, "paint", [g, a]);
277 if (this.firstLineIndent < 0) {
278 var sh = this.getChildAllocation (0, a);
279 if ((sh != null) && sh.intersects (alloc)) {
280 var x = alloc.x + this.getLeftInset () + this.firstLineIndent;
281 var y = alloc.y + this.getTopInset ();
282 var clip = g.getClipBounds ();
283 this.tempRect.x = x + this.getOffset (0, 0);
284 this.tempRect.y = y + this.getOffset (1, 0);
285 this.tempRect.width = this.getSpan (0, 0) - this.firstLineIndent;
286 this.tempRect.height = this.getSpan (1, 0);
287 if (this.tempRect.intersects (clip)) {
288 this.tempRect.x = this.tempRect.x - this.firstLineIndent;
289 this.paintChild (g, this.tempRect, 0);
290 }}}}, "java.awt.Graphics,java.awt.Shape");
291 Clazz.defineMethod (c$, "getAlignment",
296 if (this.getViewCount () != 0) {
297 var paragraphSpan = Clazz.floatToInt (this.getPreferredSpan (1));
298 var v = this.getView (0);
299 var rowSpan = Clazz.floatToInt (v.getPreferredSpan (1));
300 a = (paragraphSpan != 0) ? ((Clazz.doubleToInt (rowSpan / 2))) / paragraphSpan : 0;
305 throw new IllegalArgumentException ("Invalid axis: " + axis);
308 Clazz.defineMethod (c$, "breakView",
309 function (axis, len, a) {
312 var alloc = a.getBounds ();
313 this.setSize (alloc.width, alloc.height);
316 }, "~N,~N,java.awt.Shape");
317 Clazz.defineMethod (c$, "getBreakWeight",
318 function (axis, len) {
323 Clazz.defineMethod (c$, "changedUpdate",
324 function (changes, a, f) {
325 this.setPropertiesFromAttributes ();
326 this.layoutChanged (0);
327 this.layoutChanged (1);
328 Clazz.superCall (this, javax.swing.text.ParagraphView, "changedUpdate", [changes, a, f]);
329 }, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
330 c$.$ParagraphView$Row$ = function () {
332 c$ = Clazz.decorateAsClass (function () {
333 Clazz.prepareCallback (this, arguments);
334 this.justificationData = null;
335 Clazz.instantialize (this, arguments);
336 }, javax.swing.text.ParagraphView, "Row", javax.swing.text.BoxView);
337 Clazz.makeConstructor (c$,
339 Clazz.superConstructor (this, javax.swing.text.ParagraphView.Row, [a, 0]);
340 }, "javax.swing.text.Element");
341 Clazz.overrideMethod (c$, "loadChildren",
343 }, "javax.swing.text.ViewFactory");
344 Clazz.defineMethod (c$, "getAttributes",
346 var a = this.getParent ();
347 return (a != null) ? a.getAttributes () : null;
349 Clazz.defineMethod (c$, "getAlignment",
352 switch (this.b$["javax.swing.text.ParagraphView"].justification) {
361 if (this.isJustifiableDocument ()) {
365 }return Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "getAlignment", [a]);
367 Clazz.defineMethod (c$, "modelToView",
369 var d = b.getBounds ();
370 var e = this.getViewAtPosition (a, d);
371 if ((e != null) && (!e.getElement ().isLeaf ())) {
372 return Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "modelToView", [a, b, c]);
376 var h = Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "modelToView", [a, b, c]);
381 }, "~N,java.awt.Shape,javax.swing.text.Position.Bias");
382 Clazz.defineMethod (c$, "getStartOffset",
385 var b = this.getViewCount ();
386 for (var c = 0; c < b; c++) {
387 var d = this.getView (c);
388 a = Math.min (a, d.getStartOffset ());
392 Clazz.defineMethod (c$, "getEndOffset",
395 var b = this.getViewCount ();
396 for (var c = 0; c < b; c++) {
397 var d = this.getView (c);
398 a = Math.max (a, d.getEndOffset ());
402 Clazz.overrideMethod (c$, "layoutMinorAxis",
403 function (a, b, c, d) {
404 this.baselineLayout (a, b, c, d);
406 Clazz.overrideMethod (c$, "calculateMinorAxisRequirements",
408 return this.baselineRequirements (a, b);
409 }, "~N,javax.swing.SizeRequirements");
410 Clazz.defineMethod (c$, "isLastRow",
413 return ((a = this.getParent ()) == null || this === a.getView (a.getViewCount () - 1));
415 Clazz.defineMethod (c$, "isBrokenRow",
418 var b = this.getViewCount ();
420 var c = this.getView (b - 1);
421 if (c.getBreakWeight (0, 0, 0) >= 3000) {
425 Clazz.defineMethod (c$, "isJustifiableDocument",
427 return (!Boolean.TRUE.equals (this.getDocument ().getProperty ("i18n")));
429 Clazz.defineMethod (c$, "isJustifyEnabled",
431 var a = (this.b$["javax.swing.text.ParagraphView"].justification == 3);
432 a = a && this.isJustifiableDocument ();
433 a = a && !this.isLastRow ();
434 a = a && !this.isBrokenRow ();
437 Clazz.defineMethod (c$, "calculateMajorAxisRequirements",
439 var c = this.justificationData;
440 this.justificationData = null;
441 var d = Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "calculateMajorAxisRequirements", [a, b]);
442 if (this.isJustifyEnabled ()) {
443 this.justificationData = c;
445 }, "~N,javax.swing.SizeRequirements");
446 Clazz.defineMethod (c$, "layoutMajorAxis",
447 function (a, b, c, d) {
448 var e = this.justificationData;
449 this.justificationData = null;
450 Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "layoutMajorAxis", [a, b, c, d]);
451 if (!this.isJustifyEnabled ()) {
454 for (var span, $span = 0, $$span = d; $span < $$span.length && ((span = $$span[$span]) || true); $span++) {
463 var k = this.getStartOffset ();
464 var l = this.getEndOffset ();
465 var m = Clazz.newIntArray (l - k, 0);
466 java.util.Arrays.fill (m, 0);
467 for (var n = this.getViewCount () - 1; n >= 0; n--) {
468 var o = this.getView (n);
469 if (Clazz.instanceOf (o, javax.swing.text.GlyphView)) {
470 var p = (o).getJustificationInfo (k);
471 var q = o.getStartOffset ();
473 for (var s = 0; s < p.spaceMap.length (); s++) {
474 if (p.spaceMap.get (s)) {
479 g += p.trailingSpaces;
481 j += p.trailingSpaces;
482 }}if (p.start >= 0) {
485 }if (p.end >= 0 && i < 0) {
487 }g += p.contentSpaces;
495 var p = (g > 0) ? Clazz.doubleToInt (o / g) : 0;
497 for (var r = h - k, s = o - p * g; s > 0; s -= m[r], r++) {
500 if (p > 0 || q >= 0) {
501 this.justificationData = (e != null) ? e : Clazz.newIntArray (4, 0);
502 this.justificationData[0] = p;
503 this.justificationData[1] = q;
504 this.justificationData[2] = h - k;
505 this.justificationData[3] = i - k;
506 Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "layoutMajorAxis", [a, b, c, d]);
508 Clazz.defineMethod (c$, "getMaximumSpan",
511 if (0 == a && this.isJustifyEnabled ()) {
514 b = Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "getMaximumSpan", [a]);
517 Clazz.overrideMethod (c$, "getViewIndexAtPosition",
519 if (a < this.getStartOffset () || a >= this.getEndOffset ()) return -1;
520 for (var b = this.getViewCount () - 1; b >= 0; b--) {
521 var c = this.getView (b);
522 if (a >= c.getStartOffset () && a < c.getEndOffset ()) {
527 Clazz.defineMethod (c$, "getLeftInset",
531 if ((a = this.getParent ()) != null) {
532 if (this === a.getView (0)) {
533 b = this.b$["javax.swing.text.ParagraphView"].firstLineIndent;
534 }}return (Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "getLeftInset", []) + b);
536 Clazz.defineMethod (c$, "getBottomInset",
538 return Clazz.floatToShort (Clazz.superCall (this, javax.swing.text.ParagraphView.Row, "getBottomInset", []) + ((this.minorRequest != null) ? this.minorRequest.preferred : 0) * this.b$["javax.swing.text.ParagraphView"].lineSpacing);
540 Clazz.defineStatics (c$,
542 "SPACE_ADDON_LEFTOVER_END", 1,
543 "START_JUSTIFIABLE", 2,
544 "END_JUSTIFIABLE", 3);
547 Clazz.defineStatics (c$,
548 "i18nStrategy", null,
550 "tabDecimalChars", null);
552 javax.swing.text.ParagraphView.tabChars = Clazz.newCharArray (1, '\0');
553 javax.swing.text.ParagraphView.tabChars[0] = '\t';
554 javax.swing.text.ParagraphView.tabDecimalChars = Clazz.newCharArray (2, '\0');
555 javax.swing.text.ParagraphView.tabDecimalChars[0] = '\t';
556 javax.swing.text.ParagraphView.tabDecimalChars[1] = '.';