2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2010 Christian M. Zmasek
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 // Contact: phylosoft @ gmail . com
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25 package org.forester.archaeopteryx;
27 import java.awt.Color;
28 import java.awt.Component;
29 import java.awt.Container;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33 import java.io.IOException;
34 import java.util.LinkedList;
35 import java.util.List;
36 import java.util.Locale;
38 import java.util.NoSuchElementException;
41 import javax.swing.Box;
42 import javax.swing.JApplet;
43 import javax.swing.JCheckBoxMenuItem;
44 import javax.swing.JFrame;
45 import javax.swing.JLabel;
46 import javax.swing.JMenu;
47 import javax.swing.JMenuBar;
48 import javax.swing.JMenuItem;
49 import javax.swing.JOptionPane;
50 import javax.swing.JPanel;
51 import javax.swing.JRadioButtonMenuItem;
52 import javax.swing.JTextField;
53 import javax.swing.SwingUtilities;
55 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
56 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
57 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
58 import org.forester.archaeopteryx.tools.InferenceManager;
59 import org.forester.archaeopteryx.tools.ProcessPool;
60 import org.forester.archaeopteryx.tools.ProcessRunning;
61 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
62 import org.forester.phylogeny.Phylogeny;
63 import org.forester.phylogeny.PhylogenyNode;
64 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
65 import org.forester.phylogeny.data.Annotation;
66 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
67 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
68 import org.forester.util.ForesterConstants;
69 import org.forester.util.ForesterUtil;
71 public abstract class MainFrame extends JFrame implements ActionListener {
73 static final String USE_MOUSEWHEEL_SHIFT_TO_ROTATE = "In this display type, use mousewheel + Shift to rotate [or A and S]";
74 static final String PHYLOXML_REF_TOOL_TIP = Constants.PHYLOXML_REFERENCE; //TODO //FIXME
75 static final String APTX_REF_TOOL_TIP = Constants.APTX_REFERENCE;
76 private static final long serialVersionUID = 3655000897845508358L;
77 final static Font menu_font = new Font( Configuration.getDefaultFontFamilyName(),
80 static final String TYPE_MENU_HEADER = "Type";
81 static final String RECTANGULAR_TYPE_CBMI_LABEL = "Rectangular";
82 static final String EURO_TYPE_CBMI_LABEL = "Euro Type";
83 static final String CURVED_TYPE_CBMI_LABEL = "Curved";
84 static final String TRIANGULAR_TYPE_CBMI_LABEL = "Triangular";
85 static final String CONVEX_TYPE_CBMI_LABEL = "Convex";
86 static final String ROUNDED_TYPE_CBMI_LABEL = "Rounded";
87 static final String UNROOTED_TYPE_CBMI_LABEL = "Unrooted (alpha)"; //TODO
88 static final String CIRCULAR_TYPE_CBMI_LABEL = "Circular (alpha)"; //TODO
89 static final String OPTIONS_HEADER = "Options";
90 static final String SEARCH_SUBHEADER = "Search:";
91 static final String DISPLAY_SUBHEADER = "Display:";
92 static final String SEARCH_TERMS_ONLY_LABEL = "Match Complete Terms Only";
93 static final String SEARCH_CASE_SENSITIVE_LABEL = "Case Sensitive";
94 static final String INVERSE_SEARCH_RESULT_LABEL = "Negate Result";
95 static final String DISPLAY_BRANCH_LENGTH_VALUES_LABEL = "Display Branch Length Values";
96 static final String DISPLAY_SCALE_LABEL = "Display Scale";
97 static final String NON_LINED_UP_CLADOGRAMS_LABEL = "Non-Lined Up Cladograms";
98 static final String UNIFORM_CLADOGRAMS_LABEL = "Total Node Sum Dependent Cladograms";
99 static final String LABEL_DIRECTION_LABEL = "Radial Labels";
100 static final String LABEL_DIRECTION_TIP = "To use radial node labels in radial and unrooted display types";
101 static final String SCREEN_ANTIALIAS_LABEL = "Antialias";
102 static final String COLOR_LABELS_LABEL = "Colorize Labels Same as Parent Branch";
103 static final String BG_GRAD_LABEL = "Background Color Gradient";
104 static final String DISPLAY_NODE_BOXES_LABEL_EXT = "Show External Node Shapes";
105 static final String DISPLAY_NODE_BOXES_LABEL_INT = "Show Internal Node Shapes";
106 static final String SHOW_OVERVIEW_LABEL = "Show Overview";
107 static final String FONT_SIZE_MENU_LABEL = "Font Size";
108 static final String NONUNIFORM_CLADOGRAMS_LABEL = "External Node Sum Dependent Cladograms";
109 static final String SHOW_DOMAIN_LABELS_LABEL = "Show Domain Labels";
110 static final String COLOR_LABELS_TIP = "To use parent branch colors for node labels as well, need to turn off taxonomy dependent colorization and turn on branch colorization for this to become apparent";
111 static final String ABBREV_SN_LABEL = "Abbreviate Scientific Taxonomic Names";
112 static final String TAXONOMY_COLORIZE_NODE_SHAPES_LABEL = "Colorize Node Shapes According to Taxonomy";
113 static final String CYCLE_NODE_SHAPE_LABEL = "Cycle Node Shapes";
114 static final String CYCLE_NODE_FILL_LABEL = "Cycle Node Fill Type";
115 static final String CHOOSE_NODE_SIZE_LABEL = "Choose Node Shape Size";
116 static final String SHOW_CONF_STDDEV_LABEL = "Show Confidence Standard Deviations";
117 static final String USE_BRACKETS_FOR_CONF_IN_NH_LABEL = "Use Brackets for Confidence Values";
118 static final String USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL = "Use Internal Node Names for Confidence Values";
123 JMenu _options_jmenu;
124 JMenu _font_size_menu;
126 JMenuItem[] _load_phylogeny_from_webservice_menu_items;
128 JMenu _analysis_menu;
129 JMenuItem _load_species_tree_item;
130 JMenuItem _gsdi_item;
131 JMenuItem _gsdir_item;
132 JMenuItem _lineage_inference;
133 JMenuItem _function_analysis;
135 JMenuItem _open_item;
136 JMenuItem _open_url_item;
137 JMenuItem _save_item;
138 JMenuItem _save_all_item;
139 JMenuItem _close_item;
140 JMenuItem _exit_item;
143 JMenuItem _midpoint_root_item;
144 JMenuItem _taxcolor_item;
145 JMenuItem _confcolor_item;
146 JMenuItem _color_rank_jmi;
147 JMenuItem _collapse_species_specific_subtrees;
148 JMenuItem _collapse_below_threshold; //TODO implememt me
149 JMenuItem _obtain_detailed_taxonomic_information_jmi;
150 JMenuItem _obtain_detailed_taxonomic_information_deleting_jmi;
151 JMenuItem _obtain_seq_information_jmi;
152 JMenuItem _move_node_names_to_tax_sn_jmi;
153 JMenuItem _move_node_names_to_seq_names_jmi;
154 JMenuItem _extract_tax_code_from_node_names_jmi;
155 JMenuItem _annotate_item;
157 JMenuItem _super_tiny_fonts_item;
158 JMenuItem _tiny_fonts_item;
159 JMenuItem _small_fonts_item;
160 JMenuItem _medium_fonts_item;
161 JMenuItem _large_fonts_item;
163 // _ screen and print
164 JMenuItem _choose_font_mi;
165 JMenuItem _switch_colors_mi;
166 JCheckBoxMenuItem _label_direction_cbmi;
168 JCheckBoxMenuItem _screen_antialias_cbmi;
169 JCheckBoxMenuItem _background_gradient_cbmi;
170 JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
171 JRadioButtonMenuItem _uniform_cladograms_rbmi;
172 JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
173 JCheckBoxMenuItem _show_branch_length_values_cbmi;
174 JCheckBoxMenuItem _show_scale_cbmi; //TODO fix me
175 JCheckBoxMenuItem _show_overview_cbmi;
176 JCheckBoxMenuItem _show_domain_labels;
177 JCheckBoxMenuItem _abbreviate_scientific_names;
178 JCheckBoxMenuItem _color_labels_same_as_parent_branch;
179 JMenuItem _overview_placment_mi;
180 JMenuItem _choose_minimal_confidence_mi;
181 JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
182 JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
183 JMenuItem _cycle_node_shape_mi;
184 JMenuItem _cycle_node_fill_mi;
185 JMenuItem _choose_node_size_mi;
186 JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
187 JCheckBoxMenuItem _show_confidence_stddev_cbmi;
189 JCheckBoxMenuItem _graphics_export_visible_only_cbmi;
190 JCheckBoxMenuItem _antialias_print_cbmi;
191 JCheckBoxMenuItem _print_black_and_white_cbmi;
192 JCheckBoxMenuItem _print_using_actual_size_cbmi;
193 JCheckBoxMenuItem _graphics_export_using_actual_size_cbmi;
194 JMenuItem _print_size_mi;
195 JMenuItem _choose_pdf_width_mi;
197 JCheckBoxMenuItem _internal_number_are_confidence_for_nh_parsing_cbmi;
198 JRadioButtonMenuItem _extract_taxonomy_no_rbmi;
199 JRadioButtonMenuItem _extract_taxonomy_yes_rbmi;
200 JRadioButtonMenuItem _extract_taxonomy_pfam_rbmi;
201 JCheckBoxMenuItem _replace_underscores_cbmi;
202 JCheckBoxMenuItem _use_brackets_for_conf_in_nh_export_cbmi;
203 JCheckBoxMenuItem _use_internal_names_for_conf_in_nh_export_cbmi;
205 JCheckBoxMenuItem _search_case_senstive_cbmi;
206 JCheckBoxMenuItem _search_whole_words_only_cbmi;
207 JCheckBoxMenuItem _inverse_search_result_cbmi;
210 JCheckBoxMenuItem _rectangular_type_cbmi;
211 JCheckBoxMenuItem _triangular_type_cbmi;
212 JCheckBoxMenuItem _curved_type_cbmi;
213 JCheckBoxMenuItem _convex_type_cbmi;
214 JCheckBoxMenuItem _euro_type_cbmi;
215 JCheckBoxMenuItem _rounded_type_cbmi;
216 JCheckBoxMenuItem _unrooted_type_cbmi;
217 JCheckBoxMenuItem _circular_type_cbmi;
218 // view as text menu:
219 JMenuItem _view_as_NH_item;
220 JMenuItem _view_as_XML_item;
221 JMenuItem _view_as_nexus_item;
222 JMenuItem _display_basic_information_item;
224 JMenuItem _about_item;
225 JMenuItem _help_item;
226 JMenuItem _website_item;
227 JMenuItem _phyloxml_website_item;
228 JMenuItem _phyloxml_ref_item;
229 JMenuItem _aptx_ref_item;
232 // Handy pointers to child components:
233 MainPanel _mainpanel;
234 Container _contentpane;
235 final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>(); ;
236 Configuration _configuration;
237 JMenuItem _remove_branch_color_item;
239 Phylogeny _species_tree;
240 InferenceManager _inference_manager;
241 final ProcessPool _process_pool;
242 private String _previous_node_annotation_ref;
245 _process_pool = ProcessPool.createInstance();
252 public void actionPerformed( final ActionEvent e ) {
253 final Object o = e.getSource();
254 boolean is_applet = false;
255 JApplet applet = null;
256 if ( getCurrentTreePanel() != null ) {
257 is_applet = getCurrentTreePanel().isApplet();
259 applet = getCurrentTreePanel().obtainApplet();
262 if ( o == _open_url_item ) {
263 readPhylogeniesFromURL();
265 else if ( o == _exit_item ) {
268 else if ( o == _taxcolor_item ) {
271 else if ( o == _confcolor_item ) {
274 else if ( o == _color_rank_jmi ) {
277 else if ( o == _collapse_species_specific_subtrees ) {
278 if ( isSubtreeDisplayed() ) {
281 if ( getCurrentTreePanel() != null ) {
282 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
285 else if ( o == _remove_branch_color_item ) {
286 if ( isSubtreeDisplayed() ) {
289 removeBranchColors();
291 else if ( o == _midpoint_root_item ) {
292 if ( isSubtreeDisplayed() ) {
297 else if ( o == _annotate_item ) {
300 else if ( o == _switch_colors_mi ) {
303 else if ( o == _display_basic_information_item ) {
304 displayBasicInformation();
306 else if ( o == _view_as_NH_item ) {
309 else if ( o == _view_as_XML_item ) {
312 else if ( o == _view_as_nexus_item ) {
315 else if ( o == _super_tiny_fonts_item ) {
316 if ( getCurrentTreePanel() != null ) {
317 getCurrentTreePanel().setSuperTinyFonts();
318 getCurrentTreePanel().repaint();
321 else if ( o == _tiny_fonts_item ) {
322 if ( getCurrentTreePanel() != null ) {
323 getCurrentTreePanel().setTinyFonts();
324 getCurrentTreePanel().repaint();
327 else if ( o == _small_fonts_item ) {
328 if ( getCurrentTreePanel() != null ) {
329 getCurrentTreePanel().setSmallFonts();
330 getCurrentTreePanel().repaint();
333 else if ( o == _medium_fonts_item ) {
334 if ( getCurrentTreePanel() != null ) {
335 getCurrentTreePanel().setMediumFonts();
336 getCurrentTreePanel().repaint();
339 else if ( o == _large_fonts_item ) {
340 if ( getCurrentTreePanel() != null ) {
341 getCurrentTreePanel().setLargeFonts();
342 getCurrentTreePanel().repaint();
345 else if ( o == _choose_font_mi ) {
348 else if ( o == _choose_minimal_confidence_mi ) {
349 chooseMinimalConfidence();
351 else if ( o == _choose_node_size_mi ) {
352 chooseNodeSize( getOptions(), this );
354 else if ( o == _overview_placment_mi ) {
355 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
357 else if ( o == _cycle_node_fill_mi ) {
358 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
360 else if ( o == _cycle_node_shape_mi ) {
361 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
363 else if ( o == _screen_antialias_cbmi ) {
364 updateOptions( getOptions() );
365 updateScreenTextAntialias( getMainPanel().getTreePanels() );
367 else if ( o == _background_gradient_cbmi ) {
368 updateOptions( getOptions() );
370 else if ( o == _show_domain_labels ) {
371 updateOptions( getOptions() );
373 else if ( o == _abbreviate_scientific_names ) {
374 updateOptions( getOptions() );
376 else if ( o == _color_labels_same_as_parent_branch ) {
377 updateOptions( getOptions() );
379 else if ( o == _show_default_node_shapes_internal_cbmi ) {
380 updateOptions( getOptions() );
382 else if ( o == _show_default_node_shapes_external_cbmi ) {
383 updateOptions( getOptions() );
385 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
386 updateOptions( getOptions() );
388 else if ( o == _non_lined_up_cladograms_rbmi ) {
389 updateOptions( getOptions() );
392 else if ( o == _uniform_cladograms_rbmi ) {
393 updateOptions( getOptions() );
396 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
397 updateOptions( getOptions() );
400 else if ( o == _search_case_senstive_cbmi ) {
401 updateOptions( getOptions() );
402 getMainPanel().getControlPanel().search();
404 else if ( o == _search_whole_words_only_cbmi ) {
405 updateOptions( getOptions() );
406 getMainPanel().getControlPanel().search();
408 else if ( o == _inverse_search_result_cbmi ) {
409 updateOptions( getOptions() );
410 getMainPanel().getControlPanel().search();
412 else if ( o == _show_scale_cbmi ) {
413 updateOptions( getOptions() );
415 else if ( o == _show_branch_length_values_cbmi ) {
416 updateOptions( getOptions() );
418 else if ( o == _show_confidence_stddev_cbmi ) {
419 updateOptions( getOptions() );
421 else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
422 if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
423 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
425 updateOptions( getOptions() );
427 else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
428 if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
429 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
431 updateOptions( getOptions() );
433 else if ( o == _label_direction_cbmi ) {
434 updateOptions( getOptions() );
436 else if ( o == _show_overview_cbmi ) {
437 updateOptions( getOptions() );
438 if ( getCurrentTreePanel() != null ) {
439 getCurrentTreePanel().updateOvSizes();
442 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
443 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
444 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
447 else if ( o == _about_item ) {
450 else if ( o == _help_item ) {
451 help( getConfiguration().getWebLinks() );
453 else if ( o == _website_item ) {
455 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, is_applet, applet );
457 catch ( final IOException e1 ) {
458 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
461 else if ( o == _phyloxml_website_item ) {
463 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, is_applet, applet );
465 catch ( final IOException e1 ) {
466 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
469 else if ( o == _aptx_ref_item ) {
471 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, is_applet, applet );
473 catch ( final IOException e1 ) {
474 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
477 else if ( o == _phyloxml_ref_item ) {
479 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, is_applet, applet );
481 catch ( final IOException e1 ) {
482 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
486 if ( _load_phylogeny_from_webservice_menu_items != null ) {
487 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
488 if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
489 readPhylogeniesFromWebservice( i );
494 _contentpane.repaint();
497 public Configuration getConfiguration() {
498 return _configuration;
502 * This method returns the current external node data which
503 * has been selected by the user by clicking the "Return ..."
504 * menu item. This method is expected to be called from Javascript or
507 * @return current external node data as String
509 public String getCurrentExternalNodesDataBuffer() {
510 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
513 public int getCurrentExternalNodesDataBufferChangeCounter() {
514 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
517 public int getCurrentExternalNodesDataBufferLength() {
518 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
521 public InferenceManager getInferenceManager() {
522 return _inference_manager;
525 public MainPanel getMainPanel() {
529 public Options getOptions() {
533 public ProcessPool getProcessPool() {
534 return _process_pool;
537 public void showTextFrame( final String s, final String title ) {
539 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
542 public void showWhole() {
543 _mainpanel.getControlPanel().showWhole();
546 public void updateProcessMenu() {
547 // In general Swing is not thread safe.
548 // See "Swing's Threading Policy".
549 SwingUtilities.invokeLater( new Runnable() {
553 doUpdateProcessMenu();
558 void activateSaveAllIfNeeded() {
559 if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
560 _save_all_item.setEnabled( true );
563 _save_all_item.setEnabled( false );
567 void buildFileMenu() {
568 _file_jmenu = createMenu( "File", getConfiguration() );
569 _file_jmenu.add( _open_url_item = new JMenuItem( "Read tree from URL/webservice..." ) );
570 _file_jmenu.addSeparator();
571 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
572 customizeJMenuItem( _open_url_item );
573 customizeJMenuItem( _exit_item );
574 _jmenubar.add( _file_jmenu );
577 void buildFontSizeMenu() {
578 _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
579 _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
580 _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
581 _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
582 _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
583 _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
584 customizeJMenuItem( _super_tiny_fonts_item );
585 customizeJMenuItem( _tiny_fonts_item );
586 customizeJMenuItem( _small_fonts_item );
587 customizeJMenuItem( _medium_fonts_item );
588 customizeJMenuItem( _large_fonts_item );
589 _jmenubar.add( _font_size_menu );
592 void buildHelpMenu() {
593 _help_jmenu = createMenu( "Help", getConfiguration() );
594 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
595 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
596 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
597 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
598 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
599 _help_jmenu.addSeparator();
600 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
601 customizeJMenuItem( _help_item );
602 customizeJMenuItem( _website_item );
603 customizeJMenuItem( _phyloxml_website_item );
604 customizeJMenuItem( _aptx_ref_item );
605 customizeJMenuItem( _phyloxml_ref_item );
606 customizeJMenuItem( _about_item );
607 _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
608 _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
609 _jmenubar.add( _help_jmenu );
612 void buildTypeMenu() {
613 _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
614 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
615 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
616 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
617 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
618 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
619 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
620 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
621 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
622 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
623 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
624 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
625 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
626 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
627 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
628 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
629 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
630 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
631 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
632 initializeTypeMenu( getOptions() );
633 _jmenubar.add( _type_menu );
636 void buildViewMenu() {
637 _view_jmenu = createMenu( "View", getConfiguration() );
638 _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
639 _view_jmenu.addSeparator();
640 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
641 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
642 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
643 customizeJMenuItem( _display_basic_information_item );
644 customizeJMenuItem( _view_as_NH_item );
645 customizeJMenuItem( _view_as_XML_item );
646 customizeJMenuItem( _view_as_nexus_item );
647 _jmenubar.add( _view_jmenu );
650 void checkTextFrames() {
651 if ( _textframes.size() > 5 ) {
653 if ( _textframes.getFirst() != null ) {
654 _textframes.getFirst().removeMe();
657 _textframes.removeFirst();
660 catch ( final NoSuchElementException e ) {
667 removeAllTextFrames();
668 if ( _mainpanel != null ) {
669 _mainpanel.terminate();
671 if ( _contentpane != null ) {
672 _contentpane.removeAll();
679 if ( _mainpanel.getCurrentTreePanel() != null ) {
680 final String[] ranks = AptxUtil.getAllPossibleRanks();
681 final String rank = ( String ) JOptionPane
682 .showInputDialog( this,
683 "What rank should the colorization be based on",
685 JOptionPane.QUESTION_MESSAGE,
689 if ( !ForesterUtil.isEmpty( rank ) ) {
690 _mainpanel.getCurrentTreePanel().colorRank( rank );
696 if ( _mainpanel.getCurrentTreePanel() != null ) {
697 _mainpanel.getCurrentTreePanel().confColor();
701 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
702 if ( item != null ) {
703 item.setFont( MainFrame.menu_font );
704 if ( !getConfiguration().isUseNativeUI() ) {
705 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
706 item.setForeground( getConfiguration().getGuiMenuTextColor() );
708 item.setSelected( is_selected );
709 item.addActionListener( this );
713 JMenuItem customizeJMenuItem( final JMenuItem jmi ) {
715 jmi.setFont( MainFrame.menu_font );
716 if ( !getConfiguration().isUseNativeUI() ) {
717 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
718 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
720 jmi.addActionListener( this );
725 void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
726 if ( item != null ) {
727 item.setFont( MainFrame.menu_font );
728 if ( !getConfiguration().isUseNativeUI() ) {
729 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
730 item.setForeground( getConfiguration().getGuiMenuTextColor() );
732 item.setSelected( is_selected );
733 item.addActionListener( this );
737 void displayBasicInformation() {
738 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
739 String title = "Basic Information";
740 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
741 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
743 showTextFrame( AptxUtil.createBasicInformation( _mainpanel.getCurrentPhylogeny() ), title );
747 void exceptionOccuredDuringOpenFile( final Exception e ) {
749 _mainpanel.getCurrentTreePanel().setArrowCursor();
751 catch ( final Exception ex ) {
754 JOptionPane.showMessageDialog( this,
755 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
756 "Error during File|Open",
757 JOptionPane.ERROR_MESSAGE );
760 void exceptionOccuredDuringSaveAs( final Exception e ) {
762 _mainpanel.getCurrentTreePanel().setArrowCursor();
764 catch ( final Exception ex ) {
767 JOptionPane.showMessageDialog( this, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );
770 boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
771 if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
772 JOptionPane.showMessageDialog( this,
773 "Gene tree and species tree have no species in common.",
775 JOptionPane.ERROR_MESSAGE );
778 else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
779 JOptionPane.showMessageDialog( this,
780 "Gene tree and species tree have only one species in common.",
782 JOptionPane.ERROR_MESSAGE );
790 TreePanel getCurrentTreePanel() {
791 return getMainPanel().getCurrentTreePanel();
794 JMenu getHelpMenu() {
798 JCheckBoxMenuItem getlabelDirectionCbmi() {
799 return _label_direction_cbmi;
802 JMenuBar getMenuBarOfMainFrame() {
806 void help( final Map<String, WebLink> weblinks ) {
807 final StringBuilder sb = new StringBuilder();
808 sb.append( "Display options\n" );
809 sb.append( "-------------------\n" );
810 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
811 sb.append( "Clickable tree nodes\n" );
812 sb.append( "--------------------\n" );
813 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
814 sb.append( "or by right clicking:\n" );
815 sb.append( "o Display Node Data -- display information for a node\n" );
816 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
817 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
818 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
819 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
820 sb.append( "o Colorize Subtree -- color a subtree\n" );
821 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
822 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
823 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
824 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
825 sb.append( "Zooming\n" );
826 sb.append( "---------\n" );
827 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
828 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
829 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
830 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
831 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
832 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
833 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
834 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
835 sb.append( "Quick tree manipulation:\n" );
836 sb.append( "------------------------\n" );
837 sb.append( "Order Subtrees -- order the tree by branch length\n" );
838 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
839 sb.append( "Memory problems (Java heap space error)\n" );
840 sb.append( "---------------------------------------\n" );
841 sb.append( "Since the Java default memory allocation is quite small, it might by necessary (for trees\n" );
842 sb.append( "with more than approximately 5000 external nodes) to increase the memory which Java can use, with\n" );
843 sb.append( "the '-Xmx' Java command line option. For example:\n" );
844 sb.append( "java -Xms32m -Xmx256m -cp path\\to\\forester.jar org.forester.archaeopteryx.Archaeopteryx\n\n" );
845 if ( ( weblinks != null ) && ( weblinks.size() > 0 ) ) {
846 sb.append( "Active web links\n" );
847 sb.append( "--------------------\n" );
848 for( final String key : weblinks.keySet() ) {
849 sb.append( " " + weblinks.get( key ).toString() + "\n" );
852 // + "General remarks\n"
853 // + "---------------\n"
855 // "o The application version permits copying to the clipboard \n"
857 // " in the \"View\"|\"View as ...\" frame (either by control-c or button press).\n"
859 // "o Changes made to a subtree affect this subtree and its subtrees,\n"
860 // + " but not any of its parent tree(s).\n"
862 // "o Archaeopteryx tries to detect whether the numerical values in a NH tree\n"
864 // " are likely to be bootstrap values instead of branch length values.\n\n"
866 // " Remarks regarding SDI (Speciation Duplication Inference):\n"
868 // "o Each external node of the gene tree (in display) needs to be associated with\n"
870 // " a species: either directly through the \"Species\" field, or the species\n"
872 // " is part of the sequence name in the form \"XXXX_SPECIES\"\n"
874 // " (e.g. \"ACON_DROME\" or \"ACON_DROME/123-4489\" which is also acceptable).\n"
876 // "o A species tree for each species of the gene tree needs to be loaded with\n"
878 // " \"SDI\"|\"Load species tree\" prior the SDI execution.\n"
880 // "o !External nodes of the gene tree associated with species not present in\n"
882 // " the species tree are REMOVED prior to SDI execution!\n"
884 // "o Both the gene tree and the species tree must be completely binary.\n"
886 // "o Duplications and speciations are a function of the position of the root.\n"
888 // " Hence, after each manual \"Root/Reroot\"ing some duplications will be\n"
889 // + " incorrect and need to be inferred again\n"
891 // " with: \"SDI\"|\"SDI (Speciation Duplication Inference)\n\n"
893 sb.append( "phyloXML\n" );
894 sb.append( "-------------------\n" );
895 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
896 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
897 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
899 sb.append( "For more information: https://sites.google.com/site/cmzmasek/home/software/archaeopteryx\n" );
900 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
901 TextFrame.instantiate( sb.toString(), "Help", _textframes );
904 void initializeTypeMenu( final Options options ) {
905 setTypeMenuToAllUnselected();
906 switch ( options.getPhylogenyGraphicsType() ) {
908 _convex_type_cbmi.setSelected( true );
911 _curved_type_cbmi.setSelected( true );
914 _euro_type_cbmi.setSelected( true );
917 _rounded_type_cbmi.setSelected( true );
920 _triangular_type_cbmi.setSelected( true );
923 _unrooted_type_cbmi.setSelected( true );
926 _circular_type_cbmi.setSelected( true );
929 _rectangular_type_cbmi.setSelected( true );
934 boolean isSubtreeDisplayed() {
935 if ( getCurrentTreePanel() != null ) {
936 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
938 .showMessageDialog( this,
939 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
940 "Operation can not be exectuted on a sub-tree",
941 JOptionPane.WARNING_MESSAGE );
948 void midpointRoot() {
949 if ( _mainpanel.getCurrentTreePanel() != null ) {
950 _mainpanel.getCurrentTreePanel().midpointRoot();
954 abstract void readPhylogeniesFromURL();
956 void readPhylogeniesFromWebservice( final int i ) {
957 final UrlTreeReader reader = new UrlTreeReader( this, i );
958 new Thread( reader ).start();
961 void removeAllTextFrames() {
962 for( final TextFrame tf : _textframes ) {
970 void setConfiguration( final Configuration configuration ) {
971 _configuration = configuration;
974 void setInferenceManager( final InferenceManager i ) {
975 _inference_manager = i;
978 void setOptions( final Options options ) {
982 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
983 setTypeMenuToAllUnselected();
986 _circular_type_cbmi.setSelected( true );
989 _convex_type_cbmi.setSelected( true );
992 _curved_type_cbmi.setSelected( true );
995 _euro_type_cbmi.setSelected( true );
998 _rounded_type_cbmi.setSelected( true );
1001 _rectangular_type_cbmi.setSelected( true );
1004 _triangular_type_cbmi.setSelected( true );
1007 _unrooted_type_cbmi.setSelected( true );
1010 throw new IllegalArgumentException( "unknown type: " + type );
1014 void setTypeMenuToAllUnselected() {
1015 _convex_type_cbmi.setSelected( false );
1016 _curved_type_cbmi.setSelected( false );
1017 _euro_type_cbmi.setSelected( false );
1018 _rounded_type_cbmi.setSelected( false );
1019 _triangular_type_cbmi.setSelected( false );
1020 _rectangular_type_cbmi.setSelected( false );
1021 _unrooted_type_cbmi.setSelected( false );
1022 _circular_type_cbmi.setSelected( false );
1025 void switchColors() {
1026 final TreeColorSet colorset = _mainpanel.getTreeColorSet();
1027 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1028 csc.setVisible( true );
1032 if ( _mainpanel.getCurrentTreePanel() != null ) {
1033 _mainpanel.getCurrentTreePanel().taxColor();
1037 void typeChanged( final Object o ) {
1038 updateTypeCheckboxes( getOptions(), o );
1039 updateOptions( getOptions() );
1040 if ( getCurrentTreePanel() != null ) {
1041 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1042 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1043 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1044 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1045 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1046 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1047 getCurrentTreePanel().getControlPanel().showWhole();
1049 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1050 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1053 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1055 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1056 updateScreenTextAntialias( getMainPanel().getTreePanels() );
1057 if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
1058 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1059 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
1062 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
1068 void updateOptions( final Options options ) {
1069 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1070 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1071 && _background_gradient_cbmi.isSelected() );
1072 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1073 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1074 && _abbreviate_scientific_names.isSelected() );
1075 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1076 && _color_labels_same_as_parent_branch.isSelected() );
1077 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1078 && _show_default_node_shapes_internal_cbmi.isSelected() );
1079 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1080 && _show_default_node_shapes_external_cbmi.isSelected() );
1081 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1082 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1083 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1084 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1086 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1087 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1089 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1090 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1092 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1093 && _search_case_senstive_cbmi.isSelected() );
1094 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1095 options.setShowScale( _show_scale_cbmi.isSelected() );
1097 if ( _label_direction_cbmi != null ) {
1098 if ( _label_direction_cbmi.isSelected() ) {
1099 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1102 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1105 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1106 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1107 && _show_confidence_stddev_cbmi.isSelected() );
1108 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1109 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1111 options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
1112 && ( _print_using_actual_size_cbmi.isSelected() ) );
1113 options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
1114 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
1115 options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1116 if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1117 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1118 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1120 else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1121 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1122 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1125 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1127 options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1128 && _print_black_and_white_cbmi.isSelected() );
1129 options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1130 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1131 if ( ( _extract_taxonomy_yes_rbmi != null ) && _extract_taxonomy_yes_rbmi.isSelected() ) {
1132 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.AGRESSIVE );
1134 else if ( ( _extract_taxonomy_pfam_rbmi != null ) && _extract_taxonomy_pfam_rbmi.isSelected() ) {
1135 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1137 else if ( ( _extract_taxonomy_no_rbmi != null ) && _extract_taxonomy_no_rbmi.isSelected() ) {
1138 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.NO );
1140 options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1141 && _replace_underscores_cbmi.isSelected() );
1142 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1143 && _search_whole_words_only_cbmi.isSelected() );
1144 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1145 && _inverse_search_result_cbmi.isSelected() );
1146 if ( _graphics_export_visible_only_cbmi != null ) {
1147 options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1148 if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1149 _graphics_export_using_actual_size_cbmi.setSelected( true );
1150 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1153 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1156 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1157 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1159 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1160 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1162 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1163 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1165 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1166 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1168 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1169 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1171 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1172 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1174 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1175 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1177 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1178 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1182 void updateTypeCheckboxes( final Options options, final Object o ) {
1183 setTypeMenuToAllUnselected();
1184 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1187 void viewAsNexus() {
1188 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1189 String title = "Nexus";
1190 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1191 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1193 showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
1199 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1200 String title = "New Hampshire";
1201 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1202 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1204 showTextFrame( _mainpanel.getCurrentPhylogeny()
1205 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1211 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1212 String title = "phyloXML";
1213 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1214 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1216 showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
1220 private void annotateSequences() {
1221 if ( getCurrentTreePanel() != null ) {
1222 final Set<Long> nodes = getCurrentTreePanel().getFoundNodes();
1223 if ( ( nodes == null ) || nodes.isEmpty() ) {
1225 .showMessageDialog( this,
1226 "Need to select nodes, either via direct selection or via the \"Search\" function",
1227 "No nodes selected for annotation",
1228 JOptionPane.ERROR_MESSAGE );
1231 final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
1232 if ( ( phy != null ) && !phy.isEmpty() ) {
1233 final JTextField ref_field = new JTextField( 10 );
1234 final JTextField desc_filed = new JTextField( 20 );
1235 ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
1236 : getPreviousNodeAnnotationReference() );
1237 final JPanel my_panel = new JPanel();
1238 my_panel.add( new JLabel( "Reference " ) );
1239 my_panel.add( ref_field );
1240 my_panel.add( Box.createHorizontalStrut( 15 ) );
1241 my_panel.add( new JLabel( "Description " ) );
1242 my_panel.add( desc_filed );
1243 final int result = JOptionPane.showConfirmDialog( null,
1245 "Enter the sequence annotation(s) for the "
1246 + nodes.size() + " selected nodes",
1247 JOptionPane.OK_CANCEL_OPTION );
1248 if ( result == JOptionPane.OK_OPTION ) {
1249 String ref = ref_field.getText();
1250 String desc = desc_filed.getText();
1251 if ( !ForesterUtil.isEmpty( ref ) ) {
1253 ref = ref.replaceAll( "\\s+", " " );
1254 if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 )
1255 || ( ref.length() < 3 ) ) {
1256 JOptionPane.showMessageDialog( this,
1257 "Reference needs to be in the form of \"GO:1234567\"",
1258 "Illegal Format for Annotation Reference",
1259 JOptionPane.ERROR_MESSAGE );
1263 if ( ref != null ) {
1264 setPreviousNodeAnnotationReference( ref );
1266 if ( desc != null ) {
1268 desc = desc.replaceAll( "\\s+", " " );
1270 if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
1271 for( final Long id : nodes ) {
1272 final PhylogenyNode n = phy.getNode( id );
1273 ForesterUtil.ensurePresenceOfSequence( n );
1274 final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
1275 : new Annotation( ref );
1276 if ( !ForesterUtil.isEmpty( desc ) ) {
1277 ann.setDesc( desc );
1279 n.getNodeData().getSequence().addAnnotation( ann );
1282 getMainPanel().getControlPanel().showAnnotations();
1288 private void chooseFont() {
1289 final FontChooser fc = new FontChooser();
1290 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1291 fc.showDialog( this, "Select the Base Font" );
1292 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1295 private void chooseMinimalConfidence() {
1296 final String s = ( String ) JOptionPane
1297 .showInputDialog( this,
1298 "Please enter the minimum for confidence values to be displayed.\n"
1299 + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
1300 "Minimal Confidence Value",
1301 JOptionPane.QUESTION_MESSAGE,
1304 getOptions().getMinConfidenceValue() );
1305 if ( !ForesterUtil.isEmpty( s ) ) {
1306 boolean success = true;
1308 final String m_str = s.trim();
1309 if ( !ForesterUtil.isEmpty( m_str ) ) {
1311 m = Double.parseDouble( m_str );
1313 catch ( final Exception ex ) {
1320 if ( success && ( m >= 0.0 ) ) {
1321 getOptions().setMinConfidenceValue( m );
1326 private void doUpdateProcessMenu() {
1327 if ( _process_pool.size() > 0 ) {
1328 if ( _process_menu == null ) {
1329 _process_menu = createMenu( "", getConfiguration() );
1330 _process_menu.setForeground( Color.RED );
1332 _process_menu.removeAll();
1333 final String text = "processes running: " + _process_pool.size();
1334 _process_menu.setText( text );
1335 _jmenubar.add( _process_menu );
1336 for( int i = 0; i < _process_pool.size(); ++i ) {
1337 final ProcessRunning p = _process_pool.getProcessByIndex( i );
1338 _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
1342 if ( _process_menu != null ) {
1343 _process_menu.removeAll();
1344 _jmenubar.remove( _process_menu );
1347 _jmenubar.validate();
1348 _jmenubar.repaint();
1352 private String getPreviousNodeAnnotationReference() {
1353 return _previous_node_annotation_ref;
1356 private void removeBranchColors() {
1357 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1358 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1362 private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
1363 _previous_node_annotation_ref = previous_node_annotation_ref;
1367 * Display the about box.
1369 static void about() {
1370 final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" );
1371 about.append( "Copyright (C) 2013 Christian M. Zmasek\n" );
1372 about.append( "All Rights Reserved\n" );
1373 about.append( "License: GNU Lesser General Public License (LGPL)\n" );
1374 about.append( "Last modified: " + Constants.PRG_DATE + "\n" );
1375 about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );
1376 about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1377 about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
1378 if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
1379 about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
1381 if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
1382 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
1383 about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
1384 + ForesterUtil.OS_VERSION + "]\n" );
1386 final Runtime rt = java.lang.Runtime.getRuntime();
1387 final long free_memory = rt.freeMemory() / 1000000;
1388 final long total_memory = rt.totalMemory() / 1000000;
1389 about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
1390 about.append( "[locale: " + Locale.getDefault() + "]\n" );
1391 about.append( "References:\n" );
1392 about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" );
1393 about.append( "For more information & download:\n" );
1394 about.append( Constants.APTX_WEB_SITE + "\n" );
1395 about.append( "Comments: " + Constants.AUTHOR_EMAIL );
1396 JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
1399 static void chooseNodeSize( final Options options, final Component parent ) {
1400 final String s = ( String ) JOptionPane.showInputDialog( parent,
1401 "Please enter the default size for node shapes.\n"
1402 + "[current value: "
1403 + options.getDefaultNodeShapeSize() + "]\n",
1405 JOptionPane.QUESTION_MESSAGE,
1408 options.getDefaultNodeShapeSize() );
1409 if ( !ForesterUtil.isEmpty( s ) ) {
1410 boolean success = true;
1412 final String m_str = s.trim();
1413 if ( !ForesterUtil.isEmpty( m_str ) ) {
1415 m = Double.parseDouble( m_str );
1417 catch ( final Exception ex ) {
1424 if ( success && ( m >= 0.0 ) ) {
1425 final short size = ForesterUtil.roundToShort( m );
1426 if ( size >= 0.0 ) {
1427 options.setDefaultNodeShapeSize( size );
1433 static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
1434 return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
1437 static JMenu createMenu( final String title, final Configuration conf ) {
1438 final JMenu jmenu = new JMenu( title );
1439 if ( !conf.isUseNativeUI() ) {
1440 jmenu.setFont( MainFrame.menu_font );
1441 jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
1442 jmenu.setForeground( conf.getGuiMenuTextColor() );
1447 static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
1448 label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
1449 if ( !configuration.isUseNativeUI() ) {
1450 label.setBackground( configuration.getGuiMenuBackgroundColor() );
1451 label.setForeground( configuration.getGuiMenuTextColor() );
1452 label.setOpaque( true );
1454 label.setSelected( false );
1455 label.setEnabled( false );
1459 static void cycleNodeFill( final Options op, final TreePanel tree_panel ) {
1460 switch ( op.getDefaultNodeFill() ) {
1462 op.setDefaultNodeFill( NodeFill.SOLID );
1465 op.setDefaultNodeFill( NodeFill.GRADIENT );
1468 op.setDefaultNodeFill( NodeFill.NONE );
1471 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
1475 static void cycleNodeShape( final Options op, final TreePanel tree_panel ) {
1476 switch ( op.getDefaultNodeShape() ) {
1478 op.setDefaultNodeShape( NodeShape.RECTANGLE );
1481 op.setDefaultNodeShape( NodeShape.CIRCLE );
1484 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
1488 static void cycleOverview( final Options op, final TreePanel tree_panel ) {
1489 switch ( op.getOvPlacement() ) {
1491 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1494 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
1497 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
1500 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
1503 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
1505 if ( tree_panel != null ) {
1506 tree_panel.updateOvSettings();
1510 static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
1511 if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
1512 mi.setText( "Cycle Node Shape Fill Type... (current: "
1513 + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
1516 mi.setText( "Cycle Node Shape Fill Type..." );
1520 static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
1521 if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
1522 mi.setText( "Cycle Node Shape Fill Type... (current: "
1523 + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
1526 mi.setText( "Cycle Node Shape Fill Type..." );
1530 static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
1531 if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
1532 mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
1535 mi.setText( "Cycle Overview Placement..." );
1539 static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
1540 if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
1541 mi.setText( "Select Colors... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName() + ")" );
1544 mi.setText( "Select Colors..." );
1548 static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
1549 mi.setText( "Select Font... (current: " + font_desc + ")" );
1552 static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
1553 if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
1554 mi.setEnabled( true );
1556 else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
1557 mi.setEnabled( true );
1560 mi.setEnabled( false );
1562 mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
1565 static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
1566 mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
1569 static void updateOptionsMenuDependingOnPhylogenyType( final MainPanel main_panel,
1570 final JCheckBoxMenuItem scale,
1571 final JCheckBoxMenuItem branch_lengths,
1572 final JRadioButtonMenuItem non_lined_up,
1573 final JRadioButtonMenuItem uniform_clado,
1574 final JRadioButtonMenuItem nonuniform_clado,
1575 final JCheckBoxMenuItem label_direction_cbmi ) {
1576 final TreePanel tree_panel = main_panel.getCurrentTreePanel();
1577 final ControlPanel control = main_panel.getControlPanel();
1578 final Options options = main_panel.getOptions();
1579 scale.setSelected( options.isShowScale() );
1580 branch_lengths.setSelected( options.isShowBranchLengthValues() );
1581 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1582 if ( ( tree_panel != null ) && ( !tree_panel.isPhyHasBranchLengths() ) ) {
1583 scale.setSelected( false );
1584 scale.setEnabled( false );
1585 branch_lengths.setSelected( false );
1586 branch_lengths.setEnabled( false );
1588 else if ( ( tree_panel != null ) && !control.isDrawPhylogram() ) {
1589 scale.setSelected( false );
1590 scale.setEnabled( false );
1591 branch_lengths.setEnabled( true );
1594 scale.setEnabled( true );
1595 branch_lengths.setEnabled( true );
1597 if ( ( tree_panel != null )
1598 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
1599 && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1600 .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1601 branch_lengths.setSelected( false );
1602 branch_lengths.setEnabled( false );
1604 if ( tree_panel != null ) {
1605 if ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1606 || ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
1607 non_lined_up.setEnabled( false );
1608 uniform_clado.setEnabled( false );
1609 nonuniform_clado.setEnabled( false );
1612 non_lined_up.setEnabled( true );
1613 uniform_clado.setEnabled( true );
1614 nonuniform_clado.setEnabled( true );
1618 if ( ( tree_panel != null )
1619 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1620 .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1621 branch_lengths.setSelected( false );
1622 branch_lengths.setEnabled( false );
1624 if ( ( tree_panel != null )
1625 && ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( tree_panel
1626 .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
1627 non_lined_up.setEnabled( false );
1630 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1631 non_lined_up.setEnabled( true );
1634 label_direction_cbmi.setEnabled( true );
1635 if ( tree_panel != null ) {
1636 if ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1637 && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1638 label_direction_cbmi.setEnabled( false );
1640 if ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1641 scale.setSelected( false );
1642 scale.setEnabled( false );
1647 static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
1648 for( final TreePanel tree_panel : treepanels ) {
1649 tree_panel.setTextAntialias();