X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=44ff2ad943e9f19309353e4ef169091faa69c293;hb=1ee8b306b296ea2724e128f66486675bdaac7a3d;hp=12f2cb20640daf23751f617cd02c13317b8e049d;hpb=b12384aa7fdffd3167a83de75d2a560356ee65f1;p=jalview.git diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 12f2cb2..44ff2ad 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1,471 +1,795 @@ +/* + * 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.binding.*; + +import jalview.io.*; + +import jalview.schemes.*; + import java.io.*; + +import java.net.*; + import java.util.*; import java.util.jar.*; -import jalview.binding.*; -import jalview.schemes.*; -import javax.swing.JInternalFrame; +import javax.swing.*; +/** + * 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(); - // 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++) + if (frames == null) { - if (frames[i] instanceof AlignFrame) - { - AlignFrame af = (AlignFrame) frames[i]; + return; + } + + try + { + FileOutputStream fos = new FileOutputStream(statefile); + JarOutputStream jout = new JarOutputStream(fos); - String shortName = af.getTitle(); + //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS + //////////////////////////////////////////////////// + PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, + "UTF-8")); - shortName = shortName.replace('/', '_'); - shortName = shortName.replace('\\', '_'); + Vector shortNames = new Vector(); - int count=1; - while( shortNames.contains(shortName) ) + //REVERSE ORDER + for (int i = frames.length - 1; i > -1; i--) { - if(shortName.endsWith("_"+(count-1))) - shortName = shortName.substring(0, shortName.lastIndexOf("_")); + 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); - shortName = shortName.concat("_"+count); - count++; + if (!shortName.endsWith(".xml")) + { + shortName = shortName + ".xml"; + } + + SaveState(af, creation, shortName, jout, out); + } } - shortNames.addElement(shortName); - if(!shortName.endsWith(".xml")) - shortName = shortName+".xml"; + 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, creation, shortName, jout, out); - } + SaveState(af, System.currentTimeMillis(), fileName, jout, out); + out.close(); + jout.close(); } - out.close(); - jout.close(); - } - catch(Exception ex){ex.printStackTrace();} - } + catch (Exception ex) + { + } + } - // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW - public static void SaveState( 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")); + /** + * 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(); - SaveState(af, System.currentTimeMillis(), fileName, jout, out); - out.close(); - jout.close(); - }catch(Exception ex){} - } + AlignViewport av = af.viewport; - public static void SaveState( AlignFrame af, long timeStamp, - String fileName, JarOutputStream jout, PrintWriter out) - { + JalviewModel object = new JalviewModel(); + object.setVamsasModel(new VamsasModel()); - Vector seqids = new Vector(); + object.setCreationDate(new java.util.Date(timeStamp)); + object.setVersion(jalview.bin.Cache.getProperty("VERSION")); - AlignViewport av = af.viewport; + jalview.datamodel.AlignmentI jal = af.viewport.alignment; - JalviewModel object = new JalviewModel(); - object.setVamsasModel( new VamsasModel() ); + SequenceSet vamsasSet = new SequenceSet(); + Sequence vamsasSeq; + JalviewModelSequence jms = new JalviewModelSequence(); - object.setCreationDate( new java.util.Date(timeStamp) ); + vamsasSet.setGapChar(jal.getGapCharacter() + ""); - jalview.datamodel.AlignmentI jal = af.viewport.alignment; + JSeq jseq; - SequenceSet vamsasSet = new SequenceSet(); - Sequence vamsasSeq; - JalviewModelSequence jms = new JalviewModelSequence(); + //SAVE SEQUENCES + int id = 0; - vamsasSet.setGapChar(jal.getGapCharacter()+""); + for (int i = 0; i < jal.getHeight(); i++) + { + seqids.add(jal.getSequenceAt(i)); - JSeq jseq; + 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()); - //SAVE SEQUENCES - int id = 0; - for(int i=0; i0) + + static AlignFrame LoadFromObject(JalviewModel object) { - 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; s 0) + { + JGroup[] groups = jms.getJGroup(); - ColourSchemeI cs = af.viewport.getGlobalColourScheme(); - if(cs instanceof ConservationColourScheme) - ( (ConservationColourScheme) cs).inc = view.getConsThreshold(); + 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 instanceof ResidueColourScheme) + { + ((ResidueColourScheme) cs).setThreshold(groups[i].getPidThreshold()); + } + else if (cs instanceof ScoreColourScheme) + { + ((ScoreColourScheme) cs).setThreshold(groups[i].getPidThreshold()); + } + } + + 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); + cs = new ConservationColourScheme(c, cs); + sg.cs = cs; + } + + al.addGroup(sg); + } + } - if (cs instanceof ResidueColourScheme) - ( (ResidueColourScheme) cs).setThreshold(view.getPidThreshold()); - else if (cs instanceof ScoreColourScheme) - ( (ScoreColourScheme) cs).setThreshold(view.getPidThreshold()); + Desktop.addInternalFrame(af, view.getTitle(), + AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT); + 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()); + } - //LOAD TREES - THIS RELEASE ONLY ALLOWS 1 TREE - if(object.getVamsasModel().getTreeCount()>0) - { - try{ - af.ShowNewickTree(new jalview.io.NewickFile( - (String)object.getVamsasModel().getTree(0)), "Tree"); - }catch(Exception ex){ex.printStackTrace();} - } + 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 instanceof ConservationColourScheme) + { + ((ConservationColourScheme) cs).inc = view.getConsThreshold(); + } + if (cs instanceof ResidueColourScheme) + { + ((ResidueColourScheme) cs).setThreshold(view.getPidThreshold()); + } + else if (cs instanceof ScoreColourScheme) + { + ((ScoreColourScheme) cs).setThreshold(view.getPidThreshold()); + } + } + + af.viewport.setGlobalColourScheme(cs); + af.viewport.setColourAppliesToAllGroups(false); + af.changeColour(af.viewport.getGlobalColourScheme()); + af.viewport.setColourAppliesToAllGroups(true); + + if (view.getShowSequenceFeatures()) + { + af.viewport.showSequenceFeatures = true; + af.sequenceFeatures.setSelected(true); + new SequenceFeatureFetcher(al, af.alignPanel); + al.featuresAdded = true; + } + //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()); + + tp.setBounds(tree.getXpos(), tree.getYpos(), + tree.getWidth(), tree.getHeight()); + + tp.fitToWindow.setState(tree.getFitToWindow()); + tp.fitToWindow_actionPerformed(null); + tp.treeCanvas.fontSize = tree.getFontSize(); + tp.fontSize.setText("Font Size - " + tree.getFontSize()); + tp.placeholdersMenu.setState(tree.getMarkUnlinked()); + tp.placeholdersMenu_actionPerformed(null); + tp.bootstrapMenu.setState(tree.getShowBootstrap()); + tp.bootstrapMenu_actionPerformed(null); + tp.distanceMenu.setState(tree.getShowDistances()); + tp.distanceMenu_actionPerformed(null); + tp.treeCanvas.threshold = tree.getThreshold(); + + if (tree.getCurrentTree()) + af.viewport.setCurrentTree(tp.getTree()); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + return af; + } +}