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