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