2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.datamodel;
\r
24 public class HiddenSequences
\r
26 Hashtable hiddenSequences;
\r
27 AlignmentI alignment;
\r
29 public HiddenSequences(AlignmentI al)
\r
34 public int getSize()
\r
36 return hiddenSequences == null ? 0 : hiddenSequences.size();
\r
39 public void hideSequence(SequenceI sequence)
\r
41 if(hiddenSequences==null)
\r
42 hiddenSequences = new Hashtable();
\r
44 int alignmentIndex = alignment.findIndex(sequence);
\r
45 alignmentIndex = adjustForHiddenSeqs(alignmentIndex);
\r
47 hiddenSequences.put(new Integer(alignmentIndex), sequence);
\r
49 alignment.deleteSequence(sequence);
\r
52 public void showAll()
\r
54 for(int i=0; i<alignment.getHeight()+hiddenSequences.size(); i++)
\r
58 public void showSequence(int alignmentIndex)
\r
60 SequenceI repSequence = alignment.getSequenceAt(alignmentIndex);
\r
61 if(repSequence!=null
\r
62 && repSequence.getHiddenSequences()==null
\r
63 && alignmentIndex>0)
\r
64 repSequence = alignment.getSequenceAt(alignmentIndex-1);
\r
66 if(repSequence!=null
\r
67 && repSequence.getHiddenSequences()==null)
\r
70 int start = adjustForHiddenSeqs(alignmentIndex-1);
\r
71 int end = adjustForHiddenSeqs(alignmentIndex);
\r
73 for(int index = end; index > start; index--)
\r
75 SequenceI seq = (SequenceI)hiddenSequences.remove(new Integer(
\r
80 alignment.getSequences().insertElementAt(seq, alignmentIndex);
\r
81 if(repSequence!=null)
\r
83 repSequence.showHiddenSequence(seq);
\r
89 public SequenceI getHiddenSequence(int alignmentIndex)
\r
91 return (SequenceI)hiddenSequences.get(new Integer(alignmentIndex));
\r
94 public int findIndexWithoutHiddenSeqs(int alignmentIndex)
\r
98 while(index <= alignmentIndex)
\r
100 if(hiddenSequences.containsKey(new Integer(index)))
\r
107 return (alignmentIndex - hiddenSeqs) ;
\r
110 public int adjustForHiddenSeqs(int alignmentIndex)
\r
113 while(index <= alignmentIndex)
\r
115 if(hiddenSequences.containsKey(new Integer(index)))
\r
122 return alignmentIndex ;
\r