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