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