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