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