moved to org.biojava
[jalview.git] / src / jalview / gui / Jalview2XML.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 package jalview.gui;\r
20 \r
21 \r
22 import jalview.schemes.*;\r
23 \r
24 import jalview.gui.*;\r
25 \r
26 import java.io.*;\r
27 \r
28 import java.net.*;\r
29 \r
30 import java.util.*;\r
31 \r
32 import java.util.jar.*;\r
33 \r
34 import javax.swing.*;\r
35 \r
36 import org.exolab.castor.xml.*;\r
37 \r
38 import jalview.schemabinding.version2.*;\r
39 \r
40 \r
41 \r
42 \r
43 /**\r
44  * DOCUMENT ME!\r
45  *\r
46  * @author $author$\r
47  * @version $Revision$\r
48  */\r
49 public class Jalview2XML\r
50 {\r
51     // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE\r
52     public void SaveState(File statefile)\r
53     {\r
54         long creation = System.currentTimeMillis();\r
55         JInternalFrame[] frames = Desktop.desktop.getAllFrames();\r
56 \r
57         if (frames == null)\r
58         {\r
59             return;\r
60         }\r
61 \r
62         try\r
63         {\r
64             FileOutputStream fos = new FileOutputStream(statefile);\r
65             JarOutputStream jout = new JarOutputStream(fos);\r
66 \r
67             //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS\r
68             ////////////////////////////////////////////////////\r
69             PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,\r
70                         "UTF-8"));\r
71 \r
72             Vector shortNames = new Vector();\r
73 \r
74             //REVERSE ORDER\r
75             for (int i = frames.length - 1; i > -1; i--)\r
76             {\r
77                 if (frames[i] instanceof AlignFrame)\r
78                 {\r
79                     AlignFrame af = (AlignFrame) frames[i];\r
80 \r
81                     String shortName = af.getTitle();\r
82 \r
83                     if (shortName.indexOf(File.separatorChar) > -1)\r
84                     {\r
85                         shortName = shortName.substring(shortName.lastIndexOf(\r
86                                     File.separatorChar) + 1);\r
87                     }\r
88 \r
89                     int count = 1;\r
90 \r
91                     while (shortNames.contains(shortName))\r
92                     {\r
93                         if (shortName.endsWith("_" + (count - 1)))\r
94                         {\r
95                             shortName = shortName.substring(0,\r
96                                     shortName.lastIndexOf("_"));\r
97                         }\r
98 \r
99                         shortName = shortName.concat("_" + count);\r
100                         count++;\r
101                     }\r
102 \r
103                     shortNames.addElement(shortName);\r
104 \r
105                     if (!shortName.endsWith(".xml"))\r
106                     {\r
107                         shortName = shortName + ".xml";\r
108                     }\r
109 \r
110                     SaveState(af, creation, shortName, jout, out);\r
111                 }\r
112             }\r
113 \r
114             out.close();\r
115             jout.close();\r
116         }\r
117         catch (Exception ex)\r
118         {\r
119             ex.printStackTrace();\r
120         }\r
121     }\r
122 \r
123     // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW\r
124     public void SaveAlignment(AlignFrame af, String jarFile,\r
125         String fileName)\r
126     {\r
127         try\r
128         {\r
129             FileOutputStream fos = new FileOutputStream(jarFile);\r
130             JarOutputStream jout = new JarOutputStream(fos);\r
131 \r
132             //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS\r
133             ////////////////////////////////////////////////////\r
134             PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,\r
135                         "UTF-8"));\r
136 \r
137             SaveState(af, System.currentTimeMillis(), fileName, jout, out);\r
138             out.close();\r
139             jout.close();\r
140         }\r
141         catch (Exception ex)\r
142         {\r
143           ex.printStackTrace();\r
144         }\r
145     }\r
146 \r
147     /**\r
148      * DOCUMENT ME!\r
149      *\r
150      * @param af DOCUMENT ME!\r
151      * @param timeStamp DOCUMENT ME!\r
152      * @param fileName DOCUMENT ME!\r
153      * @param jout DOCUMENT ME!\r
154      * @param out DOCUMENT ME!\r
155      */\r
156     public void SaveState(AlignFrame af, long timeStamp,\r
157         String fileName, JarOutputStream jout, PrintWriter out)\r
158     {\r
159         Vector seqids = new Vector();\r
160         Vector userColours = new Vector();\r
161 \r
162         AlignViewport av = af.viewport;\r
163 \r
164         JalviewModel object = new JalviewModel();\r
165         object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel());\r
166 \r
167         object.setCreationDate(new java.util.Date(timeStamp));\r
168         object.setVersion(jalview.bin.Cache.getProperty("VERSION"));\r
169 \r
170         jalview.datamodel.AlignmentI jal = af.viewport.alignment;\r
171         jalview.datamodel.AlignmentI jalhidden = null;\r
172 \r
173         if(av.hasHiddenRows)\r
174         {\r
175           jalhidden = jal;\r
176           jal = jal.getHiddenSequences().getFullAlignment();\r
177         }\r
178 \r
179 \r
180         SequenceSet vamsasSet = new SequenceSet();\r
181         Sequence vamsasSeq;\r
182         JalviewModelSequence jms = new JalviewModelSequence();\r
183 \r
184         vamsasSet.setGapChar(jal.getGapCharacter() + "");\r
185 \r
186         JSeq jseq;\r
187 \r
188         //SAVE SEQUENCES\r
189         int id = 0;\r
190         for (int i = 0; i < jal.getHeight(); i++)\r
191         {\r
192             seqids.add(jal.getSequenceAt(i));\r
193             vamsasSeq = new Sequence();\r
194             vamsasSeq.setId(id + "");\r
195             vamsasSeq.setName(jal.getSequenceAt(i).getName());\r
196             vamsasSeq.setSequence(jal.getSequenceAt(i).getSequence());\r
197             vamsasSeq.setDescription(jal.getSequenceAt(i).getDescription());\r
198 \r
199             if(jal.getSequenceAt(i).getDatasetSequence().getDBRef()!=null)\r
200             {\r
201               jalview.datamodel.DBRefEntry [] dbrefs =\r
202                   jal.getSequenceAt(i).getDatasetSequence().getDBRef();\r
203 \r
204               for(int d=0; d<dbrefs.length; d++)\r
205               {\r
206                 DBRef dbref = new DBRef();\r
207                 dbref.setSource( dbrefs[d].getSource() );\r
208                 dbref.setVersion( dbrefs[d].getVersion());\r
209                 dbref.setAccessionId(dbrefs[d].getAccessionId());\r
210                 vamsasSeq.addDBRef(dbref);\r
211               }\r
212             }\r
213 \r
214             jseq = new JSeq();\r
215             jseq.setStart(jal.getSequenceAt(i).getStart());\r
216             jseq.setEnd(jal.getSequenceAt(i).getEnd());\r
217             jseq.setColour(jal.getSequenceAt(i).getColor().getRGB());\r
218 \r
219             jseq.setId(id);\r
220 \r
221             if (av.hasHiddenRows)\r
222             {\r
223               jseq.setHidden(jalhidden.getHiddenSequences().isHidden(\r
224                   jal.getSequenceAt(i)));\r
225 \r
226               if(jal.getSequenceAt(i).getHiddenSequences()!=null)\r
227               {\r
228                 jalview.datamodel.SequenceI [] reps =\r
229                     jal.getSequenceAt(i).getHiddenSequences().getSequencesInOrder(jal);\r
230 \r
231                 for(int h=0; h<reps.length; h++)\r
232                 {\r
233                   jseq.addHiddenSequences(\r
234                       jal.findIndex(reps[h])\r
235                       );\r
236                 }\r
237               }\r
238             }\r
239 \r
240 \r
241             if(jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures()!=null)\r
242             {\r
243               jalview.datamodel.SequenceFeature[] sf\r
244                   = jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures();\r
245               int index = 0;\r
246               while(index < sf.length)\r
247               {\r
248                 Features features = new Features();\r
249 \r
250                 features.setBegin(sf[index].getBegin());\r
251                 features.setEnd(sf[index].getEnd());\r
252                 features.setDescription(sf[index].getDescription());\r
253                 features.setType(sf[index].getType());\r
254                 features.setFeatureGroup(sf[index].getFeatureGroup());\r
255                 jseq.addFeatures(features);\r
256                 index ++;\r
257               }\r
258             }\r
259 \r
260             if(jal.getSequenceAt(i).getDatasetSequence().getPDBId()!=null)\r
261             {\r
262               Enumeration en = jal.getSequenceAt(i).getDatasetSequence().getPDBId().elements();\r
263               while(en.hasMoreElements())\r
264               {\r
265                 Pdbids pdb = new Pdbids();\r
266                 jalview.datamodel.PDBEntry entry\r
267                    = (jalview.datamodel.PDBEntry)en.nextElement();\r
268 \r
269                 pdb.setId(entry.getId());\r
270                 pdb.setType(entry.getType());\r
271 \r
272                 if(entry.getProperty()!=null)\r
273                 {\r
274                   PdbentryItem item = new PdbentryItem();\r
275                   Hashtable properties = entry.getProperty();\r
276                   Enumeration en2 = properties.keys();\r
277                   while(en2.hasMoreElements())\r
278                   {\r
279                     Property prop = new Property();\r
280                     String key = en2.nextElement().toString();\r
281                     prop.setName(key);\r
282                     prop.setValue( properties.get(key).toString() );\r
283                     item.addProperty(prop);\r
284                   }\r
285                   pdb.addPdbentryItem(item);\r
286                 }\r
287 \r
288                 jseq.addPdbids(pdb);\r
289               }\r
290             }\r
291 \r
292             jms.addJSeq(jseq);\r
293             vamsasSet.addSequence(vamsasSeq);\r
294             id++;\r
295         }\r
296 \r
297         //SAVE TREES\r
298         ///////////////////////////////////\r
299         if (af.viewport.currentTree != null)\r
300         {\r
301           // FIND ANY ASSOCIATED TREES\r
302           // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT\r
303           if (Desktop.desktop != null)\r
304           {\r
305             JInternalFrame[] frames = Desktop.desktop.getAllFrames();\r
306 \r
307             for (int t = 0; t < frames.length; t++)\r
308             {\r
309               if (frames[t] instanceof TreePanel)\r
310               {\r
311                 TreePanel tp = (TreePanel) frames[t];\r
312 \r
313                 if (tp.treeCanvas.av.alignment == jal)\r
314                 {\r
315                   Tree tree = new Tree();\r
316                   tree.setTitle(tp.getTitle());\r
317                   tree.setCurrentTree( (af.viewport.currentTree == tp.getTree()));\r
318                   tree.setNewick(tp.getTree().toString());\r
319                   tree.setThreshold(tp.treeCanvas.threshold);\r
320 \r
321                   tree.setFitToWindow(tp.fitToWindow.getState());\r
322                   tree.setFontName(tp.getTreeFont().getName());\r
323                   tree.setFontSize(tp.getTreeFont().getSize());\r
324                   tree.setFontStyle(tp.getTreeFont().getStyle());\r
325                   tree.setMarkUnlinked(tp.placeholdersMenu.getState());\r
326 \r
327                   tree.setShowBootstrap(tp.bootstrapMenu.getState());\r
328                   tree.setShowDistances(tp.distanceMenu.getState());\r
329 \r
330                   tree.setHeight(tp.getHeight());\r
331                   tree.setWidth(tp.getWidth());\r
332                   tree.setXpos(tp.getX());\r
333                   tree.setYpos(tp.getY());\r
334 \r
335                   jms.addTree(tree);\r
336                 }\r
337               }\r
338             }\r
339           }\r
340         }\r
341 \r
342         //SAVE ANNOTATIONS\r
343         if (jal.getAlignmentAnnotation() != null)\r
344         {\r
345             jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();\r
346 \r
347             for (int i = 0; i < aa.length; i++)\r
348             {\r
349                 Annotation an = new Annotation();\r
350 \r
351                 if (aa[i].label.equals("Quality") ||\r
352                         aa[i].label.equals("Conservation") ||\r
353                         aa[i].label.equals("Consensus"))\r
354                 {\r
355                     an.setLabel(aa[i].label);\r
356                     an.setGraph(true);\r
357                     vamsasSet.addAnnotation(an);\r
358                     continue;\r
359                 }\r
360 \r
361 \r
362                 an.setDescription(aa[i].description);\r
363 \r
364                 if(aa[i].sequenceRef!=null)\r
365                  {\r
366                    an.setSequenceRef(aa[i].sequenceRef.getName());\r
367                  }\r
368 \r
369                 if(aa[i].graph>0)\r
370                 {\r
371                   an.setGraph(true);\r
372                   an.setGraphType(aa[i].graph);\r
373                   an.setGraphGroup(aa[i].graphGroup);\r
374                   if(aa[i].getThreshold()!=null)\r
375                   {\r
376                     ThresholdLine line = new ThresholdLine();\r
377                     line.setLabel(aa[i].getThreshold().label);\r
378                     line.setValue(aa[i].getThreshold().value);\r
379                     line.setColour(aa[i].getThreshold().colour.getRGB());\r
380                     an.setThresholdLine(line);\r
381                   }\r
382                 }\r
383                 else\r
384                   an.setGraph(false);\r
385 \r
386                 an.setLabel(aa[i].label);\r
387 \r
388                 AnnotationElement ae;\r
389 \r
390                 for (int a = 0; a < aa[i].annotations.length; a++)\r
391                 {\r
392                     if ((aa[i] == null) || (aa[i].annotations[a] == null))\r
393                     {\r
394                         continue;\r
395                     }\r
396 \r
397                     ae = new AnnotationElement();\r
398                     ae.setDescription(aa[i].annotations[a].description);\r
399                     ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);\r
400                     ae.setValue(aa[i].annotations[a].value);\r
401                     ae.setPosition(a);\r
402                     ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure +\r
403                         "");\r
404 \r
405                     if(aa[i].annotations[a].colour!=java.awt.Color.black)\r
406                       ae.setColour(aa[i].annotations[a].colour.getRGB());\r
407 \r
408                     an.addAnnotationElement(ae);\r
409                 }\r
410 \r
411                 vamsasSet.addAnnotation(an);\r
412             }\r
413         }\r
414 \r
415         //SAVE GROUPS\r
416         if (jal.getGroups() != null)\r
417         {\r
418             JGroup[] groups = new JGroup[jal.getGroups().size()];\r
419 \r
420             for (int i = 0; i < groups.length; i++)\r
421             {\r
422                 groups[i] = new JGroup();\r
423 \r
424                 jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal.getGroups()\r
425                                                                                           .elementAt(i);\r
426                 groups[i].setStart(sg.getStartRes());\r
427                 groups[i].setEnd(sg.getEndRes());\r
428                 groups[i].setName(sg.getName());\r
429                 if(sg.cs!=null)\r
430                 {\r
431                   if (sg.cs.conservationApplied())\r
432                   {\r
433                     groups[i].setConsThreshold(sg.cs.getConservationInc());\r
434 \r
435                     if (sg.cs instanceof jalview.schemes.UserColourScheme)\r
436                     {\r
437                       groups[i].setColour(SetUserColourScheme(sg.cs,\r
438                           userColours,\r
439                           jms));\r
440                     }\r
441                     else\r
442                     {\r
443                       groups[i].setColour(ColourSchemeProperty.getColourName(sg.\r
444                           cs));\r
445                     }\r
446                   }\r
447                   else if(sg.cs instanceof jalview.schemes.AnnotationColourGradient)\r
448                   {\r
449                     groups[i].setColour(\r
450                         ColourSchemeProperty.getColourName(\r
451                       ( (jalview.schemes.AnnotationColourGradient) sg.cs).getBaseColour()));\r
452                   }\r
453                   else if (sg.cs instanceof jalview.schemes.UserColourScheme)\r
454                   {\r
455                     groups[i].setColour(SetUserColourScheme(sg.cs, userColours,\r
456                         jms));\r
457                   }\r
458                   else\r
459                   {\r
460                     groups[i].setColour(ColourSchemeProperty.getColourName(\r
461                         sg.cs));\r
462                   }\r
463 \r
464                   groups[i].setPidThreshold(sg.cs.getThreshold());\r
465                 }\r
466 \r
467                 groups[i].setOutlineColour(sg.getOutlineColour().getRGB());\r
468                 groups[i].setDisplayBoxes(sg.getDisplayBoxes());\r
469                 groups[i].setDisplayText(sg.getDisplayText());\r
470                 groups[i].setColourText(sg.getColourText());\r
471 \r
472                 for (int s = 0; s < sg.getSize(false); s++)\r
473                 {\r
474                     jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg.getSequenceAt(s);\r
475                     int index = seqids.indexOf(seq);\r
476                     groups[i].addSeq(index);\r
477                 }\r
478             }\r
479 \r
480             jms.setJGroup(groups);\r
481         }\r
482 \r
483 \r
484         ///////////SAVE VIEWPORT\r
485         Viewport view = new Viewport();\r
486         view.setTitle(af.getTitle());\r
487         view.setXpos(af.getX());\r
488         view.setYpos(af.getY());\r
489         view.setWidth(af.getWidth());\r
490         view.setHeight(af.getHeight());\r
491         view.setStartRes(av.startRes);\r
492         view.setStartSeq(av.startSeq);\r
493 \r
494         if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)\r
495         {\r
496             view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),\r
497                     userColours, jms));\r
498         }\r
499         else if(av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)\r
500         {\r
501            jalview.schemes.AnnotationColourGradient acg\r
502               = (jalview.schemes.AnnotationColourGradient)av.getGlobalColourScheme();\r
503 \r
504             AnnotationColours ac = new AnnotationColours();\r
505             ac.setAboveThreshold(acg.getAboveThreshold());\r
506             ac.setThreshold(acg.getAnnotationThreshold());\r
507             ac.setAnnotation(acg.getAnnotation());\r
508             if(acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)\r
509               ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),\r
510                     userColours, jms));\r
511             else\r
512               ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour()));\r
513 \r
514             ac.setMaxColour(acg.getMaxColour().getRGB());\r
515             ac.setMinColour(acg.getMinColour().getRGB());\r
516             view.setAnnotationColours(ac);\r
517             view.setBgColour("AnnotationColourGradient");\r
518         }\r
519         else\r
520         {\r
521             view.setBgColour(ColourSchemeProperty.getColourName(\r
522                     av.getGlobalColourScheme()));\r
523         }\r
524 \r
525         ColourSchemeI cs = av.getGlobalColourScheme();\r
526 \r
527         if(cs!=null)\r
528         {\r
529           if (cs.conservationApplied())\r
530           {\r
531             view.setConsThreshold(cs.getConservationInc());\r
532             if (cs instanceof jalview.schemes.UserColourScheme)\r
533               view.setBgColour(SetUserColourScheme(cs, userColours, jms));\r
534           }\r
535 \r
536           if (cs instanceof ResidueColourScheme)\r
537           {\r
538             view.setPidThreshold(cs.getThreshold());\r
539           }\r
540         }\r
541 \r
542         view.setConservationSelected(av.getConservationSelected());\r
543         view.setPidSelected(av.getAbovePIDThreshold());\r
544         view.setFontName(av.font.getName());\r
545         view.setFontSize(av.font.getSize());\r
546         view.setFontStyle(av.font.getStyle());\r
547         view.setRenderGaps(av.renderGaps);\r
548         view.setShowAnnotation(av.getShowAnnotation());\r
549         view.setShowBoxes(av.getShowBoxes());\r
550         view.setShowColourText(av.getColourText());\r
551         view.setShowConservation(av.showConservation);\r
552         view.setShowFullId(av.getShowJVSuffix());\r
553         view.setShowIdentity(av.showIdentity);\r
554         view.setShowQuality(av.showQuality);\r
555         view.setShowSequenceFeatures(av.showSequenceFeatures);\r
556         view.setShowText(av.getShowText());\r
557         view.setWrapAlignment(av.getWrapAlignment());\r
558 \r
559         if(av.featuresDisplayed!=null)\r
560         {\r
561           jalview.schemabinding.version2.FeatureSettings fs\r
562               = new jalview.schemabinding.version2.FeatureSettings();\r
563 \r
564           String [] renderOrder =\r
565               af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;\r
566           for(int ro=0; ro<renderOrder.length; ro++)\r
567           {\r
568             Setting setting = new Setting();\r
569             setting.setType(renderOrder[ro]);\r
570             setting.setColour(\r
571                 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().getColour(renderOrder[ro]).getRGB()\r
572                 );\r
573 \r
574             setting.setDisplay(\r
575                 av.featuresDisplayed.containsKey(renderOrder[ro])\r
576                 );\r
577 \r
578             fs.addSetting(setting);\r
579 \r
580           }\r
581           jms.setFeatureSettings(fs);\r
582 \r
583         }\r
584 \r
585         if(av.hasHiddenColumns)\r
586         {\r
587           for(int c=0; c<av.getColumnSelection().getHiddenColumns().size(); c++)\r
588           {\r
589             int [] region = (int[]) av.getColumnSelection().getHiddenColumns().elementAt(c);\r
590             HiddenColumns hc = new HiddenColumns();\r
591             hc.setStart(region[0]);\r
592             hc.setEnd(region[1]);\r
593             view.addHiddenColumns(hc);\r
594           }\r
595         }\r
596 \r
597         if(av.hasHiddenRows)\r
598         {\r
599         //  av.alignment.getHiddenSequences().get\r
600       //    HiddenSequences hs = new HiddenSequences();\r
601       //    hs.ad\r
602       //    view.addHiddenSequences();\r
603       //    av.showAllHiddenSeqs();.alignment.getHiddenSequences().\r
604         }\r
605 \r
606         jms.addViewport(view);\r
607 \r
608 \r
609         object.setJalviewModelSequence(jms);\r
610         object.getVamsasModel().addSequenceSet(vamsasSet);\r
611 \r
612         try\r
613         {\r
614             if (!fileName.endsWith(".xml"))\r
615             {\r
616                 fileName = fileName + ".xml";\r
617             }\r
618 \r
619             JarEntry entry = new JarEntry(fileName);\r
620             jout.putNextEntry(entry);\r
621 \r
622             object.marshal(out);\r
623         }\r
624         catch (Exception ex)\r
625         {\r
626             ex.printStackTrace();\r
627         }\r
628     }\r
629 \r
630     String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,\r
631         Vector userColours, JalviewModelSequence jms)\r
632     {\r
633         String id = null;\r
634         jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;\r
635 \r
636         if (!userColours.contains(ucs))\r
637         {\r
638             userColours.add(ucs);\r
639 \r
640             java.awt.Color[] colours = ucs.getColours();\r
641             jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours();\r
642             jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme();\r
643 \r
644             for (int i = 0; i < colours.length; i++)\r
645             {\r
646                 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();\r
647                 col.setRGB(jalview.util.Format.getHexString(colours[i]));\r
648                 jbucs.addColour(col);\r
649             }\r
650 \r
651             id = "ucs" + userColours.indexOf(ucs);\r
652             uc.setId(id);\r
653             uc.setUserColourScheme(jbucs);\r
654             jms.addUserColours(uc);\r
655         }\r
656 \r
657         return id;\r
658     }\r
659 \r
660    jalview.schemes.UserColourScheme GetUserColourScheme(\r
661         JalviewModelSequence jms, String id)\r
662     {\r
663         UserColours[] uc = jms.getUserColours();\r
664         UserColours colours = null;\r
665 \r
666         for (int i = 0; i < uc.length; i++)\r
667         {\r
668             if (uc[i].getId().equals(id))\r
669             {\r
670                 colours = uc[i];\r
671 \r
672                 break;\r
673             }\r
674         }\r
675 \r
676         int csize = colours.getUserColourScheme().getColourCount();\r
677         java.awt.Color[] newColours = new java.awt.Color[csize];\r
678 \r
679         for (int i = 0; i < csize; i++)\r
680         {\r
681             newColours[i] = new java.awt.Color(Integer.parseInt(\r
682                         colours.getUserColourScheme().getColour(i).getRGB(), 16));\r
683         }\r
684 \r
685         return new jalview.schemes.UserColourScheme(newColours);\r
686     }\r
687 \r
688     /**\r
689      * DOCUMENT ME!\r
690      *\r
691      * @param file DOCUMENT ME!\r
692      */\r
693     public AlignFrame LoadJalviewAlign(String file)\r
694     {\r
695 \r
696         jalview.gui.AlignFrame af = null;\r
697 \r
698         try\r
699         {\r
700             //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING\r
701             URL url = null;\r
702 \r
703             if (file.startsWith("http://"))\r
704             {\r
705                 url = new URL(file);\r
706             }\r
707 \r
708             JarInputStream jin = null;\r
709             JarEntry jarentry = null;\r
710             int entryCount = 1;\r
711 \r
712             do\r
713             {\r
714                 if (url != null)\r
715                 {\r
716                     jin = new JarInputStream(url.openStream());\r
717                 }\r
718                 else\r
719                 {\r
720                     jin = new JarInputStream(new FileInputStream(file));\r
721                 }\r
722 \r
723                 for (int i = 0; i < entryCount; i++)\r
724                 {\r
725                     jarentry = jin.getNextJarEntry();\r
726 \r
727                   }\r
728 \r
729 \r
730                   class NoDescIDResolver implements IDResolver\r
731                   {\r
732                     public Object resolve(String idref)\r
733                     {\r
734                       System.out.println(idref+" used");\r
735                       return null;\r
736                     }\r
737                   }\r
738 \r
739 \r
740                 if (jarentry != null)\r
741                 {\r
742                     InputStreamReader in = new InputStreamReader(jin, "UTF-8");\r
743                     JalviewModel object = new JalviewModel();\r
744 \r
745                     Unmarshaller unmar = new Unmarshaller(object);\r
746                     unmar.setValidation(false);\r
747                     object = (JalviewModel) unmar.unmarshal( in );\r
748 \r
749                     af = LoadFromObject(object);\r
750                     entryCount++;\r
751                 }\r
752             }\r
753             while (jarentry != null);\r
754         }\r
755         catch(java.net.UnknownHostException ex)\r
756         {\r
757           ex.printStackTrace();\r
758           System.err.println("Couldn't locate Jalview XML file : " +\r
759               ex + "\n");\r
760            JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
761                                     "Couldn't locate " + file,\r
762                                     "URL not found",\r
763                                     JOptionPane.WARNING_MESSAGE);\r
764 \r
765         }\r
766         catch (Exception ex)\r
767         {\r
768           //Is Version 1 Jar file?\r
769           af =  new Jalview2XML_V1().LoadJalviewAlign(file);\r
770 \r
771           if(af!=null)\r
772           {\r
773             System.out.println("Successfully loaded archive file");\r
774             return af;\r
775           }\r
776           ex.printStackTrace();\r
777             System.err.println("Exception whilst loading jalview XML file : " +\r
778                 ex + "\n");\r
779              JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
780                                       "Error loading  " + file,\r
781                                       "Error loading Jalview file",\r
782                                       JOptionPane.WARNING_MESSAGE);\r
783 \r
784         }\r
785 \r
786         return af;\r
787     }\r
788 \r
789     AlignFrame LoadFromObject(JalviewModel object)\r
790     {\r
791         Vector seqids = new Vector();\r
792         SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);\r
793         Sequence[] vamsasSeq = vamsasSet.getSequence();\r
794 \r
795         JalviewModelSequence jms = object.getJalviewModelSequence();\r
796 \r
797         //////////////////////////////////\r
798         //LOAD SEQUENCES\r
799         Vector hiddenSeqs = null;\r
800         jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];\r
801         JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();\r
802         for (int i = 0; i < vamsasSeq.length; i++)\r
803         {\r
804             jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),\r
805                     vamsasSeq[i].getSequence());\r
806             jseqs[i].setDescription( vamsasSeq[i].getDescription() );\r
807 \r
808             if(JSEQ[i].getHidden())\r
809             {\r
810               if(hiddenSeqs == null)\r
811                 hiddenSeqs = new Vector();\r
812               hiddenSeqs.addElement(jseqs[i]);\r
813             }\r
814             jseqs[i].setStart(JSEQ[i].getStart());\r
815             jseqs[i].setEnd(JSEQ[i].getEnd());\r
816             jseqs[i].setColor(new java.awt.Color(JSEQ[i].getColour()));\r
817             seqids.add(jseqs[i]);\r
818         }\r
819 \r
820         ///SequenceFeatures are added to the DatasetSequence,\r
821         // so we must create the dataset before loading features\r
822         /////////////////////////////////\r
823         jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);\r
824         al.setDataset(null);\r
825         /////////////////////////////////\r
826 \r
827 \r
828         for (int i = 0; i < vamsasSeq.length; i++)\r
829         {\r
830           if (JSEQ[i].getFeaturesCount() > 0)\r
831           {\r
832             Features[] features = JSEQ[i].getFeatures();\r
833             for (int f = 0; f < features.length; f++)\r
834             {\r
835               jalview.datamodel.SequenceFeature sf\r
836                   = new jalview.datamodel.SequenceFeature(features[f].getType(),\r
837                   features[f].getDescription(), features[f].getStatus(),\r
838                   features[f].getBegin(), features[f].getEnd(),\r
839                   features[f].getFeatureGroup());\r
840 \r
841               al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);\r
842             }\r
843           }\r
844           if (JSEQ[i].getPdbidsCount() > 0)\r
845           {\r
846             Pdbids[] ids = JSEQ[i].getPdbids();\r
847             for (int p = 0; p < ids.length; p++)\r
848             {\r
849               jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();\r
850               entry.setId(ids[p].getId());\r
851               entry.setType(ids[p].getType());\r
852               al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);\r
853             }\r
854 \r
855           }\r
856           if(vamsasSeq[i].getDBRefCount()>0)\r
857           {\r
858             for(int d=0; d<vamsasSeq[i].getDBRefCount(); d++)\r
859             {\r
860               jalview.datamodel.DBRefEntry entry =\r
861                   new jalview.datamodel.DBRefEntry(\r
862                       vamsasSeq[i].getDBRef(d).getSource(),\r
863                       vamsasSeq[i].getDBRef(d).getVersion(),\r
864                       vamsasSeq[i].getDBRef(d).getAccessionId()\r
865                       );\r
866               al.getSequenceAt(i).getDatasetSequence().addDBRef(entry);\r
867             }\r
868 \r
869           }\r
870         }\r
871 \r
872 \r
873 \r
874          /////////////////////////////////\r
875         //////////////////////////////////\r
876         //LOAD ANNOTATIONS\r
877         boolean hideQuality = true,\r
878             hideConservation = true,\r
879             hideConsensus = true;\r
880 \r
881         if (vamsasSet.getAnnotation() != null)\r
882         {\r
883             Annotation[] an = vamsasSet.getAnnotation();\r
884 \r
885             for (int i = 0; i < an.length; i++)\r
886             {\r
887                if (an[i].getLabel().equals("Quality"))\r
888                 {\r
889                  hideQuality = false;\r
890                  continue;\r
891                 }\r
892                else if(an[i].getLabel().equals("Conservation"))\r
893                {\r
894                  hideConservation = false;\r
895                  continue;\r
896                }\r
897                else if(an[i].getLabel().equals("Consensus"))\r
898                {\r
899                  hideConsensus = false;\r
900                  continue;\r
901                }\r
902 \r
903                 AnnotationElement[] ae = an[i].getAnnotationElement();\r
904                 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];\r
905 \r
906                 for (int aa = 0; aa < ae.length; aa++)\r
907                 {\r
908                     anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),\r
909                             ae[aa].getDescription(),\r
910                             ae[aa].getSecondaryStructure().length()==0?' ':ae[aa].getSecondaryStructure().charAt(0),\r
911                             ae[aa].getValue());\r
912                     anot[ae[aa].getPosition()].colour = new java.awt.Color( ae[aa].getColour() );\r
913                 }\r
914 \r
915                 jalview.datamodel.AlignmentAnnotation jaa = null;\r
916 \r
917                 if (an[i].getGraph())\r
918                 {\r
919                   jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
920                       an[i].getDescription(), anot, 0, 0,\r
921                       an[i].getGraphType());\r
922 \r
923                   jaa.graphGroup = an[i].getGraphGroup();\r
924 \r
925                   if (an[i].getThresholdLine() != null)\r
926                   {\r
927                     jaa.setThreshold(new jalview.datamodel.GraphLine(\r
928                                   an[i].getThresholdLine().getValue(),\r
929                                   an[i].getThresholdLine().getLabel(),\r
930                                 new java.awt.Color(an[i].getThresholdLine().getColour()))\r
931                              );\r
932 \r
933                   }\r
934 \r
935                 }\r
936                 else\r
937                 {\r
938                     jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
939                             an[i].getDescription(), anot);\r
940                 }\r
941 \r
942                 if(an[i].getSequenceRef()!=null)\r
943                 {\r
944                   jaa.createSequenceMapping(\r
945                       al.findName(an[i].getSequenceRef()), 1\r
946                       );\r
947                   al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);\r
948                 }\r
949 \r
950                 al.addAnnotation(jaa);\r
951             }\r
952         }\r
953 \r
954 \r
955         //  af.changeColour() );\r
956         /////////////////////////\r
957         //LOAD GROUPS\r
958         if (jms.getJGroupCount() > 0)\r
959         {\r
960             JGroup[] groups = jms.getJGroup();\r
961 \r
962             for (int i = 0; i < groups.length; i++)\r
963             {\r
964                 ColourSchemeI cs = null;\r
965 \r
966                 if (groups[i].getColour() != null)\r
967                 {\r
968                     if (groups[i].getColour().startsWith("ucs"))\r
969                     {\r
970                         cs = GetUserColourScheme(jms, groups[i].getColour());\r
971                     }\r
972                     else\r
973                     {\r
974                         cs = ColourSchemeProperty.getColour(al,\r
975                                 groups[i].getColour());\r
976                     }\r
977 \r
978                     if(cs!=null)\r
979                       cs.setThreshold(groups[i].getPidThreshold(), true);\r
980                 }\r
981 \r
982                 Vector seqs = new Vector();\r
983                 int[] ids = groups[i].getSeq();\r
984 \r
985                 for (int s = 0; s < ids.length; s++)\r
986                 {\r
987                     seqs.addElement((jalview.datamodel.SequenceI) seqids.elementAt(\r
988                             ids[s]));\r
989                 }\r
990 \r
991                 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,\r
992                         groups[i].getName(), cs, groups[i].getDisplayBoxes(),\r
993                         groups[i].getDisplayText(), groups[i].getColourText(),\r
994                         groups[i].getStart(), groups[i].getEnd());\r
995 \r
996                 sg.setOutlineColour(new java.awt.Color(\r
997                         groups[i].getOutlineColour()));\r
998 \r
999                 if (groups[i].getConsThreshold() != 0)\r
1000                 {\r
1001                     jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",\r
1002                             ResidueProperties.propHash, 3, sg.getSequences(false), 0,\r
1003                             sg.getWidth() - 1);\r
1004                     c.calculate();\r
1005                     c.verdict(false, 25);\r
1006                     sg.cs.setConservation(c);\r
1007                 }\r
1008 \r
1009                 al.addGroup(sg);\r
1010             }\r
1011         }\r
1012 \r
1013 \r
1014         /////////////////////////////////\r
1015         // LOAD VIEWPORT\r
1016         Viewport[] views = jms.getViewport();\r
1017         Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER\r
1018 \r
1019 \r
1020         AlignFrame af = new AlignFrame(al);\r
1021 \r
1022         if(hiddenSeqs!=null)\r
1023         {\r
1024           for(int s=0; s<JSEQ.length; s++)\r
1025           {\r
1026             for(int r=0; r<JSEQ[s].getHiddenSequencesCount(); r++)\r
1027             {\r
1028               al.getSequenceAt(s).addHiddenSequence(\r
1029                   al.getSequenceAt( JSEQ[s].getHiddenSequences(r)  )\r
1030                   );\r
1031             }\r
1032           }\r
1033 \r
1034           for(int s=0; s<hiddenSeqs.size(); s++)\r
1035           {\r
1036               af.viewport.hideSequence(\r
1037                 (jalview.datamodel.SequenceI)hiddenSeqs.elementAt(s));\r
1038           }\r
1039         }\r
1040 \r
1041 \r
1042         if(hideConsensus || hideQuality || hideConservation)\r
1043         {\r
1044           int hSize = al.getAlignmentAnnotation().length;\r
1045           for (int h = 0; h < hSize; h++)\r
1046           {\r
1047             if (\r
1048                 (hideConsensus &&\r
1049                  al.getAlignmentAnnotation()[h].label.equals("Consensus"))\r
1050                 ||\r
1051                 (hideQuality &&\r
1052                  al.getAlignmentAnnotation()[h].label.equals("Quality"))\r
1053                 ||\r
1054                 (hideConservation &&\r
1055                  al.getAlignmentAnnotation()[h].label.equals("Conservation")))\r
1056             {\r
1057               al.deleteAnnotation(al.getAlignmentAnnotation()[h]);\r
1058               hSize--;\r
1059               h--;\r
1060             }\r
1061           }\r
1062           af.alignPanel.adjustAnnotationHeight();\r
1063         }\r
1064 \r
1065         af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),\r
1066             view.getHeight());\r
1067         af.viewport.setStartRes(view.getStartRes());\r
1068         af.viewport.setStartSeq(view.getStartSeq());\r
1069         af.viewport.setShowAnnotation(view.getShowAnnotation());\r
1070         af.viewport.showConservation = view.getShowConservation();\r
1071         af.viewport.showQuality = view.getShowQuality();\r
1072         af.viewport.showIdentity = view.getShowIdentity();\r
1073         af.viewport.setAbovePIDThreshold(view.getPidSelected());\r
1074         af.abovePIDThreshold.setSelected(view.getPidSelected());\r
1075         af.viewport.setColourText(view.getShowColourText());\r
1076         af.colourTextMenuItem.setSelected(view.getShowColourText());\r
1077         af.viewport.setConservationSelected(view.getConservationSelected());\r
1078         af.conservationMenuItem.setSelected(view.getConservationSelected());\r
1079 \r
1080         af.viewport.setShowJVSuffix(view.getShowFullId());\r
1081         af.seqLimits.setSelected(view.getShowFullId());\r
1082 \r
1083         af.viewport.setFont(new java.awt.Font(view.getFontName(),\r
1084                 view.getFontStyle(), view.getFontSize()));\r
1085         af.alignPanel.fontChanged();\r
1086 \r
1087         af.viewport.setRenderGaps(view.getRenderGaps());\r
1088         af.renderGapsMenuItem.setSelected(view.getRenderGaps());\r
1089 \r
1090         af.viewport.setWrapAlignment(view.getWrapAlignment());\r
1091         af.wrapMenuItem.setSelected(view.getWrapAlignment());\r
1092 \r
1093         if (view.getWrapAlignment())\r
1094         {\r
1095             af.alignPanel.setWrapAlignment(view.getWrapAlignment());\r
1096         }\r
1097         else\r
1098         {\r
1099             af.annotationPanelMenuItem.setState(view.getShowAnnotation());\r
1100             af.viewport.setShowAnnotation(view.getShowAnnotation());\r
1101             af.alignPanel.setAnnotationVisible(view.getShowAnnotation());\r
1102         }\r
1103 \r
1104         af.viewport.setShowBoxes(view.getShowBoxes());\r
1105         af.viewBoxesMenuItem.setSelected(view.getShowBoxes());\r
1106         af.viewport.setShowText(view.getShowText());\r
1107         af.viewTextMenuItem.setSelected(view.getShowText());\r
1108 \r
1109         ColourSchemeI cs = null;\r
1110 \r
1111         if (view.getBgColour() != null)\r
1112         {\r
1113             if (view.getBgColour().startsWith("ucs"))\r
1114             {\r
1115                 cs = GetUserColourScheme(jms, view.getBgColour());\r
1116             }\r
1117             else if(view.getBgColour().startsWith("Annotation"))\r
1118             {\r
1119               //int find annotation\r
1120               for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++)\r
1121               {\r
1122                 if (af.viewport.alignment.getAlignmentAnnotation()[i].label.\r
1123                     equals(view.getAnnotationColours().getAnnotation()))\r
1124                 {\r
1125                   if (af.viewport.alignment.getAlignmentAnnotation()[i].\r
1126                       getThreshold() == null)\r
1127                   {\r
1128                     af.viewport.alignment.getAlignmentAnnotation()[i].\r
1129                         setThreshold(\r
1130                             new jalview.datamodel.GraphLine(\r
1131                                 view.getAnnotationColours().getThreshold(),\r
1132                                 "Threshold", java.awt.Color.black)\r
1133 \r
1134                         );\r
1135                   }\r
1136 \r
1137 \r
1138                   if (view.getAnnotationColours().getColourScheme().equals(\r
1139                       "None"))\r
1140                   {\r
1141                     cs = new AnnotationColourGradient(\r
1142                         af.viewport.alignment.getAlignmentAnnotation()[i],\r
1143                         new java.awt.Color(view.getAnnotationColours().\r
1144                                            getMinColour()),\r
1145                         new java.awt.Color(view.getAnnotationColours().\r
1146                                            getMaxColour()),\r
1147                         view.getAnnotationColours().getAboveThreshold());\r
1148                   }\r
1149                   else if (view.getAnnotationColours().getColourScheme().\r
1150                            startsWith("ucs"))\r
1151                   {\r
1152                      cs = new AnnotationColourGradient(\r
1153                          af.viewport.alignment.getAlignmentAnnotation()[i],\r
1154                          GetUserColourScheme(jms, view.getAnnotationColours().\r
1155                                                         getColourScheme()),\r
1156                          view.getAnnotationColours().getAboveThreshold()\r
1157                          );\r
1158                    }\r
1159                    else\r
1160                    {\r
1161                      cs = new AnnotationColourGradient(\r
1162                          af.viewport.alignment.getAlignmentAnnotation()[i],\r
1163                          ColourSchemeProperty.getColour(al,\r
1164                          view.getAnnotationColours().getColourScheme()),\r
1165                          view.getAnnotationColours().getAboveThreshold()\r
1166                          );\r
1167                    }\r
1168 \r
1169                   // Also use these settings for all the groups\r
1170                   if (al.getGroups() != null)\r
1171                     for (int g = 0; g < al.getGroups().size(); g++)\r
1172                     {\r
1173                       jalview.datamodel.SequenceGroup sg\r
1174                           = (jalview.datamodel.SequenceGroup)al.getGroups().elementAt(g);\r
1175 \r
1176                       if(sg.cs == null)\r
1177                         continue;\r
1178 \r
1179 \r
1180                   /*    if (view.getAnnotationColours().getColourScheme().equals("None"))\r
1181                       {\r
1182                         sg.cs = new AnnotationColourGradient(\r
1183                             af.viewport.alignment.getAlignmentAnnotation()[i],\r
1184                             new java.awt.Color(view.getAnnotationColours().\r
1185                                                getMinColour()),\r
1186                             new java.awt.Color(view.getAnnotationColours().\r
1187                                                getMaxColour()),\r
1188                             view.getAnnotationColours().getAboveThreshold());\r
1189                       }\r
1190                       else*/\r
1191                       {\r
1192                         sg.cs = new AnnotationColourGradient(\r
1193                             af.viewport.alignment.getAlignmentAnnotation()[i],\r
1194                             sg.cs,\r
1195                             view.getAnnotationColours().getAboveThreshold()\r
1196                             );\r
1197                       }\r
1198 \r
1199                     }\r
1200 \r
1201 \r
1202                   break;\r
1203                 }\r
1204 \r
1205               }\r
1206             }\r
1207             else\r
1208             {\r
1209                 cs = ColourSchemeProperty.getColour(al, view.getBgColour());\r
1210             }\r
1211 \r
1212             if(cs!=null)\r
1213             {\r
1214               cs.setThreshold(view.getPidThreshold(), true);\r
1215               cs.setConsensus(af.viewport.vconsensus);\r
1216             }\r
1217         }\r
1218 \r
1219         af.setColourSelected(view.getBgColour());\r
1220         af.viewport.setGlobalColourScheme(cs);\r
1221         af.viewport.setColourAppliesToAllGroups(false);\r
1222         af.changeColour(cs);\r
1223         if (view.getConservationSelected() && cs!=null)\r
1224         {\r
1225           cs.setConservationInc(view.getConsThreshold());\r
1226         }\r
1227 \r
1228         af.viewport.setColourAppliesToAllGroups(true);\r
1229 \r
1230         if (view.getShowSequenceFeatures())\r
1231         {\r
1232            af.viewport.showSequenceFeatures = true;\r
1233            af.showSeqFeatures.setSelected(true);\r
1234         }\r
1235 \r
1236         if(jms.getFeatureSettings()!=null)\r
1237         {\r
1238           af.viewport.featuresDisplayed = new Hashtable();\r
1239           String [] renderOrder = new String[jms.getFeatureSettings().getSettingCount()];\r
1240          for(int fs=0; fs<jms.getFeatureSettings().getSettingCount(); fs++)\r
1241          {\r
1242            Setting setting = jms.getFeatureSettings().getSetting(fs);\r
1243 \r
1244            af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(setting.getType(),\r
1245                new java.awt.Color(setting.getColour()));\r
1246 \r
1247            renderOrder[fs] = setting.getType();\r
1248 \r
1249            if(setting.getDisplay())\r
1250              af.viewport.featuresDisplayed.put(\r
1251                  setting.getType(), new Integer(setting.getColour()));\r
1252          }\r
1253          af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;\r
1254         }\r
1255 \r
1256         if (view.getHiddenColumnsCount() > 0)\r
1257         {\r
1258           for (int c = 0; c < view.getHiddenColumnsCount(); c++)\r
1259           {\r
1260               af.viewport.hideColumns(\r
1261                 view.getHiddenColumns(c).getStart(),\r
1262                 view.getHiddenColumns(c).getEnd()+1\r
1263                 );\r
1264           }\r
1265         }\r
1266 \r
1267 \r
1268         Desktop.addInternalFrame(af, view.getTitle(),\r
1269              view.getWidth(), view.getHeight());\r
1270 \r
1271         //LOAD TREES\r
1272         ///////////////////////////////////////\r
1273         if (jms.getTreeCount() > 0)\r
1274         {\r
1275             try\r
1276             {\r
1277                 for (int t = 0; t < jms.getTreeCount(); t++)\r
1278                 {\r
1279 \r
1280                     Tree tree = jms.getTree(t);\r
1281 \r
1282                     TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(\r
1283                                 tree.getNewick()), tree.getTitle(),\r
1284                                 tree.getWidth(), tree.getHeight(),\r
1285                                 tree.getXpos(), tree.getYpos());\r
1286 \r
1287                     tp.fitToWindow.setState(tree.getFitToWindow());\r
1288                     tp.fitToWindow_actionPerformed(null);\r
1289 \r
1290                     if(tree.getFontName()!=null)\r
1291                       tp.setTreeFont(new java.awt.Font(tree.getFontName(),\r
1292                                           tree.getFontStyle(),\r
1293                                           tree.getFontSize()));\r
1294                     else\r
1295                       tp.setTreeFont(new java.awt.Font(view.getFontName(),\r
1296                                             view.getFontStyle(),\r
1297                                             tree.getFontSize()));\r
1298 \r
1299                     tp.showPlaceholders(tree.getMarkUnlinked());\r
1300                     tp.showBootstrap(tree.getShowBootstrap());\r
1301                     tp.showDistances(tree.getShowDistances());\r
1302 \r
1303                     tp.treeCanvas.threshold = tree.getThreshold();\r
1304 \r
1305                     if (tree.getCurrentTree())\r
1306                       af.viewport.setCurrentTree(tp.getTree());\r
1307                 }\r
1308 \r
1309             }\r
1310             catch (Exception ex)\r
1311             {\r
1312                 ex.printStackTrace();\r
1313             }\r
1314 \r
1315         }\r
1316 \r
1317         return af;\r
1318     }\r
1319 }\r
1320 \r