initial commit
[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: www.phylosoft.org/forester
24
25 package org.forester.archaeopteryx;
26
27 import java.awt.BorderLayout;
28 import java.awt.Color;
29 import java.awt.Component;
30 import java.awt.Dimension;
31 import java.awt.Font;
32 import java.awt.GridBagLayout;
33 import java.awt.GridLayout;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.awt.event.KeyAdapter;
39 import java.awt.event.KeyEvent;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.HashMap;
44 import java.util.HashSet;
45 import java.util.List;
46 import java.util.Map;
47
48 import javax.swing.BorderFactory;
49 import javax.swing.DefaultListCellRenderer;
50 import javax.swing.JButton;
51 import javax.swing.JCheckBox;
52 import javax.swing.JComboBox;
53 import javax.swing.JLabel;
54 import javax.swing.JList;
55 import javax.swing.JPanel;
56 import javax.swing.JScrollBar;
57 import javax.swing.JTextField;
58 import javax.swing.ListCellRenderer;
59
60 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
61 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
62 import org.forester.phylogeny.Phylogeny;
63 import org.forester.phylogeny.PhylogenyMethods;
64 import org.forester.phylogeny.PhylogenyNode;
65 import org.forester.phylogeny.data.Sequence;
66 import org.forester.phylogeny.data.SequenceRelation;
67 import org.forester.util.ForesterUtil;
68
69 final class ControlPanel extends JPanel implements ActionListener {
70
71     private static final String  RETURN_TO_SUPER_TREE_TEXT = "Back to Super Tree";
72     final static Font            jcb_font                  = new Font( Configuration.getDefaultFontFamilyName(),
73                                                                        Font.PLAIN,
74                                                                        9 );
75     final static Font            js_font                   = new Font( Configuration.getDefaultFontFamilyName(),
76                                                                        Font.PLAIN,
77                                                                        9 );
78     final static Font            jcb_bold_font             = new Font( Configuration.getDefaultFontFamilyName(),
79                                                                        Font.BOLD,
80                                                                        9 );
81     private static final long    serialVersionUID          = -8463483932821545633L;
82     private final MainPanel      _mainpanel;
83     // The settings from the conf file
84     private final Configuration  _configuration;
85     // Tree checkboxes
86     private JCheckBox            _display_internal_data;
87     private JCheckBox            _show_node_names;
88     private JCheckBox            _show_taxo_code;
89     private JCheckBox            _write_confidence;
90     private JCheckBox            _show_events;
91     private JCheckBox            _color_acc_species;
92     private JCheckBox            _color_branches_cb;
93     private JCheckBox            _width_branches;
94     private JCheckBox            _show_domain_architectures;
95     private JCheckBox            _show_annotation;
96     private JCheckBox            _show_binary_characters;
97     private JCheckBox            _show_binary_character_counts;
98     private JCheckBox            _show_gene_names;
99     private JCheckBox            _show_gene_symbols;
100     private JCheckBox            _show_sequence_acc;
101     private JCheckBox            _node_desc_popup_cb;
102     private JCheckBox            _dynamically_hide_data;
103     private JCheckBox            _show_taxo_scientific_names;
104     private JCheckBox            _show_taxo_common_names;
105     private JCheckBox            _show_taxo_images_cb;
106     private JCheckBox            _color_according_to_annotation;
107     private JCheckBox            _display_as_phylogram_cb;
108     private JCheckBox            _seq_relation_confidence_switch;
109     private JComboBox            _show_sequence_relations;
110     private JComboBox            _sequence_relation_type_box;
111     private JCheckBox            _show_vector_data_cb;
112     private JLabel               _click_to_label;
113     private JLabel               _zoom_label;
114     private JLabel               _domain_display_label;
115     private JComboBox            _click_to_combobox;
116     private Map<Integer, String> _all_click_to_names;
117     private List<String>         _click_to_names;
118     // Indices for the click-to options in the combo box
119     private int                  _show_data_item;
120     private int                  _collapse_cb_item;
121     private int                  _reroot_cb_item;
122     private int                  _swap_cb_item;
123     private int                  _subtree_cb_item;
124     private int                  _color_subtree_cb_item;
125     private int                  _open_seq_web_item;
126     private int                  _open_tax_web_item;
127     private int                  _cut_subtree_item;
128     private int                  _copy_subtree_item;
129     private int                  _delete_node_or_subtree_item;
130     private int                  _paste_subtree_item;
131     private int                  _add_new_node_item;
132     private int                  _edit_node_data_item;
133     private int                  _blast_item;
134     // zooming and quick tree manipulation buttons:
135     private JButton              _zoom_in_x;
136     private JButton              _zoom_in_y;
137     private JButton              _zoom_out_x;
138     private JButton              _zoom_out_y;
139     private JButton              _show_whole;
140     private JButton              _order;
141     private JButton              _uncollapse_all;
142     private JButton              _zoom_in_domain_structure;
143     private JButton              _zoom_out_domain_structure;
144     private JButton              _decr_domain_structure_evalue_thr;
145     private JButton              _incr_domain_structure_evalue_thr;
146     private JButton              _return_to_super_tree;
147     private JTextField           _domain_structure_evalue_thr_tf;
148     private JTextField           _search_tf;
149     private boolean              _order_of_appearance;
150     private boolean              _color_branches;
151     private NodeClickAction      _action_when_node_clicked;
152     private List<Boolean>        _draw_phylogram;
153     private Map<String, Color>   _annotation_colors;
154     private Map<String, Color>   _species_colors;
155     private JButton              _search_reset_button;
156     private JLabel               _search_found_label;
157     private Sequence             _selected_query_seq;
158
159     ControlPanel( final MainPanel ap, final Configuration configuration ) {
160         init();
161         _mainpanel = ap;
162         _configuration = configuration;
163         if ( !_configuration.isUseNativeUI() ) {
164             setBackground( getConfiguration().getGuiBackgroundColor() );
165             setBorder( BorderFactory.createRaisedBevelBorder() );
166         }
167         setLayout( new GridLayout( 0, 1, 2, 2 ) );
168         _order_of_appearance = true;
169         setupControls();
170     }
171
172     /**
173      * Handle an action.
174      */
175     public void actionPerformed( final ActionEvent e ) {
176         try {
177             final TreePanel tp = getMainPanel().getCurrentTreePanel();
178             if ( tp == null ) {
179                 return;
180             }
181             if ( e.getSource() == _click_to_combobox ) {
182                 setClickToAction( _click_to_combobox.getSelectedIndex() );
183                 getCurrentTreePanel().repaint();
184             }
185             else if ( e.getSource() == _show_binary_characters ) {
186                 if ( ( _show_binary_character_counts != null ) && _show_binary_characters.isSelected() ) {
187                     _show_binary_character_counts.setSelected( false );
188                 }
189                 displayedPhylogenyMightHaveChanged( true );
190             }
191             else if ( e.getSource() == _show_binary_character_counts ) {
192                 if ( ( _show_binary_characters != null ) && _show_binary_character_counts.isSelected() ) {
193                     _show_binary_characters.setSelected( false );
194                 }
195                 displayedPhylogenyMightHaveChanged( true );
196             }
197             else if ( e.getSource() == _color_according_to_annotation ) {
198                 if ( ( _show_annotation != null ) && _color_according_to_annotation.isSelected() ) {
199                     _show_annotation.setSelected( true );
200                 }
201                 displayedPhylogenyMightHaveChanged( false );
202             }
203             else if ( e.getSource() == _show_annotation ) {
204                 if ( ( _color_according_to_annotation != null ) && !_show_annotation.isSelected() ) {
205                     _color_according_to_annotation.setSelected( false );
206                 }
207                 displayedPhylogenyMightHaveChanged( false );
208             }
209             else if ( ( tp != null ) && ( tp.getPhylogeny() != null ) ) {
210                 if ( e.getSource() == getDisplayAsPhylogramCb() ) {
211                     setDrawPhylogram( getDisplayAsPhylogramCb().isSelected() );
212                     showWhole();
213                 }
214                 // Zoom buttons
215                 else if ( e.getSource() == _zoom_in_x ) {
216                     zoomInX( Constants.BUTTON_ZOOM_IN_FACTOR, Constants.BUTTON_ZOOM_IN_X_CORRECTION_FACTOR );
217                     displayedPhylogenyMightHaveChanged( false );
218                 }
219                 else if ( e.getSource() == _zoom_in_y ) {
220                     zoomInY( Constants.BUTTON_ZOOM_IN_FACTOR );
221                     displayedPhylogenyMightHaveChanged( false );
222                 }
223                 else if ( e.getSource() == _zoom_out_x ) {
224                     zoomOutX( Constants.BUTTON_ZOOM_OUT_FACTOR, Constants.BUTTON_ZOOM_OUT_X_CORRECTION_FACTOR );
225                     displayedPhylogenyMightHaveChanged( false );
226                 }
227                 else if ( e.getSource() == _zoom_out_y ) {
228                     zoomOutY( Constants.BUTTON_ZOOM_OUT_FACTOR );
229                     displayedPhylogenyMightHaveChanged( false );
230                 }
231                 else if ( e.getSource() == _show_whole ) {
232                     showWhole();
233                 }
234                 else if ( e.getSource() == _return_to_super_tree ) {
235                     _mainpanel.getCurrentTreePanel().superTree();
236                     showWhole();
237                 }
238                 else if ( e.getSource() == _order ) {
239                     tp.getPhylogeny().orderAppearance( _order_of_appearance );
240                     _order_of_appearance = !_order_of_appearance;
241                     displayedPhylogenyMightHaveChanged( false );
242                 }
243                 else if ( e.getSource() == _uncollapse_all ) {
244                     uncollapseAll( tp );
245                     displayedPhylogenyMightHaveChanged( false );
246                 }
247                 else if ( e.getSource() == _zoom_in_domain_structure ) {
248                     _mainpanel.getCurrentTreePanel().zoomInDomainStructure();
249                     displayedPhylogenyMightHaveChanged( true );
250                 }
251                 else if ( e.getSource() == _zoom_out_domain_structure ) {
252                     _mainpanel.getCurrentTreePanel().zoomOutDomainStructure();
253                     displayedPhylogenyMightHaveChanged( true );
254                 }
255                 else if ( e.getSource() == _decr_domain_structure_evalue_thr ) {
256                     _mainpanel.getCurrentTreePanel().decreaseDomainStructureEvalueThreshold();
257                     displayedPhylogenyMightHaveChanged( true );
258                 }
259                 else if ( e.getSource() == _incr_domain_structure_evalue_thr ) {
260                     _mainpanel.getCurrentTreePanel().increaseDomainStructureEvalueThreshold();
261                     displayedPhylogenyMightHaveChanged( true );
262                 }
263                 else if ( e.getSource() == _search_tf ) {
264                     search();
265                     displayedPhylogenyMightHaveChanged( true );
266                 }
267                 else {
268                     displayedPhylogenyMightHaveChanged( true );
269                 }
270             }
271             tp.requestFocus();
272             tp.requestFocusInWindow();
273             tp.requestFocus();
274         }
275         catch ( final Exception ex ) {
276             Util.unexpectedException( ex );
277         }
278         catch ( final Error err ) {
279             Util.unexpectedError( err );
280         }
281     }
282
283     void activateButtonToReturnToSuperTree( int index ) {
284         --index;
285         if ( index > 0 ) {
286             _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT + " " + index );
287         }
288         else {
289             _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT );
290         }
291         _return_to_super_tree.setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
292         _return_to_super_tree.setEnabled( true );
293     }
294
295     /**
296      * Add zoom and quick edit buttons. (Last modified 8/9/04)
297      */
298     void addButtons() {
299         final JLabel spacer = new JLabel( "" );
300         spacer.setOpaque( false );
301         add( spacer );
302         final JPanel x_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
303         final JPanel y_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
304         final JPanel z_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
305         if ( !getConfiguration().isUseNativeUI() ) {
306             x_panel.setBackground( getBackground() );
307             y_panel.setBackground( getBackground() );
308             z_panel.setBackground( getBackground() );
309         }
310         add( _zoom_label = new JLabel( "Zoom:" ) );
311         customizeLabel( _zoom_label, getConfiguration() );
312         add( x_panel );
313         add( y_panel );
314         add( z_panel );
315         if ( getConfiguration().isUseNativeUI() ) {
316             _zoom_in_x = new JButton( "+" );
317             _zoom_out_x = new JButton( "-" );
318         }
319         else {
320             _zoom_in_x = new JButton( "X+" );
321             _zoom_out_x = new JButton( "X-" );
322         }
323         _zoom_in_y = new JButton( "Y+" );
324         _zoom_out_y = new JButton( "Y-" );
325         _show_whole = new JButton( "F" );
326         _show_whole.setToolTipText( "To fit the complete phylogeny to the current display size [Backspace]" );
327         _zoom_in_x.setToolTipText( "To zoom in horizontally [Shift+Right]" );
328         _zoom_in_y.setToolTipText( "To zoom in vertically [Shift+Up]" );
329         _zoom_out_x.setToolTipText( "To zoom out horizontally [Shift+Left]" );
330         _zoom_out_y.setToolTipText( "To zoom out vertically [Shift+Down]" );
331         if ( getConfiguration().isUseNativeUI() && Util.isMac() ) {
332             _zoom_out_x.setPreferredSize( new Dimension( 55, 10 ) );
333             _zoom_in_x.setPreferredSize( new Dimension( 55, 10 ) );
334         }
335         else {
336             _zoom_out_x.setPreferredSize( new Dimension( 10, 10 ) );
337             _zoom_in_x.setPreferredSize( new Dimension( 10, 10 ) );
338         }
339         _zoom_out_y.setPreferredSize( new Dimension( 10, 10 ) );
340         _zoom_in_y.setPreferredSize( new Dimension( 10, 10 ) );
341         _show_whole.setPreferredSize( new Dimension( 10, 10 ) );
342         _return_to_super_tree = new JButton( RETURN_TO_SUPER_TREE_TEXT );
343         _return_to_super_tree.setEnabled( false );
344         _order = new JButton( "Order Subtrees" );
345         _uncollapse_all = new JButton( "Uncollapse All" );
346         addJButton( _zoom_in_y, x_panel );
347         addJButton( _zoom_out_x, y_panel );
348         addJButton( _show_whole, y_panel );
349         addJButton( _zoom_in_x, y_panel );
350         addJButton( _zoom_out_y, z_panel );
351         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
352             setUpControlsForDomainStrucures();
353         }
354         final JLabel spacer2 = new JLabel( "" );
355         add( spacer2 );
356         addJButton( _return_to_super_tree, this );
357         addJButton( _order, this );
358         addJButton( _uncollapse_all, this );
359         final JLabel spacer3 = new JLabel( "" );
360         add( spacer3 );
361         setVisibilityOfDomainStrucureControls();
362     }
363
364     void addCheckbox( final int which, final String title ) {
365         final JPanel ch_panel = new JPanel( new BorderLayout( 0, 0 ) );
366         switch ( which ) {
367             case Configuration.display_as_phylogram:
368                 _display_as_phylogram_cb = new JCheckBox( title );
369                 getDisplayAsPhylogramCb().setToolTipText( "To switch between phylogram and cladogram display" );
370                 addJCheckBox( getDisplayAsPhylogramCb(), ch_panel );
371                 add( ch_panel );
372                 break;
373             case Configuration.display_internal_data:
374                 _display_internal_data = new JCheckBox( title );
375                 _display_internal_data.setToolTipText( "To allow or disallow display of internal labels" );
376                 addJCheckBox( _display_internal_data, ch_panel );
377                 add( ch_panel );
378                 break;
379             case Configuration.color_according_to_species:
380                 _color_acc_species = new JCheckBox( title );
381                 _color_acc_species
382                         .setToolTipText( "To colorize taxonomy and sequence labels as a function of taxonomy" );
383                 addJCheckBox( _color_acc_species, ch_panel );
384                 add( ch_panel );
385                 break;
386             case Configuration.color_according_to_annotation:
387                 _color_according_to_annotation = new JCheckBox( title );
388                 _color_according_to_annotation
389                         .setToolTipText( "To colorize sequence annotation labels as a function of sequence annotation" );
390                 addJCheckBox( _color_according_to_annotation, ch_panel );
391                 add( ch_panel );
392                 break;
393             case Configuration.show_node_names:
394                 _show_node_names = new JCheckBox( title );
395                 addJCheckBox( _show_node_names, ch_panel );
396                 add( ch_panel );
397                 break;
398             case Configuration.show_tax_code:
399                 _show_taxo_code = new JCheckBox( title );
400                 addJCheckBox( _show_taxo_code, ch_panel );
401                 add( ch_panel );
402                 break;
403             case Configuration.show_taxonomy_scientific_names:
404                 _show_taxo_scientific_names = new JCheckBox( title );
405                 addJCheckBox( _show_taxo_scientific_names, ch_panel );
406                 add( ch_panel );
407                 break;
408             case Configuration.show_taxonomy_common_names:
409                 _show_taxo_common_names = new JCheckBox( title );
410                 addJCheckBox( _show_taxo_common_names, ch_panel );
411                 add( ch_panel );
412                 break;
413             case Configuration.show_taxonomy_images:
414                 _show_taxo_images_cb = new JCheckBox( title );
415                 addJCheckBox( _show_taxo_images_cb, ch_panel );
416                 add( ch_panel );
417                 break;
418             case Configuration.show_binary_characters:
419                 _show_binary_characters = new JCheckBox( title );
420                 addJCheckBox( _show_binary_characters, ch_panel );
421                 add( ch_panel );
422                 break;
423             case Configuration.show_annotation:
424                 _show_annotation = new JCheckBox( title );
425                 addJCheckBox( _show_annotation, ch_panel );
426                 add( ch_panel );
427                 break;
428             case Configuration.show_binary_character_counts:
429                 _show_binary_character_counts = new JCheckBox( title );
430                 addJCheckBox( _show_binary_character_counts, ch_panel );
431                 add( ch_panel );
432                 break;
433             case Configuration.write_confidence_values:
434                 _write_confidence = new JCheckBox( title );
435                 addJCheckBox( getWriteConfidenceCb(), ch_panel );
436                 add( ch_panel );
437                 break;
438             case Configuration.write_events:
439                 _show_events = new JCheckBox( title );
440                 addJCheckBox( getShowEventsCb(), ch_panel );
441                 add( ch_panel );
442                 break;
443             case Configuration.color_branches:
444                 _color_branches_cb = new JCheckBox( title );
445                 getColorBranchesCb().setToolTipText( "To use branch color values, if present" );
446                 addJCheckBox( getColorBranchesCb(), ch_panel );
447                 add( ch_panel );
448                 break;
449             case Configuration.width_branches:
450                 _width_branches = new JCheckBox( title );
451                 _width_branches.setToolTipText( "To use branch width values, if present" );
452                 addJCheckBox( _width_branches, ch_panel );
453                 add( ch_panel );
454                 break;
455             case Configuration.show_domain_architectures:
456                 _show_domain_architectures = new JCheckBox( title );
457                 addJCheckBox( _show_domain_architectures, ch_panel );
458                 add( ch_panel );
459                 break;
460             case Configuration.show_gene_names:
461                 _show_gene_names = new JCheckBox( title );
462                 addJCheckBox( _show_gene_names, ch_panel );
463                 add( ch_panel );
464                 break;
465             case Configuration.show_gene_symbols:
466                 _show_gene_symbols = new JCheckBox( title );
467                 addJCheckBox( _show_gene_symbols, ch_panel );
468                 add( ch_panel );
469                 break;
470             case Configuration.show_sequence_acc:
471                 _show_sequence_acc = new JCheckBox( title );
472                 addJCheckBox( _show_sequence_acc, ch_panel );
473                 add( ch_panel );
474                 break;
475             case Configuration.dynamically_hide_data:
476                 _dynamically_hide_data = new JCheckBox( title );
477                 getDynamicallyHideData().setToolTipText( "To hide labels depending on likely visibility" );
478                 addJCheckBox( getDynamicallyHideData(), ch_panel );
479                 add( ch_panel );
480                 break;
481             case Configuration.node_data_popup:
482                 _node_desc_popup_cb = new JCheckBox( title );
483                 getNodeDescPopupCb().setToolTipText( "To enable mouse rollover display of basic node data" );
484                 addJCheckBox( getNodeDescPopupCb(), ch_panel );
485                 add( ch_panel );
486                 break;
487             case Configuration.show_relation_confidence:
488                 _seq_relation_confidence_switch = new JCheckBox( title );
489                 addJCheckBox( _seq_relation_confidence_switch, ch_panel );
490                 add( ch_panel );
491                 break;
492             case Configuration.show_vector_data:
493                 _show_vector_data_cb = new JCheckBox( title );
494                 addJCheckBox( _show_vector_data_cb, ch_panel );
495                 add( ch_panel );
496                 break;
497             default:
498                 throw new RuntimeException( "unknown checkbox: " + which );
499         }
500     }// addCheckbox
501
502     private void addClickToOption( final int which, final String title ) {
503         _click_to_combobox.addItem( title );
504         _click_to_names.add( title );
505         _all_click_to_names.put( new Integer( which ), title );
506         if ( !_configuration.isUseNativeUI() ) {
507             _click_to_combobox.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
508             _click_to_combobox.setForeground( getConfiguration().getGuiButtonTextColor() );
509         }
510     }
511
512     void addJButton( final JButton jb, final JPanel p ) {
513         jb.setFocusPainted( false );
514         jb.setFont( ControlPanel.jcb_font );
515         if ( !_configuration.isUseNativeUI() ) {
516             jb.setBorder( BorderFactory.createLineBorder( getConfiguration().getGuiButtonBorderColor() ) );
517             jb.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
518             jb.setForeground( getConfiguration().getGuiButtonTextColor() );
519         }
520         p.add( jb );
521         jb.addActionListener( this );
522     }
523
524     void addJCheckBox( final JCheckBox jcb, final JPanel p ) {
525         jcb.setFocusPainted( false );
526         jcb.setFont( ControlPanel.jcb_font );
527         if ( !_configuration.isUseNativeUI() ) {
528             jcb.setBackground( getConfiguration().getGuiBackgroundColor() );
529             jcb.setForeground( getConfiguration().getGuiCheckboxTextColor() );
530         }
531         p.add( jcb, "Center" );
532         jcb.addActionListener( this );
533     }
534
535     void addJTextField( final JTextField tf, final JPanel p ) {
536         if ( !_configuration.isUseNativeUI() ) {
537             tf.setForeground( getConfiguration().getGuiBackgroundColor() );
538             tf.setFont( ControlPanel.jcb_font );
539         }
540         p.add( tf );
541         tf.addActionListener( this );
542     }
543
544     /* GUILHEM_BEG */
545     private void addSequenceRelationBlock() {
546         final JLabel spacer = new JLabel( "" );
547         spacer.setSize( 1, 1 );
548         add( spacer );
549         final JLabel mainLabel = new JLabel( "Sequence relations to display" );
550         final JLabel typeLabel = customizeLabel( new JLabel( "(type) " ), getConfiguration() );
551         typeLabel.setFont( ControlPanel.js_font.deriveFont( 7 ) );
552         getSequenceRelationTypeBox().setFocusable( false );
553         _sequence_relation_type_box.setFont( ControlPanel.js_font );
554         if ( !_configuration.isUseNativeUI() ) {
555             _sequence_relation_type_box.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
556             _sequence_relation_type_box.setForeground( getConfiguration().getGuiButtonTextColor() );
557         }
558         _sequence_relation_type_box.setRenderer( new ListCellRenderer() {
559
560             @Override
561             public Component getListCellRendererComponent( final JList list,
562                                                            final Object value,
563                                                            final int index,
564                                                            final boolean isSelected,
565                                                            final boolean cellHasFocus ) {
566                 final Component component = new DefaultListCellRenderer().getListCellRendererComponent( list,
567                                                                                                         value,
568                                                                                                         index,
569                                                                                                         isSelected,
570                                                                                                         cellHasFocus );
571                 if ( ( value != null ) && ( value instanceof SequenceRelation.SEQUENCE_RELATION_TYPE ) ) {
572                     ( ( DefaultListCellRenderer ) component ).setText( SequenceRelation
573                             .getPrintableNameByType( ( SequenceRelation.SEQUENCE_RELATION_TYPE ) value ) );
574                 }
575                 return component;
576             }
577         } );
578         final GridBagLayout gbl = new GridBagLayout();
579         _sequence_relation_type_box.setMinimumSize( new Dimension( 115, 17 ) );
580         _sequence_relation_type_box.setPreferredSize( new Dimension( 115, 20 ) );
581         final JPanel horizGrid = new JPanel( gbl );
582         horizGrid.setBackground( getBackground() );
583         horizGrid.add( typeLabel );
584         horizGrid.add( _sequence_relation_type_box );
585         add( customizeLabel( mainLabel, getConfiguration() ) );
586         add( horizGrid );
587         add( getSequenceRelationBox() );
588         if ( _configuration.doDisplayOption( Configuration.show_relation_confidence ) ) {
589             addCheckbox( Configuration.show_relation_confidence, _configuration
590                     .getDisplayTitle( Configuration.show_relation_confidence ) );
591             setCheckbox( Configuration.show_relation_confidence, _configuration
592                     .doCheckOption( Configuration.show_relation_confidence ) );
593         }
594     }// addSequenceRelationBlock
595
596     void deactivateButtonToReturnToSuperTree() {
597         _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT );
598         _return_to_super_tree.setForeground( getConfiguration().getGuiButtonTextColor() );
599         _return_to_super_tree.setEnabled( false );
600     }
601
602     void displayedPhylogenyMightHaveChanged( final boolean recalc_longest_ext_node_info ) {
603         if ( ( _mainpanel != null ) && ( _mainpanel.getCurrentPhylogeny() != null ) ) {
604             if ( getOptions().isShowOverview() ) {
605                 _mainpanel.getCurrentTreePanel().updateOvSizes();
606             }
607             _mainpanel.getCurrentTreePanel().recalculateMaxDistanceToRoot();
608             setVisibilityOfDomainStrucureControls();
609             updateDomainStructureEvaluethresholdDisplay();
610             _mainpanel.getCurrentTreePanel().calculateScaleDistance();
611             _mainpanel.getCurrentTreePanel().calcMaxDepth();
612             _mainpanel.adjustJScrollPane();
613             if ( recalc_longest_ext_node_info ) {
614                 _mainpanel.getCurrentTreePanel().initNodeData();
615                 _mainpanel.getCurrentTreePanel().calculateLongestExtNodeInfo();
616             }
617             _mainpanel.getCurrentTreePanel().repaint();
618             // _mainpanel.getCurrentTreePanel().setUpUrtFactors();
619         }
620     }
621
622     void endClickToOptions() {
623         _click_to_combobox.addActionListener( this );
624     }
625
626     /**
627      * Indicates what action should be execute when a node is clicked
628      * 
629      * @return the click-on action
630      */
631     NodeClickAction getActionWhenNodeClicked() {
632         return _action_when_node_clicked;
633     }
634
635     Map<Integer, String> getAllClickToItems() {
636         return _all_click_to_names;
637     }
638
639     Map<String, Color> getAnnotationColors() {
640         return _annotation_colors;
641     }
642
643     public JCheckBox getColorBranchesCb() {
644         return _color_branches_cb;
645     }
646
647     Configuration getConfiguration() {
648         return _configuration;
649     }
650
651     TreePanel getCurrentTreePanel() {
652         return getMainPanel().getCurrentTreePanel();
653     }
654
655     public JCheckBox getDisplayAsPhylogramCb() {
656         return _display_as_phylogram_cb;
657     }
658
659     public JCheckBox getDynamicallyHideData() {
660         return _dynamically_hide_data;
661     }
662
663     /* GUILHEM_END */
664     private List<Boolean> getIsDrawPhylogramList() {
665         return _draw_phylogram;
666     }
667
668     MainPanel getMainPanel() {
669         return _mainpanel;
670     }
671
672     public JCheckBox getNodeDescPopupCb() {
673         return _node_desc_popup_cb;
674     }
675
676     Options getOptions() {
677         return getMainPanel().getOptions();
678     }
679
680     private JLabel getSearchFoundCountsLabel() {
681         return _search_found_label;
682     }
683
684     private JButton getSearchResetButton() {
685         return _search_reset_button;
686     }
687
688     JTextField getSearchTextField() {
689         return _search_tf;
690     }
691
692     public Sequence getSelectedQuerySequence() {
693         return _selected_query_seq;
694     }
695
696     public JComboBox getSequenceRelationBox() {
697         if ( _show_sequence_relations == null ) {
698             _show_sequence_relations = new JComboBox();
699             _show_sequence_relations.setFocusable( false );
700             _show_sequence_relations.setMaximumRowCount( 20 );
701             _show_sequence_relations.setFont( ControlPanel.js_font );
702             if ( !_configuration.isUseNativeUI() ) {
703                 _show_sequence_relations.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
704                 _show_sequence_relations.setForeground( getConfiguration().getGuiButtonTextColor() );
705             }
706             _show_sequence_relations.addItem( "-----" );
707             _show_sequence_relations.setToolTipText( "To display orthology information for selected query" );
708         }
709         return _show_sequence_relations;
710     }
711
712     /* GUILHEM_BEG */
713     public JComboBox getSequenceRelationTypeBox() {
714         if ( _sequence_relation_type_box == null ) {
715             _sequence_relation_type_box = new JComboBox();
716             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : SequenceRelation.SEQUENCE_RELATION_TYPE.values() ) {
717                 _sequence_relation_type_box.addItem( type );
718             }
719             _sequence_relation_type_box.addActionListener( new ActionListener() {
720
721                 @Override
722                 public void actionPerformed( final ActionEvent e ) {
723                     if ( _mainpanel.getCurrentPhylogeny() != null ) {
724                         setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
725                     }
726                 }
727             } );
728         }
729         return _sequence_relation_type_box;
730     }
731
732     public JCheckBox getShowEventsCb() {
733         return _show_events;
734     }
735
736     List<String> getSingleClickToNames() {
737         return _click_to_names;
738     }
739
740     Map<String, Color> getSpeciesColors() {
741         return _species_colors;
742     }
743
744     public JCheckBox getWriteConfidenceCb() {
745         return _write_confidence;
746     }
747
748     private void init() {
749         _draw_phylogram = new ArrayList<Boolean>();
750         setSpeciesColors( new HashMap<String, Color>() );
751         setAnnotationColors( new HashMap<String, Color>() );
752     }
753
754     boolean isAntialiasScreenText() {
755         return true;
756     }
757
758     boolean isColorAccordingToAnnotation() {
759         return ( ( _color_according_to_annotation != null ) && _color_according_to_annotation.isSelected() );
760     }
761
762     boolean isColorAccordingToTaxonomy() {
763         return ( ( _color_acc_species != null ) && _color_acc_species.isSelected() );
764     }
765
766     boolean isColorBranches() {
767         return ( ( ( getColorBranchesCb() != null ) && getColorBranchesCb().isSelected() ) || ( ( getColorBranchesCb() == null ) && _color_branches ) );
768     }
769
770     boolean isDrawPhylogram() {
771         return isDrawPhylogram( getMainPanel().getCurrentTabIndex() );
772     }
773
774     private boolean isDrawPhylogram( final int index ) {
775         return getIsDrawPhylogramList().get( index );
776     }
777
778     boolean isDynamicallyHideData() {
779         return ( ( getDynamicallyHideData() != null ) && getDynamicallyHideData().isSelected() );
780     }
781
782     boolean isEvents() {
783         return ( ( getShowEventsCb() != null ) && getShowEventsCb().isSelected() );
784     }
785
786     boolean isNodeDescPopup() {
787         return ( ( getNodeDescPopupCb() != null ) && getNodeDescPopupCb().isSelected() );
788     }
789
790     boolean isShowAnnotation() {
791         return ( ( _show_annotation != null ) && _show_annotation.isSelected() );
792     }
793
794     boolean isShowBinaryCharacterCounts() {
795         return ( ( _show_binary_character_counts != null ) && _show_binary_character_counts.isSelected() );
796     }
797
798     boolean isShowBinaryCharacters() {
799         return ( ( _show_binary_characters != null ) && _show_binary_characters.isSelected() );
800     }
801
802     boolean isShowBootstrapValues() {
803         return ( ( getWriteConfidenceCb() != null ) && getWriteConfidenceCb().isSelected() );
804     }
805
806     boolean isShowDomainArchitectures() {
807         return ( ( _show_domain_architectures != null ) && _show_domain_architectures.isSelected() );
808     }
809
810     boolean isShowGeneNames() {
811         return ( ( _show_gene_names != null ) && _show_gene_names.isSelected() );
812     }
813
814     public boolean isShowVectorData() {
815         return ( ( _show_vector_data_cb != null ) && _show_vector_data_cb.isSelected() );
816     }
817
818     boolean isShowGeneSymbols() {
819         return ( ( _show_gene_symbols != null ) && _show_gene_symbols.isSelected() );
820     }
821
822     boolean isShowInternalData() {
823         return ( ( _display_internal_data == null ) || _display_internal_data.isSelected() );
824     }
825
826     boolean isShowNodeNames() {
827         return ( ( _show_node_names != null ) && _show_node_names.isSelected() );
828     }
829
830     boolean isShowProperty() {
831         return ( ( _show_annotation != null ) && _show_annotation.isSelected() );
832     }
833
834     boolean isShowSequenceAcc() {
835         return ( ( _show_sequence_acc != null ) && _show_sequence_acc.isSelected() );
836     }
837
838     boolean isShowSequenceRelationConfidence() {
839         return ( ( _seq_relation_confidence_switch != null ) && ( _seq_relation_confidence_switch.isSelected() ) );
840     }
841
842     boolean isShowSequenceRelations() {
843         return ( ( _show_sequence_relations != null ) && ( _show_sequence_relations.getSelectedIndex() > 0 ) );
844     }
845
846     boolean isShowTaxonomyCode() {
847         return ( ( _show_taxo_code != null ) && _show_taxo_code.isSelected() );
848     }
849
850     public boolean isShowTaxonomyImages() {
851         return ( ( _show_taxo_images_cb != null ) && _show_taxo_images_cb.isSelected() );
852     }
853
854     boolean isShowTaxonomyCommonNames() {
855         return ( ( _show_taxo_common_names != null ) && _show_taxo_common_names.isSelected() );
856     }
857
858     boolean isShowTaxonomyScientificNames() {
859         return ( ( _show_taxo_scientific_names != null ) && _show_taxo_scientific_names.isSelected() );
860     }
861
862     boolean isWidthBranches() {
863         return ( ( _width_branches != null ) && _width_branches.isSelected() );
864     }
865
866     void phylogenyAdded( final Configuration configuration ) {
867         getIsDrawPhylogramList().add( configuration.isDrawAsPhylogram() );
868     }
869
870     void phylogenyRemoved( final int index ) {
871         getIsDrawPhylogramList().remove( index );
872     }
873
874     void search() {
875         final MainPanel main_panel = getMainPanel();
876         final Phylogeny tree = main_panel.getCurrentPhylogeny();
877         if ( ( tree == null ) || tree.isEmpty() ) {
878             return;
879         }
880         String query = getSearchTextField().getText();
881         if ( query != null ) {
882             query = query.trim();
883         }
884         else {
885             getSearchFoundCountsLabel().setVisible( false );
886             getSearchResetButton().setEnabled( false );
887             getSearchResetButton().setVisible( false );
888             searchReset();
889         }
890         if ( !ForesterUtil.isEmpty( query ) ) {
891             search( main_panel, tree, query );
892         }
893         else {
894             getSearchFoundCountsLabel().setVisible( false );
895             getSearchResetButton().setEnabled( false );
896             getSearchResetButton().setVisible( false );
897             searchReset();
898         }
899     }
900
901     private void search( final MainPanel main_panel, final Phylogeny tree, final String query_str ) {
902         getSearchFoundCountsLabel().setVisible( true );
903         getSearchResetButton().setEnabled( true );
904         getSearchResetButton().setVisible( true );
905         String[] queries = null;
906         List<PhylogenyNode> nodes = null;
907         if ( query_str.indexOf( ',' ) >= 0 ) {
908             queries = query_str.split( ",+" );
909         }
910         else {
911             queries = new String[ 1 ];
912             queries[ 0 ] = query_str.trim();
913         }
914         if ( ( queries != null ) && ( queries.length > 0 ) ) {
915             nodes = new ArrayList<PhylogenyNode>();
916             for( String query : queries ) {
917                 if ( ForesterUtil.isEmpty( query ) ) {
918                     continue;
919                 }
920                 query = query.trim();
921                 if ( query.indexOf( '+' ) >= 0 ) {
922                     nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ), tree, getOptions()
923                             .isSearchCaseSensitive(), !getOptions().isMatchWholeTermsOnly() ) );
924                 }
925                 else {
926                     nodes.addAll( PhylogenyMethods.searchData( query,
927                                                                tree,
928                                                                getOptions().isSearchCaseSensitive(),
929                                                                !getOptions().isMatchWholeTermsOnly() ) );
930                 }
931             }
932             if ( getOptions().isInverseSearchResult() ) {
933                 final List<PhylogenyNode> all = PhylogenyMethods.obtainAllNodesAsList( tree );
934                 all.removeAll( nodes );
935                 nodes = all;
936             }
937         }
938         if ( ( nodes != null ) && ( nodes.size() > 0 ) ) {
939             main_panel.getCurrentTreePanel().setFoundNodes( new HashSet<Integer>() );
940             for( final PhylogenyNode node : nodes ) {
941                 main_panel.getCurrentTreePanel().getFoundNodes().add( node.getId() );
942             }
943             setSearchFoundCountsOnLabel( nodes.size() );
944         }
945         else {
946             setSearchFoundCountsOnLabel( 0 );
947             searchReset();
948         }
949     }
950
951     private void searchReset() {
952         if ( getMainPanel().getCurrentTreePanel() != null ) {
953             getMainPanel().getCurrentTreePanel().setFoundNodes( null );
954         }
955     }
956
957     void setActionWhenNodeClicked( final NodeClickAction action ) {
958         _action_when_node_clicked = action;
959     }
960
961     void setAnnotationColors( final Map<String, Color> annotation_colors ) {
962         _annotation_colors = annotation_colors;
963     }
964
965     void setCheckbox( final int which, final boolean state ) {
966         switch ( which ) {
967             case Configuration.display_as_phylogram:
968                 if ( getDisplayAsPhylogramCb() != null ) {
969                     getDisplayAsPhylogramCb().setSelected( state );
970                 }
971                 break;
972             case Configuration.display_internal_data:
973                 if ( _display_internal_data != null ) {
974                     _display_internal_data.setSelected( state );
975                 }
976                 break;
977             case Configuration.color_according_to_species:
978                 if ( _color_acc_species != null ) {
979                     _color_acc_species.setSelected( state );
980                 }
981                 break;
982             case Configuration.color_according_to_annotation:
983                 if ( _color_according_to_annotation != null ) {
984                     _color_according_to_annotation.setSelected( state );
985                 }
986                 break;
987             case Configuration.show_node_names:
988                 if ( _show_node_names != null ) {
989                     _show_node_names.setSelected( state );
990                 }
991                 break;
992             case Configuration.show_tax_code:
993                 if ( _show_taxo_code != null ) {
994                     _show_taxo_code.setSelected( state );
995                 }
996                 break;
997             case Configuration.show_taxonomy_scientific_names:
998                 if ( _show_taxo_scientific_names != null ) {
999                     _show_taxo_scientific_names.setSelected( state );
1000                 }
1001                 break;
1002             case Configuration.show_taxonomy_common_names:
1003                 if ( _show_taxo_common_names != null ) {
1004                     _show_taxo_common_names.setSelected( state );
1005                 }
1006                 break;
1007             case Configuration.show_taxonomy_images:
1008                 if ( _show_taxo_images_cb != null ) {
1009                     _show_taxo_images_cb.setSelected( state );
1010                 }
1011                 break;
1012             case Configuration.show_annotation:
1013                 if ( _show_annotation != null ) {
1014                     _show_annotation.setSelected( state );
1015                 }
1016                 break;
1017             case Configuration.show_binary_characters:
1018                 if ( _show_binary_characters != null ) {
1019                     _show_binary_characters.setSelected( state );
1020                 }
1021                 break;
1022             case Configuration.show_binary_character_counts:
1023                 if ( _show_binary_character_counts != null ) {
1024                     _show_binary_character_counts.setSelected( state );
1025                 }
1026                 break;
1027             case Configuration.write_confidence_values:
1028                 if ( getWriteConfidenceCb() != null ) {
1029                     getWriteConfidenceCb().setSelected( state );
1030                 }
1031                 break;
1032             case Configuration.write_events:
1033                 if ( getShowEventsCb() != null ) {
1034                     getShowEventsCb().setSelected( state );
1035                 }
1036                 break;
1037             case Configuration.color_branches:
1038                 if ( getColorBranchesCb() != null ) {
1039                     getColorBranchesCb().setSelected( state );
1040                 }
1041                 break;
1042             case Configuration.width_branches:
1043                 if ( _width_branches != null ) {
1044                     _width_branches.setSelected( state );
1045                 }
1046                 break;
1047             case Configuration.show_domain_architectures:
1048                 if ( _show_domain_architectures != null ) {
1049                     _show_domain_architectures.setSelected( state );
1050                 }
1051                 break;
1052             case Configuration.show_gene_names:
1053                 if ( _show_gene_names != null ) {
1054                     _show_gene_names.setSelected( state );
1055                 }
1056                 break;
1057             case Configuration.show_gene_symbols:
1058                 if ( _show_gene_symbols != null ) {
1059                     _show_gene_symbols.setSelected( state );
1060                 }
1061                 break;
1062             case Configuration.show_vector_data:
1063                 if ( _show_vector_data_cb != null ) {
1064                     _show_vector_data_cb.setSelected( state );
1065                 }
1066                 break;
1067             case Configuration.show_sequence_acc:
1068                 if ( _show_sequence_acc != null ) {
1069                     _show_sequence_acc.setSelected( state );
1070                 }
1071                 break;
1072             case Configuration.dynamically_hide_data:
1073                 if ( getDynamicallyHideData() != null ) {
1074                     getDynamicallyHideData().setSelected( state );
1075                 }
1076                 break;
1077             case Configuration.node_data_popup:
1078                 if ( getNodeDescPopupCb() != null ) {
1079                     getNodeDescPopupCb().setSelected( state );
1080                 }
1081                 break;
1082             /* GUILHEM_BEG */
1083             case Configuration.show_relation_confidence:
1084                 if ( _seq_relation_confidence_switch != null ) {
1085                     _seq_relation_confidence_switch.setSelected( state );
1086                 }
1087                 break;
1088             /* GUILHEM_END */
1089             default:
1090                 throw new AssertionError( "unknown checkbox: " + which );
1091         }
1092     }
1093
1094     /**
1095      * Set this checkbox state. Not all checkboxes have been instantiated
1096      * depending on the config.
1097      */
1098     void setCheckbox( final JCheckBox cb, final boolean state ) {
1099         if ( cb != null ) {
1100             cb.setSelected( state );
1101         }
1102     }
1103
1104     void setClickToAction( final int action ) {
1105         // Set click-to action
1106         if ( action == _show_data_item ) {
1107             setActionWhenNodeClicked( NodeClickAction.SHOW_DATA );
1108         }
1109         else if ( action == _collapse_cb_item ) {
1110             setActionWhenNodeClicked( NodeClickAction.COLLAPSE );
1111         }
1112         else if ( action == _reroot_cb_item ) {
1113             setActionWhenNodeClicked( NodeClickAction.REROOT );
1114         }
1115         else if ( action == _subtree_cb_item ) {
1116             setActionWhenNodeClicked( NodeClickAction.SUBTREE );
1117         }
1118         else if ( action == _swap_cb_item ) {
1119             setActionWhenNodeClicked( NodeClickAction.SWAP );
1120         }
1121         else if ( action == _color_subtree_cb_item ) {
1122             setActionWhenNodeClicked( NodeClickAction.COLOR_SUBTREE );
1123         }
1124         else if ( action == _open_seq_web_item ) {
1125             setActionWhenNodeClicked( NodeClickAction.OPEN_SEQ_WEB );
1126         }
1127         else if ( action == _blast_item ) {
1128             if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
1129                 setActionWhenNodeClicked( NodeClickAction.BLAST );
1130             }
1131         }
1132         else if ( action == _open_tax_web_item ) {
1133             setActionWhenNodeClicked( NodeClickAction.OPEN_TAX_WEB );
1134         }
1135         else if ( action == _cut_subtree_item ) {
1136             setActionWhenNodeClicked( NodeClickAction.CUT_SUBTREE );
1137         }
1138         else if ( action == _copy_subtree_item ) {
1139             setActionWhenNodeClicked( NodeClickAction.COPY_SUBTREE );
1140         }
1141         else if ( action == _delete_node_or_subtree_item ) {
1142             setActionWhenNodeClicked( NodeClickAction.DELETE_NODE_OR_SUBTREE );
1143         }
1144         else if ( action == _paste_subtree_item ) {
1145             setActionWhenNodeClicked( NodeClickAction.PASTE_SUBTREE );
1146         }
1147         else if ( action == _add_new_node_item ) {
1148             setActionWhenNodeClicked( NodeClickAction.ADD_NEW_NODE );
1149         }
1150         else if ( action == _edit_node_data_item ) {
1151             setActionWhenNodeClicked( NodeClickAction.EDIT_NODE_DATA );
1152         }
1153         else {
1154             throw new RuntimeException( "unknown action: " + action );
1155         }
1156         // make sure drop down is displaying the correct action
1157         // in case this was called from outside the class
1158         _click_to_combobox.setSelectedIndex( action );
1159     }
1160
1161     void setColorBranches( final boolean color_branches ) {
1162         _color_branches = color_branches;
1163     }
1164
1165     void setDrawPhylogram( final boolean b ) {
1166         getDisplayAsPhylogramCb().setSelected( b );
1167         setDrawPhylogram( getMainPanel().getCurrentTabIndex(), b );
1168     }
1169
1170     private void setDrawPhylogram( final int index, final boolean b ) {
1171         getIsDrawPhylogramList().set( index, b );
1172     }
1173
1174     void setDrawPhylogramEnabled( final boolean b ) {
1175         getDisplayAsPhylogramCb().setEnabled( b );
1176     }
1177
1178     void setDynamicHidingIsOn( final boolean is_on ) {
1179         //  if ( !_configuration.isUseNativeUI() ) {
1180         if ( is_on ) {
1181             getDynamicallyHideData().setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
1182         }
1183         else {
1184             if ( !_configuration.isUseNativeUI() ) {
1185                 getDynamicallyHideData().setForeground( getConfiguration().getGuiButtonTextColor() );
1186             }
1187             else {
1188                 getDynamicallyHideData().setForeground( Color.BLACK );
1189             }
1190         }
1191         // }
1192     }
1193
1194     private void setSearchFoundCountsOnLabel( final int counts ) {
1195         getSearchFoundCountsLabel().setText( "Found: " + counts );
1196     }
1197
1198     public void setSequenceRelationQueries( final Collection<Sequence> sequenceRelationQueries ) {
1199         final JComboBox box = getSequenceRelationBox();
1200         while ( box.getItemCount() > 1 ) {
1201             box.removeItemAt( 1 );
1202         }
1203         final HashMap<String, Sequence> sequencesByName = new HashMap<String, Sequence>();
1204         final SequenceRelation.SEQUENCE_RELATION_TYPE relationType = ( SequenceRelation.SEQUENCE_RELATION_TYPE ) _sequence_relation_type_box
1205                 .getSelectedItem();
1206         if ( relationType == null ) {
1207             return;
1208         }
1209         final ArrayList<String> sequenceNamesToAdd = new ArrayList<String>();
1210         for( final Sequence seq : sequenceRelationQueries ) {
1211             if ( seq.hasSequenceRelations() ) {
1212                 boolean fFoundForCurrentType = false;
1213                 for( final SequenceRelation sq : seq.getSequenceRelations() ) {
1214                     if ( sq.getType().equals( relationType ) ) {
1215                         fFoundForCurrentType = true;
1216                         break;
1217                     }
1218                 }
1219                 if ( fFoundForCurrentType ) {
1220                     sequenceNamesToAdd.add( seq.getName() );
1221                     sequencesByName.put( seq.getName(), seq );
1222                 }
1223             }
1224         }
1225         // sort sequences by name before adding them to the combo
1226         final String[] sequenceNameArray = sequenceNamesToAdd.toArray( new String[ sequenceNamesToAdd.size() ] );
1227         Arrays.sort( sequenceNameArray, String.CASE_INSENSITIVE_ORDER );
1228         for( final String seqName : sequenceNameArray ) {
1229             box.addItem( seqName );
1230         }
1231         for( final ItemListener oldItemListener : box.getItemListeners() ) {
1232             box.removeItemListener( oldItemListener );
1233         }
1234         box.addItemListener( new ItemListener() {
1235
1236             @Override
1237             public void itemStateChanged( final ItemEvent e ) {
1238                 _selected_query_seq = sequencesByName.get( e.getItem() );
1239                 _mainpanel.getCurrentTreePanel().repaint();
1240             }
1241         } );
1242     }
1243
1244     void setShowEvents( final boolean show_events ) {
1245         if ( getShowEventsCb() == null ) {
1246             _show_events = new JCheckBox( "" );
1247         }
1248         getShowEventsCb().setSelected( show_events );
1249     }
1250
1251     void setSpeciesColors( final Map<String, Color> species_colors ) {
1252         _species_colors = species_colors;
1253     }
1254
1255     private void setupClickToOptions() {
1256         final int default_option = _configuration.getDefaultDisplayClicktoOption();
1257         int selected_index = 0;
1258         int cb_index = 0;
1259         if ( _configuration.doDisplayClickToOption( Configuration.display_node_data ) ) {
1260             _show_data_item = cb_index;
1261             addClickToOption( Configuration.display_node_data, _configuration
1262                     .getClickToTitle( Configuration.display_node_data ) );
1263             if ( default_option == Configuration.display_node_data ) {
1264                 selected_index = cb_index;
1265             }
1266             cb_index++;
1267         }
1268         if ( _configuration.doDisplayClickToOption( Configuration.collapse_uncollapse ) ) {
1269             _collapse_cb_item = cb_index;
1270             addClickToOption( Configuration.collapse_uncollapse, _configuration
1271                     .getClickToTitle( Configuration.collapse_uncollapse ) );
1272             if ( default_option == Configuration.collapse_uncollapse ) {
1273                 selected_index = cb_index;
1274             }
1275             cb_index++;
1276         }
1277         if ( _configuration.doDisplayClickToOption( Configuration.reroot ) ) {
1278             _reroot_cb_item = cb_index;
1279             addClickToOption( Configuration.reroot, _configuration.getClickToTitle( Configuration.reroot ) );
1280             if ( default_option == Configuration.reroot ) {
1281                 selected_index = cb_index;
1282             }
1283             cb_index++;
1284         }
1285         if ( _configuration.doDisplayClickToOption( Configuration.subtree ) ) {
1286             _subtree_cb_item = cb_index;
1287             addClickToOption( Configuration.subtree, _configuration.getClickToTitle( Configuration.subtree ) );
1288             if ( default_option == Configuration.subtree ) {
1289                 selected_index = cb_index;
1290             }
1291             cb_index++;
1292         }
1293         if ( _configuration.doDisplayClickToOption( Configuration.swap ) ) {
1294             _swap_cb_item = cb_index;
1295             addClickToOption( Configuration.swap, _configuration.getClickToTitle( Configuration.swap ) );
1296             if ( default_option == Configuration.swap ) {
1297                 selected_index = cb_index;
1298             }
1299             cb_index++;
1300         }
1301         if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) {
1302             _color_subtree_cb_item = cb_index;
1303             addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) );
1304             if ( default_option == Configuration.color_subtree ) {
1305                 selected_index = cb_index;
1306             }
1307             cb_index++;
1308         }
1309         if ( _configuration.doDisplayClickToOption( Configuration.open_seq_web ) ) {
1310             _open_seq_web_item = cb_index;
1311             addClickToOption( Configuration.open_seq_web, _configuration.getClickToTitle( Configuration.open_seq_web ) );
1312             if ( default_option == Configuration.open_seq_web ) {
1313                 selected_index = cb_index;
1314             }
1315             cb_index++;
1316         }
1317         if ( _configuration.doDisplayClickToOption( Configuration.open_tax_web ) ) {
1318             _open_tax_web_item = cb_index;
1319             addClickToOption( Configuration.open_tax_web, _configuration.getClickToTitle( Configuration.open_tax_web ) );
1320             if ( default_option == Configuration.open_tax_web ) {
1321                 selected_index = cb_index;
1322             }
1323             cb_index++;
1324         }
1325         if ( getOptions().isEditable() ) {
1326             if ( _configuration.doDisplayClickToOption( Configuration.cut_subtree ) ) {
1327                 _cut_subtree_item = cb_index;
1328                 addClickToOption( Configuration.cut_subtree, _configuration.getClickToTitle( Configuration.cut_subtree ) );
1329                 if ( default_option == Configuration.cut_subtree ) {
1330                     selected_index = cb_index;
1331                 }
1332                 cb_index++;
1333             }
1334             if ( _configuration.doDisplayClickToOption( Configuration.copy_subtree ) ) {
1335                 _copy_subtree_item = cb_index;
1336                 addClickToOption( Configuration.copy_subtree, _configuration
1337                         .getClickToTitle( Configuration.copy_subtree ) );
1338                 if ( default_option == Configuration.copy_subtree ) {
1339                     selected_index = cb_index;
1340                 }
1341                 cb_index++;
1342             }
1343             if ( _configuration.doDisplayClickToOption( Configuration.paste_subtree ) ) {
1344                 _paste_subtree_item = cb_index;
1345                 addClickToOption( Configuration.paste_subtree, _configuration
1346                         .getClickToTitle( Configuration.paste_subtree ) );
1347                 if ( default_option == Configuration.paste_subtree ) {
1348                     selected_index = cb_index;
1349                 }
1350                 cb_index++;
1351             }
1352             if ( _configuration.doDisplayClickToOption( Configuration.delete_subtree_or_node ) ) {
1353                 _delete_node_or_subtree_item = cb_index;
1354                 addClickToOption( Configuration.delete_subtree_or_node, _configuration
1355                         .getClickToTitle( Configuration.delete_subtree_or_node ) );
1356                 if ( default_option == Configuration.delete_subtree_or_node ) {
1357                     selected_index = cb_index;
1358                 }
1359                 cb_index++;
1360             }
1361             if ( _configuration.doDisplayClickToOption( Configuration.add_new_node ) ) {
1362                 _add_new_node_item = cb_index;
1363                 addClickToOption( Configuration.add_new_node, _configuration
1364                         .getClickToTitle( Configuration.add_new_node ) );
1365                 if ( default_option == Configuration.add_new_node ) {
1366                     selected_index = cb_index;
1367                 }
1368                 cb_index++;
1369             }
1370             if ( _configuration.doDisplayClickToOption( Configuration.edit_node_data ) ) {
1371                 _edit_node_data_item = cb_index;
1372                 addClickToOption( Configuration.edit_node_data, _configuration
1373                         .getClickToTitle( Configuration.edit_node_data ) );
1374                 if ( default_option == Configuration.edit_node_data ) {
1375                     selected_index = cb_index;
1376                 }
1377                 cb_index++;
1378             }
1379             if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
1380                 if ( _configuration.doDisplayClickToOption( Configuration.blast ) ) {
1381                     _blast_item = cb_index;
1382                     addClickToOption( Configuration.blast, _configuration.getClickToTitle( Configuration.blast ) );
1383                     if ( default_option == Configuration.blast ) {
1384                         selected_index = cb_index;
1385                     }
1386                     cb_index++;
1387                 }
1388             }
1389         }
1390         // Set default selection and its action
1391         _click_to_combobox.setSelectedIndex( selected_index );
1392         setClickToAction( selected_index );
1393     }
1394
1395     /* GUILHEM_END */
1396     /*
1397      * Set up the controls from the config settings. 11/26/05
1398      */
1399     void setupControls() {
1400         // The tree display options:
1401         setupDisplayCheckboxes();
1402         /* GUILHEM_BEG */
1403         // The sequence relation query selection combo-box
1404         if ( _configuration.displaySequenceRelations() ) {
1405             addSequenceRelationBlock();
1406         }
1407         /* GUILHEM_END */
1408         // Click-to options
1409         startClickToOptions();
1410         setupClickToOptions();
1411         endClickToOptions();
1412         // Zoom and quick edit buttons
1413         addButtons();
1414         setupSearchTools();
1415     }
1416
1417     void setUpControlsForDomainStrucures() {
1418         _domain_display_label = new JLabel( "Domain Display:" );
1419         add( customizeLabel( _domain_display_label, getConfiguration() ) );
1420         add( _domain_display_label );
1421         _zoom_in_domain_structure = new JButton( "d+" );
1422         _zoom_out_domain_structure = new JButton( "d-" );
1423         _decr_domain_structure_evalue_thr = new JButton( "-" );
1424         _incr_domain_structure_evalue_thr = new JButton( "+" );
1425         _zoom_in_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1426         _zoom_out_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1427         _decr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1428         _incr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1429         _incr_domain_structure_evalue_thr.setToolTipText( "Increase the E-value threshold by a factor of 10" );
1430         _decr_domain_structure_evalue_thr.setToolTipText( "Decrease the E-value threshold by a factor of 10" );
1431         _domain_structure_evalue_thr_tf = new JTextField( 3 );
1432         _domain_structure_evalue_thr_tf.setEditable( false );
1433         if ( !getConfiguration().isUseNativeUI() ) {
1434             _domain_structure_evalue_thr_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1435             _domain_structure_evalue_thr_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1436             _domain_structure_evalue_thr_tf.setBorder( null );
1437         }
1438         final JPanel d1_panel = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1439         final JPanel d2_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
1440         if ( !_configuration.isUseNativeUI() ) {
1441             d1_panel.setBackground( getBackground() );
1442             d2_panel.setBackground( getBackground() );
1443         }
1444         add( d1_panel );
1445         add( d2_panel );
1446         addJButton( _zoom_out_domain_structure, d1_panel );
1447         addJButton( _zoom_in_domain_structure, d1_panel );
1448         addJButton( _decr_domain_structure_evalue_thr, d2_panel );
1449         addJTextField( _domain_structure_evalue_thr_tf, d2_panel );
1450         addJButton( _incr_domain_structure_evalue_thr, d2_panel );
1451     }
1452
1453     private void setupDisplayCheckboxes() {
1454         if ( _configuration.doDisplayOption( Configuration.display_as_phylogram ) ) {
1455             addCheckbox( Configuration.display_as_phylogram, _configuration
1456                     .getDisplayTitle( Configuration.display_as_phylogram ) );
1457             setCheckbox( Configuration.display_as_phylogram, _configuration
1458                     .doCheckOption( Configuration.display_as_phylogram ) );
1459         }
1460         if ( _configuration.doDisplayOption( Configuration.dynamically_hide_data ) ) {
1461             addCheckbox( Configuration.dynamically_hide_data, _configuration
1462                     .getDisplayTitle( Configuration.dynamically_hide_data ) );
1463             setCheckbox( Configuration.dynamically_hide_data, _configuration
1464                     .doCheckOption( Configuration.dynamically_hide_data ) );
1465         }
1466         if ( _configuration.doDisplayOption( Configuration.node_data_popup ) ) {
1467             addCheckbox( Configuration.node_data_popup, _configuration.getDisplayTitle( Configuration.node_data_popup ) );
1468             setCheckbox( Configuration.node_data_popup, _configuration.doCheckOption( Configuration.node_data_popup ) );
1469         }
1470         if ( _configuration.doDisplayOption( Configuration.display_internal_data ) ) {
1471             addCheckbox( Configuration.display_internal_data, _configuration
1472                     .getDisplayTitle( Configuration.display_internal_data ) );
1473             setCheckbox( Configuration.display_internal_data, _configuration
1474                     .doCheckOption( Configuration.display_internal_data ) );
1475         }
1476         if ( _configuration.doDisplayOption( Configuration.color_according_to_species ) ) {
1477             addCheckbox( Configuration.color_according_to_species, _configuration
1478                     .getDisplayTitle( Configuration.color_according_to_species ) );
1479             setCheckbox( Configuration.color_according_to_species, _configuration
1480                     .doCheckOption( Configuration.color_according_to_species ) );
1481         }
1482         if ( _configuration.doDisplayOption( Configuration.color_according_to_annotation ) ) {
1483             addCheckbox( Configuration.color_according_to_annotation, _configuration
1484                     .getDisplayTitle( Configuration.color_according_to_annotation ) );
1485             setCheckbox( Configuration.color_according_to_annotation, _configuration
1486                     .doCheckOption( Configuration.color_according_to_annotation ) );
1487         }
1488         if ( _configuration.doDisplayOption( Configuration.color_branches ) ) {
1489             addCheckbox( Configuration.color_branches, _configuration.getDisplayTitle( Configuration.color_branches ) );
1490             setCheckbox( Configuration.color_branches, _configuration.doCheckOption( Configuration.color_branches ) );
1491         }
1492         if ( _configuration.doDisplayOption( Configuration.width_branches ) ) {
1493             addCheckbox( Configuration.width_branches, _configuration.getDisplayTitle( Configuration.width_branches ) );
1494             setCheckbox( Configuration.width_branches, _configuration.doCheckOption( Configuration.width_branches ) );
1495         }
1496         final JLabel label = new JLabel( "Display Data:" );
1497         label.setFont( ControlPanel.jcb_bold_font );
1498         if ( !getConfiguration().isUseNativeUI() ) {
1499             label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1500         }
1501         add( label );
1502         if ( _configuration.doDisplayOption( Configuration.show_node_names ) ) {
1503             addCheckbox( Configuration.show_node_names, _configuration.getDisplayTitle( Configuration.show_node_names ) );
1504             setCheckbox( Configuration.show_node_names, _configuration.doCheckOption( Configuration.show_node_names ) );
1505         }
1506         if ( _configuration.doDisplayOption( Configuration.show_tax_code ) ) {
1507             addCheckbox( Configuration.show_tax_code, _configuration.getDisplayTitle( Configuration.show_tax_code ) );
1508             setCheckbox( Configuration.show_tax_code, _configuration.doCheckOption( Configuration.show_tax_code ) );
1509         }
1510         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_scientific_names ) ) {
1511             addCheckbox( Configuration.show_taxonomy_scientific_names, _configuration
1512                     .getDisplayTitle( Configuration.show_taxonomy_scientific_names ) );
1513             setCheckbox( Configuration.show_taxonomy_scientific_names, _configuration
1514                     .doCheckOption( Configuration.show_taxonomy_scientific_names ) );
1515         }
1516         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_common_names ) ) {
1517             addCheckbox( Configuration.show_taxonomy_common_names, _configuration
1518                     .getDisplayTitle( Configuration.show_taxonomy_common_names ) );
1519             setCheckbox( Configuration.show_taxonomy_common_names, _configuration
1520                     .doCheckOption( Configuration.show_taxonomy_common_names ) );
1521         }
1522         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_images ) ) {
1523             addCheckbox( Configuration.show_taxonomy_images, _configuration
1524                     .getDisplayTitle( Configuration.show_taxonomy_images ) );
1525             setCheckbox( Configuration.show_taxonomy_images, _configuration
1526                     .doCheckOption( Configuration.show_taxonomy_images ) );
1527         }
1528         if ( _configuration.doDisplayOption( Configuration.show_gene_symbols ) ) {
1529             addCheckbox( Configuration.show_gene_symbols, _configuration
1530                     .getDisplayTitle( Configuration.show_gene_symbols ) );
1531             setCheckbox( Configuration.show_gene_symbols, _configuration
1532                     .doCheckOption( Configuration.show_gene_symbols ) );
1533         }
1534         if ( _configuration.doDisplayOption( Configuration.show_gene_names ) ) {
1535             addCheckbox( Configuration.show_gene_names, _configuration.getDisplayTitle( Configuration.show_gene_names ) );
1536             setCheckbox( Configuration.show_gene_names, _configuration.doCheckOption( Configuration.show_gene_names ) );
1537         }
1538         if ( _configuration.doDisplayOption( Configuration.show_sequence_acc ) ) {
1539             addCheckbox( Configuration.show_sequence_acc, _configuration
1540                     .getDisplayTitle( Configuration.show_sequence_acc ) );
1541             setCheckbox( Configuration.show_sequence_acc, _configuration
1542                     .doCheckOption( Configuration.show_sequence_acc ) );
1543         }
1544         if ( _configuration.doDisplayOption( Configuration.show_annotation ) ) {
1545             addCheckbox( Configuration.show_annotation, _configuration.getDisplayTitle( Configuration.show_annotation ) );
1546             setCheckbox( Configuration.show_annotation, _configuration.doCheckOption( Configuration.show_annotation ) );
1547         }
1548         if ( _configuration.doDisplayOption( Configuration.show_binary_characters ) ) {
1549             addCheckbox( Configuration.show_binary_characters, _configuration
1550                     .getDisplayTitle( Configuration.show_binary_characters ) );
1551             setCheckbox( Configuration.show_binary_characters, _configuration
1552                     .doCheckOption( Configuration.show_binary_characters ) );
1553         }
1554         if ( _configuration.doDisplayOption( Configuration.show_binary_character_counts ) ) {
1555             addCheckbox( Configuration.show_binary_character_counts, _configuration
1556                     .getDisplayTitle( Configuration.show_binary_character_counts ) );
1557             setCheckbox( Configuration.show_binary_character_counts, _configuration
1558                     .doCheckOption( Configuration.show_binary_character_counts ) );
1559         }
1560         if ( _configuration.doDisplayOption( Configuration.show_domain_architectures ) ) {
1561             addCheckbox( Configuration.show_domain_architectures, _configuration
1562                     .getDisplayTitle( Configuration.show_domain_architectures ) );
1563             setCheckbox( Configuration.show_domain_architectures, _configuration
1564                     .doCheckOption( Configuration.show_domain_architectures ) );
1565         }
1566         if ( _configuration.doDisplayOption( Configuration.write_confidence_values ) ) {
1567             addCheckbox( Configuration.write_confidence_values, _configuration
1568                     .getDisplayTitle( Configuration.write_confidence_values ) );
1569             setCheckbox( Configuration.write_confidence_values, _configuration
1570                     .doCheckOption( Configuration.write_confidence_values ) );
1571         }
1572         if ( _configuration.doDisplayOption( Configuration.write_events ) ) {
1573             addCheckbox( Configuration.write_events, _configuration.getDisplayTitle( Configuration.write_events ) );
1574             setCheckbox( Configuration.write_events, _configuration.doCheckOption( Configuration.write_events ) );
1575         }
1576         if ( _configuration.doDisplayOption( Configuration.show_vector_data ) ) {
1577             addCheckbox( Configuration.show_vector_data, _configuration
1578                     .getDisplayTitle( Configuration.show_vector_data ) );
1579             setCheckbox( Configuration.show_vector_data, _configuration.doCheckOption( Configuration.show_vector_data ) );
1580         }
1581     }
1582
1583     void setupSearchTools() {
1584         final String tip = "Enter text to search for. Use ',' for multiple searches (logical OR) and '+' for logical AND.";
1585         final JLabel search_label = new JLabel( "Search:" );
1586         search_label.setFont( ControlPanel.jcb_bold_font );
1587         if ( !getConfiguration().isUseNativeUI() ) {
1588             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1589         }
1590         add( search_label );
1591         search_label.setToolTipText( tip );
1592         _search_found_label = new JLabel();
1593         getSearchFoundCountsLabel().setVisible( false );
1594         _search_found_label.setFont( ControlPanel.jcb_bold_font );
1595         if ( !getConfiguration().isUseNativeUI() ) {
1596             _search_found_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1597         }
1598         _search_tf = new JTextField( 3 );
1599         _search_tf.setToolTipText( tip );
1600         _search_tf.setEditable( true );
1601         if ( !getConfiguration().isUseNativeUI() ) {
1602             _search_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1603             _search_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1604             _search_tf.setBorder( null );
1605         }
1606         _search_reset_button = new JButton();
1607         getSearchResetButton().setText( "Reset" );
1608         getSearchResetButton().setEnabled( false );
1609         getSearchResetButton().setVisible( false );
1610         final JPanel s_panel_1 = new JPanel( new BorderLayout() );
1611         final JPanel s_panel_2 = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1612         s_panel_1.setBackground( getBackground() );
1613         add( s_panel_1 );
1614         s_panel_2.setBackground( getBackground() );
1615         add( s_panel_2 );
1616         final KeyAdapter key_adapter = new KeyAdapter() {
1617
1618             @Override
1619             public void keyReleased( final KeyEvent key_event ) {
1620                 search();
1621                 displayedPhylogenyMightHaveChanged( true );
1622             }
1623         };
1624         final ActionListener action_listener = new ActionListener() {
1625
1626             @Override
1627             public void actionPerformed( final ActionEvent e ) {
1628                 searchReset();
1629                 setSearchFoundCountsOnLabel( 0 );
1630                 getSearchFoundCountsLabel().setVisible( false );
1631                 getSearchTextField().setText( "" );
1632                 getSearchResetButton().setEnabled( false );
1633                 getSearchResetButton().setVisible( false );
1634                 displayedPhylogenyMightHaveChanged( true );
1635             }
1636         };
1637         _search_reset_button.addActionListener( action_listener );
1638         _search_tf.addKeyListener( key_adapter );
1639         addJTextField( _search_tf, s_panel_1 );
1640         s_panel_2.add( _search_found_label );
1641         addJButton( _search_reset_button, s_panel_2 );
1642     }
1643
1644     private void setVisibilityOfDomainStrucureControls() {
1645         if ( _zoom_in_domain_structure != null ) {
1646             if ( isShowDomainArchitectures() ) {
1647                 _domain_display_label.setVisible( true );
1648                 _zoom_in_domain_structure.setVisible( true );
1649                 _zoom_out_domain_structure.setVisible( true );
1650                 _decr_domain_structure_evalue_thr.setVisible( true );
1651                 _incr_domain_structure_evalue_thr.setVisible( true );
1652                 _domain_structure_evalue_thr_tf.setVisible( true );
1653             }
1654             else {
1655                 _domain_display_label.setVisible( false );
1656                 _zoom_in_domain_structure.setVisible( false );
1657                 _zoom_out_domain_structure.setVisible( false );
1658                 _decr_domain_structure_evalue_thr.setVisible( false );
1659                 _incr_domain_structure_evalue_thr.setVisible( false );
1660                 _domain_structure_evalue_thr_tf.setVisible( false );
1661             }
1662         }
1663     }
1664
1665     /**
1666      * Fit entire tree into window.
1667      */
1668     void showWhole() {
1669         if ( _mainpanel.getCurrentScrollPane() == null ) {
1670             return;
1671         }
1672         displayedPhylogenyMightHaveChanged( false );
1673         _mainpanel.getCurrentTreePanel().updateOvSettings();
1674         _mainpanel.getCurrentTreePanel().validate();
1675         _mainpanel.validate();
1676         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getSizeOfViewport().width,
1677                                                                    _mainpanel.getSizeOfViewport().height,
1678                                                                    true );
1679         _mainpanel.getCurrentTreePanel().resetPreferredSize();
1680         _mainpanel.adjustJScrollPane();
1681         _mainpanel.getCurrentTreePanel().repaint();
1682         _mainpanel.getCurrentTreePanel().validate();
1683         _mainpanel.validate();
1684         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getSizeOfViewport().width,
1685                                                                    _mainpanel.getSizeOfViewport().height,
1686                                                                    true );
1687         _mainpanel.getCurrentTreePanel().resetPreferredSize();
1688         _mainpanel.adjustJScrollPane();
1689         _mainpanel.getCurrentTreePanel().repaint();
1690         _mainpanel.getCurrentTreePanel().updateOvSizes();
1691     }
1692
1693     void showWholeAll() {
1694         for( final TreePanel tree_panel : _mainpanel.getTreePanels() ) {
1695             if ( tree_panel != null ) {
1696                 tree_panel.validate();
1697                 tree_panel.setParametersForPainting( _mainpanel.getSizeOfViewport().width, _mainpanel
1698                         .getSizeOfViewport().height, true );
1699                 tree_panel.resetPreferredSize();
1700                 tree_panel.repaint();
1701             }
1702         }
1703     }
1704
1705     // Create header for click-to combo box.
1706     void startClickToOptions() {
1707         final JLabel spacer = new JLabel( "" );
1708         spacer.setFont( ControlPanel.jcb_font );
1709         add( spacer );
1710         _click_to_label = new JLabel( "Click on Node to:" );
1711         add( customizeLabel( _click_to_label, getConfiguration() ) );
1712         _click_to_combobox = new JComboBox();
1713         _click_to_combobox.setFocusable( false );
1714         _click_to_combobox.setMaximumRowCount( 14 );
1715         _click_to_combobox.setFont( ControlPanel.js_font );
1716         if ( !_configuration.isUseNativeUI() ) {
1717             _click_to_combobox.setBackground( getConfiguration().getGuiBackgroundColor() );
1718         }
1719         // don't add listener until all items are set (or each one will trigger
1720         // an event)
1721         // click_to_list.addActionListener(this);
1722         add( _click_to_combobox );
1723         // Correlates option names to titles
1724         _all_click_to_names = new HashMap<Integer, String>();
1725         _click_to_names = new ArrayList<String>();
1726     }
1727
1728     void tabChanged() {
1729         if ( getMainPanel().getTabbedPane().getTabCount() > 0 ) {
1730             if ( getCurrentTreePanel().isPhyHasBranchLengths()
1731                     && ( getCurrentTreePanel().getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1732                 setDrawPhylogramEnabled( true );
1733                 setDrawPhylogram( isDrawPhylogram() );
1734             }
1735             else {
1736                 setDrawPhylogramEnabled( false );
1737                 setDrawPhylogram( false );
1738             }
1739             if ( getMainPanel().getMainFrame() == null ) {
1740                 // Must be "E" applet version.
1741                 final ArchaeopteryxE e = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1742                 e.setSelectedTypeInTypeMenu( e.getCurrentTreePanel().getPhylogenyGraphicsType() );
1743             }
1744             else {
1745                 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getMainPanel().getCurrentTreePanel()
1746                         .getPhylogenyGraphicsType() );
1747             }
1748             getMainPanel().getCurrentTreePanel().updateSubSuperTreeButton();
1749             getMainPanel().getControlPanel().search();
1750             getSequenceRelationTypeBox().removeAllItems();
1751             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
1752                     .getRelevantSequenceRelationTypes() ) {
1753                 _sequence_relation_type_box.addItem( type );
1754             }
1755             //setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
1756             // according to GUILHEM the line above can be removed.
1757         }
1758     }
1759
1760     /**
1761      * Uncollapse all nodes.
1762      */
1763     void uncollapseAll( final TreePanel tp ) {
1764         final Phylogeny t = tp.getPhylogeny();
1765         if ( ( t != null ) && !t.isEmpty() ) {
1766             t.setAllNodesToNotCollapse();
1767             t.recalculateNumberOfExternalDescendants( false );
1768             showWhole();
1769         }
1770     }
1771
1772     void updateDomainStructureEvaluethresholdDisplay() {
1773         if ( _domain_structure_evalue_thr_tf != null ) {
1774             _domain_structure_evalue_thr_tf.setText( "10^"
1775                     + getMainPanel().getCurrentTreePanel().getDomainStructureEvalueThreshold() );
1776         }
1777     }
1778
1779     void zoomInX( final float factor, final float x_correction_factor ) {
1780         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
1781         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1782         treepanel.multiplyUrtFactor( 1f );
1783         if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1784                 || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1785                 || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
1786                 || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
1787             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1788             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1789             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1790             getMainPanel().adjustJScrollPane();
1791             treepanel.resetPreferredSize();
1792             getMainPanel().getCurrentScrollPane().getViewport().validate();
1793             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1794                     - ( sb.getVisibleAmount() / 2.0 ) ) );
1795         }
1796         else {
1797             final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
1798             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1799             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1800             getMainPanel().adjustJScrollPane();
1801             treepanel.resetPreferredSize();
1802             getMainPanel().getCurrentScrollPane().getViewport().validate();
1803             sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
1804         }
1805         treepanel.resetPreferredSize();
1806         treepanel.updateOvSizes();
1807     }
1808
1809     void zoomInY( final float factor ) {
1810         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
1811         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1812         treepanel.multiplyUrtFactor( 1.1f );
1813         final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1814         treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
1815         getMainPanel().adjustJScrollPane();
1816         treepanel.resetPreferredSize();
1817         getMainPanel().getCurrentScrollPane().getViewport().validate();
1818         sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1819                 - ( sb.getVisibleAmount() / 2.0 ) ) );
1820         treepanel.resetPreferredSize();
1821         treepanel.updateOvSizes();
1822     }
1823
1824     void zoomOutX( final float factor, final float x_correction_factor ) {
1825         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1826         treepanel.multiplyUrtFactor( 1f );
1827         if ( ( treepanel.getXdistance() * factor ) > 0.0 ) {
1828             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
1829             if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1830                     || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1831                     || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
1832                     || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
1833                 getMainPanel().adjustJScrollPane();
1834                 treepanel.resetPreferredSize();
1835                 getMainPanel().getCurrentScrollPane().getViewport().validate();
1836                 final double x = ( sb.getMaximum() - sb.getMinimum() )
1837                         / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1838                 treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1839                 treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1840                 getMainPanel().adjustJScrollPane();
1841                 treepanel.resetPreferredSize();
1842                 getMainPanel().getCurrentScrollPane().getViewport().validate();
1843                 sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1844                         - ( sb.getVisibleAmount() / 2.0 ) ) );
1845             }
1846             else {
1847                 final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
1848                 treepanel.setXdistance( treepanel.getXdistance() * factor );
1849                 treepanel.setXcorrectionFactor( treepanel.getXcorrectionFactor() * x_correction_factor );
1850                 if ( x > 0 ) {
1851                     getMainPanel().adjustJScrollPane();
1852                     treepanel.resetPreferredSize();
1853                     getMainPanel().getCurrentScrollPane().getViewport().validate();
1854                     sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
1855                 }
1856             }
1857             treepanel.resetPreferredSize();
1858             treepanel.updateOvSizes();
1859         }
1860     }
1861
1862     void zoomOutY( final float factor ) {
1863         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1864         treepanel.multiplyUrtFactor( 0.9f );
1865         if ( ( treepanel.getYdistance() * factor ) > 0.0 ) {
1866             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
1867             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1868             treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
1869             getMainPanel().adjustJScrollPane();
1870             treepanel.resetPreferredSize();
1871             getMainPanel().getCurrentScrollPane().getViewport().validate();
1872             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1873                     - ( sb.getVisibleAmount() / 2.0 ) ) );
1874             treepanel.resetPreferredSize();
1875             treepanel.updateOvSizes();
1876         }
1877     }
1878
1879     static JLabel customizeLabel( final JLabel label, final Configuration configuration ) {
1880         label.setFont( ControlPanel.jcb_bold_font );
1881         if ( !configuration.isUseNativeUI() ) {
1882             label.setForeground( configuration.getGuiCheckboxTextColor() );
1883             label.setBackground( configuration.getGuiBackgroundColor() );
1884         }
1885         return label;
1886     }
1887
1888     enum NodeClickAction {
1889         SHOW_DATA,
1890         COLLAPSE,
1891         REROOT,
1892         SUBTREE,
1893         SWAP,
1894         COLOR_SUBTREE,
1895         OPEN_TAX_WEB,
1896         OPEN_SEQ_WEB,
1897         CUT_SUBTREE,
1898         COPY_SUBTREE,
1899         DELETE_NODE_OR_SUBTREE,
1900         PASTE_SUBTREE,
1901         ADD_NEW_NODE,
1902         EDIT_NODE_DATA,
1903         BLAST;
1904     }
1905 }