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