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