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