JAL-1432 updated copyright notices
[jalview.git] / src / jalview / commands / SlideSequencesCommand.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
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, SequenceI[] seqsLeft,
28           SequenceI[] seqsRight, int slideSize, char gapChar)
29   {
30     this.description = description;
31
32     int lSize = seqsLeft.length;
33     gapsInsertedBegin = false;
34     int i, j;
35     for (i = 0; i < lSize; i++)
36     {
37       for (j = 0; j < slideSize; j++)
38         if (!jalview.util.Comparison.isGap(seqsLeft[i].getCharAt(j)))
39         {
40           gapsInsertedBegin = true;
41           break;
42         }
43     }
44
45     if (!gapsInsertedBegin)
46       edits = new Edit[]
47       { new Edit(DELETE_GAP, seqsLeft, 0, slideSize, gapChar) };
48     else
49       edits = new Edit[]
50       { new Edit(INSERT_GAP, seqsRight, 0, slideSize, gapChar) };
51
52     performEdit(0, null);
53   }
54
55   public boolean getGapsInsertedBegin()
56   {
57     return gapsInsertedBegin;
58   }
59
60   public boolean appendSlideCommand(SlideSequencesCommand command)
61   {
62     boolean same = false;
63
64     if (command.edits[0].seqs.length == edits[0].seqs.length)
65     {
66       same = true;
67       for (int i = 0; i < command.edits[0].seqs.length; i++)
68       {
69         if (edits[0].seqs[i] != command.edits[0].seqs[i])
70         {
71           same = false;
72         }
73       }
74     }
75
76     if (same)
77     {
78       Edit[] temp = new Edit[command.edits.length + 1];
79       System.arraycopy(command.edits, 0, temp, 0, command.edits.length);
80       command.edits = temp;
81       command.edits[command.edits.length - 1] = edits[0];
82     }
83
84     return same;
85   }
86 }