JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / commands / TrimRegionCommand.js
1 Clazz.declarePackage ("jalview.commands");
2 Clazz.load (["jalview.commands.EditCommand"], "jalview.commands.TrimRegionCommand", null, function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.colSel = null;
5 this.start = null;
6 this.shiftList = null;
7 this.selectionGroup = null;
8 this.deletedHiddenColumns = null;
9 this.columnsDeleted = 0;
10 Clazz.instantialize (this, arguments);
11 }, jalview.commands, "TrimRegionCommand", jalview.commands.EditCommand);
12 Clazz.makeConstructor (c$, 
13 function (description, command, seqs, column, al, colSel, selectedRegion) {
14 Clazz.superConstructor (this, jalview.commands.TrimRegionCommand, []);
15 this.description = description;
16 this.selectionGroup = selectedRegion;
17 this.colSel = colSel;
18 if (command.equalsIgnoreCase (jalview.commands.TrimRegionCommand.TRIM_LEFT)) {
19 if (column == 0) {
20 return;
21 }this.columnsDeleted = column;
22 this.setEdit (Clazz.innerTypeInstance (jalview.commands.EditCommand.Edit, this, null, jalview.commands.EditCommand.Action.CUT, seqs, 0, column, al));
23 } else if (command.equalsIgnoreCase (jalview.commands.TrimRegionCommand.TRIM_RIGHT)) {
24 var width = al.getWidth () - column - 1;
25 if (width < 2) {
26 return;
27 }this.columnsDeleted = width - 1;
28 this.setEdit (Clazz.innerTypeInstance (jalview.commands.EditCommand.Edit, this, null, jalview.commands.EditCommand.Action.CUT, seqs, column + 1, width, al));
29 }var i;
30 var isize = this.getEdit (0).seqs.length;
31 this.start =  Clazz.newIntArray (isize, 0);
32 for (i = 0; i < isize; i++) {
33 this.start[i] = this.getEdit (0).seqs[i].getStart ();
34 }
35 this.performEdit (0, null);
36 }, "~S,~S,~A,~N,jalview.datamodel.AlignmentI,jalview.datamodel.ColumnSelection,jalview.datamodel.SequenceGroup");
37 Clazz.defineMethod (c$, "cut", 
38 function (command) {
39 var column;
40 var j;
41 var jSize = command.seqs.length;
42 for (j = 0; j < jSize; j++) {
43 if (command.position == 0) {
44 column = command.seqs[j].findPosition (command.number);
45 command.seqs[j].setStart (column);
46 } else {
47 column = command.seqs[j].findPosition (command.position) - 1;
48 command.seqs[j].setEnd (column);
49 }}
50 Clazz.superCall (this, jalview.commands.TrimRegionCommand, "cut", [command, null]);
51 if (command.position == 0) {
52 this.deletedHiddenColumns = this.colSel.compensateForEdit (0, command.number);
53 if (this.selectionGroup != null) {
54 this.selectionGroup.adjustForRemoveLeft (command.number);
55 }} else {
56 this.deletedHiddenColumns = this.colSel.compensateForEdit (command.position, command.number);
57 if (this.selectionGroup != null) {
58 this.selectionGroup.adjustForRemoveRight (command.position);
59 }}}, "jalview.commands.EditCommand.Edit");
60 Clazz.defineMethod (c$, "paste", 
61 function (command) {
62 Clazz.superCall (this, jalview.commands.TrimRegionCommand, "paste", [command, null]);
63 var column;
64 var j;
65 var jSize = command.seqs.length;
66 for (j = 0; j < jSize; j++) {
67 if (command.position == 0) {
68 command.seqs[j].setStart (this.start[j]);
69 } else {
70 column = command.seqs[j].findPosition (command.number + command.position) - 1;
71 command.seqs[j].setEnd (column);
72 }}
73 if (command.position == 0) {
74 this.colSel.compensateForEdit (0, -command.number);
75 if (this.selectionGroup != null) {
76 this.selectionGroup.adjustForRemoveLeft (-command.number);
77 }}if (this.deletedHiddenColumns != null) {
78 var region;
79 for (var i = 0; i < this.deletedHiddenColumns.size (); i++) {
80 region = this.deletedHiddenColumns.get (i);
81 this.colSel.hideColumns (region[0], region[1]);
82 }
83 }}, "jalview.commands.EditCommand.Edit");
84 Clazz.overrideMethod (c$, "getSize", 
85 function () {
86 return this.columnsDeleted;
87 });
88 Clazz.defineStatics (c$,
89 "TRIM_LEFT", "TrimLeft",
90 "TRIM_RIGHT", "TrimRight");
91 });