3bb5bbdea7caa65722926578eb609ac946c8440f
[jalviewjs.git] / site / swingjs / j2s / javax / swing / text / StringContent.js
1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.text.AbstractDocument", "$.Position", "javax.swing.undo.AbstractUndoableEdit"], "javax.swing.text.StringContent", ["java.util.Vector", "javax.swing.text.BadLocationException", "javax.swing.undo.CannotRedoException", "$.CannotUndoException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.data = null;
5 this.count = 0;
6 this.marks = null;
7 if (!Clazz.isClassDefined ("javax.swing.text.StringContent.PosRec")) {
8 javax.swing.text.StringContent.$StringContent$PosRec$ ();
9 }
10 if (!Clazz.isClassDefined ("javax.swing.text.StringContent.StickyPosition")) {
11 javax.swing.text.StringContent.$StringContent$StickyPosition$ ();
12 }
13 if (!Clazz.isClassDefined ("javax.swing.text.StringContent.UndoPosRef")) {
14 javax.swing.text.StringContent.$StringContent$UndoPosRef$ ();
15 }
16 if (!Clazz.isClassDefined ("javax.swing.text.StringContent.InsertUndo")) {
17 javax.swing.text.StringContent.$StringContent$InsertUndo$ ();
18 }
19 if (!Clazz.isClassDefined ("javax.swing.text.StringContent.RemoveUndo")) {
20 javax.swing.text.StringContent.$StringContent$RemoveUndo$ ();
21 }
22 Clazz.instantialize (this, arguments);
23 }, javax.swing.text, "StringContent", null, javax.swing.text.AbstractDocument.Content);
24 Clazz.makeConstructor (c$, 
25 function () {
26 this.construct (10);
27 });
28 Clazz.makeConstructor (c$, 
29 function (initialLength) {
30 if (initialLength < 1) {
31 initialLength = 1;
32 }this.data =  Clazz.newCharArray (initialLength, '\0');
33 this.data[0] = '\n';
34 this.count = 1;
35 }, "~N");
36 Clazz.overrideMethod (c$, "length", 
37 function () {
38 return this.count;
39 });
40 Clazz.overrideMethod (c$, "insertString", 
41 function (where, str) {
42 if (where >= this.count || where < 0) {
43 throw  new javax.swing.text.BadLocationException ("Invalid location", this.count);
44 }var chars = str.toCharArray ();
45 this.replace (where, 0, chars, 0, chars.length);
46 if (this.marks != null) {
47 this.updateMarksForInsert (where, str.length);
48 }return Clazz.innerTypeInstance (javax.swing.text.StringContent.InsertUndo, this, null, where, str.length);
49 }, "~N,~S");
50 Clazz.overrideMethod (c$, "remove", 
51 function (where, nitems) {
52 if (where + nitems >= this.count) {
53 throw  new javax.swing.text.BadLocationException ("Invalid range", this.count);
54 }var removedString = this.getString (where, nitems);
55 var edit = Clazz.innerTypeInstance (javax.swing.text.StringContent.RemoveUndo, this, null, where, removedString);
56 this.replace (where, nitems, javax.swing.text.StringContent.empty, 0, 0);
57 if (this.marks != null) {
58 this.updateMarksForRemove (where, nitems);
59 }return edit;
60 }, "~N,~N");
61 Clazz.overrideMethod (c$, "getString", 
62 function (where, len) {
63 if (where + len > this.count) {
64 throw  new javax.swing.text.BadLocationException ("Invalid range", this.count);
65 }return  String.instantialize (this.data, where, len);
66 }, "~N,~N");
67 Clazz.overrideMethod (c$, "getChars", 
68 function (where, len, chars) {
69 if (where + len > this.count) {
70 throw  new javax.swing.text.BadLocationException ("Invalid location", this.count);
71 }chars.array = this.data;
72 chars.offset = where;
73 chars.count = len;
74 }, "~N,~N,javax.swing.text.Segment");
75 Clazz.overrideMethod (c$, "createPosition", 
76 function (offset) {
77 if (this.marks == null) {
78 this.marks =  new java.util.Vector ();
79 }return Clazz.innerTypeInstance (javax.swing.text.StringContent.StickyPosition, this, null, offset);
80 }, "~N");
81 Clazz.defineMethod (c$, "replace", 
82 function (offset, length, replArray, replOffset, replLength) {
83 var delta = replLength - length;
84 var src = offset + length;
85 var nmove = this.count - src;
86 var dest = src + delta;
87 if ((this.count + delta) >= this.data.length) {
88 var newLength = Math.max (2 * this.data.length, this.count + delta);
89 var newData =  Clazz.newCharArray (newLength, '\0');
90 System.arraycopy (this.data, 0, newData, 0, offset);
91 System.arraycopy (replArray, replOffset, newData, offset, replLength);
92 System.arraycopy (this.data, src, newData, dest, nmove);
93 this.data = newData;
94 } else {
95 System.arraycopy (this.data, src, this.data, dest, nmove);
96 System.arraycopy (replArray, replOffset, this.data, offset, replLength);
97 }this.count = this.count + delta;
98 }, "~N,~N,~A,~N,~N");
99 Clazz.defineMethod (c$, "resize", 
100 function (ncount) {
101 var ndata =  Clazz.newCharArray (ncount, '\0');
102 System.arraycopy (this.data, 0, ndata, 0, Math.min (ncount, this.count));
103 this.data = ndata;
104 }, "~N");
105 Clazz.defineMethod (c$, "updateMarksForInsert", 
106 function (offset, length) {
107 if (offset == 0) {
108 offset = 1;
109 }var n = this.marks.size ();
110 for (var i = 0; i < n; i++) {
111 var mark = this.marks.elementAt (i);
112 if (mark.unused) {
113 this.marks.removeElementAt (i);
114 i -= 1;
115 n -= 1;
116 } else if (mark.offset >= offset) {
117 mark.offset += length;
118 }}
119 }, "~N,~N");
120 Clazz.defineMethod (c$, "updateMarksForRemove", 
121 function (offset, length) {
122 var n = this.marks.size ();
123 for (var i = 0; i < n; i++) {
124 var mark = this.marks.elementAt (i);
125 if (mark.unused) {
126 this.marks.removeElementAt (i);
127 i -= 1;
128 n -= 1;
129 } else if (mark.offset >= (offset + length)) {
130 mark.offset -= length;
131 } else if (mark.offset >= offset) {
132 mark.offset = offset;
133 }}
134 }, "~N,~N");
135 Clazz.defineMethod (c$, "getPositionsInRange", 
136 function (v, offset, length) {
137 var n = this.marks.size ();
138 var end = offset + length;
139 var placeIn = (v == null) ?  new java.util.Vector () : v;
140 for (var i = 0; i < n; i++) {
141 var mark = this.marks.elementAt (i);
142 if (mark.unused) {
143 this.marks.removeElementAt (i);
144 i -= 1;
145 n -= 1;
146 } else if (mark.offset >= offset && mark.offset <= end) placeIn.addElement (Clazz.innerTypeInstance (javax.swing.text.StringContent.UndoPosRef, this, null, mark));
147 }
148 return placeIn;
149 }, "java.util.Vector,~N,~N");
150 Clazz.defineMethod (c$, "updateUndoPositions", 
151 function (positions) {
152 for (var counter = positions.size () - 1; counter >= 0; counter--) {
153 var ref = positions.elementAt (counter);
154 if (ref.rec.unused) {
155 positions.removeElementAt (counter);
156 } else ref.resetLocation ();
157 }
158 }, "java.util.Vector");
159 c$.$StringContent$PosRec$ = function () {
160 Clazz.pu$h(self.c$);
161 c$ = Clazz.decorateAsClass (function () {
162 Clazz.prepareCallback (this, arguments);
163 this.offset = 0;
164 this.unused = false;
165 Clazz.instantialize (this, arguments);
166 }, javax.swing.text.StringContent, "PosRec");
167 Clazz.makeConstructor (c$, 
168 function (a) {
169 this.offset = a;
170 }, "~N");
171 c$ = Clazz.p0p ();
172 };
173 c$.$StringContent$StickyPosition$ = function () {
174 Clazz.pu$h(self.c$);
175 c$ = Clazz.decorateAsClass (function () {
176 Clazz.prepareCallback (this, arguments);
177 this.rec = null;
178 Clazz.instantialize (this, arguments);
179 }, javax.swing.text.StringContent, "StickyPosition", null, javax.swing.text.Position);
180 Clazz.makeConstructor (c$, 
181 function (a) {
182 this.rec = Clazz.innerTypeInstance (javax.swing.text.StringContent.PosRec, this, null, a);
183 this.b$["javax.swing.text.StringContent"].marks.addElement (this.rec);
184 }, "~N");
185 Clazz.overrideMethod (c$, "getOffset", 
186 function () {
187 return this.rec.offset;
188 });
189 Clazz.overrideMethod (c$, "finalize", 
190 function () {
191 this.rec.unused = true;
192 });
193 Clazz.overrideMethod (c$, "toString", 
194 function () {
195 return Integer.toString (this.getOffset ());
196 });
197 c$ = Clazz.p0p ();
198 };
199 c$.$StringContent$UndoPosRef$ = function () {
200 Clazz.pu$h(self.c$);
201 c$ = Clazz.decorateAsClass (function () {
202 Clazz.prepareCallback (this, arguments);
203 this.undoLocation = 0;
204 this.rec = null;
205 Clazz.instantialize (this, arguments);
206 }, javax.swing.text.StringContent, "UndoPosRef");
207 Clazz.makeConstructor (c$, 
208 function (a) {
209 this.rec = a;
210 this.undoLocation = a.offset;
211 }, "javax.swing.text.StringContent.PosRec");
212 Clazz.defineMethod (c$, "resetLocation", 
213 function () {
214 this.rec.offset = this.undoLocation;
215 });
216 c$ = Clazz.p0p ();
217 };
218 c$.$StringContent$InsertUndo$ = function () {
219 Clazz.pu$h(self.c$);
220 c$ = Clazz.decorateAsClass (function () {
221 Clazz.prepareCallback (this, arguments);
222 this.offset = 0;
223 this.length = 0;
224 this.string = null;
225 this.posRefs = null;
226 Clazz.instantialize (this, arguments);
227 }, javax.swing.text.StringContent, "InsertUndo", javax.swing.undo.AbstractUndoableEdit);
228 Clazz.makeConstructor (c$, 
229 function (a, b) {
230 Clazz.superConstructor (this, javax.swing.text.StringContent.InsertUndo);
231 this.offset = a;
232 this.length = b;
233 }, "~N,~N");
234 Clazz.defineMethod (c$, "undo", 
235 function () {
236 Clazz.superCall (this, javax.swing.text.StringContent.InsertUndo, "undo", []);
237 try {
238 {
239 if (this.b$["javax.swing.text.StringContent"].marks != null) this.posRefs = this.b$["javax.swing.text.StringContent"].getPositionsInRange (null, this.offset, this.length);
240 this.string = this.b$["javax.swing.text.StringContent"].getString (this.offset, this.length);
241 this.b$["javax.swing.text.StringContent"].remove (this.offset, this.length);
242 }} catch (bl) {
243 if (Clazz.exceptionOf (bl, javax.swing.text.BadLocationException)) {
244 throw  new javax.swing.undo.CannotUndoException ();
245 } else {
246 throw bl;
247 }
248 }
249 });
250 Clazz.defineMethod (c$, "redo", 
251 function () {
252 Clazz.superCall (this, javax.swing.text.StringContent.InsertUndo, "redo", []);
253 try {
254 {
255 this.b$["javax.swing.text.StringContent"].insertString (this.offset, this.string);
256 this.string = null;
257 if (this.posRefs != null) {
258 this.b$["javax.swing.text.StringContent"].updateUndoPositions (this.posRefs);
259 this.posRefs = null;
260 }}} catch (bl) {
261 if (Clazz.exceptionOf (bl, javax.swing.text.BadLocationException)) {
262 throw  new javax.swing.undo.CannotRedoException ();
263 } else {
264 throw bl;
265 }
266 }
267 });
268 c$ = Clazz.p0p ();
269 };
270 c$.$StringContent$RemoveUndo$ = function () {
271 Clazz.pu$h(self.c$);
272 c$ = Clazz.decorateAsClass (function () {
273 Clazz.prepareCallback (this, arguments);
274 this.offset = 0;
275 this.length = 0;
276 this.string = null;
277 this.posRefs = null;
278 Clazz.instantialize (this, arguments);
279 }, javax.swing.text.StringContent, "RemoveUndo", javax.swing.undo.AbstractUndoableEdit);
280 Clazz.makeConstructor (c$, 
281 function (a, b) {
282 Clazz.superConstructor (this, javax.swing.text.StringContent.RemoveUndo);
283 this.offset = a;
284 this.string = b;
285 this.length = b.length;
286 if (this.b$["javax.swing.text.StringContent"].marks != null) this.posRefs = this.b$["javax.swing.text.StringContent"].getPositionsInRange (null, a, this.length);
287 }, "~N,~S");
288 Clazz.defineMethod (c$, "undo", 
289 function () {
290 Clazz.superCall (this, javax.swing.text.StringContent.RemoveUndo, "undo", []);
291 try {
292 {
293 this.b$["javax.swing.text.StringContent"].insertString (this.offset, this.string);
294 if (this.posRefs != null) {
295 this.b$["javax.swing.text.StringContent"].updateUndoPositions (this.posRefs);
296 this.posRefs = null;
297 }this.string = null;
298 }} catch (bl) {
299 if (Clazz.exceptionOf (bl, javax.swing.text.BadLocationException)) {
300 throw  new javax.swing.undo.CannotUndoException ();
301 } else {
302 throw bl;
303 }
304 }
305 });
306 Clazz.defineMethod (c$, "redo", 
307 function () {
308 Clazz.superCall (this, javax.swing.text.StringContent.RemoveUndo, "redo", []);
309 try {
310 {
311 this.string = this.b$["javax.swing.text.StringContent"].getString (this.offset, this.length);
312 if (this.b$["javax.swing.text.StringContent"].marks != null) this.posRefs = this.b$["javax.swing.text.StringContent"].getPositionsInRange (null, this.offset, this.length);
313 this.b$["javax.swing.text.StringContent"].remove (this.offset, this.length);
314 }} catch (bl) {
315 if (Clazz.exceptionOf (bl, javax.swing.text.BadLocationException)) {
316 throw  new javax.swing.undo.CannotRedoException ();
317 } else {
318 throw bl;
319 }
320 }
321 });
322 c$ = Clazz.p0p ();
323 };
324 Clazz.defineStatics (c$,
325 "empty",  Clazz.newCharArray (0, '\0'));
326 });