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