refactored do and undo() method to take array of alignments for operations that resul...
[jalview.git] / src / jalview / commands / SlideSequencesCommand.java
1
2 /*
3 * Jalview - A Sequence Alignment Editor and Viewer
4 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19 */
20
21 package jalview.commands;
22
23 import jalview.datamodel.*;
24
25 public class SlideSequencesCommand extends EditCommand
26 {
27   boolean gapsInsertedBegin = false;
28
29   public SlideSequencesCommand(String description,
30                                SequenceI[] seqsLeft,
31                                SequenceI[] seqsRight,
32                                int slideSize,
33                                char gapChar)
34   {
35     this.description = description;
36
37     int lSize = seqsLeft.length;
38     gapsInsertedBegin = false;
39     int i, j;
40     for (i = 0; i < lSize; i++)
41     {
42       for (j = 0; j < slideSize; j++)
43         if (!jalview.util.Comparison.isGap(seqsLeft[i].getCharAt(j)))
44         {
45           gapsInsertedBegin = true;
46           break;
47         }
48     }
49
50     if (!gapsInsertedBegin)
51       edits = new Edit[]
52           {  new Edit(DELETE_GAP, seqsLeft, 0, slideSize, gapChar)};
53     else
54       edits = new Edit[]
55           {  new Edit(INSERT_GAP, seqsRight, 0, slideSize, gapChar)};
56
57     performEdit(0,null);
58   }
59
60   public boolean getGapsInsertedBegin()
61   {
62     return gapsInsertedBegin;
63   }
64
65   public boolean appendSlideCommand(SlideSequencesCommand command)
66   {
67     boolean same = false;
68
69     if(command.edits[0].seqs.length==edits[0].seqs.length)
70     {
71       same = true;
72       for (int i = 0; i < command.edits[0].seqs.length; i++)
73       {
74         if (edits[0].seqs[i] != command.edits[0].seqs[i])
75         {
76           same = false;
77         }
78       }
79     }
80
81     if(same)
82     {
83       Edit[] temp = new Edit[command.edits.length + 1];
84       System.arraycopy(command.edits, 0, temp, 0, command.edits.length);
85       command.edits = temp;
86       command.edits[command.edits.length - 1] = edits[0];
87     }
88
89     return same;
90   }
91 }
92
93