JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / gui / AlignViewport.java
old mode 100755 (executable)
new mode 100644 (file)
index 1970181..8a95015
- /*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package jalview.gui;\r
-\r
-import jalview.analysis.*;\r
-\r
-import jalview.bin.*;\r
-\r
-import jalview.datamodel.*;\r
-\r
-import jalview.schemes.*;\r
-\r
-import java.awt.*;\r
-\r
-import java.util.*;\r
-\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class AlignViewport\r
-{\r
-    int startRes;\r
-    int endRes;\r
-    int startSeq;\r
-    int endSeq;\r
-    boolean showJVSuffix = true;\r
-    boolean showText = true;\r
-    boolean showColourText = false;\r
-    boolean showBoxes = true;\r
-    boolean wrapAlignment = false;\r
-    boolean renderGaps = true;\r
-    boolean showSequenceFeatures = false;\r
-    boolean showAnnotation = true;\r
-    boolean showConservation = true;\r
-    boolean showQuality = true;\r
-    boolean showIdentity = true;\r
-    boolean colourAppliesToAllGroups = true;\r
-    ColourSchemeI globalColourScheme = null;\r
-    boolean conservationColourSelected = false;\r
-    boolean abovePIDThreshold = false;\r
-    SequenceGroup selectionGroup;\r
-    int charHeight;\r
-    int charWidth;\r
-    boolean validCharWidth;\r
-    int wrappedWidth;\r
-    Font font;\r
-    AlignmentI alignment;\r
-    ColumnSelection colSel = new ColumnSelection();\r
-    int threshold;\r
-    int increment;\r
-    NJTree currentTree = null;\r
-    boolean scaleAboveWrapped = false;\r
-    boolean scaleLeftWrapped = true;\r
-    boolean scaleRightWrapped = true;\r
-    boolean hasHiddenColumns = false;\r
-    boolean hasHiddenRows = false;\r
-    boolean showHiddenMarkers = true;\r
-\r
-    boolean cursorMode = false;\r
-\r
-    // The following vector holds the features which are\r
-    // currently visible, in the correct order or rendering\r
-    Hashtable featuresDisplayed = null;\r
-\r
-\r
-    /** DOCUMENT ME!! */\r
-    public Vector vconsensus;\r
-    AlignmentAnnotation consensus;\r
-    AlignmentAnnotation conservation;\r
-    AlignmentAnnotation quality;\r
-    boolean autoCalculateConsensus = true;\r
-\r
-    /** DOCUMENT ME!! */\r
-    public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!\r
-\r
-    // JBPNote Prolly only need this in the applet version.\r
-    private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);\r
-\r
-    boolean ignoreGapsInConsensusCalculation = false;\r
-\r
-    boolean isDataset = false;\r
-\r
-    boolean antiAlias = false;\r
-\r
-    boolean padGaps = false;\r
-\r
-\r
-    public AlignViewport(AlignmentI al, boolean dataset)\r
-    {\r
-      isDataset = dataset;\r
-      setAlignment(al);\r
-      init();\r
-    }\r
-    /**\r
-     * Creates a new AlignViewport object.\r
-     *\r
-     * @param al DOCUMENT ME!\r
-     */\r
-    public AlignViewport(AlignmentI al)\r
-    {\r
-        setAlignment(al);\r
-        init();\r
-    }\r
-\r
-    void init()\r
-    {\r
-        this.startRes = 0;\r
-        this.endRes = alignment.getWidth() - 1;\r
-        this.startSeq = 0;\r
-        this.endSeq = alignment.getHeight() - 1;\r
-\r
-      antiAlias = Cache.getDefault("ANTI_ALIAS", false);\r
-\r
-      showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);\r
-      showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);\r
-      showConservation = Cache.getDefault("SHOW_CONSERVATION", true);\r
-\r
-      showQuality = Cache.getDefault("SHOW_QUALITY", true);\r
-      showIdentity = Cache.getDefault("SHOW_IDENTITY", true);\r
-\r
-      autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);\r
-\r
-      padGaps = Cache.getDefault("PAD_GAPS", false);\r
-\r
-       String fontName = Cache.getDefault("FONT_NAME", "SansSerif");\r
-       String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;\r
-       String fontSize = Cache.getDefault("FONT_SIZE", "10");\r
-\r
-       int style = 0;\r
-\r
-       if (fontStyle.equals("bold"))\r
-       {\r
-         style = 1;\r
-       }\r
-       else if (fontStyle.equals("italic"))\r
-       {\r
-         style = 2;\r
-       }\r
-\r
-       setFont(new Font(fontName, style, Integer.parseInt(fontSize)));\r
-\r
-\r
-       alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );\r
-\r
-\r
-        // We must set conservation and consensus before setting colour,\r
-        // as Blosum and Clustal require this to be done\r
-        if(vconsensus==null && !isDataset)\r
-        {\r
-          updateConservation();\r
-          updateConsensus();\r
-        }\r
-\r
-        if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)\r
-        {\r
-          globalColourScheme = ColourSchemeProperty.getColour(alignment,\r
-              jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));\r
-\r
-            if (globalColourScheme instanceof UserColourScheme)\r
-            {\r
-                globalColourScheme = UserDefinedColours.loadDefaultColours();\r
-                ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());\r
-            }\r
-\r
-            if (globalColourScheme != null)\r
-            {\r
-                globalColourScheme.setConsensus(vconsensus);\r
-            }\r
-        }\r
-    }\r
-\r
-\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setShowSequenceFeatures(boolean b)\r
-    {\r
-        showSequenceFeatures = b;\r
-    }\r
-\r
-    public boolean getShowSequenceFeatures()\r
-    {\r
-      return showSequenceFeatures;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     */\r
-    public void updateConservation()\r
-    {\r
-      if(alignment.isNucleotide())\r
-          return;\r
-\r
-      try{\r
-        Conservation cons = new jalview.analysis.Conservation("All",\r
-            jalview.schemes.ResidueProperties.propHash, 3,\r
-            alignment.getSequences(), 0, alignment.getWidth() - 1);\r
-        cons.calculate();\r
-        cons.verdict(false, ConsPercGaps);\r
-        cons.findQuality();\r
-\r
-        int alWidth = alignment.getWidth();\r
-        Annotation[] annotations = new Annotation[alWidth];\r
-        Annotation[] qannotations = new Annotation[alWidth];\r
-        String sequence = cons.getConsSequence().getSequence();\r
-        float minR;\r
-        float minG;\r
-        float minB;\r
-        float maxR;\r
-        float maxG;\r
-        float maxB;\r
-        minR = 0.3f;\r
-        minG = 0.0f;\r
-        minB = 0f;\r
-        maxR = 1.0f - minR;\r
-        maxG = 0.9f - minG;\r
-        maxB = 0f - minB; // scalable range for colouring both Conservation and Quality\r
-\r
-        float min = 0f;\r
-        float max = 11f;\r
-        float qmin = cons.qualityRange[0].floatValue();\r
-        float qmax = cons.qualityRange[1].floatValue();\r
-\r
-        for (int i = 0; i < alWidth; i++)\r
-        {\r
-          float value = 0;\r
-\r
-          try\r
-          {\r
-            value = Integer.parseInt(sequence.charAt(i) + "");\r
-          }\r
-          catch (Exception ex)\r
-          {\r
-            if (sequence.charAt(i) == '*')\r
-            {\r
-              value = 11;\r
-            }\r
-\r
-            if (sequence.charAt(i) == '+')\r
-            {\r
-              value = 10;\r
-            }\r
-          }\r
-\r
-          float vprop = value - min;\r
-          vprop /= max;\r
-          annotations[i] = new Annotation(sequence.charAt(i) + "",\r
-                                          String.valueOf(value), ' ', value,\r
-                                          new Color(minR + (maxR * vprop),\r
-              minG + (maxG * vprop),\r
-              minB + (maxB * vprop)));\r
-\r
-          // Quality calc\r
-          value = ( (Double) cons.quality.get(i)).floatValue();\r
-          vprop = value - qmin;\r
-          vprop /= qmax;\r
-          qannotations[i] = new Annotation(" ", String.valueOf(value), ' ',\r
-                                           value,\r
-                                           new Color(minR + (maxR * vprop),\r
-              minG + (maxG * vprop),\r
-              minB + (maxB * vprop)));\r
-        }\r
-\r
-        if (conservation == null)\r
-        {\r
-          conservation = new AlignmentAnnotation("Conservation",\r
-                                                 "Conservation of total alignment less than " +\r
-                                                 ConsPercGaps + "% gaps",\r
-                                                 annotations, 0f, // cons.qualityRange[0].floatValue(),\r
-                                                 11f, // cons.qualityRange[1].floatValue()\r
-                                                 AlignmentAnnotation.BAR_GRAPH);\r
-\r
-          if (showConservation)\r
-          {\r
-            alignment.addAnnotation(conservation);\r
-          }\r
-\r
-          quality = new AlignmentAnnotation("Quality",\r
-                                            "Alignment Quality based on Blosum62 scores",\r
-                                            qannotations,\r
-                                            cons.qualityRange[0].floatValue(),\r
-                                            cons.qualityRange[1].floatValue(),\r
-                                            AlignmentAnnotation.BAR_GRAPH);\r
-\r
-          if (showQuality)\r
-          {\r
-            alignment.addAnnotation(quality);\r
-          }\r
-        }\r
-        else\r
-        {\r
-          conservation.annotations = annotations;\r
-          quality.annotations = qannotations;\r
-          quality.graphMax = cons.qualityRange[1].floatValue();\r
-        }\r
-      }\r
-      catch (OutOfMemoryError error)\r
-      {\r
-        javax.swing.SwingUtilities.invokeLater(new Runnable()\r
-        {\r
-          public void run()\r
-          {\r
-            javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                "Out of memory calculating conservation!!"\r
-                +\r
-                "\nSee help files for increasing Java Virtual Machine memory."\r
-                , "Out of memory",\r
-                javax.swing.JOptionPane.WARNING_MESSAGE);\r
-          }\r
-        });\r
-\r
-        System.out.println("Conservation calculation: " + error);\r
-        System.gc();\r
-\r
-      }\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     */\r
-    public void updateConsensus()\r
-    {\r
-      try{\r
-        Annotation[] annotations = new Annotation[alignment.getWidth()];\r
-\r
-        // this routine prevents vconsensus becoming a new object each time\r
-        // consenus is calculated. Important for speed of Blosum62\r
-        // and PID colouring of alignment\r
-        if (vconsensus == null)\r
-        {\r
-          vconsensus = alignment.getAAFrequency();\r
-        }\r
-        else\r
-        {\r
-          Vector temp = alignment.getAAFrequency();\r
-          vconsensus.clear();\r
-\r
-          Enumeration e = temp.elements();\r
-\r
-          while (e.hasMoreElements())\r
-          {\r
-            vconsensus.add(e.nextElement());\r
-          }\r
-        }\r
-\r
-        Hashtable hash = null;\r
-\r
-        for (int i = 0; i < alignment.getWidth(); i++)\r
-        {\r
-          hash = (Hashtable) vconsensus.elementAt(i);\r
-\r
-          float value = 0;\r
-          if (ignoreGapsInConsensusCalculation)\r
-            value = ( (Float) hash.get("pid_nogaps")).floatValue();\r
-          else\r
-            value = ( (Float) hash.get("pid_gaps")).floatValue();\r
-\r
-          String maxRes = hash.get("maxResidue").toString();\r
-          String mouseOver = hash.get("maxResidue") + " ";\r
-\r
-          if (maxRes.length() > 1)\r
-          {\r
-            mouseOver = "[" + maxRes + "] ";\r
-            maxRes = "+";\r
-          }\r
-\r
-          mouseOver += ( (int) value + "%");\r
-          annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);\r
-        }\r
-\r
-        if (consensus == null)\r
-        {\r
-          consensus = new AlignmentAnnotation("Consensus", "PID",\r
-                                              annotations, 0f, 100f,AlignmentAnnotation.BAR_GRAPH);\r
-\r
-          if (showIdentity)\r
-          {\r
-            alignment.addAnnotation(consensus);\r
-          }\r
-        }\r
-        else\r
-        {\r
-          consensus.annotations = annotations;\r
-        }\r
-\r
-        if (globalColourScheme != null)\r
-          globalColourScheme.setConsensus(vconsensus);\r
-\r
-      }catch(OutOfMemoryError error)\r
-      {\r
-        javax.swing.SwingUtilities.invokeLater(new Runnable()\r
-        {\r
-          public void run()\r
-          {\r
-            javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                "Out of memory calc45ulating consensus!!"\r
-                +\r
-                "\nSee help files for increasing Java Virtual Machine memory."\r
-                , "Out of memory",\r
-                javax.swing.JOptionPane.WARNING_MESSAGE);\r
-          }\r
-        });\r
-\r
-\r
-        System.out.println("Consensus calculation: " + error);\r
-        System.gc();\r
-      }\r
-\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public SequenceGroup getSelectionGroup()\r
-    {\r
-        return selectionGroup;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param sg DOCUMENT ME!\r
-     */\r
-    public void setSelectionGroup(SequenceGroup sg)\r
-    {\r
-        selectionGroup = sg;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getConservationSelected()\r
-    {\r
-        return conservationColourSelected;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setConservationSelected(boolean b)\r
-    {\r
-        conservationColourSelected = b;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getAbovePIDThreshold()\r
-    {\r
-        return abovePIDThreshold;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setAbovePIDThreshold(boolean b)\r
-    {\r
-        abovePIDThreshold = b;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getStartRes()\r
-    {\r
-        return startRes;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getEndRes()\r
-    {\r
-        return endRes;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getStartSeq()\r
-    {\r
-        return startSeq;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param cs DOCUMENT ME!\r
-     */\r
-    public void setGlobalColourScheme(ColourSchemeI cs)\r
-    {\r
-        globalColourScheme = cs;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public ColourSchemeI getGlobalColourScheme()\r
-    {\r
-        return globalColourScheme;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param res DOCUMENT ME!\r
-     */\r
-    public void setStartRes(int res)\r
-    {\r
-        this.startRes = res;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param seq DOCUMENT ME!\r
-     */\r
-    public void setStartSeq(int seq)\r
-    {\r
-        this.startSeq = seq;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param res DOCUMENT ME!\r
-     */\r
-    public void setEndRes(int res)\r
-    {\r
-        if (res > (alignment.getWidth() - 1))\r
-        {\r
-            // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));\r
-            res = alignment.getWidth() - 1;\r
-        }\r
-\r
-        if (res < 0)\r
-        {\r
-            res = 0;\r
-        }\r
-\r
-        this.endRes = res;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param seq DOCUMENT ME!\r
-     */\r
-    public void setEndSeq(int seq)\r
-    {\r
-        if (seq > alignment.getHeight())\r
-        {\r
-            seq = alignment.getHeight();\r
-        }\r
-\r
-        if (seq < 0)\r
-        {\r
-            seq = 0;\r
-        }\r
-\r
-        this.endSeq = seq;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getEndSeq()\r
-    {\r
-        return endSeq;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param f DOCUMENT ME!\r
-     */\r
-    public void setFont(Font f)\r
-    {\r
-        font = f;\r
-\r
-        Container c = new Container();\r
-\r
-        java.awt.FontMetrics fm = c.getFontMetrics(font);\r
-        setCharHeight(fm.getHeight());\r
-        setCharWidth(fm.charWidth('M'));\r
-        validCharWidth = true;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public Font getFont()\r
-    {\r
-        return font;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param w DOCUMENT ME!\r
-     */\r
-    public void setCharWidth(int w)\r
-    {\r
-        this.charWidth = w;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getCharWidth()\r
-    {\r
-        return charWidth;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param h DOCUMENT ME!\r
-     */\r
-    public void setCharHeight(int h)\r
-    {\r
-        this.charHeight = h;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getCharHeight()\r
-    {\r
-        return charHeight;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param w DOCUMENT ME!\r
-     */\r
-    public void setWrappedWidth(int w)\r
-    {\r
-        this.wrappedWidth = w;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getWrappedWidth()\r
-    {\r
-        return wrappedWidth;\r
-    }\r
-\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public AlignmentI getAlignment()\r
-    {\r
-        return alignment;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param align DOCUMENT ME!\r
-     */\r
-    public void setAlignment(AlignmentI align)\r
-    {\r
-        this.alignment = align;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param state DOCUMENT ME!\r
-     */\r
-    public void setWrapAlignment(boolean state)\r
-    {\r
-        wrapAlignment = state;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param state DOCUMENT ME!\r
-     */\r
-    public void setShowText(boolean state)\r
-    {\r
-        showText = state;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param state DOCUMENT ME!\r
-     */\r
-    public void setRenderGaps(boolean state)\r
-    {\r
-        renderGaps = state;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getColourText()\r
-    {\r
-        return showColourText;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param state DOCUMENT ME!\r
-     */\r
-    public void setColourText(boolean state)\r
-    {\r
-        showColourText = state;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param state DOCUMENT ME!\r
-     */\r
-    public void setShowBoxes(boolean state)\r
-    {\r
-        showBoxes = state;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getWrapAlignment()\r
-    {\r
-        return wrapAlignment;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getShowText()\r
-    {\r
-        return showText;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getShowBoxes()\r
-    {\r
-        return showBoxes;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public char getGapCharacter()\r
-    {\r
-        return getAlignment().getGapCharacter();\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param gap DOCUMENT ME!\r
-     */\r
-    public void setGapCharacter(char gap)\r
-    {\r
-        if (getAlignment() != null)\r
-        {\r
-            getAlignment().setGapCharacter(gap);\r
-        }\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param thresh DOCUMENT ME!\r
-     */\r
-    public void setThreshold(int thresh)\r
-    {\r
-        threshold = thresh;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getThreshold()\r
-    {\r
-        return threshold;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param inc DOCUMENT ME!\r
-     */\r
-    public void setIncrement(int inc)\r
-    {\r
-        increment = inc;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getIncrement()\r
-    {\r
-        return increment;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param y DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public int getIndex(int y)\r
-    {\r
-        int y1 = 0;\r
-        int starty = getStartSeq();\r
-        int endy = getEndSeq();\r
-\r
-        for (int i = starty; i <= endy; i++)\r
-        {\r
-            if ((i < alignment.getHeight()) &&\r
-                    (alignment.getSequenceAt(i) != null))\r
-            {\r
-                int y2 = y1 + getCharHeight();\r
-\r
-                if ((y >= y1) && (y <= y2))\r
-                {\r
-                    return i;\r
-                }\r
-\r
-                y1 = y2;\r
-            }\r
-            else\r
-            {\r
-                return -1;\r
-            }\r
-        }\r
-\r
-        return -1;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public ColumnSelection getColumnSelection()\r
-    {\r
-        return colSel;\r
-    }\r
-\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param tree DOCUMENT ME!\r
-     */\r
-    public void setCurrentTree(NJTree tree)\r
-    {\r
-        currentTree = tree;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public NJTree getCurrentTree()\r
-    {\r
-        return currentTree;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setColourAppliesToAllGroups(boolean b)\r
-    {\r
-        colourAppliesToAllGroups = b;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getColourAppliesToAllGroups()\r
-    {\r
-        return colourAppliesToAllGroups;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getShowJVSuffix()\r
-    {\r
-        return showJVSuffix;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setShowJVSuffix(boolean b)\r
-    {\r
-        showJVSuffix = b;\r
-    }\r
-\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getShowAnnotation()\r
-    {\r
-        return showAnnotation;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setShowAnnotation(boolean b)\r
-    {\r
-        showAnnotation = b;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getScaleAboveWrapped()\r
-    {\r
-        return scaleAboveWrapped;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getScaleLeftWrapped()\r
-    {\r
-        return scaleLeftWrapped;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public boolean getScaleRightWrapped()\r
-    {\r
-        return scaleRightWrapped;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setScaleAboveWrapped(boolean b)\r
-    {\r
-        scaleAboveWrapped = b;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setScaleLeftWrapped(boolean b)\r
-    {\r
-        scaleLeftWrapped = b;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param b DOCUMENT ME!\r
-     */\r
-    public void setScaleRightWrapped(boolean b)\r
-    {\r
-        scaleRightWrapped = b;\r
-    }\r
-\r
-    /**\r
-     * Property change listener for changes in alignment\r
-     *\r
-     * @param listener DOCUMENT ME!\r
-     */\r
-    public void addPropertyChangeListener(\r
-        java.beans.PropertyChangeListener listener)\r
-    {\r
-        changeSupport.addPropertyChangeListener(listener);\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param listener DOCUMENT ME!\r
-     */\r
-    public void removePropertyChangeListener(\r
-        java.beans.PropertyChangeListener listener)\r
-    {\r
-        changeSupport.removePropertyChangeListener(listener);\r
-    }\r
-\r
-    /**\r
-     * Property change listener for changes in alignment\r
-     *\r
-     * @param prop DOCUMENT ME!\r
-     * @param oldvalue DOCUMENT ME!\r
-     * @param newvalue DOCUMENT ME!\r
-     */\r
-    public void firePropertyChange(String prop, Object oldvalue, Object newvalue)\r
-    {\r
-        changeSupport.firePropertyChange(prop, oldvalue, newvalue);\r
-    }\r
-\r
-    public void setIgnoreGapsConsensus(boolean b)\r
-    {\r
-      ignoreGapsInConsensusCalculation = b;\r
-      updateConsensus();\r
-      if(globalColourScheme!=null)\r
-      {\r
-        globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);\r
-      }\r
-    }\r
-\r
-    public boolean getIgnoreGapsConsensus()\r
-    {\r
-     return ignoreGapsInConsensusCalculation;\r
-    }\r
-\r
-    public void setDataset(boolean b)\r
-    {\r
-      isDataset = b;\r
-    }\r
-\r
-    public boolean isDataset()\r
-    {\r
-      return isDataset;\r
-    }\r
-\r
-\r
-    public void hideSelectedColumns()\r
-    {\r
-      if (colSel.size() < 1)\r
-        return;\r
-\r
-      while (colSel.size() > 0)\r
-      {\r
-        int column = ( (Integer) colSel.getSelected().firstElement()).intValue();\r
-        colSel.hideColumns(column);\r
-      }\r
-      setSelectionGroup(null);\r
-      hasHiddenColumns = true;\r
-    }\r
-\r
-\r
-    public void hideColumns(int start, int end)\r
-    {\r
-      if(start==end)\r
-        end++;\r
-\r
-      for(int i=start; i<end; i++)\r
-      {\r
-        colSel.addElement(i);\r
-        colSel.hideColumns(i);\r
-      }\r
-\r
-      setSelectionGroup(null);\r
-      hasHiddenColumns = true;\r
-    }\r
-\r
-    public void hideSequence(SequenceI seq)\r
-    {\r
-      if(seq!=null)\r
-      {\r
-        alignment.getHiddenSequences().hideSequence(seq);\r
-        hasHiddenRows = true;\r
-      }\r
-    }\r
-\r
-    public void showSequence(int index)\r
-    {\r
-      alignment.getHiddenSequences().showSequence(index);\r
-\r
-      if(alignment.getHiddenSequences().getSize()<1)\r
-        hasHiddenRows = false;\r
-    }\r
-\r
-    public void showColumn(int col)\r
-    {\r
-      colSel.revealHiddenColumns(col);\r
-      if(colSel.size()<1)\r
-        hasHiddenColumns = false;\r
-    }\r
-\r
-    public void showAllHiddenColumns()\r
-    {\r
-      colSel.revealAllHiddenColumns();\r
-      hasHiddenColumns = false;\r
-    }\r
-\r
-    public void showAllHiddenSeqs()\r
-    {\r
-      if(alignment.getHiddenSequences().getSize()>0)\r
-      {\r
-        alignment.getHiddenSequences().showAll();\r
-        hasHiddenRows = false;\r
-      }\r
-    }\r
-\r
-    public int adjustForHiddenSeqs(int alignmentIndex)\r
-    {\r
-      return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);\r
-    }\r
-\r
-    /**\r
-     * This method returns the a new SequenceI [] with\r
-     * the selection sequence and start and end points adjusted\r
-     * @return String[]\r
-     */\r
-    public SequenceI[] getSelectionAsNewSequence()\r
-    {\r
-      SequenceI[] sequences;\r
-\r
-      if (selectionGroup == null)\r
-        sequences = alignment.getSequencesArray();\r
-      else\r
-        sequences = selectionGroup.getSelectionAsNewSequences(alignment);\r
-\r
-      return sequences;\r
-    }\r
-\r
-\r
-    /**\r
-     * This method returns the visible alignment as text, as\r
-     * seen on the GUI, ie if columns are hidden they will not\r
-     * be returned in the result.\r
-     * Use this for calculating trees, PCA, redundancy etc on views\r
-     * which contain hidden columns.\r
-     * @return String[]\r
-     */\r
-    public String [] getViewAsString(boolean selectedRegionOnly)\r
-    {\r
-      String [] selection = null;\r
-      SequenceI [] seqs= null;\r
-      int i, iSize;\r
-      int start = 0, end = 0;\r
-      if(selectedRegionOnly && selectionGroup!=null)\r
-      {\r
-        iSize = selectionGroup.getSize(false);\r
-        seqs = selectionGroup.getSequencesInOrder(alignment);\r
-        start = selectionGroup.getStartRes();\r
-        end = selectionGroup.getEndRes()+1;\r
-      }\r
-      else\r
-      {\r
-        iSize = alignment.getHeight();\r
-        seqs = alignment.getSequencesArray();\r
-        end = alignment.getWidth();\r
-      }\r
-\r
-      selection = new String[iSize];\r
-\r
-\r
-      for(i=0; i<iSize; i++)\r
-      {\r
-        if (hasHiddenColumns)\r
-        {\r
-             StringBuffer visibleSeq = new StringBuffer();\r
-             Vector regions = colSel.getHiddenColumns();\r
-\r
-             int blockStart = start, blockEnd=end;\r
-             int [] region;\r
-             int hideStart, hideEnd;\r
-\r
-             for (int j = 0; j < regions.size(); j++)\r
-             {\r
-               region = (int[]) regions.elementAt(j);\r
-               hideStart = region[0];\r
-               hideEnd = region[1];\r
-\r
-               if(hideStart < start)\r
-               {\r
-                 continue;\r
-               }\r
-\r
-               blockStart = Math.min(blockStart, hideEnd+1);\r
-               blockEnd = Math.min(blockEnd, hideStart);\r
-\r
-               if(blockStart>blockEnd)\r
-               {\r
-                  break;\r
-               }\r
-\r
-\r
-               visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));\r
-\r
-               blockStart = hideEnd+1;\r
-               blockEnd = end;\r
-             }\r
-\r
-             if(end>blockStart)\r
-               visibleSeq.append(seqs[i].getSequence(blockStart, end));\r
-\r
-             selection[i] = visibleSeq.toString();\r
-        }\r
-        else\r
-        {\r
-          selection[i] = seqs[i].getSequence(start, end);\r
-        }\r
-      }\r
-\r
-      return selection;\r
-    }\r
-\r
-    public boolean getShowHiddenMarkers()\r
-    {\r
-      return showHiddenMarkers;\r
-    }\r
-\r
-    public void setShowHiddenMarkers(boolean show)\r
-    {\r
-      showHiddenMarkers = show;\r
-    }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package jalview.gui;
+
+import jalview.analysis.AlignmentUtils;
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.analysis.NJTree;
+import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.ViewStyleI;
+import jalview.bin.Cache;
+import jalview.commands.CommandI;
+import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.UserColourScheme;
+import jalview.structure.CommandListener;
+import jalview.structure.SelectionSource;
+import jalview.structure.StructureSelectionManager;
+import jalview.structure.VamsasSource;
+import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.params.AutoCalcSetting;
+
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JOptionPane;
+
+/**
+ * DOCUMENT ME!
+ * 
+ * @author $author$
+ * @version $Revision: 1.141 $
+ */
+public class AlignViewport extends AlignmentViewport implements
+        SelectionSource, CommandListener
+{
+  Font font;
+
+  NJTree currentTree = null;
+
+  boolean cursorMode = false;
+
+  boolean antiAlias = false;
+
+  private Rectangle explodedGeometry;
+
+  String viewName;
+
+  /*
+   * Flag set true on the view that should 'gather' multiple views of the same
+   * sequence set id when a project is reloaded. Set false on all views when
+   * they are 'exploded' into separate windows. Set true on the current view
+   * when 'Gather' is performed, and also on the first tab when the first new
+   * view is created.
+   */
+  private boolean gatherViewsHere = false;
+
+  private AnnotationColumnChooser annotationColumnSelectionState;
+
+  /**
+   * Creates a new AlignViewport object.
+   * 
+   * @param al
+   *          alignment to view
+   */
+  public AlignViewport(AlignmentI al)
+  {
+    setAlignment(al);
+    init();
+  }
+
+  /**
+   * Create a new AlignViewport object with a specific sequence set ID
+   * 
+   * @param al
+   * @param seqsetid
+   *          (may be null - but potential for ambiguous constructor exception)
+   */
+  public AlignViewport(AlignmentI al, String seqsetid)
+  {
+    this(al, seqsetid, null);
+  }
+
+  public AlignViewport(AlignmentI al, String seqsetid, String viewid)
+  {
+    sequenceSetID = seqsetid;
+    viewId = viewid;
+    // TODO remove these once 2.4.VAMSAS release finished
+    if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
+    {
+      Cache.log.debug("Setting viewport's sequence set id : "
+              + sequenceSetID);
+    }
+    if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
+    {
+      Cache.log.debug("Setting viewport's view id : " + viewId);
+    }
+    setAlignment(al);
+    init();
+  }
+
+  /**
+   * Create a new AlignViewport with hidden regions
+   * 
+   * @param al
+   *          AlignmentI
+   * @param hiddenColumns
+   *          ColumnSelection
+   */
+  public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
+  {
+    setAlignment(al);
+    if (hiddenColumns != null)
+    {
+      colSel = hiddenColumns;
+    }
+    init();
+  }
+
+  /**
+   * New viewport with hidden columns and an existing sequence set id
+   * 
+   * @param al
+   * @param hiddenColumns
+   * @param seqsetid
+   *          (may be null)
+   */
+  public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
+          String seqsetid)
+  {
+    this(al, hiddenColumns, seqsetid, null);
+  }
+
+  /**
+   * New viewport with hidden columns and an existing sequence set id and viewid
+   * 
+   * @param al
+   * @param hiddenColumns
+   * @param seqsetid
+   *          (may be null)
+   * @param viewid
+   *          (may be null)
+   */
+  public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
+          String seqsetid, String viewid)
+  {
+    sequenceSetID = seqsetid;
+    viewId = viewid;
+    // TODO remove these once 2.4.VAMSAS release finished
+    if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
+    {
+      Cache.log.debug("Setting viewport's sequence set id : "
+              + sequenceSetID);
+    }
+    if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
+    {
+      Cache.log.debug("Setting viewport's view id : " + viewId);
+    }
+    setAlignment(al);
+    if (hiddenColumns != null)
+    {
+      colSel = hiddenColumns;
+    }
+    init();
+  }
+
+  /**
+   * Apply any settings saved in user preferences
+   */
+  private void applyViewProperties()
+  {
+    antiAlias = Cache.getDefault("ANTI_ALIAS", false);
+
+    viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
+    setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
+
+    setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
+    setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
+    autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
+
+    setPadGaps(Cache.getDefault("PAD_GAPS", true));
+    setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
+    setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
+    viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
+    viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
+    viewStyle.setShowUnconserved(Cache
+            .getDefault("SHOW_UNCONSERVED", false));
+    sortByTree = Cache.getDefault("SORT_BY_TREE", false);
+    followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
+    sortAnnotationsBy = SequenceAnnotationOrder.valueOf(Cache.getDefault(
+            Preferences.SORT_ANNOTATIONS,
+            SequenceAnnotationOrder.NONE.name()));
+    showAutocalculatedAbove = Cache.getDefault(
+            Preferences.SHOW_AUTOCALC_ABOVE, false);
+    viewStyle.setScaleProteinAsCdna(Cache.getDefault(
+            Preferences.SCALE_PROTEIN_TO_CDNA, true));
+  }
+
+  void init()
+  {
+    this.startRes = 0;
+    this.endRes = alignment.getWidth() - 1;
+    this.startSeq = 0;
+    this.endSeq = alignment.getHeight() - 1;
+    applyViewProperties();
+
+    String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
+    String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
+    String fontSize = Cache.getDefault("FONT_SIZE", "10");
+
+    int style = 0;
+
+    if (fontStyle.equals("bold"))
+    {
+      style = 1;
+    }
+    else if (fontStyle.equals("italic"))
+    {
+      style = 2;
+    }
+
+    setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
+
+    alignment
+            .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
+
+    // We must set conservation and consensus before setting colour,
+    // as Blosum and Clustal require this to be done
+    if (hconsensus == null && !isDataset)
+    {
+      if (!alignment.isNucleotide())
+      {
+        showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
+        showQuality = Cache.getDefault("SHOW_QUALITY", true);
+        showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
+                false);
+      }
+      showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
+              true);
+      showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
+      normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
+              false);
+      showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
+      showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
+    }
+    initAutoAnnotation();
+    String colourProperty = alignment.isNucleotide() ? Preferences.DEFAULT_COLOUR_NUC
+            : Preferences.DEFAULT_COLOUR_PROT;
+    String propertyValue = Cache.getProperty(colourProperty);
+    if (propertyValue == null)
+    {
+      // fall back on this property for backwards compatibility
+      propertyValue = Cache.getProperty(Preferences.DEFAULT_COLOUR);
+    }
+    if (propertyValue != null)
+    {
+      globalColourScheme = ColourSchemeProperty.getColour(alignment,
+              propertyValue);
+
+      if (globalColourScheme instanceof UserColourScheme)
+      {
+        globalColourScheme = UserDefinedColours.loadDefaultColours();
+        ((UserColourScheme) globalColourScheme).setThreshold(0,
+                isIgnoreGapsConsensus());
+      }
+
+      if (globalColourScheme != null)
+      {
+        globalColourScheme.setConsensus(hconsensus);
+      }
+    }
+  }
+
+  /**
+   * get the consensus sequence as displayed under the PID consensus annotation
+   * row.
+   * 
+   * @return consensus sequence as a new sequence object
+   */
+  public SequenceI getConsensusSeq()
+  {
+    if (consensus == null)
+    {
+      updateConsensus(null);
+    }
+    if (consensus == null)
+    {
+      return null;
+    }
+    StringBuffer seqs = new StringBuffer();
+    for (int i = 0; i < consensus.annotations.length; i++)
+    {
+      if (consensus.annotations[i] != null)
+      {
+        if (consensus.annotations[i].description.charAt(0) == '[')
+        {
+          seqs.append(consensus.annotations[i].description.charAt(1));
+        }
+        else
+        {
+          seqs.append(consensus.annotations[i].displayCharacter);
+        }
+      }
+    }
+
+    SequenceI sq = new Sequence("Consensus", seqs.toString());
+    sq.setDescription("Percentage Identity Consensus "
+            + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
+    return sq;
+  }
+
+  boolean validCharWidth;
+
+  /**
+   * update view settings with the given font. You may need to call
+   * alignPanel.fontChanged to update the layout geometry
+   * 
+   * @param setGrid
+   *          when true, charWidth/height is set according to font mentrics
+   */
+  public void setFont(Font f, boolean setGrid)
+  {
+    font = f;
+
+    Container c = new Container();
+
+    java.awt.FontMetrics fm = c.getFontMetrics(font);
+    int w = viewStyle.getCharWidth(), ww = fm.charWidth('M'), h = viewStyle
+            .getCharHeight();
+    if (setGrid)
+    {
+      setCharHeight(fm.getHeight());
+      setCharWidth(ww);
+    }
+    viewStyle.setFontName(font.getName());
+    viewStyle.setFontStyle(font.getStyle());
+    viewStyle.setFontSize(font.getSize());
+
+    validCharWidth = true;
+  }
+
+  @Override
+  public void setViewStyle(ViewStyleI settingsForView)
+  {
+    super.setViewStyle(settingsForView);
+    setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
+            viewStyle.getFontSize()), false);
+
+  }
+
+  /**
+   * DOCUMENT ME!
+   * 
+   * @return DOCUMENT ME!
+   */
+  public Font getFont()
+  {
+    return font;
+  }
+
+  /**
+   * DOCUMENT ME!
+   * 
+   * @param align
+   *          DOCUMENT ME!
+   */
+  public void setAlignment(AlignmentI align)
+  {
+    replaceMappings(align);
+    this.alignment = align;
+  }
+
+  /**
+   * Replace any codon mappings for this viewport with those for the given
+   * viewport
+   * 
+   * @param align
+   */
+  public void replaceMappings(AlignmentI align)
+  {
+
+    /*
+     * Deregister current mappings (if any)
+     */
+    deregisterMappings();
+
+    /*
+     * Register new mappings (if any)
+     */
+    if (align != null)
+    {
+      StructureSelectionManager ssm = StructureSelectionManager
+              .getStructureSelectionManager(Desktop.instance);
+      ssm.registerMappings(align.getCodonFrames());
+    }
+
+    /*
+     * replace mappings on our alignment
+     */
+    if (alignment != null && align != null)
+    {
+      alignment.setCodonFrames(align.getCodonFrames());
+    }
+  }
+
+  protected void deregisterMappings()
+  {
+    AlignmentI al = getAlignment();
+    if (al != null)
+    {
+      Set<AlignedCodonFrame> mappings = al.getCodonFrames();
+      if (mappings != null)
+      {
+        StructureSelectionManager ssm = StructureSelectionManager
+                .getStructureSelectionManager(Desktop.instance);
+        for (AlignedCodonFrame acf : mappings)
+        {
+          if (noReferencesTo(acf))
+          {
+            ssm.deregisterMapping(acf);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   * 
+   * @return DOCUMENT ME!
+   */
+  public char getGapCharacter()
+  {
+    return getAlignment().getGapCharacter();
+  }
+
+  /**
+   * DOCUMENT ME!
+   * 
+   * @param gap
+   *          DOCUMENT ME!
+   */
+  public void setGapCharacter(char gap)
+  {
+    if (getAlignment() != null)
+    {
+      getAlignment().setGapCharacter(gap);
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   * 
+   * @return DOCUMENT ME!
+   */
+  public ColumnSelection getColumnSelection()
+  {
+    return colSel;
+  }
+
+  /**
+   * DOCUMENT ME!
+   * 
+   * @param tree
+   *          DOCUMENT ME!
+   */
+  public void setCurrentTree(NJTree tree)
+  {
+    currentTree = tree;
+  }
+
+  /**
+   * DOCUMENT ME!
+   * 
+   * @return DOCUMENT ME!
+   */
+  public NJTree getCurrentTree()
+  {
+    return currentTree;
+  }
+
+  /**
+   * returns the visible column regions of the alignment
+   * 
+   * @param selectedRegionOnly
+   *          true to just return the contigs intersecting with the selected
+   *          area
+   * @return
+   */
+  public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
+  {
+    int[] viscontigs = null;
+    int start = 0, end = 0;
+    if (selectedRegionOnly && selectionGroup != null)
+    {
+      start = selectionGroup.getStartRes();
+      end = selectionGroup.getEndRes() + 1;
+    }
+    else
+    {
+      end = alignment.getWidth();
+    }
+    viscontigs = colSel.getVisibleContigs(start, end);
+    return viscontigs;
+  }
+
+  /**
+   * get hash of undo and redo list for the alignment
+   * 
+   * @return long[] { historyList.hashCode, redoList.hashCode };
+   */
+  public long[] getUndoRedoHash()
+  {
+    // TODO: JAL-1126
+    if (historyList == null || redoList == null)
+    {
+      return new long[] { -1, -1 };
+    }
+    return new long[] { historyList.hashCode(), this.redoList.hashCode() };
+  }
+
+  /**
+   * test if a particular set of hashcodes are different to the hashcodes for
+   * the undo and redo list.
+   * 
+   * @param undoredo
+   *          the stored set of hashcodes as returned by getUndoRedoHash
+   * @return true if the hashcodes differ (ie the alignment has been edited) or
+   *         the stored hashcode array differs in size
+   */
+  public boolean isUndoRedoHashModified(long[] undoredo)
+  {
+    if (undoredo == null)
+    {
+      return true;
+    }
+    long[] cstate = getUndoRedoHash();
+    if (cstate.length != undoredo.length)
+    {
+      return true;
+    }
+
+    for (int i = 0; i < cstate.length; i++)
+    {
+      if (cstate[i] != undoredo[i])
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public boolean followSelection = true;
+
+  /**
+   * @return true if view selection should always follow the selections
+   *         broadcast by other selection sources
+   */
+  public boolean getFollowSelection()
+  {
+    return followSelection;
+  }
+
+  /**
+   * Send the current selection to be broadcast to any selection listeners.
+   */
+  public void sendSelection()
+  {
+    jalview.structure.StructureSelectionManager
+            .getStructureSelectionManager(Desktop.instance).sendSelection(
+                    new SequenceGroup(getSelectionGroup()),
+                    new ColumnSelection(getColumnSelection()), this);
+  }
+
+  /**
+   * return the alignPanel containing the given viewport. Use this to get the
+   * components currently handling the given viewport.
+   * 
+   * @param av
+   * @return null or an alignPanel guaranteed to have non-null alignFrame
+   *         reference
+   */
+  public AlignmentPanel getAlignPanel()
+  {
+    AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
+            .getSequenceSetId());
+    for (int p = 0; aps != null && p < aps.length; p++)
+    {
+      if (aps[p].av == this)
+      {
+        return aps[p];
+      }
+    }
+    return null;
+  }
+
+  public boolean getSortByTree()
+  {
+    return sortByTree;
+  }
+
+  public void setSortByTree(boolean sort)
+  {
+    sortByTree = sort;
+  }
+
+  /**
+   * synthesize a column selection if none exists so it covers the given
+   * selection group. if wholewidth is false, no column selection is made if the
+   * selection group covers the whole alignment width.
+   * 
+   * @param sg
+   * @param wholewidth
+   */
+  public void expandColSelection(SequenceGroup sg, boolean wholewidth)
+  {
+    int sgs, sge;
+    if (sg != null
+            && (sgs = sg.getStartRes()) >= 0
+            && sg.getStartRes() <= (sge = sg.getEndRes())
+            && (colSel == null || colSel.getSelected() == null || colSel
+                    .getSelected().size() == 0))
+    {
+      if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
+      {
+        // do nothing
+        return;
+      }
+      if (colSel == null)
+      {
+        colSel = new ColumnSelection();
+      }
+      for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
+      {
+        colSel.addElement(cspos);
+      }
+    }
+  }
+
+  /**
+   * Returns the (Desktop) instance of the StructureSelectionManager
+   */
+  @Override
+  public StructureSelectionManager getStructureSelectionManager()
+  {
+    return StructureSelectionManager
+            .getStructureSelectionManager(Desktop.instance);
+  }
+
+  /**
+   * 
+   * @param pdbEntries
+   * @return an array of SequenceI arrays, one for each PDBEntry, listing which
+   *         sequences in the alignment hold a reference to it
+   */
+  public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
+  {
+    List<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
+    for (PDBEntry pdb : pdbEntries)
+    {
+      List<SequenceI> seqs = new ArrayList<SequenceI>();
+      for (SequenceI sq : alignment.getSequences())
+      {
+        Vector<PDBEntry> pdbs = sq.getDatasetSequence().getAllPDBEntries();
+        if (pdbs == null)
+        {
+          continue;
+        }
+        for (PDBEntry p1 : pdbs)
+        {
+          if (p1.getId().equals(pdb.getId()))
+          {
+            if (!seqs.contains(sq))
+            {
+              seqs.add(sq);
+              continue;
+            }
+          }
+        }
+      }
+      seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
+    }
+    return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
+  }
+
+  public boolean isNormaliseSequenceLogo()
+  {
+    return normaliseSequenceLogo;
+  }
+
+  public void setNormaliseSequenceLogo(boolean state)
+  {
+    normaliseSequenceLogo = state;
+  }
+
+  /**
+   * 
+   * @return true if alignment characters should be displayed
+   */
+  public boolean isValidCharWidth()
+  {
+    return validCharWidth;
+  }
+
+  private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
+
+  public AutoCalcSetting getCalcIdSettingsFor(String calcId)
+  {
+    return calcIdParams.get(calcId);
+  }
+
+  public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
+          boolean needsUpdate)
+  {
+    calcIdParams.put(calcId, settings);
+    // TODO: create a restart list to trigger any calculations that need to be
+    // restarted after load
+    // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
+    if (needsUpdate)
+    {
+      Cache.log.debug("trigger update for " + calcId);
+    }
+  }
+
+  /**
+   * Method called when another alignment's edit (or possibly other) command is
+   * broadcast to here.
+   *
+   * To allow for sequence mappings (e.g. protein to cDNA), we have to first
+   * 'unwind' the command on the source sequences (in simulation, not in fact),
+   * and then for each edit in turn:
+   * <ul>
+   * <li>compute the equivalent edit on the mapped sequences</li>
+   * <li>apply the mapped edit</li>
+   * <li>'apply' the source edit to the working copy of the source sequences</li>
+   * </ul>
+   * 
+   * @param command
+   * @param undo
+   * @param ssm
+   */
+  @Override
+  public void mirrorCommand(CommandI command, boolean undo,
+          StructureSelectionManager ssm, VamsasSource source)
+  {
+    /*
+     * Do nothing unless we are a 'complement' of the source. May replace this
+     * with direct calls not via SSM.
+     */
+    if (source instanceof AlignViewportI
+            && ((AlignViewportI) source).getCodingComplement() == this)
+    {
+      // ok to continue;
+    }
+    else
+    {
+      return;
+    }
+
+    CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
+            getGapCharacter());
+    if (mappedCommand != null)
+    {
+      AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
+      mappedCommand.doCommand(views);
+      getAlignPanel().alignmentChanged();
+    }
+  }
+
+  /**
+   * Add the sequences from the given alignment to this viewport. Optionally,
+   * may give the user the option to open a new frame, or split panel, with cDNA
+   * and protein linked.
+   * 
+   * @param al
+   * @param title
+   */
+  public void addAlignment(AlignmentI al, String title)
+  {
+    // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
+
+    // JBPComment: title is a largely redundant parameter at the moment
+    // JBPComment: this really should be an 'insert/pre/append' controller
+    // JBPComment: but the DNA/Protein check makes it a bit more complex
+
+    // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
+    // this comment:
+    // TODO: create undo object for this JAL-1101
+
+    /*
+     * If any cDNA/protein mappings can be made between the alignments, offer to
+     * open a linked alignment with split frame option.
+     */
+    if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
+    {
+      if (al.getDataset() == null)
+      {
+        // need to create ds seqs
+        for (SequenceI sq : al.getSequences())
+        {
+          if (sq.getDatasetSequence() == null)
+          {
+            sq.createDatasetSequence();
+          }
+        }
+      }
+      if (AlignmentUtils.isMappable(al, getAlignment()))
+      {
+        if (openLinkedAlignment(al, title))
+        {
+          return;
+        }
+      }
+    }
+
+    /*
+     * No mappings, or offer declined - add sequences to this alignment
+     */
+    // TODO: JAL-407 regardless of above - identical sequences (based on ID and
+    // provenance) should share the same dataset sequence
+
+    for (int i = 0; i < al.getHeight(); i++)
+    {
+      getAlignment().addSequence(al.getSequenceAt(i));
+    }
+
+    setEndSeq(getAlignment().getHeight());
+    firePropertyChange("alignment", null, getAlignment().getSequences());
+  }
+
+  /**
+   * Show a dialog with the option to open and link (cDNA <-> protein) as a new
+   * alignment, either as a standalone alignment or in a split frame. Returns
+   * true if the new alignment was opened, false if not, because the user
+   * declined the offer.
+   * 
+   * @param al
+   * @param title
+   */
+  protected boolean openLinkedAlignment(AlignmentI al, String title)
+  {
+    String[] options = new String[] {
+        MessageManager.getString("action.no"),
+        MessageManager.getString("label.split_window"),
+        MessageManager.getString("label.new_window"), };
+    final String question = JvSwingUtils.wrapTooltip(true,
+            MessageManager.getString("label.open_split_window?"));
+    int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
+            MessageManager.getString("label.open_split_window"),
+            JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
+            options, options[0]);
+
+    if (response != 1 && response != 2)
+    {
+      return false;
+    }
+    final boolean openSplitPane = (response == 1);
+    final boolean openInNewWindow = (response == 2);
+
+    /*
+     * Identify protein and dna alignments. Make a copy of this one if opening
+     * in a new split pane.
+     */
+    AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
+            : getAlignment();
+    AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
+    final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
+
+    /*
+     * Map sequences. At least one should get mapped as we have already passed
+     * the test for 'mappability'. Any mappings made will be added to the
+     * protein alignment. Note creating dataset sequences on the new alignment
+     * is a pre-requisite for building mappings.
+     */
+    al.setDataset(null);
+    AlignmentUtils.mapProteinToCdna(protein, cdna);
+
+    /*
+     * Create the AlignFrame for the added alignment. If it is protein, mappings
+     * are registered with StructureSelectionManager as a side-effect.
+     */
+    AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
+            AlignFrame.DEFAULT_HEIGHT);
+    newAlignFrame.setTitle(title);
+    newAlignFrame.statusBar.setText(MessageManager.formatMessage(
+            "label.successfully_loaded_file", new Object[] { title }));
+
+    // TODO if we want this (e.g. to enable reload of the alignment from file),
+    // we will need to add parameters to the stack.
+    // if (!protocol.equals(AppletFormatAdapter.PASTE))
+    // {
+    // alignFrame.setFileName(file, format);
+    // }
+
+    if (openInNewWindow)
+    {
+      Desktop.addInternalFrame(newAlignFrame, title,
+              AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+    }
+
+    try
+    {
+      newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
+              "SHOW_FULLSCREEN", false));
+    } catch (java.beans.PropertyVetoException ex)
+    {
+    }
+
+    if (openSplitPane)
+    {
+      al.alignAs(thisAlignment);
+      protein = openSplitFrame(newAlignFrame, thisAlignment);
+    }
+
+    return true;
+  }
+
+  /**
+   * Helper method to open a new SplitFrame holding linked dna and protein
+   * alignments.
+   * 
+   * @param newAlignFrame
+   *          containing a new alignment to be shown
+   * @param complement
+   *          cdna/protein complement alignment to show in the other split half
+   * @return the protein alignment in the split frame
+   */
+  protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
+          AlignmentI complement)
+  {
+    /*
+     * Make a new frame with a copy of the alignment we are adding to. If this
+     * is protein, the mappings to cDNA will be registered with
+     * StructureSelectionManager as a side-effect.
+     */
+    AlignFrame copyMe = new AlignFrame(complement,
+            AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+    copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
+
+    AlignmentI al = newAlignFrame.viewport.getAlignment();
+    final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
+            : newAlignFrame;
+    final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
+    cdnaFrame.setVisible(true);
+    proteinFrame.setVisible(true);
+    String linkedTitle = MessageManager
+            .getString("label.linked_view_title");
+
+    /*
+     * Open in split pane. DNA sequence above, protein below.
+     */
+    JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
+    Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
+
+    return proteinFrame.viewport.getAlignment();
+  }
+
+  public AnnotationColumnChooser getAnnotationColumnSelectionState()
+  {
+    return annotationColumnSelectionState;
+  }
+
+  public void setAnnotationColumnSelectionState(
+          AnnotationColumnChooser currentAnnotationColumnSelectionState)
+  {
+    this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
+  }
+
+  @Override
+  public void setIdWidth(int i)
+  {
+    super.setIdWidth(i);
+    AlignmentPanel ap = getAlignPanel();
+    if (ap != null)
+    {
+      // modify GUI elements to reflect geometry change
+      Dimension idw = getAlignPanel().getIdPanel().getIdCanvas()
+              .getPreferredSize();
+      idw.width = i;
+      getAlignPanel().getIdPanel().getIdCanvas().setPreferredSize(idw);
+    }
+  }
+
+  public Rectangle getExplodedGeometry()
+  {
+    return explodedGeometry;
+  }
+
+  public void setExplodedGeometry(Rectangle explodedPosition)
+  {
+    this.explodedGeometry = explodedPosition;
+  }
+
+  public boolean isGatherViewsHere()
+  {
+    return gatherViewsHere;
+  }
+
+  public void setGatherViewsHere(boolean gatherViewsHere)
+  {
+    this.gatherViewsHere = gatherViewsHere;
+  }
+
+  /**
+   * If this viewport has a (Protein/cDNA) complement, then scroll the
+   * complementary alignment to match this one.
+   */
+  public void scrollComplementaryAlignment()
+  {
+    /*
+     * Populate a SearchResults object with the mapped location to scroll to. If
+     * there is no complement, or it is not following highlights, or no mapping
+     * is found, the result will be empty.
+     */
+    SearchResults sr = new SearchResults();
+    int verticalOffset = findComplementScrollTarget(sr);
+    if (!sr.isEmpty())
+    {
+      // TODO would like next line without cast but needs more refactoring...
+      final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
+              .getAlignPanel();
+      complementPanel.setFollowingComplementScroll(true);
+      complementPanel.scrollToCentre(sr, verticalOffset);
+    }
+  }
+
+  /**
+   * Answers true if no alignment holds a reference to the given mapping
+   * 
+   * @param acf
+   * @return
+   */
+  protected boolean noReferencesTo(AlignedCodonFrame acf)
+  {
+    AlignFrame[] frames = Desktop.getAlignFrames();
+    if (frames == null)
+    {
+      return true;
+    }
+    for (AlignFrame af : frames)
+    {
+      if (!af.isClosed())
+      {
+        for (AlignmentViewPanel ap : af.getAlignPanels())
+        {
+          AlignmentI al = ap.getAlignment();
+          if (al != null && al.getCodonFrames().contains(acf))
+          {
+            return false;
+          }
+        }
+      }
+    }
+    return true;
+  }
+
+}