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