JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / commands / SlideSequencesCommand.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.commands;
22
23 import jalview.datamodel.SequenceI;
24
25 public class SlideSequencesCommand extends EditCommand
26 {
27   boolean gapsInsertedBegin = false;
28
29   public SlideSequencesCommand(String description, SequenceI[] seqsLeft,
30           SequenceI[] seqsRight, int slideSize, char gapChar)
31   {
32     this.description = description;
33
34     int lSize = seqsLeft.length;
35     gapsInsertedBegin = false;
36     int i, j;
37     for (i = 0; i < lSize; i++)
38     {
39       for (j = 0; j < slideSize; j++)
40       {
41         if (!jalview.util.Comparison.isGap(seqsLeft[i].getCharAt(j)))
42         {
43           gapsInsertedBegin = true;
44           break;
45         }
46       }
47     }
48
49     Edit e = null;
50
51     if (!gapsInsertedBegin)
52     {
53       e = new Edit(Action.DELETE_GAP, seqsLeft, 0, slideSize, gapChar);
54       setEdit(e);
55     }
56     else
57     {
58       e = new Edit(Action.INSERT_GAP, seqsRight, 0, slideSize, gapChar);
59       setEdit(e);
60     }
61
62     performEdit(e, null);
63   }
64
65   public boolean getGapsInsertedBegin()
66   {
67     return gapsInsertedBegin;
68   }
69
70   public boolean appendSlideCommand(SlideSequencesCommand command)
71   {
72     boolean same = false;
73
74     if (command.getEdit(0).seqs.length == getEdit(0).seqs.length)
75     {
76       same = true;
77       for (int i = 0; i < command.getEdit(0).seqs.length; i++)
78       {
79         if (getEdit(0).seqs[i] != command.getEdit(0).seqs[i])
80         {
81           same = false;
82         }
83       }
84     }
85
86     if (same)
87     {
88       command.addEdit(getEdit(0));
89     }
90
91     return same;
92   }
93 }