minor improvements and bug-fixes
[jalview.git] / forester / java / src / org / forester / archaeopteryx / ControlPanel.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 //
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.
12 //
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.
17 //
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
21 //
22 // Contact: phylosoft @ gmail . com
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.archaeopteryx;
26
27 import java.awt.BorderLayout;
28 import java.awt.Color;
29 import java.awt.Component;
30 import java.awt.Dimension;
31 import java.awt.Font;
32 import java.awt.GridBagLayout;
33 import java.awt.GridLayout;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.awt.event.KeyAdapter;
39 import java.awt.event.KeyEvent;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.HashMap;
44 import java.util.HashSet;
45 import java.util.List;
46 import java.util.Map;
47 import java.util.Set;
48
49 import javax.swing.BorderFactory;
50 import javax.swing.DefaultListCellRenderer;
51 import javax.swing.JButton;
52 import javax.swing.JCheckBox;
53 import javax.swing.JComboBox;
54 import javax.swing.JLabel;
55 import javax.swing.JList;
56 import javax.swing.JPanel;
57 import javax.swing.JScrollBar;
58 import javax.swing.JTextField;
59 import javax.swing.ListCellRenderer;
60
61 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
62 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
63 import org.forester.phylogeny.Phylogeny;
64 import org.forester.phylogeny.PhylogenyMethods;
65 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
66 import org.forester.phylogeny.PhylogenyNode;
67 import org.forester.phylogeny.data.Sequence;
68 import org.forester.phylogeny.data.SequenceRelation;
69 import org.forester.phylogeny.data.SequenceRelation.SEQUENCE_RELATION_TYPE;
70 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
71 import org.forester.util.ForesterUtil;
72
73 final class ControlPanel extends JPanel implements ActionListener {
74
75     enum NodeClickAction {
76         ADD_NEW_NODE,
77         BLAST,
78         COLLAPSE,
79         COLOR_SUBTREE,
80         COPY_SUBTREE,
81         CUT_SUBTREE,
82         DELETE_NODE_OR_SUBTREE,
83         EDIT_NODE_DATA,
84         GET_EXT_DESC_DATA,
85         OPEN_PDB_WEB,
86         OPEN_SEQ_WEB,
87         OPEN_TAX_WEB,
88         PASTE_SUBTREE,
89         REROOT,
90         SELECT_NODES,
91         SHOW_DATA,
92         SORT_DESCENDENTS,
93         SUBTREE,
94         SWAP,
95         CHANGE_NODE_FONT,
96         COLOR_NODE_FONT;
97     }
98     final static Font                         jcb_bold_font             = new Font( Configuration.getDefaultFontFamilyName(),
99                                                                                     Font.BOLD,
100                                                                                     9 );
101     final static Font                         jcb_font                  = new Font( Configuration.getDefaultFontFamilyName(),
102                                                                                     Font.PLAIN,
103                                                                                     9 );
104     final static Font                         js_font                   = new Font( Configuration.getDefaultFontFamilyName(),
105                                                                                     Font.PLAIN,
106                                                                                     9 );
107     private static final String               RETURN_TO_SUPER_TREE_TEXT = "Back to Super Tree";
108     private static final String               SEARCH_TIP_TEXT           = "Enter text to search for. Use ',' for logical OR and '+' for logical AND (not used in this manner for regular expression searches).";
109     private static final long                 serialVersionUID          = -8463483932821545633L;
110     private NodeClickAction                   _action_when_node_clicked;
111     private int                               _add_new_node_item;
112     private Map<Integer, String>              _all_click_to_names;
113     private Map<String, Color>                _annotation_colors;
114     private int                               _blast_item;
115     private JComboBox<String>                 _click_to_combobox;
116     private JLabel                            _click_to_label;
117     private List<String>                      _click_to_names;
118     private int                               _collapse_cb_item;
119     private JCheckBox                         _color_acc_species;
120     private JCheckBox                         _color_acc_sequence;
121     private JCheckBox                         _color_according_to_annotation;
122     private boolean                           _color_branches;
123     private JCheckBox                         _use_visual_styles_cb;
124     private int                               _color_subtree_cb_item;
125     private int                               _change_node_font_item;
126     // The settings from the conf file
127     private final Configuration               _configuration;
128     private int                               _copy_subtree_item;
129     private int                               _cut_subtree_item;
130     private JButton                           _decr_domain_structure_evalue_thr;
131     private int                               _delete_node_or_subtree_item;
132     private JCheckBox                         _display_as_phylogram_cb;
133     // Tree checkboxes
134     private JCheckBox                         _display_internal_data;
135     private JLabel                            _domain_display_label;
136     private JTextField                        _domain_structure_evalue_thr_tf;
137     private List<Boolean>                     _draw_phylogram;
138     private JCheckBox                         _dynamically_hide_data;
139     private int                               _edit_node_data_item;
140     private int                               _get_ext_desc_data;
141     private JButton                           _incr_domain_structure_evalue_thr;
142     private final MainPanel                   _mainpanel;
143     private JCheckBox                         _node_desc_popup_cb;
144     private int                               _open_pdb_item;
145     private int                               _open_seq_web_item;
146     private int                               _open_tax_web_item;
147     private int                               _color_node_font_item;
148     private JButton                           _order;
149     private boolean                           _order_of_appearance;
150     private int                               _paste_subtree_item;
151     private int                               _reroot_cb_item;
152     private JButton                           _return_to_super_tree;
153     // Search
154     private JLabel                            _search_found_label_0;
155     private JLabel                            _search_found_label_1;
156     private JButton                           _search_reset_button_0;
157     private JButton                           _search_reset_button_1;
158     private JTextField                        _search_tf_0;
159     private JTextField                        _search_tf_1;
160     private int                               _select_nodes_item;
161     private Sequence                          _selected_query_seq;
162     private JCheckBox                         _seq_relation_confidence_switch;
163     private JComboBox<SEQUENCE_RELATION_TYPE> _sequence_relation_type_box;
164     private JCheckBox                         _show_annotation;
165     private JCheckBox                         _show_binary_character_counts;
166     private JCheckBox                         _show_binary_characters;
167     // Indices for the click-to options in the combo box
168     private int                               _show_data_item;
169     private JCheckBox                         _show_domain_architectures;
170     private JCheckBox                         _show_mol_seqs;
171     private JCheckBox                         _write_branch_length_values;
172     private JCheckBox                         _show_events;
173     private JCheckBox                         _show_gene_names;
174     private JCheckBox                         _show_node_names;
175     private JCheckBox                         _show_properties_cb;
176     private JCheckBox                         _show_seq_names;
177     private JCheckBox                         _show_seq_symbols;
178     private JCheckBox                         _show_sequence_acc;
179     private JComboBox<String>                 _show_sequence_relations;
180     private JCheckBox                         _show_taxo_code;
181     private JCheckBox                         _show_taxo_common_names;
182     private JCheckBox                         _show_taxo_images_cb;
183     private JCheckBox                         _show_taxo_scientific_names;
184     private JCheckBox                         _show_vector_data_cb;
185     private JButton                           _show_whole;
186     private int                               _sort_descendents_item;
187     private Map<String, Color>                _species_colors;
188     private Map<String, Color>                _sequence_colors;
189     private int                               _subtree_cb_item;
190     private int                               _swap_cb_item;
191     private JButton                           _uncollapse_all;
192     private JCheckBox                         _width_branches;
193     private JCheckBox                         _write_confidence;
194     private JButton                           _zoom_in_domain_structure;
195     private JButton                           _zoom_in_x;
196     private JButton                           _zoom_in_y;
197     private JLabel                            _zoom_label;
198     private JButton                           _zoom_out_domain_structure;
199     private JButton                           _zoom_out_x;
200     private JButton                           _zoom_out_y;
201
202     ControlPanel( final MainPanel ap, final Configuration configuration ) {
203         init();
204         _mainpanel = ap;
205         _configuration = configuration;
206         if ( !_configuration.isUseNativeUI() ) {
207             setBackground( getConfiguration().getGuiBackgroundColor() );
208             setBorder( BorderFactory.createRaisedBevelBorder() );
209         }
210         setLayout( new GridLayout( 0, 1, 2, 2 ) );
211         _order_of_appearance = true;
212         setupControls();
213     }
214
215     /**
216      * Handle an action.
217      */
218     @Override
219     public void actionPerformed( final ActionEvent e ) {
220         try {
221             if ( e.getSource() == _color_acc_sequence ) {
222                 if ( _color_acc_species != null ) {
223                     _color_acc_species.setSelected( false );
224                 }
225             }
226             else if ( e.getSource() == _color_acc_species ) {
227                 if ( _color_acc_sequence != null ) {
228                     _color_acc_sequence.setSelected( false );
229                 }
230             }
231             final TreePanel tp = getMainPanel().getCurrentTreePanel();
232             if ( tp == null ) {
233                 return;
234             }
235             if ( e.getSource() == _click_to_combobox ) {
236                 setClickToAction( _click_to_combobox.getSelectedIndex() );
237                 getCurrentTreePanel().repaint();
238             }
239             else if ( e.getSource() == _show_binary_characters ) {
240                 if ( ( _show_binary_character_counts != null ) && _show_binary_characters.isSelected() ) {
241                     _show_binary_character_counts.setSelected( false );
242                 }
243                 displayedPhylogenyMightHaveChanged( true );
244             }
245             else if ( e.getSource() == _show_binary_character_counts ) {
246                 if ( ( _show_binary_characters != null ) && _show_binary_character_counts.isSelected() ) {
247                     _show_binary_characters.setSelected( false );
248                 }
249                 displayedPhylogenyMightHaveChanged( true );
250             }
251             else if ( e.getSource() == _show_domain_architectures ) {
252                 search0();
253                 search1();
254                 displayedPhylogenyMightHaveChanged( true );
255             }
256             else if ( ( tp != null ) && ( tp.getPhylogeny() != null ) ) {
257                 if ( e.getSource() == getDisplayAsPhylogramCb() ) {
258                     setDrawPhylogram( getDisplayAsPhylogramCb().isSelected() );
259                     showWhole();
260                 }
261                 // Zoom buttons
262                 else if ( e.getSource() == _zoom_in_x ) {
263                     zoomInX( AptxConstants.BUTTON_ZOOM_IN_FACTOR, AptxConstants.BUTTON_ZOOM_IN_X_CORRECTION_FACTOR );
264                     displayedPhylogenyMightHaveChanged( false );
265                 }
266                 else if ( e.getSource() == _zoom_in_y ) {
267                     zoomInY( AptxConstants.BUTTON_ZOOM_IN_FACTOR );
268                     displayedPhylogenyMightHaveChanged( false );
269                 }
270                 else if ( e.getSource() == _zoom_out_x ) {
271                     zoomOutX( AptxConstants.BUTTON_ZOOM_OUT_FACTOR, AptxConstants.BUTTON_ZOOM_OUT_X_CORRECTION_FACTOR );
272                     displayedPhylogenyMightHaveChanged( false );
273                 }
274                 else if ( e.getSource() == _zoom_out_y ) {
275                     zoomOutY( AptxConstants.BUTTON_ZOOM_OUT_FACTOR );
276                     displayedPhylogenyMightHaveChanged( false );
277                 }
278                 else if ( e.getSource() == _show_whole ) {
279                     displayedPhylogenyMightHaveChanged( true );
280                     showWhole();
281                 }
282                 else if ( e.getSource() == _return_to_super_tree ) {
283                     _mainpanel.getCurrentTreePanel().superTree();
284                     showWhole();
285                 }
286                 else if ( e.getSource() == _order ) {
287                     DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
288                     if ( isShowTaxonomyScientificNames() || isShowTaxonomyCode() ) {
289                         pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
290                     }
291                     else if ( isShowSeqNames() || isShowSeqSymbols() || isShowGeneNames() ) {
292                         pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
293                     }
294                     PhylogenyMethods.orderAppearance( tp.getPhylogeny().getRoot(), _order_of_appearance, true, pri );
295                     _order_of_appearance = !_order_of_appearance;
296                     tp.setNodeInPreorderToNull();
297                     tp.getPhylogeny().externalNodesHaveChanged();
298                     tp.getPhylogeny().clearHashIdToNodeMap();
299                     tp.getPhylogeny().recalculateNumberOfExternalDescendants( true );
300                     tp.resetNodeIdToDistToLeafMap();
301                     tp.setEdited( true );
302                     displayedPhylogenyMightHaveChanged( true );
303                 }
304                 else if ( e.getSource() == _uncollapse_all ) {
305                     uncollapseAll( tp );
306                     displayedPhylogenyMightHaveChanged( false );
307                 }
308                 else if ( e.getSource() == _zoom_in_domain_structure ) {
309                     _mainpanel.getCurrentTreePanel().zoomInDomainStructure();
310                     displayedPhylogenyMightHaveChanged( true );
311                 }
312                 else if ( e.getSource() == _zoom_out_domain_structure ) {
313                     _mainpanel.getCurrentTreePanel().zoomOutDomainStructure();
314                     displayedPhylogenyMightHaveChanged( true );
315                 }
316                 else if ( e.getSource() == _decr_domain_structure_evalue_thr ) {
317                     _mainpanel.getCurrentTreePanel().decreaseDomainStructureEvalueThresholdExp();
318                     search0();
319                     search1();
320                     displayedPhylogenyMightHaveChanged( true );
321                 }
322                 else if ( e.getSource() == _incr_domain_structure_evalue_thr ) {
323                     _mainpanel.getCurrentTreePanel().increaseDomainStructureEvalueThresholdExp();
324                     search0();
325                     search1();
326                     displayedPhylogenyMightHaveChanged( true );
327                 }
328                 else if ( e.getSource() == _search_tf_0 ) {
329                     search0();
330                     displayedPhylogenyMightHaveChanged( true );
331                 }
332                 else if ( e.getSource() == _search_tf_1 ) {
333                     search1();
334                     displayedPhylogenyMightHaveChanged( true );
335                 }
336                 else if ( ( _dynamically_hide_data != null ) && ( e.getSource() == _dynamically_hide_data )
337                         && !_dynamically_hide_data.isSelected() ) {
338                     setDynamicHidingIsOn( false );
339                     displayedPhylogenyMightHaveChanged( true );
340                 }
341                 else {
342                     displayedPhylogenyMightHaveChanged( true );
343                 }
344             }
345             tp.requestFocus();
346             tp.requestFocusInWindow();
347             tp.requestFocus();
348         }
349         catch ( final Exception ex ) {
350             AptxUtil.unexpectedException( ex );
351         }
352         catch ( final Error err ) {
353             AptxUtil.unexpectedError( err );
354         }
355     }
356
357     public JCheckBox getColorAccSequenceCb() {
358         return _color_acc_sequence;
359     }
360
361     public JCheckBox getColorAccSpeciesCb() {
362         return _color_acc_species;
363     }
364
365     public JCheckBox getDisplayAsPhylogramCb() {
366         return _display_as_phylogram_cb;
367     }
368
369     public JCheckBox getDynamicallyHideData() {
370         return _dynamically_hide_data;
371     }
372
373     public JCheckBox getNodeDescPopupCb() {
374         return _node_desc_popup_cb;
375     }
376
377     public Sequence getSelectedQuerySequence() {
378         return _selected_query_seq;
379     }
380
381     public JComboBox<String> getSequenceRelationBox() {
382         if ( _show_sequence_relations == null ) {
383             _show_sequence_relations = new JComboBox<String>();
384             _show_sequence_relations.setFocusable( false );
385             _show_sequence_relations.setMaximumRowCount( 20 );
386             _show_sequence_relations.setFont( ControlPanel.js_font );
387             if ( !_configuration.isUseNativeUI() ) {
388                 _show_sequence_relations.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
389                 _show_sequence_relations.setForeground( getConfiguration().getGuiButtonTextColor() );
390             }
391             _show_sequence_relations.addItem( "-----" );
392             _show_sequence_relations.setToolTipText( "To display orthology information for selected query" );
393         }
394         return _show_sequence_relations;
395     }
396
397     /* GUILHEM_BEG */
398     public JComboBox<SEQUENCE_RELATION_TYPE> getSequenceRelationTypeBox() {
399         if ( _sequence_relation_type_box == null ) {
400             _sequence_relation_type_box = new JComboBox<SEQUENCE_RELATION_TYPE>();
401             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : SequenceRelation.SEQUENCE_RELATION_TYPE.values() ) {
402                 _sequence_relation_type_box.addItem( type );
403             }
404             _sequence_relation_type_box.addActionListener( new ActionListener() {
405
406                 @Override
407                 public void actionPerformed( final ActionEvent e ) {
408                     if ( _mainpanel.getCurrentPhylogeny() != null ) {
409                         setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
410                     }
411                 }
412             } );
413         }
414         return _sequence_relation_type_box;
415     }
416
417     public JCheckBox getShowEventsCb() {
418         return _show_events;
419     }
420
421     public JCheckBox getUseVisualStylesCb() {
422         return _use_visual_styles_cb;
423     }
424
425     public JCheckBox getWriteConfidenceCb() {
426         return _write_confidence;
427     }
428
429     public boolean isShowMolSequences() {
430         return ( ( _show_mol_seqs != null ) && _show_mol_seqs.isSelected() );
431     }
432
433     public boolean isShowProperties() {
434         return ( ( _show_properties_cb != null ) && _show_properties_cb.isSelected() );
435     }
436
437     public boolean isShowTaxonomyImages() {
438         return ( ( _show_taxo_images_cb != null ) && _show_taxo_images_cb.isSelected() );
439     }
440
441     public boolean isShowVectorData() {
442         return ( ( _show_vector_data_cb != null ) && _show_vector_data_cb.isSelected() );
443     }
444
445     public void setSequenceRelationQueries( final Collection<Sequence> sequenceRelationQueries ) {
446         final JComboBox<String> box = getSequenceRelationBox();
447         while ( box.getItemCount() > 1 ) {
448             box.removeItemAt( 1 );
449         }
450         final HashMap<String, Sequence> sequencesByName = new HashMap<String, Sequence>();
451         final SequenceRelation.SEQUENCE_RELATION_TYPE relationType = ( SequenceRelation.SEQUENCE_RELATION_TYPE ) _sequence_relation_type_box
452                 .getSelectedItem();
453         if ( relationType == null ) {
454             return;
455         }
456         final ArrayList<String> sequenceNamesToAdd = new ArrayList<String>();
457         for( final Sequence seq : sequenceRelationQueries ) {
458             if ( seq.isHasSequenceRelations() ) {
459                 boolean fFoundForCurrentType = false;
460                 for( final SequenceRelation sq : seq.getSequenceRelations() ) {
461                     if ( sq.getType().equals( relationType ) ) {
462                         fFoundForCurrentType = true;
463                         break;
464                     }
465                 }
466                 if ( fFoundForCurrentType ) {
467                     sequenceNamesToAdd.add( seq.getName() );
468                     sequencesByName.put( seq.getName(), seq );
469                 }
470             }
471         }
472         // sort sequences by name before adding them to the combo
473         final String[] sequenceNameArray = sequenceNamesToAdd.toArray( new String[ sequenceNamesToAdd.size() ] );
474         Arrays.sort( sequenceNameArray, String.CASE_INSENSITIVE_ORDER );
475         for( final String seqName : sequenceNameArray ) {
476             box.addItem( seqName );
477         }
478         for( final ItemListener oldItemListener : box.getItemListeners() ) {
479             box.removeItemListener( oldItemListener );
480         }
481         box.addItemListener( new ItemListener() {
482
483             @Override
484             public void itemStateChanged( final ItemEvent e ) {
485                 _selected_query_seq = sequencesByName.get( e.getItem() );
486                 _mainpanel.getCurrentTreePanel().repaint();
487             }
488         } );
489     }
490
491     private void addClickToOption( final int which, final String title ) {
492         _click_to_combobox.addItem( title );
493         _click_to_names.add( title );
494         _all_click_to_names.put( new Integer( which ), title );
495         if ( !_configuration.isUseNativeUI() ) {
496             _click_to_combobox.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
497             _click_to_combobox.setForeground( getConfiguration().getGuiButtonTextColor() );
498         }
499     }
500
501     /* GUILHEM_BEG */
502     private void addSequenceRelationBlock() {
503         final JLabel spacer = new JLabel( "" );
504         spacer.setSize( 1, 1 );
505         add( spacer );
506         final JLabel mainLabel = new JLabel( "Sequence relations to display" );
507         final JLabel typeLabel = customizeLabel( new JLabel( "(type) " ), getConfiguration() );
508         typeLabel.setFont( ControlPanel.js_font.deriveFont( 7 ) );
509         getSequenceRelationTypeBox().setFocusable( false );
510         _sequence_relation_type_box.setFont( ControlPanel.js_font );
511         if ( !_configuration.isUseNativeUI() ) {
512             _sequence_relation_type_box.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
513             _sequence_relation_type_box.setForeground( getConfiguration().getGuiButtonTextColor() );
514         }
515         _sequence_relation_type_box.setRenderer( new ListCellRenderer<Object>() {
516
517             @Override
518             public Component getListCellRendererComponent( final JList<?> list,
519                                                            final Object value,
520                                                            final int index,
521                                                            final boolean isSelected,
522                                                            final boolean cellHasFocus ) {
523                 final Component component = new DefaultListCellRenderer().getListCellRendererComponent( list,
524                                                                                                         value,
525                                                                                                         index,
526                                                                                                         isSelected,
527                                                                                                         cellHasFocus );
528                 if ( ( value != null ) && ( value instanceof SequenceRelation.SEQUENCE_RELATION_TYPE ) ) {
529                     ( ( DefaultListCellRenderer ) component ).setText( SequenceRelation
530                             .getPrintableNameByType( ( SequenceRelation.SEQUENCE_RELATION_TYPE ) value ) );
531                 }
532                 return component;
533             }
534         } );
535         final GridBagLayout gbl = new GridBagLayout();
536         _sequence_relation_type_box.setMinimumSize( new Dimension( 115, 17 ) );
537         _sequence_relation_type_box.setPreferredSize( new Dimension( 115, 20 ) );
538         final JPanel horizGrid = new JPanel( gbl );
539         horizGrid.setBackground( getBackground() );
540         horizGrid.add( typeLabel );
541         horizGrid.add( _sequence_relation_type_box );
542         add( customizeLabel( mainLabel, getConfiguration() ) );
543         add( horizGrid );
544         add( getSequenceRelationBox() );
545         if ( _configuration.doDisplayOption( Configuration.show_relation_confidence ) ) {
546             addCheckbox( Configuration.show_relation_confidence,
547                          _configuration.getDisplayTitle( Configuration.show_relation_confidence ) );
548             setCheckbox( Configuration.show_relation_confidence,
549                          _configuration.doCheckOption( Configuration.show_relation_confidence ) );
550         }
551     }// addSequenceRelationBlock
552
553     /* GUILHEM_END */
554     
555     private List<Boolean> getIsDrawPhylogramList() {
556         return _draw_phylogram;
557     }
558
559     // This takes care of ArchaeopteryxE-issue.
560     // Can, and will, return null prior to  ArchaeopteryxE initialization completion.
561     final private MainFrame getMainFrame() {
562         MainFrame mf = getMainPanel().getMainFrame();
563         if ( mf == null ) {
564             // Must be "E" applet version.
565             final ArchaeopteryxE e = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
566             if ( e.getMainPanel() == null ) {
567                 return null;
568             }
569             mf = e.getMainPanel().getMainFrame();
570         }
571         return mf;
572     }
573
574     private void init() {
575         _draw_phylogram = new ArrayList<Boolean>();
576         setSpeciesColors( new HashMap<String, Color>() );
577         setSequenceColors( new HashMap<String, Color>() );
578         setAnnotationColors( new HashMap<String, Color>() );
579     }
580
581     private boolean isDrawPhylogram( final int index ) {
582         return getIsDrawPhylogramList().get( index );
583     }
584
585     private void search0( final MainPanel main_panel, final Phylogeny tree, final String query_str ) {
586         getSearchFoundCountsLabel0().setVisible( true );
587         getSearchResetButton0().setEnabled( true );
588         getSearchResetButton0().setVisible( true );
589         String[] queries = null;
590         Set<Long> nodes = null;
591         if ( ( query_str.indexOf( ',' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
592             queries = query_str.split( ",+" );
593         }
594         else {
595             queries = new String[ 1 ];
596             queries[ 0 ] = query_str.trim();
597         }
598         if ( ( queries != null ) && ( queries.length > 0 ) ) {
599             nodes = new HashSet<Long>();
600             for( String query : queries ) {
601                 if ( ForesterUtil.isEmpty( query ) ) {
602                     continue;
603                 }
604                 query = query.trim();
605                 final TreePanel tp = getMainPanel().getCurrentTreePanel();
606                 if ( ( query.indexOf( '+' ) > 0 ) && !getOptions().isSearchWithRegex() ) {
607                     nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ),
608                                                                          tree,
609                                                                          getOptions().isSearchCaseSensitive(),
610                                                                          !getOptions().isMatchWholeTermsOnly(),
611                                                                          isShowDomainArchitectures(),
612                                                                          tp != null ? Math.pow( 10,
613                                                                                                 tp.getDomainStructureEvalueThresholdExp() )
614                                                                                                 : 0 ) );
615                 }
616                 else {
617                     nodes.addAll( PhylogenyMethods.searchData( query,
618                                                                tree,
619                                                                getOptions().isSearchCaseSensitive(),
620                                                                !getOptions().isMatchWholeTermsOnly(),
621                                                                getOptions().isSearchWithRegex(),
622                                                                isShowDomainArchitectures(),
623                                                                tp != null ? Math.pow( 10, tp
624                                                                                       .getDomainStructureEvalueThresholdExp() ) : 0 ) );
625                 }
626             }
627             if ( getOptions().isInverseSearchResult() ) {
628                 final List<PhylogenyNode> all = PhylogenyMethods.obtainAllNodesAsList( tree );
629                 final Set<Long> temp_nodes = nodes;
630                 nodes = new HashSet<Long>();
631                 for( final PhylogenyNode n : all ) {
632                     if ( (!temp_nodes.contains( n.getId() )) && n.isHasNodeData() ) {
633                         nodes.add( n.getId() );
634                     }
635                 }
636             }
637         }
638         if ( ( nodes != null ) && ( nodes.size() > 0 ) ) {
639             main_panel.getCurrentTreePanel().setFoundNodes0( new HashSet<Long>() );
640             for( final Long node : nodes ) {
641                 main_panel.getCurrentTreePanel().getFoundNodes0().add( node );
642             }
643             setSearchFoundCountsOnLabel0( nodes.size() );
644         }
645         else {
646             setSearchFoundCountsOnLabel0( 0 );
647             searchReset0();
648         }
649     }
650
651     private void search1( final MainPanel main_panel, final Phylogeny tree, final String query_str ) {
652         getSearchFoundCountsLabel1().setVisible( true );
653         getSearchResetButton1().setEnabled( true );
654         getSearchResetButton1().setVisible( true );
655         String[] queries = null;
656         Set<Long> nodes = null;
657         if ( ( query_str.indexOf( ',' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
658             queries = query_str.split( ",+" );
659         }
660         else {
661             queries = new String[ 1 ];
662             queries[ 0 ] = query_str.trim();
663         }
664         if ( ( queries != null ) && ( queries.length > 0 ) ) {
665             nodes = new HashSet<Long>();
666             for( String query : queries ) {
667                 if ( ForesterUtil.isEmpty( query ) ) {
668                     continue;
669                 }
670                 query = query.trim();
671                 final TreePanel tp = getMainPanel().getCurrentTreePanel();
672                 if ( ( query.indexOf( '+' ) > 0 ) && !getOptions().isSearchWithRegex() ) {
673                     nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ),
674                                                                          tree,
675                                                                          getOptions().isSearchCaseSensitive(),
676                                                                          !getOptions().isMatchWholeTermsOnly(),
677                                                                          isShowDomainArchitectures(),
678                                                                          tp != null ? Math.pow( 10,
679                                                                                                 tp.getDomainStructureEvalueThresholdExp() )
680                                                                                                 : 0 ) );
681                 }
682                 else {
683                     nodes.addAll( PhylogenyMethods.searchData( query,
684                                                                tree,
685                                                                getOptions().isSearchCaseSensitive(),
686                                                                !getOptions().isMatchWholeTermsOnly(),
687                                                                getOptions().isSearchWithRegex(),
688                                                                isShowDomainArchitectures(),
689                                                                tp != null ? Math.pow( 10, tp
690                                                                                       .getDomainStructureEvalueThresholdExp() ) : 0 ) );
691                 }
692             }
693             if ( getOptions().isInverseSearchResult() ) {
694                 final List<PhylogenyNode> all = PhylogenyMethods.obtainAllNodesAsList( tree );
695                 final Set<Long> temp_nodes = nodes;
696                 nodes = new HashSet<Long>();
697                 for( final PhylogenyNode n : all ) {
698                     if ( (!temp_nodes.contains( n.getId() )) && n.isHasNodeData() ) {
699                         nodes.add( n.getId() );
700                     }
701                 }
702             }
703         }
704         if ( ( nodes != null ) && ( nodes.size() > 0 ) ) {
705             main_panel.getCurrentTreePanel().setFoundNodes1( new HashSet<Long>() );
706             for( final Long node : nodes ) {
707                 main_panel.getCurrentTreePanel().getFoundNodes1().add( node );
708             }
709             setSearchFoundCountsOnLabel1( nodes.size() );
710         }
711         else {
712             setSearchFoundCountsOnLabel1( 0 );
713             searchReset1();
714         }
715     }
716     
717     private void setDrawPhylogram( final int index, final boolean b ) {
718         getIsDrawPhylogramList().set( index, b );
719     }
720
721     private void setupClickToOptions() {
722         final int default_option = _configuration.getDefaultDisplayClicktoOption();
723         int selected_index = 0;
724         int cb_index = 0;
725         if ( _configuration.doDisplayClickToOption( Configuration.display_node_data ) ) {
726             _show_data_item = cb_index;
727             addClickToOption( Configuration.display_node_data,
728                               _configuration.getClickToTitle( Configuration.display_node_data ) );
729             if ( default_option == Configuration.display_node_data ) {
730                 selected_index = cb_index;
731             }
732             cb_index++;
733         }
734         if ( _configuration.doDisplayClickToOption( Configuration.collapse_uncollapse ) ) {
735             _collapse_cb_item = cb_index;
736             addClickToOption( Configuration.collapse_uncollapse,
737                               _configuration.getClickToTitle( Configuration.collapse_uncollapse ) );
738             if ( default_option == Configuration.collapse_uncollapse ) {
739                 selected_index = cb_index;
740             }
741             cb_index++;
742         }
743         if ( _configuration.doDisplayClickToOption( Configuration.reroot ) ) {
744             _reroot_cb_item = cb_index;
745             addClickToOption( Configuration.reroot, _configuration.getClickToTitle( Configuration.reroot ) );
746             if ( default_option == Configuration.reroot ) {
747                 selected_index = cb_index;
748             }
749             cb_index++;
750         }
751         if ( _configuration.doDisplayClickToOption( Configuration.subtree ) ) {
752             _subtree_cb_item = cb_index;
753             addClickToOption( Configuration.subtree, _configuration.getClickToTitle( Configuration.subtree ) );
754             if ( default_option == Configuration.subtree ) {
755                 selected_index = cb_index;
756             }
757             cb_index++;
758         }
759         if ( _configuration.doDisplayClickToOption( Configuration.swap ) ) {
760             _swap_cb_item = cb_index;
761             addClickToOption( Configuration.swap, _configuration.getClickToTitle( Configuration.swap ) );
762             if ( default_option == Configuration.swap ) {
763                 selected_index = cb_index;
764             }
765             cb_index++;
766         }
767         if ( _configuration.doDisplayClickToOption( Configuration.sort_descendents ) ) {
768             _sort_descendents_item = cb_index;
769             addClickToOption( Configuration.sort_descendents,
770                               _configuration.getClickToTitle( Configuration.sort_descendents ) );
771             if ( default_option == Configuration.sort_descendents ) {
772                 selected_index = cb_index;
773             }
774             cb_index++;
775         }
776         if ( _configuration.doDisplayClickToOption( Configuration.color_node_font ) ) {
777             _color_node_font_item = cb_index;
778             addClickToOption( Configuration.color_node_font,
779                               _configuration.getClickToTitle( Configuration.color_node_font ) );
780             if ( default_option == Configuration.color_node_font ) {
781                 selected_index = cb_index;
782             }
783             cb_index++;
784         }
785         if ( _configuration.doDisplayClickToOption( Configuration.change_node_font ) ) {
786             _change_node_font_item = cb_index;
787             addClickToOption( Configuration.change_node_font,
788                               _configuration.getClickToTitle( Configuration.change_node_font ) );
789             if ( default_option == Configuration.change_node_font ) {
790                 selected_index = cb_index;
791             }
792             cb_index++;
793         }
794         if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) {
795             _color_subtree_cb_item = cb_index;
796             addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) );
797             if ( default_option == Configuration.color_subtree ) {
798                 selected_index = cb_index;
799             }
800             cb_index++;
801         }
802         if ( _configuration.doDisplayClickToOption( Configuration.open_seq_web ) ) {
803             _open_seq_web_item = cb_index;
804             addClickToOption( Configuration.open_seq_web, _configuration.getClickToTitle( Configuration.open_seq_web ) );
805             if ( default_option == Configuration.open_seq_web ) {
806                 selected_index = cb_index;
807             }
808             cb_index++;
809         }
810         if ( _configuration.doDisplayClickToOption( Configuration.open_pdb_web ) ) {
811             _open_pdb_item = cb_index;
812             addClickToOption( Configuration.open_pdb_web, _configuration.getClickToTitle( Configuration.open_pdb_web ) );
813             if ( default_option == Configuration.open_pdb_web ) {
814                 selected_index = cb_index;
815             }
816             cb_index++;
817         }
818         if ( _configuration.doDisplayClickToOption( Configuration.open_tax_web ) ) {
819             _open_tax_web_item = cb_index;
820             addClickToOption( Configuration.open_tax_web, _configuration.getClickToTitle( Configuration.open_tax_web ) );
821             if ( default_option == Configuration.open_tax_web ) {
822                 selected_index = cb_index;
823             }
824             cb_index++;
825         }
826         if ( _configuration.doDisplayClickToOption( Configuration.blast ) ) {
827             _blast_item = cb_index;
828             addClickToOption( Configuration.blast, _configuration.getClickToTitle( Configuration.blast ) );
829             if ( default_option == Configuration.blast ) {
830                 selected_index = cb_index;
831             }
832             cb_index++;
833         }
834         if ( _configuration.doDisplayClickToOption( Configuration.select_nodes ) ) {
835             _select_nodes_item = cb_index;
836             addClickToOption( Configuration.select_nodes, _configuration.getClickToTitle( Configuration.select_nodes ) );
837             if ( default_option == Configuration.select_nodes ) {
838                 selected_index = cb_index;
839             }
840             cb_index++;
841         }
842         if ( _configuration.doDisplayClickToOption( Configuration.get_ext_desc_data ) ) {
843             _get_ext_desc_data = cb_index;
844             if ( !ForesterUtil.isEmpty( getConfiguration().getLabelForGetExtDescendentsData() ) ) {
845                 addClickToOption( Configuration.get_ext_desc_data, getConfiguration()
846                                   .getLabelForGetExtDescendentsData() );
847             }
848             else {
849                 addClickToOption( Configuration.get_ext_desc_data,
850                                   getConfiguration().getClickToTitle( Configuration.get_ext_desc_data ) );
851             }
852             if ( default_option == Configuration.get_ext_desc_data ) {
853                 selected_index = cb_index;
854             }
855             cb_index++;
856         }
857         if ( getOptions().isEditable() ) {
858             if ( _configuration.doDisplayClickToOption( Configuration.cut_subtree ) ) {
859                 _cut_subtree_item = cb_index;
860                 addClickToOption( Configuration.cut_subtree, _configuration.getClickToTitle( Configuration.cut_subtree ) );
861                 if ( default_option == Configuration.cut_subtree ) {
862                     selected_index = cb_index;
863                 }
864                 cb_index++;
865             }
866             if ( _configuration.doDisplayClickToOption( Configuration.copy_subtree ) ) {
867                 _copy_subtree_item = cb_index;
868                 addClickToOption( Configuration.copy_subtree,
869                                   _configuration.getClickToTitle( Configuration.copy_subtree ) );
870                 if ( default_option == Configuration.copy_subtree ) {
871                     selected_index = cb_index;
872                 }
873                 cb_index++;
874             }
875             if ( _configuration.doDisplayClickToOption( Configuration.paste_subtree ) ) {
876                 _paste_subtree_item = cb_index;
877                 addClickToOption( Configuration.paste_subtree,
878                                   _configuration.getClickToTitle( Configuration.paste_subtree ) );
879                 if ( default_option == Configuration.paste_subtree ) {
880                     selected_index = cb_index;
881                 }
882                 cb_index++;
883             }
884             if ( _configuration.doDisplayClickToOption( Configuration.delete_subtree_or_node ) ) {
885                 _delete_node_or_subtree_item = cb_index;
886                 addClickToOption( Configuration.delete_subtree_or_node,
887                                   _configuration.getClickToTitle( Configuration.delete_subtree_or_node ) );
888                 if ( default_option == Configuration.delete_subtree_or_node ) {
889                     selected_index = cb_index;
890                 }
891                 cb_index++;
892             }
893             if ( _configuration.doDisplayClickToOption( Configuration.add_new_node ) ) {
894                 _add_new_node_item = cb_index;
895                 addClickToOption( Configuration.add_new_node,
896                                   _configuration.getClickToTitle( Configuration.add_new_node ) );
897                 if ( default_option == Configuration.add_new_node ) {
898                     selected_index = cb_index;
899                 }
900                 cb_index++;
901             }
902             if ( _configuration.doDisplayClickToOption( Configuration.edit_node_data ) ) {
903                 _edit_node_data_item = cb_index;
904                 addClickToOption( Configuration.edit_node_data,
905                                   _configuration.getClickToTitle( Configuration.edit_node_data ) );
906                 if ( default_option == Configuration.edit_node_data ) {
907                     selected_index = cb_index;
908                 }
909                 cb_index++;
910             }
911         }
912         // Set default selection and its action
913         _click_to_combobox.setSelectedIndex( selected_index );
914         setClickToAction( selected_index );
915     }
916
917     private void setupDisplayCheckboxes() {
918         if ( _configuration.doDisplayOption( Configuration.display_as_phylogram ) ) {
919             addCheckbox( Configuration.display_as_phylogram,
920                          _configuration.getDisplayTitle( Configuration.display_as_phylogram ) );
921             setCheckbox( Configuration.display_as_phylogram,
922                          _configuration.doCheckOption( Configuration.display_as_phylogram ) );
923         }
924         if ( _configuration.doDisplayOption( Configuration.dynamically_hide_data ) ) {
925             addCheckbox( Configuration.dynamically_hide_data,
926                          _configuration.getDisplayTitle( Configuration.dynamically_hide_data ) );
927             setCheckbox( Configuration.dynamically_hide_data,
928                          _configuration.doCheckOption( Configuration.dynamically_hide_data ) );
929         }
930         if ( _configuration.doDisplayOption( Configuration.node_data_popup ) ) {
931             addCheckbox( Configuration.node_data_popup, _configuration.getDisplayTitle( Configuration.node_data_popup ) );
932             setCheckbox( Configuration.node_data_popup, _configuration.doCheckOption( Configuration.node_data_popup ) );
933         }
934         if ( _configuration.doDisplayOption( Configuration.display_internal_data ) ) {
935             addCheckbox( Configuration.display_internal_data,
936                          _configuration.getDisplayTitle( Configuration.display_internal_data ) );
937             setCheckbox( Configuration.display_internal_data,
938                          _configuration.doCheckOption( Configuration.display_internal_data ) );
939         }
940         if ( _configuration.doDisplayOption( Configuration.color_according_to_sequence ) ) {
941             addCheckbox( Configuration.color_according_to_sequence,
942                          _configuration.getDisplayTitle( Configuration.color_according_to_sequence ) );
943             setCheckbox( Configuration.color_according_to_sequence,
944                          _configuration.doCheckOption( Configuration.color_according_to_sequence ) );
945         }
946         if ( _configuration.doDisplayOption( Configuration.color_according_to_species ) ) {
947             addCheckbox( Configuration.color_according_to_species,
948                          _configuration.getDisplayTitle( Configuration.color_according_to_species ) );
949             setCheckbox( Configuration.color_according_to_species,
950                          _configuration.doCheckOption( Configuration.color_according_to_species ) );
951         }
952         if ( _configuration.doDisplayOption( Configuration.color_according_to_annotation ) ) {
953             addCheckbox( Configuration.color_according_to_annotation,
954                          _configuration.getDisplayTitle( Configuration.color_according_to_annotation ) );
955             setCheckbox( Configuration.color_according_to_annotation,
956                          _configuration.doCheckOption( Configuration.color_according_to_annotation ) );
957         }
958         if ( _configuration.doDisplayOption( Configuration.use_style ) ) {
959             addCheckbox( Configuration.use_style, _configuration.getDisplayTitle( Configuration.use_style ) );
960             setCheckbox( Configuration.use_style, _configuration.doCheckOption( Configuration.use_style ) );
961         }
962         if ( _configuration.doDisplayOption( Configuration.width_branches ) ) {
963             addCheckbox( Configuration.width_branches, _configuration.getDisplayTitle( Configuration.width_branches ) );
964             setCheckbox( Configuration.width_branches, _configuration.doCheckOption( Configuration.width_branches ) );
965         }
966         final JLabel label = new JLabel( "Display Data:" );
967         label.setFont( ControlPanel.jcb_bold_font );
968         if ( !getConfiguration().isUseNativeUI() ) {
969             label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
970         }
971         add( label );
972         if ( _configuration.doDisplayOption( Configuration.show_node_names ) ) {
973             addCheckbox( Configuration.show_node_names, _configuration.getDisplayTitle( Configuration.show_node_names ) );
974             setCheckbox( Configuration.show_node_names, _configuration.doCheckOption( Configuration.show_node_names ) );
975         }
976         if ( _configuration.doDisplayOption( Configuration.show_tax_code ) ) {
977             addCheckbox( Configuration.show_tax_code, _configuration.getDisplayTitle( Configuration.show_tax_code ) );
978             setCheckbox( Configuration.show_tax_code, _configuration.doCheckOption( Configuration.show_tax_code ) );
979         }
980         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_scientific_names ) ) {
981             addCheckbox( Configuration.show_taxonomy_scientific_names,
982                          _configuration.getDisplayTitle( Configuration.show_taxonomy_scientific_names ) );
983             setCheckbox( Configuration.show_taxonomy_scientific_names,
984                          _configuration.doCheckOption( Configuration.show_taxonomy_scientific_names ) );
985         }
986         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_common_names ) ) {
987             addCheckbox( Configuration.show_taxonomy_common_names,
988                          _configuration.getDisplayTitle( Configuration.show_taxonomy_common_names ) );
989             setCheckbox( Configuration.show_taxonomy_common_names,
990                          _configuration.doCheckOption( Configuration.show_taxonomy_common_names ) );
991         }
992         if ( _configuration.doDisplayOption( Configuration.show_seq_names ) ) {
993             addCheckbox( Configuration.show_seq_names, _configuration.getDisplayTitle( Configuration.show_seq_names ) );
994             setCheckbox( Configuration.show_seq_names, _configuration.doCheckOption( Configuration.show_seq_names ) );
995         }
996         if ( _configuration.doDisplayOption( Configuration.show_gene_names ) ) {
997             addCheckbox( Configuration.show_gene_names, _configuration.getDisplayTitle( Configuration.show_gene_names ) );
998             setCheckbox( Configuration.show_gene_names, _configuration.doCheckOption( Configuration.show_gene_names ) );
999         }
1000         if ( _configuration.doDisplayOption( Configuration.show_seq_symbols ) ) {
1001             addCheckbox( Configuration.show_seq_symbols,
1002                          _configuration.getDisplayTitle( Configuration.show_seq_symbols ) );
1003             setCheckbox( Configuration.show_seq_symbols, _configuration.doCheckOption( Configuration.show_seq_symbols ) );
1004         }
1005         if ( _configuration.doDisplayOption( Configuration.show_sequence_acc ) ) {
1006             addCheckbox( Configuration.show_sequence_acc,
1007                          _configuration.getDisplayTitle( Configuration.show_sequence_acc ) );
1008             setCheckbox( Configuration.show_sequence_acc,
1009                          _configuration.doCheckOption( Configuration.show_sequence_acc ) );
1010         }
1011         if ( _configuration.doDisplayOption( Configuration.show_annotation ) ) {
1012             addCheckbox( Configuration.show_annotation, _configuration.getDisplayTitle( Configuration.show_annotation ) );
1013             setCheckbox( Configuration.show_annotation, _configuration.doCheckOption( Configuration.show_annotation ) );
1014         }
1015         if ( _configuration.doDisplayOption( Configuration.write_confidence_values ) ) {
1016             addCheckbox( Configuration.write_confidence_values,
1017                          _configuration.getDisplayTitle( Configuration.write_confidence_values ) );
1018             setCheckbox( Configuration.write_confidence_values,
1019                          _configuration.doCheckOption( Configuration.write_confidence_values ) );
1020         }
1021         if ( _configuration.doDisplayOption( Configuration.write_branch_length_values ) ) {
1022             addCheckbox( Configuration.write_branch_length_values,
1023                          _configuration.getDisplayTitle( Configuration.write_branch_length_values ) );
1024             setCheckbox( Configuration.write_branch_length_values,
1025                          _configuration.doCheckOption( Configuration.write_branch_length_values ) );
1026         }
1027         if ( _configuration.doDisplayOption( Configuration.show_binary_characters ) ) {
1028             addCheckbox( Configuration.show_binary_characters,
1029                          _configuration.getDisplayTitle( Configuration.show_binary_characters ) );
1030             setCheckbox( Configuration.show_binary_characters,
1031                          _configuration.doCheckOption( Configuration.show_binary_characters ) );
1032         }
1033         if ( _configuration.doDisplayOption( Configuration.show_binary_character_counts ) ) {
1034             addCheckbox( Configuration.show_binary_character_counts,
1035                          _configuration.getDisplayTitle( Configuration.show_binary_character_counts ) );
1036             setCheckbox( Configuration.show_binary_character_counts,
1037                          _configuration.doCheckOption( Configuration.show_binary_character_counts ) );
1038         }
1039         if ( _configuration.doDisplayOption( Configuration.show_domain_architectures ) ) {
1040             addCheckbox( Configuration.show_domain_architectures,
1041                          _configuration.getDisplayTitle( Configuration.show_domain_architectures ) );
1042             setCheckbox( Configuration.show_domain_architectures,
1043                          _configuration.doCheckOption( Configuration.show_domain_architectures ) );
1044         }
1045         if ( _configuration.doDisplayOption( Configuration.show_mol_seqs ) ) {
1046             addCheckbox( Configuration.show_mol_seqs, _configuration.getDisplayTitle( Configuration.show_mol_seqs ) );
1047             setCheckbox( Configuration.show_mol_seqs, _configuration.doCheckOption( Configuration.show_mol_seqs ) );
1048         }
1049         if ( _configuration.doDisplayOption( Configuration.write_events ) ) {
1050             addCheckbox( Configuration.write_events, _configuration.getDisplayTitle( Configuration.write_events ) );
1051             setCheckbox( Configuration.write_events, _configuration.doCheckOption( Configuration.write_events ) );
1052         }
1053         if ( _configuration.doDisplayOption( Configuration.show_vector_data ) ) {
1054             addCheckbox( Configuration.show_vector_data,
1055                          _configuration.getDisplayTitle( Configuration.show_vector_data ) );
1056             setCheckbox( Configuration.show_vector_data, _configuration.doCheckOption( Configuration.show_vector_data ) );
1057         }
1058         if ( _configuration.doDisplayOption( Configuration.show_properties ) ) {
1059             addCheckbox( Configuration.show_properties, _configuration.getDisplayTitle( Configuration.show_properties ) );
1060             setCheckbox( Configuration.show_properties, _configuration.doCheckOption( Configuration.show_properties ) );
1061         }
1062         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_images ) ) {
1063             addCheckbox( Configuration.show_taxonomy_images,
1064                          _configuration.getDisplayTitle( Configuration.show_taxonomy_images ) );
1065             setCheckbox( Configuration.show_taxonomy_images,
1066                          _configuration.doCheckOption( Configuration.show_taxonomy_images ) );
1067         }
1068     }
1069
1070     private void setVisibilityOfDomainStrucureControls() {
1071         if ( _zoom_in_domain_structure != null ) {
1072             final MainFrame mf = getMainFrame();
1073             if ( mf != null ) {
1074                 if ( isShowDomainArchitectures() ) {
1075                     _domain_display_label.setVisible( true );
1076                     _zoom_in_domain_structure.setVisible( true );
1077                     _zoom_out_domain_structure.setVisible( true );
1078                     _decr_domain_structure_evalue_thr.setVisible( true );
1079                     _incr_domain_structure_evalue_thr.setVisible( true );
1080                     _domain_structure_evalue_thr_tf.setVisible( true );
1081                     if ( mf._right_line_up_domains_cbmi != null ) {
1082                         mf._right_line_up_domains_cbmi.setVisible( true );
1083                     }
1084                     if ( mf._show_domain_labels != null ) {
1085                         mf._show_domain_labels.setVisible( true );
1086                     }
1087                 }
1088                 else {
1089                     _domain_display_label.setVisible( false );
1090                     _zoom_in_domain_structure.setVisible( false );
1091                     _zoom_out_domain_structure.setVisible( false );
1092                     _decr_domain_structure_evalue_thr.setVisible( false );
1093                     _incr_domain_structure_evalue_thr.setVisible( false );
1094                     _domain_structure_evalue_thr_tf.setVisible( false );
1095                     if ( mf._right_line_up_domains_cbmi != null ) {
1096                         mf._right_line_up_domains_cbmi.setVisible( false );
1097                     }
1098                     if ( mf._show_domain_labels != null ) {
1099                         mf._show_domain_labels.setVisible( false );
1100                     }
1101                 }
1102             }
1103         }
1104     }
1105
1106     void activateButtonToReturnToSuperTree( int index ) {
1107         --index;
1108         if ( index > 0 ) {
1109             _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT + " " + index );
1110         }
1111         else {
1112             _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT );
1113         }
1114         _return_to_super_tree.setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
1115         _return_to_super_tree.setEnabled( true );
1116     }
1117
1118     /**
1119      * Add zoom and quick edit buttons. (Last modified 8/9/04)
1120      */
1121     void addButtons() {
1122         final JLabel spacer = new JLabel( "" );
1123         spacer.setOpaque( false );
1124         add( spacer );
1125         final JPanel x_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
1126         final JPanel y_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
1127         final JPanel z_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
1128         if ( !getConfiguration().isUseNativeUI() ) {
1129             x_panel.setBackground( getBackground() );
1130             y_panel.setBackground( getBackground() );
1131             z_panel.setBackground( getBackground() );
1132         }
1133         add( _zoom_label = new JLabel( "Zoom:" ) );
1134         customizeLabel( _zoom_label, getConfiguration() );
1135         add( x_panel );
1136         add( y_panel );
1137         add( z_panel );
1138         if ( getConfiguration().isUseNativeUI() ) {
1139             _zoom_in_x = new JButton( "+" );
1140             _zoom_out_x = new JButton( "-" );
1141         }
1142         else {
1143             _zoom_in_x = new JButton( "X+" );
1144             _zoom_out_x = new JButton( "X-" );
1145         }
1146         _zoom_in_y = new JButton( "Y+" );
1147         _zoom_out_y = new JButton( "Y-" );
1148         _show_whole = new JButton( "F" );
1149         _show_whole.setToolTipText( "To fit the complete phylogeny to the current display size [F or Home]" );
1150         _zoom_in_x.setToolTipText( "To zoom in horizontally [Shift+cursor-right]" );
1151         _zoom_in_y.setToolTipText( "To zoom in vertically [Shift+cursor-up]" );
1152         _zoom_out_x.setToolTipText( "To zoom out horizontally [Shift+cursor-left]" );
1153         _zoom_out_y.setToolTipText( "To zoom out vertically [Shift+cursor-down]" );
1154         if ( getConfiguration().isUseNativeUI() && ForesterUtil.isMac() ) {
1155             _zoom_out_x.setPreferredSize( new Dimension( 55, 10 ) );
1156             _zoom_in_x.setPreferredSize( new Dimension( 55, 10 ) );
1157         }
1158         else {
1159             _zoom_out_x.setPreferredSize( new Dimension( 10, 10 ) );
1160             _zoom_in_x.setPreferredSize( new Dimension( 10, 10 ) );
1161         }
1162         _zoom_out_y.setPreferredSize( new Dimension( 10, 10 ) );
1163         _zoom_in_y.setPreferredSize( new Dimension( 10, 10 ) );
1164         _show_whole.setPreferredSize( new Dimension( 10, 10 ) );
1165         _return_to_super_tree = new JButton( RETURN_TO_SUPER_TREE_TEXT );
1166         _return_to_super_tree.setEnabled( false );
1167         _order = new JButton( "Order Subtrees" );
1168         _uncollapse_all = new JButton( "Uncollapse All" );
1169         addJButton( _zoom_in_y, x_panel );
1170         addJButton( _zoom_out_x, y_panel );
1171         addJButton( _show_whole, y_panel );
1172         addJButton( _zoom_in_x, y_panel );
1173         addJButton( _zoom_out_y, z_panel );
1174         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
1175             setUpControlsForDomainStrucures();
1176         }
1177         final JLabel spacer2 = new JLabel( "" );
1178         add( spacer2 );
1179         addJButton( _return_to_super_tree, this );
1180         addJButton( _order, this );
1181         addJButton( _uncollapse_all, this );
1182         final JLabel spacer3 = new JLabel( "" );
1183         add( spacer3 );
1184         setVisibilityOfDomainStrucureControls();
1185     }
1186
1187     void addCheckbox( final int which, final String title ) {
1188         final JPanel ch_panel = new JPanel( new BorderLayout( 0, 0 ) );
1189         switch ( which ) {
1190             case Configuration.display_as_phylogram:
1191                 _display_as_phylogram_cb = new JCheckBox( title );
1192                 getDisplayAsPhylogramCb().setToolTipText( "To switch between phylogram and cladogram display" );
1193                 addJCheckBox( getDisplayAsPhylogramCb(), ch_panel );
1194                 add( ch_panel );
1195                 break;
1196             case Configuration.display_internal_data:
1197                 _display_internal_data = new JCheckBox( title );
1198                 _display_internal_data.setToolTipText( "To allow or disallow display of internal labels" );
1199                 addJCheckBox( _display_internal_data, ch_panel );
1200                 add( ch_panel );
1201                 break;
1202             case Configuration.color_according_to_species:
1203                 _color_acc_species = new JCheckBox( title );
1204                 _color_acc_species.setToolTipText( "To colorize node labels as a function of taxonomy" );
1205                 addJCheckBox( _color_acc_species, ch_panel );
1206                 add( ch_panel );
1207                 break;
1208             case Configuration.color_according_to_sequence:
1209                 _color_acc_sequence = new JCheckBox( title );
1210                 _color_acc_sequence.setToolTipText( "To colorize node labels as a function of sequence name" );
1211                 addJCheckBox( _color_acc_sequence, ch_panel );
1212                 add( ch_panel );
1213                 break;
1214             case Configuration.color_according_to_annotation:
1215                 _color_according_to_annotation = new JCheckBox( title );
1216                 _color_according_to_annotation
1217                         .setToolTipText( "To colorize sequence annotation labels as a function of sequence annotation" );
1218                 addJCheckBox( _color_according_to_annotation, ch_panel );
1219                 add( ch_panel );
1220                 break;
1221             case Configuration.show_node_names:
1222                 _show_node_names = new JCheckBox( title );
1223                 addJCheckBox( _show_node_names, ch_panel );
1224                 add( ch_panel );
1225                 break;
1226             case Configuration.show_taxonomy_scientific_names:
1227                 _show_taxo_scientific_names = new JCheckBox( title );
1228                 addJCheckBox( _show_taxo_scientific_names, ch_panel );
1229                 add( ch_panel );
1230                 break;
1231             case Configuration.show_taxonomy_common_names:
1232                 _show_taxo_common_names = new JCheckBox( title );
1233                 addJCheckBox( _show_taxo_common_names, ch_panel );
1234                 add( ch_panel );
1235                 break;
1236             case Configuration.show_tax_code:
1237                 _show_taxo_code = new JCheckBox( title );
1238                 addJCheckBox( _show_taxo_code, ch_panel );
1239                 add( ch_panel );
1240                 break;
1241             case Configuration.show_taxonomy_images:
1242                 _show_taxo_images_cb = new JCheckBox( title );
1243                 addJCheckBox( _show_taxo_images_cb, ch_panel );
1244                 add( ch_panel );
1245                 break;
1246             case Configuration.show_binary_characters:
1247                 _show_binary_characters = new JCheckBox( title );
1248                 addJCheckBox( _show_binary_characters, ch_panel );
1249                 add( ch_panel );
1250                 break;
1251             case Configuration.show_annotation:
1252                 _show_annotation = new JCheckBox( title );
1253                 addJCheckBox( _show_annotation, ch_panel );
1254                 add( ch_panel );
1255                 break;
1256             case Configuration.show_binary_character_counts:
1257                 _show_binary_character_counts = new JCheckBox( title );
1258                 addJCheckBox( _show_binary_character_counts, ch_panel );
1259                 add( ch_panel );
1260                 break;
1261             case Configuration.write_confidence_values:
1262                 _write_confidence = new JCheckBox( title );
1263                 addJCheckBox( getWriteConfidenceCb(), ch_panel );
1264                 add( ch_panel );
1265                 break;
1266             case Configuration.write_events:
1267                 _show_events = new JCheckBox( title );
1268                 addJCheckBox( getShowEventsCb(), ch_panel );
1269                 add( ch_panel );
1270                 break;
1271             case Configuration.use_style:
1272                 _use_visual_styles_cb = new JCheckBox( title );
1273                 getUseVisualStylesCb()
1274                         .setToolTipText( "To use visual styles (node colors, fonts) and branch colors, if present" );
1275                 addJCheckBox( getUseVisualStylesCb(), ch_panel );
1276                 add( ch_panel );
1277                 break;
1278             case Configuration.width_branches:
1279                 _width_branches = new JCheckBox( title );
1280                 _width_branches.setToolTipText( "To use branch width values, if present" );
1281                 addJCheckBox( _width_branches, ch_panel );
1282                 add( ch_panel );
1283                 break;
1284             case Configuration.write_branch_length_values:
1285                 _write_branch_length_values = new JCheckBox( title );
1286                 addJCheckBox( _write_branch_length_values, ch_panel );
1287                 add( ch_panel );
1288                 break;
1289             case Configuration.show_domain_architectures:
1290                 _show_domain_architectures = new JCheckBox( title );
1291                 addJCheckBox( _show_domain_architectures, ch_panel );
1292                 add( ch_panel );
1293                 break;
1294             case Configuration.show_mol_seqs:
1295                 _show_mol_seqs = new JCheckBox( title );
1296                 addJCheckBox( _show_mol_seqs, ch_panel );
1297                 add( ch_panel );
1298                 break;
1299             case Configuration.show_seq_names:
1300                 _show_seq_names = new JCheckBox( title );
1301                 addJCheckBox( _show_seq_names, ch_panel );
1302                 add( ch_panel );
1303                 break;
1304             case Configuration.show_gene_names:
1305                 _show_gene_names = new JCheckBox( title );
1306                 addJCheckBox( _show_gene_names, ch_panel );
1307                 add( ch_panel );
1308                 break;
1309             case Configuration.show_seq_symbols:
1310                 _show_seq_symbols = new JCheckBox( title );
1311                 addJCheckBox( _show_seq_symbols, ch_panel );
1312                 add( ch_panel );
1313                 break;
1314             case Configuration.show_sequence_acc:
1315                 _show_sequence_acc = new JCheckBox( title );
1316                 addJCheckBox( _show_sequence_acc, ch_panel );
1317                 add( ch_panel );
1318                 break;
1319             case Configuration.dynamically_hide_data:
1320                 _dynamically_hide_data = new JCheckBox( title );
1321                 getDynamicallyHideData().setToolTipText( "To hide labels depending on expected visibility" );
1322                 addJCheckBox( getDynamicallyHideData(), ch_panel );
1323                 add( ch_panel );
1324                 break;
1325             case Configuration.node_data_popup:
1326                 _node_desc_popup_cb = new JCheckBox( title );
1327                 getNodeDescPopupCb().setToolTipText( "To enable mouse rollover display of basic node data" );
1328                 addJCheckBox( getNodeDescPopupCb(), ch_panel );
1329                 add( ch_panel );
1330                 break;
1331             case Configuration.show_relation_confidence:
1332                 _seq_relation_confidence_switch = new JCheckBox( title );
1333                 addJCheckBox( _seq_relation_confidence_switch, ch_panel );
1334                 add( ch_panel );
1335                 break;
1336             case Configuration.show_vector_data:
1337                 _show_vector_data_cb = new JCheckBox( title );
1338                 addJCheckBox( _show_vector_data_cb, ch_panel );
1339                 add( ch_panel );
1340                 break;
1341             case Configuration.show_properties:
1342                 _show_properties_cb = new JCheckBox( title );
1343                 addJCheckBox( _show_properties_cb, ch_panel );
1344                 add( ch_panel );
1345                 break;
1346             default:
1347                 throw new RuntimeException( "unknown checkbox: " + which );
1348         }
1349     }// addCheckbox
1350
1351     void addJButton( final JButton jb, final JPanel p ) {
1352         jb.setFocusPainted( false );
1353         jb.setFont( ControlPanel.jcb_font );
1354         if ( !_configuration.isUseNativeUI() ) {
1355             jb.setBorder( BorderFactory.createLineBorder( getConfiguration().getGuiButtonBorderColor() ) );
1356             jb.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
1357             jb.setForeground( getConfiguration().getGuiButtonTextColor() );
1358         }
1359         p.add( jb );
1360         jb.addActionListener( this );
1361     }
1362
1363     void addJCheckBox( final JCheckBox jcb, final JPanel p ) {
1364         jcb.setFocusPainted( false );
1365         jcb.setFont( ControlPanel.jcb_font );
1366         if ( !_configuration.isUseNativeUI() ) {
1367             jcb.setBackground( getConfiguration().getGuiBackgroundColor() );
1368             jcb.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1369         }
1370         p.add( jcb, "Center" );
1371         jcb.addActionListener( this );
1372     }
1373
1374     void addJTextField( final JTextField tf, final JPanel p ) {
1375         if ( !_configuration.isUseNativeUI() ) {
1376             tf.setForeground( getConfiguration().getGuiBackgroundColor() );
1377             tf.setFont( ControlPanel.jcb_font );
1378         }
1379         p.add( tf );
1380         tf.addActionListener( this );
1381     }
1382
1383     void deactivateButtonToReturnToSuperTree() {
1384         _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT );
1385         _return_to_super_tree.setForeground( getConfiguration().getGuiButtonTextColor() );
1386         _return_to_super_tree.setEnabled( false );
1387     }
1388
1389     void displayedPhylogenyMightHaveChanged( final boolean recalc_longest_ext_node_info ) {
1390         if ( ( _mainpanel != null )
1391                 && ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1392             
1393             if ( recalc_longest_ext_node_info ) {
1394                 _mainpanel.getCurrentTreePanel().initNodeData();
1395                 _mainpanel.getCurrentTreePanel().calculateLongestExtNodeInfo();
1396             }
1397             if ( getOptions().isShowOverview() ) {
1398                 _mainpanel.getCurrentTreePanel().updateOvSizes();
1399             }
1400             _mainpanel.getCurrentTreePanel().recalculateMaxDistanceToRoot();
1401             setVisibilityOfDomainStrucureControls();
1402             updateDomainStructureEvaluethresholdDisplay();
1403             _mainpanel.getCurrentTreePanel().calculateScaleDistance();
1404             _mainpanel.getCurrentTreePanel().calcMaxDepth();
1405             _mainpanel.adjustJScrollPane();
1406           
1407             _mainpanel.getCurrentTreePanel().repaint();
1408             // _mainpanel.getCurrentTreePanel().setUpUrtFactor();
1409         }
1410     }
1411
1412     void endClickToOptions() {
1413         _click_to_combobox.addActionListener( this );
1414     }
1415
1416     /**
1417      * Indicates what action should be execute when a node is clicked
1418      *
1419      * @return the click-on action
1420      */
1421     NodeClickAction getActionWhenNodeClicked() {
1422         return _action_when_node_clicked;
1423     }
1424
1425     Map<Integer, String> getAllClickToItems() {
1426         return _all_click_to_names;
1427     }
1428
1429     Map<String, Color> getAnnotationColors() {
1430         return _annotation_colors;
1431     }
1432
1433     Configuration getConfiguration() {
1434         return _configuration;
1435     }
1436
1437     TreePanel getCurrentTreePanel() {
1438         return getMainPanel().getCurrentTreePanel();
1439     }
1440
1441     MainPanel getMainPanel() {
1442         return _mainpanel;
1443     }
1444
1445     Options getOptions() {
1446         return getMainPanel().getOptions();
1447     }
1448
1449     JLabel getSearchFoundCountsLabel0() {
1450         return _search_found_label_0;
1451     }
1452
1453     JLabel getSearchFoundCountsLabel1() {
1454         return _search_found_label_1;
1455     }
1456
1457     JButton getSearchResetButton0() {
1458         return _search_reset_button_0;
1459     }
1460
1461     JButton getSearchResetButton1() {
1462         return _search_reset_button_1;
1463     }
1464
1465     JTextField getSearchTextField0() {
1466         return _search_tf_0;
1467     }
1468
1469     JTextField getSearchTextField1() {
1470         return _search_tf_1;
1471     }
1472
1473     Map<String, Color> getSequenceColors() {
1474         return _sequence_colors;
1475     }
1476
1477     List<String> getSingleClickToNames() {
1478         return _click_to_names;
1479     }
1480
1481     Map<String, Color> getSpeciesColors() {
1482         return _species_colors;
1483     }
1484
1485     boolean isAntialiasScreenText() {
1486         return true;
1487     }
1488
1489     boolean isColorAccordingToAnnotation() {
1490         return ( ( _color_according_to_annotation != null ) && _color_according_to_annotation.isSelected() );
1491     }
1492
1493     boolean isColorAccordingToSequence() {
1494         return ( ( _color_acc_sequence != null ) && _color_acc_sequence.isSelected() );
1495     }
1496
1497     boolean isColorAccordingToTaxonomy() {
1498         return ( ( _color_acc_species != null ) && _color_acc_species.isSelected() );
1499     }
1500
1501     boolean isDrawPhylogram() {
1502         return isDrawPhylogram( getMainPanel().getCurrentTabIndex() );
1503     }
1504
1505     boolean isDynamicallyHideData() {
1506         return ( ( getDynamicallyHideData() != null ) && getDynamicallyHideData().isSelected() );
1507     }
1508
1509     boolean isEvents() {
1510         return ( ( getShowEventsCb() != null ) && getShowEventsCb().isSelected() );
1511     }
1512
1513     boolean isNodeDescPopup() {
1514         return ( ( getNodeDescPopupCb() != null ) && getNodeDescPopupCb().isSelected() );
1515     }
1516
1517     boolean isShowAnnotation() {
1518         return ( ( _show_annotation != null ) && _show_annotation.isSelected() );
1519     }
1520
1521     boolean isShowBinaryCharacterCounts() {
1522         return ( ( _show_binary_character_counts != null ) && _show_binary_character_counts.isSelected() );
1523     }
1524
1525     boolean isShowBinaryCharacters() {
1526         return ( ( _show_binary_characters != null ) && _show_binary_characters.isSelected() );
1527     }
1528
1529     boolean isShowConfidenceValues() {
1530         return ( ( getWriteConfidenceCb() != null ) && getWriteConfidenceCb().isSelected() );
1531     }
1532
1533     boolean isShowDomainArchitectures() {
1534         return ( ( _show_domain_architectures != null ) && _show_domain_architectures.isSelected() );
1535     }
1536
1537     boolean isShowGeneNames() {
1538         return ( ( _show_gene_names != null ) && _show_gene_names.isSelected() );
1539     }
1540
1541     boolean isShowInternalData() {
1542         return ( ( _display_internal_data == null ) || _display_internal_data.isSelected() );
1543     }
1544
1545     boolean isShowNodeNames() {
1546         return ( ( _show_node_names != null ) && _show_node_names.isSelected() );
1547     }
1548
1549     boolean isShowSeqNames() {
1550         return ( ( _show_seq_names != null ) && _show_seq_names.isSelected() );
1551     }
1552
1553     boolean isShowSeqSymbols() {
1554         return ( ( _show_seq_symbols != null ) && _show_seq_symbols.isSelected() );
1555     }
1556
1557     boolean isShowSequenceAcc() {
1558         return ( ( _show_sequence_acc != null ) && _show_sequence_acc.isSelected() );
1559     }
1560
1561     boolean isShowSequenceRelationConfidence() {
1562         return ( ( _seq_relation_confidence_switch != null ) && ( _seq_relation_confidence_switch.isSelected() ) );
1563     }
1564
1565     boolean isShowSequenceRelations() {
1566         return ( ( _show_sequence_relations != null ) && ( _show_sequence_relations.getSelectedIndex() > 0 ) );
1567     }
1568
1569     boolean isShowTaxonomyCode() {
1570         return ( ( _show_taxo_code != null ) && _show_taxo_code.isSelected() );
1571     }
1572
1573     boolean isShowTaxonomyCommonNames() {
1574         return ( ( _show_taxo_common_names != null ) && _show_taxo_common_names.isSelected() );
1575     }
1576
1577     boolean isShowTaxonomyScientificNames() {
1578         return ( ( _show_taxo_scientific_names != null ) && _show_taxo_scientific_names.isSelected() );
1579     }
1580
1581     boolean isUseVisualStyles() {
1582         return ( ( ( getUseVisualStylesCb() != null ) && getUseVisualStylesCb().isSelected() ) || ( ( getUseVisualStylesCb() == null ) && _color_branches ) );
1583     }
1584
1585     boolean isWidthBranches() {
1586         return ( ( _width_branches != null ) && _width_branches.isSelected() );
1587     }
1588
1589     boolean isWriteBranchLengthValues() {
1590         return ( ( _write_branch_length_values != null ) && _write_branch_length_values.isSelected() );
1591     }
1592
1593     void phylogenyAdded( final Configuration configuration ) {
1594         getIsDrawPhylogramList().add( configuration.isDrawAsPhylogram() );
1595     }
1596
1597     void phylogenyRemoved( final int index ) {
1598         getIsDrawPhylogramList().remove( index );
1599     }
1600
1601     void search0() {
1602         final MainPanel main_panel = getMainPanel();
1603         final Phylogeny tree = main_panel.getCurrentPhylogeny();
1604         if ( ( tree == null ) || tree.isEmpty() ) {
1605             return;
1606         }
1607         String query = getSearchTextField0().getText();
1608         if ( query != null ) {
1609             query = query.trim();
1610         }
1611         if ( !ForesterUtil.isEmpty( query ) ) {
1612             search0( main_panel, tree, query );
1613         }
1614         else {
1615             getSearchFoundCountsLabel0().setVisible( false );
1616             getSearchResetButton0().setEnabled( false );
1617             getSearchResetButton0().setVisible( false );
1618             searchReset0();
1619         }
1620     }
1621
1622     void search1() {
1623         final MainPanel main_panel = getMainPanel();
1624         final Phylogeny tree = main_panel.getCurrentPhylogeny();
1625         if ( ( tree == null ) || tree.isEmpty() ) {
1626             return;
1627         }
1628         String query = getSearchTextField1().getText();
1629         if ( query != null ) {
1630             query = query.trim();
1631         }
1632         if ( !ForesterUtil.isEmpty( query ) ) {
1633             search1( main_panel, tree, query );
1634         }
1635         else {
1636             getSearchFoundCountsLabel1().setVisible( false );
1637             getSearchResetButton1().setEnabled( false );
1638             getSearchResetButton1().setVisible( false );
1639             searchReset1();
1640         }
1641     }
1642
1643     void searchReset0() {
1644         if ( getMainPanel().getCurrentTreePanel() != null ) {
1645             getMainPanel().getCurrentTreePanel().setFoundNodes0( null );
1646         }
1647     }
1648
1649     void searchReset1() {
1650         if ( getMainPanel().getCurrentTreePanel() != null ) {
1651             getMainPanel().getCurrentTreePanel().setFoundNodes1( null );
1652         }
1653     }
1654
1655     void setActionWhenNodeClicked( final NodeClickAction action ) {
1656         _action_when_node_clicked = action;
1657     }
1658
1659     void setAnnotationColors( final Map<String, Color> annotation_colors ) {
1660         _annotation_colors = annotation_colors;
1661     }
1662
1663     void setCheckbox( final int which, final boolean state ) {
1664         switch ( which ) {
1665             case Configuration.display_as_phylogram:
1666                 if ( getDisplayAsPhylogramCb() != null ) {
1667                     getDisplayAsPhylogramCb().setSelected( state );
1668                 }
1669                 break;
1670             case Configuration.display_internal_data:
1671                 if ( _display_internal_data != null ) {
1672                     _display_internal_data.setSelected( state );
1673                 }
1674                 break;
1675             case Configuration.color_according_to_species:
1676                 if ( _color_acc_species != null ) {
1677                     _color_acc_species.setSelected( state );
1678                 }
1679                 break;
1680             case Configuration.color_according_to_sequence:
1681                 if ( _color_acc_sequence != null ) {
1682                     _color_acc_sequence.setSelected( state );
1683                 }
1684                 break;
1685             case Configuration.color_according_to_annotation:
1686                 if ( _color_according_to_annotation != null ) {
1687                     _color_according_to_annotation.setSelected( state );
1688                 }
1689                 break;
1690             case Configuration.show_node_names:
1691                 if ( _show_node_names != null ) {
1692                     _show_node_names.setSelected( state );
1693                 }
1694                 break;
1695             case Configuration.show_taxonomy_scientific_names:
1696                 if ( _show_taxo_scientific_names != null ) {
1697                     _show_taxo_scientific_names.setSelected( state );
1698                 }
1699                 break;
1700             case Configuration.show_taxonomy_common_names:
1701                 if ( _show_taxo_common_names != null ) {
1702                     _show_taxo_common_names.setSelected( state );
1703                 }
1704                 break;
1705             case Configuration.show_tax_code:
1706                 if ( _show_taxo_code != null ) {
1707                     _show_taxo_code.setSelected( state );
1708                 }
1709                 break;
1710             case Configuration.show_taxonomy_images:
1711                 if ( _show_taxo_images_cb != null ) {
1712                     _show_taxo_images_cb.setSelected( state );
1713                 }
1714                 break;
1715             case Configuration.show_annotation:
1716                 if ( _show_annotation != null ) {
1717                     _show_annotation.setSelected( state );
1718                 }
1719                 break;
1720             case Configuration.show_binary_characters:
1721                 if ( _show_binary_characters != null ) {
1722                     _show_binary_characters.setSelected( state );
1723                 }
1724                 break;
1725             case Configuration.show_binary_character_counts:
1726                 if ( _show_binary_character_counts != null ) {
1727                     _show_binary_character_counts.setSelected( state );
1728                 }
1729                 break;
1730             case Configuration.write_confidence_values:
1731                 if ( getWriteConfidenceCb() != null ) {
1732                     getWriteConfidenceCb().setSelected( state );
1733                 }
1734                 break;
1735             case Configuration.write_events:
1736                 if ( getShowEventsCb() != null ) {
1737                     getShowEventsCb().setSelected( state );
1738                 }
1739                 break;
1740             case Configuration.use_style:
1741                 if ( getUseVisualStylesCb() != null ) {
1742                     getUseVisualStylesCb().setSelected( state );
1743                 }
1744                 break;
1745             case Configuration.width_branches:
1746                 if ( _width_branches != null ) {
1747                     _width_branches.setSelected( state );
1748                 }
1749                 break;
1750             case Configuration.show_domain_architectures:
1751                 if ( _show_domain_architectures != null ) {
1752                     _show_domain_architectures.setSelected( state );
1753                 }
1754                 break;
1755             case Configuration.write_branch_length_values:
1756                 if ( _write_branch_length_values != null ) {
1757                     _write_branch_length_values.setSelected( state );
1758                 }
1759                 break;
1760             case Configuration.show_mol_seqs:
1761                 if ( _show_mol_seqs != null ) {
1762                     _show_mol_seqs.setSelected( state );
1763                 }
1764                 break;
1765             case Configuration.show_seq_names:
1766                 if ( _show_seq_names != null ) {
1767                     _show_seq_names.setSelected( state );
1768                 }
1769                 break;
1770             case Configuration.show_gene_names:
1771                 if ( _show_gene_names != null ) {
1772                     _show_gene_names.setSelected( state );
1773                 }
1774                 break;
1775             case Configuration.show_seq_symbols:
1776                 if ( _show_seq_symbols != null ) {
1777                     _show_seq_symbols.setSelected( state );
1778                 }
1779                 break;
1780             case Configuration.show_vector_data:
1781                 if ( _show_vector_data_cb != null ) {
1782                     _show_vector_data_cb.setSelected( state );
1783                 }
1784                 break;
1785             case Configuration.show_properties:
1786                 if ( _show_properties_cb != null ) {
1787                     _show_properties_cb.setSelected( state );
1788                 }
1789                 break;
1790             case Configuration.show_sequence_acc:
1791                 if ( _show_sequence_acc != null ) {
1792                     _show_sequence_acc.setSelected( state );
1793                 }
1794                 break;
1795             case Configuration.dynamically_hide_data:
1796                 if ( getDynamicallyHideData() != null ) {
1797                     getDynamicallyHideData().setSelected( state );
1798                 }
1799                 break;
1800             case Configuration.node_data_popup:
1801                 if ( getNodeDescPopupCb() != null ) {
1802                     getNodeDescPopupCb().setSelected( state );
1803                 }
1804                 break;
1805             /* GUILHEM_BEG */
1806             case Configuration.show_relation_confidence:
1807                 if ( _seq_relation_confidence_switch != null ) {
1808                     _seq_relation_confidence_switch.setSelected( state );
1809                 }
1810                 break;
1811             /* GUILHEM_END */
1812             default:
1813                 throw new AssertionError( "unknown checkbox: " + which );
1814         }
1815     }
1816
1817     /**
1818      * Set this checkbox state. Not all checkboxes have been instantiated
1819      * depending on the config.
1820      */
1821     void setCheckbox( final JCheckBox cb, final boolean state ) {
1822         if ( cb != null ) {
1823             cb.setSelected( state );
1824         }
1825     }
1826
1827     void setClickToAction( final int action ) {
1828         // Set click-to action
1829         if ( action == _show_data_item ) {
1830             setActionWhenNodeClicked( NodeClickAction.SHOW_DATA );
1831         }
1832         else if ( action == _collapse_cb_item ) {
1833             setActionWhenNodeClicked( NodeClickAction.COLLAPSE );
1834         }
1835         else if ( action == _reroot_cb_item ) {
1836             setActionWhenNodeClicked( NodeClickAction.REROOT );
1837         }
1838         else if ( action == _subtree_cb_item ) {
1839             setActionWhenNodeClicked( NodeClickAction.SUBTREE );
1840         }
1841         else if ( action == _swap_cb_item ) {
1842             setActionWhenNodeClicked( NodeClickAction.SWAP );
1843         }
1844         else if ( action == _color_subtree_cb_item ) {
1845             setActionWhenNodeClicked( NodeClickAction.COLOR_SUBTREE );
1846         }
1847         else if ( action == _open_seq_web_item ) {
1848             setActionWhenNodeClicked( NodeClickAction.OPEN_SEQ_WEB );
1849         }
1850         else if ( action == _sort_descendents_item ) {
1851             setActionWhenNodeClicked( NodeClickAction.SORT_DESCENDENTS );
1852         }
1853         else if ( action == _blast_item ) {
1854             setActionWhenNodeClicked( NodeClickAction.BLAST );
1855         }
1856         else if ( action == _open_tax_web_item ) {
1857             setActionWhenNodeClicked( NodeClickAction.OPEN_TAX_WEB );
1858         }
1859         else if ( action == _cut_subtree_item ) {
1860             setActionWhenNodeClicked( NodeClickAction.CUT_SUBTREE );
1861         }
1862         else if ( action == _copy_subtree_item ) {
1863             setActionWhenNodeClicked( NodeClickAction.COPY_SUBTREE );
1864         }
1865         else if ( action == _delete_node_or_subtree_item ) {
1866             setActionWhenNodeClicked( NodeClickAction.DELETE_NODE_OR_SUBTREE );
1867         }
1868         else if ( action == _paste_subtree_item ) {
1869             setActionWhenNodeClicked( NodeClickAction.PASTE_SUBTREE );
1870         }
1871         else if ( action == _add_new_node_item ) {
1872             setActionWhenNodeClicked( NodeClickAction.ADD_NEW_NODE );
1873         }
1874         else if ( action == _edit_node_data_item ) {
1875             setActionWhenNodeClicked( NodeClickAction.EDIT_NODE_DATA );
1876         }
1877         else if ( action == _select_nodes_item ) {
1878             setActionWhenNodeClicked( NodeClickAction.SELECT_NODES );
1879         }
1880         else if ( action == _get_ext_desc_data ) {
1881             setActionWhenNodeClicked( NodeClickAction.GET_EXT_DESC_DATA );
1882         }
1883         else if ( action == _open_pdb_item ) {
1884             setActionWhenNodeClicked( NodeClickAction.OPEN_PDB_WEB );
1885         }
1886         else if ( action == _color_node_font_item ) {
1887             setActionWhenNodeClicked( NodeClickAction.COLOR_NODE_FONT );
1888         }
1889         else if ( action == _change_node_font_item ) {
1890             setActionWhenNodeClicked( NodeClickAction.CHANGE_NODE_FONT );
1891         }
1892         else {
1893             throw new RuntimeException( "unknown action: " + action );
1894         }
1895         // make sure drop down is displaying the correct action
1896         // in case this was called from outside the class
1897         _click_to_combobox.setSelectedIndex( action );
1898     }
1899
1900     void setColorBranches( final boolean color_branches ) {
1901         _color_branches = color_branches;
1902     }
1903
1904     void setDrawPhylogram( final boolean b ) {
1905         getDisplayAsPhylogramCb().setSelected( b );
1906         setDrawPhylogram( getMainPanel().getCurrentTabIndex(), b );
1907     }
1908
1909     void setDrawPhylogramEnabled( final boolean b ) {
1910         getDisplayAsPhylogramCb().setEnabled( b );
1911     }
1912
1913     void setDynamicHidingIsOn( final boolean is_on ) {
1914         if ( is_on ) {
1915             getDynamicallyHideData().setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
1916         }
1917         else {
1918             if ( !_configuration.isUseNativeUI() ) {
1919                 getDynamicallyHideData().setForeground( getConfiguration().getGuiButtonTextColor() );
1920             }
1921             else {
1922                 getDynamicallyHideData().setForeground( Color.BLACK );
1923             }
1924         }
1925     }
1926
1927     void setSearchFoundCountsOnLabel0( final int counts ) {
1928         getSearchFoundCountsLabel0().setText( "Found: " + counts );
1929     }
1930
1931     void setSearchFoundCountsOnLabel1( final int counts ) {
1932         getSearchFoundCountsLabel1().setText( "Found: " + counts );
1933     }
1934
1935     void setSequenceColors( final Map<String, Color> sequence_colors ) {
1936         _sequence_colors = sequence_colors;
1937     }
1938
1939     void setShowEvents( final boolean show_events ) {
1940         if ( getShowEventsCb() == null ) {
1941             _show_events = new JCheckBox( "" );
1942         }
1943         getShowEventsCb().setSelected( show_events );
1944     }
1945
1946     void setSpeciesColors( final Map<String, Color> species_colors ) {
1947         _species_colors = species_colors;
1948     }
1949
1950     void setupControls() {
1951         // The tree display options:
1952         setupDisplayCheckboxes();
1953         /* GUILHEM_BEG */
1954         // The sequence relation query selection combo-box
1955         if ( _configuration.displaySequenceRelations() ) {
1956             addSequenceRelationBlock();
1957         }
1958         /* GUILHEM_END */
1959         // Click-to options
1960         startClickToOptions();
1961         setupClickToOptions();
1962         endClickToOptions();
1963         // Zoom and quick edit buttons
1964         addButtons();
1965         setupSearchTools0();
1966         setupSearchTools1();
1967     }
1968
1969     void setUpControlsForDomainStrucures() {
1970         _domain_display_label = new JLabel( "Domain Architectures:" );
1971         add( customizeLabel( _domain_display_label, getConfiguration() ) );
1972         add( _domain_display_label );
1973         _zoom_in_domain_structure = new JButton( "d+" );
1974         _zoom_out_domain_structure = new JButton( "d-" );
1975         _decr_domain_structure_evalue_thr = new JButton( "-" );
1976         _incr_domain_structure_evalue_thr = new JButton( "+" );
1977         _zoom_in_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1978         _zoom_out_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1979         _decr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1980         _incr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1981         _incr_domain_structure_evalue_thr.setToolTipText( "Increase the E-value threshold by a factor of 10" );
1982         _decr_domain_structure_evalue_thr.setToolTipText( "Decrease the E-value threshold by a factor of 10" );
1983         _domain_structure_evalue_thr_tf = new JTextField( 3 );
1984         _domain_structure_evalue_thr_tf.setEditable( false );
1985         if ( !getConfiguration().isUseNativeUI() ) {
1986             _domain_structure_evalue_thr_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1987             _domain_structure_evalue_thr_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1988             _domain_structure_evalue_thr_tf.setBorder( null );
1989         }
1990         final JPanel d1_panel = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1991         final JPanel d2_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
1992         if ( !_configuration.isUseNativeUI() ) {
1993             d1_panel.setBackground( getBackground() );
1994             d2_panel.setBackground( getBackground() );
1995         }
1996         add( d1_panel );
1997         add( d2_panel );
1998         addJButton( _zoom_out_domain_structure, d1_panel );
1999         addJButton( _zoom_in_domain_structure, d1_panel );
2000         addJButton( _decr_domain_structure_evalue_thr, d2_panel );
2001         addJTextField( _domain_structure_evalue_thr_tf, d2_panel );
2002         addJButton( _incr_domain_structure_evalue_thr, d2_panel );
2003     }
2004
2005     void setupSearchTools0() {
2006         final JLabel search_label = new JLabel( "Search (A):" );
2007         search_label.setFont( ControlPanel.jcb_bold_font );
2008         if ( !getConfiguration().isUseNativeUI() ) {
2009             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
2010         }
2011         add( search_label );
2012         search_label.setToolTipText( SEARCH_TIP_TEXT );
2013         _search_found_label_0 = new JLabel();
2014         getSearchFoundCountsLabel0().setVisible( false );
2015         _search_found_label_0.setFont( ControlPanel.jcb_bold_font );
2016         if ( !getConfiguration().isUseNativeUI() ) {
2017             _search_found_label_0.setForeground( getConfiguration().getGuiCheckboxTextColor() );
2018         }
2019         _search_tf_0 = new JTextField( 3 );
2020         _search_tf_0.setToolTipText( SEARCH_TIP_TEXT );
2021         _search_tf_0.setEditable( true );
2022         if ( !getConfiguration().isUseNativeUI() ) {
2023             _search_tf_0.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
2024             _search_tf_0.setBackground( getConfiguration().getGuiCheckboxTextColor() );
2025             _search_tf_0.setBorder( null );
2026         }
2027         _search_reset_button_0 = new JButton();
2028         getSearchResetButton0().setText( "Reset" );
2029         getSearchResetButton0().setEnabled( false );
2030         getSearchResetButton0().setVisible( false );
2031         final JPanel s_panel_1 = new JPanel( new BorderLayout() );
2032         final JPanel s_panel_2 = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
2033         s_panel_1.setBackground( getBackground() );
2034         add( s_panel_1 );
2035         s_panel_2.setBackground( getBackground() );
2036         add( s_panel_2 );
2037         final KeyAdapter key_adapter = new KeyAdapter() {
2038
2039             @Override
2040             public void keyReleased( final KeyEvent key_event ) {
2041                 search0();
2042                 displayedPhylogenyMightHaveChanged( true );
2043             }
2044         };
2045         final ActionListener action_listener = new ActionListener() {
2046
2047             @Override
2048             public void actionPerformed( final ActionEvent e ) {
2049                 searchReset0();
2050                 setSearchFoundCountsOnLabel0( 0 );
2051                 getSearchFoundCountsLabel0().setVisible( false );
2052                 getSearchTextField0().setText( "" );
2053                 getSearchResetButton0().setEnabled( false );
2054                 getSearchResetButton0().setVisible( false );
2055                 displayedPhylogenyMightHaveChanged( true );
2056             }
2057         };
2058         _search_reset_button_0.addActionListener( action_listener );
2059         _search_tf_0.addKeyListener( key_adapter );
2060         addJTextField( _search_tf_0, s_panel_1 );
2061         s_panel_2.add( _search_found_label_0 );
2062         addJButton( _search_reset_button_0, s_panel_2 );
2063     }
2064
2065     void setupSearchTools1() {
2066         final JLabel search_label = new JLabel( "Search (B):" );
2067         search_label.setFont( ControlPanel.jcb_bold_font );
2068         if ( !getConfiguration().isUseNativeUI() ) {
2069             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
2070         }
2071         add( search_label );
2072         search_label.setToolTipText( SEARCH_TIP_TEXT );
2073         _search_found_label_1 = new JLabel();
2074         getSearchFoundCountsLabel1().setVisible( false );
2075         _search_found_label_1.setFont( ControlPanel.jcb_bold_font );
2076         if ( !getConfiguration().isUseNativeUI() ) {
2077             _search_found_label_1.setForeground( getConfiguration().getGuiCheckboxTextColor() );
2078         }
2079         _search_tf_1 = new JTextField( 3 );
2080         _search_tf_1.setToolTipText( SEARCH_TIP_TEXT );
2081         _search_tf_1.setEditable( true );
2082         if ( !getConfiguration().isUseNativeUI() ) {
2083             _search_tf_1.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
2084             _search_tf_1.setBackground( getConfiguration().getGuiCheckboxTextColor() );
2085             _search_tf_1.setBorder( null );
2086         }
2087         _search_reset_button_1 = new JButton();
2088         getSearchResetButton1().setText( "Reset" );
2089         getSearchResetButton1().setEnabled( false );
2090         getSearchResetButton1().setVisible( false );
2091         final JPanel s_panel_1 = new JPanel( new BorderLayout() );
2092         final JPanel s_panel_2 = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
2093         s_panel_1.setBackground( getBackground() );
2094         add( s_panel_1 );
2095         s_panel_2.setBackground( getBackground() );
2096         add( s_panel_2 );
2097         final KeyAdapter key_adapter = new KeyAdapter() {
2098
2099             @Override
2100             public void keyReleased( final KeyEvent key_event ) {
2101                 search1();
2102                 displayedPhylogenyMightHaveChanged( true );
2103             }
2104         };
2105         final ActionListener action_listener = new ActionListener() {
2106
2107             @Override
2108             public void actionPerformed( final ActionEvent e ) {
2109                 searchReset1();
2110                 setSearchFoundCountsOnLabel1( 0 );
2111                 getSearchFoundCountsLabel1().setVisible( false );
2112                 getSearchTextField1().setText( "" );
2113                 getSearchResetButton1().setEnabled( false );
2114                 getSearchResetButton1().setVisible( false );
2115                 displayedPhylogenyMightHaveChanged( true );
2116             }
2117         };
2118         _search_reset_button_1.addActionListener( action_listener );
2119         _search_tf_1.addKeyListener( key_adapter );
2120         addJTextField( _search_tf_1, s_panel_1 );
2121         s_panel_2.add( _search_found_label_1 );
2122         addJButton( _search_reset_button_1, s_panel_2 );
2123     }
2124
2125     void setVisibilityOfDomainStrucureCB() {
2126         try {
2127             if ( ( getCurrentTreePanel() != null )
2128                     && ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( getCurrentTreePanel()
2129                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
2130                 if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) {
2131                     getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( false );
2132                 }
2133                 if ( getMainPanel().getMainFrame()._show_domain_labels != null ) {
2134                     getMainPanel().getMainFrame()._show_domain_labels.setVisible( false );
2135                 }
2136             }
2137             else if ( isShowDomainArchitectures() ) {
2138                 if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) {
2139                     getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( true );
2140                 }
2141                 if ( getMainPanel().getMainFrame()._show_domain_labels != null ) {
2142                     getMainPanel().getMainFrame()._show_domain_labels.setVisible( true );
2143                 }
2144             }
2145             else {
2146                 if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) {
2147                     getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( false );
2148                 }
2149                 if ( getMainPanel().getMainFrame()._show_domain_labels != null ) {
2150                     getMainPanel().getMainFrame()._show_domain_labels.setVisible( false );
2151                 }
2152             }
2153         }
2154         catch ( final Exception ignore ) {
2155             //not important...
2156         }
2157     }
2158
2159     void setVisibilityOfX() {
2160         final MainFrame mf = getMainFrame();
2161         if ( mf != null ) {
2162             if ( ( getCurrentTreePanel() != null ) && ( getCurrentTreePanel().getPhylogeny() != null ) ) {
2163                 if ( AptxUtil.isHasAtLeastOneBranchWithSupportSD( getCurrentTreePanel().getPhylogeny() ) ) {
2164                     if ( mf._show_confidence_stddev_cbmi != null ) {
2165                         mf._show_confidence_stddev_cbmi.setVisible( true );
2166                     }
2167                 }
2168                 else {
2169                     if ( mf._show_confidence_stddev_cbmi != null ) {
2170                         mf._show_confidence_stddev_cbmi.setVisible( false );
2171                     }
2172                 }
2173                 if ( AptxUtil.isHasAtLeastOneNodeWithScientificName( getCurrentTreePanel().getPhylogeny() ) ) {
2174                     if ( mf._abbreviate_scientific_names != null ) {
2175                         mf._abbreviate_scientific_names.setVisible( true );
2176                     }
2177                 }
2178                 else {
2179                     if ( mf._abbreviate_scientific_names != null ) {
2180                         mf._abbreviate_scientific_names.setVisible( false );
2181                     }
2182                 }
2183                 if ( AptxUtil.isHasAtLeastOneNodeWithSequenceAnnotation( getCurrentTreePanel().getPhylogeny() ) ) {
2184                     if ( mf._show_annotation_ref_source != null ) {
2185                         mf._show_annotation_ref_source.setVisible( true );
2186                     }
2187                 }
2188                 else {
2189                     if ( mf._show_annotation_ref_source != null ) {
2190                         mf._show_annotation_ref_source.setVisible( false );
2191                     }
2192                 }
2193             }
2194             if ( isDrawPhylogram()
2195                     || ( ( getCurrentTreePanel() != null ) && ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( getCurrentTreePanel()
2196                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) ) {
2197                 if ( mf._non_lined_up_cladograms_rbmi != null ) {
2198                     mf._non_lined_up_cladograms_rbmi.setVisible( false );
2199                 }
2200                 if ( mf._uniform_cladograms_rbmi != null ) {
2201                     mf._uniform_cladograms_rbmi.setVisible( false );
2202                 }
2203                 if ( mf._ext_node_dependent_cladogram_rbmi != null ) {
2204                     mf._ext_node_dependent_cladogram_rbmi.setVisible( false );
2205                 }
2206             }
2207             else {
2208                 if ( mf._non_lined_up_cladograms_rbmi != null ) {
2209                     mf._non_lined_up_cladograms_rbmi.setVisible( true );
2210                 }
2211                 if ( mf._uniform_cladograms_rbmi != null ) {
2212                     mf._uniform_cladograms_rbmi.setVisible( true );
2213                 }
2214                 if ( mf._ext_node_dependent_cladogram_rbmi != null ) {
2215                     mf._ext_node_dependent_cladogram_rbmi.setVisible( true );
2216                 }
2217             }
2218             if ( isDrawPhylogram() ) {
2219                 if ( mf._show_scale_cbmi != null ) {
2220                     mf._show_scale_cbmi.setVisible( true );
2221                 }
2222             }
2223             else {
2224                 if ( mf._show_scale_cbmi != null ) {
2225                     mf._show_scale_cbmi.setVisible( false );
2226                 }
2227             }
2228             if ( getCurrentTreePanel() != null ) {
2229                 if ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
2230                         || ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
2231                     if ( mf._label_direction_cbmi != null ) {
2232                         mf._label_direction_cbmi.setVisible( true );
2233                     }
2234                 }
2235                 else {
2236                     if ( mf._label_direction_cbmi != null ) {
2237                         mf._label_direction_cbmi.setVisible( false );
2238                     }
2239                 }
2240             }
2241         }
2242     }
2243
2244     void showAnnotations() {
2245         if ( _show_annotation != null ) {
2246             _show_annotation.setSelected( true );
2247         }
2248         if ( _color_according_to_annotation != null ) {
2249             _color_according_to_annotation.setSelected( true );
2250         }
2251         if ( _color_acc_species != null ) {
2252             _color_acc_species.setSelected( false );
2253         }
2254         if ( _color_acc_sequence != null ) {
2255             _color_acc_sequence.setSelected( false );
2256         }
2257         _mainpanel.getCurrentTreePanel().repaint();
2258     }
2259
2260     /**
2261      * Fit entire tree into window.
2262      */
2263     void showWhole() {
2264         if ( ( _mainpanel.getCurrentScrollPane() == null ) || _mainpanel.getCurrentTreePanel().getPhylogeny().isEmpty() ) {
2265             return;
2266         }
2267         getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
2268         displayedPhylogenyMightHaveChanged( true );
2269         _mainpanel.getCurrentTreePanel().updateOvSettings();
2270         _mainpanel.getCurrentTreePanel().validate();
2271         _mainpanel.validate();
2272         _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
2273                                                                     _mainpanel.getSizeOfViewport().height );
2274         _mainpanel.getCurrentTreePanel().resetPreferredSize();
2275         _mainpanel.adjustJScrollPane();
2276         _mainpanel.getCurrentTreePanel().repaint();
2277         _mainpanel.getCurrentTreePanel().validate();
2278         _mainpanel.validate();
2279         _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
2280                                                                     _mainpanel.getSizeOfViewport().height );
2281         _mainpanel.getCurrentTreePanel().resetPreferredSize();
2282         _mainpanel.adjustJScrollPane();
2283         _mainpanel.getCurrentTreePanel().repaint();
2284         _mainpanel.getCurrentTreePanel().updateOvSizes();
2285     }
2286
2287     void showWholeAll() {
2288         for( final TreePanel tree_panel : _mainpanel.getTreePanels() ) {
2289             if ( tree_panel != null ) {
2290                 tree_panel.validate();
2291                 tree_panel.calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
2292                                                       _mainpanel.getSizeOfViewport().height );
2293                 tree_panel.resetPreferredSize();
2294                 tree_panel.repaint();
2295             }
2296         }
2297     }
2298
2299     // Create header for click-to combo box.
2300     void startClickToOptions() {
2301         final JLabel spacer = new JLabel( "" );
2302         spacer.setFont( ControlPanel.jcb_font );
2303         add( spacer );
2304         _click_to_label = new JLabel( "Click on Node to:" );
2305         add( customizeLabel( _click_to_label, getConfiguration() ) );
2306         _click_to_combobox = new JComboBox<String>();
2307         _click_to_combobox.setFocusable( false );
2308         _click_to_combobox.setMaximumRowCount( 14 );
2309         _click_to_combobox.setFont( ControlPanel.js_font );
2310         if ( !_configuration.isUseNativeUI() ) {
2311             _click_to_combobox.setBackground( getConfiguration().getGuiBackgroundColor() );
2312         }
2313         // don't add listener until all items are set (or each one will trigger
2314         // an event)
2315         // click_to_list.addActionListener(this);
2316         add( _click_to_combobox );
2317         // Correlates option names to titles
2318         _all_click_to_names = new HashMap<Integer, String>();
2319         _click_to_names = new ArrayList<String>();
2320     }
2321
2322     void tabChanged() {
2323         if ( getMainPanel().getTabbedPane().getTabCount() > 0 ) {
2324             if ( getCurrentTreePanel().isPhyHasBranchLengths()
2325                     && ( getCurrentTreePanel().getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
2326                 setDrawPhylogramEnabled( true );
2327                 setDrawPhylogram( isDrawPhylogram() );
2328             }
2329             else {
2330                 setDrawPhylogramEnabled( false );
2331                 setDrawPhylogram( false );
2332             }
2333             if ( getMainPanel().getMainFrame() == null ) {
2334                 // Must be "E" applet version.
2335                 final ArchaeopteryxE e = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
2336                 e.setSelectedTypeInTypeMenu( e.getCurrentTreePanel().getPhylogenyGraphicsType() );
2337             }
2338             else {
2339                 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getMainPanel().getCurrentTreePanel()
2340                         .getPhylogenyGraphicsType() );
2341             }
2342             getMainPanel().getCurrentTreePanel().updateSubSuperTreeButton();
2343             getMainPanel().getControlPanel().search0();
2344             getMainPanel().getControlPanel().search1();
2345             getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
2346             getSequenceRelationTypeBox().removeAllItems();
2347             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
2348                     .getRelevantSequenceRelationTypes() ) {
2349                 _sequence_relation_type_box.addItem( type );
2350             }
2351             getMainPanel().getCurrentTreePanel().repaint();
2352             //setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
2353             // according to GUILHEM the line above can be removed.
2354         }
2355     }
2356
2357     /**
2358      * Uncollapse all nodes.
2359      */
2360     void uncollapseAll( final TreePanel tp ) {
2361         final Phylogeny t = tp.getPhylogeny();
2362         if ( ( t != null ) && !t.isEmpty() ) {
2363             for( final PhylogenyNodeIterator iter = t.iteratorPreorder(); iter.hasNext(); ) {
2364                 final PhylogenyNode node = iter.next();
2365                 node.setCollapse( false );
2366             }
2367             tp.resetNodeIdToDistToLeafMap();
2368             tp.updateSetOfCollapsedExternalNodes();
2369             t.recalculateNumberOfExternalDescendants( false );
2370             tp.setNodeInPreorderToNull();
2371             t.clearHashIdToNodeMap();
2372             showWhole();
2373         }
2374     }
2375
2376     void updateDomainStructureEvaluethresholdDisplay() {
2377         if ( _domain_structure_evalue_thr_tf != null ) {
2378             _domain_structure_evalue_thr_tf.setText( "10^"
2379                     + getMainPanel().getCurrentTreePanel().getDomainStructureEvalueThresholdExp() );
2380         }
2381     }
2382
2383     void zoomInX( final float factor, final float x_correction_factor ) {
2384         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
2385         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
2386         treepanel.multiplyUrtFactor( 1f );
2387         if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
2388                 || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
2389                 || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
2390                 || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
2391             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
2392             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
2393             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
2394             getMainPanel().adjustJScrollPane();
2395             treepanel.resetPreferredSize();
2396             getMainPanel().getCurrentScrollPane().getViewport().validate();
2397             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
2398                     - ( sb.getVisibleAmount() / 2.0 ) ) );
2399         }
2400         else {
2401             final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
2402             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
2403             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
2404             getMainPanel().adjustJScrollPane();
2405             treepanel.resetPreferredSize();
2406             getMainPanel().getCurrentScrollPane().getViewport().validate();
2407             sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
2408         }
2409         treepanel.resetPreferredSize();
2410         treepanel.updateOvSizes();
2411     }
2412
2413     void zoomInY( final float factor ) {
2414         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
2415         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
2416         treepanel.multiplyUrtFactor( 1.1f );
2417         final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
2418         treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
2419         getMainPanel().adjustJScrollPane();
2420         treepanel.resetPreferredSize();
2421         getMainPanel().getCurrentScrollPane().getViewport().validate();
2422         sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
2423                 - ( sb.getVisibleAmount() / 2.0 ) ) );
2424         treepanel.resetPreferredSize();
2425         treepanel.updateOvSizes();
2426     }
2427
2428     void zoomOutX( final float factor, final float x_correction_factor ) {
2429         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
2430         treepanel.multiplyUrtFactor( 1f );
2431         if ( ( treepanel.getXdistance() * factor ) > 0.0 ) {
2432             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
2433             if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
2434                     || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
2435                     || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
2436                     || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
2437                 getMainPanel().adjustJScrollPane();
2438                 treepanel.resetPreferredSize();
2439                 getMainPanel().getCurrentScrollPane().getViewport().validate();
2440                 final double x = ( sb.getMaximum() - sb.getMinimum() )
2441                         / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
2442                 treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
2443                 treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
2444                 getMainPanel().adjustJScrollPane();
2445                 treepanel.resetPreferredSize();
2446                 getMainPanel().getCurrentScrollPane().getViewport().validate();
2447                 sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
2448                         - ( sb.getVisibleAmount() / 2.0 ) ) );
2449             }
2450             else {
2451                 final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
2452                 treepanel.setXdistance( treepanel.getXdistance() * factor );
2453                 treepanel.setXcorrectionFactor( treepanel.getXcorrectionFactor() * x_correction_factor );
2454                 if ( x > 0 ) {
2455                     getMainPanel().adjustJScrollPane();
2456                     treepanel.resetPreferredSize();
2457                     getMainPanel().getCurrentScrollPane().getViewport().validate();
2458                     sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
2459                 }
2460             }
2461             treepanel.resetPreferredSize();
2462             treepanel.updateOvSizes();
2463         }
2464     }
2465
2466     void zoomOutY( final float factor ) {
2467         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
2468         treepanel.multiplyUrtFactor( 0.9f );
2469         if ( ( treepanel.getYdistance() * factor ) > 0.0 ) {
2470             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
2471             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
2472             treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
2473             getMainPanel().adjustJScrollPane();
2474             treepanel.resetPreferredSize();
2475             getMainPanel().getCurrentScrollPane().getViewport().validate();
2476             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
2477                     - ( sb.getVisibleAmount() / 2.0 ) ) );
2478             treepanel.resetPreferredSize();
2479             treepanel.updateOvSizes();
2480         }
2481     }
2482
2483     static JLabel customizeLabel( final JLabel label, final Configuration configuration ) {
2484         label.setFont( ControlPanel.jcb_bold_font );
2485         if ( !configuration.isUseNativeUI() ) {
2486             label.setForeground( configuration.getGuiCheckboxTextColor() );
2487             label.setBackground( configuration.getGuiBackgroundColor() );
2488         }
2489         return label;
2490     }
2491
2492     public JCheckBox getUseBranchWidthsCb() {
2493         return _width_branches;
2494     }
2495 }