in progress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / ArchaeopteryxE.java
1
2 package org.forester.archaeopteryx;
3
4 import java.awt.BorderLayout;
5 import java.awt.Container;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.ComponentAdapter;
9 import java.awt.event.ComponentEvent;
10 import java.io.ByteArrayOutputStream;
11 import java.io.File;
12 import java.io.IOException;
13 import java.net.URL;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.NoSuchElementException;
17
18 import javax.swing.ButtonGroup;
19 import javax.swing.JApplet;
20 import javax.swing.JCheckBoxMenuItem;
21 import javax.swing.JMenu;
22 import javax.swing.JMenuBar;
23 import javax.swing.JMenuItem;
24 import javax.swing.JOptionPane;
25 import javax.swing.JRadioButtonMenuItem;
26 import javax.swing.UIManager;
27 import javax.swing.UnsupportedLookAndFeelException;
28 import javax.swing.event.ChangeEvent;
29 import javax.swing.event.ChangeListener;
30
31 import org.apache.commons.codec.binary.Base64;
32 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
33 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
34 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
35 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
36 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.PhylogenyMethods;
39 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
40 import org.forester.phylogeny.data.SequenceRelation;
41 import org.forester.sdi.GSDI;
42 import org.forester.sdi.GSDIR;
43 import org.forester.sdi.SDIException;
44 import org.forester.util.ForesterConstants;
45 import org.forester.util.ForesterUtil;
46
47 // Use like this:
48 // <applet archive="forester.jar"
49 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
50 // codebase="http://www.myserver.org/path/to/forester"
51 // width="600"
52 // height="500"
53 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
54 // <param name="url_of_tree_to_load"
55 // value="http://www.myserver.org/examples/data/apaf.xml">
56 // <param name="config_file"
57 // value="http://www.myserver.org/examples/config/config_file.txt">
58 // </applet>
59 public class ArchaeopteryxE extends JApplet implements ActionListener {
60
61     private final static String         NAME             = "ArchaeopteryxE";
62     private static final long           serialVersionUID = -1220055577935759443L;
63     private Configuration               _configuration;
64     private MainPanelApplets            _mainpanel;
65     private JMenuBar                    _jmenubar;
66     private JMenu                       _options_jmenu;
67     private JMenu                       _font_size_menu;
68     private JMenuItem                   _super_tiny_fonts_mi;
69     private JMenuItem                   _tiny_fonts_mi;
70     private JMenuItem                   _small_fonts_mi;
71     private JMenuItem                   _medium_fonts_mi;
72     private JMenuItem                   _large_fonts_mi;
73     private JMenu                       _tools_menu;
74     private JMenuItem                   _taxcolor_item;
75     private JMenuItem                   _confcolor_item;
76     private JMenuItem                   _midpoint_root_item;
77     private JMenu                       _view_jmenu;
78     private JMenuItem                   _view_as_XML_item;
79     private JMenuItem                   _view_as_NH_item;
80     private JMenuItem                   _view_as_nexus_item;
81     private JMenuItem                   _display_basic_information_item;
82     private JMenu                       _type_menu;
83     private JCheckBoxMenuItem           _rectangular_type_cbmi;
84     private JCheckBoxMenuItem           _triangular_type_cbmi;
85     private JCheckBoxMenuItem           _curved_type_cbmi;
86     private JCheckBoxMenuItem           _convex_type_cbmi;
87     private JCheckBoxMenuItem           _euro_type_cbmi;
88     private JCheckBoxMenuItem           _rounded_type_cbmi;
89     private JCheckBoxMenuItem           _unrooted_type_cbmi;
90     private JCheckBoxMenuItem           _circular_type_cbmi;
91     private JMenuItem                   _help_item;
92     private JMenuItem                   _about_item;
93     private JMenu                       _help_jmenu;
94     private JMenuItem                   _website_item;
95     private JMenuItem                   _phyloxml_website_item;
96     private JMenuItem                   _phyloxml_ref_item;
97     private JMenuItem                   _aptx_ref_item;
98     private JMenuItem                   _remove_branch_color_item;
99     private JCheckBoxMenuItem           _show_domain_labels;
100     private JCheckBoxMenuItem           _show_annotation_ref_source;
101     private JCheckBoxMenuItem           _color_labels_same_as_parent_branch;
102     private JCheckBoxMenuItem           _abbreviate_scientific_names;
103     private JCheckBoxMenuItem           _screen_antialias_cbmi;
104     private JCheckBoxMenuItem           _background_gradient_cbmi;
105     private JCheckBoxMenuItem           _color_by_taxonomic_group_cbmi;
106     private JRadioButtonMenuItem        _non_lined_up_cladograms_rbmi;
107     private JRadioButtonMenuItem        _uniform_cladograms_rbmi;
108     private JRadioButtonMenuItem        _ext_node_dependent_cladogram_rbmi;
109     private Options                     _options;
110     private JMenuItem                   _choose_font_mi;
111     private JMenuItem                   _switch_colors_mi;
112     JCheckBoxMenuItem                   _label_direction_cbmi;
113     private JCheckBoxMenuItem           _show_scale_cbmi;
114     private JCheckBoxMenuItem           _search_case_senstive_cbmi;
115     private JCheckBoxMenuItem           _search_whole_words_only_cbmi;
116     private JCheckBoxMenuItem           _inverse_search_result_cbmi;
117     private JCheckBoxMenuItem           _show_overview_cbmi;
118     private JMenuItem                   _choose_minimal_confidence_mi;
119     private JCheckBoxMenuItem           _show_branch_length_values_cbmi;
120     private JMenuItem                   _collapse_species_specific_subtrees;
121     private JMenuItem                   _overview_placment_mi;
122     private ButtonGroup                 _radio_group_1;
123     private JCheckBoxMenuItem           _show_default_node_shapes_internal_cbmi;
124     private JCheckBoxMenuItem           _show_default_node_shapes_external_cbmi;
125     private JMenuItem                   _cycle_node_shape_mi;
126     private JMenuItem                   _cycle_node_fill_mi;
127     private JMenuItem                   _choose_node_size_mi;
128     private JCheckBoxMenuItem           _taxonomy_colorize_node_shapes_cbmi;
129     private JCheckBoxMenuItem           _show_confidence_stddev_cbmi;
130     private final LinkedList<TextFrame> _textframes      = new LinkedList<TextFrame>();
131     private JMenu                       _analysis_menu;
132     private JMenuItem                   _gsdi_item;
133     private JMenuItem                   _gsdir_item;
134     private Phylogeny                   _species_tree;
135
136     @Override
137     public void actionPerformed( final ActionEvent e ) {
138         final Object o = e.getSource();
139         if ( o == _midpoint_root_item ) {
140             getMainPanel().getCurrentTreePanel().midpointRoot();
141         }
142         else if ( o == _gsdi_item ) {
143             if ( isSubtreeDisplayed() ) {
144                 return;
145             }
146             executeGSDI();
147         }
148         else if ( o == _gsdir_item ) {
149             if ( isSubtreeDisplayed() ) {
150                 return;
151             }
152             executeGSDIR();
153         }
154         else if ( o == _taxcolor_item ) {
155             getMainPanel().getCurrentTreePanel().taxColor();
156         }
157         else if ( o == _confcolor_item ) {
158             getMainPanel().getCurrentTreePanel().confColor();
159         }
160         else if ( o == _collapse_species_specific_subtrees ) {
161             if ( getCurrentTreePanel() != null ) {
162                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
163             }
164         }
165         else if ( o == _remove_branch_color_item ) {
166             removeBranchColors();
167         }
168         else if ( o == _switch_colors_mi ) {
169             switchColors();
170         }
171         else if ( o == _display_basic_information_item ) {
172             displayBasicInformation();
173         }
174         else if ( o == _view_as_NH_item ) {
175             viewAsNH();
176         }
177         else if ( o == _view_as_XML_item ) {
178             viewAsXML();
179         }
180         else if ( o == _view_as_nexus_item ) {
181             viewAsNexus();
182         }
183         else if ( o == _super_tiny_fonts_mi ) {
184             if ( getCurrentTreePanel() != null ) {
185                 getCurrentTreePanel().setSuperTinyFonts();
186                 getCurrentTreePanel().repaint();
187             }
188         }
189         else if ( o == _tiny_fonts_mi ) {
190             if ( getCurrentTreePanel() != null ) {
191                 getCurrentTreePanel().setTinyFonts();
192                 getCurrentTreePanel().repaint();
193             }
194         }
195         else if ( o == _small_fonts_mi ) {
196             if ( getCurrentTreePanel() != null ) {
197                 getCurrentTreePanel().setSmallFonts();
198                 getCurrentTreePanel().repaint();
199             }
200         }
201         else if ( o == _medium_fonts_mi ) {
202             if ( getCurrentTreePanel() != null ) {
203                 getCurrentTreePanel().setMediumFonts();
204                 getCurrentTreePanel().repaint();
205             }
206         }
207         else if ( o == _large_fonts_mi ) {
208             if ( getCurrentTreePanel() != null ) {
209                 getCurrentTreePanel().setLargeFonts();
210                 getCurrentTreePanel().repaint();
211             }
212         }
213         else if ( o == _choose_font_mi ) {
214             chooseFont();
215         }
216         else if ( o == _choose_minimal_confidence_mi ) {
217             chooseMinimalConfidence();
218         }
219         else if ( o == _choose_node_size_mi ) {
220             MainFrame.chooseNodeSize( getOptions(), this );
221         }
222         else if ( o == _overview_placment_mi ) {
223             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
224         }
225         else if ( o == _cycle_node_fill_mi ) {
226             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
227         }
228         else if ( o == _cycle_node_shape_mi ) {
229             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
230         }
231         else if ( o == _non_lined_up_cladograms_rbmi ) {
232             updateOptions( getOptions() );
233             _mainpanel.getControlPanel().showWhole();
234         }
235         else if ( o == _uniform_cladograms_rbmi ) {
236             updateOptions( getOptions() );
237             _mainpanel.getControlPanel().showWhole();
238         }
239         else if ( o == _ext_node_dependent_cladogram_rbmi ) {
240             updateOptions( getOptions() );
241             _mainpanel.getControlPanel().showWhole();
242         }
243         else if ( o == _search_case_senstive_cbmi ) {
244             updateOptions( getOptions() );
245             getMainPanel().getControlPanel().search0();
246             getMainPanel().getControlPanel().search1();
247         }
248         else if ( o == _search_whole_words_only_cbmi ) {
249             updateOptions( getOptions() );
250             getMainPanel().getControlPanel().search0();
251             getMainPanel().getControlPanel().search1();
252         }
253         else if ( o == _inverse_search_result_cbmi ) {
254             updateOptions( getOptions() );
255             getMainPanel().getControlPanel().search0();
256             getMainPanel().getControlPanel().search1();
257         }
258         else if ( o == _show_scale_cbmi ) {
259             updateOptions( getOptions() );
260         }
261         else if ( o == _show_branch_length_values_cbmi ) {
262             updateOptions( getOptions() );
263         }
264         else if ( o == _show_confidence_stddev_cbmi ) {
265             updateOptions( getOptions() );
266         }
267         else if ( o == _label_direction_cbmi ) {
268             updateOptions( getOptions() );
269         }
270         else if ( o == _abbreviate_scientific_names ) {
271             updateOptions( getOptions() );
272         }
273         else if ( o == _show_overview_cbmi ) {
274             updateOptions( getOptions() );
275             if ( getCurrentTreePanel() != null ) {
276                 getCurrentTreePanel().updateOvSizes();
277             }
278         }
279         else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
280                 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
281                 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
282             typeChanged( o );
283         }
284         else if ( o == _screen_antialias_cbmi ) {
285             updateOptions( getOptions() );
286             setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
287         }
288         else if ( o == _background_gradient_cbmi ) {
289             updateOptions( getOptions() );
290         }
291         else if ( o == _show_domain_labels ) {
292             updateOptions( getOptions() );
293         }
294         else if ( o == _color_labels_same_as_parent_branch ) {
295             updateOptions( getOptions() );
296         }
297         else if ( o == _show_default_node_shapes_internal_cbmi ) {
298             updateOptions( getOptions() );
299         }
300         else if ( o == _show_default_node_shapes_external_cbmi ) {
301             updateOptions( getOptions() );
302         }
303         else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
304             updateOptions( getOptions() );
305         }
306         else if ( o == _about_item ) {
307             MainFrame.about();
308         }
309         else if ( o == _help_item ) {
310             help();
311         }
312         else if ( o == _website_item ) {
313             try {
314                 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
315             }
316             catch ( final IOException e1 ) {
317                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
318             }
319         }
320         else if ( o == _phyloxml_website_item ) {
321             try {
322                 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
323             }
324             catch ( final IOException e1 ) {
325                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
326             }
327         }
328         else if ( o == _aptx_ref_item ) {
329             try {
330                 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
331             }
332             catch ( final IOException e1 ) {
333                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
334             }
335         }
336         else if ( o == _phyloxml_ref_item ) {
337             try {
338                 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
339             }
340             catch ( final IOException e1 ) {
341                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
342             }
343         }
344         else if ( o == _color_by_taxonomic_group_cbmi ) {
345             updateOptions( getOptions() );
346         }
347         repaint();
348     }
349
350     @Override
351     public void destroy() {
352         AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
353         removeAllTextFrames();
354         if ( getMainPanel() != null ) {
355             getMainPanel().terminate();
356         }
357     }
358
359     /**
360      * This method returns the current external node data which
361      * has been selected by the user by clicking the "Return ..."
362      * menu item. This method is expected to be called from Javascript or
363      * something like it.
364      * 
365      * @return current external node data as String
366      */
367     public String getCurrentExternalNodesDataBuffer() {
368         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
369     }
370
371     public int getCurrentExternalNodesDataBufferChangeCounter() {
372         return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
373     }
374
375     public int getCurrentExternalNodesDataBufferLength() {
376         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
377     }
378
379     /**
380      * This method returns the current phylogeny as a string in the chosen format
381      * 
382      * @param format must be NH, NHX, NEXUS or PHYLOXML
383      * @return the phylogeny string
384      * @author Herve Menager
385      */
386     public String getCurrentPhylogeny( final String format ) {
387         removeAllTextFrames();
388         if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
389                 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
390             return new String();
391         }
392         switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
393             case NH:
394                 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
395             case NHX:
396                 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
397             case NEXUS:
398                 return getMainPanel().getCurrentPhylogeny().toNexus();
399             case PHYLOXML:
400                 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
401             default:
402                 break;
403         }
404         return new String();
405     }
406
407     /**
408      * This method returns a view of the current phylogeny in a chosen 
409      * graphics format, base64-encoded in a string so that in can be used
410      * from javascript.
411      * 
412      * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
413      * @return the phylogeny string
414      * @author Herve Menager
415      */
416     public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
417         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
418         try {
419             AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
420                                                                     _mainpanel.getWidth(),
421                                                                     _mainpanel.getHeight(),
422                                                                     getCurrentTreePanel(),
423                                                                     getCurrentTreePanel().getControlPanel(),
424                                                                     GraphicsExportType.valueOf( format ),
425                                                                     getOptions() );
426         }
427         catch ( final IOException ioe ) {
428             ForesterUtil.printErrorMessage( NAME, ioe.toString() );
429             ioe.printStackTrace();
430             JOptionPane.showMessageDialog( this,
431                                            NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
432                                            "Failed to generate graphics",
433                                            JOptionPane.ERROR_MESSAGE );
434             return null;
435         }
436         final byte[] bytes = baos.toByteArray();
437         final String dataImg = Base64.encodeBase64String( bytes );
438         return dataImg;
439     }
440
441     public Options getOptions() {
442         return _options;
443     }
444
445     @Override
446     public void init() {
447         final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
448         AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
449         final Configuration configuration = new Configuration( config_filename, true, true, true );
450         setConfiguration( configuration );
451         setOptions( Options.createInstance( configuration ) );
452         setupUI();
453         URL phys_url = null;
454         Phylogeny[] phys = null;
455         final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
456         AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
457         // Get URL to tree file
458         if ( tree_url_str != null ) {
459             try {
460                 phys_url = new URL( tree_url_str );
461             }
462             catch ( final Exception e ) {
463                 ForesterUtil.printErrorMessage( NAME, "error: " + e );
464                 e.printStackTrace();
465                 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
466                         + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
467             }
468         }
469         // Load the tree from URL
470         if ( phys_url != null ) {
471             try {
472                 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
473                                                         getConfiguration().isValidatePhyloXmlAgainstSchema(),
474                                                         getConfiguration().isReplaceUnderscoresInNhParsing(),
475                                                         getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
476                                                         getConfiguration().getTaxonomyExtraction(),
477                                                         getConfiguration().isMidpointReroot() );
478             }
479             catch ( final Exception e ) {
480                 ForesterUtil.printErrorMessage( NAME, e.toString() );
481                 e.printStackTrace();
482                 JOptionPane.showMessageDialog( this,
483                                                NAME + ": Failed to read phylogenies: " + "\nException: " + e,
484                                                "Failed to read phylogenies",
485                                                JOptionPane.ERROR_MESSAGE );
486             }
487         }
488         if ( ( phys == null ) || ( phys.length < 1 ) ) {
489             ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
490             JOptionPane.showMessageDialog( this,
491                                            NAME + ": phylogenies from [" + phys_url + "] are null or empty",
492                                            "Failed to read phylogenies",
493                                            JOptionPane.ERROR_MESSAGE );
494             return;
495         }
496         else {
497             AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
498         }
499         //
500         final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
501         if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
502             AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
503             Phylogeny[] species_trees = null;
504             try {
505                 final URL species_tree_url = new URL( species_tree_url_str );
506                 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
507                                                                  configuration.isValidatePhyloXmlAgainstSchema(),
508                                                                  configuration.isReplaceUnderscoresInNhParsing(),
509                                                                  false,
510                                                                  TAXONOMY_EXTRACTION.NO,
511                                                                  false );
512             }
513             catch ( final IOException e ) {
514                 ForesterUtil.printErrorMessage( NAME, "could not read species tree from  [" + species_tree_url_str
515                         + "]" );
516                 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from  ["
517                         + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
518             }
519             if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
520                 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
521                 if ( species_trees[ 0 ].isEmpty() ) {
522                     ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
523                 }
524                 else if ( !species_trees[ 0 ].isRooted() ) {
525                     ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
526                 }
527                 else {
528                     setSpeciesTree( species_trees[ 0 ] );
529                     AptxUtil.printAppletMessage( NAME, "species tree OK" );
530                 }
531             }
532         }
533         //
534         setVisible( false );
535         setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
536         _jmenubar = new JMenuBar();
537         if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
538             if ( !getConfiguration().isUseNativeUI() ) {
539                 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
540             }
541             if ( getSpeciesTree() != null ) {
542                 buildAnalysisMenu();
543             }
544             buildToolsMenu();
545             buildViewMenu();
546             buildFontSizeMenu();
547             buildOptionsMenu();
548             buildTypeMenu();
549             buildHelpMenu();
550             setJMenuBar( _jmenubar );
551         }
552         final Container contentpane = getContentPane();
553         contentpane.setLayout( new BorderLayout() );
554         contentpane.add( getMainPanel(), BorderLayout.CENTER );
555         addComponentListener( new ComponentAdapter() {
556
557             @Override
558             public void componentResized( final ComponentEvent e ) {
559                 if ( getMainPanel().getCurrentTreePanel() != null ) {
560                     getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
561                                                                                             .getCurrentTreePanel()
562                                                                                             .getWidth(),
563                                                                                     getMainPanel()
564                                                                                             .getCurrentTreePanel()
565                                                                                             .getHeight(),
566                                                                                     getOptions()
567                                                                                             .isAllowFontSizeChange() );
568                 }
569             }
570         } );
571         if ( getConfiguration().isUseTabbedDisplay() ) {
572             AptxUtil.printAppletMessage( NAME, "using tabbed display" );
573             AptxUtil.addPhylogeniesToTabs( phys,
574                                            new File( phys_url.getFile() ).getName(),
575                                            phys_url.toString(),
576                                            getConfiguration(),
577                                            getMainPanel() );
578         }
579         else {
580             AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
581             if ( getSpeciesTree() != null ) {
582                 AptxUtil.printAppletMessage( NAME,
583                                              "Warning: gsdi (gene duplication inference) only available tabbed display" );
584             }
585             AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
586         }
587         validate();
588         setName( NAME );
589         getMainPanel().getControlPanel().showWholeAll();
590         getMainPanel().getControlPanel().showWhole();
591         System.gc();
592         AptxUtil.printAppletMessage( NAME, "successfully initialized" );
593         /* GUILHEM_BEG */
594         getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
595         for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
596                 .getRelevantSequenceRelationTypes() ) {
597             getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
598         }
599         final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
600         if ( default_relation != null ) {
601             getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
602         }
603         final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
604         if ( default_sequence != null ) {
605             getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
606         }
607         /* GUILHEM_END */
608         setVisible( true );
609     }
610
611     public void showTextFrame( final String s, final String title ) {
612         checkTextFrames();
613         _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
614     }
615
616     @Override
617     public void start() {
618         if ( getMainPanel() != null ) {
619             getMainPanel().validate();
620         }
621         requestFocus();
622         requestFocusInWindow();
623         requestFocus();
624         AptxUtil.printAppletMessage( NAME, "started" );
625     }
626
627     void buildAnalysisMenu() {
628         _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
629         _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
630         _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
631         customizeJMenuItem( _gsdi_item );
632         customizeJMenuItem( _gsdir_item );
633         //  _analysis_menu.addSeparator();
634         //  _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
635         //  customizeJMenuItem( _lineage_inference );
636         //  _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
637         _jmenubar.add( _analysis_menu );
638     }
639
640     void buildFontSizeMenu() {
641         _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
642         _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
643         _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
644         _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
645         _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
646         _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
647         customizeJMenuItem( _super_tiny_fonts_mi );
648         customizeJMenuItem( _tiny_fonts_mi );
649         customizeJMenuItem( _small_fonts_mi );
650         customizeJMenuItem( _medium_fonts_mi );
651         customizeJMenuItem( _large_fonts_mi );
652         _jmenubar.add( _font_size_menu );
653     }
654
655     void buildHelpMenu() {
656         _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
657         _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
658         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
659         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
660         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
661         _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
662         _help_jmenu.addSeparator();
663         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
664         customizeJMenuItem( _help_item );
665         customizeJMenuItem( _website_item );
666         customizeJMenuItem( _phyloxml_website_item );
667         customizeJMenuItem( _aptx_ref_item );
668         customizeJMenuItem( _phyloxml_ref_item );
669         customizeJMenuItem( _about_item );
670         _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
671         _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
672         _jmenubar.add( _help_jmenu );
673     }
674
675     void buildOptionsMenu() {
676         _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
677         _options_jmenu.addChangeListener( new ChangeListener() {
678
679             @Override
680             public void stateChanged( final ChangeEvent e ) {
681                 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
682                 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
683                 MainFrame
684                         .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
685                 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
686                         .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
687                 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
688                                                                      _show_scale_cbmi,
689                                                                      _show_branch_length_values_cbmi,
690                                                                      _non_lined_up_cladograms_rbmi,
691                                                                      _uniform_cladograms_rbmi,
692                                                                      _ext_node_dependent_cladogram_rbmi,
693                                                                      _label_direction_cbmi );
694                 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
695                 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
696                 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
697             }
698         } );
699         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
700                                                                 getConfiguration() ) );
701         _options_jmenu
702                 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
703         _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
704         _options_jmenu
705                 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
706         _radio_group_1 = new ButtonGroup();
707         _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
708         _radio_group_1.add( _uniform_cladograms_rbmi );
709         _radio_group_1.add( _non_lined_up_cladograms_rbmi );
710         /////
711         _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
712         _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
713         _options_jmenu
714                 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
715         _options_jmenu
716                 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
717         _options_jmenu
718                 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
719         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
720             _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
721         }
722         _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
723         _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
724         _options_jmenu
725                 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
726         _options_jmenu
727                 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
728         _options_jmenu
729                 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
730         _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
731         _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
732         _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
733         _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
734         _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
735         _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
736         _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
737         _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
738         _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
739         _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
740         _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
741         _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
742         _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
743         /////
744         _options_jmenu.addSeparator();
745         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
746                                                                 getConfiguration() ) );
747         _options_jmenu
748                 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
749         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
750         _options_jmenu
751                 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
752         customizeJMenuItem( _choose_font_mi );
753         customizeJMenuItem( _choose_minimal_confidence_mi );
754         customizeJMenuItem( _switch_colors_mi );
755         customizeJMenuItem( _overview_placment_mi );
756         customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
757         customizeCheckBoxMenuItem( _label_direction_cbmi,
758                                    getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
759         customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
760         customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
761         customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
762         customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
763         customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
764         customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
765                 .isShowDefaultNodeShapesExternal() );
766         customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
767                 .isShowDefaultNodeShapesInternal() );
768         customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
769         customizeJMenuItem( _cycle_node_shape_mi );
770         customizeJMenuItem( _cycle_node_fill_mi );
771         customizeJMenuItem( _choose_node_size_mi );
772         customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
773         customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
774         customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
775         customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
776                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
777         customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
778                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
779         customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
780                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
781         customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
782         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
783         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
784         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
785         customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
786         _jmenubar.add( _options_jmenu );
787     }
788
789     void buildToolsMenu() {
790         _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
791         _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
792         customizeJMenuItem( _confcolor_item );
793         _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
794         customizeJMenuItem( _taxcolor_item );
795         _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
796         _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
797         customizeJMenuItem( _remove_branch_color_item );
798         _tools_menu.addSeparator();
799         _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
800         customizeJMenuItem( _midpoint_root_item );
801         _tools_menu.addSeparator();
802         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
803         customizeJMenuItem( _collapse_species_specific_subtrees );
804         _jmenubar.add( _tools_menu );
805     }
806
807     void buildTypeMenu() {
808         _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
809         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
810         _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
811         _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
812         _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
813         _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
814         _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
815         _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
816         _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
817         customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
818         customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
819         customizeCheckBoxMenuItem( _euro_type_cbmi, false );
820         customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
821         customizeCheckBoxMenuItem( _curved_type_cbmi, false );
822         customizeCheckBoxMenuItem( _convex_type_cbmi, false );
823         customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
824         customizeCheckBoxMenuItem( _circular_type_cbmi, false );
825         _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
826         _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
827         initializeTypeMenu( getOptions() );
828         _jmenubar.add( _type_menu );
829     }
830
831     void buildViewMenu() {
832         _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
833         _view_jmenu
834                 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
835         _view_jmenu.addSeparator();
836         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
837         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
838         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
839         customizeJMenuItem( _display_basic_information_item );
840         customizeJMenuItem( _view_as_NH_item );
841         customizeJMenuItem( _view_as_XML_item );
842         customizeJMenuItem( _view_as_nexus_item );
843         _jmenubar.add( _view_jmenu );
844     }
845
846     void checkTextFrames() {
847         if ( _textframes.size() > 5 ) {
848             try {
849                 if ( _textframes.getFirst() != null ) {
850                     _textframes.getFirst().removeMe();
851                 }
852                 else {
853                     _textframes.removeFirst();
854                 }
855             }
856             catch ( final NoSuchElementException e ) {
857                 // Ignore.
858             }
859         }
860     }
861
862     void clearCurrentExternalNodesDataBuffer() {
863         getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
864     }
865
866     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
867         if ( item != null ) {
868             item.setFont( MainFrame.menu_font );
869             if ( !getConfiguration().isUseNativeUI() ) {
870                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
871                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
872             }
873             item.setSelected( is_selected );
874             item.addActionListener( this );
875         }
876     }
877
878     void customizeJMenuItem( final JMenuItem jmi ) {
879         jmi.setFont( MainFrame.menu_font );
880         if ( !getConfiguration().isUseNativeUI() ) {
881             jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
882             jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
883         }
884         jmi.addActionListener( this );
885     }
886
887     void displayBasicInformation() {
888         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
889             String title = "Basic Information";
890             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
891                 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
892             }
893             showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
894         }
895     }
896
897     void executeGSDI() {
898         if ( !isOKforSDI( false, true ) ) {
899             return;
900         }
901         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
902             JOptionPane.showMessageDialog( this,
903                                            "Gene tree is not rooted.",
904                                            "Cannot execute GSDI",
905                                            JOptionPane.ERROR_MESSAGE );
906             return;
907         }
908         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
909         gene_tree.setAllNodesToNotCollapse();
910         gene_tree.recalculateNumberOfExternalDescendants( false );
911         GSDI gsdi = null;
912         final Phylogeny species_tree = _species_tree.copy();
913         try {
914             gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
915         }
916         catch ( final SDIException e ) {
917             JOptionPane.showMessageDialog( this,
918                                            e.getLocalizedMessage(),
919                                            "Error during GSDI",
920                                            JOptionPane.ERROR_MESSAGE );
921             return;
922         }
923         catch ( final Exception e ) {
924             AptxUtil.unexpectedException( e );
925             return;
926         }
927         gene_tree.setRerootable( false );
928         gene_tree.clearHashIdToNodeMap();
929         gene_tree.recalculateNumberOfExternalDescendants( true );
930         _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
931         getMainPanel().getControlPanel().setShowEvents( true );
932         showWhole();
933         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
934         _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
935         showWhole();
936         _mainpanel.getTabbedPane().setSelectedIndex( selected );
937         showWhole();
938         _mainpanel.getCurrentTreePanel().setEdited( true );
939         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
940         if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
941             JOptionPane.showMessageDialog( this,
942                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
943                                                    + "Potential duplications: "
944                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
945                                                    + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
946                                                    + "Stripped gene tree nodes: "
947                                                    + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
948                                                    + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
949                                                    + "Number of polytomies in species tree used: " + poly + "\n",
950                                            "GSDI successfully completed",
951                                            JOptionPane.WARNING_MESSAGE );
952         }
953         else {
954             JOptionPane.showMessageDialog( this,
955                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
956                                                    + "Potential duplications: "
957                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
958                                                    + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
959                                                    + "Stripped gene tree nodes: "
960                                                    + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
961                                                    + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
962                                                    + "Number of polytomies in species tree used: " + poly + "\n",
963                                            "GSDI successfully completed",
964                                            JOptionPane.INFORMATION_MESSAGE );
965         }
966     }
967
968     void executeGSDIR() {
969         if ( !isOKforSDI( false, false ) ) {
970             return;
971         }
972         final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
973         if ( ( p > 0 )
974                 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
975             JOptionPane.showMessageDialog( this,
976                                            "Gene tree is not completely binary",
977                                            "Cannot execute GSDI",
978                                            JOptionPane.ERROR_MESSAGE );
979             return;
980         }
981         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
982         gene_tree.setAllNodesToNotCollapse();
983         gene_tree.recalculateNumberOfExternalDescendants( false );
984         GSDIR gsdir = null;
985         final Phylogeny species_tree = _species_tree.copy();
986         try {
987             gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
988         }
989         catch ( final SDIException e ) {
990             JOptionPane.showMessageDialog( this,
991                                            e.getLocalizedMessage(),
992                                            "Error during GSDIR",
993                                            JOptionPane.ERROR_MESSAGE );
994             return;
995         }
996         catch ( final Exception e ) {
997             AptxUtil.unexpectedException( e );
998             return;
999         }
1000         final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1001         result_gene_tree.setRerootable( false );
1002         result_gene_tree.clearHashIdToNodeMap();
1003         result_gene_tree.recalculateNumberOfExternalDescendants( true );
1004         PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1005         _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1006         getMainPanel().getControlPanel().setShowEvents( true );
1007         showWhole();
1008         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1009         _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1010         showWhole();
1011         _mainpanel.getTabbedPane().setSelectedIndex( selected );
1012         showWhole();
1013         _mainpanel.getCurrentTreePanel().setEdited( true );
1014         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1015         if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1016             JOptionPane.showMessageDialog( this,
1017                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1018                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1019                                                    + "Stripped gene tree nodes: "
1020                                                    + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1021                                                    + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1022                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1023                                            "GSDIR successfully completed",
1024                                            JOptionPane.WARNING_MESSAGE );
1025         }
1026         else {
1027             JOptionPane.showMessageDialog( this,
1028                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1029                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1030                                                    + "Stripped gene tree nodes: "
1031                                                    + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1032                                                    + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1033                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1034                                            "GSDIR successfully completed",
1035                                            JOptionPane.INFORMATION_MESSAGE );
1036         }
1037     }
1038
1039     Configuration getConfiguration() {
1040         return _configuration;
1041     }
1042
1043     TreePanel getCurrentTreePanel() {
1044         return getMainPanel().getCurrentTreePanel();
1045     }
1046
1047     JCheckBoxMenuItem getlabelDirectionCbmi() {
1048         return _label_direction_cbmi;
1049     }
1050
1051     Options getOtions() {
1052         return _options;
1053     }
1054
1055     void help() {
1056         final StringBuilder sb = new StringBuilder();
1057         sb.append( "Display options\n" );
1058         sb.append( "-------------------\n" );
1059         sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1060         sb.append( "Clickable tree nodes\n" );
1061         sb.append( "--------------------\n" );
1062         sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1063         sb.append( "or by right clicking:\n" );
1064         sb.append( "o  Display Node Data -- display information for a node\n" );
1065         sb.append( "o  Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1066         sb.append( "o  Root/Reroot -- change tree root to clicked node\n" );
1067         sb.append( "o  Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1068         sb.append( "o  Swap Descendants -- switch descendant on either side of clicked node\n" );
1069         sb.append( "o  Colorize Subtree -- color a subtree\n" );
1070         sb.append( "o  Open Sequence Web -- launch a web browser to display sequence information\n" );
1071         sb.append( "o  Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1072         sb.append( "-  there may be additional choices depending on this particular setup\n\n" );
1073         sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1074         sb.append( "Zooming\n" );
1075         sb.append( "---------\n" );
1076         sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1077         sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1078         sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1079         sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1080         sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1081         sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1082         sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1083         sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1084         sb.append( "Quick tree manipulation:\n" );
1085         sb.append( "------------------------\n" );
1086         sb.append( "Order Subtrees -- order the tree by branch length\n" );
1087         sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1088         sb.append( "phyloXML\n" );
1089         sb.append( "-------------------\n" );
1090         sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1091         sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1092         sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1093         sb.append( "\n" );
1094         sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1095         sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1096         TextFrame.instantiate( sb.toString(), "Help", _textframes );
1097     }
1098
1099     void initializeTypeMenu( final Options options ) {
1100         setTypeMenuToAllUnselected();
1101         try {
1102             switch ( options.getPhylogenyGraphicsType() ) {
1103                 case CONVEX:
1104                     _convex_type_cbmi.setSelected( true );
1105                     break;
1106                 case CURVED:
1107                     _curved_type_cbmi.setSelected( true );
1108                     break;
1109                 case EURO_STYLE:
1110                     _euro_type_cbmi.setSelected( true );
1111                     break;
1112                 case ROUNDED:
1113                     _rounded_type_cbmi.setSelected( true );
1114                     break;
1115                 case TRIANGULAR:
1116                     _triangular_type_cbmi.setSelected( true );
1117                     break;
1118                 case UNROOTED:
1119                     _unrooted_type_cbmi.setSelected( true );
1120                     break;
1121                 case CIRCULAR:
1122                     _circular_type_cbmi.setSelected( true );
1123                     break;
1124                 default:
1125                     _rectangular_type_cbmi.setSelected( true );
1126                     break;
1127             }
1128         }
1129         catch ( final NullPointerException np ) {
1130             // In all likelihood, this is caused by menu-less display.
1131         }
1132     }
1133
1134     boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1135         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1136             return false;
1137         }
1138         else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1139             JOptionPane.showMessageDialog( this,
1140                                            "No species tree loaded",
1141                                            "Cannot execute GSDI",
1142                                            JOptionPane.ERROR_MESSAGE );
1143             return false;
1144         }
1145         else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1146             JOptionPane.showMessageDialog( this,
1147                                            "Species tree is not completely binary",
1148                                            "Cannot execute GSDI",
1149                                            JOptionPane.ERROR_MESSAGE );
1150             return false;
1151         }
1152         else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1153             JOptionPane.showMessageDialog( this,
1154                                            "Gene tree is not completely binary",
1155                                            "Cannot execute GSDI",
1156                                            JOptionPane.ERROR_MESSAGE );
1157             return false;
1158         }
1159         else {
1160             return true;
1161         }
1162     }
1163
1164     boolean isSubtreeDisplayed() {
1165         if ( getCurrentTreePanel() != null ) {
1166             if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1167                 JOptionPane
1168                         .showMessageDialog( this,
1169                                             "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1170                                             "Operation can not be exectuted on a sub-tree",
1171                                             JOptionPane.WARNING_MESSAGE );
1172                 return true;
1173             }
1174         }
1175         return false;
1176     }
1177
1178     void removeAllTextFrames() {
1179         for( final TextFrame tf : _textframes ) {
1180             if ( tf != null ) {
1181                 tf.close();
1182             }
1183         }
1184         _textframes.clear();
1185     }
1186
1187     void setConfiguration( final Configuration configuration ) {
1188         _configuration = configuration;
1189     }
1190
1191     void setOptions( final Options options ) {
1192         _options = options;
1193     }
1194
1195     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1196         setTypeMenuToAllUnselected();
1197         try {
1198             switch ( type ) {
1199                 case CIRCULAR:
1200                     _circular_type_cbmi.setSelected( true );
1201                     break;
1202                 case CONVEX:
1203                     _convex_type_cbmi.setSelected( true );
1204                     break;
1205                 case CURVED:
1206                     _curved_type_cbmi.setSelected( true );
1207                     break;
1208                 case EURO_STYLE:
1209                     _euro_type_cbmi.setSelected( true );
1210                     break;
1211                 case ROUNDED:
1212                     _rounded_type_cbmi.setSelected( true );
1213                     break;
1214                 case RECTANGULAR:
1215                     _rectangular_type_cbmi.setSelected( true );
1216                     break;
1217                 case TRIANGULAR:
1218                     _triangular_type_cbmi.setSelected( true );
1219                     break;
1220                 case UNROOTED:
1221                     _unrooted_type_cbmi.setSelected( true );
1222                     break;
1223                 default:
1224                     throw new IllegalArgumentException( "unknown type: " + type );
1225             }
1226         }
1227         catch ( final NullPointerException np ) {
1228             // In all likelihood, this is caused by menu-less display.
1229         }
1230     }
1231
1232     void setTypeMenuToAllUnselected() {
1233         if ( _convex_type_cbmi != null ) {
1234             _convex_type_cbmi.setSelected( false );
1235         }
1236         if ( _curved_type_cbmi != null ) {
1237             _curved_type_cbmi.setSelected( false );
1238         }
1239         if ( _euro_type_cbmi != null ) {
1240             _euro_type_cbmi.setSelected( false );
1241         }
1242         if ( _rounded_type_cbmi != null ) {
1243             _rounded_type_cbmi.setSelected( false );
1244         }
1245         if ( _triangular_type_cbmi != null ) {
1246             _triangular_type_cbmi.setSelected( false );
1247         }
1248         if ( _rectangular_type_cbmi != null ) {
1249             _rectangular_type_cbmi.setSelected( false );
1250         }
1251         if ( _unrooted_type_cbmi != null ) {
1252             _unrooted_type_cbmi.setSelected( false );
1253         }
1254         if ( _circular_type_cbmi != null ) {
1255             _circular_type_cbmi.setSelected( false );
1256         }
1257     }
1258
1259     void showWhole() {
1260         _mainpanel.getControlPanel().showWhole();
1261     }
1262
1263     void switchColors() {
1264         final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1265         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1266         csc.setVisible( true );
1267         getMainPanel().setTreeColorSet( colorset );
1268     }
1269
1270     void typeChanged( final Object o ) {
1271         updateTypeCheckboxes( getOptions(), o );
1272         updateOptions( getOptions() );
1273         if ( getCurrentTreePanel() != null ) {
1274             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1275             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1276             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1277                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1278                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1279                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1280                 getCurrentTreePanel().getControlPanel().showWhole();
1281             }
1282             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1283                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1284             }
1285             else {
1286                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1287             }
1288             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1289             MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1290         }
1291     }
1292
1293     void updateOptions( final Options options ) {
1294         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1295         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1296                 && _background_gradient_cbmi.isSelected() );
1297         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1298         options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1299                 && _show_annotation_ref_source.isSelected() );
1300         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1301                 && _abbreviate_scientific_names.isSelected() );
1302         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1303                 && _color_labels_same_as_parent_branch.isSelected() );
1304         options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1305                 && _show_default_node_shapes_internal_cbmi.isSelected() );
1306         options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1307                 && _show_default_node_shapes_external_cbmi.isSelected() );
1308         options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1309                 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1310         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1311             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1312         }
1313         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1314             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1315         }
1316         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1317             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1318         }
1319         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1320                 && _search_case_senstive_cbmi.isSelected() );
1321         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1322             options.setShowScale( _show_scale_cbmi.isSelected() );
1323         }
1324         if ( _label_direction_cbmi != null ) {
1325             if ( _label_direction_cbmi.isSelected() ) {
1326                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1327             }
1328             else {
1329                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1330             }
1331         }
1332         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1333         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1334                 && _show_confidence_stddev_cbmi.isSelected() );
1335         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1336             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1337         }
1338         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1339                 && _search_whole_words_only_cbmi.isSelected() );
1340         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1341                 && _inverse_search_result_cbmi.isSelected() );
1342         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1343             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1344         }
1345         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1346             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1347         }
1348         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1349             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1350         }
1351         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1352             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1353         }
1354         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1355             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1356         }
1357         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1358             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1359         }
1360         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1361             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1362         }
1363         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1364             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1365         }
1366         if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1367             options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1368         }
1369     }
1370
1371     void updateTypeCheckboxes( final Options options, final Object o ) {
1372         setTypeMenuToAllUnselected();
1373         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1374     }
1375
1376     void viewAsNexus() {
1377         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1378             String title = "Nexus";
1379             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1380                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1381             }
1382             showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1383                                    .getNhConversionSupportValueStyle() ),
1384                            title );
1385         }
1386     }
1387
1388     void viewAsNH() {
1389         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1390             String title = "New Hampshire";
1391             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1392                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1393             }
1394             showTextFrame( getMainPanel().getCurrentPhylogeny()
1395                                    .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1396                            title );
1397         }
1398     }
1399
1400     void viewAsXML() {
1401         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1402             String title = "phyloXML";
1403             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1404                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1405             }
1406             showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1407         }
1408     }
1409
1410     private void chooseFont() {
1411         final FontChooser fc = new FontChooser();
1412         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1413         fc.showDialog( this, "Select the Base Font" );
1414         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1415     }
1416
1417     private void chooseMinimalConfidence() {
1418         final String s = ( String ) JOptionPane
1419                 .showInputDialog( this,
1420                                   "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1421                                           + getOptions().getMinConfidenceValue() + "]\n",
1422                                   "Minimal Confidence Value",
1423                                   JOptionPane.QUESTION_MESSAGE,
1424                                   null,
1425                                   null,
1426                                   getOptions().getMinConfidenceValue() );
1427         if ( !ForesterUtil.isEmpty( s ) ) {
1428             boolean success = true;
1429             double m = 0.0;
1430             final String m_str = s.trim();
1431             if ( !ForesterUtil.isEmpty( m_str ) ) {
1432                 try {
1433                     m = Double.parseDouble( m_str );
1434                 }
1435                 catch ( final Exception ex ) {
1436                     success = false;
1437                 }
1438             }
1439             else {
1440                 success = false;
1441             }
1442             if ( success && ( m >= 0.0 ) ) {
1443                 getOptions().setMinConfidenceValue( m );
1444             }
1445         }
1446     }
1447
1448     private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1449         if ( item != null ) {
1450             item.setFont( MainFrame.menu_font );
1451             if ( !getConfiguration().isUseNativeUI() ) {
1452                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1453                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1454             }
1455             item.setSelected( is_selected );
1456             item.addActionListener( this );
1457         }
1458     }
1459
1460     private MainPanel getMainPanel() {
1461         return _mainpanel;
1462     }
1463
1464     private Phylogeny getSpeciesTree() {
1465         return _species_tree;
1466     }
1467
1468     private boolean isScreenAntialias() {
1469         return true;
1470     }
1471
1472     private void removeBranchColors() {
1473         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1474             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1475         }
1476     }
1477
1478     private void setMainPanel( final MainPanelApplets main_panel ) {
1479         _mainpanel = main_panel;
1480     }
1481
1482     private void setSpeciesTree( final Phylogeny species_tree ) {
1483         _species_tree = species_tree;
1484     }
1485
1486     private void setupUI() {
1487         try {
1488             if ( getConfiguration().isUseNativeUI() ) {
1489                 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1490             }
1491             else {
1492                 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1493             }
1494         }
1495         catch ( final UnsupportedLookAndFeelException e ) {
1496             AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1497         }
1498         catch ( final ClassNotFoundException e ) {
1499             AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1500         }
1501         catch ( final InstantiationException e ) {
1502             AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1503         }
1504         catch ( final IllegalAccessException e ) {
1505             AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1506         }
1507         catch ( final Exception e ) {
1508             AptxUtil.dieWithSystemError( e.toString() );
1509         }
1510     }
1511
1512     static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1513         for( final TreePanel tree_panel : treepanels ) {
1514             tree_panel.setTextAntialias();
1515         }
1516     }
1517 }