removed view as NHX
[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.Map;
17 import java.util.NoSuchElementException;
18
19 import javax.swing.ButtonGroup;
20 import javax.swing.JApplet;
21 import javax.swing.JCheckBoxMenuItem;
22 import javax.swing.JMenu;
23 import javax.swing.JMenuBar;
24 import javax.swing.JMenuItem;
25 import javax.swing.JOptionPane;
26 import javax.swing.JRadioButtonMenuItem;
27 import javax.swing.UIManager;
28 import javax.swing.UnsupportedLookAndFeelException;
29 import javax.swing.event.ChangeEvent;
30 import javax.swing.event.ChangeListener;
31
32 import org.apache.commons.codec.binary.Base64;
33 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
34 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
35 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
36 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.data.SequenceRelation;
39 import org.forester.util.ForesterConstants;
40 import org.forester.util.ForesterUtil;
41
42 // Use like this:
43 // <applet archive="forester.jar"
44 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
45 // codebase="http://www.myserver.org/path/to/forester"
46 // width="600"
47 // height="500"
48 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
49 // <param name="url_of_tree_to_load"
50 // value="http://www.myserver.org/examples/data/apaf.xml">
51 // <param name="config_file"
52 // value="http://www.myserver.org/examples/config/config_file.txt">
53 // </applet>
54 public class ArchaeopteryxE extends JApplet implements ActionListener {
55
56     private final static String         NAME             = "ArchaeopteryxE";
57     private static final long           serialVersionUID = -1220055577935759443L;
58     private Configuration               _configuration;
59     private MainPanelApplets            _main_panel;
60     private JMenuBar                    _jmenubar;
61     private JMenu                       _options_jmenu;
62     private JMenu                       _font_size_menu;
63     private JMenuItem                   _super_tiny_fonts_mi;
64     private JMenuItem                   _tiny_fonts_mi;
65     private JMenuItem                   _small_fonts_mi;
66     private JMenuItem                   _medium_fonts_mi;
67     private JMenuItem                   _large_fonts_mi;
68     private JMenu                       _tools_menu;
69     private JMenuItem                   _taxcolor_item;
70     private JMenuItem                   _confcolor_item;
71     private JMenuItem                   _midpoint_root_item;
72     private JMenu                       _view_jmenu;
73     private JMenuItem                   _view_as_XML_item;
74     private JMenuItem                   _view_as_NH_item;
75     private JMenuItem                   _view_as_nexus_item;
76     private JMenuItem                   _display_basic_information_item;
77     private JMenu                       _type_menu;
78     private JCheckBoxMenuItem           _rectangular_type_cbmi;
79     private JCheckBoxMenuItem           _triangular_type_cbmi;
80     private JCheckBoxMenuItem           _curved_type_cbmi;
81     private JCheckBoxMenuItem           _convex_type_cbmi;
82     private JCheckBoxMenuItem           _euro_type_cbmi;
83     private JCheckBoxMenuItem           _rounded_type_cbmi;
84     private JCheckBoxMenuItem           _unrooted_type_cbmi;
85     private JCheckBoxMenuItem           _circular_type_cbmi;
86     private JMenuItem                   _help_item;
87     private JMenuItem                   _about_item;
88     private JMenu                       _help_jmenu;
89     private JMenuItem                   _website_item;
90     private JMenuItem                   _phyloxml_website_item;
91     private JMenuItem                   _phyloxml_ref_item;
92     private JMenuItem                   _aptx_ref_item;
93     private JMenuItem                   _remove_branch_color_item;
94     private JCheckBoxMenuItem           _show_domain_labels;
95     private JCheckBoxMenuItem           _color_labels_same_as_parent_branch;
96     private JCheckBoxMenuItem           _abbreviate_scientific_names;
97     private JCheckBoxMenuItem           _screen_antialias_cbmi;
98     private JCheckBoxMenuItem           _background_gradient_cbmi;
99     private JRadioButtonMenuItem        _non_lined_up_cladograms_rbmi;
100     private JRadioButtonMenuItem        _uniform_cladograms_rbmi;
101     private JRadioButtonMenuItem        _ext_node_dependent_cladogram_rbmi;
102     private Options                     _options;
103     private JMenuItem                   _choose_font_mi;
104     private JMenuItem                   _switch_colors_mi;
105     JCheckBoxMenuItem                   _label_direction_cbmi;
106     private JCheckBoxMenuItem           _show_scale_cbmi;
107     private JCheckBoxMenuItem           _search_case_senstive_cbmi;
108     private JCheckBoxMenuItem           _search_whole_words_only_cbmi;
109     private JCheckBoxMenuItem           _inverse_search_result_cbmi;
110     private JCheckBoxMenuItem           _show_overview_cbmi;
111     private JMenuItem                   _choose_minimal_confidence_mi;
112     private JCheckBoxMenuItem           _show_branch_length_values_cbmi;
113     private JMenuItem                   _collapse_species_specific_subtrees;
114     private JMenuItem                   _overview_placment_mi;
115     private ButtonGroup                 _radio_group_1;
116     private JCheckBoxMenuItem           _show_default_node_shapes_cbmi;
117     private JMenuItem                   _cycle_node_shape_mi;
118     private JMenuItem                   _cycle_node_fill_mi;
119     private JMenuItem                   _choose_node_size_mi;
120     private JCheckBoxMenuItem           _taxonomy_colorize_node_shapes_cbmi;
121     private JCheckBoxMenuItem           _show_confidence_stddev_cbmi;
122     private final LinkedList<TextFrame> _textframes      = new LinkedList<TextFrame>();
123
124     // private String                      _ext_node_data_buffer                = "";
125     // private int                         _ext_node_data_buffer_change_counter = 0;
126     @Override
127     public void actionPerformed( final ActionEvent e ) {
128         final Object o = e.getSource();
129         if ( o == _midpoint_root_item ) {
130             getMainPanel().getCurrentTreePanel().midpointRoot();
131         }
132         else if ( o == _taxcolor_item ) {
133             getMainPanel().getCurrentTreePanel().taxColor();
134         }
135         else if ( o == _confcolor_item ) {
136             getMainPanel().getCurrentTreePanel().confColor();
137         }
138         else if ( o == _collapse_species_specific_subtrees ) {
139             if ( getCurrentTreePanel() != null ) {
140                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
141             }
142         }
143         else if ( o == _remove_branch_color_item ) {
144             removeBranchColors();
145         }
146         else if ( o == _switch_colors_mi ) {
147             switchColors();
148         }
149         else if ( o == _display_basic_information_item ) {
150             displayBasicInformation();
151         }
152         else if ( o == _view_as_NH_item ) {
153             viewAsNH();
154         }
155         else if ( o == _view_as_XML_item ) {
156             viewAsXML();
157         }
158         else if ( o == _view_as_nexus_item ) {
159             viewAsNexus();
160         }
161         else if ( o == _super_tiny_fonts_mi ) {
162             if ( getCurrentTreePanel() != null ) {
163                 getCurrentTreePanel().setSuperTinyFonts();
164                 getCurrentTreePanel().repaint();
165             }
166         }
167         else if ( o == _tiny_fonts_mi ) {
168             if ( getCurrentTreePanel() != null ) {
169                 getCurrentTreePanel().setTinyFonts();
170                 getCurrentTreePanel().repaint();
171             }
172         }
173         else if ( o == _small_fonts_mi ) {
174             if ( getCurrentTreePanel() != null ) {
175                 getCurrentTreePanel().setSmallFonts();
176                 getCurrentTreePanel().repaint();
177             }
178         }
179         else if ( o == _medium_fonts_mi ) {
180             if ( getCurrentTreePanel() != null ) {
181                 getCurrentTreePanel().setMediumFonts();
182                 getCurrentTreePanel().repaint();
183             }
184         }
185         else if ( o == _large_fonts_mi ) {
186             if ( getCurrentTreePanel() != null ) {
187                 getCurrentTreePanel().setLargeFonts();
188                 getCurrentTreePanel().repaint();
189             }
190         }
191         else if ( o == _choose_font_mi ) {
192             chooseFont();
193         }
194         else if ( o == _choose_minimal_confidence_mi ) {
195             chooseMinimalConfidence();
196         }
197         else if ( o == _choose_node_size_mi ) {
198             MainFrame.chooseNodeSize( getOptions(), this );
199         }
200         else if ( o == _overview_placment_mi ) {
201             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
202         }
203         else if ( o == _cycle_node_fill_mi ) {
204             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
205         }
206         else if ( o == _cycle_node_shape_mi ) {
207             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
208         }
209         else if ( o == _non_lined_up_cladograms_rbmi ) {
210             updateOptions( getOptions() );
211             _main_panel.getControlPanel().showWhole();
212         }
213         else if ( o == _uniform_cladograms_rbmi ) {
214             updateOptions( getOptions() );
215             _main_panel.getControlPanel().showWhole();
216         }
217         else if ( o == _ext_node_dependent_cladogram_rbmi ) {
218             updateOptions( getOptions() );
219             _main_panel.getControlPanel().showWhole();
220         }
221         else if ( o == _search_case_senstive_cbmi ) {
222             updateOptions( getOptions() );
223             getMainPanel().getControlPanel().search();
224         }
225         else if ( o == _search_whole_words_only_cbmi ) {
226             updateOptions( getOptions() );
227             getMainPanel().getControlPanel().search();
228         }
229         else if ( o == _inverse_search_result_cbmi ) {
230             updateOptions( getOptions() );
231             getMainPanel().getControlPanel().search();
232         }
233         else if ( o == _show_scale_cbmi ) {
234             updateOptions( getOptions() );
235         }
236         else if ( o == _show_branch_length_values_cbmi ) {
237             updateOptions( getOptions() );
238         }
239         else if ( o == _show_confidence_stddev_cbmi ) {
240             updateOptions( getOptions() );
241         }
242         else if ( o == _label_direction_cbmi ) {
243             updateOptions( getOptions() );
244         }
245         else if ( o == _show_overview_cbmi ) {
246             updateOptions( getOptions() );
247             if ( getCurrentTreePanel() != null ) {
248                 getCurrentTreePanel().updateOvSizes();
249             }
250         }
251         else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
252                 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
253                 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
254             typeChanged( o );
255         }
256         else if ( o == _screen_antialias_cbmi ) {
257             updateOptions( getOptions() );
258             setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
259         }
260         else if ( o == _background_gradient_cbmi ) {
261             updateOptions( getOptions() );
262         }
263         else if ( o == _show_domain_labels ) {
264             updateOptions( getOptions() );
265         }
266         else if ( o == _color_labels_same_as_parent_branch ) {
267             updateOptions( getOptions() );
268         }
269         else if ( o == _show_default_node_shapes_cbmi ) {
270             updateOptions( getOptions() );
271         }
272         else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
273             updateOptions( getOptions() );
274         }
275         else if ( o == _about_item ) {
276             MainFrame.about();
277         }
278         else if ( o == _help_item ) {
279             help( getConfiguration().getWebLinks() );
280         }
281         else if ( o == _website_item ) {
282             try {
283                 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
284             }
285             catch ( final IOException e1 ) {
286                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
287             }
288         }
289         else if ( o == _phyloxml_website_item ) {
290             try {
291                 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
292             }
293             catch ( final IOException e1 ) {
294                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
295             }
296         }
297         else if ( o == _aptx_ref_item ) {
298             try {
299                 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
300             }
301             catch ( final IOException e1 ) {
302                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
303             }
304         }
305         else if ( o == _phyloxml_ref_item ) {
306             try {
307                 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
308             }
309             catch ( final IOException e1 ) {
310                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
311             }
312         }
313         repaint();
314     }
315
316     @Override
317     public void destroy() {
318         AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
319         removeAllTextFrames();
320         if ( getMainPanel() != null ) {
321             getMainPanel().terminate();
322         }
323     }
324
325     /**
326      * This method returns the current external node data which
327      * has been selected by the user by clicking the "Return ..."
328      * menu item. This method is expected to be called from Javascript or
329      * something like it.
330      * 
331      * @return current external node data as String
332      */
333     public String getCurrentExternalNodesDataBuffer() {
334         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
335     }
336
337     public int getCurrentExternalNodesDataBufferChangeCounter() {
338         return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
339     }
340
341     public int getCurrentExternalNodesDataBufferLength() {
342         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
343     }
344
345     /**
346      * This method returns the current phylogeny as a string in the chosen format
347      * 
348      * @param format must be NH, NHX, NEXUS or PHYLOXML
349      * @return the phylogeny string
350      * @author Herve Menager
351      */
352     public String getCurrentPhylogeny( final String format ) {
353         removeAllTextFrames();
354         if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
355                 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
356             return new String();
357         }
358         switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
359             case NH:
360                 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
361             case NHX:
362                 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
363             case NEXUS:
364                 return getMainPanel().getCurrentPhylogeny().toNexus();
365             case PHYLOXML:
366                 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
367             default:
368                 break;
369         }
370         return new String();
371     }
372
373     /**
374      * This method returns a view of the current phylogeny in a chosen 
375      * graphics format, base64-encoded in a string so that in can be used
376      * from javascript.
377      * 
378      * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
379      * @return the phylogeny string
380      * @author Herve Menager
381      */
382     public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
383         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
384         try {
385             AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
386                                                                     _main_panel.getWidth(),
387                                                                     _main_panel.getHeight(),
388                                                                     getCurrentTreePanel(),
389                                                                     getCurrentTreePanel().getControlPanel(),
390                                                                     GraphicsExportType.valueOf( format ),
391                                                                     getOptions() );
392         }
393         catch ( final IOException ioe ) {
394             ForesterUtil.printErrorMessage( NAME, ioe.toString() );
395             ioe.printStackTrace();
396             JOptionPane.showMessageDialog( this,
397                                            NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
398                                            "Failed to generate graphics",
399                                            JOptionPane.ERROR_MESSAGE );
400             return null;
401         }
402         final byte[] bytes = baos.toByteArray();
403         final String dataImg = Base64.encodeBase64String( bytes );
404         return dataImg;
405     }
406
407     public Options getOptions() {
408         return _options;
409     }
410
411     @Override
412     public void init() {
413         final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
414         AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
415         final Configuration configuration = new Configuration( config_filename, true, true, true );
416         setConfiguration( configuration );
417         setOptions( Options.createInstance( configuration ) );
418         setupUI();
419         URL phys_url = null;
420         Phylogeny[] phys = null;
421         final String phys_url_string = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
422         AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + phys_url_string );
423         // Get URL to tree file
424         if ( phys_url_string != null ) {
425             try {
426                 phys_url = new URL( phys_url_string );
427             }
428             catch ( final Exception e ) {
429                 ForesterUtil.printErrorMessage( NAME, "error: " + e );
430                 e.printStackTrace();
431                 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + phys_url_string
432                         + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
433             }
434         }
435         // Load the tree from URL
436         if ( phys_url != null ) {
437             try {
438                 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
439                                                         getConfiguration().isValidatePhyloXmlAgainstSchema(),
440                                                         getConfiguration().isReplaceUnderscoresInNhParsing(),
441                                                         getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
442                                                         getConfiguration().getTaxonomyExtraction() );
443             }
444             catch ( final Exception e ) {
445                 ForesterUtil.printErrorMessage( NAME, e.toString() );
446                 e.printStackTrace();
447                 JOptionPane.showMessageDialog( this,
448                                                NAME + ": Failed to read phylogenies: " + "\nException: " + e,
449                                                "Failed to read phylogenies",
450                                                JOptionPane.ERROR_MESSAGE );
451             }
452         }
453         if ( ( phys == null ) || ( phys.length < 1 ) ) {
454             ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
455             JOptionPane.showMessageDialog( this,
456                                            NAME + ": phylogenies from [" + phys_url + "] are null or empty",
457                                            "Failed to read phylogenies",
458                                            JOptionPane.ERROR_MESSAGE );
459             return;
460         }
461         else {
462             AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
463         }
464         setVisible( false );
465         setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
466         _jmenubar = new JMenuBar();
467         if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
468             if ( !getConfiguration().isUseNativeUI() ) {
469                 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
470             }
471             buildToolsMenu();
472             buildViewMenu();
473             buildFontSizeMenu();
474             buildOptionsMenu();
475             buildTypeMenu();
476             buildHelpMenu();
477             setJMenuBar( _jmenubar );
478         }
479         final Container contentpane = getContentPane();
480         contentpane.setLayout( new BorderLayout() );
481         contentpane.add( getMainPanel(), BorderLayout.CENTER );
482         addComponentListener( new ComponentAdapter() {
483
484             @Override
485             public void componentResized( final ComponentEvent e ) {
486                 if ( getMainPanel().getCurrentTreePanel() != null ) {
487                     getMainPanel().getCurrentTreePanel().setParametersForPainting( getMainPanel().getCurrentTreePanel()
488                                                                                            .getWidth(),
489                                                                                    getMainPanel().getCurrentTreePanel()
490                                                                                            .getHeight(),
491                                                                                    false );
492                 }
493             }
494         } );
495         if ( getConfiguration().isUseTabbedDisplay() ) {
496             AptxUtil.printAppletMessage( NAME, "using tabbed display" );
497             AptxUtil.addPhylogeniesToTabs( phys,
498                                            new File( phys_url.getFile() ).getName(),
499                                            phys_url.toString(),
500                                            getConfiguration(),
501                                            getMainPanel() );
502         }
503         else {
504             AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
505             AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
506         }
507         validate();
508         setName( NAME );
509         getMainPanel().getControlPanel().showWholeAll();
510         getMainPanel().getControlPanel().showWhole();
511         System.gc();
512         AptxUtil.printAppletMessage( NAME, "successfully initialized" );
513         /* GUILHEM_BEG */
514         getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
515         for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
516                 .getRelevantSequenceRelationTypes() ) {
517             getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
518         }
519         final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
520         if ( default_relation != null ) {
521             getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
522         }
523         final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
524         if ( default_sequence != null ) {
525             getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
526             /* GUILHEM_END */
527         }
528         setVisible( true );
529     }
530
531     public void showTextFrame( final String s, final String title ) {
532         checkTextFrames();
533         _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
534     }
535
536     @Override
537     public void start() {
538         if ( getMainPanel() != null ) {
539             getMainPanel().validate();
540         }
541         requestFocus();
542         requestFocusInWindow();
543         requestFocus();
544         AptxUtil.printAppletMessage( NAME, "started" );
545     }
546
547     void buildFontSizeMenu() {
548         _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
549         _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
550         _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
551         _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
552         _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
553         _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
554         customizeJMenuItem( _super_tiny_fonts_mi );
555         customizeJMenuItem( _tiny_fonts_mi );
556         customizeJMenuItem( _small_fonts_mi );
557         customizeJMenuItem( _medium_fonts_mi );
558         customizeJMenuItem( _large_fonts_mi );
559         _jmenubar.add( _font_size_menu );
560     }
561
562     void buildHelpMenu() {
563         _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
564         _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
565         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
566         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
567         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
568         _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
569         _help_jmenu.addSeparator();
570         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
571         customizeJMenuItem( _help_item );
572         customizeJMenuItem( _website_item );
573         customizeJMenuItem( _phyloxml_website_item );
574         customizeJMenuItem( _aptx_ref_item );
575         customizeJMenuItem( _phyloxml_ref_item );
576         customizeJMenuItem( _about_item );
577         _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
578         _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
579         _jmenubar.add( _help_jmenu );
580     }
581
582     void buildOptionsMenu() {
583         _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
584         _options_jmenu.addChangeListener( new ChangeListener() {
585
586             @Override
587             public void stateChanged( final ChangeEvent e ) {
588                 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
589                 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
590                 MainFrame
591                         .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
592                 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
593                         .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
594                 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
595                                                                      _show_scale_cbmi,
596                                                                      _show_branch_length_values_cbmi,
597                                                                      _non_lined_up_cladograms_rbmi,
598                                                                      _uniform_cladograms_rbmi,
599                                                                      _ext_node_dependent_cladogram_rbmi,
600                                                                      _label_direction_cbmi );
601                 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
602                 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
603                 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
604             }
605         } );
606         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
607                                                                 getConfiguration() ) );
608         _options_jmenu
609                 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
610         _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
611         _options_jmenu
612                 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
613         _radio_group_1 = new ButtonGroup();
614         _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
615         _radio_group_1.add( _uniform_cladograms_rbmi );
616         _radio_group_1.add( _non_lined_up_cladograms_rbmi );
617         _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
618         _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
619         _options_jmenu
620                 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
621         _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
622         _options_jmenu
623                 .add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) );
624         _options_jmenu
625                 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
626         _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
627         _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
628         _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
629         _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
630         _options_jmenu
631                 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
632         _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
633         _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
634         _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
635         _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
636         _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
637         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
638             _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
639         }
640         _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
641         _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
642         _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
643         _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
644         _options_jmenu.addSeparator();
645         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
646                                                                 getConfiguration() ) );
647         _options_jmenu
648                 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
649         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
650         _options_jmenu
651                 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
652         customizeJMenuItem( _choose_font_mi );
653         customizeJMenuItem( _choose_minimal_confidence_mi );
654         customizeJMenuItem( _switch_colors_mi );
655         customizeJMenuItem( _overview_placment_mi );
656         customizeCheckBoxMenuItem( _label_direction_cbmi,
657                                    getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
658         customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
659         customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
660         customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
661         customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
662         customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
663         customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
664         customizeJMenuItem( _cycle_node_shape_mi );
665         customizeJMenuItem( _cycle_node_fill_mi );
666         customizeJMenuItem( _choose_node_size_mi );
667         customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
668         customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
669         customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
670         customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
671                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
672         customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
673                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
674         customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
675                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
676         customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
677         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
678         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
679         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
680         customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
681         _jmenubar.add( _options_jmenu );
682     }
683
684     void buildToolsMenu() {
685         _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
686         _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
687         customizeJMenuItem( _confcolor_item );
688         _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
689         customizeJMenuItem( _taxcolor_item );
690         _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
691         _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
692         customizeJMenuItem( _remove_branch_color_item );
693         _tools_menu.addSeparator();
694         _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
695         customizeJMenuItem( _midpoint_root_item );
696         _tools_menu.addSeparator();
697         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
698         customizeJMenuItem( _collapse_species_specific_subtrees );
699         _jmenubar.add( _tools_menu );
700     }
701
702     void buildTypeMenu() {
703         _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
704         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
705         _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
706         _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
707         _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
708         _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
709         _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
710         _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
711         _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
712         customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
713         customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
714         customizeCheckBoxMenuItem( _euro_type_cbmi, false );
715         customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
716         customizeCheckBoxMenuItem( _curved_type_cbmi, false );
717         customizeCheckBoxMenuItem( _convex_type_cbmi, false );
718         customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
719         customizeCheckBoxMenuItem( _circular_type_cbmi, false );
720         _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
721         _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
722         initializeTypeMenu( getOptions() );
723         _jmenubar.add( _type_menu );
724     }
725
726     void buildViewMenu() {
727         _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
728         _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
729         _view_jmenu.addSeparator();
730         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
731         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
732         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
733         customizeJMenuItem( _display_basic_information_item );
734         customizeJMenuItem( _view_as_NH_item );
735         customizeJMenuItem( _view_as_XML_item );
736         customizeJMenuItem( _view_as_nexus_item );
737         _jmenubar.add( _view_jmenu );
738     }
739
740     void checkTextFrames() {
741         if ( _textframes.size() > 5 ) {
742             try {
743                 if ( _textframes.getFirst() != null ) {
744                     _textframes.getFirst().removeMe();
745                 }
746                 else {
747                     _textframes.removeFirst();
748                 }
749             }
750             catch ( final NoSuchElementException e ) {
751                 // Ignore.
752             }
753         }
754     }
755
756     void clearCurrentExternalNodesDataBuffer() {
757         getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
758     }
759
760     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
761         if ( item != null ) {
762             item.setFont( MainFrame.menu_font );
763             if ( !getConfiguration().isUseNativeUI() ) {
764                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
765                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
766             }
767             item.setSelected( is_selected );
768             item.addActionListener( this );
769         }
770     }
771
772     void customizeJMenuItem( final JMenuItem jmi ) {
773         jmi.setFont( MainFrame.menu_font );
774         if ( !getConfiguration().isUseNativeUI() ) {
775             jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
776             jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
777         }
778         jmi.addActionListener( this );
779     }
780
781     void displayBasicInformation() {
782         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
783             String title = "Basic Information";
784             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
785                 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
786             }
787             showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny() ), title );
788         }
789     }
790
791     Configuration getConfiguration() {
792         return _configuration;
793     }
794
795     TreePanel getCurrentTreePanel() {
796         return getMainPanel().getCurrentTreePanel();
797     }
798
799     JCheckBoxMenuItem getlabelDirectionCbmi() {
800         return _label_direction_cbmi;
801     }
802
803     Options getOtions() {
804         return _options;
805     }
806
807     void help( final Map<String, WebLink> weblinks ) {
808         final StringBuilder sb = new StringBuilder();
809         sb.append( "Display options\n" );
810         sb.append( "-------------------\n" );
811         sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
812         sb.append( "Clickable tree nodes\n" );
813         sb.append( "--------------------\n" );
814         sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
815         sb.append( "or by right clicking:\n" );
816         sb.append( "o  Display Node Data -- display information for a node\n" );
817         sb.append( "o  Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
818         sb.append( "o  Root/Reroot -- change tree root to clicked node\n" );
819         sb.append( "o  Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
820         sb.append( "o  Swap Descendants -- switch descendant on either side of clicked node\n" );
821         sb.append( "o  Colorize Subtree -- color a subtree\n" );
822         sb.append( "o  Open Sequence Web -- launch a web browser to display sequence information\n" );
823         sb.append( "o  Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
824         sb.append( "-  there may be additional choices depending on this particular setup\n\n" );
825         sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
826         sb.append( "Zooming\n" );
827         sb.append( "---------\n" );
828         sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
829         sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
830         sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
831         sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
832         sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
833         sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
834         sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
835         sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
836         sb.append( "Quick tree manipulation:\n" );
837         sb.append( "------------------------\n" );
838         sb.append( "Order Subtrees -- order the tree by branch length\n" );
839         sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
840         sb.append( "Memory problems (Java heap space error)\n" );
841         sb.append( "---------------------------------------\n" );
842         sb.append( "Since the Java default memory allocation is quite small, it might by necessary (for trees\n" );
843         sb.append( "with more than approximately 5000 external nodes) to increase the memory which Java can use, with\n" );
844         sb.append( "the '-Xmx' Java command line option. For example:\n" );
845         sb.append( "java -Xms32m -Xmx256m -cp path\\to\\forester.jar org.forester.archaeopteryx.Archaeopteryx\n\n" );
846         if ( ( weblinks != null ) && ( weblinks.size() > 0 ) ) {
847             sb.append( "Active web links\n" );
848             sb.append( "--------------------\n" );
849             for( final String key : weblinks.keySet() ) {
850                 sb.append( " " + weblinks.get( key ).toString() + "\n" );
851             }
852         }
853         sb.append( "\n" );
854         sb.append( "phyloXML\n" );
855         sb.append( "-------------------\n" );
856         sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
857         sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
858         sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
859         sb.append( "\n" );
860         sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
861         sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
862         TextFrame.instantiate( sb.toString(), "Help", _textframes );
863     }
864
865     void initializeTypeMenu( final Options options ) {
866         setTypeMenuToAllUnselected();
867         try {
868             switch ( options.getPhylogenyGraphicsType() ) {
869                 case CONVEX:
870                     _convex_type_cbmi.setSelected( true );
871                     break;
872                 case CURVED:
873                     _curved_type_cbmi.setSelected( true );
874                     break;
875                 case EURO_STYLE:
876                     _euro_type_cbmi.setSelected( true );
877                     break;
878                 case ROUNDED:
879                     _rounded_type_cbmi.setSelected( true );
880                     break;
881                 case TRIANGULAR:
882                     _triangular_type_cbmi.setSelected( true );
883                     break;
884                 case UNROOTED:
885                     _unrooted_type_cbmi.setSelected( true );
886                     break;
887                 case CIRCULAR:
888                     _circular_type_cbmi.setSelected( true );
889                     break;
890                 default:
891                     _rectangular_type_cbmi.setSelected( true );
892                     break;
893             }
894         }
895         catch ( final NullPointerException np ) {
896             // In all likelihood, this is caused by menu-less display.
897         }
898     }
899
900     void removeAllTextFrames() {
901         for( final TextFrame tf : _textframes ) {
902             if ( tf != null ) {
903                 tf.close();
904             }
905         }
906         _textframes.clear();
907     }
908
909     void setConfiguration( final Configuration configuration ) {
910         _configuration = configuration;
911     }
912
913     void setOptions( final Options options ) {
914         _options = options;
915     }
916
917     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
918         setTypeMenuToAllUnselected();
919         try {
920             switch ( type ) {
921                 case CIRCULAR:
922                     _circular_type_cbmi.setSelected( true );
923                     break;
924                 case CONVEX:
925                     _convex_type_cbmi.setSelected( true );
926                     break;
927                 case CURVED:
928                     _curved_type_cbmi.setSelected( true );
929                     break;
930                 case EURO_STYLE:
931                     _euro_type_cbmi.setSelected( true );
932                     break;
933                 case ROUNDED:
934                     _rounded_type_cbmi.setSelected( true );
935                     break;
936                 case RECTANGULAR:
937                     _rectangular_type_cbmi.setSelected( true );
938                     break;
939                 case TRIANGULAR:
940                     _triangular_type_cbmi.setSelected( true );
941                     break;
942                 case UNROOTED:
943                     _unrooted_type_cbmi.setSelected( true );
944                     break;
945                 default:
946                     throw new IllegalArgumentException( "unknown type: " + type );
947             }
948         }
949         catch ( final NullPointerException np ) {
950             // In all likelihood, this is caused by menu-less display.
951         }
952     }
953
954     void setTypeMenuToAllUnselected() {
955         if ( _convex_type_cbmi != null ) {
956             _convex_type_cbmi.setSelected( false );
957         }
958         if ( _curved_type_cbmi != null ) {
959             _curved_type_cbmi.setSelected( false );
960         }
961         if ( _euro_type_cbmi != null ) {
962             _euro_type_cbmi.setSelected( false );
963         }
964         if ( _rounded_type_cbmi != null ) {
965             _rounded_type_cbmi.setSelected( false );
966         }
967         if ( _triangular_type_cbmi != null ) {
968             _triangular_type_cbmi.setSelected( false );
969         }
970         if ( _rectangular_type_cbmi != null ) {
971             _rectangular_type_cbmi.setSelected( false );
972         }
973         if ( _unrooted_type_cbmi != null ) {
974             _unrooted_type_cbmi.setSelected( false );
975         }
976         if ( _circular_type_cbmi != null ) {
977             _circular_type_cbmi.setSelected( false );
978         }
979     }
980
981     void switchColors() {
982         final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
983         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
984         csc.setVisible( true );
985         getMainPanel().setTreeColorSet( colorset );
986     }
987
988     void typeChanged( final Object o ) {
989         updateTypeCheckboxes( getOptions(), o );
990         updateOptions( getOptions() );
991         if ( getCurrentTreePanel() != null ) {
992             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
993             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
994             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
995                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
996                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
997                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
998                 getCurrentTreePanel().getControlPanel().showWhole();
999             }
1000             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1001                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1002             }
1003             else {
1004                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1005             }
1006             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1007             MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1008         }
1009     }
1010
1011     void updateOptions( final Options options ) {
1012         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1013         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1014                 && _background_gradient_cbmi.isSelected() );
1015         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1016         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1017                 && _abbreviate_scientific_names.isSelected() );
1018         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1019                 && _color_labels_same_as_parent_branch.isSelected() );
1020         options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null )
1021                 && _show_default_node_shapes_cbmi.isSelected() );
1022         options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1023                 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1024         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1025             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1026         }
1027         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1028             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1029         }
1030         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1031             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1032         }
1033         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1034                 && _search_case_senstive_cbmi.isSelected() );
1035         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1036             options.setShowScale( _show_scale_cbmi.isSelected() );
1037         }
1038         if ( _label_direction_cbmi != null ) {
1039             if ( _label_direction_cbmi.isSelected() ) {
1040                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1041             }
1042             else {
1043                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1044             }
1045         }
1046         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1047         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1048                 && _show_confidence_stddev_cbmi.isSelected() );
1049         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1050             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1051         }
1052         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1053                 && _search_whole_words_only_cbmi.isSelected() );
1054         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1055                 && _inverse_search_result_cbmi.isSelected() );
1056         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1057             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1058         }
1059         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1060             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1061         }
1062         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1063             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1064         }
1065         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1066             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1067         }
1068         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1069             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1070         }
1071         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1072             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1073         }
1074         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1075             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1076         }
1077         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1078             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1079         }
1080     }
1081
1082     void updateTypeCheckboxes( final Options options, final Object o ) {
1083         setTypeMenuToAllUnselected();
1084         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1085     }
1086
1087     void viewAsNexus() {
1088         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1089             String title = "Nexus";
1090             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1091                 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1092             }
1093             showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1094                                    .getNhConversionSupportValueStyle() ),
1095                            title );
1096         }
1097     }
1098
1099     void viewAsNH() {
1100         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1101             String title = "New Hampshire";
1102             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1103                 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1104             }
1105             showTextFrame( getMainPanel().getCurrentPhylogeny()
1106                                    .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1107                            title );
1108         }
1109     }
1110
1111     void viewAsXML() {
1112         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1113             String title = "phyloXML";
1114             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1115                 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1116             }
1117             showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1118         }
1119     }
1120
1121     private void chooseFont() {
1122         final FontChooser fc = new FontChooser();
1123         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1124         fc.showDialog( this, "Select the Base Font" );
1125         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1126     }
1127
1128     private void chooseMinimalConfidence() {
1129         final String s = ( String ) JOptionPane
1130                 .showInputDialog( this,
1131                                   "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1132                                           + getOptions().getMinConfidenceValue() + "]\n",
1133                                   "Minimal Confidence Value",
1134                                   JOptionPane.QUESTION_MESSAGE,
1135                                   null,
1136                                   null,
1137                                   getOptions().getMinConfidenceValue() );
1138         if ( !ForesterUtil.isEmpty( s ) ) {
1139             boolean success = true;
1140             double m = 0.0;
1141             final String m_str = s.trim();
1142             if ( !ForesterUtil.isEmpty( m_str ) ) {
1143                 try {
1144                     m = Double.parseDouble( m_str );
1145                 }
1146                 catch ( final Exception ex ) {
1147                     success = false;
1148                 }
1149             }
1150             else {
1151                 success = false;
1152             }
1153             if ( success && ( m >= 0.0 ) ) {
1154                 getOptions().setMinConfidenceValue( m );
1155             }
1156         }
1157     }
1158
1159     private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1160         if ( item != null ) {
1161             item.setFont( MainFrame.menu_font );
1162             if ( !getConfiguration().isUseNativeUI() ) {
1163                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1164                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1165             }
1166             item.setSelected( is_selected );
1167             item.addActionListener( this );
1168         }
1169     }
1170
1171     private MainPanel getMainPanel() {
1172         return _main_panel;
1173     }
1174
1175     private boolean isScreenAntialias() {
1176         return true;
1177     }
1178
1179     private void removeBranchColors() {
1180         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1181             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1182         }
1183     }
1184
1185     private void setMainPanel( final MainPanelApplets main_panel ) {
1186         _main_panel = main_panel;
1187     }
1188
1189     private void setupUI() {
1190         try {
1191             if ( getConfiguration().isUseNativeUI() ) {
1192                 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1193             }
1194             else {
1195                 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1196             }
1197         }
1198         catch ( final UnsupportedLookAndFeelException e ) {
1199             AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1200         }
1201         catch ( final ClassNotFoundException e ) {
1202             AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1203         }
1204         catch ( final InstantiationException e ) {
1205             AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1206         }
1207         catch ( final IllegalAccessException e ) {
1208             AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1209         }
1210         catch ( final Exception e ) {
1211             AptxUtil.dieWithSystemError( e.toString() );
1212         }
1213     }
1214
1215     static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1216         for( final TreePanel tree_panel : treepanels ) {
1217             tree_panel.setTextAntialias();
1218         }
1219     }
1220 }