JAL-1807 update
[jalviewjs.git] / site / t.js
1 Clazz.declarePackage ("jalview.commands");
2 Clazz.load (["jalview.commands.CommandI", "java.lang.Enum", "java.util.ArrayList"], "jalview.commands.EditCommand", ["jalview.analysis.AlignSeq", "jalview.datamodel.AlignmentAnnotation", "$.Annotation", "$.Sequence", "$.SequenceFeature", "jalview.schemes.ResidueProperties", "jalview.util.Comparison", "$.ReverseListIterator", "$.StringUtils", "java.lang.StringBuffer", "java.util.HashMap", "$.Hashtable"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.edits = null;
5 this.description = null;
6 if (!Clazz.isClassDefined ("jalview.commands.EditCommand.Edit")) {
7 jalview.commands.EditCommand.$EditCommand$Edit$ ();
8 }
9 Clazz.instantialize (this, arguments);
10 }, jalview.commands, "EditCommand", null, jalview.commands.CommandI);
11 Clazz.prepareFields (c$, function () {
12 this.edits =  new java.util.ArrayList ();
13 });
14 Clazz.makeConstructor (c$, 
15 function () {
16 });
17 Clazz.makeConstructor (c$, 
18 function (description) {
19 this.description = description;
20 }, "~S");
21 Clazz.makeConstructor (c$, 
22 function (description, command, seqs, position, number, al) {
23 this.description = description;
24 if (command === jalview.commands.EditCommand.Action.CUT || command === jalview.commands.EditCommand.Action.PASTE) {
25 this.setEdit (Clazz.innerTypeInstance (jalview.commands.EditCommand.Edit, this, null, command, seqs, position, number, al));
26 }this.performEdit (0, null);
27 }, "~S,jalview.commands.EditCommand.Action,~A,~N,~N,jalview.datamodel.AlignmentI");
28 Clazz.makeConstructor (c$, 
29 function (description, command, replace, seqs, position, number, al) {
30 this.description = description;
31 if (command === jalview.commands.EditCommand.Action.REPLACE) {
32 this.setEdit (Clazz.innerTypeInstance (jalview.commands.EditCommand.Edit, this, null, command, seqs, position, number, al, replace));
33 }this.performEdit (0, null);
34 }, "~S,jalview.commands.EditCommand.Action,~S,~A,~N,~N,jalview.datamodel.AlignmentI");
35 Clazz.defineMethod (c$, "setEdit", 
36 function (e) {
37 this.edits.clear ();
38 this.edits.add (e);
39 }, "jalview.commands.EditCommand.Edit");
40 Clazz.defineMethod (c$, "addEdit", 
41 function (e) {
42 if (!jalview.commands.EditCommand.expandEdit (this.edits, e)) {
43 this.edits.add (e);
44 }}, "jalview.commands.EditCommand.Edit");
45 c$.expandEdit = Clazz.defineMethod (c$, "expandEdit", 
46 function (edits, e) {
47 if (edits == null || edits.isEmpty ()) {
48 return false;
49 }var lastEdit = edits.get (edits.size () - 1);
50 var action = e.command;
51 if (lastEdit.command !== action) {
52 return false;
53 }if (lastEdit.seqs.length != e.seqs.length) {
54 return false;
55 }for (var i = 0; i < e.seqs.length; i++) {
56 if (lastEdit.seqs[i].getDatasetSequence () !== e.seqs[i].getDatasetSequence ()) {
57 return false;
58 }}
59 var contiguous = (action === jalview.commands.EditCommand.Action.INSERT_GAP && e.position == lastEdit.position + lastEdit.number) || (action === jalview.commands.EditCommand.Action.DELETE_GAP && e.position + e.number == lastEdit.position);
60 if (contiguous) {
61 lastEdit.number += e.number;
62 lastEdit.seqs = e.seqs;
63 if (action === jalview.commands.EditCommand.Action.DELETE_GAP) {
64 lastEdit.position--;
65 }return true;
66 }return false;
67 }, "java.util.List,jalview.commands.EditCommand.Edit");
68 Clazz.defineMethod (c$, "clearEdits", 
69 function () {
70 this.edits.clear ();
71 });
72 Clazz.defineMethod (c$, "getEdit", 
73 function (i) {
74 if (i >= 0 && i < this.edits.size ()) {
75 return this.edits.get (i);
76 }return null;
77 }, "~N");
78 Clazz.overrideMethod (c$, "getDescription", 
79 function () {
80 return this.description;
81 });
82 Clazz.overrideMethod (c$, "getSize", 
83 function () {
84 return this.edits.size ();
85 });
86 Clazz.defineMethod (c$, "getAlignment", 
87 function () {
88 return (this.edits.isEmpty () ? null : this.edits.get (0).al);
89 });
90 Clazz.defineMethod (c$, "appendEdit", 
91 function (command, seqs, position, number, al, performEdit) {
92 this.appendEdit (command, seqs, position, number, al, performEdit, null);
93 }, "jalview.commands.EditCommand.Action,~A,~N,~N,jalview.datamodel.AlignmentI,~B");
94 Clazz.defineMethod (c$, "appendEdit", 
95 function (command, seqs, position, number, al, performEdit, views) {
96 var edit = Clazz.innerTypeInstance (jalview.commands.EditCommand.Edit, this, null, command, seqs, position, number, al.getGapCharacter ());
97 if (al.getHeight () == seqs.length) {
98 edit.al = al;
99 edit.fullAlignmentHeight = true;
100 }this.addEdit (edit);
101 if (performEdit) {
102 jalview.commands.EditCommand.performEdit (edit, views);
103 }}, "jalview.commands.EditCommand.Action,~A,~N,~N,jalview.datamodel.AlignmentI,~B,~A");
104 Clazz.defineMethod (c$, "appendEdit", 
105 function (edit, al, performEdit, views) {
106 if (al.getHeight () == edit.seqs.length) {
107 edit.al = al;
108 edit.fullAlignmentHeight = true;
109 }this.addEdit (edit);
110 if (performEdit) {
111 jalview.commands.EditCommand.performEdit (edit, views);
112 }}, "jalview.commands.EditCommand.Edit,jalview.datamodel.AlignmentI,~B,~A");
113 Clazz.defineMethod (c$, "performEdit", 
114 function (commandIndex, views) {
115 var iterator = this.edits.listIterator (commandIndex);
116 while (iterator.hasNext ()) {
117 var edit = iterator.next ();
118 jalview.commands.EditCommand.performEdit (edit, views);
119 }
120 }, "~N,~A");
121 c$.performEdit = Clazz.defineMethod (c$, "performEdit", 
122 function (edit, views) {
123 switch (edit.command) {
124 case jalview.commands.EditCommand.Action.INSERT_GAP:
125 jalview.commands.EditCommand.insertGap (edit);
126 break;
127 case jalview.commands.EditCommand.Action.DELETE_GAP:
128 jalview.commands.EditCommand.deleteGap (edit);
129 break;
130 case jalview.commands.EditCommand.Action.CUT:
131 jalview.commands.EditCommand.cut (edit, views);
132 break;
133 case jalview.commands.EditCommand.Action.PASTE:
134 jalview.commands.EditCommand.paste (edit, views);
135 break;
136 case jalview.commands.EditCommand.Action.REPLACE:
137 jalview.commands.EditCommand.replace (edit);
138 break;
139 case jalview.commands.EditCommand.Action.INSERT_NUC:
140 break;
141 default:
142 break;
143 }
144 }, "jalview.commands.EditCommand.Edit,~A");
145 Clazz.overrideMethod (c$, "doCommand", 
146 function (views) {
147 this.performEdit (0, views);
148 }, "~A");
149 Clazz.overrideMethod (c$, "undoCommand", 
150 function (views) {
151 var iterator = this.edits.listIterator (this.edits.size ());
152 while (iterator.hasPrevious ()) {
153 var e = iterator.previous ();
154 switch (e.command) {
155 case jalview.commands.EditCommand.Action.INSERT_GAP:
156 jalview.commands.EditCommand.deleteGap (e);
157 break;
158 case jalview.commands.EditCommand.Action.DELETE_GAP:
159 jalview.commands.EditCommand.insertGap (e);
160 break;
161 case jalview.commands.EditCommand.Action.CUT:
162 jalview.commands.EditCommand.paste (e, views);
163 break;
164 case jalview.commands.EditCommand.Action.PASTE:
165 jalview.commands.EditCommand.cut (e, views);
166 break;
167 case jalview.commands.EditCommand.Action.REPLACE:
168 jalview.commands.EditCommand.replace (e);
169 break;
170 case jalview.commands.EditCommand.Action.INSERT_NUC:
171 break;
172 default:
173 break;
174 }
175 }
176 }, "~A");
177 c$.insertGap = Clazz.defineMethod (c$, "insertGap", 
178  function (command) {
179 for (var s = 0; s < command.seqs.length; s++) {
180 command.seqs[s].insertCharAt (command.position, command.number, command.gapChar);
181 }
182 jalview.commands.EditCommand.adjustAnnotations (command, true, false, null);
183 }, "jalview.commands.EditCommand.Edit");
184 c$.deleteGap = Clazz.defineMethod (c$, "deleteGap", 
185  function (command) {
186 for (var s = 0; s < command.seqs.length; s++) {
187 command.seqs[s].deleteChars (command.position, command.position + command.number);
188 }
189 jalview.commands.EditCommand.adjustAnnotations (command, false, false, null);
190 }, "jalview.commands.EditCommand.Edit");
191 c$.cut = Clazz.defineMethod (c$, "cut", 
192 function (command, views) {
193 var seqDeleted = false;
194 command.string =  Clazz.newCharArray (command.seqs.length, '\0');
195 for (var i = 0; i < command.seqs.length; i++) {
196 var sequence = command.seqs[i];
197 if (sequence.getLength () > command.position) {
198 command.string[i] = sequence.getSequence (command.position, command.position + command.number);
199 var oldds = sequence.getDatasetSequence ();
200 if (command.oldds != null && command.oldds[i] != null) {
201 sequence.setDatasetSequence (null);
202 }sequence.deleteChars (command.position, command.position + command.number);
203 if (command.oldds != null && command.oldds[i] != null) {
204 sequence.setDatasetSequence (command.oldds[i]);
205 command.oldds[i] = oldds;
206 } else {
207 if (oldds !== sequence.getDatasetSequence () || sequence.getSequenceFeatures () != null) {
208 if (command.oldds == null) {
209 command.oldds =  new Array (command.seqs.length);
210 }command.oldds[i] = oldds;
211 jalview.commands.EditCommand.adjustFeatures (command, i, sequence.findPosition (command.position), sequence.findPosition (command.position + command.number), false);
212 }}}if (sequence.getLength () < 1) {
213 command.al.deleteSequence (sequence);
214 seqDeleted = true;
215 }}
216 jalview.commands.EditCommand.adjustAnnotations (command, false, seqDeleted, views);
217 }, "jalview.commands.EditCommand.Edit,~A");
218 c$.paste = Clazz.defineMethod (c$, "paste", 
219 function (command, views) {
220 var tmp;
221 var newDSNeeded;
222 var newDSWasNeeded;
223 var newstart;
224 var newend;
225 var seqWasDeleted = false;
226 var start = 0;
227 var end = 0;
228 for (var i = 0; i < command.seqs.length; i++) {
229 newDSNeeded = false;
230 newDSWasNeeded = command.oldds != null && command.oldds[i] != null;
231 if (command.seqs[i].getLength () < 1) {
232 if (command.alIndex[i] < command.al.getHeight ()) {
233 var sequences;
234 {
235 if (!(command.alIndex[i] < 0)) {
236 sequences.add (command.alIndex[i], command.seqs[i]);
237 }}} else {
238 command.al.addSequence (command.seqs[i]);
239 }seqWasDeleted = true;
240 }newstart = command.seqs[i].getStart ();
241 newend = command.seqs[i].getEnd ();
242 tmp =  new StringBuffer ();
243 tmp.append (command.seqs[i].getSequence ());
244 if (command.string != null && command.string[i] != null) {
245 if (command.position >= tmp.length ()) {
246 var length = command.position - tmp.length ();
247 while (length > 0) {
248 tmp.append (command.gapChar);
249 length--;
250 }
251 }tmp.insert (command.position, command.string[i]);
252 for (var s = 0; s < command.string[i].length; s++) {
253 if (jalview.schemes.ResidueProperties.aaIndex[command.string[i][s].charCodeAt (0)] != 23) {
254 if (!newDSNeeded) {
255 newDSNeeded = true;
256 start = command.seqs[i].findPosition (command.position);
257 end = command.seqs[i].findPosition (command.position + command.number);
258 }if (command.seqs[i].getStart () == start) {
259 newstart--;
260 } else {
261 newend++;
262 }}}
263 command.string[i] = null;
264 }command.seqs[i].setSequence (tmp.toString ());
265 command.seqs[i].setStart (newstart);
266 command.seqs[i].setEnd (newend);
267 if (newDSNeeded) {
268 if (command.seqs[i].getDatasetSequence () != null) {
269 var ds;
270 if (newDSWasNeeded) {
271 ds = command.oldds[i];
272 } else {
273 ds =  new jalview.datamodel.Sequence (command.seqs[i].getName (), jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars, command.seqs[i].getSequenceAsString ()), command.seqs[i].getStart (), command.seqs[i].getEnd ());
274 ds.setDescription (command.seqs[i].getDescription ());
275 }if (command.oldds == null) {
276 command.oldds =  new Array (command.seqs.length);
277 }command.oldds[i] = command.seqs[i].getDatasetSequence ();
278 command.seqs[i].setDatasetSequence (ds);
279 }jalview.commands.EditCommand.adjustFeatures (command, i, start, end, true);
280 }}
281 jalview.commands.EditCommand.adjustAnnotations (command, true, seqWasDeleted, views);
282 command.string = null;
283 }, "jalview.commands.EditCommand.Edit,~A");
284 c$.replace = Clazz.defineMethod (c$, "replace", 
285 function (command) {
286 var tmp;
287 var oldstring;
288 var start = command.position;
289 var end = command.number;
290 command.number = start + command.string[0].length;
291 for (var i = 0; i < command.seqs.length; i++) {
292 var newDSWasNeeded = command.oldds != null && command.oldds[i] != null;
293 oldstring = command.seqs[i].getSequenceAsString ();
294 tmp =  new StringBuffer (oldstring.substring (0, start));
295 tmp.append (command.string[i]);
296 var nogaprep = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars,  String.instantialize (command.string[i]));
297 var ipos = command.seqs[i].findPosition (start) - command.seqs[i].getStart ();
298 tmp.append (oldstring.substring (end));
299 command.seqs[i].setSequence (tmp.toString ());
300 command.string[i] = oldstring.substring (start, end).toCharArray ();
301 var nogapold = jalview.analysis.AlignSeq.extractGaps (jalview.util.Comparison.GapChars,  String.instantialize (command.string[i]));
302 if (!nogaprep.toLowerCase ().equals (nogapold.toLowerCase ())) {
303 if (newDSWasNeeded) {
304 var oldds = command.seqs[i].getDatasetSequence ();
305 command.seqs[i].setDatasetSequence (command.oldds[i]);
306 command.oldds[i] = oldds;
307 } else {
308 if (command.oldds == null) {
309 command.oldds =  new Array (command.seqs.length);
310 }command.oldds[i] = command.seqs[i].getDatasetSequence ();
311 var newds =  new jalview.datamodel.Sequence (command.seqs[i].getDatasetSequence ());
312 var fullseq;
313 var osp = newds.getSequenceAsString ();
314 fullseq = osp.substring (0, ipos) + nogaprep + osp.substring (ipos + nogaprep.length);
315 newds.setSequence (fullseq.toUpperCase ());
316 command.seqs[i].setDatasetSequence (newds);
317 }}tmp = null;
318 oldstring = null;
319 }
320 }, "jalview.commands.EditCommand.Edit");
321 c$.adjustAnnotations = Clazz.defineMethod (c$, "adjustAnnotations", 
322 function (command, insert, modifyVisibility, views) {
323 var annotations = null;
324 if (modifyVisibility && !insert) {
325 command.deletedAnnotationRows =  new java.util.Hashtable ();
326 }if (command.fullAlignmentHeight) {
327 annotations = command.al.getAlignmentAnnotation ();
328 } else {
329 var aSize = 0;
330 var tmp;
331 for (var s = 0; s < command.seqs.length; s++) {
332 if (modifyVisibility) {
333 if (!insert) {
334 tmp = command.seqs[s].getAnnotation ();
335 if (tmp != null) {
336 var alen = tmp.length;
337 for (var aa = 0; aa < tmp.length; aa++) {
338 if (!command.al.deleteAnnotation (tmp[aa])) {
339 tmp[aa] = null;
340 alen--;
341 }}
342 command.seqs[s].setAlignmentAnnotation (null);
343 if (alen != tmp.length) {
344 var saved =  new Array (alen);
345 for (var aa = 0, aapos = 0; aa < tmp.length; aa++) {
346 if (tmp[aa] != null) {
347 saved[aapos++] = tmp[aa];
348 tmp[aa] = null;
349 }}
350 tmp = saved;
351 command.deletedAnnotationRows.put (command.seqs[s], saved);
352 for (var alview = 0; views != null && alview < views.length; alview++) {
353 if (views[alview] !== command.al) {
354 var toremove = views[alview].getAlignmentAnnotation ();
355 if (toremove == null || toremove.length == 0) {
356 continue;
357 }for (var aa = 0; aa < toremove.length; aa++) {
358 if (toremove[aa].sequenceRef === command.seqs[s]) {
359 views[alview].deleteAnnotation (toremove[aa]);
360 }}
361 }}
362 } else {
363 command.deletedAnnotationRows.put (command.seqs[s], tmp);
364 }}} else {
365 if (command.deletedAnnotationRows != null && command.deletedAnnotationRows.containsKey (command.seqs[s])) {
366 var revealed = command.deletedAnnotationRows.get (command.seqs[s]);
367 command.seqs[s].setAlignmentAnnotation (revealed);
368 if (revealed != null) {
369 for (var aa = 0; aa < revealed.length; aa++) {
370 command.al.addAnnotation (revealed[aa]);
371 }
372 for (var aa = 0; aa < revealed.length; aa++) {
373 command.al.setAnnotationIndex (revealed[aa], aa);
374 }
375 for (var vnum = 0; views != null && vnum < views.length; vnum++) {
376 if (views[vnum] !== command.al) {
377 var avwidth = views[vnum].getWidth () + 1;
378 for (var a = 0; a < revealed.length; a++) {
379 var newann =  new jalview.datamodel.AlignmentAnnotation (revealed[a]);
380 command.seqs[s].addAlignmentAnnotation (newann);
381 newann.padAnnotation (avwidth);
382 views[vnum].addAnnotation (newann);
383 views[vnum].setAnnotationIndex (newann, a);
384 }
385 }}
386 }}}continue;
387 }if (command.seqs[s].getAnnotation () == null) {
388 continue;
389 }if (aSize == 0) {
390 annotations = command.seqs[s].getAnnotation ();
391 } else {
392 tmp =  new Array (aSize + command.seqs[s].getAnnotation ().length);
393 System.arraycopy (annotations, 0, tmp, 0, aSize);
394 System.arraycopy (command.seqs[s].getAnnotation (), 0, tmp, aSize, command.seqs[s].getAnnotation ().length);
395 annotations = tmp;
396 }aSize = annotations.length;
397 }
398 }if (annotations == null) {
399 return;
400 }if (!insert) {
401 command.deletedAnnotations =  new java.util.Hashtable ();
402 }var aSize;
403 var temp;
404 for (var a = 0; a < annotations.length; a++) {
405 if (annotations[a].autoCalculated || annotations[a].annotations == null) {
406 continue;
407 }var tSize = 0;
408 aSize = annotations[a].annotations.length;
409 if (insert) {
410 temp =  new Array (aSize + command.number);
411 if (annotations[a].padGaps) {
412 for (var aa = 0; aa < temp.length; aa++) {
413 temp[aa] =  new jalview.datamodel.Annotation (command.gapChar + "", null, ' ', 0);
414 }
415 }} else {
416 if (command.position < aSize) {
417 if (command.position + command.number >= aSize) {
418 tSize = aSize;
419 } else {
420 tSize = aSize - command.number;
421 }} else {
422 tSize = aSize;
423 }if (tSize < 0) {
424 tSize = aSize;
425 }temp =  new Array (tSize);
426 }if (insert) {
427 if (command.position < annotations[a].annotations.length) {
428 System.arraycopy (annotations[a].annotations, 0, temp, 0, command.position);
429 if (command.deletedAnnotations != null && command.deletedAnnotations.containsKey (annotations[a].annotationId)) {
430 var restore = command.deletedAnnotations.get (annotations[a].annotationId);
431 System.arraycopy (restore, 0, temp, command.position, command.number);
432 }System.arraycopy (annotations[a].annotations, command.position, temp, command.position + command.number, aSize - command.position);
433 } else {
434 if (command.deletedAnnotations != null && command.deletedAnnotations.containsKey (annotations[a].annotationId)) {
435 var restore = command.deletedAnnotations.get (annotations[a].annotationId);
436 temp =  new Array (annotations[a].annotations.length + restore.length);
437 System.arraycopy (annotations[a].annotations, 0, temp, 0, annotations[a].annotations.length);
438 System.arraycopy (restore, 0, temp, annotations[a].annotations.length, restore.length);
439 } else {
440 temp = annotations[a].annotations;
441 }}} else {
442 if (tSize != aSize || command.position < 2) {
443 var copylen = Math.min (command.position, annotations[a].annotations.length);
444 if (copylen > 0) {
445 System.arraycopy (annotations[a].annotations, 0, temp, 0, copylen);
446 }var deleted =  new Array (command.number);
447 if (copylen >= command.position) {
448 copylen = Math.min (command.number, annotations[a].annotations.length - command.position);
449 if (copylen > 0) {
450 System.arraycopy (annotations[a].annotations, command.position, deleted, 0, copylen);
451 }}command.deletedAnnotations.put (annotations[a].annotationId, deleted);
452 if (annotations[a].annotations.length > command.position + command.number) {
453 System.arraycopy (annotations[a].annotations, command.position + command.number, temp, command.position, annotations[a].annotations.length - command.position - command.number);
454 }} else {
455 var dSize = aSize - command.position;
456 if (dSize > 0) {
457 var deleted =  new Array (command.number);
458 System.arraycopy (annotations[a].annotations, command.position, deleted, 0, dSize);
459 command.deletedAnnotations.put (annotations[a].annotationId, deleted);
460 tSize = Math.min (annotations[a].annotations.length, command.position);
461 temp =  new Array (tSize);
462 System.arraycopy (annotations[a].annotations, 0, temp, 0, tSize);
463 } else {
464 temp = annotations[a].annotations;
465 }}}annotations[a].annotations = temp;
466 }
467 }, "jalview.commands.EditCommand.Edit,~B,~B,~A");
468 c$.adjustFeatures = Clazz.defineMethod (c$, "adjustFeatures", 
469 function (command, index, i, j, insert) {
470 var seq = command.seqs[index];
471 var sequence = seq.getDatasetSequence ();
472 if (sequence == null) {
473 sequence = seq;
474 }if (insert) {
475 if (command.editedFeatures != null && command.editedFeatures.containsKey (seq)) {
476 sequence.setSequenceFeatures (command.editedFeatures.get (seq));
477 }return;
478 }var sf = sequence.getSequenceFeatures ();
479 if (sf == null) {
480 return;
481 }var oldsf =  new Array (sf.length);
482 var cSize = j - i;
483 for (var s = 0; s < sf.length; s++) {
484 var copy =  new jalview.datamodel.SequenceFeature (sf[s]);
485 oldsf[s] = copy;
486 if (sf[s].getEnd () < i) {
487 continue;
488 }if (sf[s].getBegin () > j) {
489 sf[s].setBegin (copy.getBegin () - cSize);
490 sf[s].setEnd (copy.getEnd () - cSize);
491 continue;
492 }if (sf[s].getBegin () >= i) {
493 sf[s].setBegin (i);
494 }if (sf[s].getEnd () < j) {
495 sf[s].setEnd (j - 1);
496 }sf[s].setEnd (sf[s].getEnd () - (cSize));
497 if (sf[s].getBegin () > sf[s].getEnd ()) {
498 sequence.deleteFeature (sf[s]);
499 }}
500 if (command.editedFeatures == null) {
501 command.editedFeatures =  new java.util.Hashtable ();
502 }command.editedFeatures.put (seq, oldsf);
503 }, "jalview.commands.EditCommand.Edit,~N,~N,~N,~B");
504 Clazz.defineMethod (c$, "getEdits", 
505 function () {
506 return this.edits;
507 });
508 Clazz.defineMethod (c$, "priorState", 
509 function (forUndo) {
510 var result =  new java.util.HashMap ();
511 if (this.getEdits () == null) {
512 return result;
513 }if (forUndo) {
514 for (var e, $e = this.getEdits ().iterator (); $e.hasNext () && ((e = $e.next ()) || true);) {
515 for (var seq, $seq = 0, $$seq = e.getSequences (); $seq < $$seq.length && ((seq = $$seq[$seq]) || true); $seq++) {
516 var ds = seq.getDatasetSequence ();
517 var preEdit = result.get (ds);
518 if (preEdit == null) {
519 preEdit =  new jalview.datamodel.Sequence ("", seq.getSequenceAsString ());
520 preEdit.setDatasetSequence (ds);
521 result.put (ds, preEdit);
522 }}
523 }
524 return result;
525 }var edits =  new jalview.util.ReverseListIterator (this.getEdits ());
526 while (edits.hasNext ()) {
527 var oldEdit = edits.next ();
528 var action = oldEdit.getAction ();
529 var position = oldEdit.getPosition ();
530 var number = oldEdit.getNumber ();
531 var gap = oldEdit.getGapCharacter ();
532 for (var seq, $seq = 0, $$seq = oldEdit.getSequences (); $seq < $$seq.length && ((seq = $$seq[$seq]) || true); $seq++) {
533 var ds = seq.getDatasetSequence ();
534 var preEdit = result.get (ds);
535 if (preEdit == null) {
536 preEdit =  new jalview.datamodel.Sequence ("", seq.getSequenceAsString ());
537 preEdit.setDatasetSequence (ds);
538 result.put (ds, preEdit);
539 }if (ds != null) {
540 if (action === jalview.commands.EditCommand.Action.DELETE_GAP) {
541 preEdit.setSequence ( String.instantialize (jalview.util.StringUtils.insertCharAt (preEdit.getSequence (), position, number, gap)));
542 } else if (action === jalview.commands.EditCommand.Action.INSERT_GAP) {
543 preEdit.setSequence ( String.instantialize (jalview.util.StringUtils.deleteChars (preEdit.getSequence (), position, position + number)));
544 } else {
545 System.err.println ("Can't undo edit action " + action);
546 }}}
547 }
548 return result;
549 }, "~B");
550 Clazz.defineMethod (c$, "getEditIterator", 
551 function (forwards) {
552 if (forwards) {
553 return this.getEdits ().iterator ();
554 } else {
555 return  new jalview.util.ReverseListIterator (this.getEdits ());
556 }}, "~B");
557 c$.$EditCommand$Edit$ = function () {
558 Clazz.pu$h(self.c$);
559 c$ = Clazz.decorateAsClass (function () {
560 Clazz.prepareCallback (this, arguments);
561 this.oldds = null;
562 this.fullAlignmentHeight = false;
563 this.deletedAnnotationRows = null;
564 this.deletedAnnotations = null;
565 this.editedFeatures = null;
566 this.al = null;
567 this.command = null;
568 this.string = null;
569 this.seqs = null;
570 this.alIndex = null;
571 this.position = 0;
572 this.number = 0;
573 this.gapChar = '\0';
574 Clazz.instantialize (this, arguments);
575 }, jalview.commands.EditCommand, "Edit");
576 Clazz.makeConstructor (c$, 
577 function (a, b, c, d, e) {
578 this.command = a;
579 this.seqs = b;
580 this.position = c;
581 this.number = d;
582 this.gapChar = e;
583 }, "jalview.commands.EditCommand.Action,~A,~N,~N,~S");
584 Clazz.makeConstructor (c$, 
585 function (a, b, c, d, e) {
586 this.gapChar = e.getGapCharacter ();
587 this.command = a;
588 this.seqs = b;
589 this.position = c;
590 this.number = d;
591 this.al = e;
592 this.alIndex =  Clazz.newIntArray (b.length, 0);
593 for (var f = 0; f < b.length; f++) {
594 this.alIndex[f] = e.findIndex (b[f]);
595 }
596 this.fullAlignmentHeight = (e.getHeight () == b.length);
597 }, "jalview.commands.EditCommand.Action,~A,~N,~N,jalview.datamodel.AlignmentI");
598 Clazz.makeConstructor (c$, 
599 function (a, b, c, d, e, f) {
600 this.command = a;
601 this.seqs = b;
602 this.position = c;
603 this.number = d;
604 this.al = e;
605 this.gapChar = e.getGapCharacter ();
606 this.string =  Clazz.newCharArray (b.length, '\0');
607 for (var g = 0; g < b.length; g++) {
608 this.string[g] = f.toCharArray ();
609 }
610 this.fullAlignmentHeight = (e.getHeight () == b.length);
611 }, "jalview.commands.EditCommand.Action,~A,~N,~N,jalview.datamodel.AlignmentI,~S");
612 Clazz.defineMethod (c$, "getSequences", 
613 function () {
614 return this.seqs;
615 });
616 Clazz.defineMethod (c$, "getPosition", 
617 function () {
618 return this.position;
619 });
620 Clazz.defineMethod (c$, "getAction", 
621 function () {
622 return this.command;
623 });
624 Clazz.defineMethod (c$, "getNumber", 
625 function () {
626 return this.number;
627 });
628 Clazz.defineMethod (c$, "getGapCharacter", 
629 function () {
630 return this.gapChar;
631 });
632 c$ = Clazz.p0p ();
633 };
634 Clazz.pu$h(self.c$);
635 c$ = Clazz.declareType (jalview.commands.EditCommand, "Action", Enum);
636 (Clazz.isClassDefined ("jalview.commands.EditCommand$Action$1") ? 0 : jalview.commands.EditCommand.$EditCommand$Action$1$ ())Clazz.defineEnumConstant (c$, "INSERT_GAP", 0, [], jalview.commands.EditCommand.Action);
637 (Clazz.isClassDefined ("jalview.commands.EditCommand$Action$2") ? 0 : jalview.commands.EditCommand.$EditCommand$Action$2$ ())Clazz.defineEnumConstant (c$, "DELETE_GAP", 1, [], jalview.commands.EditCommand.Action);
638 (Clazz.isClassDefined ("jalview.commands.EditCommand$Action$3") ? 0 : jalview.commands.EditCommand.$EditCommand$Action$3$ ())Clazz.defineEnumConstant (c$, "CUT", 2, [], jalview.commands.EditCommand.Action);
639 (Clazz.isClassDefined ("jalview.commands.EditCommand$Action$4") ? 0 : jalview.commands.EditCommand.$EditCommand$Action$4$ ())Clazz.defineEnumConstant (c$, "PASTE", 3, [], jalview.commands.EditCommand.Action);
640 (Clazz.isClassDefined ("jalview.commands.EditCommand$Action$5") ? 0 : jalview.commands.EditCommand.$EditCommand$Action$5$ ())Clazz.defineEnumConstant (c$, "REPLACE", 4, [], jalview.commands.EditCommand.Action);
641 (Clazz.isClassDefined ("jalview.commands.EditCommand$Action$6") ? 0 : jalview.commands.EditCommand.$EditCommand$Action$6$ ())Clazz.defineEnumConstant (c$, "INSERT_NUC", 5, [], jalview.commands.EditCommand.Action);
642 c$ = Clazz.p0p ();
643 });