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