apply gpl development license
[jalview.git] / src / jalview / commands / SlideSequencesCommand.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3  * Copyright (C) 2009 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, 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 }