quick fix for nullpointer in column selection when saving jalview project (David...
[jalview.git] / src / jalview / gui / AlignViewport.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 /*
20  * Jalview - A Sequence Alignment Editor and Viewer
21  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
22  *
23  * This program is free software; you can redistribute it and/or
24  * modify it under the terms of the GNU General Public License
25  * as published by the Free Software Foundation; either version 2
26  * of the License, or (at your option) any later version.
27  *
28  * This program is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License
34  * along with this program; if not, write to the Free Software
35  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
36  */
37 package jalview.gui;
38
39 import java.util.*;
40
41 import java.awt.*;
42
43 import jalview.analysis.*;
44
45 import jalview.bin.*;
46
47 import jalview.datamodel.*;
48
49 import jalview.schemes.*;
50 import jalview.structure.SelectionSource;
51 import jalview.structure.StructureSelectionManager;
52
53 /**
54  * DOCUMENT ME!
55  * 
56  * @author $author$
57  * @version $Revision$
58  */
59 public class AlignViewport implements SelectionSource
60 {
61   private static final int RIGHT_JUSTIFY = 1;
62
63   int startRes;
64
65   int endRes;
66
67   int startSeq;
68
69   int endSeq;
70
71   boolean showJVSuffix = true;
72
73   boolean showText = true;
74
75   boolean showColourText = false;
76
77   boolean showBoxes = true;
78
79   boolean wrapAlignment = false;
80
81   boolean renderGaps = true;
82
83   boolean showSequenceFeatures = false;
84
85   boolean showAnnotation = true;
86
87   boolean colourAppliesToAllGroups = true;
88
89   ColourSchemeI globalColourScheme = null;
90
91   boolean conservationColourSelected = false;
92
93   boolean abovePIDThreshold = false;
94
95   SequenceGroup selectionGroup;
96
97   int charHeight;
98
99   int charWidth;
100
101   boolean validCharWidth;
102
103   int wrappedWidth;
104
105   Font font;
106
107   boolean seqNameItalics;
108
109   AlignmentI alignment;
110
111   ColumnSelection colSel = new ColumnSelection();
112
113   int threshold;
114
115   int increment;
116
117   NJTree currentTree = null;
118
119   boolean scaleAboveWrapped = false;
120
121   boolean scaleLeftWrapped = true;
122
123   boolean scaleRightWrapped = true;
124
125   boolean hasHiddenColumns = false;
126
127   boolean hasHiddenRows = false;
128
129   boolean showHiddenMarkers = true;
130
131   boolean cursorMode = false;
132
133   // The following vector holds the features which are
134   // currently visible, in the correct order or rendering
135   Hashtable featuresDisplayed = null;
136
137   /** DOCUMENT ME!! */
138   public Hashtable[] hconsensus;
139
140   AlignmentAnnotation consensus;
141
142   AlignmentAnnotation conservation;
143
144   AlignmentAnnotation quality;
145   AlignmentAnnotation[] groupConsensus;
146   AlignmentAnnotation[] groupConservation;
147   
148   boolean autoCalculateConsensus = true;
149
150   /** DOCUMENT ME!! */
151   public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
152
153   // JBPNote Prolly only need this in the applet version.
154   private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
155           this);
156
157   boolean ignoreGapsInConsensusCalculation = false;
158
159   boolean isDataset = false;
160
161   boolean antiAlias = false;
162
163   boolean padGaps = false;
164
165   Rectangle explodedPosition;
166
167   String viewName;
168
169   String sequenceSetID;
170
171   boolean gatherViewsHere = false;
172
173   Stack historyList = new Stack();
174
175   Stack redoList = new Stack();
176
177   Hashtable sequenceColours;
178
179   int thresholdTextColour = 0;
180
181   Color textColour = Color.black;
182
183   Color textColour2 = Color.white;
184
185   boolean rightAlignIds = false;
186
187   Hashtable hiddenRepSequences;
188
189   boolean sortByTree;
190
191   /**
192    * Creates a new AlignViewport object.
193    * 
194    * @param al alignment to view
195    */
196   public AlignViewport(AlignmentI al)
197   {
198     setAlignment(al);
199     init();
200   }
201   /**
202    * Create a new AlignViewport object with a specific sequence set ID
203    * @param al
204    * @param seqsetid (may be null - but potential for ambiguous constructor exception)
205    */
206   public AlignViewport(AlignmentI al, String seqsetid)
207   {
208     this(al,seqsetid,null);
209   }
210   public AlignViewport(AlignmentI al, String seqsetid, String viewid)
211   {
212     sequenceSetID = seqsetid;
213     viewId = viewid;
214     // TODO remove these once 2.4.VAMSAS release finished
215     if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
216     if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
217     setAlignment(al);
218     init();
219   }
220
221   /**
222    * Create a new AlignViewport with hidden regions
223    * 
224    * @param al
225    *                AlignmentI
226    * @param hiddenColumns
227    *                ColumnSelection
228    */
229   public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
230   {
231     setAlignment(al);
232     if (hiddenColumns != null)
233     {
234       this.colSel = hiddenColumns;
235       if (hiddenColumns.getHiddenColumns() != null && hiddenColumns.getHiddenColumns().size()>0)
236       {
237         hasHiddenColumns = true;
238       } else {
239         hasHiddenColumns = false;
240       }
241     }
242     init();
243   }
244   /**
245    * New viewport with hidden columns and an existing sequence set id
246    * @param al
247    * @param hiddenColumns
248    * @param seqsetid (may be null)
249    */
250   public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid)
251   {
252     this(al,hiddenColumns,seqsetid,null);
253   }
254   /**
255    * New viewport with hidden columns and an existing sequence set id and viewid
256    * @param al
257    * @param hiddenColumns
258    * @param seqsetid (may be null)
259    * @param viewid (may be null)
260    */
261   public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid, String viewid)
262   {
263     sequenceSetID = seqsetid;
264     viewId = viewid;
265     // TODO remove these once 2.4.VAMSAS release finished
266     if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
267     if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
268     setAlignment(al);
269     if (hiddenColumns != null)
270     {
271       this.colSel = hiddenColumns;
272       if (hiddenColumns.getHiddenColumns() != null && hiddenColumns.getHiddenColumns().size()>0)
273       {
274         hasHiddenColumns = true;
275       } else {
276         hasHiddenColumns = false;
277       }
278     }
279     init();
280   }
281
282   void init()
283   {
284     this.startRes = 0;
285     this.endRes = alignment.getWidth() - 1;
286     this.startSeq = 0;
287     this.endSeq = alignment.getHeight() - 1;
288
289     antiAlias = Cache.getDefault("ANTI_ALIAS", false);
290
291     showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
292     showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
293
294     rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
295     centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
296     autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
297
298     padGaps = Cache.getDefault("PAD_GAPS", true);
299     shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP",true);
300     showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP",true);
301     
302     String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
303     String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
304     String fontSize = Cache.getDefault("FONT_SIZE", "10");
305
306     seqNameItalics = Cache.getDefault("ID_ITALICS", true);
307
308     int style = 0;
309
310     if (fontStyle.equals("bold"))
311     {
312       style = 1;
313     }
314     else if (fontStyle.equals("italic"))
315     {
316       style = 2;
317     }
318
319     setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
320
321     alignment
322             .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
323
324     // We must set conservation and consensus before setting colour,
325     // as Blosum and Clustal require this to be done
326     if (hconsensus == null && !isDataset)
327     {
328       if (!alignment.isNucleotide())
329       {
330         conservation = new AlignmentAnnotation("Conservation",
331                 "Conservation of total alignment less than " + ConsPercGaps
332                         + "% gaps", new Annotation[1], 0f, 11f,
333                 AlignmentAnnotation.BAR_GRAPH);
334         conservation.hasText = true;
335         conservation.autoCalculated = true;
336
337         if (Cache.getDefault("SHOW_CONSERVATION", true))
338         {
339           alignment.addAnnotation(conservation);
340         }
341
342         if (Cache.getDefault("SHOW_QUALITY", true))
343         {
344           quality = new AlignmentAnnotation("Quality",
345                   "Alignment Quality based on Blosum62 scores",
346                   new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
347           quality.hasText = true;
348           quality.autoCalculated = true;
349
350           alignment.addAnnotation(quality);
351         }
352       }
353       // TODO: add menu option action that nulls or creates consensus object depending on if the user wants to see the annotation or not in a specific alignment
354       consensus = new AlignmentAnnotation("Consensus", "PID",
355               new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
356       consensus.hasText = true;
357       consensus.autoCalculated = true;
358
359       if (Cache.getDefault("SHOW_IDENTITY", true))
360       {
361         alignment.addAnnotation(consensus);
362       }
363     }
364
365     if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
366     {
367       globalColourScheme = ColourSchemeProperty.getColour(alignment,
368               jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
369
370       if (globalColourScheme instanceof UserColourScheme)
371       {
372         globalColourScheme = UserDefinedColours.loadDefaultColours();
373         ((UserColourScheme) globalColourScheme).setThreshold(0,
374                 getIgnoreGapsConsensus());
375       }
376
377       if (globalColourScheme != null)
378       {
379         globalColourScheme.setConsensus(hconsensus);
380       }
381     }
382
383     wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
384     showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED", false);
385     sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
386   }
387
388   /**
389    * set the flag
390    * 
391    * @param b
392    *             features are displayed if true
393    */
394   public void setShowSequenceFeatures(boolean b)
395   {
396     showSequenceFeatures = b;
397   }
398
399   public boolean getShowSequenceFeatures()
400   {
401     return showSequenceFeatures;
402   }
403
404   ConservationThread conservationThread;
405
406   ConsensusThread consensusThread;
407
408   boolean consUpdateNeeded = false;
409
410   static boolean UPDATING_CONSENSUS = false;
411
412   static boolean UPDATING_CONSERVATION = false;
413
414   boolean updatingConsensus = false;
415
416   boolean updatingConservation = false;
417
418   /**
419    * centre columnar annotation labels in displayed alignment annotation TODO:
420    * add to jalviewXML and annotation display settings
421    */
422   boolean centreColumnLabels = false;
423
424   private boolean showdbrefs;
425
426   private boolean shownpfeats;
427
428   /**
429    * consensus annotation includes all percentage for all symbols in column
430    */
431   private boolean includeAllConsensusSymbols=true;
432
433   /**
434    * trigger update of conservation annotation
435    */
436   public void updateConservation(final AlignmentPanel ap)
437   {
438     // see note in mantis : issue number 8585
439     if (alignment.isNucleotide() || conservation == null || !autoCalculateConsensus)
440     {
441       return;
442     }
443
444     conservationThread = new ConservationThread(this, ap);
445     conservationThread.start();
446   }
447
448   /**
449    * trigger update of consensus annotation
450    */
451   public void updateConsensus(final AlignmentPanel ap)
452   {
453     // see note in mantis : issue number 8585
454     if (consensus == null || !autoCalculateConsensus)
455     {
456       return;
457     }
458     consensusThread = new ConsensusThread(ap);
459     consensusThread.start();
460   }
461
462   class ConsensusThread extends Thread
463   {
464     AlignmentPanel ap;
465
466     public ConsensusThread(AlignmentPanel ap)
467     {
468       this.ap = ap;
469     }
470
471     public void run()
472     {
473       updatingConsensus = true;
474       while (UPDATING_CONSENSUS)
475       {
476         try
477         {
478           if (ap != null)
479           {
480             ap.paintAlignment(false);
481           }
482
483           Thread.sleep(200);
484         } catch (Exception ex)
485         {
486           ex.printStackTrace();
487         }
488       }
489
490       UPDATING_CONSENSUS = true;
491
492       try
493       {
494         int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
495                                                                       // pointer
496                                                                       // possibility
497                                                                       // here.
498         if (aWidth < 0)
499         {
500           return;
501         }
502
503         consensus.annotations = null;
504         consensus.annotations = new Annotation[aWidth];
505
506         hconsensus = new Hashtable[aWidth];
507         AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
508                 .getWidth(), hconsensus, includeAllConsensusSymbols);
509         AAFrequency.completeConsensus(consensus,hconsensus,0,aWidth,ignoreGapsInConsensusCalculation, includeAllConsensusSymbols);
510         
511         if (globalColourScheme != null)
512         {
513           globalColourScheme.setConsensus(hconsensus);
514         }
515
516       } catch (OutOfMemoryError error)
517       {
518         alignment.deleteAnnotation(consensus);
519
520         consensus = null;
521         hconsensus = null;
522         new OOMWarning("calculating consensus", error);
523       }
524       UPDATING_CONSENSUS = false;
525       updatingConsensus = false;
526
527       if (ap != null)
528       {
529         ap.paintAlignment(true);
530       }
531     }
532   }
533
534   /**
535    * get the consensus sequence as displayed under the PID consensus annotation
536    * row.
537    * 
538    * @return consensus sequence as a new sequence object
539    */
540   public SequenceI getConsensusSeq()
541   {
542     if (consensus == null)
543     {
544       updateConsensus(null);
545     }
546     if (consensus == null)
547     {
548       return null;
549     }
550     StringBuffer seqs = new StringBuffer();
551     for (int i = 0; i < consensus.annotations.length; i++)
552     {
553       if (consensus.annotations[i] != null)
554       {
555         if (consensus.annotations[i].description.charAt(0) == '[')
556         {
557           seqs.append(consensus.annotations[i].description.charAt(1));
558         }
559         else
560         {
561           seqs.append(consensus.annotations[i].displayCharacter);
562         }
563       }
564     }
565
566     SequenceI sq = new Sequence("Consensus", seqs.toString());
567     sq.setDescription("Percentage Identity Consensus "
568             + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
569     return sq;
570   }
571
572   /**
573    * DOCUMENT ME!
574    * 
575    * @return DOCUMENT ME!
576    */
577   public SequenceGroup getSelectionGroup()
578   {
579     return selectionGroup;
580   }
581
582   /**
583    * DOCUMENT ME!
584    * 
585    * @param sg
586    *                DOCUMENT ME!
587    */
588   public void setSelectionGroup(SequenceGroup sg)
589   {
590     selectionGroup = sg;    
591   }
592
593   /**
594    * DOCUMENT ME!
595    * 
596    * @return DOCUMENT ME!
597    */
598   public boolean getConservationSelected()
599   {
600     return conservationColourSelected;
601   }
602
603   /**
604    * DOCUMENT ME!
605    * 
606    * @param b
607    *                DOCUMENT ME!
608    */
609   public void setConservationSelected(boolean b)
610   {
611     conservationColourSelected = b;
612   }
613
614   /**
615    * DOCUMENT ME!
616    * 
617    * @return DOCUMENT ME!
618    */
619   public boolean getAbovePIDThreshold()
620   {
621     return abovePIDThreshold;
622   }
623
624   /**
625    * DOCUMENT ME!
626    * 
627    * @param b
628    *                DOCUMENT ME!
629    */
630   public void setAbovePIDThreshold(boolean b)
631   {
632     abovePIDThreshold = b;
633   }
634
635   /**
636    * DOCUMENT ME!
637    * 
638    * @return DOCUMENT ME!
639    */
640   public int getStartRes()
641   {
642     return startRes;
643   }
644
645   /**
646    * DOCUMENT ME!
647    * 
648    * @return DOCUMENT ME!
649    */
650   public int getEndRes()
651   {
652     return endRes;
653   }
654
655   /**
656    * DOCUMENT ME!
657    * 
658    * @return DOCUMENT ME!
659    */
660   public int getStartSeq()
661   {
662     return startSeq;
663   }
664
665   /**
666    * DOCUMENT ME!
667    * 
668    * @param cs
669    *                DOCUMENT ME!
670    */
671   public void setGlobalColourScheme(ColourSchemeI cs)
672   {
673     globalColourScheme = cs;
674   }
675
676   /**
677    * DOCUMENT ME!
678    * 
679    * @return DOCUMENT ME!
680    */
681   public ColourSchemeI getGlobalColourScheme()
682   {
683     return globalColourScheme;
684   }
685
686   /**
687    * DOCUMENT ME!
688    * 
689    * @param res
690    *                DOCUMENT ME!
691    */
692   public void setStartRes(int res)
693   {
694     this.startRes = res;
695   }
696
697   /**
698    * DOCUMENT ME!
699    * 
700    * @param seq
701    *                DOCUMENT ME!
702    */
703   public void setStartSeq(int seq)
704   {
705     this.startSeq = seq;
706   }
707
708   /**
709    * DOCUMENT ME!
710    * 
711    * @param res
712    *                DOCUMENT ME!
713    */
714   public void setEndRes(int res)
715   {
716     if (res > (alignment.getWidth() - 1))
717     {
718       // log.System.out.println(" Corrected res from " + res + " to maximum " +
719       // (alignment.getWidth()-1));
720       res = alignment.getWidth() - 1;
721     }
722
723     if (res < 0)
724     {
725       res = 0;
726     }
727
728     this.endRes = res;
729   }
730
731   /**
732    * DOCUMENT ME!
733    * 
734    * @param seq
735    *                DOCUMENT ME!
736    */
737   public void setEndSeq(int seq)
738   {
739     if (seq > alignment.getHeight())
740     {
741       seq = alignment.getHeight();
742     }
743
744     if (seq < 0)
745     {
746       seq = 0;
747     }
748
749     this.endSeq = seq;
750   }
751
752   /**
753    * DOCUMENT ME!
754    * 
755    * @return DOCUMENT ME!
756    */
757   public int getEndSeq()
758   {
759     return endSeq;
760   }
761
762   /**
763    * DOCUMENT ME!
764    * 
765    * @param f
766    *                DOCUMENT ME!
767    */
768   public void setFont(Font f)
769   {
770     font = f;
771
772     Container c = new Container();
773
774     java.awt.FontMetrics fm = c.getFontMetrics(font);
775     setCharHeight(fm.getHeight());
776     setCharWidth(fm.charWidth('M'));
777     validCharWidth = true;
778   }
779
780   /**
781    * DOCUMENT ME!
782    * 
783    * @return DOCUMENT ME!
784    */
785   public Font getFont()
786   {
787     return font;
788   }
789
790   /**
791    * DOCUMENT ME!
792    * 
793    * @param w
794    *                DOCUMENT ME!
795    */
796   public void setCharWidth(int w)
797   {
798     this.charWidth = w;
799   }
800
801   /**
802    * DOCUMENT ME!
803    * 
804    * @return DOCUMENT ME!
805    */
806   public int getCharWidth()
807   {
808     return charWidth;
809   }
810
811   /**
812    * DOCUMENT ME!
813    * 
814    * @param h
815    *                DOCUMENT ME!
816    */
817   public void setCharHeight(int h)
818   {
819     this.charHeight = h;
820   }
821
822   /**
823    * DOCUMENT ME!
824    * 
825    * @return DOCUMENT ME!
826    */
827   public int getCharHeight()
828   {
829     return charHeight;
830   }
831
832   /**
833    * DOCUMENT ME!
834    * 
835    * @param w
836    *                DOCUMENT ME!
837    */
838   public void setWrappedWidth(int w)
839   {
840     this.wrappedWidth = w;
841   }
842
843   /**
844    * DOCUMENT ME!
845    * 
846    * @return DOCUMENT ME!
847    */
848   public int getWrappedWidth()
849   {
850     return wrappedWidth;
851   }
852
853   /**
854    * DOCUMENT ME!
855    * 
856    * @return DOCUMENT ME!
857    */
858   public AlignmentI getAlignment()
859   {
860     return alignment;
861   }
862
863   /**
864    * DOCUMENT ME!
865    * 
866    * @param align
867    *                DOCUMENT ME!
868    */
869   public void setAlignment(AlignmentI align)
870   {
871     if (alignment != null && alignment.getCodonFrames() != null)
872     {
873       StructureSelectionManager.getStructureSelectionManager()
874               .removeMappings(alignment.getCodonFrames());
875     }
876     this.alignment = align;
877     if (alignment.getCodonFrames() != null)
878     {
879       StructureSelectionManager.getStructureSelectionManager().addMappings(
880               alignment.getCodonFrames());
881     }
882   }
883
884   /**
885    * DOCUMENT ME!
886    * 
887    * @param state
888    *                DOCUMENT ME!
889    */
890   public void setWrapAlignment(boolean state)
891   {
892     wrapAlignment = state;
893   }
894
895   /**
896    * DOCUMENT ME!
897    * 
898    * @param state
899    *                DOCUMENT ME!
900    */
901   public void setShowText(boolean state)
902   {
903     showText = state;
904   }
905
906   /**
907    * DOCUMENT ME!
908    * 
909    * @param state
910    *                DOCUMENT ME!
911    */
912   public void setRenderGaps(boolean state)
913   {
914     renderGaps = state;
915   }
916
917   /**
918    * DOCUMENT ME!
919    * 
920    * @return DOCUMENT ME!
921    */
922   public boolean getColourText()
923   {
924     return showColourText;
925   }
926
927   /**
928    * DOCUMENT ME!
929    * 
930    * @param state
931    *                DOCUMENT ME!
932    */
933   public void setColourText(boolean state)
934   {
935     showColourText = state;
936   }
937
938   /**
939    * DOCUMENT ME!
940    * 
941    * @param state
942    *                DOCUMENT ME!
943    */
944   public void setShowBoxes(boolean state)
945   {
946     showBoxes = state;
947   }
948
949   /**
950    * DOCUMENT ME!
951    * 
952    * @return DOCUMENT ME!
953    */
954   public boolean getWrapAlignment()
955   {
956     return wrapAlignment;
957   }
958
959   /**
960    * DOCUMENT ME!
961    * 
962    * @return DOCUMENT ME!
963    */
964   public boolean getShowText()
965   {
966     return showText;
967   }
968
969   /**
970    * DOCUMENT ME!
971    * 
972    * @return DOCUMENT ME!
973    */
974   public boolean getShowBoxes()
975   {
976     return showBoxes;
977   }
978
979   /**
980    * DOCUMENT ME!
981    * 
982    * @return DOCUMENT ME!
983    */
984   public char getGapCharacter()
985   {
986     return getAlignment().getGapCharacter();
987   }
988
989   /**
990    * DOCUMENT ME!
991    * 
992    * @param gap
993    *                DOCUMENT ME!
994    */
995   public void setGapCharacter(char gap)
996   {
997     if (getAlignment() != null)
998     {
999       getAlignment().setGapCharacter(gap);
1000     }
1001   }
1002
1003   /**
1004    * DOCUMENT ME!
1005    * 
1006    * @param thresh
1007    *                DOCUMENT ME!
1008    */
1009   public void setThreshold(int thresh)
1010   {
1011     threshold = thresh;
1012   }
1013
1014   /**
1015    * DOCUMENT ME!
1016    * 
1017    * @return DOCUMENT ME!
1018    */
1019   public int getThreshold()
1020   {
1021     return threshold;
1022   }
1023
1024   /**
1025    * DOCUMENT ME!
1026    * 
1027    * @param inc
1028    *                DOCUMENT ME!
1029    */
1030   public void setIncrement(int inc)
1031   {
1032     increment = inc;
1033   }
1034
1035   /**
1036    * DOCUMENT ME!
1037    * 
1038    * @return DOCUMENT ME!
1039    */
1040   public int getIncrement()
1041   {
1042     return increment;
1043   }
1044
1045   /**
1046    * DOCUMENT ME!
1047    * 
1048    * @return DOCUMENT ME!
1049    */
1050   public ColumnSelection getColumnSelection()
1051   {
1052     return colSel;
1053   }
1054
1055   /**
1056    * DOCUMENT ME!
1057    * 
1058    * @param tree
1059    *                DOCUMENT ME!
1060    */
1061   public void setCurrentTree(NJTree tree)
1062   {
1063     currentTree = tree;
1064   }
1065
1066   /**
1067    * DOCUMENT ME!
1068    * 
1069    * @return DOCUMENT ME!
1070    */
1071   public NJTree getCurrentTree()
1072   {
1073     return currentTree;
1074   }
1075
1076   /**
1077    * DOCUMENT ME!
1078    * 
1079    * @param b
1080    *                DOCUMENT ME!
1081    */
1082   public void setColourAppliesToAllGroups(boolean b)
1083   {
1084     colourAppliesToAllGroups = b;
1085   }
1086
1087   /**
1088    * DOCUMENT ME!
1089    * 
1090    * @return DOCUMENT ME!
1091    */
1092   public boolean getColourAppliesToAllGroups()
1093   {
1094     return colourAppliesToAllGroups;
1095   }
1096
1097   /**
1098    * DOCUMENT ME!
1099    * 
1100    * @return DOCUMENT ME!
1101    */
1102   public boolean getShowJVSuffix()
1103   {
1104     return showJVSuffix;
1105   }
1106
1107   /**
1108    * DOCUMENT ME!
1109    * 
1110    * @param b
1111    *                DOCUMENT ME!
1112    */
1113   public void setShowJVSuffix(boolean b)
1114   {
1115     showJVSuffix = b;
1116   }
1117
1118   /**
1119    * DOCUMENT ME!
1120    * 
1121    * @return DOCUMENT ME!
1122    */
1123   public boolean getShowAnnotation()
1124   {
1125     return showAnnotation;
1126   }
1127
1128   /**
1129    * DOCUMENT ME!
1130    * 
1131    * @param b
1132    *                DOCUMENT ME!
1133    */
1134   public void setShowAnnotation(boolean b)
1135   {
1136     showAnnotation = b;
1137   }
1138
1139   /**
1140    * DOCUMENT ME!
1141    * 
1142    * @return DOCUMENT ME!
1143    */
1144   public boolean getScaleAboveWrapped()
1145   {
1146     return scaleAboveWrapped;
1147   }
1148
1149   /**
1150    * DOCUMENT ME!
1151    * 
1152    * @return DOCUMENT ME!
1153    */
1154   public boolean getScaleLeftWrapped()
1155   {
1156     return scaleLeftWrapped;
1157   }
1158
1159   /**
1160    * DOCUMENT ME!
1161    * 
1162    * @return DOCUMENT ME!
1163    */
1164   public boolean getScaleRightWrapped()
1165   {
1166     return scaleRightWrapped;
1167   }
1168
1169   /**
1170    * DOCUMENT ME!
1171    * 
1172    * @param b
1173    *                DOCUMENT ME!
1174    */
1175   public void setScaleAboveWrapped(boolean b)
1176   {
1177     scaleAboveWrapped = b;
1178   }
1179
1180   /**
1181    * DOCUMENT ME!
1182    * 
1183    * @param b
1184    *                DOCUMENT ME!
1185    */
1186   public void setScaleLeftWrapped(boolean b)
1187   {
1188     scaleLeftWrapped = b;
1189   }
1190
1191   /**
1192    * DOCUMENT ME!
1193    * 
1194    * @param b
1195    *                DOCUMENT ME!
1196    */
1197   public void setScaleRightWrapped(boolean b)
1198   {
1199     scaleRightWrapped = b;
1200   }
1201
1202   /**
1203    * Property change listener for changes in alignment
1204    * 
1205    * @param listener
1206    *                DOCUMENT ME!
1207    */
1208   public void addPropertyChangeListener(
1209           java.beans.PropertyChangeListener listener)
1210   {
1211     changeSupport.addPropertyChangeListener(listener);
1212   }
1213
1214   /**
1215    * DOCUMENT ME!
1216    * 
1217    * @param listener
1218    *                DOCUMENT ME!
1219    */
1220   public void removePropertyChangeListener(
1221           java.beans.PropertyChangeListener listener)
1222   {
1223     changeSupport.removePropertyChangeListener(listener);
1224   }
1225
1226   /**
1227    * Property change listener for changes in alignment
1228    * 
1229    * @param prop
1230    *                DOCUMENT ME!
1231    * @param oldvalue
1232    *                DOCUMENT ME!
1233    * @param newvalue
1234    *                DOCUMENT ME!
1235    */
1236   public void firePropertyChange(String prop, Object oldvalue,
1237           Object newvalue)
1238   {
1239     changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1240   }
1241
1242   public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1243   {
1244     ignoreGapsInConsensusCalculation = b;
1245     updateConsensus(ap);
1246     if (globalColourScheme != null)
1247     {
1248       globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1249               ignoreGapsInConsensusCalculation);
1250     }
1251   }
1252
1253   public boolean getIgnoreGapsConsensus()
1254   {
1255     return ignoreGapsInConsensusCalculation;
1256   }
1257
1258   public void setDataset(boolean b)
1259   {
1260     isDataset = b;
1261   }
1262
1263   public boolean isDataset()
1264   {
1265     return isDataset;
1266   }
1267
1268   public void hideSelectedColumns()
1269   {
1270     if (colSel.size() < 1)
1271     {
1272       return;
1273     }
1274
1275     colSel.hideSelectedColumns();
1276     setSelectionGroup(null);
1277
1278     hasHiddenColumns = true;
1279   }
1280
1281   public void hideColumns(int start, int end)
1282   {
1283     if (start == end)
1284     {
1285       colSel.hideColumns(start);
1286     }
1287     else
1288     {
1289       colSel.hideColumns(start, end);
1290     }
1291
1292     hasHiddenColumns = true;
1293   }
1294
1295   public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1296   {
1297     int sSize = sg.getSize();
1298     if (sSize < 2)
1299     {
1300       return;
1301     }
1302
1303     if (hiddenRepSequences == null)
1304     {
1305       hiddenRepSequences = new Hashtable();
1306     }
1307
1308     hiddenRepSequences.put(repSequence, sg);
1309
1310     // Hide all sequences except the repSequence
1311     SequenceI[] seqs = new SequenceI[sSize - 1];
1312     int index = 0;
1313     for (int i = 0; i < sSize; i++)
1314     {
1315       if (sg.getSequenceAt(i) != repSequence)
1316       {
1317         if (index == sSize - 1)
1318         {
1319           return;
1320         }
1321
1322         seqs[index++] = sg.getSequenceAt(i);
1323       }
1324     }
1325     sg.setSeqrep(repSequence);
1326     sg.setHidereps(true);
1327     hideSequence(seqs);
1328
1329   }
1330
1331   public void hideAllSelectedSeqs()
1332   {
1333     if (selectionGroup == null || selectionGroup.getSize() < 1)
1334     {
1335       return;
1336     }
1337
1338     SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1339
1340     hideSequence(seqs);
1341
1342     setSelectionGroup(null);
1343   }
1344
1345   public void hideSequence(SequenceI[] seq)
1346   {
1347     if (seq != null)
1348     {
1349       for (int i = 0; i < seq.length; i++)
1350       {
1351         alignment.getHiddenSequences().hideSequence(seq[i]);
1352       }
1353       hasHiddenRows = true;
1354       firePropertyChange("alignment", null, alignment.getSequences());
1355     }
1356   }
1357
1358   public void showSequence(int index)
1359   {
1360     Vector tmp = alignment.getHiddenSequences().showSequence(index,
1361             hiddenRepSequences);
1362     if (tmp.size() > 0)
1363     {
1364       if (selectionGroup == null)
1365       {
1366         selectionGroup = new SequenceGroup();
1367         selectionGroup.setEndRes(alignment.getWidth() - 1);
1368       }
1369
1370       for (int t = 0; t < tmp.size(); t++)
1371       {
1372         selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1373       }
1374       firePropertyChange("alignment", null, alignment.getSequences());
1375       sendSelection();
1376     }
1377
1378     if (alignment.getHiddenSequences().getSize() < 1)
1379     {
1380       hasHiddenRows = false;
1381     }
1382   }
1383
1384   public void showColumn(int col)
1385   {
1386     colSel.revealHiddenColumns(col);
1387     if (colSel.getHiddenColumns() == null)
1388     {
1389       hasHiddenColumns = false;
1390     }
1391   }
1392
1393   public void showAllHiddenColumns()
1394   {
1395     colSel.revealAllHiddenColumns();
1396     hasHiddenColumns = false;
1397   }
1398
1399   public void showAllHiddenSeqs()
1400   {
1401     if (alignment.getHiddenSequences().getSize() > 0)
1402     {
1403       if (selectionGroup == null)
1404       {
1405         selectionGroup = new SequenceGroup();
1406         selectionGroup.setEndRes(alignment.getWidth() - 1);
1407       }
1408       Vector tmp = alignment.getHiddenSequences().showAll(
1409               hiddenRepSequences);
1410       for (int t = 0; t < tmp.size(); t++)
1411       {
1412         selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1413       }
1414       firePropertyChange("alignment", null, alignment.getSequences());
1415       sendSelection();
1416       hasHiddenRows = false;
1417       hiddenRepSequences = null;
1418     }
1419   }
1420
1421   public void invertColumnSelection()
1422   {
1423     colSel.invertColumnSelection(0, alignment.getWidth());
1424   }
1425
1426   public int adjustForHiddenSeqs(int alignmentIndex)
1427   {
1428     return alignment.getHiddenSequences().adjustForHiddenSeqs(
1429             alignmentIndex);
1430   }
1431
1432   /**
1433    * This method returns an array of new SequenceI objects derived from the
1434    * whole alignment or just the current selection with start and end points
1435    * adjusted
1436    * 
1437    * @note if you need references to the actual SequenceI objects in the
1438    *       alignment or currently selected then use getSequenceSelection()
1439    * @return selection as new sequenceI objects
1440    */
1441   public SequenceI[] getSelectionAsNewSequence()
1442   {
1443     SequenceI[] sequences;
1444
1445     if (selectionGroup == null)
1446     {
1447       sequences = alignment.getSequencesArray();
1448       AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1449       for (int i = 0; i < sequences.length; i++)
1450       {
1451         sequences[i] = new Sequence(sequences[i], annots); // construct new
1452                                                             // sequence with
1453                                                             // subset of visible
1454                                                             // annotation
1455       }
1456     }
1457     else
1458     {
1459       sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1460     }
1461
1462     return sequences;
1463   }
1464
1465   /**
1466    * get the currently selected sequence objects or all the sequences in the
1467    * alignment.
1468    * 
1469    * @return array of references to sequence objects
1470    */
1471   public SequenceI[] getSequenceSelection()
1472   {
1473     SequenceI[] sequences=null;
1474     if (selectionGroup!=null)
1475     {
1476       sequences = selectionGroup.getSequencesInOrder(alignment);
1477     }
1478     if (sequences == null)
1479     {
1480       sequences = alignment.getSequencesArray();
1481     }
1482     return sequences;
1483   }
1484
1485   /**
1486    * This method returns the visible alignment as text, as seen on the GUI, ie
1487    * if columns are hidden they will not be returned in the result. Use this for
1488    * calculating trees, PCA, redundancy etc on views which contain hidden
1489    * columns.
1490    * 
1491    * @return String[]
1492    */
1493   public jalview.datamodel.CigarArray getViewAsCigars(
1494           boolean selectedRegionOnly)
1495   {
1496     CigarArray selection = null;
1497     SequenceI[] seqs = null;
1498     int i, iSize;
1499     int start = 0, end = 0;
1500     if (selectedRegionOnly && selectionGroup != null)
1501     {
1502       iSize = selectionGroup.getSize();
1503       seqs = selectionGroup.getSequencesInOrder(alignment);
1504       start = selectionGroup.getStartRes();
1505       end = selectionGroup.getEndRes(); // inclusive for start and end in
1506                                         // SeqCigar constructor
1507     }
1508     else
1509     {
1510       iSize = alignment.getHeight();
1511       seqs = alignment.getSequencesArray();
1512       end = alignment.getWidth() - 1;
1513     }
1514     SeqCigar[] selseqs = new SeqCigar[iSize];
1515     for (i = 0; i < iSize; i++)
1516     {
1517       selseqs[i] = new SeqCigar(seqs[i], start, end);
1518     }
1519     selection = new CigarArray(selseqs);
1520     // now construct the CigarArray operations
1521     if (hasHiddenColumns)
1522     {
1523       Vector regions = colSel.getHiddenColumns();
1524       int[] region;
1525       int hideStart, hideEnd;
1526       int last = start;
1527       for (int j = 0; last < end & j < regions.size(); j++)
1528       {
1529         region = (int[]) regions.elementAt(j);
1530         hideStart = region[0];
1531         hideEnd = region[1];
1532         // edit hidden regions to selection range
1533         if (hideStart < last)
1534         {
1535           if (hideEnd > last)
1536           {
1537             hideStart = last;
1538           }
1539           else
1540           {
1541             continue;
1542           }
1543         }
1544
1545         if (hideStart > end)
1546         {
1547           break;
1548         }
1549
1550         if (hideEnd > end)
1551         {
1552           hideEnd = end;
1553         }
1554
1555         if (hideStart > hideEnd)
1556         {
1557           break;
1558         }
1559         /**
1560          * form operations...
1561          */
1562         if (last < hideStart)
1563         {
1564           selection.addOperation(CigarArray.M, hideStart - last);
1565         }
1566         selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1567         last = hideEnd + 1;
1568       }
1569       // Final match if necessary.
1570       if (last < end)
1571       {
1572         selection.addOperation(CigarArray.M, end - last + 1);
1573       }
1574     }
1575     else
1576     {
1577       selection.addOperation(CigarArray.M, end - start + 1);
1578     }
1579     return selection;
1580   }
1581
1582   /**
1583    * return a compact representation of the current alignment selection to pass
1584    * to an analysis function
1585    * 
1586    * @param selectedOnly
1587    *                boolean true to just return the selected view
1588    * @return AlignmentView
1589    */
1590   jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1591   {
1592     // JBPNote:
1593     // this is here because the AlignmentView constructor modifies the
1594     // CigarArray
1595     // object. Refactoring of Cigar and alignment view representation should
1596     // be done to remove redundancy.
1597     CigarArray aligview = getViewAsCigars(selectedOnly);
1598     if (aligview != null)
1599     {
1600       return new AlignmentView(aligview,
1601               (selectedOnly && selectionGroup != null) ? selectionGroup
1602                       .getStartRes() : 0);
1603     }
1604     return null;
1605   }
1606
1607   /**
1608    * This method returns the visible alignment as text, as seen on the GUI, ie
1609    * if columns are hidden they will not be returned in the result. Use this for
1610    * calculating trees, PCA, redundancy etc on views which contain hidden
1611    * columns.
1612    * 
1613    * @return String[]
1614    */
1615   public String[] getViewAsString(boolean selectedRegionOnly)
1616   {
1617     String[] selection = null;
1618     SequenceI[] seqs = null;
1619     int i, iSize;
1620     int start = 0, end = 0;
1621     if (selectedRegionOnly && selectionGroup != null)
1622     {
1623       iSize = selectionGroup.getSize();
1624       seqs = selectionGroup.getSequencesInOrder(alignment);
1625       start = selectionGroup.getStartRes();
1626       end = selectionGroup.getEndRes() + 1;
1627     }
1628     else
1629     {
1630       iSize = alignment.getHeight();
1631       seqs = alignment.getSequencesArray();
1632       end = alignment.getWidth();
1633     }
1634
1635     selection = new String[iSize];
1636     if (hasHiddenColumns)
1637     {
1638       selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1639     }
1640     else
1641     {
1642       for (i = 0; i < iSize; i++)
1643       {
1644         selection[i] = seqs[i].getSequenceAsString(start, end);
1645       }
1646
1647     }
1648     return selection;
1649   }
1650
1651   public int[][] getVisibleRegionBoundaries(int min, int max)
1652   {
1653     Vector regions = new Vector();
1654     int start = min;
1655     int end = max;
1656
1657     do
1658     {
1659       if (hasHiddenColumns)
1660       {
1661         if (start == 0)
1662         {
1663           start = colSel.adjustForHiddenColumns(start);
1664         }
1665
1666         end = colSel.getHiddenBoundaryRight(start);
1667         if (start == end)
1668         {
1669           end = max;
1670         }
1671         if (end > max)
1672         {
1673           end = max;
1674         }
1675       }
1676
1677       regions.addElement(new int[]
1678       { start, end });
1679
1680       if (hasHiddenColumns)
1681       {
1682         start = colSel.adjustForHiddenColumns(end);
1683         start = colSel.getHiddenBoundaryLeft(start) + 1;
1684       }
1685     } while (end < max);
1686
1687     int[][] startEnd = new int[regions.size()][2];
1688
1689     regions.copyInto(startEnd);
1690
1691     return startEnd;
1692
1693   }
1694
1695   public boolean getShowHiddenMarkers()
1696   {
1697     return showHiddenMarkers;
1698   }
1699
1700   public void setShowHiddenMarkers(boolean show)
1701   {
1702     showHiddenMarkers = show;
1703   }
1704
1705   public String getSequenceSetId()
1706   {
1707     if (sequenceSetID == null)
1708     {
1709       sequenceSetID = alignment.hashCode() + "";
1710     }
1711
1712     return sequenceSetID;
1713   }
1714   /**
1715    * unique viewId for synchronizing state with stored Jalview Project 
1716    * 
1717    */
1718   private String viewId=null;
1719
1720   
1721   public String getViewId()
1722   {
1723     if (viewId==null)
1724     {
1725       viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1726     }
1727     return viewId;
1728   }
1729   
1730   public void alignmentChanged(AlignmentPanel ap)
1731   {
1732     if (padGaps)
1733     {
1734       alignment.padGaps();
1735     }
1736     if (hconsensus != null && autoCalculateConsensus)
1737     {
1738       updateConservation(ap);
1739     }
1740     if (autoCalculateConsensus)
1741     {
1742       updateConsensus(ap);
1743     }
1744
1745     // Reset endRes of groups if beyond alignment width
1746     int alWidth = alignment.getWidth();
1747     Vector groups = alignment.getGroups();
1748     if (groups != null)
1749     {
1750       for (int i = 0; i < groups.size(); i++)
1751       {
1752         SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1753         if (sg.getEndRes() > alWidth)
1754         {
1755           sg.setEndRes(alWidth - 1);
1756         }
1757       }
1758     }
1759
1760     if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1761     {
1762       selectionGroup.setEndRes(alWidth - 1);
1763     }
1764
1765     resetAllColourSchemes();
1766
1767     // alignment.adjustSequenceAnnotations();
1768   }
1769
1770   void resetAllColourSchemes()
1771   {
1772     ColourSchemeI cs = globalColourScheme;
1773     if (cs != null)
1774     {
1775       if (cs instanceof ClustalxColourScheme)
1776       {
1777         ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1778                 alignment.getWidth());
1779       }
1780
1781       cs.setConsensus(hconsensus);
1782       if (cs.conservationApplied())
1783       {
1784         Alignment al = (Alignment) alignment;
1785         Conservation c = new Conservation("All",
1786                 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1787                         .getWidth() - 1);
1788         c.calculate();
1789         c.verdict(false, ConsPercGaps);
1790
1791         cs.setConservation(c);
1792       }
1793     }
1794
1795     int s, sSize = alignment.getGroups().size();
1796     for (s = 0; s < sSize; s++)
1797     {
1798       SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1799       if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1800       {
1801         ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1802                 .getSequences(hiddenRepSequences), sg.getWidth());
1803       }
1804       sg.recalcConservation();
1805     }
1806   }
1807
1808   public Color getSequenceColour(SequenceI seq)
1809   {
1810     if (sequenceColours == null || !sequenceColours.containsKey(seq))
1811     {
1812       return Color.white;
1813     }
1814     else
1815     {
1816       return (Color) sequenceColours.get(seq);
1817     }
1818   }
1819
1820   public void setSequenceColour(SequenceI seq, Color col)
1821   {
1822     if (sequenceColours == null)
1823     {
1824       sequenceColours = new Hashtable();
1825     }
1826
1827     if (col == null)
1828     {
1829       sequenceColours.remove(seq);
1830     }
1831     else
1832     {
1833       sequenceColours.put(seq, col);
1834     }
1835   }
1836
1837   /**
1838    * returns the visible column regions of the alignment
1839    * 
1840    * @param selectedRegionOnly
1841    *                true to just return the contigs intersecting with the
1842    *                selected area
1843    * @return
1844    */
1845   public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1846   {
1847     int[] viscontigs = null;
1848     int start = 0, end = 0;
1849     if (selectedRegionOnly && selectionGroup != null)
1850     {
1851       start = selectionGroup.getStartRes();
1852       end = selectionGroup.getEndRes() + 1;
1853     }
1854     else
1855     {
1856       end = alignment.getWidth();
1857     }
1858     viscontigs = colSel.getVisibleContigs(start, end);
1859     return viscontigs;
1860   }
1861
1862   /**
1863    * get hash of undo and redo list for the alignment
1864    * 
1865    * @return long[] { historyList.hashCode, redoList.hashCode };
1866    */
1867   public long[] getUndoRedoHash()
1868   {
1869     if (historyList == null || redoList == null)
1870       return new long[]
1871       { -1, -1 };
1872     return new long[]
1873     { historyList.hashCode(), this.redoList.hashCode() };
1874   }
1875
1876   /**
1877    * test if a particular set of hashcodes are different to the hashcodes for
1878    * the undo and redo list.
1879    * 
1880    * @param undoredo
1881    *                the stored set of hashcodes as returned by getUndoRedoHash
1882    * @return true if the hashcodes differ (ie the alignment has been edited) or
1883    *         the stored hashcode array differs in size
1884    */
1885   public boolean isUndoRedoHashModified(long[] undoredo)
1886   {
1887     if (undoredo == null)
1888     {
1889       return true;
1890     }
1891     long[] cstate = getUndoRedoHash();
1892     if (cstate.length != undoredo.length)
1893     {
1894       return true;
1895     }
1896
1897     for (int i = 0; i < cstate.length; i++)
1898     {
1899       if (cstate[i] != undoredo[i])
1900       {
1901         return true;
1902       }
1903     }
1904     return false;
1905   }
1906
1907   public boolean getCentreColumnLabels()
1908   {
1909     return centreColumnLabels;
1910   }
1911
1912   public void setCentreColumnLabels(boolean centrecolumnlabels)
1913   {
1914     centreColumnLabels = centrecolumnlabels;
1915   }
1916
1917   public void updateSequenceIdColours()
1918   {
1919     Vector groups = alignment.getGroups();
1920     if (sequenceColours == null)
1921     {
1922       sequenceColours = new Hashtable();
1923     }
1924     for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1925     {
1926       SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1927       if (sg.idColour != null)
1928       {
1929         Vector sqs = sg.getSequences(hiddenRepSequences);
1930         for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1931         {
1932           sequenceColours.put(sqs.elementAt(s), sg.idColour);
1933         }
1934       }
1935     }
1936   }
1937
1938   /**
1939    *  enable or disable the display of Database Cross References in the sequence ID tooltip
1940    */ 
1941   public void setShowDbRefs(boolean show)
1942   {
1943     showdbrefs=show;
1944   }
1945
1946   /**
1947    * 
1948    * @return true if Database References are to be displayed on tooltips.
1949    */
1950   public boolean isShowDbRefs()
1951   {
1952     return showdbrefs;
1953   }
1954
1955   /**
1956    * 
1957    * @return true if Non-positional features are to be displayed on tooltips.
1958    */
1959   public boolean isShowNpFeats()
1960   {
1961     return shownpfeats;
1962   }
1963   /**
1964    * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip 
1965    * @param show 
1966    */
1967   public void setShowNpFeats(boolean show)
1968   {
1969     shownpfeats=show;
1970   }
1971   /**
1972    * 
1973    * @return true if view has hidden rows
1974    */
1975   public boolean hasHiddenRows()
1976   {
1977     return hasHiddenRows;
1978   }
1979   /**
1980    * 
1981    * @return true if view has hidden columns
1982    */
1983   public boolean hasHiddenColumns()
1984   {
1985     return hasHiddenColumns;
1986   }
1987   /**
1988    * when set, view will scroll to show the highlighted position
1989    */
1990   public boolean followHighlight=true;
1991   /**
1992    * @return true if view should scroll to show the highlighted region of a sequence
1993    * @return
1994    */
1995   public boolean getFollowHighlight() {
1996     return followHighlight;
1997   }
1998   public boolean followSelection=true;
1999   /**
2000    * @return true if view selection should always follow the selections broadcast by other selection sources
2001    */
2002   public boolean getFollowSelection() {
2003     return followSelection;
2004   }
2005   private long sgrouphash=-1,colselhash=-1;
2006
2007   boolean showSeqFeaturesHeight;
2008   /**
2009    * checks current SelectionGroup against record of last hash value, and updates record.
2010    * @return true if SelectionGroup changed since last call
2011    */
2012   boolean isSelectionGroupChanged() {
2013     int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2014     if (hc!=sgrouphash)
2015     {
2016       sgrouphash = hc;
2017       return true;
2018     }
2019     return false;
2020   }
2021   /**
2022    * checks current colsel against record of last hash value, and updates record.
2023    * @return true if colsel changed since last call
2024    */
2025   boolean isColSelChanged() {
2026     int hc=(colSel==null) ? -1 : colSel.hashCode();
2027     if (hc!=colselhash)
2028     {
2029       colselhash = hc;
2030       return true;
2031     }
2032     return false;
2033   }
2034   public void sendSelection()
2035   {
2036     jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);
2037   }
2038   public void setShowSequenceFeaturesHeight(boolean selected)
2039   {
2040     showSeqFeaturesHeight = selected; 
2041   }
2042   public boolean getShowSequenceFeaturesHeight()
2043   {
2044     return showSeqFeaturesHeight; 
2045   }
2046   boolean showUnconserved=false;
2047   public boolean getShowUnconserved()
2048   {
2049     return showUnconserved;
2050   }
2051   public void setShowUnconserved(boolean showunconserved)
2052   {
2053     showUnconserved=showunconserved;
2054   }
2055   /**
2056    * return the alignPanel containing the given viewport. Use this to get the
2057    * components currently handling the given viewport.
2058    * @param av
2059    * @return null or an alignPanel guaranteed to have non-null alignFrame reference
2060    */
2061   public AlignmentPanel getAlignPanel()
2062   {
2063     AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this.getSequenceSetId());
2064     AlignmentPanel ap=null;
2065     for (int p=0;aps!=null && p<aps.length; p++)
2066     {
2067       if (aps[p].av == this)
2068       {
2069         return aps[p];
2070       }
2071     }
2072     return null;
2073   }
2074   public boolean getSortByTree()
2075   {
2076     return sortByTree;
2077   }
2078   public void setSortByTree(boolean sort) {
2079     sortByTree = sort;
2080   }
2081   /**
2082    * should conservation rows be shown for groups
2083    */
2084   boolean showGroupConservation = false;
2085   /**
2086    * should consensus rows be shown for groups
2087    */
2088   boolean showGroupConsensus = false;
2089   
2090   /**
2091    * @return the showGroupConservation
2092    */
2093   public boolean isShowGroupConservation()
2094   {
2095     return showGroupConservation;
2096   }
2097   /**
2098    * @param showGroupConservation the showGroupConservation to set
2099    */
2100   public void setShowGroupConservation(boolean showGroupConservation)
2101   {
2102     this.showGroupConservation = showGroupConservation;
2103   }
2104   /**
2105    * @return the showGroupConsensus
2106    */
2107   public boolean isShowGroupConsensus()
2108   {
2109     return showGroupConsensus;
2110   }
2111   /**
2112    * @param showGroupConsensus the showGroupConsensus to set
2113    */
2114   public void setShowGroupConsensus(boolean showGroupConsensus)
2115   {
2116     this.showGroupConsensus = showGroupConsensus;
2117   }
2118   /**
2119    * @return the includeAllConsensusSymbols
2120    */
2121   public boolean isIncludeAllConsensusSymbols()
2122   {
2123     return includeAllConsensusSymbols;
2124   }
2125   /**
2126    * @param includeAllConsensusSymbols the includeAllConsensusSymbols to set
2127    */
2128   public void setIncludeAllConsensusSymbols(boolean includeAllConsensusSymbols)
2129   {
2130     this.includeAllConsensusSymbols = includeAllConsensusSymbols;
2131   }
2132   
2133 }