X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=addba63ec5ebb6c0eb5c8c9d2e6ad505af235bbe;hb=0a5c25233b642021bec70224aff9d405b70a3f72;hp=12f2cb20640daf23751f617cd02c13317b8e049d;hpb=b12384aa7fdffd3167a83de75d2a560356ee65f1;p=jalview.git diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 12f2cb2..addba63 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1,92 +1,143 @@ +/* + * 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 java.io.*; +import java.net.*; import java.util.*; import java.util.jar.*; +import javax.swing.*; + import jalview.binding.*; +import jalview.io.*; import jalview.schemes.*; -import javax.swing.JInternalFrame; - 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(); - 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(); - for (int i = 0; i < frames.length; i++) + 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) { - if (frames[i] instanceof AlignFrame) - { - AlignFrame af = (AlignFrame) frames[i]; + AlignFrame af = (AlignFrame) frames[i]; - String shortName = af.getTitle(); + String shortName = af.getTitle(); - shortName = shortName.replace('/', '_'); - shortName = shortName.replace('\\', '_'); + 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("_")); + int count = 1; - shortName = shortName.concat("_"+count); - count++; + while (shortNames.contains(shortName)) + { + if (shortName.endsWith("_" + (count - 1))) + { + shortName = shortName.substring(0, + shortName.lastIndexOf("_")); } - shortNames.addElement(shortName); - if(!shortName.endsWith(".xml")) - shortName = shortName+".xml"; + shortName = shortName.concat("_" + count); + count++; + } - SaveState( af, creation, shortName, jout, out); - } + 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();} + + out.close(); + jout.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } } // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW - public static void SaveState( AlignFrame af, String jarFile, String fileName) + public static void SaveState(AlignFrame af, String jarFile, String fileName) { - try{ + 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")); + PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, + "UTF-8")); SaveState(af, System.currentTimeMillis(), fileName, jout, out); out.close(); jout.close(); - }catch(Exception ex){} + } + catch (Exception ex) + { + } } - public static void SaveState( AlignFrame af, long timeStamp, - String fileName, JarOutputStream jout, PrintWriter out) + 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.setVamsasModel(new VamsasModel()); - object.setCreationDate( new java.util.Date(timeStamp) ); + object.setCreationDate(new java.util.Date(timeStamp)); jalview.datamodel.AlignmentI jal = af.viewport.alignment; @@ -94,19 +145,19 @@ public class Jalview2XML Sequence vamsasSeq; JalviewModelSequence jms = new JalviewModelSequence(); - vamsasSet.setGapChar(jal.getGapCharacter()+""); + vamsasSet.setGapChar(jal.getGapCharacter() + ""); JSeq jseq; - //SAVE SEQUENCES int id = 0; - for(int i=0; i0) + if (jms.getJGroupCount() > 0) { JGroup[] groups = jms.getJGroup(); + for (int i = 0; i < groups.length; i++) { - ColourSchemeI cs = ColourSchemeProperty.getColour(al, groups[i].getColour() ); - if (cs instanceof ResidueColourScheme) - ( (ResidueColourScheme) cs).setThreshold(groups[i].getPidThreshold()); - else if (cs instanceof ScoreColourScheme) - ( (ScoreColourScheme) cs).setThreshold(groups[i].getPidThreshold()); - - jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup - (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())); - int [] ids = groups[i].getSeq(); - for(int s=0; s0) + if (object.getVamsasModel().getTreeCount() > 0) { - try{ + try + { af.ShowNewickTree(new jalview.io.NewickFile( - (String)object.getVamsasModel().getTree(0)), "Tree"); - }catch(Exception ex){ex.printStackTrace();} + (String) object.getVamsasModel().getTree(0)), "Tree"); + } + catch (Exception ex) + { + ex.printStackTrace(); + } } - } } - - -