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