1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.text.BoxView", "$.TabExpander", "$.View"], "javax.swing.text.WrappedPlainView", ["java.lang.IllegalArgumentException", "javax.swing.text.BadLocationException", "$.LayeredHighlighter", "$.Position", "$.Segment", "$.SegmentCache", "$.StateInvariantError", "$.Utilities"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 this.lineBuffer = null;
6 this.widthChanging = false;
12 this.unselected = null;
14 if (!Clazz.isClassDefined ("javax.swing.text.WrappedPlainView.WrappedLine")) {
15 javax.swing.text.WrappedPlainView.$WrappedPlainView$WrappedLine$ ();
17 Clazz.instantialize (this, arguments);
18 }, javax.swing.text, "WrappedPlainView", javax.swing.text.BoxView, javax.swing.text.TabExpander);
19 Clazz.makeConstructor (c$,
21 this.construct (elem, false);
22 }, "javax.swing.text.Element");
23 Clazz.makeConstructor (c$,
24 function (elem, wordWrap) {
25 Clazz.superConstructor (this, javax.swing.text.WrappedPlainView, [elem, 1]);
26 this.wordWrap = wordWrap;
27 }, "javax.swing.text.Element,~B");
28 Clazz.defineMethod (c$, "getTabSize",
30 var i = this.getDocument ().getProperty ("tabSize");
31 var size = (i != null) ? i.intValue () : 8;
34 Clazz.defineMethod (c$, "drawLine",
35 function (p0, p1, g, x, y) {
36 var lineMap = this.getElement ();
37 var line = lineMap.getElement (lineMap.getElementIndex (p0));
41 this.drawText (line, p0, p1, g, x, y);
43 var idx = line.getElementIndex (p0);
44 var lastIdx = line.getElementIndex (p1);
45 for (; idx <= lastIdx; idx++) {
46 elem = line.getElement (idx);
47 var start = Math.max (elem.getStartOffset (), p0);
48 var end = Math.min (elem.getEndOffset (), p1);
49 x = this.drawText (elem, start, end, g, x, y);
52 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
53 throw new javax.swing.text.StateInvariantError ("Can't render: " + p0 + "," + p1);
58 }, "~N,~N,java.awt.Graphics,~N,~N");
59 Clazz.defineMethod (c$, "drawText",
60 function (elem, p0, p1, g, x, y) {
62 }, "javax.swing.text.Element,~N,~N,java.awt.Graphics,~N,~N");
63 Clazz.defineMethod (c$, "getLineBuffer",
65 if (this.lineBuffer == null) {
66 this.lineBuffer = new javax.swing.text.Segment ();
67 }return this.lineBuffer;
69 Clazz.defineMethod (c$, "calculateBreakPosition",
72 var segment = javax.swing.text.SegmentCache.getSharedSegment ();
73 this.loadText (segment, p0, p1);
74 var currentWidth = this.getWidth ();
75 if (currentWidth == 2147483647) {
76 currentWidth = Clazz.floatToInt (this.getDefaultSpan (0));
78 p = p0 + javax.swing.text.Utilities.getBreakLocation (segment, this.metrics, this.tabBase, this.tabBase + currentWidth, this, p0);
80 p = p0 + javax.swing.text.Utilities.getTabbedTextOffset (segment, this.metrics, this.tabBase, this.tabBase + currentWidth, this, p0, false);
81 }javax.swing.text.SegmentCache.releaseSharedSegment (segment);
84 Clazz.overrideMethod (c$, "loadChildren",
86 var e = this.getElement ();
87 var n = e.getElementCount ();
89 var added = new Array (n);
90 for (var i = 0; i < n; i++) {
91 added[i] = Clazz.innerTypeInstance (javax.swing.text.WrappedPlainView.WrappedLine, this, null, e.getElement (i));
93 this.replace (0, 0, added);
94 }}, "javax.swing.text.ViewFactory");
95 Clazz.defineMethod (c$, "updateChildren",
97 var elem = this.getElement ();
98 var ec = e.getChange (elem);
100 var removedElems = ec.getChildrenRemoved ();
101 var addedElems = ec.getChildrenAdded ();
102 var added = new Array (addedElems.length);
103 for (var i = 0; i < addedElems.length; i++) {
104 added[i] = Clazz.innerTypeInstance (javax.swing.text.WrappedPlainView.WrappedLine, this, null, addedElems[i]);
106 this.replace (ec.getIndex (), removedElems.length, added);
108 this.preferenceChanged (null, true, true);
109 this.getContainer ().repaint ();
110 }}this.updateMetrics ();
111 }, "javax.swing.event.DocumentEvent,java.awt.Shape");
112 Clazz.defineMethod (c$, "loadText",
113 function (segment, p0, p1) {
115 var doc = this.getDocument ();
116 doc.getText (p0, p1 - p0, segment);
118 if (Clazz.exceptionOf (bl, javax.swing.text.BadLocationException)) {
119 throw new javax.swing.text.StateInvariantError ("Can't get line text");
124 }, "javax.swing.text.Segment,~N,~N");
125 Clazz.defineMethod (c$, "updateMetrics",
127 var host = this.getContainer ();
128 var f = host.getFont ();
129 this.metrics = host.getFontMetrics (f);
130 this.tabSize = this.getTabSize () * this.metrics.charWidth ('m');
132 Clazz.defineMethod (c$, "getDefaultSpan",
134 var host = this.getContainer ();
137 parent = host.getParent ();
140 var defaultWidth = 80 * this.metrics.charWidth ('M');
142 if (parent != null) {
143 parentWidth = parent.getWidth ();
144 }if (defaultWidth > parentWidth) {
146 }return defaultWidth;
148 var defaultHeight = 24 * this.metrics.getHeight ();
149 var parentHeight = 0;
150 if (parent != null) {
151 parentHeight = parent.getHeight ();
152 }if (defaultHeight > parentHeight) {
154 }return defaultHeight;
156 throw new IllegalArgumentException ("Invalid axis: " + axis);
159 Clazz.overrideMethod (c$, "nextTabStop",
160 function (x, tabOffset) {
161 if (this.tabSize == 0) return x;
162 var ntabs = Clazz.doubleToInt ((Clazz.floatToInt (x) - this.tabBase) / this.tabSize);
163 return this.tabBase + ((ntabs + 1) * this.tabSize);
165 Clazz.defineMethod (c$, "paint",
168 this.tabBase = alloc.x;
169 var host = this.getContainer ();
170 this.sel0 = host.getSelectionStart ();
171 this.sel1 = host.getSelectionEnd ();
172 this.unselected = (host.isEnabled ()) ? host.getForeground () : host.getDisabledTextColor ();
173 var c = host.getCaret ();
174 this.selected = c.isSelectionVisible () && host.getHighlighter () != null ? host.getSelectedTextColor () : this.unselected;
175 g.setFont (host.getFont ());
176 Clazz.superCall (this, javax.swing.text.WrappedPlainView, "paint", [g, a]);
177 }, "java.awt.Graphics,java.awt.Shape");
178 Clazz.defineMethod (c$, "setSize",
179 function (width, height) {
180 this.updateMetrics ();
181 if (Clazz.floatToInt (width) != this.getWidth ()) {
182 this.preferenceChanged (null, true, true);
183 this.widthChanging = true;
184 }Clazz.superCall (this, javax.swing.text.WrappedPlainView, "setSize", [width, height]);
185 this.widthChanging = false;
187 Clazz.defineMethod (c$, "getPreferredSpan",
189 this.updateMetrics ();
190 return Clazz.superCall (this, javax.swing.text.WrappedPlainView, "getPreferredSpan", [axis]);
192 Clazz.defineMethod (c$, "getMinimumSpan",
194 this.updateMetrics ();
195 return Clazz.superCall (this, javax.swing.text.WrappedPlainView, "getMinimumSpan", [axis]);
197 Clazz.defineMethod (c$, "getMaximumSpan",
199 this.updateMetrics ();
200 return Clazz.superCall (this, javax.swing.text.WrappedPlainView, "getMaximumSpan", [axis]);
202 Clazz.defineMethod (c$, "insertUpdate",
204 this.updateChildren (e, a);
205 var alloc = ((a != null) && this.isAllocationValid ()) ? this.getInsideAllocation (a) : null;
206 var pos = e.getOffset ();
207 var v = this.getViewAtPosition (pos, alloc);
209 v.insertUpdate (e, alloc, f);
210 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
211 Clazz.defineMethod (c$, "removeUpdate",
213 this.updateChildren (e, a);
214 var alloc = ((a != null) && this.isAllocationValid ()) ? this.getInsideAllocation (a) : null;
215 var pos = e.getOffset ();
216 var v = this.getViewAtPosition (pos, alloc);
218 v.removeUpdate (e, alloc, f);
219 }}, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
220 Clazz.overrideMethod (c$, "changedUpdate",
222 this.updateChildren (e, a);
223 }, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
224 c$.$WrappedPlainView$WrappedLine$ = function () {
226 c$ = Clazz.decorateAsClass (function () {
227 Clazz.prepareCallback (this, arguments);
229 Clazz.instantialize (this, arguments);
230 }, javax.swing.text.WrappedPlainView, "WrappedLine", javax.swing.text.View);
231 Clazz.makeConstructor (c$,
233 Clazz.superConstructor (this, javax.swing.text.WrappedPlainView.WrappedLine, [a]);
235 }, "javax.swing.text.Element");
236 Clazz.overrideMethod (c$, "getPreferredSpan",
240 var b = this.b$["javax.swing.text.WrappedPlainView"].getWidth ();
241 if (b == 2147483647) {
242 b = this.b$["javax.swing.text.WrappedPlainView"].getDefaultSpan (a);
245 if (this.getDocument ().getLength () > 0) {
246 if ((this.lineCount < 0) || this.b$["javax.swing.text.WrappedPlainView"].widthChanging) {
247 this.breakLines (this.getStartOffset ());
248 }return this.lineCount * this.b$["javax.swing.text.WrappedPlainView"].metrics.getHeight ();
250 return this.b$["javax.swing.text.WrappedPlainView"].getDefaultSpan (a);
252 throw new IllegalArgumentException ("Invalid axis: " + a);
255 Clazz.overrideMethod (c$, "paint",
258 var d = c.y + this.b$["javax.swing.text.WrappedPlainView"].metrics.getAscent ();
260 var f = this.getContainer ();
261 var g = f.getHighlighter ();
262 var h = (Clazz.instanceOf (g, javax.swing.text.LayeredHighlighter)) ? g : null;
263 var i = this.getStartOffset ();
264 var j = this.getEndOffset ();
266 var l = this.getLineEnds ();
267 for (var m = 0; m < this.lineCount; m++) {
268 var n = (l == null) ? j : i + l[m];
270 var o = (n == j) ? (n - 1) : n;
271 h.paintLayeredHighlights (a, k, o, b, f, this);
272 }this.b$["javax.swing.text.WrappedPlainView"].drawLine (k, n, a, e, d);
274 d += this.b$["javax.swing.text.WrappedPlainView"].metrics.getHeight ();
276 }, "java.awt.Graphics,java.awt.Shape");
277 Clazz.defineMethod (c$, "modelToView",
279 var d = b.getBounds ();
280 d.height = this.b$["javax.swing.text.WrappedPlainView"].metrics.getHeight ();
282 var e = this.getStartOffset ();
283 if (a < e || a > this.getEndOffset ()) {
284 throw new javax.swing.text.BadLocationException ("Position out of range", a);
285 }var f = (c === javax.swing.text.Position.Bias.Forward) ? a : Math.max (e, a - 1);
287 var h = this.getLineEnds ();
289 g = this.findLine (f - e);
292 }d.y += d.height * g;
294 var i = javax.swing.text.SegmentCache.getSharedSegment ();
295 this.b$["javax.swing.text.WrappedPlainView"].loadText (i, e, a);
296 d.x += javax.swing.text.Utilities.getTabbedTextWidth (i, this.b$["javax.swing.text.WrappedPlainView"].metrics, d.x, this.b$["javax.swing.text.WrappedPlainView"], e);
297 javax.swing.text.SegmentCache.releaseSharedSegment (i);
299 }, "~N,java.awt.Shape,javax.swing.text.Position.Bias");
300 Clazz.defineMethod (c$, "viewToModel",
301 function (a, b, c, d) {
302 d[0] = javax.swing.text.Position.Bias.Forward;
304 var f = Clazz.floatToInt (a);
305 var g = Clazz.floatToInt (b);
307 return this.getStartOffset ();
308 } else if (g > e.y + e.height) {
309 return this.getEndOffset () - 1;
311 e.height = this.b$["javax.swing.text.WrappedPlainView"].metrics.getHeight ();
312 var h = (e.height > 0 ? Clazz.doubleToInt ((g - e.y) / e.height) : this.lineCount - 1);
313 if (h >= this.lineCount) {
314 return this.getEndOffset () - 1;
316 var i = this.getStartOffset ();
318 if (this.lineCount == 1) {
319 j = this.getEndOffset ();
321 var k = this.getLineEnds ();
327 } else if (f > e.x + e.width) {
330 var k = javax.swing.text.SegmentCache.getSharedSegment ();
331 this.b$["javax.swing.text.WrappedPlainView"].loadText (k, i, j);
332 var l = javax.swing.text.Utilities.getTabbedTextOffset (k, this.b$["javax.swing.text.WrappedPlainView"].metrics, e.x, f, this.b$["javax.swing.text.WrappedPlainView"], i);
333 javax.swing.text.SegmentCache.releaseSharedSegment (k);
334 return Math.min (i + l, j - 1);
335 }}}}, "~N,~N,java.awt.Shape,~A");
336 Clazz.overrideMethod (c$, "insertUpdate",
339 }, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
340 Clazz.overrideMethod (c$, "removeUpdate",
343 }, "javax.swing.event.DocumentEvent,java.awt.Shape,javax.swing.text.ViewFactory");
344 Clazz.defineMethod (c$, "update",
346 var c = this.lineCount;
347 this.breakLines (a.getOffset ());
348 if (c != this.lineCount) {
349 this.b$["javax.swing.text.WrappedPlainView"].preferenceChanged (this, false, true);
350 this.getContainer ().repaint ();
351 } else if (b != null) {
352 var d = this.getContainer ();
354 d.repaint (e.x, e.y, e.width, e.height);
355 }}, "javax.swing.event.DocumentEvent,java.awt.Shape");
356 Clazz.defineMethod (c$, "getLineEnds",
360 Clazz.defineMethod (c$, "breakLines",
365 Clazz.defineMethod (c$, "findLine",
369 Clazz.defineMethod (c$, "findLine",
370 function (a, b, c, d) {
374 var e = Clazz.doubleToInt ((d + c) / 2);
375 return (b < a[e]) ? this.findLine (a, b, c, e) : this.findLine (a, b, e, d);