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