1 Clazz.declarePackage ("swingjs");
2 Clazz.load (["javax.swing.text.DocumentFilter", "$.Element", "$.JSMinimalAbstractDocument"], "swingjs.JSAbstractDocument", ["java.lang.IllegalStateException", "java.util.HashMap", "JU.AU", "javax.swing.event.DocumentEvent", "$.DocumentListener", "$.EventListenerList", "javax.swing.text.BadLocationException", "swingjs.JSDocumentEvent"], function () {
3 c$ = Clazz.decorateAsClass (function () {
7 this.listenerList = null;
8 this.notifyingListeners = false;
9 this.filterBypass = null;
14 if (!Clazz.isClassDefined ("swingjs.JSAbstractDocument.DefaultFilterBypass")) {
15 swingjs.JSAbstractDocument.$JSAbstractDocument$DefaultFilterBypass$ ();
17 if (!Clazz.isClassDefined ("swingjs.JSAbstractDocument.JSElement")) {
18 swingjs.JSAbstractDocument.$JSAbstractDocument$JSElement$ ();
20 Clazz.instantialize (this, arguments);
21 }, swingjs, "JSAbstractDocument", null, javax.swing.text.JSMinimalAbstractDocument);
22 Clazz.makeConstructor (c$,
25 this.props = new java.util.HashMap ();
27 Clazz.overrideMethod (c$, "getRootElements",
29 return Clazz.newArray (-1, [this.root, null]);
31 Clazz.defineMethod (c$, "checkLoc",
32 function (start, end) {
33 if (start < 0 || end > this.getLength ()) throw new javax.swing.text.BadLocationException ("JSAbstractDocument: out of range", (start < 0 ? start : end));
35 Clazz.defineMethod (c$, "fixPositions",
36 function (offset, length, isInsert) {
37 if (this.positions == null || this.positions.isEmpty ()) return;
39 for (var i, $i = this.positions.keySet ().iterator (); $i.hasNext () && ((i = $i.next ()) || true);) {
40 var pos = i.intValue ();
41 if (pos > offset) this.positions.get (i).pos += length;
44 }for (var i, $i = this.positions.keySet ().iterator (); $i.hasNext () && ((i = $i.next ()) || true);) {
45 var pos = i.intValue ();
46 if (pos <= offset) continue;
47 if (pos >= offset + length) this.positions.get (i).pos -= length;
48 else this.positions.get (i).pos = offset;
51 Clazz.defineMethod (c$, "getFilterBypass",
53 if (this.filterBypass == null) {
54 this.filterBypass = Clazz.innerTypeInstance (swingjs.JSAbstractDocument.DefaultFilterBypass, this, null);
55 }return this.filterBypass;
57 Clazz.overrideMethod (c$, "remove",
58 function (offs, len) {
59 var filter = this.getDocumentFilter ();
60 if (filter == null) this.handleRemove (offs, len);
61 else filter.remove (this.getFilterBypass (), offs, len);
63 Clazz.overrideMethod (c$, "insertString",
64 function (offset, str, a) {
65 var filter = this.getDocumentFilter ();
66 if (filter == null) this.handleInsertString (offset, str, a);
67 else filter.insertString (this.getFilterBypass (), offset, str, a);
68 }, "~N,~S,javax.swing.text.AttributeSet");
69 Clazz.overrideMethod (c$, "replace",
70 function (offset, length, text, attrs) {
71 if (length == 0 && (text == null || text.length == 0)) return;
72 var filter = this.getDocumentFilter ();
74 filter.replace (this.getFilterBypass (), offset, length, text, attrs);
76 if (length > 0) this.remove (offset, length);
77 if (text != null && text.length > 0) this.insertString (offset, text, attrs);
78 }}, "~N,~N,~S,javax.swing.text.AttributeSet");
79 Clazz.defineMethod (c$, "taint",
83 Clazz.defineMethod (c$, "setLines",
85 this.root = Clazz.innerTypeInstance (swingjs.JSAbstractDocument.JSElement, this, null);
86 var s = this.sb.toString ();
87 if (s.lastIndexOf ('\n') != s.length - 1) s += "\n";
89 for (var i = 0; i < s.length; i++) {
90 if (s.charAt (i) != '\n') continue;
91 var e = Clazz.innerTypeInstance (swingjs.JSAbstractDocument.JSElement, this, null);
95 this.root.addChild (e);
98 Clazz.defineMethod (c$, "handleInsertString",
99 function (offs, str, a) {
100 if ((str == null) || (str.length == 0)) {
102 }this.checkLoc (offs, offs);
104 this.sb.insert (offs, str);
105 this.fixPositions (offs, str.length, true);
106 if (str.indexOf ('\n') >= 0) this.setLines ();
107 var e = new swingjs.JSDocumentEvent (this, offs, str.length, javax.swing.event.DocumentEvent.EventType.INSERT);
108 this.fireInsertUpdate (e);
109 }, "~N,~S,javax.swing.text.AttributeSet");
110 Clazz.defineMethod (c$, "handleRemove",
111 function (offs, len) {
112 this.checkLoc (offs, offs + len);
114 var str = this.sb.substring2 (offs, offs + len);
115 this.sb.replace (offs, offs + len, "");
116 this.fixPositions (offs, offs + len, false);
117 if (str.indexOf ('\n') >= 0) this.setLines ();
119 var chng = new swingjs.JSDocumentEvent (this, offs, len, javax.swing.event.DocumentEvent.EventType.REMOVE);
120 this.fireRemoveUpdate (chng);
122 Clazz.defineMethod (c$, "fireInsertUpdate",
124 if (this.listenerList == null) return;
125 this.checkAlreadyNotifying ();
126 this.notifyingListeners = true;
128 var listeners = this.listenerList.getListenerList ();
129 for (var i = listeners.length - 2; i >= 0; i -= 2) {
130 if (listeners[i] === javax.swing.event.DocumentListener) {
131 (listeners[i + 1]).insertUpdate (e);
134 this.notifyingListeners = false;
136 }, "javax.swing.event.DocumentEvent");
137 Clazz.defineMethod (c$, "fireChangedUpdate",
139 if (this.listenerList == null) return;
140 this.checkAlreadyNotifying ();
141 this.notifyingListeners = true;
143 var listeners = this.listenerList.getListenerList ();
144 for (var i = listeners.length - 2; i >= 0; i -= 2) {
145 if (listeners[i] === javax.swing.event.DocumentListener) {
146 (listeners[i + 1]).changedUpdate (e);
149 this.notifyingListeners = false;
151 }, "javax.swing.event.DocumentEvent");
152 Clazz.defineMethod (c$, "fireRemoveUpdate",
154 if (this.listenerList == null) return;
155 this.checkAlreadyNotifying ();
156 this.notifyingListeners = true;
158 var listeners = this.listenerList.getListenerList ();
159 for (var i = listeners.length - 2; i >= 0; i -= 2) {
160 if (listeners[i] === javax.swing.event.DocumentListener) {
161 (listeners[i + 1]).removeUpdate (e);
164 this.notifyingListeners = false;
166 }, "javax.swing.event.DocumentEvent");
167 Clazz.defineMethod (c$, "checkAlreadyNotifying",
169 if (this.notifyingListeners) throw new IllegalStateException ("One of the document listeners modifed the document. This is not allowed.");
171 Clazz.overrideMethod (c$, "addDocumentListener",
172 function (listener) {
173 if (this.listenerList == null) this.listenerList = new javax.swing.event.EventListenerList ();
174 this.listenerList.add (javax.swing.event.DocumentListener, listener);
175 }, "javax.swing.event.DocumentListener");
176 Clazz.overrideMethod (c$, "removeDocumentListener",
177 function (listener) {
178 if (this.listenerList != null) this.listenerList.remove (javax.swing.event.DocumentListener, listener);
179 }, "javax.swing.event.DocumentListener");
180 Clazz.overrideMethod (c$, "addUndoableEditListener",
181 function (listener) {
182 }, "javax.swing.event.UndoableEditListener");
183 Clazz.overrideMethod (c$, "removeUndoableEditListener",
184 function (listener) {
185 }, "javax.swing.event.UndoableEditListener");
186 Clazz.overrideMethod (c$, "getProperty",
188 return this.props.get (key);
190 Clazz.overrideMethod (c$, "putProperty",
191 function (key, value) {
192 this.props.put (key, value);
194 Clazz.overrideMethod (c$, "getAsynchronousLoadPriority",
198 Clazz.overrideMethod (c$, "setDocumentFilter",
200 this.filter = filter;
201 }, "javax.swing.text.DocumentFilter");
202 Clazz.defineMethod (c$, "getDocumentFilter",
206 c$.$JSAbstractDocument$DefaultFilterBypass$ = function () {
208 c$ = Clazz.decorateAsClass (function () {
209 Clazz.prepareCallback (this, arguments);
210 Clazz.instantialize (this, arguments);
211 }, swingjs.JSAbstractDocument, "DefaultFilterBypass", javax.swing.text.DocumentFilter.FilterBypass);
212 Clazz.overrideMethod (c$, "getDocument",
214 return this.b$["swingjs.JSAbstractDocument"].me;
216 Clazz.overrideMethod (c$, "remove",
218 this.b$["swingjs.JSAbstractDocument"].handleRemove (a, b);
220 Clazz.overrideMethod (c$, "insertString",
222 this.b$["swingjs.JSAbstractDocument"].handleInsertString (a, b, c);
223 }, "~N,~S,javax.swing.text.AttributeSet");
224 Clazz.overrideMethod (c$, "replace",
225 function (a, b, c, d) {
226 this.b$["swingjs.JSAbstractDocument"].handleRemove (a, b);
227 this.b$["swingjs.JSAbstractDocument"].handleInsertString (a, c, d);
228 }, "~N,~N,~S,javax.swing.text.AttributeSet");
231 c$.$JSAbstractDocument$JSElement$ = function () {
233 c$ = Clazz.decorateAsClass (function () {
234 Clazz.prepareCallback (this, arguments);
236 this.attributeSet = null;
240 this.children = null;
242 Clazz.instantialize (this, arguments);
243 }, swingjs.JSAbstractDocument, "JSElement", null, javax.swing.text.Element);
244 Clazz.makeConstructor (c$,
246 this.children = null;
250 Clazz.defineMethod (c$, "addChild",
252 if (this.children == null) this.children = new Array (10);
253 else if (this.nchildren == this.children.length) this.children = JU.AU.doubleLength (this.children);
254 this.children[this.nchildren++] = a;
255 }, "swingjs.JSAbstractDocument.JSElement");
256 Clazz.overrideMethod (c$, "getDocument",
258 return this.b$["swingjs.JSAbstractDocument"].me;
260 Clazz.overrideMethod (c$, "getParentElement",
264 Clazz.overrideMethod (c$, "getName",
266 return this.getName ();
268 Clazz.overrideMethod (c$, "getAttributes",
270 return this.attributeSet;
272 Clazz.defineMethod (c$, "getStartOffset",
276 Clazz.defineMethod (c$, "getEndOffset",
280 Clazz.overrideMethod (c$, "getElementIndex",
284 var d = this.nchildren - 1;
286 var f = this.getStartOffset ();
288 if (this.nchildren == 0) {
290 }if (a >= this.getEndOffset ()) {
291 return this.nchildren - 1;
292 }if ((this.lastIndex >= c) && (this.lastIndex <= d)) {
293 var h = this.children[this.lastIndex];
294 f = h.getStartOffset ();
295 g = h.getEndOffset ();
296 if ((a >= f) && (a < g)) {
297 return this.lastIndex;
303 e = c + (Clazz.doubleToInt ((d - c) / 2));
304 var h = this.children[e];
305 f = h.getStartOffset ();
306 g = h.getEndOffset ();
307 if ((a >= f) && (a < g)) {
323 Clazz.overrideMethod (c$, "getElementCount",
325 return this.nchildren;
327 Clazz.overrideMethod (c$, "getElement",
329 return (a >= this.nchildren ? null : this.children[a]);
331 Clazz.overrideMethod (c$, "isLeaf",
333 return (this.parent != null);
337 Clazz.defineStatics (c$,
338 "ParagraphElementName", "paragraph",
339 "ContentElementName", "content");