off by one bug in hiden column unmarshalling
authorjprocter <Jim Procter>
Tue, 22 Aug 2006 08:32:40 +0000 (08:32 +0000)
committerjprocter <Jim Procter>
Tue, 22 Aug 2006 08:32:40 +0000 (08:32 +0000)
src/jalview/gui/Jalview2XML.java

index 5b8f2dd..8cf676d 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2006 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
-\r
-import jalview.schemes.*;\r
-\r
-import jalview.gui.*;\r
-\r
-import java.io.*;\r
-\r
-import java.net.*;\r
-\r
-import java.util.*;\r
-\r
-import java.util.jar.*;\r
-\r
-import javax.swing.*;\r
-\r
-import org.exolab.castor.xml.*;\r
-\r
-import jalview.schemabinding.version2.*;\r
-\r
-\r
-\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class Jalview2XML\r
-{\r
-    // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE\r
-    public void SaveState(File statefile)\r
-    {\r
-        long creation = System.currentTimeMillis();\r
-        JInternalFrame[] frames = Desktop.desktop.getAllFrames();\r
-\r
-        if (frames == null)\r
-        {\r
-            return;\r
-        }\r
-\r
-        try\r
-        {\r
-            FileOutputStream fos = new FileOutputStream(statefile);\r
-            JarOutputStream jout = new JarOutputStream(fos);\r
-\r
-            //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS\r
-            ////////////////////////////////////////////////////\r
-            PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,\r
-                        "UTF-8"));\r
-\r
-            Vector shortNames = new Vector();\r
-\r
-            //REVERSE ORDER\r
-            for (int i = frames.length - 1; i > -1; i--)\r
-            {\r
-                if (frames[i] instanceof AlignFrame)\r
-                {\r
-                    AlignFrame af = (AlignFrame) frames[i];\r
-\r
-                    String shortName = af.getTitle();\r
-\r
-                    if (shortName.indexOf(File.separatorChar) > -1)\r
-                    {\r
-                        shortName = shortName.substring(shortName.lastIndexOf(\r
-                                    File.separatorChar) + 1);\r
-                    }\r
-\r
-                    int count = 1;\r
-\r
-                    while (shortNames.contains(shortName))\r
-                    {\r
-                        if (shortName.endsWith("_" + (count - 1)))\r
-                        {\r
-                            shortName = shortName.substring(0,\r
-                                    shortName.lastIndexOf("_"));\r
-                        }\r
-\r
-                        shortName = shortName.concat("_" + count);\r
-                        count++;\r
-                    }\r
-\r
-                    shortNames.addElement(shortName);\r
-\r
-                    if (!shortName.endsWith(".xml"))\r
-                    {\r
-                        shortName = shortName + ".xml";\r
-                    }\r
-\r
-                    SaveState(af, creation, shortName, jout, out);\r
-                }\r
-            }\r
-\r
-            out.close();\r
-            jout.close();\r
-        }\r
-        catch (Exception ex)\r
-        {\r
-            ex.printStackTrace();\r
-        }\r
-    }\r
-\r
-    // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW\r
-    public void SaveAlignment(AlignFrame af, String jarFile,\r
-        String fileName)\r
-    {\r
-        try\r
-        {\r
-            FileOutputStream fos = new FileOutputStream(jarFile);\r
-            JarOutputStream jout = new JarOutputStream(fos);\r
-\r
-            //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS\r
-            ////////////////////////////////////////////////////\r
-            PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,\r
-                        "UTF-8"));\r
-\r
-            SaveState(af, System.currentTimeMillis(), fileName, jout, out);\r
-            out.close();\r
-            jout.close();\r
-        }\r
-        catch (Exception ex)\r
-        {\r
-          ex.printStackTrace();\r
-        }\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param af DOCUMENT ME!\r
-     * @param timeStamp DOCUMENT ME!\r
-     * @param fileName DOCUMENT ME!\r
-     * @param jout DOCUMENT ME!\r
-     * @param out DOCUMENT ME!\r
-     */\r
-    public void SaveState(AlignFrame af, long timeStamp,\r
-        String fileName, JarOutputStream jout, PrintWriter out)\r
-    {\r
-        Vector seqids = new Vector();\r
-        Vector userColours = new Vector();\r
-\r
-        AlignViewport av = af.viewport;\r
-\r
-        JalviewModel object = new JalviewModel();\r
-        object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel());\r
-\r
-        object.setCreationDate(new java.util.Date(timeStamp));\r
-        object.setVersion(jalview.bin.Cache.getProperty("VERSION"));\r
-\r
-        jalview.datamodel.AlignmentI jal = af.viewport.alignment;\r
-        jalview.datamodel.AlignmentI jalhidden = null;\r
-\r
-        if(av.hasHiddenRows)\r
-        {\r
-          jalhidden = jal;\r
-          jal = jal.getHiddenSequences().getFullAlignment();\r
-        }\r
-\r
-\r
-        SequenceSet vamsasSet = new SequenceSet();\r
-        Sequence vamsasSeq;\r
-        JalviewModelSequence jms = new JalviewModelSequence();\r
-\r
-        vamsasSet.setGapChar(jal.getGapCharacter() + "");\r
-\r
-        JSeq jseq;\r
-        Vector pdbfiles = null;\r
-\r
-        //SAVE SEQUENCES\r
-        int id = 0;\r
-        for (int i = 0; i < jal.getHeight(); i++)\r
-        {\r
-            seqids.add(jal.getSequenceAt(i));\r
-            vamsasSeq = new Sequence();\r
-            vamsasSeq.setId(id + "");\r
-            vamsasSeq.setName(jal.getSequenceAt(i).getName());\r
-            vamsasSeq.setSequence(jal.getSequenceAt(i).getSequence());\r
-            vamsasSeq.setDescription(jal.getSequenceAt(i).getDescription());\r
-\r
-            if(jal.getSequenceAt(i).getDatasetSequence().getDBRef()!=null)\r
-            {\r
-              jalview.datamodel.DBRefEntry [] dbrefs =\r
-                  jal.getSequenceAt(i).getDatasetSequence().getDBRef();\r
-\r
-              for(int d=0; d<dbrefs.length; d++)\r
-              {\r
-                DBRef dbref = new DBRef();\r
-                dbref.setSource( dbrefs[d].getSource() );\r
-                dbref.setVersion( dbrefs[d].getVersion());\r
-                dbref.setAccessionId(dbrefs[d].getAccessionId());\r
-                vamsasSeq.addDBRef(dbref);\r
-              }\r
-            }\r
-\r
-            jseq = new JSeq();\r
-            jseq.setStart(jal.getSequenceAt(i).getStart());\r
-            jseq.setEnd(jal.getSequenceAt(i).getEnd());\r
-            jseq.setColour(jal.getSequenceAt(i).getColor().getRGB());\r
-\r
-            jseq.setId(id);\r
-\r
-            if (av.hasHiddenRows)\r
-            {\r
-              jseq.setHidden(jalhidden.getHiddenSequences().isHidden(\r
-                  jal.getSequenceAt(i)));\r
-\r
-              if(jal.getSequenceAt(i).getHiddenSequences()!=null)\r
-              {\r
-                jalview.datamodel.SequenceI [] reps =\r
-                    jal.getSequenceAt(i).getHiddenSequences().getSequencesInOrder(jal);\r
-\r
-                for(int h=0; h<reps.length; h++)\r
-                {\r
-                  jseq.addHiddenSequences(\r
-                      jal.findIndex(reps[h])\r
-                      );\r
-                }\r
-              }\r
-            }\r
-\r
-\r
-            if(jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures()!=null)\r
-            {\r
-              jalview.datamodel.SequenceFeature[] sf\r
-                  = jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures();\r
-              int index = 0;\r
-              while(index < sf.length)\r
-              {\r
-                Features features = new Features();\r
-\r
-                features.setBegin(sf[index].getBegin());\r
-                features.setEnd(sf[index].getEnd());\r
-                features.setDescription(sf[index].getDescription());\r
-                features.setType(sf[index].getType());\r
-                features.setFeatureGroup(sf[index].getFeatureGroup());\r
-                features.setScore(sf[index].getScore());\r
-                if(sf[index].links!=null)\r
-                {\r
-                  for(int l=0; l<sf[index].links.size(); l++)\r
-                  {\r
-                    OtherData keyValue = new OtherData();\r
-                    keyValue.setKey("LINK_"+l);\r
-                    keyValue.setValue(sf[index].links.elementAt(l).toString());\r
-                    features.addOtherData(keyValue);\r
-                  }\r
-                }\r
-                if(sf[index].otherDetails!=null)\r
-                {\r
-                  String key;\r
-                  Enumeration keys = sf[index].otherDetails.keys();\r
-                  while(keys.hasMoreElements())\r
-                  {\r
-                    key = keys.nextElement().toString();\r
-                    OtherData keyValue = new OtherData();\r
-                    keyValue.setKey( key );\r
-                    keyValue.setValue(\r
-                        sf[index].otherDetails.get(key).toString());\r
-                    features.addOtherData(keyValue);\r
-                  }\r
-                }\r
-\r
-                jseq.addFeatures(features);\r
-                index ++;\r
-              }\r
-            }\r
-\r
-            if(jal.getSequenceAt(i).getDatasetSequence().getPDBId()!=null)\r
-            {\r
-              Enumeration en = jal.getSequenceAt(i).getDatasetSequence().getPDBId().elements();\r
-              while(en.hasMoreElements())\r
-              {\r
-                Pdbids pdb = new Pdbids();\r
-                jalview.datamodel.PDBEntry entry\r
-                   = (jalview.datamodel.PDBEntry)en.nextElement();\r
-\r
-                pdb.setId(entry.getId());\r
-                pdb.setType(entry.getType());\r
-\r
-                if(entry.getFile()!=null)\r
-                {\r
-                  if(pdbfiles==null)\r
-                    pdbfiles = new Vector();\r
-\r
-\r
-                  if(!pdbfiles.contains(entry.getId()))\r
-                  {\r
-                    pdbfiles.addElement(entry.getId());\r
-                    try\r
-                    {\r
-                      File file = new File(entry.getFile());\r
-                      if(file.exists())\r
-                      {\r
-                        byte[] data = new byte[ (int) file.length()];\r
-                        jout.putNextEntry(new JarEntry(entry.getId()));\r
-                        DataInputStream dis = new DataInputStream(new\r
-                            FileInputStream(file));\r
-                        dis.readFully(data);\r
-\r
-                        DataOutputStream dout = new DataOutputStream(jout);\r
-                        dout.write(data, 0, data.length);\r
-                        jout.closeEntry();\r
-                      }\r
-                    }\r
-                    catch (Exception ex)\r
-                    {\r
-                      ex.printStackTrace();\r
-                    }\r
-                  }\r
-                }\r
-\r
-\r
-                if(entry.getProperty()!=null)\r
-                {\r
-                  PdbentryItem item = new PdbentryItem();\r
-                  Hashtable properties = entry.getProperty();\r
-                  Enumeration en2 = properties.keys();\r
-                  while(en2.hasMoreElements())\r
-                  {\r
-                    Property prop = new Property();\r
-                    String key = en2.nextElement().toString();\r
-                    prop.setName(key);\r
-                    prop.setValue( properties.get(key).toString() );\r
-                    item.addProperty(prop);\r
-                  }\r
-                  pdb.addPdbentryItem(item);\r
-                }\r
-\r
-                jseq.addPdbids(pdb);\r
-              }\r
-            }\r
-\r
-            jms.addJSeq(jseq);\r
-            vamsasSet.addSequence(vamsasSeq);\r
-            id++;\r
-        }\r
-\r
-        //SAVE TREES\r
-        ///////////////////////////////////\r
-        if (af.viewport.currentTree != null)\r
-        {\r
-          // FIND ANY ASSOCIATED TREES\r
-          // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT\r
-          if (Desktop.desktop != null)\r
-          {\r
-            JInternalFrame[] frames = Desktop.desktop.getAllFrames();\r
-\r
-            for (int t = 0; t < frames.length; t++)\r
-            {\r
-              if (frames[t] instanceof TreePanel)\r
-              {\r
-                TreePanel tp = (TreePanel) frames[t];\r
-\r
-                if (tp.treeCanvas.av.alignment == jal)\r
-                {\r
-                  Tree tree = new Tree();\r
-                  tree.setTitle(tp.getTitle());\r
-                  tree.setCurrentTree( (af.viewport.currentTree == tp.getTree()));\r
-                  tree.setNewick(tp.getTree().toString());\r
-                  tree.setThreshold(tp.treeCanvas.threshold);\r
-\r
-                  tree.setFitToWindow(tp.fitToWindow.getState());\r
-                  tree.setFontName(tp.getTreeFont().getName());\r
-                  tree.setFontSize(tp.getTreeFont().getSize());\r
-                  tree.setFontStyle(tp.getTreeFont().getStyle());\r
-                  tree.setMarkUnlinked(tp.placeholdersMenu.getState());\r
-\r
-                  tree.setShowBootstrap(tp.bootstrapMenu.getState());\r
-                  tree.setShowDistances(tp.distanceMenu.getState());\r
-\r
-                  tree.setHeight(tp.getHeight());\r
-                  tree.setWidth(tp.getWidth());\r
-                  tree.setXpos(tp.getX());\r
-                  tree.setYpos(tp.getY());\r
-\r
-                  jms.addTree(tree);\r
-                }\r
-              }\r
-            }\r
-          }\r
-        }\r
-\r
-        //SAVE ANNOTATIONS\r
-        if (jal.getAlignmentAnnotation() != null)\r
-        {\r
-            jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();\r
-\r
-            for (int i = 0; i < aa.length; i++)\r
-            {\r
-                Annotation an = new Annotation();\r
-\r
-                if (aa[i].label.equals("Quality") ||\r
-                        aa[i].label.equals("Conservation") ||\r
-                        aa[i].label.equals("Consensus"))\r
-                {\r
-                    an.setLabel(aa[i].label);\r
-                    an.setGraph(true);\r
-                    vamsasSet.addAnnotation(an);\r
-                    continue;\r
-                }\r
-\r
-\r
-                an.setDescription(aa[i].description);\r
-\r
-                if(aa[i].sequenceRef!=null)\r
-                 {\r
-                   an.setSequenceRef(aa[i].sequenceRef.getName());\r
-                 }\r
-\r
-                if(aa[i].graph>0)\r
-                {\r
-                  an.setGraph(true);\r
-                  an.setGraphType(aa[i].graph);\r
-                  an.setGraphGroup(aa[i].graphGroup);\r
-                  if(aa[i].getThreshold()!=null)\r
-                  {\r
-                    ThresholdLine line = new ThresholdLine();\r
-                    line.setLabel(aa[i].getThreshold().label);\r
-                    line.setValue(aa[i].getThreshold().value);\r
-                    line.setColour(aa[i].getThreshold().colour.getRGB());\r
-                    an.setThresholdLine(line);\r
-                  }\r
-                }\r
-                else\r
-                  an.setGraph(false);\r
-\r
-                an.setLabel(aa[i].label);\r
-\r
-                AnnotationElement ae;\r
-\r
-                for (int a = 0; a < aa[i].annotations.length; a++)\r
-                {\r
-                    if ((aa[i] == null) || (aa[i].annotations[a] == null))\r
-                    {\r
-                        continue;\r
-                    }\r
-\r
-                    ae = new AnnotationElement();\r
-                    ae.setDescription(aa[i].annotations[a].description);\r
-                    ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);\r
-                    ae.setValue(aa[i].annotations[a].value);\r
-                    ae.setPosition(a);\r
-                    ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure +\r
-                        "");\r
-\r
-                    if(aa[i].annotations[a].colour!=java.awt.Color.black)\r
-                      ae.setColour(aa[i].annotations[a].colour.getRGB());\r
-\r
-                    an.addAnnotationElement(ae);\r
-                }\r
-\r
-                vamsasSet.addAnnotation(an);\r
-            }\r
-        }\r
-\r
-        //SAVE GROUPS\r
-        if (jal.getGroups() != null)\r
-        {\r
-            JGroup[] groups = new JGroup[jal.getGroups().size()];\r
-\r
-            for (int i = 0; i < groups.length; i++)\r
-            {\r
-                groups[i] = new JGroup();\r
-\r
-                jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal.getGroups()\r
-                                                                                          .elementAt(i);\r
-                groups[i].setStart(sg.getStartRes());\r
-                groups[i].setEnd(sg.getEndRes());\r
-                groups[i].setName(sg.getName());\r
-                if(sg.cs!=null)\r
-                {\r
-                  if (sg.cs.conservationApplied())\r
-                  {\r
-                    groups[i].setConsThreshold(sg.cs.getConservationInc());\r
-\r
-                    if (sg.cs instanceof jalview.schemes.UserColourScheme)\r
-                    {\r
-                      groups[i].setColour(SetUserColourScheme(sg.cs,\r
-                          userColours,\r
-                          jms));\r
-                    }\r
-                    else\r
-                    {\r
-                      groups[i].setColour(ColourSchemeProperty.getColourName(sg.\r
-                          cs));\r
-                    }\r
-                  }\r
-                  else if(sg.cs instanceof jalview.schemes.AnnotationColourGradient)\r
-                  {\r
-                    groups[i].setColour(\r
-                        ColourSchemeProperty.getColourName(\r
-                      ( (jalview.schemes.AnnotationColourGradient) sg.cs).getBaseColour()));\r
-                  }\r
-                  else if (sg.cs instanceof jalview.schemes.UserColourScheme)\r
-                  {\r
-                    groups[i].setColour(SetUserColourScheme(sg.cs, userColours,\r
-                        jms));\r
-                  }\r
-                  else\r
-                  {\r
-                    groups[i].setColour(ColourSchemeProperty.getColourName(\r
-                        sg.cs));\r
-                  }\r
-\r
-                  groups[i].setPidThreshold(sg.cs.getThreshold());\r
-                }\r
-\r
-                groups[i].setOutlineColour(sg.getOutlineColour().getRGB());\r
-                groups[i].setDisplayBoxes(sg.getDisplayBoxes());\r
-                groups[i].setDisplayText(sg.getDisplayText());\r
-                groups[i].setColourText(sg.getColourText());\r
-\r
-                for (int s = 0; s < sg.getSize(false); s++)\r
-                {\r
-                    jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg.getSequenceAt(s);\r
-                    int index = seqids.indexOf(seq);\r
-                    groups[i].addSeq(index);\r
-                }\r
-            }\r
-\r
-            jms.setJGroup(groups);\r
-        }\r
-\r
-\r
-        ///////////SAVE VIEWPORT\r
-        Viewport view = new Viewport();\r
-        view.setTitle(af.getTitle());\r
-        view.setXpos(af.getX());\r
-        view.setYpos(af.getY());\r
-        view.setWidth(af.getWidth());\r
-        view.setHeight(af.getHeight());\r
-        view.setStartRes(av.startRes);\r
-        view.setStartSeq(av.startSeq);\r
-\r
-        if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)\r
-        {\r
-            view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),\r
-                    userColours, jms));\r
-        }\r
-        else if(av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)\r
-        {\r
-           jalview.schemes.AnnotationColourGradient acg\r
-              = (jalview.schemes.AnnotationColourGradient)av.getGlobalColourScheme();\r
-\r
-            AnnotationColours ac = new AnnotationColours();\r
-            ac.setAboveThreshold(acg.getAboveThreshold());\r
-            ac.setThreshold(acg.getAnnotationThreshold());\r
-            ac.setAnnotation(acg.getAnnotation());\r
-            if(acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)\r
-              ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),\r
-                    userColours, jms));\r
-            else\r
-              ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour()));\r
-\r
-            ac.setMaxColour(acg.getMaxColour().getRGB());\r
-            ac.setMinColour(acg.getMinColour().getRGB());\r
-            view.setAnnotationColours(ac);\r
-            view.setBgColour("AnnotationColourGradient");\r
-        }\r
-        else\r
-        {\r
-            view.setBgColour(ColourSchemeProperty.getColourName(\r
-                    av.getGlobalColourScheme()));\r
-        }\r
-\r
-        ColourSchemeI cs = av.getGlobalColourScheme();\r
-\r
-        if(cs!=null)\r
-        {\r
-          if (cs.conservationApplied())\r
-          {\r
-            view.setConsThreshold(cs.getConservationInc());\r
-            if (cs instanceof jalview.schemes.UserColourScheme)\r
-              view.setBgColour(SetUserColourScheme(cs, userColours, jms));\r
-          }\r
-\r
-          if (cs instanceof ResidueColourScheme)\r
-          {\r
-            view.setPidThreshold(cs.getThreshold());\r
-          }\r
-        }\r
-\r
-        view.setConservationSelected(av.getConservationSelected());\r
-        view.setPidSelected(av.getAbovePIDThreshold());\r
-        view.setFontName(av.font.getName());\r
-        view.setFontSize(av.font.getSize());\r
-        view.setFontStyle(av.font.getStyle());\r
-        view.setRenderGaps(av.renderGaps);\r
-        view.setShowAnnotation(av.getShowAnnotation());\r
-        view.setShowBoxes(av.getShowBoxes());\r
-        view.setShowColourText(av.getColourText());\r
-        view.setShowConservation(av.showConservation);\r
-        view.setShowFullId(av.getShowJVSuffix());\r
-        view.setShowIdentity(av.showIdentity);\r
-        view.setShowQuality(av.showQuality);\r
-        view.setShowSequenceFeatures(av.showSequenceFeatures);\r
-        view.setShowText(av.getShowText());\r
-        view.setWrapAlignment(av.getWrapAlignment());\r
-\r
-        if(av.featuresDisplayed!=null)\r
-        {\r
-          jalview.schemabinding.version2.FeatureSettings fs\r
-              = new jalview.schemabinding.version2.FeatureSettings();\r
-\r
-          String [] renderOrder =\r
-              af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;\r
-\r
-          Vector settingsAdded = new Vector();\r
-          for(int ro=0; ro<renderOrder.length; ro++)\r
-          {\r
-            Setting setting = new Setting();\r
-            setting.setType(renderOrder[ro]);\r
-            setting.setColour(\r
-                af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().getColour(renderOrder[ro]).getRGB()\r
-                );\r
-\r
-            setting.setDisplay(\r
-                av.featuresDisplayed.containsKey(renderOrder[ro])\r
-                );\r
-\r
-            fs.addSetting(setting);\r
-            settingsAdded.addElement(renderOrder[ro]);\r
-          }\r
-\r
-          //Make sure we save none displayed feature settings\r
-          Enumeration en =\r
-              af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours.keys();\r
-          while(en.hasMoreElements())\r
-          {\r
-            String key = en.nextElement().toString();\r
-            if(settingsAdded.contains(key))\r
-              continue;\r
-\r
-            Setting setting = new Setting();\r
-            setting.setType(key);\r
-            setting.setColour(\r
-                af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().getColour(key).getRGB()\r
-                );\r
-\r
-            setting.setDisplay(false);\r
-\r
-            fs.addSetting(setting);\r
-            settingsAdded.addElement(key);\r
-          }\r
-\r
-          jms.setFeatureSettings(fs);\r
-\r
-        }\r
-\r
-        if(av.hasHiddenColumns)\r
-        {\r
-          for(int c=0; c<av.getColumnSelection().getHiddenColumns().size(); c++)\r
-          {\r
-            int [] region = (int[]) av.getColumnSelection().getHiddenColumns().elementAt(c);\r
-            HiddenColumns hc = new HiddenColumns();\r
-            hc.setStart(region[0]);\r
-            hc.setEnd(region[1]);\r
-            view.addHiddenColumns(hc);\r
-          }\r
-        }\r
-\r
-        jms.addViewport(view);\r
-\r
-\r
-        object.setJalviewModelSequence(jms);\r
-        object.getVamsasModel().addSequenceSet(vamsasSet);\r
-\r
-        try\r
-        {\r
-            if (!fileName.endsWith(".xml"))\r
-            {\r
-                fileName = fileName + ".xml";\r
-            }\r
-\r
-            JarEntry entry = new JarEntry(fileName);\r
-            jout.putNextEntry(entry);\r
-\r
-            object.marshal(out);\r
-        }\r
-        catch (Exception ex)\r
-        {\r
-            ex.printStackTrace();\r
-        }\r
-    }\r
-\r
-    String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,\r
-        Vector userColours, JalviewModelSequence jms)\r
-    {\r
-        String id = null;\r
-        jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;\r
-\r
-        if (!userColours.contains(ucs))\r
-        {\r
-            userColours.add(ucs);\r
-\r
-            java.awt.Color[] colours = ucs.getColours();\r
-            jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours();\r
-            jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme();\r
-\r
-            for (int i = 0; i < colours.length; i++)\r
-            {\r
-                jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();\r
-                col.setRGB(jalview.util.Format.getHexString(colours[i]));\r
-                jbucs.addColour(col);\r
-            }\r
-\r
-            id = "ucs" + userColours.indexOf(ucs);\r
-            uc.setId(id);\r
-            uc.setUserColourScheme(jbucs);\r
-            jms.addUserColours(uc);\r
-        }\r
-\r
-        return id;\r
-    }\r
-\r
-   jalview.schemes.UserColourScheme GetUserColourScheme(\r
-        JalviewModelSequence jms, String id)\r
-    {\r
-        UserColours[] uc = jms.getUserColours();\r
-        UserColours colours = null;\r
-\r
-        for (int i = 0; i < uc.length; i++)\r
-        {\r
-            if (uc[i].getId().equals(id))\r
-            {\r
-                colours = uc[i];\r
-\r
-                break;\r
-            }\r
-        }\r
-\r
-        int csize = colours.getUserColourScheme().getColourCount();\r
-        java.awt.Color[] newColours = new java.awt.Color[csize];\r
-\r
-        for (int i = 0; i < csize; i++)\r
-        {\r
-            newColours[i] = new java.awt.Color(Integer.parseInt(\r
-                        colours.getUserColourScheme().getColour(i).getRGB(), 16));\r
-        }\r
-\r
-        return new jalview.schemes.UserColourScheme(newColours);\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param file DOCUMENT ME!\r
-     */\r
-    public AlignFrame LoadJalviewAlign(final String file)\r
-    {\r
-        jalview.gui.AlignFrame af = null;\r
-        try\r
-        {\r
-            //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING\r
-            URL url = null;\r
-\r
-            if (file.startsWith("http://"))\r
-            {\r
-                url = new URL(file);\r
-            }\r
-\r
-            JarInputStream jin = null;\r
-            JarEntry jarentry = null;\r
-            int entryCount = 1;\r
-\r
-            do\r
-            {\r
-                if (url != null)\r
-                {\r
-                    jin = new JarInputStream(url.openStream());\r
-                }\r
-                else\r
-                {\r
-                    jin = new JarInputStream(new FileInputStream(file));\r
-                }\r
-\r
-                for (int i = 0; i < entryCount; i++)\r
-                {\r
-                    jarentry = jin.getNextJarEntry();\r
-                }\r
-\r
-                if (jarentry != null && jarentry.getName().endsWith(".xml"))\r
-                {\r
-                    InputStreamReader in = new InputStreamReader(jin, "UTF-8");\r
-                    JalviewModel object = new JalviewModel();\r
-\r
-                    Unmarshaller unmar = new Unmarshaller(object);\r
-                    unmar.setValidation(false);\r
-                    object = (JalviewModel) unmar.unmarshal( in );\r
-\r
-                    af = LoadFromObject(object, file);\r
-                    entryCount++;\r
-                }\r
-                else if (jarentry != null)\r
-                {\r
-                  //Some other file here.\r
-                  entryCount++;\r
-                }\r
-            }\r
-            while (jarentry != null);\r
-        }\r
-        catch(java.net.UnknownHostException ex)\r
-        {\r
-          ex.printStackTrace();\r
-          System.err.println("Couldn't locate Jalview XML file : " +\r
-              ex + "\n");\r
-\r
-          javax.swing.SwingUtilities.invokeLater(new Runnable()\r
-          {\r
-            public void run()\r
-            {\r
-              JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                  "Couldn't locate " + file,\r
-                  "URL not found",\r
-                  JOptionPane.WARNING_MESSAGE);\r
-            }\r
-          });\r
-        }\r
-        catch (Exception ex)\r
-        {\r
-\r
-          //Is Version 1 Jar file?\r
-          af =  new Jalview2XML_V1().LoadJalviewAlign(file);\r
-\r
-          if(af!=null)\r
-          {\r
-            System.out.println("Successfully loaded archive file");\r
-            return af;\r
-          }\r
-          ex.printStackTrace();\r
-            System.err.println("Exception whilst loading jalview XML file : " +\r
-                ex + "\n");\r
-            javax.swing.SwingUtilities.invokeLater(new Runnable()\r
-            {\r
-              public void run()\r
-              {\r
-\r
-                JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                    "Error loading  " + file,\r
-                    "Error loading Jalview file",\r
-                    JOptionPane.WARNING_MESSAGE);\r
-              }});\r
-        }\r
-\r
-        return af;\r
-    }\r
-\r
-    String loadPDBFile(String file, String pdbId)\r
-    {\r
-      System.out.println("load file "+file);\r
-      try\r
-      {\r
-        JarInputStream jin = null;\r
-\r
-        if (file.startsWith("http://"))\r
-        {\r
-          jin = new JarInputStream(new URL(file).openStream());\r
-        }\r
-        else\r
-        {\r
-          jin = new JarInputStream(new FileInputStream(file));\r
-        }\r
-\r
-        JarEntry entry = null;\r
-        do\r
-        {\r
-          entry = jin.getNextJarEntry();\r
-        }\r
-        while (!entry.getName().equals(pdbId));\r
-\r
-        BufferedReader in = new BufferedReader(new InputStreamReader(jin));\r
-        File outFile = File.createTempFile("jalview_pdb", ".txt");\r
-        outFile.deleteOnExit();\r
-        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));\r
-        String data;\r
-\r
-        while ( (data = in.readLine()) != null)\r
-        {\r
-          out.println(data);\r
-        }\r
-        out.close();\r
-        return outFile.getAbsolutePath();\r
-\r
-      }\r
-      catch (Exception ex)\r
-      {\r
-        ex.printStackTrace();\r
-      }\r
-\r
-      return null;\r
-    }\r
-\r
-\r
-    AlignFrame LoadFromObject(JalviewModel object, String file)\r
-    {\r
-        Vector seqids = new Vector();\r
-        SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);\r
-        Sequence[] vamsasSeq = vamsasSet.getSequence();\r
-\r
-        JalviewModelSequence jms = object.getJalviewModelSequence();\r
-\r
-        //////////////////////////////////\r
-        //LOAD SEQUENCES\r
-        Vector hiddenSeqs = null;\r
-        jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];\r
-        JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();\r
-        for (int i = 0; i < vamsasSeq.length; i++)\r
-        {\r
-            jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),\r
-                    vamsasSeq[i].getSequence());\r
-            jseqs[i].setDescription( vamsasSeq[i].getDescription() );\r
-\r
-            if(JSEQ[i].getHidden())\r
-            {\r
-              if(hiddenSeqs == null)\r
-                hiddenSeqs = new Vector();\r
-              hiddenSeqs.addElement(jseqs[i]);\r
-            }\r
-            jseqs[i].setStart(JSEQ[i].getStart());\r
-            jseqs[i].setEnd(JSEQ[i].getEnd());\r
-            jseqs[i].setColor(new java.awt.Color(JSEQ[i].getColour()));\r
-            seqids.add(jseqs[i]);\r
-        }\r
-\r
-        ///SequenceFeatures are added to the DatasetSequence,\r
-        // so we must create the dataset before loading features\r
-        /////////////////////////////////\r
-        jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);\r
-        al.setDataset(null);\r
-        /////////////////////////////////\r
-\r
-\r
-        Hashtable pdbloaded = new Hashtable();\r
-        for (int i = 0; i < vamsasSeq.length; i++)\r
-        {\r
-          if (JSEQ[i].getFeaturesCount() > 0)\r
-          {\r
-            Features[] features = JSEQ[i].getFeatures();\r
-            for (int f = 0; f < features.length; f++)\r
-            {\r
-              jalview.datamodel.SequenceFeature sf\r
-                  = new jalview.datamodel.SequenceFeature(features[f].getType(),\r
-                  features[f].getDescription(), features[f].getStatus(),\r
-                  features[f].getBegin(), features[f].getEnd(),\r
-                  features[f].getFeatureGroup());\r
-\r
-              sf.setScore(features[f].getScore());\r
-              for(int od=0; od<features[f].getOtherDataCount(); od++)\r
-              {\r
-                OtherData keyValue = features[f].getOtherData(od);\r
-                if(keyValue.getKey().startsWith("LINK"))\r
-                  sf.addLink(keyValue.getValue());\r
-                else\r
-                  sf.setValue(keyValue.getKey(), keyValue.getValue());\r
-\r
-              }\r
-\r
-              al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);\r
-            }\r
-          }\r
-          if (JSEQ[i].getPdbidsCount() > 0)\r
-          {\r
-            Pdbids[] ids = JSEQ[i].getPdbids();\r
-            for (int p = 0; p < ids.length; p++)\r
-            {\r
-              jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();\r
-              entry.setId(ids[p].getId());\r
-              entry.setType(ids[p].getType());\r
-              if (ids[p].getFile() != null)\r
-              {\r
-                if (!pdbloaded.containsKey(ids[p].getFile()))\r
-                {\r
-                  String tmppdb = loadPDBFile(file, ids[p].getId());\r
-                  entry.setFile(tmppdb);\r
-                  pdbloaded.put(ids[p].getId(), tmppdb);\r
-                }\r
-                else\r
-                  entry.setFile(pdbloaded.get(ids[p].getId()).toString());\r
-              }\r
-\r
-              al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);\r
-            }\r
-          }\r
-          if(vamsasSeq[i].getDBRefCount()>0)\r
-          {\r
-            for(int d=0; d<vamsasSeq[i].getDBRefCount(); d++)\r
-            {\r
-              jalview.datamodel.DBRefEntry entry =\r
-                  new jalview.datamodel.DBRefEntry(\r
-                      vamsasSeq[i].getDBRef(d).getSource(),\r
-                      vamsasSeq[i].getDBRef(d).getVersion(),\r
-                      vamsasSeq[i].getDBRef(d).getAccessionId()\r
-                      );\r
-              al.getSequenceAt(i).getDatasetSequence().addDBRef(entry);\r
-            }\r
-\r
-          }\r
-        }\r
-\r
-\r
-\r
-         /////////////////////////////////\r
-        //////////////////////////////////\r
-        //LOAD ANNOTATIONS\r
-        boolean hideQuality = true,\r
-            hideConservation = true,\r
-            hideConsensus = true;\r
-\r
-        if (vamsasSet.getAnnotation() != null)\r
-        {\r
-            Annotation[] an = vamsasSet.getAnnotation();\r
-\r
-            for (int i = 0; i < an.length; i++)\r
-            {\r
-               if (an[i].getLabel().equals("Quality"))\r
-                {\r
-                 hideQuality = false;\r
-                 continue;\r
-                }\r
-               else if(an[i].getLabel().equals("Conservation"))\r
-               {\r
-                 hideConservation = false;\r
-                 continue;\r
-               }\r
-               else if(an[i].getLabel().equals("Consensus"))\r
-               {\r
-                 hideConsensus = false;\r
-                 continue;\r
-               }\r
-\r
-                AnnotationElement[] ae = an[i].getAnnotationElement();\r
-                jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];\r
-\r
-                for (int aa = 0; aa < ae.length; aa++)\r
-                {\r
-                    anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),\r
-                            ae[aa].getDescription(),\r
-                            ae[aa].getSecondaryStructure().length()==0?' ':ae[aa].getSecondaryStructure().charAt(0),\r
-                            ae[aa].getValue());\r
-                    anot[ae[aa].getPosition()].colour = new java.awt.Color( ae[aa].getColour() );\r
-                }\r
-\r
-                jalview.datamodel.AlignmentAnnotation jaa = null;\r
-\r
-                if (an[i].getGraph())\r
-                {\r
-                  jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
-                      an[i].getDescription(), anot, 0, 0,\r
-                      an[i].getGraphType());\r
-\r
-                  jaa.graphGroup = an[i].getGraphGroup();\r
-\r
-                  if (an[i].getThresholdLine() != null)\r
-                  {\r
-                    jaa.setThreshold(new jalview.datamodel.GraphLine(\r
-                                  an[i].getThresholdLine().getValue(),\r
-                                  an[i].getThresholdLine().getLabel(),\r
-                                new java.awt.Color(an[i].getThresholdLine().getColour()))\r
-                             );\r
-\r
-                  }\r
-\r
-                }\r
-                else\r
-                {\r
-                    jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
-                            an[i].getDescription(), anot);\r
-                }\r
-\r
-                if(an[i].getSequenceRef()!=null)\r
-                {\r
-                  jaa.createSequenceMapping(\r
-                      al.findName(an[i].getSequenceRef()), 1\r
-                      );\r
-                  al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);\r
-                }\r
-\r
-                al.addAnnotation(jaa);\r
-            }\r
-        }\r
-\r
-\r
-        //  af.changeColour() );\r
-        /////////////////////////\r
-        //LOAD GROUPS\r
-        if (jms.getJGroupCount() > 0)\r
-        {\r
-            JGroup[] groups = jms.getJGroup();\r
-\r
-            for (int i = 0; i < groups.length; i++)\r
-            {\r
-                ColourSchemeI cs = null;\r
-\r
-                if (groups[i].getColour() != null)\r
-                {\r
-                    if (groups[i].getColour().startsWith("ucs"))\r
-                    {\r
-                        cs = GetUserColourScheme(jms, groups[i].getColour());\r
-                    }\r
-                    else\r
-                    {\r
-                        cs = ColourSchemeProperty.getColour(al,\r
-                                groups[i].getColour());\r
-                    }\r
-\r
-                    if(cs!=null)\r
-                      cs.setThreshold(groups[i].getPidThreshold(), true);\r
-                }\r
-\r
-                Vector seqs = new Vector();\r
-                int[] ids = groups[i].getSeq();\r
-\r
-                for (int s = 0; s < ids.length; s++)\r
-                {\r
-                    seqs.addElement((jalview.datamodel.SequenceI) seqids.elementAt(\r
-                            ids[s]));\r
-                }\r
-\r
-                jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,\r
-                        groups[i].getName(), cs, groups[i].getDisplayBoxes(),\r
-                        groups[i].getDisplayText(), groups[i].getColourText(),\r
-                        groups[i].getStart(), groups[i].getEnd());\r
-\r
-                sg.setOutlineColour(new java.awt.Color(\r
-                        groups[i].getOutlineColour()));\r
-\r
-                if (groups[i].getConsThreshold() != 0)\r
-                {\r
-                    jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",\r
-                            ResidueProperties.propHash, 3, sg.getSequences(false), 0,\r
-                            sg.getWidth() - 1);\r
-                    c.calculate();\r
-                    c.verdict(false, 25);\r
-                    sg.cs.setConservation(c);\r
-                }\r
-\r
-                al.addGroup(sg);\r
-            }\r
-        }\r
-\r
-\r
-        /////////////////////////////////\r
-        // LOAD VIEWPORT\r
-        Viewport[] views = jms.getViewport();\r
-        Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER\r
-\r
-\r
-        AlignFrame af = new AlignFrame(al);\r
-\r
-        if(hiddenSeqs!=null)\r
-        {\r
-          for(int s=0; s<JSEQ.length; s++)\r
-          {\r
-            for(int r=0; r<JSEQ[s].getHiddenSequencesCount(); r++)\r
-            {\r
-              al.getSequenceAt(s).addHiddenSequence(\r
-                  al.getSequenceAt( JSEQ[s].getHiddenSequences(r)  )\r
-                  );\r
-            }\r
-          }\r
-\r
-          for(int s=0; s<hiddenSeqs.size(); s++)\r
-          {\r
-              af.viewport.hideSequence(\r
-                (jalview.datamodel.SequenceI)hiddenSeqs.elementAt(s));\r
-          }\r
-        }\r
-\r
-\r
-        if(hideConsensus || hideQuality || hideConservation)\r
-        {\r
-          int hSize = al.getAlignmentAnnotation().length;\r
-          for (int h = 0; h < hSize; h++)\r
-          {\r
-            if (\r
-                (hideConsensus &&\r
-                 al.getAlignmentAnnotation()[h].label.equals("Consensus"))\r
-                ||\r
-                (hideQuality &&\r
-                 al.getAlignmentAnnotation()[h].label.equals("Quality"))\r
-                ||\r
-                (hideConservation &&\r
-                 al.getAlignmentAnnotation()[h].label.equals("Conservation")))\r
-            {\r
-              al.deleteAnnotation(al.getAlignmentAnnotation()[h]);\r
-              hSize--;\r
-              h--;\r
-            }\r
-          }\r
-          af.alignPanel.adjustAnnotationHeight();\r
-        }\r
-\r
-        af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),\r
-            view.getHeight());\r
-        af.viewport.setStartRes(view.getStartRes());\r
-        af.viewport.setStartSeq(view.getStartSeq());\r
-        af.viewport.setShowAnnotation(view.getShowAnnotation());\r
-        af.viewport.showConservation = view.getShowConservation();\r
-        af.viewport.showQuality = view.getShowQuality();\r
-        af.viewport.showIdentity = view.getShowIdentity();\r
-        af.viewport.setAbovePIDThreshold(view.getPidSelected());\r
-        af.abovePIDThreshold.setSelected(view.getPidSelected());\r
-        af.viewport.setColourText(view.getShowColourText());\r
-        af.colourTextMenuItem.setSelected(view.getShowColourText());\r
-        af.viewport.setConservationSelected(view.getConservationSelected());\r
-        af.conservationMenuItem.setSelected(view.getConservationSelected());\r
-\r
-        af.viewport.setShowJVSuffix(view.getShowFullId());\r
-        af.seqLimits.setSelected(view.getShowFullId());\r
-\r
-        af.viewport.setFont(new java.awt.Font(view.getFontName(),\r
-                view.getFontStyle(), view.getFontSize()));\r
-        af.alignPanel.fontChanged();\r
-\r
-        af.viewport.setRenderGaps(view.getRenderGaps());\r
-        af.renderGapsMenuItem.setSelected(view.getRenderGaps());\r
-\r
-        af.viewport.setWrapAlignment(view.getWrapAlignment());\r
-        af.wrapMenuItem.setSelected(view.getWrapAlignment());\r
-\r
-        af.alignPanel.setWrapAlignment(view.getWrapAlignment());\r
-\r
-        af.annotationPanelMenuItem.setState(view.getShowAnnotation());\r
-        af.viewport.setShowAnnotation(view.getShowAnnotation());\r
-        af.alignPanel.setAnnotationVisible(view.getShowAnnotation());\r
-\r
-        af.viewport.setShowBoxes(view.getShowBoxes());\r
-        af.viewBoxesMenuItem.setSelected(view.getShowBoxes());\r
-        af.viewport.setShowText(view.getShowText());\r
-        af.viewTextMenuItem.setSelected(view.getShowText());\r
-\r
-        ColourSchemeI cs = null;\r
-\r
-        if (view.getBgColour() != null)\r
-        {\r
-            if (view.getBgColour().startsWith("ucs"))\r
-            {\r
-                cs = GetUserColourScheme(jms, view.getBgColour());\r
-            }\r
-            else if(view.getBgColour().startsWith("Annotation"))\r
-            {\r
-              //int find annotation\r
-              for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++)\r
-              {\r
-                if (af.viewport.alignment.getAlignmentAnnotation()[i].label.\r
-                    equals(view.getAnnotationColours().getAnnotation()))\r
-                {\r
-                  if (af.viewport.alignment.getAlignmentAnnotation()[i].\r
-                      getThreshold() == null)\r
-                  {\r
-                    af.viewport.alignment.getAlignmentAnnotation()[i].\r
-                        setThreshold(\r
-                            new jalview.datamodel.GraphLine(\r
-                                view.getAnnotationColours().getThreshold(),\r
-                                "Threshold", java.awt.Color.black)\r
-\r
-                        );\r
-                  }\r
-\r
-\r
-                  if (view.getAnnotationColours().getColourScheme().equals(\r
-                      "None"))\r
-                  {\r
-                    cs = new AnnotationColourGradient(\r
-                        af.viewport.alignment.getAlignmentAnnotation()[i],\r
-                        new java.awt.Color(view.getAnnotationColours().\r
-                                           getMinColour()),\r
-                        new java.awt.Color(view.getAnnotationColours().\r
-                                           getMaxColour()),\r
-                        view.getAnnotationColours().getAboveThreshold());\r
-                  }\r
-                  else if (view.getAnnotationColours().getColourScheme().\r
-                           startsWith("ucs"))\r
-                  {\r
-                     cs = new AnnotationColourGradient(\r
-                         af.viewport.alignment.getAlignmentAnnotation()[i],\r
-                         GetUserColourScheme(jms, view.getAnnotationColours().\r
-                                                        getColourScheme()),\r
-                         view.getAnnotationColours().getAboveThreshold()\r
-                         );\r
-                   }\r
-                   else\r
-                   {\r
-                     cs = new AnnotationColourGradient(\r
-                         af.viewport.alignment.getAlignmentAnnotation()[i],\r
-                         ColourSchemeProperty.getColour(al,\r
-                         view.getAnnotationColours().getColourScheme()),\r
-                         view.getAnnotationColours().getAboveThreshold()\r
-                         );\r
-                   }\r
-\r
-                  // Also use these settings for all the groups\r
-                  if (al.getGroups() != null)\r
-                    for (int g = 0; g < al.getGroups().size(); g++)\r
-                    {\r
-                      jalview.datamodel.SequenceGroup sg\r
-                          = (jalview.datamodel.SequenceGroup)al.getGroups().elementAt(g);\r
-\r
-                      if(sg.cs == null)\r
-                        continue;\r
-\r
-\r
-                  /*    if (view.getAnnotationColours().getColourScheme().equals("None"))\r
-                      {\r
-                        sg.cs = new AnnotationColourGradient(\r
-                            af.viewport.alignment.getAlignmentAnnotation()[i],\r
-                            new java.awt.Color(view.getAnnotationColours().\r
-                                               getMinColour()),\r
-                            new java.awt.Color(view.getAnnotationColours().\r
-                                               getMaxColour()),\r
-                            view.getAnnotationColours().getAboveThreshold());\r
-                      }\r
-                      else*/\r
-                      {\r
-                        sg.cs = new AnnotationColourGradient(\r
-                            af.viewport.alignment.getAlignmentAnnotation()[i],\r
-                            sg.cs,\r
-                            view.getAnnotationColours().getAboveThreshold()\r
-                            );\r
-                      }\r
-\r
-                    }\r
-\r
-\r
-                  break;\r
-                }\r
-\r
-              }\r
-            }\r
-            else\r
-            {\r
-                cs = ColourSchemeProperty.getColour(al, view.getBgColour());\r
-            }\r
-\r
-            if(cs!=null)\r
-            {\r
-              cs.setThreshold(view.getPidThreshold(), true);\r
-              cs.setConsensus(af.viewport.vconsensus);\r
-            }\r
-        }\r
-\r
-        af.setColourSelected(view.getBgColour());\r
-        af.viewport.setGlobalColourScheme(cs);\r
-        af.viewport.setColourAppliesToAllGroups(false);\r
-        af.changeColour(cs);\r
-        if (view.getConservationSelected() && cs!=null)\r
-        {\r
-          cs.setConservationInc(view.getConsThreshold());\r
-        }\r
-\r
-        af.viewport.setColourAppliesToAllGroups(true);\r
-\r
-        if (view.getShowSequenceFeatures())\r
-        {\r
-           af.viewport.showSequenceFeatures = true;\r
-           af.showSeqFeatures.setSelected(true);\r
-        }\r
-\r
-        if(jms.getFeatureSettings()!=null)\r
-        {\r
-          af.viewport.featuresDisplayed = new Hashtable();\r
-          String [] renderOrder = new String[jms.getFeatureSettings().getSettingCount()];\r
-         for(int fs=0; fs<jms.getFeatureSettings().getSettingCount(); fs++)\r
-         {\r
-           Setting setting = jms.getFeatureSettings().getSetting(fs);\r
-\r
-           af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(setting.getType(),\r
-               new java.awt.Color(setting.getColour()));\r
-\r
-           renderOrder[fs] = setting.getType();\r
-\r
-           if(setting.getDisplay())\r
-             af.viewport.featuresDisplayed.put(\r
-                 setting.getType(), new Integer(setting.getColour()));\r
-         }\r
-         af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;\r
-        }\r
-\r
-        if (view.getHiddenColumnsCount() > 0)\r
-        {\r
-          for (int c = 0; c < view.getHiddenColumnsCount(); c++)\r
-          {\r
-              af.viewport.hideColumns(\r
-                view.getHiddenColumns(c).getStart(),\r
-                view.getHiddenColumns(c).getEnd()+1\r
-                );\r
-          }\r
-        }\r
-\r
-\r
-        Desktop.addInternalFrame(af, view.getTitle(),\r
-             view.getWidth(), view.getHeight());\r
-\r
-        //LOAD TREES\r
-        ///////////////////////////////////////\r
-        if (jms.getTreeCount() > 0)\r
-        {\r
-            try\r
-            {\r
-                for (int t = 0; t < jms.getTreeCount(); t++)\r
-                {\r
-\r
-                    Tree tree = jms.getTree(t);\r
-\r
-                    TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(\r
-                                tree.getNewick()), tree.getTitle(),\r
-                                tree.getWidth(), tree.getHeight(),\r
-                                tree.getXpos(), tree.getYpos());\r
-\r
-                    tp.fitToWindow.setState(tree.getFitToWindow());\r
-                    tp.fitToWindow_actionPerformed(null);\r
-\r
-                    if(tree.getFontName()!=null)\r
-                      tp.setTreeFont(new java.awt.Font(tree.getFontName(),\r
-                                          tree.getFontStyle(),\r
-                                          tree.getFontSize()));\r
-                    else\r
-                      tp.setTreeFont(new java.awt.Font(view.getFontName(),\r
-                                            view.getFontStyle(),\r
-                                            tree.getFontSize()));\r
-\r
-                    tp.showPlaceholders(tree.getMarkUnlinked());\r
-                    tp.showBootstrap(tree.getShowBootstrap());\r
-                    tp.showDistances(tree.getShowDistances());\r
-\r
-                    tp.treeCanvas.threshold = tree.getThreshold();\r
-\r
-                    if (tree.getCurrentTree())\r
-                      af.viewport.setCurrentTree(tp.getTree());\r
-                }\r
-\r
-            }\r
-            catch (Exception ex)\r
-            {\r
-                ex.printStackTrace();\r
-            }\r
-\r
-        }\r
-\r
-        return af;\r
-    }\r
-}\r
-\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 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.schemes.*;
+
+import jalview.gui.*;
+
+import java.io.*;
+
+import java.net.*;
+
+import java.util.*;
+
+import java.util.jar.*;
+
+import javax.swing.*;
+
+import org.exolab.castor.xml.*;
+
+import jalview.schemabinding.version2.*;
+
+
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Jalview2XML
+{
+    // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE
+    public void SaveState(File statefile)
+    {
+        long creation = System.currentTimeMillis();
+        JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+
+        if (frames == null)
+        {
+            return;
+        }
+
+        try
+        {
+            FileOutputStream fos = new FileOutputStream(statefile);
+            JarOutputStream jout = new JarOutputStream(fos);
+
+            //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
+            ////////////////////////////////////////////////////
+            PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,
+                        "UTF-8"));
+
+            Vector shortNames = new Vector();
+
+            //REVERSE ORDER
+            for (int i = frames.length - 1; i > -1; i--)
+            {
+                if (frames[i] instanceof AlignFrame)
+                {
+                    AlignFrame af = (AlignFrame) frames[i];
+
+                    String shortName = af.getTitle();
+
+                    if (shortName.indexOf(File.separatorChar) > -1)
+                    {
+                        shortName = shortName.substring(shortName.lastIndexOf(
+                                    File.separatorChar) + 1);
+                    }
+
+                    int count = 1;
+
+                    while (shortNames.contains(shortName))
+                    {
+                        if (shortName.endsWith("_" + (count - 1)))
+                        {
+                            shortName = shortName.substring(0,
+                                    shortName.lastIndexOf("_"));
+                        }
+
+                        shortName = shortName.concat("_" + count);
+                        count++;
+                    }
+
+                    shortNames.addElement(shortName);
+
+                    if (!shortName.endsWith(".xml"))
+                    {
+                        shortName = shortName + ".xml";
+                    }
+
+                    SaveState(af, creation, shortName, jout, out);
+                }
+            }
+
+            out.close();
+            jout.close();
+        }
+        catch (Exception ex)
+        {
+            ex.printStackTrace();
+        }
+    }
+
+    // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
+    public void SaveAlignment(AlignFrame af, String jarFile,
+        String fileName)
+    {
+        try
+        {
+            FileOutputStream fos = new FileOutputStream(jarFile);
+            JarOutputStream jout = new JarOutputStream(fos);
+
+            //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
+            ////////////////////////////////////////////////////
+            PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,
+                        "UTF-8"));
+
+            SaveState(af, System.currentTimeMillis(), fileName, jout, out);
+            out.close();
+            jout.close();
+        }
+        catch (Exception ex)
+        {
+          ex.printStackTrace();
+        }
+    }
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @param af DOCUMENT ME!
+     * @param timeStamp DOCUMENT ME!
+     * @param fileName DOCUMENT ME!
+     * @param jout DOCUMENT ME!
+     * @param out DOCUMENT ME!
+     */
+    public void SaveState(AlignFrame af, long timeStamp,
+        String fileName, JarOutputStream jout, PrintWriter out)
+    {
+        Vector seqids = new Vector();
+        Vector userColours = new Vector();
+
+        AlignViewport av = af.viewport;
+
+        JalviewModel object = new JalviewModel();
+        object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel());
+
+        object.setCreationDate(new java.util.Date(timeStamp));
+        object.setVersion(jalview.bin.Cache.getProperty("VERSION"));
+
+        jalview.datamodel.AlignmentI jal = af.viewport.alignment;
+        jalview.datamodel.AlignmentI jalhidden = null;
+
+        if(av.hasHiddenRows)
+        {
+          jalhidden = jal;
+          jal = jal.getHiddenSequences().getFullAlignment();
+        }
+
+
+        SequenceSet vamsasSet = new SequenceSet();
+        Sequence vamsasSeq;
+        JalviewModelSequence jms = new JalviewModelSequence();
+
+        vamsasSet.setGapChar(jal.getGapCharacter() + "");
+
+        JSeq jseq;
+        Vector pdbfiles = null;
+
+        //SAVE SEQUENCES
+        int id = 0;
+        for (int i = 0; i < jal.getHeight(); i++)
+        {
+            seqids.add(jal.getSequenceAt(i));
+            vamsasSeq = new Sequence();
+            vamsasSeq.setId(id + "");
+            vamsasSeq.setName(jal.getSequenceAt(i).getName());
+            vamsasSeq.setSequence(jal.getSequenceAt(i).getSequence());
+            vamsasSeq.setDescription(jal.getSequenceAt(i).getDescription());
+
+            if(jal.getSequenceAt(i).getDatasetSequence().getDBRef()!=null)
+            {
+              jalview.datamodel.DBRefEntry [] dbrefs =
+                  jal.getSequenceAt(i).getDatasetSequence().getDBRef();
+
+              for(int d=0; d<dbrefs.length; d++)
+              {
+                DBRef dbref = new DBRef();
+                dbref.setSource( dbrefs[d].getSource() );
+                dbref.setVersion( dbrefs[d].getVersion());
+                dbref.setAccessionId(dbrefs[d].getAccessionId());
+                vamsasSeq.addDBRef(dbref);
+              }
+            }
+
+            jseq = new JSeq();
+            jseq.setStart(jal.getSequenceAt(i).getStart());
+            jseq.setEnd(jal.getSequenceAt(i).getEnd());
+            jseq.setColour(jal.getSequenceAt(i).getColor().getRGB());
+
+            jseq.setId(id);
+
+            if (av.hasHiddenRows)
+            {
+              jseq.setHidden(jalhidden.getHiddenSequences().isHidden(
+                  jal.getSequenceAt(i)));
+
+              if(jal.getSequenceAt(i).getHiddenSequences()!=null)
+              {
+                jalview.datamodel.SequenceI [] reps =
+                    jal.getSequenceAt(i).getHiddenSequences().getSequencesInOrder(jal);
+
+                for(int h=0; h<reps.length; h++)
+                {
+                  jseq.addHiddenSequences(
+                      jal.findIndex(reps[h])
+                      );
+                }
+              }
+            }
+
+
+            if(jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures()!=null)
+            {
+              jalview.datamodel.SequenceFeature[] sf
+                  = jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures();
+              int index = 0;
+              while(index < sf.length)
+              {
+                Features features = new Features();
+
+                features.setBegin(sf[index].getBegin());
+                features.setEnd(sf[index].getEnd());
+                features.setDescription(sf[index].getDescription());
+                features.setType(sf[index].getType());
+                features.setFeatureGroup(sf[index].getFeatureGroup());
+                features.setScore(sf[index].getScore());
+                if(sf[index].links!=null)
+                {
+                  for(int l=0; l<sf[index].links.size(); l++)
+                  {
+                    OtherData keyValue = new OtherData();
+                    keyValue.setKey("LINK_"+l);
+                    keyValue.setValue(sf[index].links.elementAt(l).toString());
+                    features.addOtherData(keyValue);
+                  }
+                }
+                if(sf[index].otherDetails!=null)
+                {
+                  String key;
+                  Enumeration keys = sf[index].otherDetails.keys();
+                  while(keys.hasMoreElements())
+                  {
+                    key = keys.nextElement().toString();
+                    OtherData keyValue = new OtherData();
+                    keyValue.setKey( key );
+                    keyValue.setValue(
+                        sf[index].otherDetails.get(key).toString());
+                    features.addOtherData(keyValue);
+                  }
+                }
+
+                jseq.addFeatures(features);
+                index ++;
+              }
+            }
+
+            if(jal.getSequenceAt(i).getDatasetSequence().getPDBId()!=null)
+            {
+              Enumeration en = jal.getSequenceAt(i).getDatasetSequence().getPDBId().elements();
+              while(en.hasMoreElements())
+              {
+                Pdbids pdb = new Pdbids();
+                jalview.datamodel.PDBEntry entry
+                   = (jalview.datamodel.PDBEntry)en.nextElement();
+
+                pdb.setId(entry.getId());
+                pdb.setType(entry.getType());
+
+                if(entry.getFile()!=null)
+                {
+                  if(pdbfiles==null)
+                    pdbfiles = new Vector();
+
+
+                  if(!pdbfiles.contains(entry.getId()))
+                  {
+                    pdbfiles.addElement(entry.getId());
+                    try
+                    {
+                      File file = new File(entry.getFile());
+                      if(file.exists())
+                      {
+                        byte[] data = new byte[ (int) file.length()];
+                        jout.putNextEntry(new JarEntry(entry.getId()));
+                        DataInputStream dis = new DataInputStream(new
+                            FileInputStream(file));
+                        dis.readFully(data);
+
+                        DataOutputStream dout = new DataOutputStream(jout);
+                        dout.write(data, 0, data.length);
+                        jout.closeEntry();
+                      }
+                    }
+                    catch (Exception ex)
+                    {
+                      ex.printStackTrace();
+                    }
+                  }
+                }
+
+
+                if(entry.getProperty()!=null)
+                {
+                  PdbentryItem item = new PdbentryItem();
+                  Hashtable properties = entry.getProperty();
+                  Enumeration en2 = properties.keys();
+                  while(en2.hasMoreElements())
+                  {
+                    Property prop = new Property();
+                    String key = en2.nextElement().toString();
+                    prop.setName(key);
+                    prop.setValue( properties.get(key).toString() );
+                    item.addProperty(prop);
+                  }
+                  pdb.addPdbentryItem(item);
+                }
+
+                jseq.addPdbids(pdb);
+              }
+            }
+
+            jms.addJSeq(jseq);
+            vamsasSet.addSequence(vamsasSeq);
+            id++;
+        }
+
+        //SAVE TREES
+        ///////////////////////////////////
+        if (af.viewport.currentTree != null)
+        {
+          // FIND ANY ASSOCIATED TREES
+          // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
+          if (Desktop.desktop != null)
+          {
+            JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+
+            for (int t = 0; t < frames.length; t++)
+            {
+              if (frames[t] instanceof TreePanel)
+              {
+                TreePanel tp = (TreePanel) frames[t];
+
+                if (tp.treeCanvas.av.alignment == jal)
+                {
+                  Tree tree = new Tree();
+                  tree.setTitle(tp.getTitle());
+                  tree.setCurrentTree( (af.viewport.currentTree == tp.getTree()));
+                  tree.setNewick(tp.getTree().toString());
+                  tree.setThreshold(tp.treeCanvas.threshold);
+
+                  tree.setFitToWindow(tp.fitToWindow.getState());
+                  tree.setFontName(tp.getTreeFont().getName());
+                  tree.setFontSize(tp.getTreeFont().getSize());
+                  tree.setFontStyle(tp.getTreeFont().getStyle());
+                  tree.setMarkUnlinked(tp.placeholdersMenu.getState());
+
+                  tree.setShowBootstrap(tp.bootstrapMenu.getState());
+                  tree.setShowDistances(tp.distanceMenu.getState());
+
+                  tree.setHeight(tp.getHeight());
+                  tree.setWidth(tp.getWidth());
+                  tree.setXpos(tp.getX());
+                  tree.setYpos(tp.getY());
+
+                  jms.addTree(tree);
+                }
+              }
+            }
+          }
+        }
+
+        //SAVE ANNOTATIONS
+        if (jal.getAlignmentAnnotation() != null)
+        {
+            jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();
+
+            for (int i = 0; i < aa.length; i++)
+            {
+                Annotation an = new Annotation();
+
+                if (aa[i].label.equals("Quality") ||
+                        aa[i].label.equals("Conservation") ||
+                        aa[i].label.equals("Consensus"))
+                {
+                    an.setLabel(aa[i].label);
+                    an.setGraph(true);
+                    vamsasSet.addAnnotation(an);
+                    continue;
+                }
+
+
+                an.setDescription(aa[i].description);
+
+                if(aa[i].sequenceRef!=null)
+                 {
+                   an.setSequenceRef(aa[i].sequenceRef.getName());
+                 }
+
+                if(aa[i].graph>0)
+                {
+                  an.setGraph(true);
+                  an.setGraphType(aa[i].graph);
+                  an.setGraphGroup(aa[i].graphGroup);
+                  if(aa[i].getThreshold()!=null)
+                  {
+                    ThresholdLine line = new ThresholdLine();
+                    line.setLabel(aa[i].getThreshold().label);
+                    line.setValue(aa[i].getThreshold().value);
+                    line.setColour(aa[i].getThreshold().colour.getRGB());
+                    an.setThresholdLine(line);
+                  }
+                }
+                else
+                  an.setGraph(false);
+
+                an.setLabel(aa[i].label);
+
+                AnnotationElement ae;
+
+                for (int a = 0; a < aa[i].annotations.length; a++)
+                {
+                    if ((aa[i] == null) || (aa[i].annotations[a] == null))
+                    {
+                        continue;
+                    }
+
+                    ae = new AnnotationElement();
+                    ae.setDescription(aa[i].annotations[a].description);
+                    ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);
+                    ae.setValue(aa[i].annotations[a].value);
+                    ae.setPosition(a);
+                    ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure +
+                        "");
+
+                    if(aa[i].annotations[a].colour!=java.awt.Color.black)
+                      ae.setColour(aa[i].annotations[a].colour.getRGB());
+
+                    an.addAnnotationElement(ae);
+                }
+
+                vamsasSet.addAnnotation(an);
+            }
+        }
+
+        //SAVE GROUPS
+        if (jal.getGroups() != null)
+        {
+            JGroup[] groups = new JGroup[jal.getGroups().size()];
+
+            for (int i = 0; i < groups.length; i++)
+            {
+                groups[i] = new JGroup();
+
+                jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal.getGroups()
+                                                                                          .elementAt(i);
+                groups[i].setStart(sg.getStartRes());
+                groups[i].setEnd(sg.getEndRes());
+                groups[i].setName(sg.getName());
+                if(sg.cs!=null)
+                {
+                  if (sg.cs.conservationApplied())
+                  {
+                    groups[i].setConsThreshold(sg.cs.getConservationInc());
+
+                    if (sg.cs instanceof jalview.schemes.UserColourScheme)
+                    {
+                      groups[i].setColour(SetUserColourScheme(sg.cs,
+                          userColours,
+                          jms));
+                    }
+                    else
+                    {
+                      groups[i].setColour(ColourSchemeProperty.getColourName(sg.
+                          cs));
+                    }
+                  }
+                  else if(sg.cs instanceof jalview.schemes.AnnotationColourGradient)
+                  {
+                    groups[i].setColour(
+                        ColourSchemeProperty.getColourName(
+                      ( (jalview.schemes.AnnotationColourGradient) sg.cs).getBaseColour()));
+                  }
+                  else if (sg.cs instanceof jalview.schemes.UserColourScheme)
+                  {
+                    groups[i].setColour(SetUserColourScheme(sg.cs, userColours,
+                        jms));
+                  }
+                  else
+                  {
+                    groups[i].setColour(ColourSchemeProperty.getColourName(
+                        sg.cs));
+                  }
+
+                  groups[i].setPidThreshold(sg.cs.getThreshold());
+                }
+
+                groups[i].setOutlineColour(sg.getOutlineColour().getRGB());
+                groups[i].setDisplayBoxes(sg.getDisplayBoxes());
+                groups[i].setDisplayText(sg.getDisplayText());
+                groups[i].setColourText(sg.getColourText());
+
+                for (int s = 0; s < sg.getSize(false); s++)
+                {
+                    jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg.getSequenceAt(s);
+                    int index = seqids.indexOf(seq);
+                    groups[i].addSeq(index);
+                }
+            }
+
+            jms.setJGroup(groups);
+        }
+
+
+        ///////////SAVE VIEWPORT
+        Viewport view = new Viewport();
+        view.setTitle(af.getTitle());
+        view.setXpos(af.getX());
+        view.setYpos(af.getY());
+        view.setWidth(af.getWidth());
+        view.setHeight(af.getHeight());
+        view.setStartRes(av.startRes);
+        view.setStartSeq(av.startSeq);
+
+        if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
+        {
+            view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),
+                    userColours, jms));
+        }
+        else if(av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
+        {
+           jalview.schemes.AnnotationColourGradient acg
+              = (jalview.schemes.AnnotationColourGradient)av.getGlobalColourScheme();
+
+            AnnotationColours ac = new AnnotationColours();
+            ac.setAboveThreshold(acg.getAboveThreshold());
+            ac.setThreshold(acg.getAnnotationThreshold());
+            ac.setAnnotation(acg.getAnnotation());
+            if(acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
+              ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),
+                    userColours, jms));
+            else
+              ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour()));
+
+            ac.setMaxColour(acg.getMaxColour().getRGB());
+            ac.setMinColour(acg.getMinColour().getRGB());
+            view.setAnnotationColours(ac);
+            view.setBgColour("AnnotationColourGradient");
+        }
+        else
+        {
+            view.setBgColour(ColourSchemeProperty.getColourName(
+                    av.getGlobalColourScheme()));
+        }
+
+        ColourSchemeI cs = av.getGlobalColourScheme();
+
+        if(cs!=null)
+        {
+          if (cs.conservationApplied())
+          {
+            view.setConsThreshold(cs.getConservationInc());
+            if (cs instanceof jalview.schemes.UserColourScheme)
+              view.setBgColour(SetUserColourScheme(cs, userColours, jms));
+          }
+
+          if (cs instanceof ResidueColourScheme)
+          {
+            view.setPidThreshold(cs.getThreshold());
+          }
+        }
+
+        view.setConservationSelected(av.getConservationSelected());
+        view.setPidSelected(av.getAbovePIDThreshold());
+        view.setFontName(av.font.getName());
+        view.setFontSize(av.font.getSize());
+        view.setFontStyle(av.font.getStyle());
+        view.setRenderGaps(av.renderGaps);
+        view.setShowAnnotation(av.getShowAnnotation());
+        view.setShowBoxes(av.getShowBoxes());
+        view.setShowColourText(av.getColourText());
+        view.setShowConservation(av.showConservation);
+        view.setShowFullId(av.getShowJVSuffix());
+        view.setShowIdentity(av.showIdentity);
+        view.setShowQuality(av.showQuality);
+        view.setShowSequenceFeatures(av.showSequenceFeatures);
+        view.setShowText(av.getShowText());
+        view.setWrapAlignment(av.getWrapAlignment());
+
+        if(av.featuresDisplayed!=null)
+        {
+          jalview.schemabinding.version2.FeatureSettings fs
+              = new jalview.schemabinding.version2.FeatureSettings();
+
+          String [] renderOrder =
+              af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;
+
+          Vector settingsAdded = new Vector();
+          for(int ro=0; ro<renderOrder.length; ro++)
+          {
+            Setting setting = new Setting();
+            setting.setType(renderOrder[ro]);
+            setting.setColour(
+                af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().getColour(renderOrder[ro]).getRGB()
+                );
+
+            setting.setDisplay(
+                av.featuresDisplayed.containsKey(renderOrder[ro])
+                );
+
+            fs.addSetting(setting);
+            settingsAdded.addElement(renderOrder[ro]);
+          }
+
+          //Make sure we save none displayed feature settings
+          Enumeration en =
+              af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours.keys();
+          while(en.hasMoreElements())
+          {
+            String key = en.nextElement().toString();
+            if(settingsAdded.contains(key))
+              continue;
+
+            Setting setting = new Setting();
+            setting.setType(key);
+            setting.setColour(
+                af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().getColour(key).getRGB()
+                );
+
+            setting.setDisplay(false);
+
+            fs.addSetting(setting);
+            settingsAdded.addElement(key);
+          }
+
+          jms.setFeatureSettings(fs);
+
+        }
+
+        if(av.hasHiddenColumns)
+        {
+          for(int c=0; c<av.getColumnSelection().getHiddenColumns().size(); c++)
+          {
+            int [] region = (int[]) av.getColumnSelection().getHiddenColumns().elementAt(c);
+            HiddenColumns hc = new HiddenColumns();
+            hc.setStart(region[0]);
+            hc.setEnd(region[1]);
+            view.addHiddenColumns(hc);
+          }
+        }
+
+        jms.addViewport(view);
+
+
+        object.setJalviewModelSequence(jms);
+        object.getVamsasModel().addSequenceSet(vamsasSet);
+
+        try
+        {
+            if (!fileName.endsWith(".xml"))
+            {
+                fileName = fileName + ".xml";
+            }
+
+            JarEntry entry = new JarEntry(fileName);
+            jout.putNextEntry(entry);
+
+            object.marshal(out);
+        }
+        catch (Exception ex)
+        {
+            ex.printStackTrace();
+        }
+    }
+
+    String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,
+        Vector userColours, JalviewModelSequence jms)
+    {
+        String id = null;
+        jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;
+
+        if (!userColours.contains(ucs))
+        {
+            userColours.add(ucs);
+
+            java.awt.Color[] colours = ucs.getColours();
+            jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours();
+            jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme();
+
+            for (int i = 0; i < colours.length; i++)
+            {
+                jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
+                col.setRGB(jalview.util.Format.getHexString(colours[i]));
+                jbucs.addColour(col);
+            }
+
+            id = "ucs" + userColours.indexOf(ucs);
+            uc.setId(id);
+            uc.setUserColourScheme(jbucs);
+            jms.addUserColours(uc);
+        }
+
+        return id;
+    }
+
+   jalview.schemes.UserColourScheme GetUserColourScheme(
+        JalviewModelSequence jms, String id)
+    {
+        UserColours[] uc = jms.getUserColours();
+        UserColours colours = null;
+
+        for (int i = 0; i < uc.length; i++)
+        {
+            if (uc[i].getId().equals(id))
+            {
+                colours = uc[i];
+
+                break;
+            }
+        }
+
+        int csize = colours.getUserColourScheme().getColourCount();
+        java.awt.Color[] newColours = new java.awt.Color[csize];
+
+        for (int i = 0; i < csize; i++)
+        {
+            newColours[i] = new java.awt.Color(Integer.parseInt(
+                        colours.getUserColourScheme().getColour(i).getRGB(), 16));
+        }
+
+        return new jalview.schemes.UserColourScheme(newColours);
+    }
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @param file DOCUMENT ME!
+     */
+    public AlignFrame LoadJalviewAlign(final String file)
+    {
+        jalview.gui.AlignFrame af = null;
+        try
+        {
+            //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
+            URL url = null;
+
+            if (file.startsWith("http://"))
+            {
+                url = new URL(file);
+            }
+
+            JarInputStream jin = null;
+            JarEntry jarentry = null;
+            int entryCount = 1;
+
+            do
+            {
+                if (url != null)
+                {
+                    jin = new JarInputStream(url.openStream());
+                }
+                else
+                {
+                    jin = new JarInputStream(new FileInputStream(file));
+                }
+
+                for (int i = 0; i < entryCount; i++)
+                {
+                    jarentry = jin.getNextJarEntry();
+                }
+
+                if (jarentry != null && jarentry.getName().endsWith(".xml"))
+                {
+                    InputStreamReader in = new InputStreamReader(jin, "UTF-8");
+                    JalviewModel object = new JalviewModel();
+
+                    Unmarshaller unmar = new Unmarshaller(object);
+                    unmar.setValidation(false);
+                    object = (JalviewModel) unmar.unmarshal( in );
+
+                    af = LoadFromObject(object, file);
+                    entryCount++;
+                }
+                else if (jarentry != null)
+                {
+                  //Some other file here.
+                  entryCount++;
+                }
+            }
+            while (jarentry != null);
+        }
+        catch(java.net.UnknownHostException ex)
+        {
+          ex.printStackTrace();
+          System.err.println("Couldn't locate Jalview XML file : " +
+              ex + "\n");
+
+          javax.swing.SwingUtilities.invokeLater(new Runnable()
+          {
+            public void run()
+            {
+              JOptionPane.showInternalMessageDialog(Desktop.desktop,
+                  "Couldn't locate " + file,
+                  "URL not found",
+                  JOptionPane.WARNING_MESSAGE);
+            }
+          });
+        }
+        catch (Exception ex)
+        {
+
+          //Is Version 1 Jar file?
+          af =  new Jalview2XML_V1().LoadJalviewAlign(file);
+
+          if(af!=null)
+          {
+            System.out.println("Successfully loaded archive file");
+            return af;
+          }
+          ex.printStackTrace();
+            System.err.println("Exception whilst loading jalview XML file : " +
+                ex + "\n");
+            javax.swing.SwingUtilities.invokeLater(new Runnable()
+            {
+              public void run()
+              {
+
+                JOptionPane.showInternalMessageDialog(Desktop.desktop,
+                    "Error loading  " + file,
+                    "Error loading Jalview file",
+                    JOptionPane.WARNING_MESSAGE);
+              }});
+        }
+
+        return af;
+    }
+
+    String loadPDBFile(String file, String pdbId)
+    {
+      System.out.println("load file "+file);
+      try
+      {
+        JarInputStream jin = null;
+
+        if (file.startsWith("http://"))
+        {
+          jin = new JarInputStream(new URL(file).openStream());
+        }
+        else
+        {
+          jin = new JarInputStream(new FileInputStream(file));
+        }
+
+        JarEntry entry = null;
+        do
+        {
+          entry = jin.getNextJarEntry();
+        }
+        while (!entry.getName().equals(pdbId));
+
+        BufferedReader in = new BufferedReader(new InputStreamReader(jin));
+        File outFile = File.createTempFile("jalview_pdb", ".txt");
+        outFile.deleteOnExit();
+        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
+        String data;
+
+        while ( (data = in.readLine()) != null)
+        {
+          out.println(data);
+        }
+        out.close();
+        return outFile.getAbsolutePath();
+
+      }
+      catch (Exception ex)
+      {
+        ex.printStackTrace();
+      }
+
+      return null;
+    }
+
+
+    AlignFrame LoadFromObject(JalviewModel object, String file)
+    {
+        Vector seqids = new Vector();
+        SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
+        Sequence[] vamsasSeq = vamsasSet.getSequence();
+
+        JalviewModelSequence jms = object.getJalviewModelSequence();
+
+        //////////////////////////////////
+        //LOAD SEQUENCES
+        Vector hiddenSeqs = null;
+        jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];
+        JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
+        for (int i = 0; i < vamsasSeq.length; i++)
+        {
+            jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
+                    vamsasSeq[i].getSequence());
+            jseqs[i].setDescription( vamsasSeq[i].getDescription() );
+
+            if(JSEQ[i].getHidden())
+            {
+              if(hiddenSeqs == null)
+                hiddenSeqs = new Vector();
+              hiddenSeqs.addElement(jseqs[i]);
+            }
+            jseqs[i].setStart(JSEQ[i].getStart());
+            jseqs[i].setEnd(JSEQ[i].getEnd());
+            jseqs[i].setColor(new java.awt.Color(JSEQ[i].getColour()));
+            seqids.add(jseqs[i]);
+        }
+
+        ///SequenceFeatures are added to the DatasetSequence,
+        // so we must create the dataset before loading features
+        /////////////////////////////////
+        jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
+        al.setDataset(null);
+        /////////////////////////////////
+
+
+        Hashtable pdbloaded = new Hashtable();
+        for (int i = 0; i < vamsasSeq.length; i++)
+        {
+          if (JSEQ[i].getFeaturesCount() > 0)
+          {
+            Features[] features = JSEQ[i].getFeatures();
+            for (int f = 0; f < features.length; f++)
+            {
+              jalview.datamodel.SequenceFeature sf
+                  = new jalview.datamodel.SequenceFeature(features[f].getType(),
+                  features[f].getDescription(), features[f].getStatus(),
+                  features[f].getBegin(), features[f].getEnd(),
+                  features[f].getFeatureGroup());
+
+              sf.setScore(features[f].getScore());
+              for(int od=0; od<features[f].getOtherDataCount(); od++)
+              {
+                OtherData keyValue = features[f].getOtherData(od);
+                if(keyValue.getKey().startsWith("LINK"))
+                  sf.addLink(keyValue.getValue());
+                else
+                  sf.setValue(keyValue.getKey(), keyValue.getValue());
+
+              }
+
+              al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
+            }
+          }
+          if (JSEQ[i].getPdbidsCount() > 0)
+          {
+            Pdbids[] ids = JSEQ[i].getPdbids();
+            for (int p = 0; p < ids.length; p++)
+            {
+              jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
+              entry.setId(ids[p].getId());
+              entry.setType(ids[p].getType());
+              if (ids[p].getFile() != null)
+              {
+                if (!pdbloaded.containsKey(ids[p].getFile()))
+                {
+                  String tmppdb = loadPDBFile(file, ids[p].getId());
+                  entry.setFile(tmppdb);
+                  pdbloaded.put(ids[p].getId(), tmppdb);
+                }
+                else
+                  entry.setFile(pdbloaded.get(ids[p].getId()).toString());
+              }
+
+              al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
+            }
+          }
+          if(vamsasSeq[i].getDBRefCount()>0)
+          {
+            for(int d=0; d<vamsasSeq[i].getDBRefCount(); d++)
+            {
+              jalview.datamodel.DBRefEntry entry =
+                  new jalview.datamodel.DBRefEntry(
+                      vamsasSeq[i].getDBRef(d).getSource(),
+                      vamsasSeq[i].getDBRef(d).getVersion(),
+                      vamsasSeq[i].getDBRef(d).getAccessionId()
+                      );
+              al.getSequenceAt(i).getDatasetSequence().addDBRef(entry);
+            }
+
+          }
+        }
+
+
+
+         /////////////////////////////////
+        //////////////////////////////////
+        //LOAD ANNOTATIONS
+        boolean hideQuality = true,
+            hideConservation = true,
+            hideConsensus = true;
+
+        if (vamsasSet.getAnnotation() != null)
+        {
+            Annotation[] an = vamsasSet.getAnnotation();
+
+            for (int i = 0; i < an.length; i++)
+            {
+               if (an[i].getLabel().equals("Quality"))
+                {
+                 hideQuality = false;
+                 continue;
+                }
+               else if(an[i].getLabel().equals("Conservation"))
+               {
+                 hideConservation = false;
+                 continue;
+               }
+               else if(an[i].getLabel().equals("Consensus"))
+               {
+                 hideConsensus = false;
+                 continue;
+               }
+
+                AnnotationElement[] ae = an[i].getAnnotationElement();
+                jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];
+
+                for (int aa = 0; aa < ae.length; aa++)
+                {
+                    anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),
+                            ae[aa].getDescription(),
+                            ae[aa].getSecondaryStructure().length()==0?' ':ae[aa].getSecondaryStructure().charAt(0),
+                            ae[aa].getValue());
+                    anot[ae[aa].getPosition()].colour = new java.awt.Color( ae[aa].getColour() );
+                }
+
+                jalview.datamodel.AlignmentAnnotation jaa = null;
+
+                if (an[i].getGraph())
+                {
+                  jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
+                      an[i].getDescription(), anot, 0, 0,
+                      an[i].getGraphType());
+
+                  jaa.graphGroup = an[i].getGraphGroup();
+
+                  if (an[i].getThresholdLine() != null)
+                  {
+                    jaa.setThreshold(new jalview.datamodel.GraphLine(
+                                  an[i].getThresholdLine().getValue(),
+                                  an[i].getThresholdLine().getLabel(),
+                                new java.awt.Color(an[i].getThresholdLine().getColour()))
+                             );
+
+                  }
+
+                }
+                else
+                {
+                    jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
+                            an[i].getDescription(), anot);
+                }
+
+                if(an[i].getSequenceRef()!=null)
+                {
+                  jaa.createSequenceMapping(
+                      al.findName(an[i].getSequenceRef()), 1
+                      );
+                  al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);
+                }
+
+                al.addAnnotation(jaa);
+            }
+        }
+
+
+        //  af.changeColour() );
+        /////////////////////////
+        //LOAD GROUPS
+        if (jms.getJGroupCount() > 0)
+        {
+            JGroup[] groups = jms.getJGroup();
+
+            for (int i = 0; i < groups.length; i++)
+            {
+                ColourSchemeI cs = null;
+
+                if (groups[i].getColour() != null)
+                {
+                    if (groups[i].getColour().startsWith("ucs"))
+                    {
+                        cs = GetUserColourScheme(jms, groups[i].getColour());
+                    }
+                    else
+                    {
+                        cs = ColourSchemeProperty.getColour(al,
+                                groups[i].getColour());
+                    }
+
+                    if(cs!=null)
+                      cs.setThreshold(groups[i].getPidThreshold(), true);
+                }
+
+                Vector seqs = new Vector();
+                int[] ids = groups[i].getSeq();
+
+                for (int s = 0; s < ids.length; s++)
+                {
+                    seqs.addElement((jalview.datamodel.SequenceI) seqids.elementAt(
+                            ids[s]));
+                }
+
+                jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,
+                        groups[i].getName(), cs, groups[i].getDisplayBoxes(),
+                        groups[i].getDisplayText(), groups[i].getColourText(),
+                        groups[i].getStart(), groups[i].getEnd());
+
+                sg.setOutlineColour(new java.awt.Color(
+                        groups[i].getOutlineColour()));
+
+                if (groups[i].getConsThreshold() != 0)
+                {
+                    jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",
+                            ResidueProperties.propHash, 3, sg.getSequences(false), 0,
+                            sg.getWidth() - 1);
+                    c.calculate();
+                    c.verdict(false, 25);
+                    sg.cs.setConservation(c);
+                }
+
+                al.addGroup(sg);
+            }
+        }
+
+
+        /////////////////////////////////
+        // LOAD VIEWPORT
+        Viewport[] views = jms.getViewport();
+        Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
+
+
+        AlignFrame af = new AlignFrame(al);
+
+        if(hiddenSeqs!=null)
+        {
+          for(int s=0; s<JSEQ.length; s++)
+          {
+            for(int r=0; r<JSEQ[s].getHiddenSequencesCount(); r++)
+            {
+              al.getSequenceAt(s).addHiddenSequence(
+                  al.getSequenceAt( JSEQ[s].getHiddenSequences(r)  )
+                  );
+            }
+          }
+
+          for(int s=0; s<hiddenSeqs.size(); s++)
+          {
+              af.viewport.hideSequence(
+                (jalview.datamodel.SequenceI)hiddenSeqs.elementAt(s));
+          }
+        }
+
+
+        if(hideConsensus || hideQuality || hideConservation)
+        {
+          int hSize = al.getAlignmentAnnotation().length;
+          for (int h = 0; h < hSize; h++)
+          {
+            if (
+                (hideConsensus &&
+                 al.getAlignmentAnnotation()[h].label.equals("Consensus"))
+                ||
+                (hideQuality &&
+                 al.getAlignmentAnnotation()[h].label.equals("Quality"))
+                ||
+                (hideConservation &&
+                 al.getAlignmentAnnotation()[h].label.equals("Conservation")))
+            {
+              al.deleteAnnotation(al.getAlignmentAnnotation()[h]);
+              hSize--;
+              h--;
+            }
+          }
+          af.alignPanel.adjustAnnotationHeight();
+        }
+
+        af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
+            view.getHeight());
+        af.viewport.setStartRes(view.getStartRes());
+        af.viewport.setStartSeq(view.getStartSeq());
+        af.viewport.setShowAnnotation(view.getShowAnnotation());
+        af.viewport.showConservation = view.getShowConservation();
+        af.viewport.showQuality = view.getShowQuality();
+        af.viewport.showIdentity = view.getShowIdentity();
+        af.viewport.setAbovePIDThreshold(view.getPidSelected());
+        af.abovePIDThreshold.setSelected(view.getPidSelected());
+        af.viewport.setColourText(view.getShowColourText());
+        af.colourTextMenuItem.setSelected(view.getShowColourText());
+        af.viewport.setConservationSelected(view.getConservationSelected());
+        af.conservationMenuItem.setSelected(view.getConservationSelected());
+
+        af.viewport.setShowJVSuffix(view.getShowFullId());
+        af.seqLimits.setSelected(view.getShowFullId());
+
+        af.viewport.setFont(new java.awt.Font(view.getFontName(),
+                view.getFontStyle(), view.getFontSize()));
+        af.alignPanel.fontChanged();
+
+        af.viewport.setRenderGaps(view.getRenderGaps());
+        af.renderGapsMenuItem.setSelected(view.getRenderGaps());
+
+        af.viewport.setWrapAlignment(view.getWrapAlignment());
+        af.wrapMenuItem.setSelected(view.getWrapAlignment());
+
+        af.alignPanel.setWrapAlignment(view.getWrapAlignment());
+
+        af.annotationPanelMenuItem.setState(view.getShowAnnotation());
+        af.viewport.setShowAnnotation(view.getShowAnnotation());
+        af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
+
+        af.viewport.setShowBoxes(view.getShowBoxes());
+        af.viewBoxesMenuItem.setSelected(view.getShowBoxes());
+        af.viewport.setShowText(view.getShowText());
+        af.viewTextMenuItem.setSelected(view.getShowText());
+
+        ColourSchemeI cs = null;
+
+        if (view.getBgColour() != null)
+        {
+            if (view.getBgColour().startsWith("ucs"))
+            {
+                cs = GetUserColourScheme(jms, view.getBgColour());
+            }
+            else if(view.getBgColour().startsWith("Annotation"))
+            {
+              //int find annotation
+              for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++)
+              {
+                if (af.viewport.alignment.getAlignmentAnnotation()[i].label.
+                    equals(view.getAnnotationColours().getAnnotation()))
+                {
+                  if (af.viewport.alignment.getAlignmentAnnotation()[i].
+                      getThreshold() == null)
+                  {
+                    af.viewport.alignment.getAlignmentAnnotation()[i].
+                        setThreshold(
+                            new jalview.datamodel.GraphLine(
+                                view.getAnnotationColours().getThreshold(),
+                                "Threshold", java.awt.Color.black)
+
+                        );
+                  }
+
+
+                  if (view.getAnnotationColours().getColourScheme().equals(
+                      "None"))
+                  {
+                    cs = new AnnotationColourGradient(
+                        af.viewport.alignment.getAlignmentAnnotation()[i],
+                        new java.awt.Color(view.getAnnotationColours().
+                                           getMinColour()),
+                        new java.awt.Color(view.getAnnotationColours().
+                                           getMaxColour()),
+                        view.getAnnotationColours().getAboveThreshold());
+                  }
+                  else if (view.getAnnotationColours().getColourScheme().
+                           startsWith("ucs"))
+                  {
+                     cs = new AnnotationColourGradient(
+                         af.viewport.alignment.getAlignmentAnnotation()[i],
+                         GetUserColourScheme(jms, view.getAnnotationColours().
+                                                        getColourScheme()),
+                         view.getAnnotationColours().getAboveThreshold()
+                         );
+                   }
+                   else
+                   {
+                     cs = new AnnotationColourGradient(
+                         af.viewport.alignment.getAlignmentAnnotation()[i],
+                         ColourSchemeProperty.getColour(al,
+                         view.getAnnotationColours().getColourScheme()),
+                         view.getAnnotationColours().getAboveThreshold()
+                         );
+                   }
+
+                  // Also use these settings for all the groups
+                  if (al.getGroups() != null)
+                    for (int g = 0; g < al.getGroups().size(); g++)
+                    {
+                      jalview.datamodel.SequenceGroup sg
+                          = (jalview.datamodel.SequenceGroup)al.getGroups().elementAt(g);
+
+                      if(sg.cs == null)
+                        continue;
+
+
+                  /*    if (view.getAnnotationColours().getColourScheme().equals("None"))
+                      {
+                        sg.cs = new AnnotationColourGradient(
+                            af.viewport.alignment.getAlignmentAnnotation()[i],
+                            new java.awt.Color(view.getAnnotationColours().
+                                               getMinColour()),
+                            new java.awt.Color(view.getAnnotationColours().
+                                               getMaxColour()),
+                            view.getAnnotationColours().getAboveThreshold());
+                      }
+                      else*/
+                      {
+                        sg.cs = new AnnotationColourGradient(
+                            af.viewport.alignment.getAlignmentAnnotation()[i],
+                            sg.cs,
+                            view.getAnnotationColours().getAboveThreshold()
+                            );
+                      }
+
+                    }
+
+
+                  break;
+                }
+
+              }
+            }
+            else
+            {
+                cs = ColourSchemeProperty.getColour(al, view.getBgColour());
+            }
+
+            if(cs!=null)
+            {
+              cs.setThreshold(view.getPidThreshold(), true);
+              cs.setConsensus(af.viewport.vconsensus);
+            }
+        }
+
+        af.setColourSelected(view.getBgColour());
+        af.viewport.setGlobalColourScheme(cs);
+        af.viewport.setColourAppliesToAllGroups(false);
+        af.changeColour(cs);
+        if (view.getConservationSelected() && cs!=null)
+        {
+          cs.setConservationInc(view.getConsThreshold());
+        }
+
+        af.viewport.setColourAppliesToAllGroups(true);
+
+        if (view.getShowSequenceFeatures())
+        {
+           af.viewport.showSequenceFeatures = true;
+           af.showSeqFeatures.setSelected(true);
+        }
+
+        if(jms.getFeatureSettings()!=null)
+        {
+          af.viewport.featuresDisplayed = new Hashtable();
+          String [] renderOrder = new String[jms.getFeatureSettings().getSettingCount()];
+         for(int fs=0; fs<jms.getFeatureSettings().getSettingCount(); fs++)
+         {
+           Setting setting = jms.getFeatureSettings().getSetting(fs);
+
+           af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(setting.getType(),
+               new java.awt.Color(setting.getColour()));
+
+           renderOrder[fs] = setting.getType();
+
+           if(setting.getDisplay())
+             af.viewport.featuresDisplayed.put(
+                 setting.getType(), new Integer(setting.getColour()));
+         }
+         af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
+        }
+
+        if (view.getHiddenColumnsCount() > 0)
+        {
+          for (int c = 0; c < view.getHiddenColumnsCount(); c++)
+          {
+              af.viewport.hideColumns(
+                view.getHiddenColumns(c).getStart(),
+                view.getHiddenColumns(c).getEnd() //+1
+                );
+          }
+        }
+
+
+        Desktop.addInternalFrame(af, view.getTitle(),
+             view.getWidth(), view.getHeight());
+
+        //LOAD TREES
+        ///////////////////////////////////////
+        if (jms.getTreeCount() > 0)
+        {
+            try
+            {
+                for (int t = 0; t < jms.getTreeCount(); t++)
+                {
+
+                    Tree tree = jms.getTree(t);
+
+                    TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(
+                                tree.getNewick()), tree.getTitle(),
+                                tree.getWidth(), tree.getHeight(),
+                                tree.getXpos(), tree.getYpos());
+
+                    tp.fitToWindow.setState(tree.getFitToWindow());
+                    tp.fitToWindow_actionPerformed(null);
+
+                    if(tree.getFontName()!=null)
+                      tp.setTreeFont(new java.awt.Font(tree.getFontName(),
+                                          tree.getFontStyle(),
+                                          tree.getFontSize()));
+                    else
+                      tp.setTreeFont(new java.awt.Font(view.getFontName(),
+                                            view.getFontStyle(),
+                                            tree.getFontSize()));
+
+                    tp.showPlaceholders(tree.getMarkUnlinked());
+                    tp.showBootstrap(tree.getShowBootstrap());
+                    tp.showDistances(tree.getShowDistances());
+
+                    tp.treeCanvas.threshold = tree.getThreshold();
+
+                    if (tree.getCurrentTree())
+                      af.viewport.setCurrentTree(tp.getTree());
+                }
+
+            }
+            catch (Exception ex)
+            {
+                ex.printStackTrace();
+            }
+
+        }
+
+        return af;
+    }
+}
+