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 JMenuItem _open_item;
129 JMenuItem _open_url_item;
130 JMenuItem _save_item;
131 JMenuItem _save_all_item;
132 JMenuItem _close_item;
133 JMenuItem _exit_item;
136 JMenuItem _midpoint_root_item;
137 JMenuItem _taxcolor_item;
138 JMenuItem _confcolor_item;
139 JMenuItem _color_rank_jmi;
140 JMenuItem _collapse_species_specific_subtrees;
141 JMenuItem _collapse_below_threshold; //TODO implememt me
142 JMenuItem _obtain_detailed_taxonomic_information_jmi;
143 JMenuItem _obtain_detailed_taxonomic_information_deleting_jmi;
144 JMenuItem _obtain_seq_information_jmi;
145 JMenuItem _move_node_names_to_tax_sn_jmi;
146 JMenuItem _move_node_names_to_seq_names_jmi;
147 JMenuItem _extract_tax_code_from_node_names_jmi;
148 JMenuItem _annotate_item;
150 JMenuItem _super_tiny_fonts_item;
151 JMenuItem _tiny_fonts_item;
152 JMenuItem _small_fonts_item;
153 JMenuItem _medium_fonts_item;
154 JMenuItem _large_fonts_item;
156 // _ screen and print
157 JMenuItem _choose_font_mi;
158 JMenuItem _switch_colors_mi;
159 JCheckBoxMenuItem _label_direction_cbmi;
161 JCheckBoxMenuItem _screen_antialias_cbmi;
162 JCheckBoxMenuItem _background_gradient_cbmi;
163 JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
164 JRadioButtonMenuItem _uniform_cladograms_rbmi;
165 JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
166 JCheckBoxMenuItem _show_branch_length_values_cbmi;
167 JCheckBoxMenuItem _show_scale_cbmi; //TODO fix me
168 JCheckBoxMenuItem _show_overview_cbmi;
169 JCheckBoxMenuItem _show_domain_labels;
170 JCheckBoxMenuItem _abbreviate_scientific_names;
171 JCheckBoxMenuItem _color_labels_same_as_parent_branch;
172 JMenuItem _overview_placment_mi;
173 JMenuItem _choose_minimal_confidence_mi;
174 JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
175 JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
176 JMenuItem _cycle_node_shape_mi;
177 JMenuItem _cycle_node_fill_mi;
178 JMenuItem _choose_node_size_mi;
179 JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
180 JCheckBoxMenuItem _show_confidence_stddev_cbmi;
182 JCheckBoxMenuItem _graphics_export_visible_only_cbmi;
183 JCheckBoxMenuItem _antialias_print_cbmi;
184 JCheckBoxMenuItem _print_black_and_white_cbmi;
185 JCheckBoxMenuItem _print_using_actual_size_cbmi;
186 JCheckBoxMenuItem _graphics_export_using_actual_size_cbmi;
187 JMenuItem _print_size_mi;
188 JMenuItem _choose_pdf_width_mi;
190 JCheckBoxMenuItem _internal_number_are_confidence_for_nh_parsing_cbmi;
191 JRadioButtonMenuItem _extract_taxonomy_no_rbmi;
192 JRadioButtonMenuItem _extract_taxonomy_yes_rbmi;
193 JRadioButtonMenuItem _extract_taxonomy_pfam_rbmi;
194 JCheckBoxMenuItem _replace_underscores_cbmi;
195 JCheckBoxMenuItem _use_brackets_for_conf_in_nh_export_cbmi;
196 JCheckBoxMenuItem _use_internal_names_for_conf_in_nh_export_cbmi;
198 JCheckBoxMenuItem _search_case_senstive_cbmi;
199 JCheckBoxMenuItem _search_whole_words_only_cbmi;
200 JCheckBoxMenuItem _inverse_search_result_cbmi;
203 JCheckBoxMenuItem _rectangular_type_cbmi;
204 JCheckBoxMenuItem _triangular_type_cbmi;
205 JCheckBoxMenuItem _curved_type_cbmi;
206 JCheckBoxMenuItem _convex_type_cbmi;
207 JCheckBoxMenuItem _euro_type_cbmi;
208 JCheckBoxMenuItem _rounded_type_cbmi;
209 JCheckBoxMenuItem _unrooted_type_cbmi;
210 JCheckBoxMenuItem _circular_type_cbmi;
211 // view as text menu:
212 JMenuItem _view_as_NH_item;
213 JMenuItem _view_as_XML_item;
214 JMenuItem _view_as_nexus_item;
215 JMenuItem _display_basic_information_item;
217 JMenuItem _about_item;
218 JMenuItem _help_item;
219 JMenuItem _website_item;
220 JMenuItem _phyloxml_website_item;
221 JMenuItem _phyloxml_ref_item;
222 JMenuItem _aptx_ref_item;
225 // Handy pointers to child components:
226 MainPanel _mainpanel;
227 Container _contentpane;
228 final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>(); ;
229 Configuration _configuration;
230 JMenuItem _remove_branch_color_item;
232 InferenceManager _inference_manager;
233 final ProcessPool _process_pool;
234 private String _previous_node_annotation_ref;
237 _process_pool = ProcessPool.createInstance();
244 public void actionPerformed( final ActionEvent e ) {
245 final Object o = e.getSource();
246 boolean is_applet = false;
247 JApplet applet = null;
248 if ( getCurrentTreePanel() != null ) {
249 is_applet = getCurrentTreePanel().isApplet();
251 applet = getCurrentTreePanel().obtainApplet();
254 if ( o == _open_url_item ) {
255 readPhylogeniesFromURL();
257 else if ( o == _exit_item ) {
260 else if ( o == _taxcolor_item ) {
263 else if ( o == _confcolor_item ) {
266 else if ( o == _color_rank_jmi ) {
269 else if ( o == _collapse_species_specific_subtrees ) {
270 if ( isSubtreeDisplayed() ) {
273 if ( getCurrentTreePanel() != null ) {
274 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
277 else if ( o == _remove_branch_color_item ) {
278 if ( isSubtreeDisplayed() ) {
281 removeBranchColors();
283 else if ( o == _midpoint_root_item ) {
284 if ( isSubtreeDisplayed() ) {
289 else if ( o == _annotate_item ) {
292 else if ( o == _switch_colors_mi ) {
295 else if ( o == _display_basic_information_item ) {
296 displayBasicInformation();
298 else if ( o == _view_as_NH_item ) {
301 else if ( o == _view_as_XML_item ) {
304 else if ( o == _view_as_nexus_item ) {
307 else if ( o == _super_tiny_fonts_item ) {
308 if ( getCurrentTreePanel() != null ) {
309 getCurrentTreePanel().setSuperTinyFonts();
310 getCurrentTreePanel().repaint();
313 else if ( o == _tiny_fonts_item ) {
314 if ( getCurrentTreePanel() != null ) {
315 getCurrentTreePanel().setTinyFonts();
316 getCurrentTreePanel().repaint();
319 else if ( o == _small_fonts_item ) {
320 if ( getCurrentTreePanel() != null ) {
321 getCurrentTreePanel().setSmallFonts();
322 getCurrentTreePanel().repaint();
325 else if ( o == _medium_fonts_item ) {
326 if ( getCurrentTreePanel() != null ) {
327 getCurrentTreePanel().setMediumFonts();
328 getCurrentTreePanel().repaint();
331 else if ( o == _large_fonts_item ) {
332 if ( getCurrentTreePanel() != null ) {
333 getCurrentTreePanel().setLargeFonts();
334 getCurrentTreePanel().repaint();
337 else if ( o == _choose_font_mi ) {
340 else if ( o == _choose_minimal_confidence_mi ) {
341 chooseMinimalConfidence();
343 else if ( o == _choose_node_size_mi ) {
344 chooseNodeSize( getOptions(), this );
346 else if ( o == _overview_placment_mi ) {
347 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
349 else if ( o == _cycle_node_fill_mi ) {
350 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
352 else if ( o == _cycle_node_shape_mi ) {
353 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
355 else if ( o == _screen_antialias_cbmi ) {
356 updateOptions( getOptions() );
357 updateScreenTextAntialias( getMainPanel().getTreePanels() );
359 else if ( o == _background_gradient_cbmi ) {
360 updateOptions( getOptions() );
362 else if ( o == _show_domain_labels ) {
363 updateOptions( getOptions() );
365 else if ( o == _abbreviate_scientific_names ) {
366 updateOptions( getOptions() );
368 else if ( o == _color_labels_same_as_parent_branch ) {
369 updateOptions( getOptions() );
371 else if ( o == _show_default_node_shapes_internal_cbmi ) {
372 updateOptions( getOptions() );
374 else if ( o == _show_default_node_shapes_external_cbmi ) {
375 updateOptions( getOptions() );
377 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
378 updateOptions( getOptions() );
380 else if ( o == _non_lined_up_cladograms_rbmi ) {
381 updateOptions( getOptions() );
384 else if ( o == _uniform_cladograms_rbmi ) {
385 updateOptions( getOptions() );
388 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
389 updateOptions( getOptions() );
392 else if ( o == _search_case_senstive_cbmi ) {
393 updateOptions( getOptions() );
394 getMainPanel().getControlPanel().search();
396 else if ( o == _search_whole_words_only_cbmi ) {
397 updateOptions( getOptions() );
398 getMainPanel().getControlPanel().search();
400 else if ( o == _inverse_search_result_cbmi ) {
401 updateOptions( getOptions() );
402 getMainPanel().getControlPanel().search();
404 else if ( o == _show_scale_cbmi ) {
405 updateOptions( getOptions() );
407 else if ( o == _show_branch_length_values_cbmi ) {
408 updateOptions( getOptions() );
410 else if ( o == _show_confidence_stddev_cbmi ) {
411 updateOptions( getOptions() );
413 else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
414 if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
415 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
417 updateOptions( getOptions() );
419 else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
420 if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
421 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
423 updateOptions( getOptions() );
425 else if ( o == _label_direction_cbmi ) {
426 updateOptions( getOptions() );
428 else if ( o == _show_overview_cbmi ) {
429 updateOptions( getOptions() );
430 if ( getCurrentTreePanel() != null ) {
431 getCurrentTreePanel().updateOvSizes();
434 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
435 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
436 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
439 else if ( o == _about_item ) {
442 else if ( o == _help_item ) {
443 help( getConfiguration().getWebLinks() );
445 else if ( o == _website_item ) {
447 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, is_applet, applet );
449 catch ( final IOException e1 ) {
450 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
453 else if ( o == _phyloxml_website_item ) {
455 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, is_applet, applet );
457 catch ( final IOException e1 ) {
458 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
461 else if ( o == _aptx_ref_item ) {
463 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, is_applet, applet );
465 catch ( final IOException e1 ) {
466 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
469 else if ( o == _phyloxml_ref_item ) {
471 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, is_applet, applet );
473 catch ( final IOException e1 ) {
474 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
478 if ( _load_phylogeny_from_webservice_menu_items != null ) {
479 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
480 if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
481 readPhylogeniesFromWebservice( i );
486 _contentpane.repaint();
489 public Configuration getConfiguration() {
490 return _configuration;
494 * This method returns the current external node data which
495 * has been selected by the user by clicking the "Return ..."
496 * menu item. This method is expected to be called from Javascript or
499 * @return current external node data as String
501 public String getCurrentExternalNodesDataBuffer() {
502 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
505 public int getCurrentExternalNodesDataBufferChangeCounter() {
506 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
509 public int getCurrentExternalNodesDataBufferLength() {
510 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
513 public InferenceManager getInferenceManager() {
514 return _inference_manager;
517 public MainPanel getMainPanel() {
521 public Options getOptions() {
525 public ProcessPool getProcessPool() {
526 return _process_pool;
529 public void showTextFrame( final String s, final String title ) {
531 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
534 public void showWhole() {
535 _mainpanel.getControlPanel().showWhole();
538 public void updateProcessMenu() {
539 // In general Swing is not thread safe.
540 // See "Swing's Threading Policy".
541 SwingUtilities.invokeLater( new Runnable() {
545 doUpdateProcessMenu();
550 void activateSaveAllIfNeeded() {
551 if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
552 _save_all_item.setEnabled( true );
555 _save_all_item.setEnabled( false );
559 void buildFileMenu() {
560 _file_jmenu = createMenu( "File", getConfiguration() );
561 _file_jmenu.add( _open_url_item = new JMenuItem( "Read tree from URL/webservice..." ) );
562 _file_jmenu.addSeparator();
563 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
564 customizeJMenuItem( _open_url_item );
565 customizeJMenuItem( _exit_item );
566 _jmenubar.add( _file_jmenu );
569 void buildFontSizeMenu() {
570 _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
571 _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
572 _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
573 _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
574 _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
575 _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
576 customizeJMenuItem( _super_tiny_fonts_item );
577 customizeJMenuItem( _tiny_fonts_item );
578 customizeJMenuItem( _small_fonts_item );
579 customizeJMenuItem( _medium_fonts_item );
580 customizeJMenuItem( _large_fonts_item );
581 _jmenubar.add( _font_size_menu );
584 void buildHelpMenu() {
585 _help_jmenu = createMenu( "Help", getConfiguration() );
586 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
587 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
588 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
589 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
590 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
591 _help_jmenu.addSeparator();
592 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
593 customizeJMenuItem( _help_item );
594 customizeJMenuItem( _website_item );
595 customizeJMenuItem( _phyloxml_website_item );
596 customizeJMenuItem( _aptx_ref_item );
597 customizeJMenuItem( _phyloxml_ref_item );
598 customizeJMenuItem( _about_item );
599 _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
600 _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
601 _jmenubar.add( _help_jmenu );
604 void buildTypeMenu() {
605 _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
606 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
607 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
608 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
609 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
610 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
611 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
612 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
613 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
614 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
615 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
616 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
617 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
618 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
619 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
620 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
621 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
622 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
623 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
624 initializeTypeMenu( getOptions() );
625 _jmenubar.add( _type_menu );
628 void buildViewMenu() {
629 _view_jmenu = createMenu( "View", getConfiguration() );
630 _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
631 _view_jmenu.addSeparator();
632 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
633 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
634 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
635 customizeJMenuItem( _display_basic_information_item );
636 customizeJMenuItem( _view_as_NH_item );
637 customizeJMenuItem( _view_as_XML_item );
638 customizeJMenuItem( _view_as_nexus_item );
639 _jmenubar.add( _view_jmenu );
642 void checkTextFrames() {
643 if ( _textframes.size() > 5 ) {
645 if ( _textframes.getFirst() != null ) {
646 _textframes.getFirst().removeMe();
649 _textframes.removeFirst();
652 catch ( final NoSuchElementException e ) {
659 removeAllTextFrames();
660 if ( _mainpanel != null ) {
661 _mainpanel.terminate();
663 if ( _contentpane != null ) {
664 _contentpane.removeAll();
671 if ( _mainpanel.getCurrentTreePanel() != null ) {
672 final String[] ranks = AptxUtil.getAllPossibleRanks();
673 final String rank = ( String ) JOptionPane
674 .showInputDialog( this,
675 "What rank should the colorization be based on",
677 JOptionPane.QUESTION_MESSAGE,
681 if ( !ForesterUtil.isEmpty( rank ) ) {
682 _mainpanel.getCurrentTreePanel().colorRank( rank );
688 if ( _mainpanel.getCurrentTreePanel() != null ) {
689 _mainpanel.getCurrentTreePanel().confColor();
693 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
694 if ( item != null ) {
695 item.setFont( MainFrame.menu_font );
696 if ( !getConfiguration().isUseNativeUI() ) {
697 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
698 item.setForeground( getConfiguration().getGuiMenuTextColor() );
700 item.setSelected( is_selected );
701 item.addActionListener( this );
705 JMenuItem customizeJMenuItem( final JMenuItem jmi ) {
707 jmi.setFont( MainFrame.menu_font );
708 if ( !getConfiguration().isUseNativeUI() ) {
709 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
710 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
712 jmi.addActionListener( this );
717 void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
718 if ( item != null ) {
719 item.setFont( MainFrame.menu_font );
720 if ( !getConfiguration().isUseNativeUI() ) {
721 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
722 item.setForeground( getConfiguration().getGuiMenuTextColor() );
724 item.setSelected( is_selected );
725 item.addActionListener( this );
729 void displayBasicInformation() {
730 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
731 String title = "Basic Information";
732 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
733 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
735 showTextFrame( AptxUtil.createBasicInformation( _mainpanel.getCurrentPhylogeny() ), title );
739 void exceptionOccuredDuringOpenFile( final Exception e ) {
741 _mainpanel.getCurrentTreePanel().setArrowCursor();
743 catch ( final Exception ex ) {
746 JOptionPane.showMessageDialog( this,
747 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
748 "Error during File|Open",
749 JOptionPane.ERROR_MESSAGE );
752 void exceptionOccuredDuringSaveAs( final Exception e ) {
754 _mainpanel.getCurrentTreePanel().setArrowCursor();
756 catch ( final Exception ex ) {
759 JOptionPane.showMessageDialog( this, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );
762 boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
763 if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
764 JOptionPane.showMessageDialog( this,
765 "Gene tree and species tree have no species in common.",
767 JOptionPane.ERROR_MESSAGE );
770 else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
771 JOptionPane.showMessageDialog( this,
772 "Gene tree and species tree have only one species in common.",
774 JOptionPane.ERROR_MESSAGE );
782 TreePanel getCurrentTreePanel() {
783 return getMainPanel().getCurrentTreePanel();
786 JMenu getHelpMenu() {
790 JCheckBoxMenuItem getlabelDirectionCbmi() {
791 return _label_direction_cbmi;
794 JMenuBar getMenuBarOfMainFrame() {
798 void help( final Map<String, WebLink> weblinks ) {
799 final StringBuilder sb = new StringBuilder();
800 sb.append( "Display options\n" );
801 sb.append( "-------------------\n" );
802 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
803 sb.append( "Clickable tree nodes\n" );
804 sb.append( "--------------------\n" );
805 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
806 sb.append( "or by right clicking:\n" );
807 sb.append( "o Display Node Data -- display information for a node\n" );
808 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
809 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
810 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
811 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
812 sb.append( "o Colorize Subtree -- color a subtree\n" );
813 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
814 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
815 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
816 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
817 sb.append( "Zooming\n" );
818 sb.append( "---------\n" );
819 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
820 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
821 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
822 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
823 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
824 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
825 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
826 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
827 sb.append( "Quick tree manipulation:\n" );
828 sb.append( "------------------------\n" );
829 sb.append( "Order Subtrees -- order the tree by branch length\n" );
830 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
831 sb.append( "Memory problems (Java heap space error)\n" );
832 sb.append( "---------------------------------------\n" );
833 sb.append( "Since the Java default memory allocation is quite small, it might by necessary (for trees\n" );
834 sb.append( "with more than approximately 5000 external nodes) to increase the memory which Java can use, with\n" );
835 sb.append( "the '-Xmx' Java command line option. For example:\n" );
836 sb.append( "java -Xms32m -Xmx256m -cp path\\to\\forester.jar org.forester.archaeopteryx.Archaeopteryx\n\n" );
837 if ( ( weblinks != null ) && ( weblinks.size() > 0 ) ) {
838 sb.append( "Active web links\n" );
839 sb.append( "--------------------\n" );
840 for( final String key : weblinks.keySet() ) {
841 sb.append( " " + weblinks.get( key ).toString() + "\n" );
844 // + "General remarks\n"
845 // + "---------------\n"
847 // "o The application version permits copying to the clipboard \n"
849 // " in the \"View\"|\"View as ...\" frame (either by control-c or button press).\n"
851 // "o Changes made to a subtree affect this subtree and its subtrees,\n"
852 // + " but not any of its parent tree(s).\n"
854 // "o Archaeopteryx tries to detect whether the numerical values in a NH tree\n"
856 // " are likely to be bootstrap values instead of branch length values.\n\n"
858 // " Remarks regarding SDI (Speciation Duplication Inference):\n"
860 // "o Each external node of the gene tree (in display) needs to be associated with\n"
862 // " a species: either directly through the \"Species\" field, or the species\n"
864 // " is part of the sequence name in the form \"XXXX_SPECIES\"\n"
866 // " (e.g. \"ACON_DROME\" or \"ACON_DROME/123-4489\" which is also acceptable).\n"
868 // "o A species tree for each species of the gene tree needs to be loaded with\n"
870 // " \"SDI\"|\"Load species tree\" prior the SDI execution.\n"
872 // "o !External nodes of the gene tree associated with species not present in\n"
874 // " the species tree are REMOVED prior to SDI execution!\n"
876 // "o Both the gene tree and the species tree must be completely binary.\n"
878 // "o Duplications and speciations are a function of the position of the root.\n"
880 // " Hence, after each manual \"Root/Reroot\"ing some duplications will be\n"
881 // + " incorrect and need to be inferred again\n"
883 // " with: \"SDI\"|\"SDI (Speciation Duplication Inference)\n\n"
885 sb.append( "phyloXML\n" );
886 sb.append( "-------------------\n" );
887 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
888 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
889 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
891 sb.append( "For more information: https://sites.google.com/site/cmzmasek/home/software/archaeopteryx\n" );
892 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
893 TextFrame.instantiate( sb.toString(), "Help", _textframes );
896 void initializeTypeMenu( final Options options ) {
897 setTypeMenuToAllUnselected();
898 switch ( options.getPhylogenyGraphicsType() ) {
900 _convex_type_cbmi.setSelected( true );
903 _curved_type_cbmi.setSelected( true );
906 _euro_type_cbmi.setSelected( true );
909 _rounded_type_cbmi.setSelected( true );
912 _triangular_type_cbmi.setSelected( true );
915 _unrooted_type_cbmi.setSelected( true );
918 _circular_type_cbmi.setSelected( true );
921 _rectangular_type_cbmi.setSelected( true );
926 boolean isSubtreeDisplayed() {
927 if ( getCurrentTreePanel() != null ) {
928 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
930 .showMessageDialog( this,
931 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
932 "Operation can not be exectuted on a sub-tree",
933 JOptionPane.WARNING_MESSAGE );
940 void midpointRoot() {
941 if ( _mainpanel.getCurrentTreePanel() != null ) {
942 _mainpanel.getCurrentTreePanel().midpointRoot();
946 abstract void readPhylogeniesFromURL();
948 void readPhylogeniesFromWebservice( final int i ) {
949 final UrlTreeReader reader = new UrlTreeReader( this, i );
950 new Thread( reader ).start();
953 void removeAllTextFrames() {
954 for( final TextFrame tf : _textframes ) {
962 void setConfiguration( final Configuration configuration ) {
963 _configuration = configuration;
966 void setInferenceManager( final InferenceManager i ) {
967 _inference_manager = i;
970 void setOptions( final Options options ) {
974 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
975 setTypeMenuToAllUnselected();
978 _circular_type_cbmi.setSelected( true );
981 _convex_type_cbmi.setSelected( true );
984 _curved_type_cbmi.setSelected( true );
987 _euro_type_cbmi.setSelected( true );
990 _rounded_type_cbmi.setSelected( true );
993 _rectangular_type_cbmi.setSelected( true );
996 _triangular_type_cbmi.setSelected( true );
999 _unrooted_type_cbmi.setSelected( true );
1002 throw new IllegalArgumentException( "unknown type: " + type );
1006 void setTypeMenuToAllUnselected() {
1007 _convex_type_cbmi.setSelected( false );
1008 _curved_type_cbmi.setSelected( false );
1009 _euro_type_cbmi.setSelected( false );
1010 _rounded_type_cbmi.setSelected( false );
1011 _triangular_type_cbmi.setSelected( false );
1012 _rectangular_type_cbmi.setSelected( false );
1013 _unrooted_type_cbmi.setSelected( false );
1014 _circular_type_cbmi.setSelected( false );
1017 void switchColors() {
1018 final TreeColorSet colorset = _mainpanel.getTreeColorSet();
1019 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1020 csc.setVisible( true );
1024 if ( _mainpanel.getCurrentTreePanel() != null ) {
1025 _mainpanel.getCurrentTreePanel().taxColor();
1029 void typeChanged( final Object o ) {
1030 updateTypeCheckboxes( getOptions(), o );
1031 updateOptions( getOptions() );
1032 if ( getCurrentTreePanel() != null ) {
1033 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1034 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1035 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1036 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1037 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1038 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1039 getCurrentTreePanel().getControlPanel().showWhole();
1041 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1042 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1045 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1047 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1048 updateScreenTextAntialias( getMainPanel().getTreePanels() );
1049 if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
1050 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1051 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
1054 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
1060 void updateOptions( final Options options ) {
1061 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1062 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1063 && _background_gradient_cbmi.isSelected() );
1064 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1065 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1066 && _abbreviate_scientific_names.isSelected() );
1067 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1068 && _color_labels_same_as_parent_branch.isSelected() );
1069 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1070 && _show_default_node_shapes_internal_cbmi.isSelected() );
1071 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1072 && _show_default_node_shapes_external_cbmi.isSelected() );
1073 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1074 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1075 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1076 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1078 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1079 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1081 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1082 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1084 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1085 && _search_case_senstive_cbmi.isSelected() );
1086 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1087 options.setShowScale( _show_scale_cbmi.isSelected() );
1089 if ( _label_direction_cbmi != null ) {
1090 if ( _label_direction_cbmi.isSelected() ) {
1091 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1094 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1097 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1098 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1099 && _show_confidence_stddev_cbmi.isSelected() );
1100 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1101 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1103 options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
1104 && ( _print_using_actual_size_cbmi.isSelected() ) );
1105 options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
1106 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
1107 options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1108 if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1109 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1110 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1112 else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1113 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1114 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1117 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1119 options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1120 && _print_black_and_white_cbmi.isSelected() );
1121 options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1122 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1123 if ( ( _extract_taxonomy_yes_rbmi != null ) && _extract_taxonomy_yes_rbmi.isSelected() ) {
1124 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.YES );
1126 else if ( ( _extract_taxonomy_pfam_rbmi != null ) && _extract_taxonomy_pfam_rbmi.isSelected() ) {
1127 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
1129 else if ( ( _extract_taxonomy_no_rbmi != null ) && _extract_taxonomy_no_rbmi.isSelected() ) {
1130 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.NO );
1132 options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1133 && _replace_underscores_cbmi.isSelected() );
1134 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1135 && _search_whole_words_only_cbmi.isSelected() );
1136 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1137 && _inverse_search_result_cbmi.isSelected() );
1138 if ( _graphics_export_visible_only_cbmi != null ) {
1139 options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1140 if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1141 _graphics_export_using_actual_size_cbmi.setSelected( true );
1142 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1145 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1148 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1149 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1151 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1152 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1154 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1155 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1157 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1158 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1160 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1161 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1163 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1164 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1166 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1167 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1169 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1170 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1174 void updateTypeCheckboxes( final Options options, final Object o ) {
1175 setTypeMenuToAllUnselected();
1176 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1179 void viewAsNexus() {
1180 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1181 String title = "Nexus";
1182 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1183 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1185 showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
1191 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1192 String title = "New Hampshire";
1193 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1194 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1196 showTextFrame( _mainpanel.getCurrentPhylogeny()
1197 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1203 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1204 String title = "phyloXML";
1205 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1206 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1208 showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
1212 private void annotateSequences() {
1213 if ( getCurrentTreePanel() != null ) {
1214 final Set<Integer> nodes = getCurrentTreePanel().getFoundNodes();
1215 if ( ( nodes == null ) || nodes.isEmpty() ) {
1217 .showMessageDialog( this,
1218 "Need to select nodes, either via direct selection or via the \"Search\" function",
1219 "No nodes selected for annotation",
1220 JOptionPane.ERROR_MESSAGE );
1223 final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
1224 if ( ( phy != null ) && !phy.isEmpty() ) {
1225 final JTextField ref_field = new JTextField( 10 );
1226 final JTextField desc_filed = new JTextField( 20 );
1227 ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
1228 : getPreviousNodeAnnotationReference() );
1229 final JPanel my_panel = new JPanel();
1230 my_panel.add( new JLabel( "Reference " ) );
1231 my_panel.add( ref_field );
1232 my_panel.add( Box.createHorizontalStrut( 15 ) );
1233 my_panel.add( new JLabel( "Description " ) );
1234 my_panel.add( desc_filed );
1235 final int result = JOptionPane.showConfirmDialog( null,
1237 "Enter the sequence annotation(s) for the "
1238 + nodes.size() + " selected nodes",
1239 JOptionPane.OK_CANCEL_OPTION );
1240 if ( result == JOptionPane.OK_OPTION ) {
1241 String ref = ref_field.getText();
1242 String desc = desc_filed.getText();
1243 if ( !ForesterUtil.isEmpty( ref ) ) {
1245 ref = ref.replaceAll( "\\s+", " " );
1246 if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 )
1247 || ( ref.length() < 3 ) ) {
1248 JOptionPane.showMessageDialog( this,
1249 "Reference needs to be in the form of \"GO:1234567\"",
1250 "Illegal Format for Annotation Reference",
1251 JOptionPane.ERROR_MESSAGE );
1255 if ( ref != null ) {
1256 setPreviousNodeAnnotationReference( ref );
1258 if ( desc != null ) {
1260 desc = desc.replaceAll( "\\s+", " " );
1262 if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
1263 for( final Integer id : nodes ) {
1264 final PhylogenyNode n = phy.getNode( id );
1265 ForesterUtil.ensurePresenceOfSequence( n );
1266 final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
1267 : new Annotation( ref );
1268 if ( !ForesterUtil.isEmpty( desc ) ) {
1269 ann.setDesc( desc );
1271 n.getNodeData().getSequence().addAnnotation( ann );
1274 getMainPanel().getControlPanel().showAnnotations();
1280 private void chooseFont() {
1281 final FontChooser fc = new FontChooser();
1282 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1283 fc.showDialog( this, "Select the Base Font" );
1284 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1287 private void chooseMinimalConfidence() {
1288 final String s = ( String ) JOptionPane
1289 .showInputDialog( this,
1290 "Please enter the minimum for confidence values to be displayed.\n"
1291 + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
1292 "Minimal Confidence Value",
1293 JOptionPane.QUESTION_MESSAGE,
1296 getOptions().getMinConfidenceValue() );
1297 if ( !ForesterUtil.isEmpty( s ) ) {
1298 boolean success = true;
1300 final String m_str = s.trim();
1301 if ( !ForesterUtil.isEmpty( m_str ) ) {
1303 m = Double.parseDouble( m_str );
1305 catch ( final Exception ex ) {
1312 if ( success && ( m >= 0.0 ) ) {
1313 getOptions().setMinConfidenceValue( m );
1318 private void doUpdateProcessMenu() {
1319 if ( _process_pool.size() > 0 ) {
1320 if ( _process_menu == null ) {
1321 _process_menu = createMenu( "", getConfiguration() );
1322 _process_menu.setForeground( Color.RED );
1324 _process_menu.removeAll();
1325 final String text = "processes running: " + _process_pool.size();
1326 _process_menu.setText( text );
1327 _jmenubar.add( _process_menu );
1328 for( int i = 0; i < _process_pool.size(); ++i ) {
1329 final ProcessRunning p = _process_pool.getProcessByIndex( i );
1330 _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
1334 if ( _process_menu != null ) {
1335 _process_menu.removeAll();
1336 _jmenubar.remove( _process_menu );
1339 _jmenubar.validate();
1340 _jmenubar.repaint();
1344 private String getPreviousNodeAnnotationReference() {
1345 return _previous_node_annotation_ref;
1348 private void removeBranchColors() {
1349 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1350 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1354 private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
1355 _previous_node_annotation_ref = previous_node_annotation_ref;
1359 * Display the about box.
1361 static void about() {
1362 final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" );
1363 about.append( "Copyright (C) 2013 Christian M. Zmasek\n" );
1364 about.append( "All Rights Reserved\n" );
1365 about.append( "License: GNU Lesser General Public License (LGPL)\n" );
1366 about.append( "Last modified: " + Constants.PRG_DATE + "\n" );
1367 about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );
1368 about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1369 about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
1370 if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
1371 about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
1373 if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
1374 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
1375 about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
1376 + ForesterUtil.OS_VERSION + "]\n" );
1378 final Runtime rt = java.lang.Runtime.getRuntime();
1379 final long free_memory = rt.freeMemory() / 1000000;
1380 final long total_memory = rt.totalMemory() / 1000000;
1381 about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
1382 about.append( "[locale: " + Locale.getDefault() + "]\n" );
1383 about.append( "References:\n" );
1384 about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" );
1385 about.append( "For more information & download:\n" );
1386 about.append( Constants.APTX_WEB_SITE + "\n" );
1387 about.append( "Comments: " + Constants.AUTHOR_EMAIL );
1388 JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
1391 static void chooseNodeSize( final Options options, final Component parent ) {
1392 final String s = ( String ) JOptionPane.showInputDialog( parent,
1393 "Please enter the default size for node shapes.\n"
1394 + "[current value: "
1395 + options.getDefaultNodeShapeSize() + "]\n",
1397 JOptionPane.QUESTION_MESSAGE,
1400 options.getDefaultNodeShapeSize() );
1401 if ( !ForesterUtil.isEmpty( s ) ) {
1402 boolean success = true;
1404 final String m_str = s.trim();
1405 if ( !ForesterUtil.isEmpty( m_str ) ) {
1407 m = Double.parseDouble( m_str );
1409 catch ( final Exception ex ) {
1416 if ( success && ( m >= 0.0 ) ) {
1417 final short size = ForesterUtil.roundToShort( m );
1418 if ( size >= 0.0 ) {
1419 options.setDefaultNodeShapeSize( size );
1425 static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
1426 return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
1429 static JMenu createMenu( final String title, final Configuration conf ) {
1430 final JMenu jmenu = new JMenu( title );
1431 if ( !conf.isUseNativeUI() ) {
1432 jmenu.setFont( MainFrame.menu_font );
1433 jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
1434 jmenu.setForeground( conf.getGuiMenuTextColor() );
1439 static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
1440 label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
1441 if ( !configuration.isUseNativeUI() ) {
1442 label.setBackground( configuration.getGuiMenuBackgroundColor() );
1443 label.setForeground( configuration.getGuiMenuTextColor() );
1444 label.setOpaque( true );
1446 label.setSelected( false );
1447 label.setEnabled( false );
1451 static void cycleNodeFill( final Options op, final TreePanel tree_panel ) {
1452 switch ( op.getDefaultNodeFill() ) {
1454 op.setDefaultNodeFill( NodeFill.SOLID );
1457 op.setDefaultNodeFill( NodeFill.GRADIENT );
1460 op.setDefaultNodeFill( NodeFill.NONE );
1463 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
1467 static void cycleNodeShape( final Options op, final TreePanel tree_panel ) {
1468 switch ( op.getDefaultNodeShape() ) {
1470 op.setDefaultNodeShape( NodeShape.RECTANGLE );
1473 op.setDefaultNodeShape( NodeShape.CIRCLE );
1476 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
1480 static void cycleOverview( final Options op, final TreePanel tree_panel ) {
1481 switch ( op.getOvPlacement() ) {
1483 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1486 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
1489 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
1492 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
1495 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
1497 if ( tree_panel != null ) {
1498 tree_panel.updateOvSettings();
1502 static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
1503 if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
1504 mi.setText( "Cycle Node Shape Fill Type... (current: "
1505 + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
1508 mi.setText( "Cycle Node Shape Fill Type..." );
1512 static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
1513 if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
1514 mi.setText( "Cycle Node Shape Fill Type... (current: "
1515 + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
1518 mi.setText( "Cycle Node Shape Fill Type..." );
1522 static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
1523 if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
1524 mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
1527 mi.setText( "Cycle Overview Placement..." );
1531 static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
1532 if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
1533 mi.setText( "Select Colors... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName() + ")" );
1536 mi.setText( "Select Colors..." );
1540 static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
1541 mi.setText( "Select Font... (current: " + font_desc + ")" );
1544 static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
1545 if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
1546 mi.setEnabled( true );
1548 else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
1549 mi.setEnabled( true );
1552 mi.setEnabled( false );
1554 mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
1557 static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
1558 mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
1561 static void updateOptionsMenuDependingOnPhylogenyType( final MainPanel main_panel,
1562 final JCheckBoxMenuItem scale,
1563 final JCheckBoxMenuItem branch_lengths,
1564 final JRadioButtonMenuItem non_lined_up,
1565 final JRadioButtonMenuItem uniform_clado,
1566 final JRadioButtonMenuItem nonuniform_clado,
1567 final JCheckBoxMenuItem label_direction_cbmi ) {
1568 final TreePanel tree_panel = main_panel.getCurrentTreePanel();
1569 final ControlPanel control = main_panel.getControlPanel();
1570 final Options options = main_panel.getOptions();
1571 scale.setSelected( options.isShowScale() );
1572 branch_lengths.setSelected( options.isShowBranchLengthValues() );
1573 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1574 if ( ( tree_panel != null ) && ( !tree_panel.isPhyHasBranchLengths() ) ) {
1575 scale.setSelected( false );
1576 scale.setEnabled( false );
1577 branch_lengths.setSelected( false );
1578 branch_lengths.setEnabled( false );
1580 else if ( ( tree_panel != null ) && !control.isDrawPhylogram() ) {
1581 scale.setSelected( false );
1582 scale.setEnabled( false );
1583 branch_lengths.setEnabled( true );
1586 scale.setEnabled( true );
1587 branch_lengths.setEnabled( true );
1589 if ( ( tree_panel != null )
1590 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
1591 && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1592 .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1593 branch_lengths.setSelected( false );
1594 branch_lengths.setEnabled( false );
1596 if ( tree_panel != null ) {
1597 if ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1598 || ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
1599 non_lined_up.setEnabled( false );
1600 uniform_clado.setEnabled( false );
1601 nonuniform_clado.setEnabled( false );
1604 non_lined_up.setEnabled( true );
1605 uniform_clado.setEnabled( true );
1606 nonuniform_clado.setEnabled( true );
1610 if ( ( tree_panel != null )
1611 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1612 .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1613 branch_lengths.setSelected( false );
1614 branch_lengths.setEnabled( false );
1616 if ( ( tree_panel != null )
1617 && ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( tree_panel
1618 .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
1619 non_lined_up.setEnabled( false );
1622 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1623 non_lined_up.setEnabled( true );
1626 label_direction_cbmi.setEnabled( true );
1627 if ( tree_panel != null ) {
1628 if ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1629 && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1630 label_direction_cbmi.setEnabled( false );
1632 if ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1633 scale.setSelected( false );
1634 scale.setEnabled( false );
1639 static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
1640 for( final TreePanel tree_panel : treepanels ) {
1641 tree_panel.setTextAntialias();