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: www.phylosoft.org/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 = "Show Node Shapes";
105 static final String SHOW_OVERVIEW_LABEL = "Show Overview";
106 static final String FONT_SIZE_MENU_LABEL = "Font Size";
107 static final String NONUNIFORM_CLADOGRAMS_LABEL = "External Node Sum Dependent Cladograms";
108 static final String SHOW_DOMAIN_LABELS_LABEL = "Show Domain Labels";
109 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";
110 static final String ABBREV_SN_LABEL = "Abbreviate Scientific Taxonomic Names";
111 static final String TAXONOMY_COLORIZE_NODE_SHAPES_LABEL = "Colorize Node Shapes According to Taxonomy";
112 static final String CYCLE_NODE_SHAPE_LABEL = "Cycle Node Shapes";
113 static final String CYCLE_NODE_FILL_LABEL = "Cycle Node Fill Type";
114 static final String CHOOSE_NODE_SIZE_LABEL = "Choose Node Shape Size";
115 static final String SHOW_CONF_STDDEV_LABEL = "Show Confidence Standard Deviations";
116 static final String USE_BRACKETS_FOR_CONF_IN_NH_LABEL = "Use Brackets for Confidence Values";
117 static final String USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL = "Use Internal Node Names for Confidence Values";
122 JMenu _options_jmenu;
123 JMenu _font_size_menu;
125 JMenuItem[] _load_phylogeny_from_webservice_menu_items;
127 JMenuItem _open_item;
128 JMenuItem _open_url_item;
129 JMenuItem _save_item;
130 JMenuItem _save_all_item;
131 JMenuItem _close_item;
132 JMenuItem _exit_item;
135 JMenuItem _midpoint_root_item;
136 JMenuItem _taxcolor_item;
137 JMenuItem _confcolor_item;
138 JMenuItem _color_rank_jmi;
139 JMenuItem _collapse_species_specific_subtrees;
140 JMenuItem _collapse_below_threshold; //TODO implememt me
141 JMenuItem _obtain_detailed_taxonomic_information_jmi;
142 JMenuItem _obtain_detailed_taxonomic_information_deleting_jmi;
143 JMenuItem _obtain_seq_information_jmi;
144 JMenuItem _move_node_names_to_tax_sn_jmi;
145 JMenuItem _move_node_names_to_seq_names_jmi;
146 JMenuItem _extract_tax_code_from_node_names_jmi;
147 JMenuItem _annotate_item;
149 JMenuItem _super_tiny_fonts_item;
150 JMenuItem _tiny_fonts_item;
151 JMenuItem _small_fonts_item;
152 JMenuItem _medium_fonts_item;
153 JMenuItem _large_fonts_item;
155 // _ screen and print
156 JMenuItem _choose_font_mi;
157 JMenuItem _switch_colors_mi;
158 JCheckBoxMenuItem _label_direction_cbmi;
160 JCheckBoxMenuItem _screen_antialias_cbmi;
161 JCheckBoxMenuItem _background_gradient_cbmi;
162 JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
163 JRadioButtonMenuItem _uniform_cladograms_rbmi;
164 JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
165 JCheckBoxMenuItem _show_branch_length_values_cbmi;
166 JCheckBoxMenuItem _show_scale_cbmi; //TODO fix me
167 JCheckBoxMenuItem _show_overview_cbmi;
168 JCheckBoxMenuItem _show_domain_labels;
169 JCheckBoxMenuItem _abbreviate_scientific_names;
170 JCheckBoxMenuItem _color_labels_same_as_parent_branch;
171 JMenuItem _overview_placment_mi;
172 JMenuItem _choose_minimal_confidence_mi;
173 JCheckBoxMenuItem _show_default_node_shapes_cbmi;
174 JMenuItem _cycle_node_shape_mi;
175 JMenuItem _cycle_node_fill_mi;
176 JMenuItem _choose_node_size_mi;
177 JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
178 JCheckBoxMenuItem _show_confidence_stddev_cbmi;
180 JCheckBoxMenuItem _graphics_export_visible_only_cbmi;
181 JCheckBoxMenuItem _antialias_print_cbmi;
182 JCheckBoxMenuItem _print_black_and_white_cbmi;
183 JCheckBoxMenuItem _print_using_actual_size_cbmi;
184 JCheckBoxMenuItem _graphics_export_using_actual_size_cbmi;
185 JMenuItem _print_size_mi;
186 JMenuItem _choose_pdf_width_mi;
188 JCheckBoxMenuItem _internal_number_are_confidence_for_nh_parsing_cbmi;
189 JRadioButtonMenuItem _extract_taxonomy_no_rbmi;
190 JRadioButtonMenuItem _extract_taxonomy_yes_rbmi;
191 JRadioButtonMenuItem _extract_taxonomy_pfam_rbmi;
192 JCheckBoxMenuItem _replace_underscores_cbmi;
193 JCheckBoxMenuItem _use_brackets_for_conf_in_nh_export_cbmi;
194 JCheckBoxMenuItem _use_internal_names_for_conf_in_nh_export_cbmi;
196 JCheckBoxMenuItem _search_case_senstive_cbmi;
197 JCheckBoxMenuItem _search_whole_words_only_cbmi;
198 JCheckBoxMenuItem _inverse_search_result_cbmi;
201 JCheckBoxMenuItem _rectangular_type_cbmi;
202 JCheckBoxMenuItem _triangular_type_cbmi;
203 JCheckBoxMenuItem _curved_type_cbmi;
204 JCheckBoxMenuItem _convex_type_cbmi;
205 JCheckBoxMenuItem _euro_type_cbmi;
206 JCheckBoxMenuItem _rounded_type_cbmi;
207 JCheckBoxMenuItem _unrooted_type_cbmi;
208 JCheckBoxMenuItem _circular_type_cbmi;
209 // view as text menu:
210 JMenuItem _view_as_NH_item;
211 JMenuItem _view_as_NHX_item;
212 JMenuItem _view_as_XML_item;
213 JMenuItem _view_as_nexus_item;
214 JMenuItem _display_basic_information_item;
216 JMenuItem _about_item;
217 JMenuItem _help_item;
218 JMenuItem _website_item;
219 JMenuItem _phyloxml_website_item;
220 JMenuItem _phyloxml_ref_item;
221 JMenuItem _aptx_ref_item;
224 // Handy pointers to child components:
225 MainPanel _mainpanel;
226 Container _contentpane;
227 final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>(); ;
228 Configuration _configuration;
229 JMenuItem _remove_branch_color_item;
231 InferenceManager _inference_manager;
232 final ProcessPool _process_pool;
233 private String _previous_node_annotation_ref;
236 _process_pool = ProcessPool.createInstance();
243 public void actionPerformed( final ActionEvent e ) {
244 final Object o = e.getSource();
245 boolean is_applet = false;
246 JApplet applet = null;
247 if ( getCurrentTreePanel() != null ) {
248 is_applet = getCurrentTreePanel().isApplet();
250 applet = getCurrentTreePanel().obtainApplet();
253 if ( o == _open_url_item ) {
254 readPhylogeniesFromURL();
256 else if ( o == _exit_item ) {
259 else if ( o == _taxcolor_item ) {
262 else if ( o == _confcolor_item ) {
265 else if ( o == _color_rank_jmi ) {
268 else if ( o == _collapse_species_specific_subtrees ) {
269 if ( isSubtreeDisplayed() ) {
272 if ( getCurrentTreePanel() != null ) {
273 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
276 else if ( o == _remove_branch_color_item ) {
277 if ( isSubtreeDisplayed() ) {
280 removeBranchColors();
282 else if ( o == _midpoint_root_item ) {
283 if ( isSubtreeDisplayed() ) {
288 else if ( o == _annotate_item ) {
291 else if ( o == _switch_colors_mi ) {
294 else if ( o == _display_basic_information_item ) {
295 displayBasicInformation();
297 else if ( o == _view_as_NH_item ) {
300 else if ( o == _view_as_NHX_item ) {
303 else if ( o == _view_as_XML_item ) {
306 else if ( o == _view_as_nexus_item ) {
309 else if ( o == _super_tiny_fonts_item ) {
310 if ( getCurrentTreePanel() != null ) {
311 getCurrentTreePanel().setSuperTinyFonts();
312 getCurrentTreePanel().repaint();
315 else if ( o == _tiny_fonts_item ) {
316 if ( getCurrentTreePanel() != null ) {
317 getCurrentTreePanel().setTinyFonts();
318 getCurrentTreePanel().repaint();
321 else if ( o == _small_fonts_item ) {
322 if ( getCurrentTreePanel() != null ) {
323 getCurrentTreePanel().setSmallFonts();
324 getCurrentTreePanel().repaint();
327 else if ( o == _medium_fonts_item ) {
328 if ( getCurrentTreePanel() != null ) {
329 getCurrentTreePanel().setMediumFonts();
330 getCurrentTreePanel().repaint();
333 else if ( o == _large_fonts_item ) {
334 if ( getCurrentTreePanel() != null ) {
335 getCurrentTreePanel().setLargeFonts();
336 getCurrentTreePanel().repaint();
339 else if ( o == _choose_font_mi ) {
342 else if ( o == _choose_minimal_confidence_mi ) {
343 chooseMinimalConfidence();
345 else if ( o == _choose_node_size_mi ) {
346 chooseNodeSize( getOptions(), this );
348 else if ( o == _overview_placment_mi ) {
349 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
351 else if ( o == _cycle_node_fill_mi ) {
352 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
354 else if ( o == _cycle_node_shape_mi ) {
355 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
357 else if ( o == _screen_antialias_cbmi ) {
358 updateOptions( getOptions() );
359 updateScreenTextAntialias( getMainPanel().getTreePanels() );
361 else if ( o == _background_gradient_cbmi ) {
362 updateOptions( getOptions() );
364 else if ( o == _show_domain_labels ) {
365 updateOptions( getOptions() );
367 else if ( o == _abbreviate_scientific_names ) {
368 updateOptions( getOptions() );
370 else if ( o == _color_labels_same_as_parent_branch ) {
371 updateOptions( getOptions() );
373 else if ( o == _show_default_node_shapes_cbmi ) {
374 updateOptions( getOptions() );
376 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
377 updateOptions( getOptions() );
379 else if ( o == _non_lined_up_cladograms_rbmi ) {
380 updateOptions( getOptions() );
383 else if ( o == _uniform_cladograms_rbmi ) {
384 updateOptions( getOptions() );
387 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
388 updateOptions( getOptions() );
391 else if ( o == _search_case_senstive_cbmi ) {
392 updateOptions( getOptions() );
393 getMainPanel().getControlPanel().search();
395 else if ( o == _search_whole_words_only_cbmi ) {
396 updateOptions( getOptions() );
397 getMainPanel().getControlPanel().search();
399 else if ( o == _inverse_search_result_cbmi ) {
400 updateOptions( getOptions() );
401 getMainPanel().getControlPanel().search();
403 else if ( o == _show_scale_cbmi ) {
404 updateOptions( getOptions() );
406 else if ( o == _show_branch_length_values_cbmi ) {
407 updateOptions( getOptions() );
409 else if ( o == _show_confidence_stddev_cbmi ) {
410 updateOptions( getOptions() );
412 else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
413 if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
414 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
416 updateOptions( getOptions() );
418 else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
419 if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
420 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
422 updateOptions( getOptions() );
424 else if ( o == _label_direction_cbmi ) {
425 updateOptions( getOptions() );
427 else if ( o == _show_overview_cbmi ) {
428 updateOptions( getOptions() );
429 if ( getCurrentTreePanel() != null ) {
430 getCurrentTreePanel().updateOvSizes();
433 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
434 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
435 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
438 else if ( o == _about_item ) {
441 else if ( o == _help_item ) {
442 help( getConfiguration().getWebLinks() );
444 else if ( o == _website_item ) {
446 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, is_applet, applet );
448 catch ( final IOException e1 ) {
449 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
452 else if ( o == _phyloxml_website_item ) {
454 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, is_applet, applet );
456 catch ( final IOException e1 ) {
457 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
460 else if ( o == _aptx_ref_item ) {
462 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, is_applet, applet );
464 catch ( final IOException e1 ) {
465 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
468 else if ( o == _phyloxml_ref_item ) {
470 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, is_applet, applet );
472 catch ( final IOException e1 ) {
473 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
477 if ( _load_phylogeny_from_webservice_menu_items != null ) {
478 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
479 if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
480 readPhylogeniesFromWebservice( i );
485 _contentpane.repaint();
488 public Configuration getConfiguration() {
489 return _configuration;
492 public InferenceManager getInferenceManager() {
493 return _inference_manager;
496 public MainPanel getMainPanel() {
500 public Options getOptions() {
504 public ProcessPool getProcessPool() {
505 return _process_pool;
508 public void showTextFrame( final String s, final String title ) {
510 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
513 public void showWhole() {
514 _mainpanel.getControlPanel().showWhole();
517 public void updateProcessMenu() {
518 // In general Swing is not thread safe.
519 // See "Swing's Threading Policy".
520 SwingUtilities.invokeLater( new Runnable() {
524 doUpdateProcessMenu();
529 void activateSaveAllIfNeeded() {
530 if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
531 _save_all_item.setEnabled( true );
534 _save_all_item.setEnabled( false );
538 void buildFileMenu() {
539 _file_jmenu = createMenu( "File", getConfiguration() );
540 _file_jmenu.add( _open_url_item = new JMenuItem( "Read tree from URL/webservice..." ) );
541 _file_jmenu.addSeparator();
542 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
543 customizeJMenuItem( _open_url_item );
544 customizeJMenuItem( _exit_item );
545 _jmenubar.add( _file_jmenu );
548 void buildFontSizeMenu() {
549 _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
550 _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
551 _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
552 _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
553 _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
554 _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
555 customizeJMenuItem( _super_tiny_fonts_item );
556 customizeJMenuItem( _tiny_fonts_item );
557 customizeJMenuItem( _small_fonts_item );
558 customizeJMenuItem( _medium_fonts_item );
559 customizeJMenuItem( _large_fonts_item );
560 _jmenubar.add( _font_size_menu );
563 void buildHelpMenu() {
564 _help_jmenu = createMenu( "Help", getConfiguration() );
565 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
566 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
567 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
568 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
569 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
570 _help_jmenu.addSeparator();
571 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
572 customizeJMenuItem( _help_item );
573 customizeJMenuItem( _website_item );
574 customizeJMenuItem( _phyloxml_website_item );
575 customizeJMenuItem( _aptx_ref_item );
576 customizeJMenuItem( _phyloxml_ref_item );
577 customizeJMenuItem( _about_item );
578 _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
579 _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
580 _jmenubar.add( _help_jmenu );
583 void buildTypeMenu() {
584 _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
585 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
586 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
587 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
588 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
589 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
590 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
591 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
592 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
593 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
594 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
595 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
596 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
597 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
598 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
599 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
600 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
601 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
602 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
603 initializeTypeMenu( getOptions() );
604 _jmenubar.add( _type_menu );
607 void buildViewMenu() {
608 _view_jmenu = createMenu( "View", getConfiguration() );
609 _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
610 _view_jmenu.addSeparator();
611 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
612 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
613 _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
614 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
615 customizeJMenuItem( _display_basic_information_item );
616 customizeJMenuItem( _view_as_NH_item );
617 customizeJMenuItem( _view_as_NHX_item );
618 customizeJMenuItem( _view_as_XML_item );
619 customizeJMenuItem( _view_as_nexus_item );
620 _jmenubar.add( _view_jmenu );
623 void checkTextFrames() {
624 if ( _textframes.size() > 5 ) {
626 if ( _textframes.getFirst() != null ) {
627 _textframes.getFirst().removeMe();
630 _textframes.removeFirst();
633 catch ( final NoSuchElementException e ) {
640 removeAllTextFrames();
641 if ( _mainpanel != null ) {
642 _mainpanel.terminate();
644 if ( _contentpane != null ) {
645 _contentpane.removeAll();
652 if ( _mainpanel.getCurrentTreePanel() != null ) {
653 final String[] ranks = AptxUtil.getAllPossibleRanks();
654 final String rank = ( String ) JOptionPane
655 .showInputDialog( this,
656 "What rank should the colorization be based on",
658 JOptionPane.QUESTION_MESSAGE,
662 if ( !ForesterUtil.isEmpty( rank ) ) {
663 _mainpanel.getCurrentTreePanel().colorRank( rank );
669 if ( _mainpanel.getCurrentTreePanel() != null ) {
670 _mainpanel.getCurrentTreePanel().confColor();
674 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
675 if ( item != null ) {
676 item.setFont( MainFrame.menu_font );
677 if ( !getConfiguration().isUseNativeUI() ) {
678 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
679 item.setForeground( getConfiguration().getGuiMenuTextColor() );
681 item.setSelected( is_selected );
682 item.addActionListener( this );
686 JMenuItem customizeJMenuItem( final JMenuItem jmi ) {
688 jmi.setFont( MainFrame.menu_font );
689 if ( !getConfiguration().isUseNativeUI() ) {
690 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
691 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
693 jmi.addActionListener( this );
698 void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
699 if ( item != null ) {
700 item.setFont( MainFrame.menu_font );
701 if ( !getConfiguration().isUseNativeUI() ) {
702 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
703 item.setForeground( getConfiguration().getGuiMenuTextColor() );
705 item.setSelected( is_selected );
706 item.addActionListener( this );
710 void displayBasicInformation() {
711 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
712 String title = "Basic Information";
713 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
714 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
716 showTextFrame( AptxUtil.createBasicInformation( _mainpanel.getCurrentPhylogeny() ), title );
720 void exceptionOccuredDuringOpenFile( final Exception e ) {
722 _mainpanel.getCurrentTreePanel().setArrowCursor();
724 catch ( final Exception ex ) {
727 JOptionPane.showMessageDialog( this,
728 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
729 "Error during File|Open",
730 JOptionPane.ERROR_MESSAGE );
733 void exceptionOccuredDuringSaveAs( final Exception e ) {
735 _mainpanel.getCurrentTreePanel().setArrowCursor();
737 catch ( final Exception ex ) {
740 JOptionPane.showMessageDialog( this, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );
743 boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
744 if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
745 JOptionPane.showMessageDialog( this,
746 "Gene tree and species tree have no species in common.",
748 JOptionPane.ERROR_MESSAGE );
751 else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
752 JOptionPane.showMessageDialog( this,
753 "Gene tree and species tree have only one species in common.",
755 JOptionPane.ERROR_MESSAGE );
763 TreePanel getCurrentTreePanel() {
764 return getMainPanel().getCurrentTreePanel();
767 JMenu getHelpMenu() {
771 JCheckBoxMenuItem getlabelDirectionCbmi() {
772 return _label_direction_cbmi;
775 JMenuBar getMenuBarOfMainFrame() {
779 void help( final Map<String, WebLink> weblinks ) {
780 final StringBuilder sb = new StringBuilder();
781 sb.append( "Display options\n" );
782 sb.append( "-------------------\n" );
783 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
784 sb.append( "Clickable tree nodes\n" );
785 sb.append( "--------------------\n" );
786 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
787 sb.append( "or by right clicking:\n" );
788 sb.append( "o Display Node Data -- display information for a node\n" );
789 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
790 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
791 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
792 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
793 sb.append( "o Colorize Subtree -- color a subtree\n" );
794 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
795 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
796 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
797 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
798 sb.append( "Zooming\n" );
799 sb.append( "---------\n" );
800 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
801 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
802 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
803 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
804 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
805 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
806 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
807 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
808 sb.append( "Quick tree manipulation:\n" );
809 sb.append( "------------------------\n" );
810 sb.append( "Order Subtrees -- order the tree by branch length\n" );
811 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
812 sb.append( "Memory problems (Java heap space error)\n" );
813 sb.append( "---------------------------------------\n" );
814 sb.append( "Since the Java default memory allocation is quite small, it might by necessary (for trees\n" );
815 sb.append( "with more than approximately 5000 external nodes) to increase the memory which Java can use, with\n" );
816 sb.append( "the '-Xmx' Java command line option. For example:\n" );
817 sb.append( "java -Xms32m -Xmx256m -cp path\\to\\forester.jar org.forester.archaeopteryx.Archaeopteryx\n\n" );
818 if ( ( weblinks != null ) && ( weblinks.size() > 0 ) ) {
819 sb.append( "Active web links\n" );
820 sb.append( "--------------------\n" );
821 for( final String key : weblinks.keySet() ) {
822 sb.append( " " + weblinks.get( key ).toString() + "\n" );
825 // + "General remarks\n"
826 // + "---------------\n"
828 // "o The application version permits copying to the clipboard \n"
830 // " in the \"View\"|\"View as ...\" frame (either by control-c or button press).\n"
832 // "o Changes made to a subtree affect this subtree and its subtrees,\n"
833 // + " but not any of its parent tree(s).\n"
835 // "o Archaeopteryx tries to detect whether the numerical values in a NH tree\n"
837 // " are likely to be bootstrap values instead of branch length values.\n\n"
839 // " Remarks regarding SDI (Speciation Duplication Inference):\n"
841 // "o Each external node of the gene tree (in display) needs to be associated with\n"
843 // " a species: either directly through the \"Species\" field, or the species\n"
845 // " is part of the sequence name in the form \"XXXX_SPECIES\"\n"
847 // " (e.g. \"ACON_DROME\" or \"ACON_DROME/123-4489\" which is also acceptable).\n"
849 // "o A species tree for each species of the gene tree needs to be loaded with\n"
851 // " \"SDI\"|\"Load species tree\" prior the SDI execution.\n"
853 // "o !External nodes of the gene tree associated with species not present in\n"
855 // " the species tree are REMOVED prior to SDI execution!\n"
857 // "o Both the gene tree and the species tree must be completely binary.\n"
859 // "o Duplications and speciations are a function of the position of the root.\n"
861 // " Hence, after each manual \"Root/Reroot\"ing some duplications will be\n"
862 // + " incorrect and need to be inferred again\n"
864 // " with: \"SDI\"|\"SDI (Speciation Duplication Inference)\n\n"
866 sb.append( "phyloXML\n" );
867 sb.append( "-------------------\n" );
868 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
869 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
870 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
872 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
873 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
874 TextFrame.instantiate( sb.toString(), "Help", _textframes );
877 void initializeTypeMenu( final Options options ) {
878 setTypeMenuToAllUnselected();
879 switch ( options.getPhylogenyGraphicsType() ) {
881 _convex_type_cbmi.setSelected( true );
884 _curved_type_cbmi.setSelected( true );
887 _euro_type_cbmi.setSelected( true );
890 _rounded_type_cbmi.setSelected( true );
893 _triangular_type_cbmi.setSelected( true );
896 _unrooted_type_cbmi.setSelected( true );
899 _circular_type_cbmi.setSelected( true );
902 _rectangular_type_cbmi.setSelected( true );
907 boolean isSubtreeDisplayed() {
908 if ( getCurrentTreePanel() != null ) {
909 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
911 .showMessageDialog( this,
912 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
913 "Operation can not be exectuted on a sub-tree",
914 JOptionPane.WARNING_MESSAGE );
921 void midpointRoot() {
922 if ( _mainpanel.getCurrentTreePanel() != null ) {
923 _mainpanel.getCurrentTreePanel().midpointRoot();
927 abstract void readPhylogeniesFromURL();
929 void readPhylogeniesFromWebservice( final int i ) {
930 final UrlTreeReader reader = new UrlTreeReader( this, i );
931 new Thread( reader ).start();
934 void removeAllTextFrames() {
935 for( final TextFrame tf : _textframes ) {
943 void setConfiguration( final Configuration configuration ) {
944 _configuration = configuration;
947 void setInferenceManager( final InferenceManager i ) {
948 _inference_manager = i;
951 void setOptions( final Options options ) {
955 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
956 setTypeMenuToAllUnselected();
959 _circular_type_cbmi.setSelected( true );
962 _convex_type_cbmi.setSelected( true );
965 _curved_type_cbmi.setSelected( true );
968 _euro_type_cbmi.setSelected( true );
971 _rounded_type_cbmi.setSelected( true );
974 _rectangular_type_cbmi.setSelected( true );
977 _triangular_type_cbmi.setSelected( true );
980 _unrooted_type_cbmi.setSelected( true );
983 throw new IllegalArgumentException( "unknown type: " + type );
987 void setTypeMenuToAllUnselected() {
988 _convex_type_cbmi.setSelected( false );
989 _curved_type_cbmi.setSelected( false );
990 _euro_type_cbmi.setSelected( false );
991 _rounded_type_cbmi.setSelected( false );
992 _triangular_type_cbmi.setSelected( false );
993 _rectangular_type_cbmi.setSelected( false );
994 _unrooted_type_cbmi.setSelected( false );
995 _circular_type_cbmi.setSelected( false );
998 void switchColors() {
999 final TreeColorSet colorset = _mainpanel.getTreeColorSet();
1000 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1001 csc.setVisible( true );
1005 if ( _mainpanel.getCurrentTreePanel() != null ) {
1006 _mainpanel.getCurrentTreePanel().taxColor();
1010 void typeChanged( final Object o ) {
1011 updateTypeCheckboxes( getOptions(), o );
1012 updateOptions( getOptions() );
1013 if ( getCurrentTreePanel() != null ) {
1014 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1015 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1016 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1017 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1018 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1019 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1020 getCurrentTreePanel().getControlPanel().showWhole();
1022 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1023 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1026 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1028 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1029 updateScreenTextAntialias( getMainPanel().getTreePanels() );
1030 if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
1031 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1032 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
1035 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
1041 void updateOptions( final Options options ) {
1042 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1043 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1044 && _background_gradient_cbmi.isSelected() );
1045 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1046 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1047 && _abbreviate_scientific_names.isSelected() );
1048 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1049 && _color_labels_same_as_parent_branch.isSelected() );
1050 options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null )
1051 && _show_default_node_shapes_cbmi.isSelected() );
1052 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1053 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1054 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1055 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1057 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1058 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1060 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1061 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1063 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1064 && _search_case_senstive_cbmi.isSelected() );
1065 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1066 options.setShowScale( _show_scale_cbmi.isSelected() );
1068 if ( _label_direction_cbmi != null ) {
1069 if ( _label_direction_cbmi.isSelected() ) {
1070 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1073 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1076 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1077 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1078 && _show_confidence_stddev_cbmi.isSelected() );
1079 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1080 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1082 options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
1083 && ( _print_using_actual_size_cbmi.isSelected() ) );
1084 options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
1085 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
1086 options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1087 if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1088 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1089 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1091 else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1092 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1093 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1096 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1098 options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1099 && _print_black_and_white_cbmi.isSelected() );
1100 options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1101 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1102 if ( ( _extract_taxonomy_yes_rbmi != null ) && _extract_taxonomy_yes_rbmi.isSelected() ) {
1103 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.YES );
1105 else if ( ( _extract_taxonomy_pfam_rbmi != null ) && _extract_taxonomy_pfam_rbmi.isSelected() ) {
1106 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
1108 else if ( ( _extract_taxonomy_no_rbmi != null ) && _extract_taxonomy_no_rbmi.isSelected() ) {
1109 options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.NO );
1111 options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1112 && _replace_underscores_cbmi.isSelected() );
1113 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1114 && _search_whole_words_only_cbmi.isSelected() );
1115 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1116 && _inverse_search_result_cbmi.isSelected() );
1117 if ( _graphics_export_visible_only_cbmi != null ) {
1118 options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1119 if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1120 _graphics_export_using_actual_size_cbmi.setSelected( true );
1121 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1124 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1127 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1128 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1130 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1131 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1133 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1134 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1136 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1137 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1139 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1140 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1142 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1143 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1145 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1146 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1148 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1149 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1153 void updateTypeCheckboxes( final Options options, final Object o ) {
1154 setTypeMenuToAllUnselected();
1155 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1158 void viewAsNexus() {
1159 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1160 String title = "Nexus";
1161 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1162 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1164 showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
1170 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1171 String title = "New Hampshire";
1172 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1173 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1175 showTextFrame( _mainpanel.getCurrentPhylogeny()
1176 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1182 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1183 String title = "NHX";
1184 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1185 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1187 showTextFrame( _mainpanel.getCurrentPhylogeny().toNewHampshireX(), title );
1192 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1193 String title = "phyloXML";
1194 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1195 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1197 showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
1201 private void annotateSequences() {
1202 if ( getCurrentTreePanel() != null ) {
1203 final Set<Integer> nodes = getCurrentTreePanel().getFoundNodes();
1204 if ( ( nodes == null ) || nodes.isEmpty() ) {
1206 .showMessageDialog( this,
1207 "Need to select nodes, either via direct selection or via the \"Search\" function",
1208 "No nodes selected for annotation",
1209 JOptionPane.ERROR_MESSAGE );
1212 final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
1213 if ( ( phy != null ) && !phy.isEmpty() ) {
1214 final JTextField ref_field = new JTextField( 10 );
1215 final JTextField desc_filed = new JTextField( 20 );
1216 ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
1217 : getPreviousNodeAnnotationReference() );
1218 final JPanel my_panel = new JPanel();
1219 my_panel.add( new JLabel( "Reference " ) );
1220 my_panel.add( ref_field );
1221 my_panel.add( Box.createHorizontalStrut( 15 ) );
1222 my_panel.add( new JLabel( "Description " ) );
1223 my_panel.add( desc_filed );
1224 final int result = JOptionPane.showConfirmDialog( null,
1226 "Enter the sequence annotation(s) for the "
1227 + nodes.size() + " selected nodes",
1228 JOptionPane.OK_CANCEL_OPTION );
1229 if ( result == JOptionPane.OK_OPTION ) {
1230 String ref = ref_field.getText();
1231 String desc = desc_filed.getText();
1232 if ( !ForesterUtil.isEmpty( ref ) ) {
1234 ref = ref.replaceAll( "\\s+", " " );
1235 if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 )
1236 || ( ref.length() < 3 ) ) {
1237 JOptionPane.showMessageDialog( this,
1238 "Reference needs to be in the form of \"GO:1234567\"",
1239 "Illegal Format for Annotation Reference",
1240 JOptionPane.ERROR_MESSAGE );
1244 if ( ref != null ) {
1245 setPreviousNodeAnnotationReference( ref );
1247 if ( desc != null ) {
1249 desc = desc.replaceAll( "\\s+", " " );
1251 if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
1252 for( final Integer id : nodes ) {
1253 final PhylogenyNode n = phy.getNode( id );
1254 ForesterUtil.ensurePresenceOfSequence( n );
1255 final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
1256 : new Annotation( ref );
1257 if ( !ForesterUtil.isEmpty( desc ) ) {
1258 ann.setDesc( desc );
1260 n.getNodeData().getSequence().addAnnotation( ann );
1263 getMainPanel().getControlPanel().showAnnotations();
1269 private String getPreviousNodeAnnotationReference() {
1270 return _previous_node_annotation_ref;
1273 private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
1274 _previous_node_annotation_ref = previous_node_annotation_ref;
1277 private void chooseFont() {
1278 final FontChooser fc = new FontChooser();
1279 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1280 fc.showDialog( this, "Select the Base Font" );
1281 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1284 private void chooseMinimalConfidence() {
1285 final String s = ( String ) JOptionPane
1286 .showInputDialog( this,
1287 "Please enter the minimum for confidence values to be displayed.\n"
1288 + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
1289 "Minimal Confidence Value",
1290 JOptionPane.QUESTION_MESSAGE,
1293 getOptions().getMinConfidenceValue() );
1294 if ( !ForesterUtil.isEmpty( s ) ) {
1295 boolean success = true;
1297 final String m_str = s.trim();
1298 if ( !ForesterUtil.isEmpty( m_str ) ) {
1300 m = Double.parseDouble( m_str );
1302 catch ( final Exception ex ) {
1309 if ( success && ( m >= 0.0 ) ) {
1310 getOptions().setMinConfidenceValue( m );
1315 private void doUpdateProcessMenu() {
1316 if ( _process_pool.size() > 0 ) {
1317 if ( _process_menu == null ) {
1318 _process_menu = createMenu( "", getConfiguration() );
1319 _process_menu.setForeground( Color.RED );
1321 _process_menu.removeAll();
1322 final String text = "processes running: " + _process_pool.size();
1323 _process_menu.setText( text );
1324 _jmenubar.add( _process_menu );
1325 for( int i = 0; i < _process_pool.size(); ++i ) {
1326 final ProcessRunning p = _process_pool.getProcessByIndex( i );
1327 _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
1331 if ( _process_menu != null ) {
1332 _process_menu.removeAll();
1333 _jmenubar.remove( _process_menu );
1336 _jmenubar.validate();
1337 _jmenubar.repaint();
1341 private void removeBranchColors() {
1342 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1343 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1348 * Display the about box.
1350 static void about() {
1351 final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" );
1352 about.append( "Copyright (C) 2007-2012 Christian M. Zmasek\n" );
1353 about.append( "All Rights Reserved\n" );
1354 about.append( "License: GNU Lesser General Public License (LGPL)\n" );
1355 about.append( "Last modified: " + Constants.PRG_DATE + "\n" );
1356 about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );
1357 about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1358 about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
1359 if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
1360 about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
1362 if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
1363 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
1364 about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
1365 + ForesterUtil.OS_VERSION + "]\n" );
1367 final Runtime rt = java.lang.Runtime.getRuntime();
1368 final long free_memory = rt.freeMemory() / 1000000;
1369 final long total_memory = rt.totalMemory() / 1000000;
1370 about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
1371 about.append( "[locale: " + Locale.getDefault() + "]\n" );
1372 about.append( "References:\n" );
1373 about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" );
1374 about.append( "For more information & download:\n" );
1375 about.append( Constants.APTX_WEB_SITE + "\n" );
1376 about.append( "Comments: " + Constants.AUTHOR_EMAIL );
1377 JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
1380 static void chooseNodeSize( final Options options, final Component parent ) {
1381 final String s = ( String ) JOptionPane.showInputDialog( parent,
1382 "Please enter the default size for node shapes.\n"
1383 + "[current value: "
1384 + options.getDefaultNodeShapeSize() + "]\n",
1386 JOptionPane.QUESTION_MESSAGE,
1389 options.getDefaultNodeShapeSize() );
1390 if ( !ForesterUtil.isEmpty( s ) ) {
1391 boolean success = true;
1393 final String m_str = s.trim();
1394 if ( !ForesterUtil.isEmpty( m_str ) ) {
1396 m = Double.parseDouble( m_str );
1398 catch ( final Exception ex ) {
1405 if ( success && ( m >= 0.0 ) ) {
1406 final short size = ForesterUtil.roundToShort( m );
1407 if ( size >= 0.0 ) {
1408 options.setDefaultNodeShapeSize( size );
1414 static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
1415 return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
1418 static JMenu createMenu( final String title, final Configuration conf ) {
1419 final JMenu jmenu = new JMenu( title );
1420 if ( !conf.isUseNativeUI() ) {
1421 jmenu.setFont( MainFrame.menu_font );
1422 jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
1423 jmenu.setForeground( conf.getGuiMenuTextColor() );
1428 static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
1429 label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
1430 if ( !configuration.isUseNativeUI() ) {
1431 label.setBackground( configuration.getGuiMenuBackgroundColor() );
1432 label.setForeground( configuration.getGuiMenuTextColor() );
1433 label.setOpaque( true );
1435 label.setSelected( false );
1436 label.setEnabled( false );
1440 static void cycleNodeFill( final Options op, final TreePanel tree_panel ) {
1441 switch ( op.getDefaultNodeFill() ) {
1443 op.setDefaultNodeFill( NodeFill.SOLID );
1446 op.setDefaultNodeFill( NodeFill.GRADIENT );
1449 op.setDefaultNodeFill( NodeFill.NONE );
1452 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
1456 static void cycleNodeShape( final Options op, final TreePanel tree_panel ) {
1457 switch ( op.getDefaultNodeShape() ) {
1459 op.setDefaultNodeShape( NodeShape.RECTANGLE );
1462 op.setDefaultNodeShape( NodeShape.CIRCLE );
1465 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
1469 static void cycleOverview( final Options op, final TreePanel tree_panel ) {
1470 switch ( op.getOvPlacement() ) {
1472 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1475 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
1478 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
1481 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
1484 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
1486 if ( tree_panel != null ) {
1487 tree_panel.updateOvSettings();
1491 static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
1492 if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
1493 mi.setText( "Cycle Node Shape Fill Type... (current: "
1494 + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
1497 mi.setText( "Cycle Node Shape Fill Type..." );
1501 static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
1502 if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
1503 mi.setText( "Cycle Node Shape Fill Type... (current: "
1504 + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
1507 mi.setText( "Cycle Node Shape Fill Type..." );
1511 static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
1512 if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
1513 mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
1516 mi.setText( "Cycle Overview Placement..." );
1520 static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
1521 if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
1522 mi.setText( "Select Colors... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName() + ")" );
1525 mi.setText( "Select Colors..." );
1529 static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
1530 mi.setText( "Select Font... (current: " + font_desc + ")" );
1533 static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
1534 if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
1535 mi.setEnabled( true );
1537 else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
1538 mi.setEnabled( true );
1541 mi.setEnabled( false );
1543 mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
1546 static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
1547 mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
1550 static void updateOptionsMenuDependingOnPhylogenyType( final MainPanel main_panel,
1551 final JCheckBoxMenuItem scale,
1552 final JCheckBoxMenuItem branch_lengths,
1553 final JRadioButtonMenuItem non_lined_up,
1554 final JRadioButtonMenuItem uniform_clado,
1555 final JRadioButtonMenuItem nonuniform_clado,
1556 final JCheckBoxMenuItem label_direction_cbmi ) {
1557 final TreePanel tree_panel = main_panel.getCurrentTreePanel();
1558 final ControlPanel control = main_panel.getControlPanel();
1559 final Options options = main_panel.getOptions();
1560 scale.setSelected( options.isShowScale() );
1561 branch_lengths.setSelected( options.isShowBranchLengthValues() );
1562 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1563 if ( ( tree_panel != null ) && ( !tree_panel.isPhyHasBranchLengths() ) ) {
1564 scale.setSelected( false );
1565 scale.setEnabled( false );
1566 branch_lengths.setSelected( false );
1567 branch_lengths.setEnabled( false );
1569 else if ( ( tree_panel != null ) && !control.isDrawPhylogram() ) {
1570 scale.setSelected( false );
1571 scale.setEnabled( false );
1572 branch_lengths.setEnabled( true );
1575 scale.setEnabled( true );
1576 branch_lengths.setEnabled( true );
1578 if ( ( tree_panel != null )
1579 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
1580 && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1581 .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1582 branch_lengths.setSelected( false );
1583 branch_lengths.setEnabled( false );
1585 if ( tree_panel != null ) {
1586 if ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1587 || ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
1588 non_lined_up.setEnabled( false );
1589 uniform_clado.setEnabled( false );
1590 nonuniform_clado.setEnabled( false );
1593 non_lined_up.setEnabled( true );
1594 uniform_clado.setEnabled( true );
1595 nonuniform_clado.setEnabled( true );
1599 if ( ( tree_panel != null )
1600 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1601 .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1602 branch_lengths.setSelected( false );
1603 branch_lengths.setEnabled( false );
1605 if ( ( tree_panel != null )
1606 && ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( tree_panel
1607 .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
1608 non_lined_up.setEnabled( false );
1611 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1612 non_lined_up.setEnabled( true );
1615 label_direction_cbmi.setEnabled( true );
1616 if ( tree_panel != null ) {
1617 if ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1618 && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1619 label_direction_cbmi.setEnabled( false );
1621 if ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1622 scale.setSelected( false );
1623 scale.setEnabled( false );
1628 static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
1629 for( final TreePanel tree_panel : treepanels ) {
1630 tree_panel.setTextAntialias();