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