X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=945651b9dcefd8ec123d90d1a3acb23a1293bb57;hb=8dfdafee89d06dd397c392619b4b285f0dc35430;hp=d2d55f8c7c182a05893ded920e784ff11ee0aca4;hpb=bb19b02db6a50024556a86d7c4eba1053cf9fb57;p=jalview.git
diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java
old mode 100755
new mode 100644
index d2d55f8..945651b
--- a/src/jalview/gui/Jalview2XML.java
+++ b/src/jalview/gui/Jalview2XML.java
@@ -1,824 +1,5344 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 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.io.*;
-
-import jalview.schemes.*;
-
-import java.io.*;
-
-import java.net.*;
-
-import java.util.*;
-import java.util.jar.*;
-
-import javax.swing.*;
-
-import jalview.binding.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class Jalview2XML
-{
- // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE
- public static 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 static 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 static 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 VamsasModel());
-
- object.setCreationDate(new java.util.Date(timeStamp));
- object.setVersion(jalview.bin.Cache.getProperty("VERSION"));
-
- jalview.datamodel.AlignmentI jal = af.viewport.alignment;
-
- SequenceSet vamsasSet = new SequenceSet();
- Sequence vamsasSeq;
- JalviewModelSequence jms = new JalviewModelSequence();
-
- vamsasSet.setGapChar(jal.getGapCharacter() + "");
-
- JSeq jseq;
-
- //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());
-
- 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);
-
- 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++)
- {
- if (aa[i].label.equals("Quality") ||
- aa[i].label.equals("Conservation") ||
- aa[i].label.equals("Consensus"))
- {
- continue;
- }
-
- Annotation an = new Annotation();
- an.setDescription(aa[i].description);
- an.setGraph(aa[i].isGraph);
- 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 +
- "");
- 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.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(); 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
- {
- 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.getShowFullId());
- view.setShowIdentity(av.showIdentity);
- view.setShowQuality(av.showQuality);
- view.setShowSequenceFeatures(av.showSequenceFeatures);
- view.setShowText(av.getShowText());
- view.setWrapAlignment(av.getWrapAlignment());
-
- 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();
- }
- }
-
- static 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.binding.UserColours uc = new jalview.binding.UserColours();
- jalview.binding.UserColourScheme jbucs = new jalview.binding.UserColourScheme();
-
- for (int i = 0; i < colours.length; i++)
- {
- jalview.binding.Colour col = new jalview.binding.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;
- }
-
- static 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 static AlignFrame LoadJalviewAlign(String file)
- {
- JalviewModel object = new JalviewModel();
- 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)
- {
- InputStreamReader in = new InputStreamReader(jin, "UTF-8");
- object = (JalviewModel) object.unmarshal(in);
- af = LoadFromObject(object);
- entryCount++;
- }
- }
- while (jarentry != null);
- }
- catch(java.net.UnknownHostException ex)
- {
- ex.printStackTrace();
- System.err.println("Couldn't locate Jalview XML file : " +
- ex + "\n");
- JOptionPane.showInternalMessageDialog(Desktop.desktop,
- "Couldn't locate " + file,
- "URL not found",
- JOptionPane.WARNING_MESSAGE);
-
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- System.err.println("Exception whilst loading jalview XML file : " +
- ex + "\n");
- JOptionPane.showInternalMessageDialog(Desktop.desktop,
- "Error loading " + file,
- "Error loading Jalview file",
- JOptionPane.WARNING_MESSAGE);
-
- }
-
- return af;
- }
-
- static AlignFrame LoadFromObject(JalviewModel object)
- {
- Vector seqids = new Vector();
- SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
- Sequence[] vamsasSeq = vamsasSet.getSequence();
-
- JalviewModelSequence jms = object.getJalviewModelSequence();
-
- //////////////////////////////////
- //LOAD SEQUENCES
- 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].setStart(JSEQ[i].getStart());
- jseqs[i].setEnd(JSEQ[i].getEnd());
- jseqs[i].setColor(new java.awt.Color(JSEQ[i].getColour()));
- seqids.add(jseqs[i]);
- }
-
- /////////////////////////////////
- jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
-
- /////////////////////////////////
- //////////////////////////////////
- //LOAD ANNOTATIONS
- if (vamsasSet.getAnnotation() != null)
- {
- Annotation[] an = vamsasSet.getAnnotation();
-
- for (int i = 0; i < an.length; i++)
- {
- 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().charAt(0),
- ae[aa].getValue());
- }
-
- jalview.datamodel.AlignmentAnnotation jaa = null;
-
- if (an[i].getGraph())
- {
- jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
- an[i].getDescription(), anot, 0, 0, 1);
- }
- else
- {
- jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
- an[i].getDescription(), anot);
- }
-
- al.addAnnotation(jaa);
- }
- }
-
- /////////////////////////////////
- // LOAD VIEWPORT
- Viewport[] views = jms.getViewport();
- Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
-
- AlignFrame af = new AlignFrame(al);
-
- // 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());
- }
-
- 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.sequences, 0,
- sg.getWidth() - 1);
- c.calculate();
- c.verdict(false, 25);
- sg.cs.setConservation(c);
- }
-
- al.addGroup(sg);
- }
- }
-
-
- af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
- view.getHeight());
- af.viewport.setStartRes(view.getStartRes());
- af.viewport.setStartSeq(view.getStartSeq());
- 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.setShowFullId(view.getShowFullId());
- af.fullSeqId.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());
-
- if (view.getWrapAlignment())
- {
- af.alignPanel.setWrapAlignment(view.getWrapAlignment());
- }
- else
- {
- 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
- {
- 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.sequenceFeatures.setSelected(true);
- new SequenceFeatureFetcher(al, af.alignPanel);
- al.featuresAdded = true;
- }
-
- 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.placeholdersMenu.setState(tree.getMarkUnlinked());
- tp.treeCanvas.setMarkPlaceholders(tree.getMarkUnlinked());
- tp.bootstrapMenu.setState(tree.getShowBootstrap());
- tp.treeCanvas.setShowBootstrap(tree.getShowBootstrap());
- tp.distanceMenu.setState(tree.getShowDistances());
- tp.treeCanvas.setShowDistances(tree.getShowDistances());
- tp.treeCanvas.threshold = tree.getThreshold();
-
- if (tree.getCurrentTree())
- af.viewport.setCurrentTree(tp.getTree());
- }
-
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
-
- }
-
- return af;
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.gui;
+
+import jalview.api.FeatureColourI;
+import jalview.api.ViewStyleI;
+import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.bin.Cache;
+import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.RnaViewerModel;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.datamodel.StructureViewerModel;
+import jalview.datamodel.StructureViewerModel.StructureData;
+import jalview.ext.varna.RnaModel;
+import jalview.gui.StructureViewer.ViewerType;
+import jalview.schemabinding.version2.AlcodMap;
+import jalview.schemabinding.version2.AlcodonFrame;
+import jalview.schemabinding.version2.Annotation;
+import jalview.schemabinding.version2.AnnotationColours;
+import jalview.schemabinding.version2.AnnotationElement;
+import jalview.schemabinding.version2.CalcIdParam;
+import jalview.schemabinding.version2.DBRef;
+import jalview.schemabinding.version2.Features;
+import jalview.schemabinding.version2.Group;
+import jalview.schemabinding.version2.HiddenColumns;
+import jalview.schemabinding.version2.JGroup;
+import jalview.schemabinding.version2.JSeq;
+import jalview.schemabinding.version2.JalviewModel;
+import jalview.schemabinding.version2.JalviewModelSequence;
+import jalview.schemabinding.version2.MapListFrom;
+import jalview.schemabinding.version2.MapListTo;
+import jalview.schemabinding.version2.Mapping;
+import jalview.schemabinding.version2.MappingChoice;
+import jalview.schemabinding.version2.OtherData;
+import jalview.schemabinding.version2.PdbentryItem;
+import jalview.schemabinding.version2.Pdbids;
+import jalview.schemabinding.version2.Property;
+import jalview.schemabinding.version2.RnaViewer;
+import jalview.schemabinding.version2.SecondaryStructure;
+import jalview.schemabinding.version2.Sequence;
+import jalview.schemabinding.version2.SequenceSet;
+import jalview.schemabinding.version2.SequenceSetProperties;
+import jalview.schemabinding.version2.Setting;
+import jalview.schemabinding.version2.StructureState;
+import jalview.schemabinding.version2.ThresholdLine;
+import jalview.schemabinding.version2.Tree;
+import jalview.schemabinding.version2.UserColours;
+import jalview.schemabinding.version2.Viewport;
+import jalview.schemes.AnnotationColourGradient;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.FeatureColour;
+import jalview.schemes.ResidueColourScheme;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.UserColourScheme;
+import jalview.structure.StructureSelectionManager;
+import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.util.StringUtils;
+import jalview.util.jarInputStreamProvider;
+import jalview.viewmodel.AlignmentViewport;
+import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
+import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
+import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.jws2.dm.AAConSettings;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.AutoCalcSetting;
+import jalview.ws.params.WsParamSetI;
+
+import java.awt.Color;
+import java.awt.Rectangle;
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.Vector;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
+import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.Unmarshaller;
+
+/**
+ * Write out the current jalview desktop state as a Jalview XML stream.
+ *
+ * Note: the vamsas objects referred to here are primitive versions of the
+ * VAMSAS project schema elements - they are not the same and most likely never
+ * will be :)
+ *
+ * @author $author$
+ * @version $Revision: 1.134 $
+ */
+public class Jalview2XML
+{
+ private static final String VIEWER_PREFIX = "viewer_";
+
+ private static final String RNA_PREFIX = "rna_";
+
+ private static final String UTF_8 = "UTF-8";
+
+ // use this with nextCounter() to make unique names for entities
+ private int counter = 0;
+
+ /*
+ * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
+ * of sequence objects are created.
+ */
+ IdentityHashMap seqsToIds = null;
+
+ /**
+ * jalview XML Sequence ID to jalview sequence object reference (both dataset
+ * and alignment sequences. Populated as XML reps of sequence objects are
+ * created.)
+ */
+ Map seqRefIds = null;
+
+ Vector