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