1 Clazz.declarePackage ("javax.swing.text");
\r
2 Clazz.load (null, "javax.swing.text.AbstractWriter", ["java.lang.Character", "javax.swing.text.ElementIterator", "$.Segment"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
6 this.indentLevel = 0;
\r
7 this.indentSpace = 2;
\r
9 this.maxLineLength = 100;
\r
10 this.currLength = 0;
\r
11 this.startOffset = 0;
\r
13 this.offsetIndent = 0;
\r
14 this.lineSeparator = null;
\r
15 this.canWrapLines = false;
\r
16 this.$isLineEmpty = false;
\r
17 this.indentChars = null;
\r
18 this.tempChars = null;
\r
19 this.newlineChars = null;
\r
20 this.segment = null;
\r
21 Clazz.instantialize (this, arguments);
\r
22 }, javax.swing.text, "AbstractWriter");
\r
23 Clazz.makeConstructor (c$,
\r
25 this.construct (w, doc, 0, doc.getLength ());
\r
26 }, "java.io.Writer,javax.swing.text.Document");
\r
27 Clazz.makeConstructor (c$,
\r
28 function (w, doc, pos, len) {
\r
30 this.it = new javax.swing.text.ElementIterator (doc.getDefaultRootElement ());
\r
32 this.startOffset = pos;
\r
33 this.endOffset = pos + len;
\r
34 var docNewline = doc.getProperty ("__EndOfLine__");
\r
35 if (Clazz.instanceOf (docNewline, String)) {
\r
36 this.setLineSeparator (docNewline);
\r
40 newline = System.getProperty ("line.separator");
\r
42 if (Clazz.exceptionOf (se, SecurityException)) {
\r
47 if (newline == null) {
\r
49 }this.setLineSeparator (newline);
\r
50 }this.canWrapLines = true;
\r
51 }, "java.io.Writer,javax.swing.text.Document,~N,~N");
\r
52 Clazz.makeConstructor (c$,
\r
53 function (w, root) {
\r
54 this.construct (w, root, 0, root.getEndOffset ());
\r
55 }, "java.io.Writer,javax.swing.text.Element");
\r
56 Clazz.makeConstructor (c$,
\r
57 function (w, root, pos, len) {
\r
58 this.doc = root.getDocument ();
\r
59 this.it = new javax.swing.text.ElementIterator (root);
\r
61 this.startOffset = pos;
\r
62 this.endOffset = pos + len;
\r
63 this.canWrapLines = true;
\r
64 }, "java.io.Writer,javax.swing.text.Element,~N,~N");
\r
65 Clazz.defineMethod (c$, "getStartOffset",
\r
67 return this.startOffset;
\r
69 Clazz.defineMethod (c$, "getEndOffset",
\r
71 return this.endOffset;
\r
73 Clazz.defineMethod (c$, "getElementIterator",
\r
77 Clazz.defineMethod (c$, "getWriter",
\r
81 Clazz.defineMethod (c$, "getDocument",
\r
85 Clazz.defineMethod (c$, "inRange",
\r
87 var startOffset = this.getStartOffset ();
\r
88 var endOffset = this.getEndOffset ();
\r
89 if ((next.getStartOffset () >= startOffset && next.getStartOffset () < endOffset) || (startOffset >= next.getStartOffset () && startOffset < next.getEndOffset ())) {
\r
92 }, "javax.swing.text.Element");
\r
93 Clazz.defineMethod (c$, "getText",
\r
95 return this.doc.getText (elem.getStartOffset (), elem.getEndOffset () - elem.getStartOffset ());
\r
96 }, "javax.swing.text.Element");
\r
97 Clazz.defineMethod (c$, "text",
\r
99 var start = Math.max (this.getStartOffset (), elem.getStartOffset ());
\r
100 var end = Math.min (this.getEndOffset (), elem.getEndOffset ());
\r
102 if (this.segment == null) {
\r
103 this.segment = new javax.swing.text.Segment ();
\r
104 }this.getDocument ().getText (start, end - start, this.segment);
\r
105 if (this.segment.count > 0) {
\r
106 this.write (this.segment.array, this.segment.offset, this.segment.count);
\r
107 }}}, "javax.swing.text.Element");
\r
108 Clazz.defineMethod (c$, "setLineLength",
\r
110 this.maxLineLength = l;
\r
112 Clazz.defineMethod (c$, "getLineLength",
\r
114 return this.maxLineLength;
\r
116 Clazz.defineMethod (c$, "setCurrentLineLength",
\r
117 function (length) {
\r
118 this.currLength = length;
\r
119 this.$isLineEmpty = (this.currLength == 0);
\r
121 Clazz.defineMethod (c$, "getCurrentLineLength",
\r
123 return this.currLength;
\r
125 Clazz.defineMethod (c$, "isLineEmpty",
\r
127 return this.$isLineEmpty;
\r
129 Clazz.defineMethod (c$, "setCanWrapLines",
\r
130 function (newValue) {
\r
131 this.canWrapLines = newValue;
\r
133 Clazz.defineMethod (c$, "getCanWrapLines",
\r
135 return this.canWrapLines;
\r
137 Clazz.defineMethod (c$, "setIndentSpace",
\r
139 this.indentSpace = space;
\r
141 Clazz.defineMethod (c$, "getIndentSpace",
\r
143 return this.indentSpace;
\r
145 Clazz.defineMethod (c$, "setLineSeparator",
\r
147 this.lineSeparator = value;
\r
149 Clazz.defineMethod (c$, "getLineSeparator",
\r
151 return this.lineSeparator;
\r
153 Clazz.defineMethod (c$, "incrIndent",
\r
155 if (this.offsetIndent > 0) {
\r
156 this.offsetIndent++;
\r
158 if (++this.indentLevel * this.getIndentSpace () >= this.getLineLength ()) {
\r
159 this.offsetIndent++;
\r
160 --this.indentLevel;
\r
162 Clazz.defineMethod (c$, "decrIndent",
\r
164 if (this.offsetIndent > 0) {
\r
165 --this.offsetIndent;
\r
167 this.indentLevel--;
\r
169 Clazz.defineMethod (c$, "getIndentLevel",
\r
171 return this.indentLevel;
\r
173 Clazz.defineMethod (c$, "indent",
\r
175 var max = this.getIndentLevel () * this.getIndentSpace ();
\r
176 if (this.indentChars == null || max > this.indentChars.length) {
\r
177 this.indentChars = Clazz.newCharArray (max, '\0');
\r
178 for (var counter = 0; counter < max; counter++) {
\r
179 this.indentChars[counter] = ' ';
\r
181 }var length = this.getCurrentLineLength ();
\r
182 var wasEmpty = this.isLineEmpty ();
\r
183 this.output (this.indentChars, 0, max);
\r
184 if (wasEmpty && length == 0) {
\r
185 this.$isLineEmpty = true;
\r
187 Clazz.defineMethod (c$, "write",
\r
189 if (this.tempChars == null) {
\r
190 this.tempChars = Clazz.newCharArray (128, '\0');
\r
191 }this.tempChars[0] = ch;
\r
192 this.write (this.tempChars, 0, 1);
\r
194 Clazz.defineMethod (c$, "write",
\r
195 function (content) {
\r
196 if (content == null) {
\r
198 }var size = content.length;
\r
199 if (this.tempChars == null || this.tempChars.length < size) {
\r
200 this.tempChars = Clazz.newCharArray (size, '\0');
\r
201 }content.getChars (0, size, this.tempChars, 0);
\r
202 this.write (this.tempChars, 0, size);
\r
204 Clazz.defineMethod (c$, "writeLineSeparator",
\r
206 var newline = this.getLineSeparator ();
\r
207 var length = newline.length;
\r
208 if (this.newlineChars == null || this.newlineChars.length < length) {
\r
209 this.newlineChars = Clazz.newCharArray (length, '\0');
\r
210 }newline.getChars (0, length, this.newlineChars, 0);
\r
211 this.output (this.newlineChars, 0, length);
\r
212 this.setCurrentLineLength (0);
\r
214 Clazz.defineMethod (c$, "write",
\r
215 function (chars, startIndex, length) {
\r
216 if (!this.getCanWrapLines ()) {
\r
217 var lastIndex = startIndex;
\r
218 var endIndex = startIndex + length;
\r
219 var newlineIndex = this.indexOf (chars, '\u000a', startIndex, endIndex);
\r
220 while (newlineIndex != -1) {
\r
221 if (newlineIndex > lastIndex) {
\r
222 this.output (chars, lastIndex, newlineIndex - lastIndex);
\r
223 }this.writeLineSeparator ();
\r
224 lastIndex = newlineIndex + 1;
\r
225 newlineIndex = this.indexOf (chars, '\n', lastIndex, endIndex);
\r
227 if (lastIndex < endIndex) {
\r
228 this.output (chars, lastIndex, endIndex - lastIndex);
\r
230 var lastIndex = startIndex;
\r
231 var endIndex = startIndex + length;
\r
232 var lineLength = this.getCurrentLineLength ();
\r
233 var maxLength = this.getLineLength ();
\r
234 while (lastIndex < endIndex) {
\r
235 var newlineIndex = this.indexOf (chars, '\u000a', lastIndex, endIndex);
\r
236 var needsNewline = false;
\r
237 var forceNewLine = false;
\r
238 lineLength = this.getCurrentLineLength ();
\r
239 if (newlineIndex != -1 && (lineLength + (newlineIndex - lastIndex)) < maxLength) {
\r
240 if (newlineIndex > lastIndex) {
\r
241 this.output (chars, lastIndex, newlineIndex - lastIndex);
\r
242 }lastIndex = newlineIndex + 1;
\r
243 forceNewLine = true;
\r
244 } else if (newlineIndex == -1 && (lineLength + (endIndex - lastIndex)) < maxLength) {
\r
245 if (endIndex > lastIndex) {
\r
246 this.output (chars, lastIndex, endIndex - lastIndex);
\r
247 }lastIndex = endIndex;
\r
249 var breakPoint = -1;
\r
250 var maxBreak = Math.min (endIndex - lastIndex, maxLength - lineLength - 1);
\r
252 while (counter < maxBreak) {
\r
253 if (Character.isWhitespace (chars[counter + lastIndex])) {
\r
254 breakPoint = counter;
\r
257 if (breakPoint != -1) {
\r
258 breakPoint += lastIndex + 1;
\r
259 this.output (chars, lastIndex, breakPoint - lastIndex);
\r
260 lastIndex = breakPoint;
\r
261 needsNewline = true;
\r
263 counter = Math.max (0, maxBreak);
\r
264 maxBreak = endIndex - lastIndex;
\r
265 while (counter < maxBreak) {
\r
266 if (Character.isWhitespace (chars[counter + lastIndex])) {
\r
267 breakPoint = counter;
\r
271 if (breakPoint == -1) {
\r
272 this.output (chars, lastIndex, endIndex - lastIndex);
\r
273 breakPoint = endIndex;
\r
275 breakPoint += lastIndex;
\r
276 if (chars[breakPoint] == '\u000a') {
\r
277 this.output (chars, lastIndex, breakPoint++ - lastIndex);
\r
278 forceNewLine = true;
\r
280 this.output (chars, lastIndex, ++breakPoint - lastIndex);
\r
281 needsNewline = true;
\r
282 }}lastIndex = breakPoint;
\r
283 }}if (forceNewLine || needsNewline || lastIndex < endIndex) {
\r
284 this.writeLineSeparator ();
\r
285 if (lastIndex < endIndex || !forceNewLine) {
\r
289 Clazz.defineMethod (c$, "writeAttributes",
\r
291 var names = attr.getAttributeNames ();
\r
292 while (names.hasMoreElements ()) {
\r
293 var name = names.nextElement ();
\r
294 this.write (" " + name + "=" + attr.getAttribute (name));
\r
296 }, "javax.swing.text.AttributeSet");
\r
297 Clazz.defineMethod (c$, "output",
\r
298 function (content, start, length) {
\r
299 this.getWriter ().write (content, start, length);
\r
300 this.setCurrentLineLength (this.getCurrentLineLength () + length);
\r
302 Clazz.defineMethod (c$, "indexOf",
\r
303 function (chars, sChar, startIndex, endIndex) {
\r
304 while (startIndex < endIndex) {
\r
305 if (chars[startIndex] == sChar) {
\r
311 Clazz.defineStatics (c$,
\r