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