2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.archaeopteryx;
28 import java.awt.BasicStroke;
29 import java.awt.Color;
30 import java.awt.Cursor;
31 import java.awt.Dimension;
33 import java.awt.GradientPaint;
34 import java.awt.Graphics;
35 import java.awt.Graphics2D;
36 import java.awt.Point;
37 import java.awt.Polygon;
38 import java.awt.Rectangle;
39 import java.awt.RenderingHints;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.FocusAdapter;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.InputEvent;
45 import java.awt.event.KeyAdapter;
46 import java.awt.event.KeyEvent;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseWheelEvent;
49 import java.awt.event.MouseWheelListener;
50 import java.awt.font.FontRenderContext;
51 import java.awt.font.TextLayout;
52 import java.awt.geom.AffineTransform;
53 import java.awt.geom.Arc2D;
54 import java.awt.geom.CubicCurve2D;
55 import java.awt.geom.Ellipse2D;
56 import java.awt.geom.Line2D;
57 import java.awt.geom.QuadCurve2D;
58 import java.awt.geom.Rectangle2D;
59 import java.awt.image.BufferedImage;
60 import java.awt.print.PageFormat;
61 import java.awt.print.Printable;
62 import java.awt.print.PrinterException;
64 import java.io.IOException;
65 import java.io.UnsupportedEncodingException;
67 import java.net.URISyntaxException;
68 import java.net.URLEncoder;
69 import java.text.DecimalFormat;
70 import java.text.DecimalFormatSymbols;
71 import java.text.NumberFormat;
72 import java.util.ArrayList;
73 import java.util.Collections;
74 import java.util.HashMap;
75 import java.util.HashSet;
76 import java.util.Hashtable;
77 import java.util.List;
80 import javax.swing.BorderFactory;
81 import javax.swing.JApplet;
82 import javax.swing.JColorChooser;
83 import javax.swing.JDialog;
84 import javax.swing.JMenuItem;
85 import javax.swing.JOptionPane;
86 import javax.swing.JPanel;
87 import javax.swing.JPopupMenu;
88 import javax.swing.JTextArea;
89 import javax.swing.Popup;
90 import javax.swing.PopupFactory;
92 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
93 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
94 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
95 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
96 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
97 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
98 import org.forester.archaeopteryx.tools.Blast;
99 import org.forester.archaeopteryx.tools.ImageLoader;
100 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
101 import org.forester.phylogeny.Phylogeny;
102 import org.forester.phylogeny.PhylogenyMethods;
103 import org.forester.phylogeny.PhylogenyNode;
104 import org.forester.phylogeny.data.Annotation;
105 import org.forester.phylogeny.data.BranchColor;
106 import org.forester.phylogeny.data.Confidence;
107 import org.forester.phylogeny.data.Event;
108 import org.forester.phylogeny.data.NodeVisualization;
109 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
110 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
111 import org.forester.phylogeny.data.PhylogenyData;
112 import org.forester.phylogeny.data.PropertiesMap;
113 import org.forester.phylogeny.data.Property;
114 import org.forester.phylogeny.data.Sequence;
115 import org.forester.phylogeny.data.SequenceRelation;
116 import org.forester.phylogeny.data.Taxonomy;
117 import org.forester.phylogeny.data.Uri;
118 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
119 import org.forester.phylogeny.iterators.PreorderTreeIterator;
120 import org.forester.util.BasicDescriptiveStatistics;
121 import org.forester.util.DescriptiveStatistics;
122 import org.forester.util.ForesterConstants;
123 import org.forester.util.ForesterUtil;
125 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
127 private static final float PI = ( float ) ( Math.PI );
128 private static final double TWO_PI = 2 * Math.PI;
129 private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
130 private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
131 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
132 private static final short OV_BORDER = 10;
133 final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
134 final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
135 final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
136 final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
137 final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
138 private final static long serialVersionUID = -978349745916505029L;
139 private final static int EURO_D = 10;
140 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
141 private final static int MIN_ROOT_LENGTH = 3;
142 private final static int MAX_SUBTREES = 100;
143 private final static int MAX_NODE_FRAMES = 10;
144 private final static int MOVE = 20;
145 private final static NumberFormat FORMATTER_CONFIDENCE;
146 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
147 private final static int WIGGLE = 2;
148 private final static int LIMIT_FOR_HQ_RENDERING = 1000;
149 private final static int CONFIDENCE_LEFT_MARGIN = 4;
150 // TODO "rendering_hints" was static before. Need to make sure everything is OK with it not
151 // being static anymore (02/20/2009).
152 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
153 RenderingHints.VALUE_RENDER_DEFAULT );
154 private File _treefile = null;
155 private Configuration _configuration = null;
156 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
157 private int _node_frame_index = 0;
158 private Phylogeny _phylogeny = null;
159 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
160 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
161 private int _subtree_index = 0;
162 private MainPanel _main_panel = null;
163 private Set<Integer> _found_nodes = null;
164 private PhylogenyNode _highlight_node = null;
165 private JPopupMenu _node_popup_menu = null;
166 private JMenuItem _node_popup_menu_items[] = null;
167 private int _longest_ext_node_info = 0;
168 private float _x_correction_factor = 0.0f;
169 private float _ov_x_correction_factor = 0.0f;
170 private float _x_distance = 0.0f;
171 private float _y_distance = 0.0f;
172 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
173 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
174 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
175 private float _last_drag_point_x = 0;
176 private float _last_drag_point_y = 0;
177 private ControlPanel _control_panel = null;
178 private int _external_node_index = 0;
179 private final Polygon _polygon = new Polygon();
180 private final StringBuilder _sb = new StringBuilder();
181 private JColorChooser _color_chooser = null;
182 private double _scale_distance = 0.0;
183 private String _scale_label = null;
184 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
185 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
186 private final Line2D _line = new Line2D.Float();
187 private final Ellipse2D _ellipse = new Ellipse2D.Float();
188 private final Rectangle2D _rectangle = new Rectangle2D.Float();
189 private Options _options = null;
190 private float _ov_max_width = 0;
191 private float _ov_max_height = 0;
192 private int _ov_x_position = 0;
193 private int _ov_y_position = 0;
194 private int _ov_y_start = 0;
195 private float _ov_y_distance = 0;
196 private float _ov_x_distance = 0;
197 private boolean _ov_on = false;
198 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
199 private float _urt_factor = 1;
200 private float _urt_factor_ov = 1;
201 private final boolean _phy_has_branch_lengths;
202 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
203 private boolean _in_ov_rect = false;
204 private boolean _in_ov = false;
205 private final Rectangle _ov_virtual_rectangle = new Rectangle();
206 final private static double _180_OVER_PI = 180.0 / Math.PI;
207 private static final float ROUNDED_D = 8;
208 private int _circ_max_depth;
209 private PhylogenyNode _root;
210 final private Arc2D _arc = new Arc2D.Double();
211 final private HashMap<Integer, Double> _urt_nodeid_angle_map = new HashMap<Integer, Double>();
212 final private HashMap<Integer, Integer> _urt_nodeid_index_map = new HashMap<Integer, Integer>();
213 final private Set<Integer> _collapsed_external_nodeid_set = new HashSet<Integer>();
214 HashMap<Integer, Short> _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
215 private AffineTransform _at;
216 private double _max_distance_to_root = -1;
217 private int _dynamic_hiding_factor = 0;
218 private boolean _edited = false;
219 private Popup _node_desc_popup;
220 private JTextArea _rollover_popup;
221 // private final int _box_size;
222 // private final int _half_box_size;
223 //private final short _skip_counter = 0;
224 private final StringBuffer _popup_buffer = new StringBuffer();
225 final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(),
228 private static final boolean DRAW_MEAN_COUNTS = true; //TODO remove me later
229 private Sequence _query_sequence = null;
230 private final FontRenderContext _frc = new FontRenderContext( null,
233 // expression values menu:
234 private DescriptiveStatistics _statistics_for_vector_data;
235 private PhylogenyNode[] _nodes_in_preorder = null;
236 // private Image offscreenImage;
237 // private Graphics offscreenGraphics;
238 // private Dimension offscreenDimension;
240 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
241 dfs.setDecimalSeparator( '.' );
242 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
243 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
246 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
247 requestFocusInWindow();
248 addKeyListener( new KeyAdapter() {
251 public void keyPressed( final KeyEvent key_event ) {
252 keyPressedCalls( key_event );
253 requestFocusInWindow();
256 addFocusListener( new FocusAdapter() {
259 public void focusGained( final FocusEvent e ) {
260 requestFocusInWindow();
263 if ( ( t == null ) || t.isEmpty() ) {
264 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
266 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
268 _configuration = configuration;
270 _phy_has_branch_lengths = ForesterUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
272 // if ( !_phylogeny.isEmpty() ) {
273 _phylogeny.recalculateNumberOfExternalDescendants( true );
274 checkForVectorProperties( _phylogeny );
276 setBackground( getTreeColorSet().getBackgroundColor() );
277 final MouseListener mouse_listener = new MouseListener( this );
278 addMouseListener( mouse_listener );
279 addMouseMotionListener( mouse_listener );
280 addMouseWheelListener( this );
281 calculateScaleDistance();
282 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
283 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
284 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
287 public void checkForVectorProperties( final Phylogeny phy ) {
288 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
289 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
290 final PhylogenyNode node = iter.next();
291 if ( node.getNodeData().getProperties() != null ) {
292 final PropertiesMap pm = node.getNodeData().getProperties();
293 final double[] vector = new double[ pm.getProperties().size() ];
295 for( final String ref : pm.getProperties().keySet() ) {
296 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
297 final Property p = pm.getProperty( ref );
298 final String value_str = p.getValue();
299 final String index_str = ref
300 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
303 d = Double.parseDouble( value_str );
305 catch ( final NumberFormatException e ) {
306 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
307 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
312 i = Integer.parseInt( index_str );
314 catch ( final NumberFormatException e ) {
315 JOptionPane.showMessageDialog( this,
316 "Could not parse \"" + index_str
317 + "\" into index for vector data",
318 "Problem with Vector Data",
319 JOptionPane.ERROR_MESSAGE );
323 JOptionPane.showMessageDialog( this,
324 "Attempt to use negative index for vector data",
325 "Problem with Vector Data",
326 JOptionPane.ERROR_MESSAGE );
334 final List<Double> vector_l = new ArrayList<Double>( counter );
335 for( int i = 0; i < counter; ++i ) {
336 vector_l.add( vector[ i ] );
338 node.getNodeData().setVector( vector_l );
341 if ( stats.getN() > 0 ) {
342 _statistics_for_vector_data = stats;
346 final public void actionPerformed( final ActionEvent e ) {
348 boolean done = false;
349 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
350 for( index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
351 // NOTE: index corresponds to the indices of click-to options
352 // in the control panel.
353 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
354 // Set this as the new default click-to action
355 _main_panel.getControlPanel().setClickToAction( index );
356 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
357 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
358 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
363 requestFocusInWindow();
366 final private void addEmptyNode( final PhylogenyNode node ) {
367 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
368 errorMessageNoCutCopyPasteInUnrootedDisplay();
371 final String label = getASimpleTextRepresentationOfANode( node );
373 if ( ForesterUtil.isEmpty( label ) ) {
374 msg = "How to add the new, empty node?";
377 msg = "How to add the new, empty node to node" + label + "?";
379 final Object[] options = { "As sibling", "As descendant", "Cancel" };
380 final int r = JOptionPane.showOptionDialog( this,
382 "Addition of Empty New Node",
383 JOptionPane.CLOSED_OPTION,
384 JOptionPane.QUESTION_MESSAGE,
388 boolean add_as_sibling = true;
390 add_as_sibling = false;
395 final Phylogeny phy = new Phylogeny();
396 phy.setRoot( new PhylogenyNode() );
397 phy.setRooted( true );
398 if ( add_as_sibling ) {
399 if ( node.isRoot() ) {
400 JOptionPane.showMessageDialog( this,
401 "Cannot add sibling to root",
402 "Attempt to add sibling to root",
403 JOptionPane.ERROR_MESSAGE );
406 phy.addAsSibling( node );
409 phy.addAsChild( node );
411 _nodes_in_preorder = null;
412 _phylogeny.externalNodesHaveChanged();
413 _phylogeny.hashIDs();
414 _phylogeny.recalculateNumberOfExternalDescendants( true );
415 resetNodeIdToDistToLeafMap();
420 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
421 final boolean is_vertical,
423 final boolean to_pdf,
424 final boolean to_graphics_file ) {
425 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
426 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
427 g.setColor( Color.BLACK );
429 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
430 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
431 && ( getCutOrCopiedTree() != null )
432 && ( getCopiedAndPastedNodes() != null )
434 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
435 g.setColor( getTreeColorSet().getFoundColor() );
437 else if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
438 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
441 g.setColor( getTreeColorSet().getBranchColorForPdf() );
444 g.setColor( getTreeColorSet().getBranchColor() );
448 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
449 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
450 return ( PhylogenyMethods.getBranchColorValue( node ) );
453 return ( getTreeColorSet().getBranchColor() );
457 final private void blast( final PhylogenyNode node ) {
458 if ( !isCanBlast( node ) ) {
459 JOptionPane.showMessageDialog( this,
460 "No sequence information present",
462 JOptionPane.WARNING_MESSAGE );
465 if ( node.getNodeData().isHasSequence() ) {
467 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) {
468 name = node.getNodeData().getSequence().getName();
470 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) {
471 name = node.getNodeData().getSequence().getSymbol();
473 else if ( node.getNodeData().getSequence().getAccession() != null ) {
474 name = node.getNodeData().getSequence().getAccession().getValue();
476 if ( !ForesterUtil.isEmpty( name ) ) {
478 System.out.println( "trying: " + name );
479 final Blast s = new Blast();
482 catch ( final Exception e ) {
489 final void calcMaxDepth() {
490 if ( _phylogeny != null ) {
491 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
496 * Calculate the length of the distance between the given node and its
502 * @return the distance value
504 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
505 if ( getControlPanel().isDrawPhylogram() ) {
506 if ( node.getDistanceToParent() < 0.0 ) {
509 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
512 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
513 return getXdistance();
515 return getXdistance() * factor;
519 final private Color calculateColorForAnnotation( final PhylogenyData ann ) {
520 Color c = getTreeColorSet().getAnnotationColor();
521 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
522 c = getControlPanel().getAnnotationColors().get( ann.asSimpleText().toString() );
524 c = getTreeColorSet().getAnnotationColor();
530 final void calculateLongestExtNodeInfo() {
531 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
535 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
537 if ( node.isCollapse() ) {
540 if ( getControlPanel().isShowNodeNames() ) {
541 sum += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
543 if ( node.getNodeData().isHasSequence() ) {
544 if ( getControlPanel().isShowSequenceAcc()
545 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
546 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
550 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
551 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
553 if ( getControlPanel().isShowGeneSymbols()
554 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
555 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
557 if ( getControlPanel().isShowAnnotation()
558 && ( node.getNodeData().getSequence().getAnnotations() != null )
559 && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
560 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAnnotation( 0 )
565 if ( node.getNodeData().isHasTaxonomy() ) {
566 final Taxonomy tax = node.getNodeData().getTaxonomy();
567 if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
568 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getTaxonomyCode() + " " );
570 if ( getControlPanel().isShowTaxonomyScientificNames()
571 && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
572 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getScientificName() + " " );
574 if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
575 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getCommonName() + " ()" );
578 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
579 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters()
580 .getGainedCharactersAsStringBuffer().toString() );
582 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
583 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
584 sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() )
585 .getRenderingSize().getWidth();
587 if ( sum >= Constants.EXT_NODE_INFO_LENGTH_MAX ) {
588 setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX );
591 if ( sum > longest ) {
595 if ( longest >= Constants.EXT_NODE_INFO_LENGTH_MAX ) {
596 setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX );
599 setLongestExtNodeInfo( longest );
603 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
604 if ( getControlPanel().isDrawPhylogram() ) {
605 if ( node.getDistanceToParent() < 0.0 ) {
608 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
611 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
612 return getOvXDistance();
614 return getOvXDistance() * factor;
618 final void calculateScaleDistance() {
619 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
622 final double height = getMaxDistanceToRoot();
624 if ( ( height <= 0.5 ) ) {
625 setScaleDistance( 0.01 );
627 else if ( height <= 5.0 ) {
628 setScaleDistance( 0.1 );
630 else if ( height <= 50.0 ) {
631 setScaleDistance( 1 );
633 else if ( height <= 500.0 ) {
634 setScaleDistance( 10 );
637 setScaleDistance( 100 );
641 setScaleDistance( 0.0 );
643 String scale_label = String.valueOf( getScaleDistance() );
644 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
645 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
647 setScaleLabel( scale_label );
650 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
651 String species = tax.getTaxonomyCode();
652 if ( ForesterUtil.isEmpty( species ) ) {
653 species = tax.getScientificName();
654 if ( ForesterUtil.isEmpty( species ) ) {
655 species = tax.getCommonName();
658 if ( ForesterUtil.isEmpty( species ) ) {
659 return getTreeColorSet().getTaxonomyColor();
661 // Look in species hash
662 Color c = getControlPanel().getSpeciesColors().get( species );
664 c = Util.calculateColorFromString( species );
665 getControlPanel().getSpeciesColors().put( species, c );
670 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
671 JOptionPane.showMessageDialog( this,
672 "Cannot launch web browser for " + type_type + " data of this node",
673 "Cannot launch web browser",
674 JOptionPane.WARNING_MESSAGE );
678 * Collapse the tree from the given node
683 final void collapse( final PhylogenyNode node ) {
684 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
685 JOptionPane.showMessageDialog( this,
686 "Cannot collapse in unrooted display type",
687 "Attempt to collapse in unrooted display",
688 JOptionPane.WARNING_MESSAGE );
691 if ( !node.isExternal() && !node.isRoot() ) {
692 final boolean collapse = !node.isCollapse();
693 Util.collapseSubtree( node, collapse );
694 updateSetOfCollapsedExternalNodes( _phylogeny );
695 _phylogeny.recalculateNumberOfExternalDescendants( true );
696 resetNodeIdToDistToLeafMap();
697 calculateLongestExtNodeInfo();
698 _nodes_in_preorder = null;
699 resetPreferredSize();
701 _main_panel.adjustJScrollPane();
706 final void collapseSpeciesSpecificSubtrees() {
707 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
711 Util.collapseSpeciesSpecificSubtrees( _phylogeny );
712 updateSetOfCollapsedExternalNodes( _phylogeny );
713 _phylogeny.recalculateNumberOfExternalDescendants( true );
714 resetNodeIdToDistToLeafMap();
715 calculateLongestExtNodeInfo();
716 _nodes_in_preorder = null;
717 resetPreferredSize();
718 _main_panel.adjustJScrollPane();
723 final private void colorizeSubtree( final Color c, final PhylogenyNode node ) {
724 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
725 JOptionPane.showMessageDialog( this,
726 "Cannot colorize subtree in unrooted display type",
727 "Attempt to colorize subtree in unrooted display",
728 JOptionPane.WARNING_MESSAGE );
731 _control_panel.setColorBranches( true );
732 if ( _control_panel.getColorBranchesCb() != null ) {
733 _control_panel.getColorBranchesCb().setSelected( true );
735 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
736 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
741 final private void colorSubtree( final PhylogenyNode node ) {
742 Color intitial_color = null;
743 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null )
744 && ( ( ( !node.isRoot() && ( node.getParent().getNumberOfDescendants() < 3 ) ) ) || ( node.isRoot() ) ) ) {
745 intitial_color = PhylogenyMethods.getBranchColorValue( node );
748 intitial_color = getTreeColorSet().getBranchColor();
750 _color_chooser.setColor( intitial_color );
751 _color_chooser.setPreviewPanel( new JPanel() );
752 final JDialog dialog = JColorChooser
754 "Subtree colorization",
757 new SubtreeColorizationActionListener( _color_chooser, node ),
759 dialog.setVisible( true );
762 final void confColor() {
763 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
767 Util.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
768 _control_panel.setColorBranches( true );
769 if ( _control_panel.getColorBranchesCb() != null ) {
770 _control_panel.getColorBranchesCb().setSelected( true );
776 final private void copySubtree( final PhylogenyNode node ) {
777 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
778 errorMessageNoCutCopyPasteInUnrootedDisplay();
781 _nodes_in_preorder = null;
782 setCutOrCopiedTree( _phylogeny.copy( node ) );
783 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
784 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
785 for( final PhylogenyNode n : nodes ) {
786 node_ids.add( n.getId() );
788 node_ids.add( node.getId() );
789 setCopiedAndPastedNodes( node_ids );
793 final private void cutSubtree( final PhylogenyNode node ) {
794 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
795 errorMessageNoCutCopyPasteInUnrootedDisplay();
798 if ( node.isRoot() ) {
799 JOptionPane.showMessageDialog( this,
800 "Cannot cut entire tree as subtree",
801 "Attempt to cut entire tree",
802 JOptionPane.ERROR_MESSAGE );
805 final String label = getASimpleTextRepresentationOfANode( node );
806 final int r = JOptionPane.showConfirmDialog( null,
807 "Cut subtree" + label + "?",
808 "Confirm Cutting of Subtree",
809 JOptionPane.YES_NO_OPTION );
810 if ( r != JOptionPane.OK_OPTION ) {
813 _nodes_in_preorder = null;
814 setCopiedAndPastedNodes( null );
815 setCutOrCopiedTree( _phylogeny.copy( node ) );
816 _phylogeny.deleteSubtree( node, true );
817 _phylogeny.hashIDs();
818 _phylogeny.recalculateNumberOfExternalDescendants( true );
819 resetNodeIdToDistToLeafMap();
824 final private void cycleColors() {
825 getMainPanel().getTreeColorSet().cycleColorScheme();
826 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
827 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
831 final void decreaseDomainStructureEvalueThreshold() {
832 if ( _domain_structure_e_value_thr_exp > -20 ) {
833 _domain_structure_e_value_thr_exp -= 1;
837 final private void decreaseOvSize() {
838 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
839 setOvMaxWidth( getOvMaxWidth() - 5 );
840 setOvMaxHeight( getOvMaxHeight() - 5 );
842 getControlPanel().displayedPhylogenyMightHaveChanged( false );
846 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
847 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
848 errorMessageNoCutCopyPasteInUnrootedDisplay();
851 if ( node.isRoot() ) {
852 JOptionPane.showMessageDialog( this,
853 "Cannot delete entire tree",
854 "Attempt to delete entire tree",
855 JOptionPane.ERROR_MESSAGE );
858 final String label = getASimpleTextRepresentationOfANode( node );
859 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
860 final int r = JOptionPane.showOptionDialog( this,
861 "Delete" + label + "?",
862 "Delete Node/Subtree",
863 JOptionPane.CLOSED_OPTION,
864 JOptionPane.QUESTION_MESSAGE,
868 _nodes_in_preorder = null;
869 boolean node_only = true;
877 PhylogenyMethods.removeNode( node, _phylogeny );
880 _phylogeny.deleteSubtree( node, true );
882 _phylogeny.externalNodesHaveChanged();
883 _phylogeny.hashIDs();
884 _phylogeny.recalculateNumberOfExternalDescendants( true );
885 resetNodeIdToDistToLeafMap();
890 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
891 makePopupMenus( node );
892 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
893 _node_popup_menu.show( this, x, y );
896 final private void drawArc( final double x,
900 final double start_angle,
901 final double arc_angle,
902 final Graphics2D g ) {
903 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
907 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
908 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
911 _line.setLine( x1, y1, x2, y2 );
915 final private void drawOval( final double x,
919 final Graphics2D g ) {
920 _ellipse.setFrame( x, y, width, heigth );
924 final private void drawOvalFilled( final double x,
928 final Graphics2D g ) {
929 _ellipse.setFrame( x, y, width, heigth );
933 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
934 _rectangle.setFrame( x, y, width, heigth );
935 g.draw( _rectangle );
938 final private void drawRectFilled( final double x,
942 final Graphics2D g ) {
943 _rectangle.setFrame( x, y, width, heigth );
944 g.fill( _rectangle );
947 final private void drawRectGradient( final double x,
954 final Color color_border ) {
955 _rectangle.setFrame( x, y, width, heigth );
956 g.setPaint( new GradientPaint( ( float ) x,
959 ( float ) ( x + width ),
960 ( float ) ( y + heigth ),
963 g.fill( _rectangle );
964 if ( color_border != null ) {
965 g.setPaint( color_border );
966 g.draw( _rectangle );
970 final private void drawOvalGradient( final double x,
977 final Color color_border ) {
978 _ellipse.setFrame( x, y, width, heigth );
979 g.setPaint( new GradientPaint( ( float ) x,
982 ( float ) ( x + width ),
983 ( float ) ( y + heigth ),
987 if ( color_border != null ) {
988 g.setPaint( color_border );
993 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
994 JOptionPane.showMessageDialog( this,
995 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
996 "Attempt to cut/copy/paste/add/delete in unrooted display",
997 JOptionPane.ERROR_MESSAGE );
1001 * Find the node, if any, at the given location
1005 * @return pointer to the node at x,y, null if not found
1007 final PhylogenyNode findNode( final int x, final int y ) {
1008 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1011 final int half_box_size_plus_wiggle = getOptions().getDefaultNodeShapeSize() / 2 + WIGGLE;
1012 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
1013 final PhylogenyNode node = iter.next();
1014 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
1015 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
1016 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
1017 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
1018 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
1025 final private String getASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
1026 final String tax = PhylogenyMethods.getSpecies( node );
1027 String label = node.getName();
1028 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
1029 label = label + " " + tax;
1031 else if ( !ForesterUtil.isEmpty( tax ) ) {
1037 if ( !ForesterUtil.isEmpty( label ) ) {
1038 label = " [" + label + "]";
1043 final Configuration getConfiguration() {
1044 return _configuration;
1047 final ControlPanel getControlPanel() {
1048 return _control_panel;
1051 final private Set<Integer> getCopiedAndPastedNodes() {
1052 return getMainPanel().getCopiedAndPastedNodes();
1055 final private Phylogeny getCutOrCopiedTree() {
1056 return getMainPanel().getCutOrCopiedTree();
1059 final int getDomainStructureEvalueThreshold() {
1060 return _domain_structure_e_value_thr_exp;
1063 final Set<Integer> getFoundNodes() {
1064 return _found_nodes;
1067 final private float getLastDragPointX() {
1068 return _last_drag_point_x;
1071 final private float getLastDragPointY() {
1072 return _last_drag_point_y;
1075 final int getLongestExtNodeInfo() {
1076 return _longest_ext_node_info;
1079 final public MainPanel getMainPanel() {
1083 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
1084 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
1085 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
1086 _nodeid_dist_to_leaf.put( node.getId(), m );
1090 return _nodeid_dist_to_leaf.get( node.getId() );
1094 final private double getMaxDistanceToRoot() {
1095 if ( _max_distance_to_root < 0 ) {
1096 recalculateMaxDistanceToRoot();
1098 return _max_distance_to_root;
1101 final Options getOptions() {
1102 if ( _options == null ) {
1103 _options = getControlPanel().getOptions();
1108 final private float getOvMaxHeight() {
1109 return _ov_max_height;
1112 final private float getOvMaxWidth() {
1113 return _ov_max_width;
1116 final Rectangle2D getOvRectangle() {
1117 return _ov_rectangle;
1120 final Rectangle getOvVirtualRectangle() {
1121 return _ov_virtual_rectangle;
1124 final private float getOvXcorrectionFactor() {
1125 return _ov_x_correction_factor;
1128 final private float getOvXDistance() {
1129 return _ov_x_distance;
1132 final private int getOvXPosition() {
1133 return _ov_x_position;
1136 final private float getOvYDistance() {
1137 return _ov_y_distance;
1140 final private int getOvYPosition() {
1141 return _ov_y_position;
1144 final private int getOvYStart() {
1149 * Get a pointer to the phylogeny
1151 * @return a pointer to the phylogeny
1153 public final Phylogeny getPhylogeny() {
1157 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
1158 return _graphics_type;
1161 final private double getScaleDistance() {
1162 return _scale_distance;
1165 final private String getScaleLabel() {
1166 return _scale_label;
1169 final double getStartingAngle() {
1170 return _urt_starting_angle;
1174 * Find a color for this species name.
1177 * @return the species color
1179 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
1180 if ( node.getNodeData().isHasTaxonomy() ) {
1181 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
1183 // return non-colorized color
1184 return getTreeColorSet().getTaxonomyColor();
1188 * @return pointer to colorset for tree drawing
1190 final TreeColorSet getTreeColorSet() {
1191 return getMainPanel().getTreeColorSet();
1194 final File getTreeFile() {
1198 final private TreeFontSet getTreeFontSet() {
1199 return getMainPanel().getTreeFontSet();
1202 final private float getUrtFactor() {
1206 final private float getUrtFactorOv() {
1207 return _urt_factor_ov;
1210 final float getXcorrectionFactor() {
1211 return _x_correction_factor;
1214 final float getXdistance() {
1218 final float getYdistance() {
1222 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
1225 showNodeFrame( node );
1240 colorSubtree( node );
1255 copySubtree( node );
1258 pasteSubtree( node );
1260 case DELETE_NODE_OR_SUBTREE:
1261 deleteNodeOrSubtree( node );
1264 addEmptyNode( node );
1266 case EDIT_NODE_DATA:
1267 showNodeEditFrame( node );
1270 throw new IllegalArgumentException( "unknown action: " + action );
1274 final void increaseDomainStructureEvalueThreshold() {
1275 if ( _domain_structure_e_value_thr_exp < 3 ) {
1276 _domain_structure_e_value_thr_exp += 1;
1280 final private void increaseOvSize() {
1281 if ( ( getOvMaxWidth() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 )
1282 && ( getOvMaxHeight() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
1283 .getHeight() / 2 ) ) {
1284 setOvMaxWidth( getOvMaxWidth() + 5 );
1285 setOvMaxHeight( getOvMaxHeight() + 5 );
1287 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1291 final void inferCommonPartOfScientificNames() {
1292 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1296 Util.inferCommonPartOfScientificNames( _phylogeny );
1301 final private void init() {
1302 _color_chooser = new JColorChooser();
1303 _rollover_popup = new JTextArea();
1304 _rollover_popup.setFont( POPUP_FONT );
1305 resetNodeIdToDistToLeafMap();
1307 setTreeFile( null );
1309 initializeOvSettings();
1310 setStartingAngle( TWO_PI * 3 / 4 );
1311 final ImageLoader il = new ImageLoader( this );
1312 new Thread( il ).start();
1315 final private void initializeOvSettings() {
1316 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
1317 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
1320 final void initNodeData() {
1321 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1324 double max_original_domain_structure_width = 0.0;
1325 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1326 if ( node.getNodeData().isHasSequence()
1327 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1328 RenderableDomainArchitecture rds = null;
1329 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
1330 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
1331 getConfiguration() );
1332 node.getNodeData().getSequence().setDomainArchitecture( rds );
1335 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1337 if ( getControlPanel().isShowDomainArchitectures() ) {
1338 final double dsw = rds.getOriginalSize().getWidth();
1339 if ( dsw > max_original_domain_structure_width ) {
1340 max_original_domain_structure_width = dsw;
1345 if ( getControlPanel().isShowDomainArchitectures() ) {
1346 final double ds_factor_width = _domain_structure_width / max_original_domain_structure_width;
1347 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1348 if ( node.getNodeData().isHasSequence()
1349 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1350 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1351 .getSequence().getDomainArchitecture();
1352 rds.setRenderingFactorWidth( ds_factor_width );
1353 rds.setParameter( _domain_structure_e_value_thr_exp );
1359 final boolean inOv( final MouseEvent e ) {
1360 return ( ( e.getX() > getVisibleRect().x + getOvXPosition() + 1 )
1361 && ( e.getX() < getVisibleRect().x + getOvXPosition() + getOvMaxWidth() - 1 )
1362 && ( e.getY() > getVisibleRect().y + getOvYPosition() + 1 ) && ( e.getY() < getVisibleRect().y
1363 + getOvYPosition() + getOvMaxHeight() - 1 ) );
1366 final boolean inOvRectangle( final MouseEvent e ) {
1367 return ( ( e.getX() >= getOvRectangle().getX() - 1 )
1368 && ( e.getX() <= getOvRectangle().getX() + getOvRectangle().getWidth() + 1 )
1369 && ( e.getY() >= getOvRectangle().getY() - 1 ) && ( e.getY() <= getOvRectangle().getY()
1370 + getOvRectangle().getHeight() + 1 ) );
1373 final private boolean inOvVirtualRectangle( final int x, final int y ) {
1374 return ( ( x >= getOvVirtualRectangle().x - 1 )
1375 && ( x <= getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 )
1376 && ( y >= getOvVirtualRectangle().y - 1 ) && ( y <= getOvVirtualRectangle().y
1377 + getOvVirtualRectangle().height + 1 ) );
1380 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
1381 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
1384 final boolean isApplet() {
1385 return getMainPanel() instanceof MainPanelApplets;
1388 final private boolean isCanBlast( final PhylogenyNode node ) {
1389 return ( node.getNodeData().isHasSequence() && ( ( ( node.getNodeData().getSequence().getAccession() != null ) && !ForesterUtil
1390 .isEmpty( node.getNodeData().getSequence().getAccession().getValue() ) )
1391 || !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) || !ForesterUtil.isEmpty( node
1392 .getNodeData().getSequence().getSymbol() ) ) );
1395 final boolean isCanCollapse() {
1396 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1399 final boolean isCanColorSubtree() {
1400 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1403 final boolean isCanCopy() {
1404 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1407 final boolean isCanCut( final PhylogenyNode node ) {
1408 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1412 final boolean isCanDelete() {
1413 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1416 final private boolean isCanOpenSeqWeb( final PhylogenyNode node ) {
1417 if ( node.getNodeData().isHasSequence()
1418 && ( node.getNodeData().getSequence().getAccession() != null )
1419 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
1420 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
1421 && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource()
1422 .toLowerCase() ) ) {
1428 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
1429 if ( node.getNodeData().isHasTaxonomy()
1430 && ( ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
1431 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getProvider() )
1432 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && getConfiguration()
1433 .isHasWebLink( node.getNodeData().getTaxonomy().getIdentifier().getProvider().toLowerCase() ) )
1434 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
1435 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
1436 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
1437 .getNodeData().getTaxonomy().getIdentifier() != null )
1438 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && node
1439 .getNodeData().getTaxonomy().getIdentifier().getValue().startsWith( "http://" ) ) ) ) {
1447 final boolean isCanPaste() {
1448 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1449 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1452 final boolean isCanReroot() {
1453 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1456 final boolean isCanSubtree( final PhylogenyNode node ) {
1457 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1458 .isRoot() || ( _subtree_index > 0 ) ) );
1461 final boolean isEdited() {
1465 final private boolean isInFoundNodes( final PhylogenyNode node ) {
1466 return ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) );
1469 final private boolean isInOv() {
1473 final boolean isInOvRect() {
1477 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
1479 if ( getControlPanel().isShowTaxonomyImages() ) {
1480 y_dist = 40 + ( int ) getYdistance();
1482 return ( ( node.getYcoord() < getVisibleRect().getMinY() - y_dist )
1483 || ( node.getYcoord() > getVisibleRect().getMaxY() + y_dist ) || ( ( node.getParent() != null ) && ( node
1484 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
1487 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
1488 return ( ( node.getYcoord() < getVisibleRect().getMinY() - 20 )
1489 || ( node.getYcoord() > getVisibleRect().getMaxY() + 20 )
1490 || ( node.getXcoord() < getVisibleRect().getMinX() - 20 ) || ( node.getXcoord() > getVisibleRect()
1491 .getMaxX() + 20 ) );
1494 final private boolean isNonLinedUpCladogram() {
1495 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
1498 final boolean isOvOn() {
1502 final boolean isPhyHasBranchLengths() {
1503 return _phy_has_branch_lengths;
1506 final private boolean isUniformBranchLengthsForCladogram() {
1507 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
1510 final private void keyPressedCalls( final KeyEvent e ) {
1511 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
1512 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
1513 if ( !isInOvRect() ) {
1514 setInOvRect( true );
1517 else if ( isInOvRect() ) {
1518 setInOvRect( false );
1521 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
1522 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1523 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
1524 getMainPanel().getTreeFontSet().mediumFonts();
1525 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1527 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1528 getMainPanel().getTreeFontSet().decreaseFontSize();
1529 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1531 else if ( plusPressed( e.getKeyCode() ) ) {
1532 getMainPanel().getTreeFontSet().increaseFontSize();
1533 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1537 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1538 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
1539 getControlPanel().showWhole();
1541 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
1542 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
1543 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
1544 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
1545 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1546 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1548 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1549 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1550 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1552 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1553 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1554 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1555 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1557 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1558 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1559 Constants.WHEEL_ZOOM_IN_FACTOR );
1560 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1567 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1570 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1574 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1578 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1579 scroll_position.x = scroll_position.x + dx;
1580 scroll_position.y = scroll_position.y + dy;
1581 if ( scroll_position.x <= 0 ) {
1582 scroll_position.x = 0;
1585 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1586 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1587 if ( scroll_position.x >= max_x ) {
1588 scroll_position.x = max_x;
1591 if ( scroll_position.y <= 0 ) {
1592 scroll_position.y = 0;
1595 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1596 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1597 if ( scroll_position.y >= max_y ) {
1598 scroll_position.y = max_y;
1602 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1605 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1606 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1607 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1608 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1609 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1611 else if ( plusPressed( e.getKeyCode() ) ) {
1612 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1613 Constants.WHEEL_ZOOM_IN_FACTOR );
1614 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1615 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1617 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
1618 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1619 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1620 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1621 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1624 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
1625 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1626 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1627 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1628 if ( getStartingAngle() < 0 ) {
1629 setStartingAngle( TWO_PI + getStartingAngle() );
1631 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1634 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
1635 boolean selected = false;
1636 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
1637 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1641 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1643 if ( getMainPanel().getMainFrame() == null ) {
1644 // Must be "E" applet version.
1645 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1646 if ( ae.getlabelDirectionCbmi() != null ) {
1647 ae.getlabelDirectionCbmi().setSelected( selected );
1651 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
1655 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
1656 switchDisplaygetPhylogenyGraphicsType();
1659 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
1663 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
1664 MainFrame.cycleOverview( getOptions(), this );
1667 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
1670 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
1677 final private void makePopupMenus( final PhylogenyNode node ) {
1678 _node_popup_menu = new JPopupMenu();
1679 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
1680 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
1681 for( int i = 0; i < clickto_names.size(); i++ ) {
1682 final String title = clickto_names.get( i );
1683 _node_popup_menu_items[ i ] = new JMenuItem( title );
1684 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
1685 _node_popup_menu_items[ i ].setEnabled( isCanOpenSeqWeb( node ) );
1687 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
1688 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
1690 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
1691 if ( Constants.__RELEASE || Constants.__SNAPSHOT_RELEASE ) {
1694 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
1696 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
1697 if ( !getOptions().isEditable() ) {
1700 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
1702 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
1703 if ( !getOptions().isEditable() ) {
1706 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
1708 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
1709 if ( !getOptions().isEditable() ) {
1712 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
1714 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
1715 if ( !getOptions().isEditable() ) {
1718 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
1720 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
1721 if ( !getOptions().isEditable() ) {
1725 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
1726 if ( !getOptions().isEditable() ) {
1730 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
1731 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
1733 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
1734 _node_popup_menu_items[ i ].setEnabled( isCanCollapse() );
1736 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
1737 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
1739 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
1740 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
1742 _node_popup_menu_items[ i ].addActionListener( this );
1743 _node_popup_menu.add( _node_popup_menu_items[ i ] );
1747 final void midpointRoot() {
1748 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1751 if ( !_phylogeny.isRerootable() ) {
1752 JOptionPane.showMessageDialog( this,
1753 "This is not rerootable",
1755 JOptionPane.WARNING_MESSAGE );
1758 _nodes_in_preorder = null;
1760 PhylogenyMethods.midpointRoot( _phylogeny );
1761 resetNodeIdToDistToLeafMap();
1766 final void mouseClicked( final MouseEvent e ) {
1767 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1768 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1769 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1770 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - getOvRectangle().getWidth() / 2.0 )
1772 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - getOvRectangle().getHeight() / 2.0 )
1780 final double max_x = getWidth() - getVisibleRect().width;
1781 final double max_y = getHeight() - getVisibleRect().height;
1788 getMainPanel().getCurrentScrollPane().getViewport()
1789 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1790 setInOvRect( true );
1794 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1795 if ( node != null ) {
1796 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1799 _highlight_node = node;
1800 // Check if shift key is down
1801 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1802 // Yes, so add to _found_nodes
1803 if ( getFoundNodes() == null ) {
1804 setFoundNodes( new HashSet<Integer>() );
1806 getFoundNodes().add( node.getId() );
1807 // Check if control key is down
1809 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1810 // Yes, so pop-up menu
1811 displayNodePopupMenu( node, e.getX(), e.getY() );
1812 // Handle unadorned click
1815 // Check for right mouse button
1816 if ( e.getModifiers() == 4 ) {
1817 displayNodePopupMenu( node, e.getX(), e.getY() );
1820 // if not in _found_nodes, clear _found_nodes
1821 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1826 // no node was clicked
1827 _highlight_node = null;
1833 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1834 setCursor( MOVE_CURSOR );
1835 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1836 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1837 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1838 if ( scroll_position.x < 0 ) {
1839 scroll_position.x = 0;
1842 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1843 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1844 if ( scroll_position.x > max_x ) {
1845 scroll_position.x = max_x;
1848 if ( scroll_position.y < 0 ) {
1849 scroll_position.y = 0;
1852 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1853 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1854 if ( scroll_position.y > max_y ) {
1855 scroll_position.y = max_y;
1858 if ( isOvOn() || getOptions().isShowScale() ) {
1861 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1864 final void mouseDragInOvRectangle( final MouseEvent e ) {
1865 setCursor( HAND_CURSOR );
1866 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1867 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1868 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1869 double dx = ( w_ratio * e.getX() - w_ratio * getLastDragPointX() );
1870 double dy = ( h_ratio * e.getY() - h_ratio * getLastDragPointY() );
1871 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1872 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1873 if ( scroll_position.x <= 0 ) {
1874 scroll_position.x = 0;
1878 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1879 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1880 if ( scroll_position.x >= max_x ) {
1882 scroll_position.x = max_x;
1885 if ( scroll_position.y <= 0 ) {
1887 scroll_position.y = 0;
1890 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1891 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1892 if ( scroll_position.y >= max_y ) {
1894 scroll_position.y = max_y;
1898 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1899 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1900 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1903 final void mouseMoved( final MouseEvent e ) {
1904 requestFocusInWindow();
1905 if ( getControlPanel().isNodeDescPopup() ) {
1906 if ( _node_desc_popup != null ) {
1907 _node_desc_popup.hide();
1908 _node_desc_popup = null;
1911 if ( getOptions().isShowOverview() && isOvOn() ) {
1912 if ( inOvVirtualRectangle( e ) ) {
1913 if ( !isInOvRect() ) {
1914 setInOvRect( true );
1919 if ( isInOvRect() ) {
1920 setInOvRect( false );
1925 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
1934 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1935 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
1936 // cursor is over a tree node
1937 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
1938 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
1939 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
1940 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
1941 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
1942 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
1943 setCursor( CUT_CURSOR );
1946 setCursor( HAND_CURSOR );
1947 if ( getControlPanel().isNodeDescPopup() ) {
1948 showNodeDataPopup( e, node );
1953 setCursor( ARROW_CURSOR );
1958 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
1959 setCursor( ARROW_CURSOR );
1962 final public void mouseWheelMoved( final MouseWheelEvent e ) {
1963 final int notches = e.getWheelRotation();
1964 if ( inOvVirtualRectangle( e ) ) {
1965 if ( !isInOvRect() ) {
1966 setInOvRect( true );
1971 if ( isInOvRect() ) {
1972 setInOvRect( false );
1976 if ( e.isControlDown() ) {
1977 if ( notches < 0 ) {
1978 getTreeFontSet().increaseFontSize();
1979 getControlPanel().displayedPhylogenyMightHaveChanged( true );
1982 getTreeFontSet().decreaseFontSize();
1983 getControlPanel().displayedPhylogenyMightHaveChanged( true );
1986 else if ( e.isShiftDown() ) {
1987 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1988 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1989 if ( notches < 0 ) {
1990 for( int i = 0; i < ( -notches ); ++i ) {
1991 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1992 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1996 for( int i = 0; i < notches; ++i ) {
1997 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1998 if ( getStartingAngle() < 0 ) {
1999 setStartingAngle( TWO_PI + getStartingAngle() );
2001 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2006 if ( notches < 0 ) {
2007 for( int i = 0; i < ( -notches ); ++i ) {
2008 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
2009 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2013 for( int i = 0; i < notches; ++i ) {
2014 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
2015 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2021 if ( notches < 0 ) {
2022 for( int i = 0; i < ( -notches ); ++i ) {
2023 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
2024 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
2025 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
2026 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2030 for( int i = 0; i < notches; ++i ) {
2031 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
2032 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
2033 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
2034 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2039 requestFocusInWindow();
2043 final void multiplyUrtFactor( final float f ) {
2047 final JApplet obtainApplet() {
2048 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
2051 final private void openSeqWeb( final PhylogenyNode node ) {
2052 if ( !isCanOpenSeqWeb( node ) ) {
2053 cannotOpenBrowserWarningMessage( "sequence" );
2056 String uri_str = null;
2057 final Sequence seq = node.getNodeData().getSequence();
2058 final String source = seq.getAccession().getSource().toLowerCase();
2060 if ( source.toLowerCase().equals( "ncbi" ) ) {
2061 url = Constants.NCBI_ALL_DATABASE_SEARCH;
2064 final WebLink weblink = getConfiguration().getWebLink( source );
2065 url = weblink.getUrl().toString();
2068 uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 );
2070 catch ( final UnsupportedEncodingException e ) {
2071 Util.showErrorMessage( this, e.toString() );
2072 e.printStackTrace();
2074 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2076 JApplet applet = null;
2078 applet = obtainApplet();
2080 Util.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_seq" );
2082 catch ( final IOException e ) {
2083 Util.showErrorMessage( this, e.toString() );
2084 e.printStackTrace();
2086 catch ( final URISyntaxException e ) {
2087 Util.showErrorMessage( this, e.toString() );
2088 e.printStackTrace();
2092 cannotOpenBrowserWarningMessage( "sequence" );
2096 final private void openTaxWeb( final PhylogenyNode node ) {
2097 if ( !isCanOpenTaxWeb( node ) ) {
2098 cannotOpenBrowserWarningMessage( "taxonomic" );
2101 String uri_str = null;
2102 final Taxonomy tax = node.getNodeData().getTaxonomy();
2103 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
2104 && getConfiguration().isHasWebLink( tax.getIdentifier().getProvider().toLowerCase() ) ) {
2105 final String type = tax.getIdentifier().getProvider().toLowerCase();
2106 final WebLink weblink = getConfiguration().getWebLink( type );
2108 uri_str = weblink.getUrl() + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
2110 catch ( final UnsupportedEncodingException e ) {
2111 Util.showErrorMessage( this, e.toString() );
2112 e.printStackTrace();
2115 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2116 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
2118 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
2120 catch ( final URISyntaxException e ) {
2121 Util.showErrorMessage( this, e.toString() );
2123 e.printStackTrace();
2126 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
2128 uri_str = "http://www.eol.org/search?q="
2129 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
2131 catch ( final UnsupportedEncodingException e ) {
2132 Util.showErrorMessage( this, e.toString() );
2133 e.printStackTrace();
2136 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
2138 uri_str = "http://www.uniprot.org/taxonomy/?query="
2139 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
2141 catch ( final UnsupportedEncodingException e ) {
2142 Util.showErrorMessage( this, e.toString() );
2143 e.printStackTrace();
2146 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
2148 uri_str = "http://www.eol.org/search?q="
2149 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
2151 catch ( final UnsupportedEncodingException e ) {
2152 Util.showErrorMessage( this, e.toString() );
2153 e.printStackTrace();
2156 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2158 JApplet applet = null;
2160 applet = obtainApplet();
2162 Util.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_tax" );
2164 catch ( final IOException e ) {
2165 Util.showErrorMessage( this, e.toString() );
2166 e.printStackTrace();
2168 catch ( final URISyntaxException e ) {
2169 Util.showErrorMessage( this, e.toString() );
2170 e.printStackTrace();
2174 cannotOpenBrowserWarningMessage( "taxonomic" );
2178 final void paintBranchCircular( final PhylogenyNode p,
2179 final PhylogenyNode c,
2181 final boolean radial_labels,
2182 final boolean to_pdf,
2183 final boolean to_graphics_file ) {
2184 final double angle = _urt_nodeid_angle_map.get( c.getId() );
2185 final double root_x = _root.getXcoord();
2186 final double root_y = _root.getYcoord();
2187 final double dx = root_x - p.getXcoord();
2188 final double dy = root_y - p.getYcoord();
2189 final double parent_radius = Math.sqrt( dx * dx + dy * dy );
2190 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
2191 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
2192 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
2193 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
2194 final double r2 = 2.0 * parent_radius;
2195 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
2197 drawLine( c.getXcoord(),
2199 root_x + ( Math.cos( angle ) * parent_radius ),
2200 root_y + ( Math.sin( angle ) * parent_radius ),
2202 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c ) );
2203 if ( c.isExternal() ) {
2204 final boolean is_in_found_nodes = isInFoundNodes( c );
2205 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
2206 && ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor != 1 ) ) {
2209 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
2213 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
2214 final double angle = _urt_nodeid_angle_map.get( c.getId() );
2215 final double root_x = _root.getXSecondary();
2216 final double root_y = _root.getYSecondary();
2217 final double dx = root_x - p.getXSecondary();
2218 final double dy = root_y - p.getYSecondary();
2219 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
2220 final double parent_radius = Math.sqrt( dx * dx + dy * dy );
2221 g.setColor( getTreeColorSet().getOvColor() );
2222 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
2223 final double r2 = 2.0 * parent_radius;
2224 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
2226 drawLine( c.getXSecondary(),
2228 root_x + ( Math.cos( angle ) * parent_radius ),
2229 root_y + ( Math.sin( angle ) * parent_radius ),
2231 if ( isInFoundNodes( c ) ) {
2232 g.setColor( getTreeColorSet().getFoundColor() );
2233 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
2237 final private void paintBranchLength( final Graphics2D g,
2238 final PhylogenyNode node,
2239 final boolean to_pdf,
2240 final boolean to_graphics_file ) {
2241 g.setFont( getTreeFontSet().getSmallFont() );
2242 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2243 g.setColor( Color.BLACK );
2246 g.setColor( getTreeColorSet().getBranchLengthColor() );
2248 if ( !node.isRoot() ) {
2249 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2250 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2251 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2253 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2254 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2255 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2258 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2259 .getXcoord() + 3, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2263 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
2264 - getTreeFontSet()._small_max_descent, g );
2268 final private void paintBranchLite( final Graphics2D g,
2273 final PhylogenyNode node ) {
2274 g.setColor( getTreeColorSet().getOvColor() );
2275 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2276 drawLine( x1, y1, x2, y2, g );
2278 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2279 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2280 ( g ).draw( _quad_curve );
2282 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2283 final float dx = x2 - x1;
2284 final float dy = y2 - y1;
2285 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
2286 + ( dy * 0.8f ), x2, y2 );
2287 ( g ).draw( _cubic_curve );
2290 final float x2a = x2;
2291 final float x1a = x1;
2292 // draw the vertical line
2293 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
2294 drawLine( x1, y1, x1, y2, g );
2296 // draw the horizontal line
2297 drawLine( x1a, y2, x2a, y2, g );
2302 * Paint a branch which consists of a vertical and a horizontal bar
2303 * @param is_ind_found_nodes
2305 final private void paintBranchRectangular( final Graphics2D g,
2310 final PhylogenyNode node,
2311 final boolean to_pdf,
2312 final boolean to_graphics_file ) {
2313 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
2314 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2315 drawLine( x1, y1, x2, y2, g );
2317 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2318 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2319 g.draw( _quad_curve );
2321 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2322 final float dx = x2 - x1;
2323 final float dy = y2 - y1;
2324 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
2325 + ( dy * 0.8f ), x2, y2 );
2326 g.draw( _cubic_curve );
2329 final float x2a = x2;
2330 final float x1a = x1;
2332 if ( node.isFirstChildNode() || node.isLastChildNode()
2333 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2334 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2335 if ( !to_graphics_file
2337 && ( ( ( y2 < getVisibleRect().getMinY() - 20 ) && ( y1 < getVisibleRect().getMinY() - 20 ) ) || ( ( y2 > getVisibleRect()
2338 .getMaxY() + 20 ) && ( y1 > getVisibleRect().getMaxY() + 20 ) ) ) ) {
2342 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2343 float x2c = x1 + EURO_D;
2347 drawLine( x1, y1, x2c, y2, g );
2349 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2351 y2_r = y2 - ROUNDED_D;
2355 drawLine( x1, y1, x1, y2_r, g );
2358 y2_r = y2 + ROUNDED_D;
2362 drawLine( x1, y1, x1, y2_r, g );
2366 drawLine( x1, y1, x1, y2, g );
2370 // draw the horizontal line
2371 if ( !to_graphics_file && !to_pdf
2372 && ( ( y2 < getVisibleRect().getMinY() - 20 ) || ( y2 > getVisibleRect().getMaxY() + 20 ) ) ) {
2376 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
2377 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2378 x1_r = x1a + ROUNDED_D;
2380 drawLine( x1_r, y2, x2a, y2, g );
2383 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2384 final float x1c = x1a + EURO_D;
2386 drawLine( x1c, y2, x2a, y2, g );
2390 drawLine( x1a, y2, x2a, y2, g );
2394 final double w = PhylogenyMethods.getBranchWidthValue( node );
2395 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2396 x1_r = x1a + ROUNDED_D;
2398 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
2401 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2402 final float x1c = x1a + EURO_D;
2404 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
2408 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
2411 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2416 final double diff = y2 - y2_r;
2417 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
2420 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
2425 if ( node.isExternal() ) {
2426 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
2430 final void paintCircular( final Phylogeny phy,
2431 final double starting_angle,
2436 final boolean to_pdf,
2437 final boolean to_graphics_file ) {
2438 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
2439 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
2440 _root = phy.getRoot();
2441 _root.setXcoord( center_x );
2442 _root.setYcoord( center_y );
2443 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
2444 double current_angle = starting_angle;
2446 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2447 final PhylogenyNode n = it.next();
2448 if ( !n.isCollapse() ) {
2449 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
2450 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
2451 _urt_nodeid_angle_map.put( n.getId(), current_angle );
2452 _urt_nodeid_index_map.put( n.getId(), i++ );
2453 current_angle += ( TWO_PI / circ_num_ext_nodes );
2457 System.out.println( "is collapse" + n.getName() );
2460 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
2461 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file, isInFoundNodes( _root ) );
2464 private void updateSetOfCollapsedExternalNodes( final Phylogeny phy ) {
2465 _collapsed_external_nodeid_set.clear();
2466 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2467 final PhylogenyNode ext_node = it.next();
2468 PhylogenyNode n = ext_node;
2469 while ( !n.isRoot() ) {
2470 if ( n.isCollapse() ) {
2471 _collapsed_external_nodeid_set.add( ext_node.getId() );
2479 final void paintCircularLite( final Phylogeny phy,
2480 final double starting_angle,
2484 final Graphics2D g ) {
2485 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
2486 _root = phy.getRoot();
2487 _root.setXSecondary( center_x );
2488 _root.setYSecondary( center_y );
2489 double current_angle = starting_angle;
2490 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2491 final PhylogenyNode n = it.next();
2492 n.setXSecondary( ( float ) ( center_x + radius * Math.cos( current_angle ) ) );
2493 n.setYSecondary( ( float ) ( center_y + radius * Math.sin( current_angle ) ) );
2494 _urt_nodeid_angle_map.put( n.getId(), current_angle );
2495 current_angle += ( TWO_PI / circ_num_ext_nodes );
2497 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
2500 final private double paintCirculars( final PhylogenyNode n,
2501 final Phylogeny phy,
2502 final float center_x,
2503 final float center_y,
2504 final double radius,
2505 final boolean radial_labels,
2507 final boolean to_pdf,
2508 final boolean to_graphics_file ) {
2509 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
2510 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
2511 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
2513 return _urt_nodeid_angle_map.get( n.getId() );
2516 final List<PhylogenyNode> descs = n.getDescendants();
2518 for( final PhylogenyNode desc : descs ) {
2519 sum += paintCirculars( desc,
2530 if ( !n.isRoot() ) {
2531 r = 1 - ( ( ( double ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth );
2533 final double theta = sum / descs.size();
2534 n.setXcoord( ( float ) ( center_x + r * radius * Math.cos( theta ) ) );
2535 n.setYcoord( ( float ) ( center_y + r * radius * Math.sin( theta ) ) );
2536 _urt_nodeid_angle_map.put( n.getId(), theta );
2537 for( final PhylogenyNode desc : descs ) {
2538 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
2544 final private void paintCircularsLite( final PhylogenyNode n,
2545 final Phylogeny phy,
2549 final Graphics2D g ) {
2550 if ( n.isExternal() ) {
2554 final List<PhylogenyNode> descs = n.getDescendants();
2555 for( final PhylogenyNode desc : descs ) {
2556 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
2559 if ( !n.isRoot() ) {
2560 r = 1 - ( ( ( float ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth );
2562 final double theta = _urt_nodeid_angle_map.get( n.getId() );
2563 n.setXSecondary( ( float ) ( center_x + radius * r * Math.cos( theta ) ) );
2564 n.setYSecondary( ( float ) ( center_y + radius * r * Math.sin( theta ) ) );
2565 for( final PhylogenyNode desc : descs ) {
2566 paintBranchCircularLite( n, desc, g );
2571 final private void paintCollapsedNode( final Graphics2D g,
2572 final PhylogenyNode node,
2573 final boolean to_graphics_file,
2574 final boolean to_pdf,
2575 final boolean is_in_found_nodes ) {
2577 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2580 else if ( is_in_found_nodes ) {
2581 c = getTreeColorSet().getFoundColor();
2583 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2584 c = getTaxonomyBasedColor( node );
2586 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
2587 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2588 c = PhylogenyMethods.getBranchColorValue( node );
2591 c = getTreeColorSet().getCollapseFillColor();
2593 double d = node.getAllExternalDescendants().size();
2595 d = ( 3 * _y_distance ) / 3;
2598 d = ( Math.log10( d ) * _y_distance ) / 2.5;
2600 final int box_size = getOptions().getDefaultNodeShapeSize();
2601 if ( d < box_size ) {
2605 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() - box_size ),
2606 ForesterUtil.roundToInt( node.getYcoord() ) );
2607 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ),
2608 ForesterUtil.roundToInt( node.getYcoord() - d ) );
2609 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ),
2610 ForesterUtil.roundToInt( node.getYcoord() + d ) );
2611 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
2613 g.fillPolygon( _polygon );
2615 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
2616 g.setColor( getBackground() );
2617 g.fillPolygon( _polygon );
2619 g.drawPolygon( _polygon );
2621 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2622 g.setPaint( new GradientPaint( node.getXcoord() - box_size, node.getYcoord(), getBackground(), ( node
2623 .getXcoord() + box_size ), ( float ) ( node.getYcoord() - d ), c, false ) );
2628 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
2632 final public void paintComponent( final Graphics g ) {
2633 // Dimension currentSize = getSize();
2634 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
2635 // call the 'java.awt.Component.createImage(...)' method to get an
2637 // offscreenImage = createImage( currentSize.width, currentSize.height );
2638 // offscreenGraphics = offscreenImage.getGraphics();
2639 // offscreenDimension = currentSize;
2641 // super.paintComponent( g ); //why?
2642 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
2643 final Graphics2D g2d = ( Graphics2D ) g;
2644 g2d.setRenderingHints( _rendering_hints );
2645 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
2646 //g.drawImage( offscreenImage, 0, 0, this );
2650 public void update( final Graphics g ) {
2654 final private void paintConfidenceValues( final Graphics2D g,
2655 final PhylogenyNode node,
2656 final boolean to_pdf,
2657 final boolean to_graphics_file ) {
2658 String conf_str = "";
2659 final List<Confidence> confidences = node.getBranchData().getConfidences();
2660 if ( confidences.size() == 1 ) {
2661 final double value = node.getBranchData().getConfidence( 0 ).getValue();
2662 if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
2665 conf_str = FORMATTER_CONFIDENCE.format( value );
2667 else if ( confidences.size() > 1 ) {
2668 boolean one_ok = false;
2669 boolean not_first = false;
2670 Collections.sort( confidences );
2671 final StringBuilder sb = new StringBuilder();
2672 for( final Confidence confidence : confidences ) {
2673 final double value = confidence.getValue();
2674 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2675 if ( value >= getOptions().getMinConfidenceValue() ) {
2684 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
2685 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2689 conf_str = sb.toString();
2692 if ( conf_str.length() > 0 ) {
2693 final double parent_x = node.getParent().getXcoord();
2694 double x = node.getXcoord();
2695 g.setFont( getTreeFontSet().getSmallFont() );
2696 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2699 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2702 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2703 g.setColor( Color.BLACK );
2706 g.setColor( getTreeColorSet().getConfidenceColor() );
2709 .drawString( conf_str,
2711 + ( ( x - parent_x - getTreeFontSet()._fm_small.stringWidth( conf_str ) ) / 2 ),
2712 ( node.getYcoord() + getTreeFontSet()._small_max_ascent ) - 1,
2717 final private void paintFoundNode( final int x, final int y, final Graphics2D g ) {
2718 final int box_size = getOptions().getDefaultNodeShapeSize();
2719 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
2720 g.setColor( getTreeColorSet().getFoundColor() );
2721 g.fillRect( x - half_box_size, y - half_box_size, box_size, box_size );
2724 final private void paintGainedAndLostCharacters( final Graphics2D g,
2725 final PhylogenyNode node,
2726 final String gained,
2727 final String lost ) {
2728 if ( node.getParent() != null ) {
2729 final double parent_x = node.getParent().getXcoord();
2730 final double x = node.getXcoord();
2731 g.setFont( getTreeFontSet().getLargeFont() );
2732 g.setColor( getTreeColorSet().getGainedCharactersColor() );
2733 if ( Constants.SPECIAL_CUSTOM ) {
2734 g.setColor( Color.BLUE );
2737 .drawString( gained,
2738 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( gained ) ) / 2 ),
2739 ( node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent() ),
2741 g.setColor( getTreeColorSet().getLostCharactersColor() );
2742 TreePanel.drawString( lost,
2743 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( lost ) ) / 2 ),
2744 ( node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent() ),
2750 * Draw a box at the indicated node.
2757 final private void paintNodeBox( final double x,
2759 final PhylogenyNode node,
2761 final boolean to_pdf,
2762 final boolean to_graphics_file,
2763 final boolean is_in_found_nodes ) {
2764 if ( node.isCollapse() ) {
2767 // if this node should be highlighted, do so
2768 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
2769 g.setColor( getTreeColorSet().getFoundColor() );
2770 drawOval( x - 8, y - 8, 16, 16, g );
2771 drawOval( x - 9, y - 8, 17, 17, g );
2772 drawOval( x - 9, y - 9, 18, 18, g );
2774 if ( is_in_found_nodes ) {
2775 paintFoundNode( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ), g );
2778 Color outline_color = null;
2779 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2780 outline_color = Color.BLACK;
2782 else if ( getControlPanel().isEvents() && Util.isHasAssignedEvent( node ) ) {
2783 final Event event = node.getNodeData().getEvent();
2784 if ( event.isDuplication() ) {
2785 outline_color = getTreeColorSet().getDuplicationBoxColor();
2787 else if ( event.isSpeciation() ) {
2788 outline_color = getTreeColorSet().getSpecBoxColor();
2790 else if ( event.isSpeciationOrDuplication() ) {
2791 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
2794 else if ( getOptions().isTaxonomyColorizeNodeShapes() ) {
2795 outline_color = getTaxonomyBasedColor( node );
2798 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
2799 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
2800 outline_color = getTreeColorSet().getBranchColorForPdf();
2803 final int box_size = getOptions().getDefaultNodeShapeSize();
2804 final int half_box_size = box_size / 2;
2805 if ( getOptions().isShowDefaultNodeShapes() || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) {
2806 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
2807 if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2808 drawOvalGradient( x - half_box_size,
2813 to_pdf ? Color.WHITE : outline_color,
2814 to_pdf ? outline_color : getBackground(),
2817 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
2818 Color background = getBackground();
2820 background = Color.WHITE;
2822 drawOvalGradient( x - half_box_size,
2831 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
2832 g.setColor( outline_color );
2833 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2836 else if ( getOptions().getDefaultNodeShape() == NodeVisualization.NodeShape.RECTANGLE ) {
2837 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.GRADIENT ) {
2838 drawRectGradient( x - half_box_size,
2843 to_pdf ? Color.WHITE : outline_color,
2844 to_pdf ? outline_color : getBackground(),
2847 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
2848 Color background = getBackground();
2850 background = Color.WHITE;
2852 drawRectGradient( x - half_box_size,
2861 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
2862 g.setColor( outline_color );
2863 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2870 final private void paintNodeData( final Graphics2D g,
2871 final PhylogenyNode node,
2872 final boolean to_graphics_file,
2873 final boolean to_pdf,
2874 final boolean is_in_found_nodes ) {
2875 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
2878 if ( getOptions().isShowBranchLengthValues()
2879 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2880 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
2881 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) ) {
2882 paintBranchLength( g, node, to_pdf, to_graphics_file );
2884 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
2888 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
2889 if ( getControlPanel().isShowTaxonomyImages()
2890 && ( getImageMap() != null )
2891 && !getImageMap().isEmpty()
2892 && node.getNodeData().isHasTaxonomy()
2893 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
2894 .getUris().isEmpty() ) ) {
2895 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
2897 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
2898 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
2899 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
2901 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2902 g.setColor( Color.BLACK );
2904 else if ( is_in_found_nodes ) {
2905 g.setColor( getTreeColorSet().getFoundColor() );
2907 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2908 g.setColor( getTaxonomyBasedColor( node ) );
2910 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
2911 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2912 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2914 else if ( to_pdf ) {
2915 g.setColor( Color.BLACK );
2918 g.setColor( getTreeColorSet().getSequenceColor() );
2921 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
2923 _sb.append( node.getAllExternalDescendants().size() );
2926 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
2927 if ( _sb.length() > 0 ) {
2930 _sb.append( node.getName() );
2932 if ( node.getNodeData().isHasSequence() ) {
2933 if ( getControlPanel().isShowGeneSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
2934 if ( _sb.length() > 0 ) {
2937 _sb.append( node.getNodeData().getSequence().getSymbol() );
2939 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
2940 if ( _sb.length() > 0 ) {
2943 _sb.append( node.getNodeData().getSequence().getName() );
2945 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
2946 if ( _sb.length() > 0 ) {
2949 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
2950 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
2953 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
2956 g.setFont( getTreeFontSet().getLargeFont() );
2957 if ( is_in_found_nodes ) {
2958 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
2960 double down_shift_factor = 3.0;
2961 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
2962 down_shift_factor = 1;
2964 final double pos_x = node.getXcoord() + x + 2 + half_box_size;
2965 final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
2966 final String sb_str = _sb.toString();
2967 // GUILHEM_BEG ______________
2968 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
2969 && ( _query_sequence != null ) ) {
2970 int nodeTextBoundsWidth = 0;
2971 if ( sb_str.length() > 0 ) {
2972 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
2973 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
2975 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
2976 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
2977 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
2978 g.setColor( getTreeColorSet().getBackgroundColor() );
2982 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
2983 for( final SequenceRelation seqRelation : seqRelations ) {
2984 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
2985 .getRef1().isEqual( _query_sequence ) )
2986 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
2987 .getSelectedItem() );
2988 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
2989 final double linePosX = node.getXcoord() + 2 + half_box_size;
2990 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
2991 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
2993 if ( sConfidence != null ) {
2994 double confidenceX = pos_x;
2995 if ( sb_str.length() > 0 ) {
2996 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
2997 + CONFIDENCE_LEFT_MARGIN;
2999 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
3000 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
3001 .getBounds().getWidth();
3002 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
3003 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
3006 if ( x + nodeTextBoundsWidth > 0 ) /* we only underline if there is something displayed */
3008 if ( nodeTextBoundsWidth == 0 ) {
3009 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
3012 nodeTextBoundsWidth += 2;
3014 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
3015 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
3022 if ( sb_str.length() > 0 ) {
3023 TreePanel.drawString( sb_str, pos_x, pos_y, g );
3025 // GUILHEM_END _____________
3026 // COMMENTED_OUT_BY_GUILHEM_BEG _______________
3027 // TODO FIXME need to check this one!
3028 //if ( _sb.length() > 0 ) {
3029 // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
3030 // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3032 // COMMENTED_OUT_BY_GUILHEM_END ________________
3033 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
3034 && ( node.getNodeData().getSequence().getAnnotations() != null )
3035 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
3036 if ( _sb.length() > 0 ) {
3037 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
3039 final Annotation ann = node.getNodeData().getSequence().getAnnotation( 0 );
3040 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3041 g.setColor( Color.BLACK );
3044 g.setColor( calculateColorForAnnotation( ann ) );
3046 final String ann_str = ann.asSimpleText().toString();
3047 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
3048 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3050 _sb.append( ann_str );
3052 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3053 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
3054 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3055 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
3056 && node.getNodeData().isHasBinaryCharacters() ) {
3057 if ( _sb.length() > 0 ) {
3058 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
3060 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3061 g.setColor( Color.BLACK );
3064 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
3066 if ( getControlPanel().isShowBinaryCharacters() ) {
3067 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
3068 .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord()
3069 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3070 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
3071 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
3072 .getLostCharactersAsStringBuffer().toString() );
3075 if ( DRAW_MEAN_COUNTS && node.isInternal() ) {
3076 final List<PhylogenyNode> ec = node.getAllExternalDescendants();
3079 for( final PhylogenyNode phylogenyNode : ec ) {
3081 if ( phylogenyNode.getNodeData().getBinaryCharacters() != null ) {
3082 sum += phylogenyNode.getNodeData().getBinaryCharacters().getPresentCount();
3085 final double mean = ForesterUtil.round( sum / count, 1 );
3086 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount() + " ["
3087 + mean + "]", node.getXcoord() + x + 4 + half_box_size, node.getYcoord()
3088 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3091 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
3092 node.getXcoord() + x + 4 + half_box_size,
3094 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ),
3097 paintGainedAndLostCharacters( g, node, "+"
3098 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
3099 + node.getNodeData().getBinaryCharacters().getLostCount() );
3105 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
3106 final List<Uri> us = new ArrayList<Uri>();
3107 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
3108 for( final Uri uri : t.getUris() ) {
3113 for( final Uri uri : us ) {
3114 if ( uri != null ) {
3115 final String uri_str = uri.getValue().toString().toLowerCase();
3116 if ( getImageMap().containsKey( uri_str ) ) {
3117 final BufferedImage bi = getImageMap().get( uri_str );
3118 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
3119 double scaling_factor = 1;
3120 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
3121 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
3122 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
3124 // y = y - ( 0.9 * getYdistance() );
3125 final double hs = bi.getHeight() * scaling_factor;
3126 double ws = bi.getWidth() * scaling_factor + offset;
3127 final double my_y = y - ( 0.5 * hs );
3128 final int x_w = ( int ) ( x + ws + 0.5 );
3129 final int y_h = ( int ) ( my_y + hs + 0.5 );
3130 if ( ( x_w - x > 7 ) && ( y_h - my_y > 7 ) ) {
3132 ( int ) ( x + 0.5 + offset ),
3133 ( int ) ( my_y + 0.5 ),
3154 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
3155 final PhylogenyNode node,
3156 final boolean to_pdf,
3157 final boolean to_graphics_file,
3158 final boolean radial_labels,
3159 final double ur_angle,
3160 final boolean is_in_found_nodes ) {
3161 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
3164 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3165 g.setColor( Color.BLACK );
3167 else if ( is_in_found_nodes ) {
3168 g.setColor( getTreeColorSet().getFoundColor() );
3170 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3171 g.setColor( getTaxonomyBasedColor( node ) );
3174 g.setColor( getTreeColorSet().getSequenceColor() );
3178 if ( node.getNodeData().isHasTaxonomy()
3179 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
3180 .isShowTaxonomyCommonNames() ) ) {
3181 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3182 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3183 _sb.append( taxonomy.getTaxonomyCode() );
3186 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3187 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3188 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3189 _sb.append( taxonomy.getScientificName() );
3191 _sb.append( taxonomy.getCommonName() );
3194 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3195 _sb.append( taxonomy.getScientificName() );
3198 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3199 _sb.append( taxonomy.getCommonName() );
3203 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3204 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3205 _sb.append( taxonomy.getScientificName() );
3209 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3210 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3211 _sb.append( taxonomy.getCommonName() );
3216 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3218 _sb.append( node.getAllExternalDescendants().size() );
3221 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3222 if ( _sb.length() > 0 ) {
3225 _sb.append( node.getName() );
3227 if ( node.getNodeData().isHasSequence() ) {
3228 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3229 if ( _sb.length() > 0 ) {
3232 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3233 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3236 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3238 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3239 if ( _sb.length() > 0 ) {
3242 _sb.append( node.getNodeData().getSequence().getName() );
3245 g.setFont( getTreeFontSet().getLargeFont() );
3246 if ( is_in_found_nodes ) {
3247 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3249 if ( _sb.length() > 1 ) {
3250 final String sb_str = _sb.toString();
3252 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3253 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
3256 m = ( float ) ( ur_angle % TWO_PI );
3258 _at = g.getTransform();
3259 boolean need_to_reset = false;
3260 final float x_coord = node.getXcoord();
3261 final float y_coord = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / 3.0f );
3262 if ( radial_labels ) {
3263 need_to_reset = true;
3264 boolean left = false;
3265 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3269 g.rotate( m, x_coord, node.getYcoord() );
3271 g.translate( -( getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth() ), 0 );
3275 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3276 need_to_reset = true;
3277 g.translate( -getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth(), 0 );
3280 TreePanel.drawString( sb_str, x_coord, y_coord, g );
3281 if ( need_to_reset ) {
3282 g.setTransform( _at );
3287 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
3288 if ( node.isCollapse() ) {
3289 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
3290 paintCollapsedNode( g, node, false, false, false );
3294 if ( isInFoundNodes( node ) ) {
3295 g.setColor( getTreeColorSet().getFoundColor() );
3296 drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
3299 if ( !node.isExternal() && !node.isCollapse() ) {
3300 boolean first_child = true;
3302 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3303 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3304 final PhylogenyNode child_node = node.getChildNode( i );
3306 if ( !isUniformBranchLengthsForCladogram() ) {
3307 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3310 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
3312 if ( first_child ) {
3313 first_child = false;
3314 y2 = node.getYSecondary()
3315 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
3316 .getNumberOfExternalNodes() ) );
3319 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3321 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
3322 new_x = x2 + node.getXSecondary();
3323 final float diff_y = node.getYSecondary() - y2;
3324 final float diff_x = node.getXSecondary() - new_x;
3325 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
3326 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
3328 child_node.setXSecondary( new_x );
3329 child_node.setYSecondary( y2 );
3330 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3335 final private void paintNodeRectangular( final Graphics2D g,
3336 final PhylogenyNode node,
3337 final boolean to_pdf,
3338 final boolean dynamically_hide,
3339 final int dynamic_hiding_factor,
3340 final boolean to_graphics_file ) {
3341 final boolean is_in_found_nodes = isInFoundNodes( node );
3342 if ( node.isCollapse() ) {
3343 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
3344 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3348 if ( node.isExternal() ) {
3349 ++_external_node_index;
3351 // Confidence values
3352 if ( getControlPanel().isShowBootstrapValues()
3353 && !node.isExternal()
3355 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
3356 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3357 && node.getBranchData().isHasConfidences() ) {
3358 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
3360 // Draw a line to root:
3361 if ( node.isRoot() && _phylogeny.isRooted() ) {
3362 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
3365 float new_x_min = Float.MAX_VALUE;
3366 final boolean disallow_shortcutting = dynamic_hiding_factor < 40;
3367 float min_dist = 1.5f;
3368 if ( !disallow_shortcutting ) {
3369 // System.out.println( dynamic_hiding_factor );
3370 if ( dynamic_hiding_factor > 4000 ) {
3373 else if ( dynamic_hiding_factor > 1000 ) {
3376 else if ( dynamic_hiding_factor > 100 ) {
3380 if ( !node.isExternal() && !node.isCollapse() ) {
3381 boolean first_child = true;
3383 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3384 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3385 final PhylogenyNode child_node = node.getChildNode( i );
3387 if ( !isUniformBranchLengthsForCladogram() ) {
3388 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3391 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
3393 if ( first_child ) {
3394 first_child = false;
3395 y2 = node.getYcoord()
3396 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3399 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3401 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
3402 new_x = x2 + node.getXcoord();
3403 if ( dynamically_hide && ( x2 < new_x_min ) ) {
3406 final float diff_y = node.getYcoord() - y2;
3407 final float diff_x = node.getXcoord() - new_x;
3408 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
3409 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
3410 paintBranchRectangular( g,
3419 child_node.setXcoord( new_x );
3420 child_node.setYcoord( y2 );
3421 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3423 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
3425 if ( dynamically_hide
3426 && !is_in_found_nodes
3427 && ( ( node.isExternal() && ( _external_node_index % dynamic_hiding_factor != 1 ) ) || ( !node
3428 .isExternal() && ( ( new_x_min < 20 ) || ( _y_distance * node.getNumberOfExternalNodes() < getTreeFontSet()._fm_large
3429 .getHeight() ) ) ) ) ) {
3432 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3433 paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
3436 final private void paintNodeWithRenderableData( final Graphics2D g,
3437 final PhylogenyNode node,
3438 final boolean to_graphics_file,
3439 final boolean to_pdf ) {
3440 if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
3443 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
3446 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3447 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
3448 RenderableDomainArchitecture rds = null;
3449 if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
3451 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
3453 catch ( final ClassCastException cce ) {
3454 cce.printStackTrace();
3457 rds.setRenderingHeight( 6 );
3459 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( node ).length() > 0 ) ) {
3460 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( node ) + " " );
3462 if ( getControlPanel().isShowGeneNames() ) {
3463 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
3465 if ( getControlPanel().isShowGeneSymbols() ) {
3466 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
3468 if ( getControlPanel().isShowSequenceAcc() ) {
3469 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
3473 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3474 x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
3476 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
3480 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
3481 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
3482 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
3483 getStatisticsForExpressionValues(),
3484 getConfiguration() );
3486 PhylogenyNode my_node = node;
3487 if ( !getControlPanel().isDrawPhylogram() ) {
3488 my_node = getPhylogeny().getFirstExternalNode();
3490 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
3491 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
3493 if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
3494 x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
3496 rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
3501 final private void paintOvRectangle( final Graphics2D g ) {
3502 final float w_ratio = ( float ) getWidth() / getVisibleRect().width;
3503 final float h_ratio = ( float ) getHeight() / getVisibleRect().height;
3504 final float x_ratio = ( float ) getWidth() / getVisibleRect().x;
3505 final float y_ratio = ( float ) getHeight() / getVisibleRect().y;
3506 final float width = getOvMaxWidth() / w_ratio;
3507 final float height = getOvMaxHeight() / h_ratio;
3508 final float x = getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / x_ratio;
3509 final float y = getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / y_ratio;
3510 g.setColor( getTreeColorSet().getFoundColor() );
3511 getOvRectangle().setRect( x, y, width, height );
3512 if ( ( width < 6 ) && ( height < 6 ) ) {
3513 drawRectFilled( x, y, 6, 6, g );
3514 getOvVirtualRectangle().setRect( x, y, 6, 6 );
3516 else if ( width < 6 ) {
3517 drawRectFilled( x, y, 6, height, g );
3518 getOvVirtualRectangle().setRect( x, y, 6, height );
3520 else if ( height < 6 ) {
3521 drawRectFilled( x, y, width, 6, g );
3522 getOvVirtualRectangle().setRect( x, y, width, 6 );
3525 drawRect( x, y, width, height, g );
3526 if ( isInOvRect() ) {
3527 drawRect( x + 1, y + 1, width - 2, height - 2, g );
3529 getOvVirtualRectangle().setRect( x, y, width, height );
3533 final void paintPhylogeny( final Graphics2D g,
3534 final boolean to_pdf,
3535 final boolean to_graphics_file,
3536 final int graphics_file_width,
3537 final int graphics_file_height,
3538 final int graphics_file_x,
3539 final int graphics_file_y ) {
3540 if ( _control_panel.isShowSequenceRelations() ) {
3541 _query_sequence = _control_panel.getSelectedQuerySequence();
3543 // Color the background
3545 final Rectangle r = getVisibleRect();
3546 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
3547 g.setColor( getTreeColorSet().getBackgroundColor() );
3548 if ( !to_graphics_file ) {
3552 if ( getOptions().isPrintBlackAndWhite() ) {
3553 g.setColor( Color.WHITE );
3555 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
3559 if ( !to_graphics_file ) {
3560 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
3561 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
3565 g.setPaint( new GradientPaint( graphics_file_x,
3567 getTreeColorSet().getBackgroundColor(),
3569 graphics_file_y + graphics_file_height,
3570 getTreeColorSet().getBackgroundColorGradientBottom() ) );
3571 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
3574 g.setStroke( new BasicStroke( 1 ) );
3577 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
3579 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3580 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3581 _external_node_index = 0;
3582 // Position starting X of tree
3583 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
3584 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
3586 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
3587 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
3588 .getDistanceToParent() * getXcorrectionFactor() ) ) );
3591 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
3593 // Position starting Y of tree
3594 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
3595 + ( TreePanel.MOVE / 2.0f ) );
3596 final int dynamic_hiding_factor = ( int ) ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) );
3597 if ( getControlPanel().isDynamicallyHideData() ) {
3598 if ( dynamic_hiding_factor > 1 ) {
3599 getControlPanel().setDynamicHidingIsOn( true );
3602 getControlPanel().setDynamicHidingIsOn( false );
3605 if ( _nodes_in_preorder == null ) {
3606 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
3608 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3609 _nodes_in_preorder[ i++ ] = it.next();
3612 //final PhylogenyNodeIterator it;
3613 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3614 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
3615 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
3617 for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
3618 paintNodeRectangular( g, _nodes_in_preorder[ i ], to_pdf, getControlPanel().isDynamicallyHideData()
3619 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
3621 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
3622 if ( !( to_graphics_file || to_pdf ) ) {
3625 getVisibleRect().y + getVisibleRect().height,
3630 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
3633 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3634 paintPhylogenyLite( g );
3637 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3638 if ( getControlPanel().getDynamicallyHideData() != null ) {
3639 getControlPanel().setDynamicHidingIsOn( false );
3641 final double angle = getStartingAngle();
3642 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
3643 _dynamic_hiding_factor = 0;
3644 if ( getControlPanel().isDynamicallyHideData() ) {
3645 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
3646 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
3648 if ( getControlPanel().getDynamicallyHideData() != null ) {
3649 if ( _dynamic_hiding_factor > 1 ) {
3650 getControlPanel().setDynamicHidingIsOn( true );
3653 getControlPanel().setDynamicHidingIsOn( false );
3656 paintUnrooted( _phylogeny.getRoot(),
3658 ( float ) ( angle + 2 * Math.PI ),
3663 if ( getOptions().isShowScale() ) {
3664 if ( !( to_graphics_file || to_pdf ) ) {
3667 getVisibleRect().y + getVisibleRect().height,
3672 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
3675 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3676 g.setColor( getTreeColorSet().getOvColor() );
3677 paintUnrootedLite( _phylogeny.getRoot(),
3679 angle + 2 * Math.PI,
3681 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
3682 paintOvRectangle( g );
3685 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3686 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
3687 final int d = radius + MOVE + getLongestExtNodeInfo();
3688 _dynamic_hiding_factor = 0;
3689 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
3690 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
3691 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
3693 if ( getControlPanel().getDynamicallyHideData() != null ) {
3694 if ( _dynamic_hiding_factor > 1 ) {
3695 getControlPanel().setDynamicHidingIsOn( true );
3698 getControlPanel().setDynamicHidingIsOn( false );
3701 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
3702 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3703 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
3704 : getOvMaxWidth() / 2 );
3705 double x_scale = 1.0;
3706 double y_scale = 1.0;
3707 int x_pos = getVisibleRect().x + getOvXPosition();
3708 int y_pos = getVisibleRect().y + getOvYPosition();
3709 if ( getWidth() > getHeight() ) {
3710 x_scale = ( double ) getHeight() / getWidth();
3711 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
3714 y_scale = ( double ) getWidth() / getHeight();
3715 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
3717 _at = g.getTransform();
3718 g.scale( x_scale, y_scale );
3719 paintCircularLite( _phylogeny,
3723 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
3726 g.setTransform( _at );
3727 paintOvRectangle( g );
3732 final private void paintPhylogenyLite( final Graphics2D g ) {
3733 //System.out.println( getVisibleRect().x + " " + getVisibleRect().y );
3736 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
3737 .getWidth() ) ) ) );
3738 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
3739 //final PhylogenyNodeIterator it;
3740 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3741 // paintNodeLite( g, it.next() );
3743 for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
3744 paintNodeLite( g, _nodes_in_preorder[ i ] );
3746 paintOvRectangle( g );
3750 * Paint the root branch. (Differs from others because it will always be a
3751 * single horizontal line).
3752 * @param to_graphics_file
3754 * @return new x1 value
3756 final private void paintRootBranch( final Graphics2D g,
3759 final PhylogenyNode root,
3760 final boolean to_pdf,
3761 final boolean to_graphics_file ) {
3762 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
3763 float d = getXdistance();
3764 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
3765 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
3767 if ( d < MIN_ROOT_LENGTH ) {
3768 d = MIN_ROOT_LENGTH;
3770 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
3771 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
3774 final double w = PhylogenyMethods.getBranchWidthValue( root );
3775 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
3777 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file, isInFoundNodes( root ) );
3780 final private void paintScale( final Graphics2D g,
3783 final boolean to_pdf,
3784 final boolean to_graphics_file ) {
3786 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
3788 final int y2 = y1 - 8;
3789 final int y3 = y1 - 4;
3790 g.setFont( getTreeFontSet().getSmallFont() );
3791 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3792 g.setColor( Color.BLACK );
3795 g.setColor( getTreeColorSet().getBranchLengthColor() );
3797 drawLine( x1, y1, x1, y2, g );
3798 drawLine( x2, y1, x2, y2, g );
3799 drawLine( x1, y3, x2, y3, g );
3800 if ( getScaleLabel() != null ) {
3801 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
3805 final private int paintTaxonomy( final Graphics2D g,
3806 final PhylogenyNode node,
3807 final boolean is_in_found_nodes,
3808 final boolean to_pdf,
3809 final boolean to_graphics_file,
3810 final double x_shift ) {
3811 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3812 g.setFont( getTreeFontSet().getLargeItalicFont() );
3813 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3814 g.setColor( Color.BLACK );
3816 else if ( is_in_found_nodes ) {
3817 g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
3818 g.setColor( getTreeColorSet().getFoundColor() );
3820 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3821 g.setColor( getTaxonomyBasedColor( node ) );
3823 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3824 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3825 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3827 else if ( to_pdf ) {
3828 g.setColor( Color.BLACK );
3831 g.setColor( getTreeColorSet().getTaxonomyColor() );
3833 final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
3834 final double start_y = node.getYcoord()
3835 + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
3837 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3838 _sb.append( taxonomy.getTaxonomyCode() );
3841 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3842 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3843 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3844 if ( getOptions().isAbbreviateScientificTaxonNames()
3845 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3846 abbreviateScientificName( taxonomy.getScientificName() );
3849 _sb.append( taxonomy.getScientificName() );
3852 _sb.append( taxonomy.getCommonName() );
3855 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3856 if ( getOptions().isAbbreviateScientificTaxonNames()
3857 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3858 abbreviateScientificName( taxonomy.getScientificName() );
3861 _sb.append( taxonomy.getScientificName() );
3865 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3866 _sb.append( taxonomy.getCommonName() );
3870 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3871 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3872 if ( getOptions().isAbbreviateScientificTaxonNames()
3873 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3874 abbreviateScientificName( taxonomy.getScientificName() );
3877 _sb.append( taxonomy.getScientificName() );
3882 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3883 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3884 _sb.append( taxonomy.getCommonName() );
3888 final String label = _sb.toString();
3890 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
3891 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
3892 // invert font color and background color to show that this is the query sequence
3893 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
3897 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
3898 g.setColor( getTreeColorSet().getBackgroundColor() );
3901 TreePanel.drawString( label, start_x, start_y, g );
3902 if ( is_in_found_nodes ) {
3903 return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
3906 return getTreeFontSet()._fm_large_italic.stringWidth( label );
3910 private void abbreviateScientificName( final String sn ) {
3911 final String[] a = sn.split( "\\s+" );
3912 _sb.append( a[ 0 ].substring( 0, 1 ) );
3913 _sb.append( a[ 1 ].substring( 0, 2 ) );
3914 if ( a.length > 2 ) {
3915 for( int i = 2; i < a.length; i++ ) {
3917 _sb.append( a[ i ] );
3922 final private void paintUnrooted( final PhylogenyNode n,
3923 final double low_angle,
3924 final double high_angle,
3925 final boolean radial_labels,
3927 final boolean to_pdf,
3928 final boolean to_graphics_file ) {
3930 n.setXcoord( getWidth() / 2 );
3931 n.setYcoord( getHeight() / 2 );
3933 if ( n.isExternal() ) {
3934 paintNodeDataUnrootedCirc( g,
3939 ( high_angle + low_angle ) / 2,
3940 isInFoundNodes( n ) );
3943 final float num_enclosed = n.getNumberOfExternalNodes();
3944 final float x = n.getXcoord();
3945 final float y = n.getYcoord();
3946 double current_angle = low_angle;
3947 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
3948 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
3949 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
3950 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
3951 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3952 final PhylogenyNode desc = n.getChildNode( i );
3953 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
3954 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
3955 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
3956 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
3959 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
3962 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
3965 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3966 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3968 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3969 if ( desc.getDistanceToParent() < 0 ) {
3973 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
3977 length = getUrtFactor();
3979 final double mid_angle = current_angle + arc_size / 2;
3980 final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length );
3981 final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length );
3982 desc.setXcoord( new_x );
3983 desc.setYcoord( new_y );
3984 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
3985 current_angle += arc_size;
3986 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
3987 drawLine( x, y, new_x, new_y, g );
3988 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc ) );
3991 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file, isInFoundNodes( n ) );
3995 final private void paintUnrootedLite( final PhylogenyNode n,
3996 final double low_angle,
3997 final double high_angle,
3999 final float urt_ov_factor ) {
4001 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / 2 );
4002 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / 2 );
4003 n.setXSecondary( x_pos );
4004 n.setYSecondary( y_pos );
4006 if ( n.isExternal() ) {
4009 final float num_enclosed = n.getNumberOfExternalNodes();
4010 final float x = n.getXSecondary();
4011 final float y = n.getYSecondary();
4012 double current_angle = low_angle;
4013 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4014 final PhylogenyNode desc = n.getChildNode( i );
4015 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4016 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4018 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4019 if ( desc.getDistanceToParent() < 0 ) {
4023 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
4027 length = urt_ov_factor;
4029 final double mid_angle = current_angle + arc_size / 2;
4030 final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length );
4031 final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length );
4032 desc.setXSecondary( new_x );
4033 desc.setYSecondary( new_y );
4034 if ( isInFoundNodes( desc ) ) {
4035 g.setColor( getTreeColorSet().getFoundColor() );
4036 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
4037 g.setColor( getTreeColorSet().getOvColor() );
4039 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
4040 current_angle += arc_size;
4041 drawLine( x, y, new_x, new_y, g );
4045 final private void pasteSubtree( final PhylogenyNode node ) {
4046 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4047 errorMessageNoCutCopyPasteInUnrootedDisplay();
4050 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
4051 JOptionPane.showMessageDialog( this,
4052 "No tree in buffer (need to copy or cut a subtree first)",
4053 "Attempt to paste with empty buffer",
4054 JOptionPane.ERROR_MESSAGE );
4057 final String label = getASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
4058 final Object[] options = { "As sibling", "As descendant", "Cancel" };
4059 final int r = JOptionPane.showOptionDialog( this,
4060 "How to paste subtree" + label + "?",
4062 JOptionPane.CLOSED_OPTION,
4063 JOptionPane.QUESTION_MESSAGE,
4067 boolean paste_as_sibling = true;
4069 paste_as_sibling = false;
4071 else if ( r != 0 ) {
4074 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
4075 buffer_phy.setAllNodesToNotCollapse();
4076 buffer_phy.preOrderReId();
4077 buffer_phy.setRooted( true );
4078 boolean need_to_show_whole = false;
4079 if ( paste_as_sibling ) {
4080 if ( node.isRoot() ) {
4081 JOptionPane.showMessageDialog( this,
4082 "Cannot paste sibling to root",
4083 "Attempt to paste sibling to root",
4084 JOptionPane.ERROR_MESSAGE );
4087 buffer_phy.addAsSibling( node );
4090 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
4091 need_to_show_whole = true;
4092 _phylogeny = buffer_phy;
4095 buffer_phy.addAsChild( node );
4098 if ( getCopiedAndPastedNodes() == null ) {
4099 setCopiedAndPastedNodes( new HashSet<Integer>() );
4101 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
4102 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
4103 for( final PhylogenyNode n : nodes ) {
4104 node_ids.add( n.getId() );
4106 node_ids.add( node.getId() );
4107 getCopiedAndPastedNodes().addAll( node_ids );
4108 _nodes_in_preorder = null;
4109 _phylogeny.externalNodesHaveChanged();
4110 _phylogeny.hashIDs();
4111 _phylogeny.recalculateNumberOfExternalDescendants( true );
4112 resetNodeIdToDistToLeafMap();
4114 if ( need_to_show_whole ) {
4115 getControlPanel().showWhole();
4120 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
4121 throws PrinterException {
4122 if ( page_index > 0 ) {
4123 return ( NO_SUCH_PAGE );
4126 final Graphics2D g2d = ( Graphics2D ) g;
4127 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
4128 // Turn off double buffering !?
4129 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
4130 // Turn double buffering back on !?
4131 return ( PAGE_EXISTS );
4135 final void recalculateMaxDistanceToRoot() {
4136 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
4140 * Remove all edit-node frames
4142 final void removeAllEditNodeJFrames() {
4143 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
4144 if ( _node_frames[ i ] != null ) {
4145 _node_frames[ i ].dispose();
4146 _node_frames[ i ] = null;
4149 _node_frame_index = 0;
4153 * Remove a node-edit frame.
4155 final void removeEditNodeFrame( final int i ) {
4156 _node_frame_index--;
4157 _node_frames[ i ] = null;
4158 if ( i < _node_frame_index ) {
4159 for( int j = 0; j < _node_frame_index - 1; j++ ) {
4160 _node_frames[ j ] = _node_frames[ j + 1 ];
4162 _node_frames[ _node_frame_index ] = null;
4166 final void reRoot( final PhylogenyNode node ) {
4167 if ( !getPhylogeny().isRerootable() ) {
4168 JOptionPane.showMessageDialog( this,
4169 "This is not rerootable",
4171 JOptionPane.WARNING_MESSAGE );
4174 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4175 JOptionPane.showMessageDialog( this,
4176 "Cannot reroot in unrooted display type",
4177 "Attempt to reroot tree in unrooted display",
4178 JOptionPane.WARNING_MESSAGE );
4181 getPhylogeny().reRoot( node );
4182 getPhylogeny().recalculateNumberOfExternalDescendants( true );
4183 resetNodeIdToDistToLeafMap();
4184 _nodes_in_preorder = null;
4185 resetPreferredSize();
4186 getMainPanel().adjustJScrollPane();
4188 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4189 getControlPanel().showWhole();
4193 final void resetNodeIdToDistToLeafMap() {
4194 _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
4197 final void resetPreferredSize() {
4198 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
4204 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
4205 if ( getControlPanel().isDrawPhylogram() ) {
4207 + getLongestExtNodeInfo()
4209 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
4212 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4214 + getLongestExtNodeInfo()
4215 + ForesterUtil.roundToInt( getXdistance()
4216 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
4220 + getLongestExtNodeInfo()
4221 + ForesterUtil.roundToInt( getXdistance()
4222 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
4225 setPreferredSize( new Dimension( x, y ) );
4228 public final void setArrowCursor() {
4229 setCursor( ARROW_CURSOR );
4233 final void setControlPanel( final ControlPanel atv_control ) {
4234 _control_panel = atv_control;
4237 final private void setCopiedAndPastedNodes( final Set<Integer> nodeIds ) {
4238 getMainPanel().setCopiedAndPastedNodes( nodeIds );
4241 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
4242 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
4245 public final void setEdited( final boolean edited ) {
4249 final void setFoundNodes( final Set<Integer> found_nodes ) {
4250 _found_nodes = found_nodes;
4253 final private void setInOv( final boolean in_ov ) {
4257 final void setInOvRect( final boolean in_ov_rect ) {
4258 _in_ov_rect = in_ov_rect;
4261 final void setLargeFonts() {
4262 getTreeFontSet().largeFonts();
4265 final void setLastMouseDragPointX( final float x ) {
4266 _last_drag_point_x = x;
4269 final void setLastMouseDragPointY( final float y ) {
4270 _last_drag_point_y = y;
4273 final void setLongestExtNodeInfo( final int i ) {
4274 _longest_ext_node_info = i;
4277 final void setMediumFonts() {
4278 getTreeFontSet().mediumFonts();
4281 final private void setOvMaxHeight( final float ov_max_height ) {
4282 _ov_max_height = ov_max_height;
4285 final private void setOvMaxWidth( final float ov_max_width ) {
4286 _ov_max_width = ov_max_width;
4289 final void setOvOn( final boolean ov_on ) {
4293 final private void setOvXcorrectionFactor( final float f ) {
4294 _ov_x_correction_factor = f;
4297 final private void setOvXDistance( final float ov_x_distance ) {
4298 _ov_x_distance = ov_x_distance;
4301 final private void setOvXPosition( final int ov_x_position ) {
4302 _ov_x_position = ov_x_position;
4305 final private void setOvYDistance( final float ov_y_distance ) {
4306 _ov_y_distance = ov_y_distance;
4309 final private void setOvYPosition( final int ov_y_position ) {
4310 _ov_y_position = ov_y_position;
4313 final private void setOvYStart( final int ov_y_start ) {
4314 _ov_y_start = ov_y_start;
4318 * Set parameters for printing the displayed tree
4323 final void setParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
4324 // updateStyle(); not needed?
4325 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4327 if ( recalc_longest_ext_node_info ) {
4328 calculateLongestExtNodeInfo();
4330 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4331 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4332 if ( ext_nodes == 1 ) {
4333 ext_nodes = max_depth;
4334 if ( ext_nodes < 1 ) {
4341 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4342 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
4343 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
4346 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
4347 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
4349 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
4350 if ( xdist < 0.0 ) {
4353 if ( ov_xdist < 0.0 ) {
4356 if ( ydist < 0.0 ) {
4359 setXdistance( xdist );
4360 setYdistance( ydist );
4361 setOvXDistance( ov_xdist );
4362 final double height = _phylogeny.getHeight();
4364 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
4365 setXcorrectionFactor( corr > 0 ? corr : 0 );
4366 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
4367 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4370 setXcorrectionFactor( 0 );
4371 setOvXcorrectionFactor( 0 );
4373 _circ_max_depth = max_depth;
4378 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
4379 _graphics_type = graphics_type;
4383 final private void setScaleDistance( final double scale_distance ) {
4384 _scale_distance = scale_distance;
4387 final private void setScaleLabel( final String scale_label ) {
4388 _scale_label = scale_label;
4391 final void setSmallFonts() {
4392 getTreeFontSet().smallFonts();
4395 final void setStartingAngle( final double starting_angle ) {
4396 _urt_starting_angle = starting_angle;
4399 final void setSuperTinyFonts() {
4400 getTreeFontSet().superTinyFonts();
4403 final void setTextAntialias() {
4404 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4405 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
4406 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
4409 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
4412 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
4413 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) {
4414 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
4417 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
4420 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING,
4421 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
4423 catch ( final Throwable e ) {
4424 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
4428 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
4429 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
4433 final void setTinyFonts() {
4434 getTreeFontSet().tinyFonts();
4438 * Set a phylogeny tree.
4441 * an instance of a Phylogeny
4443 public final void setTree( final Phylogeny t ) {
4444 _nodes_in_preorder = null;
4448 final void setTreeFile( final File treefile ) {
4449 _treefile = treefile;
4452 final private void setUpUrtFactor() {
4453 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
4454 : getVisibleRect().height;
4455 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4456 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
4459 final int max_depth = _circ_max_depth;
4460 if ( max_depth > 0 ) {
4461 setUrtFactor( d / ( 2 * max_depth ) );
4464 setUrtFactor( d / 2 );
4467 setUrtFactorOv( getUrtFactor() );
4470 final private void setUrtFactor( final float urt_factor ) {
4471 _urt_factor = urt_factor;
4474 final private void setUrtFactorOv( final float urt_factor_ov ) {
4475 _urt_factor_ov = urt_factor_ov;
4478 public final void setWaitCursor() {
4479 setCursor( WAIT_CURSOR );
4483 final void setXcorrectionFactor( final float f ) {
4484 _x_correction_factor = f;
4487 final void setXdistance( final float x ) {
4491 final void setYdistance( final float y ) {
4495 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
4497 if ( ( node.getName().length() > 0 )
4498 || ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
4499 || ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) )
4500 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
4501 || node.getBranchData().isHasConfidences() ) {
4502 _popup_buffer.setLength( 0 );
4504 if ( node.getName().length() > 0 ) {
4506 _popup_buffer.append( node.getName() );
4508 if ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
4510 boolean enc_data = false;
4511 final Taxonomy tax = node.getNodeData().getTaxonomy();
4512 if ( _popup_buffer.length() > 0 ) {
4513 _popup_buffer.append( "\n" );
4515 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4516 _popup_buffer.append( "[" );
4517 _popup_buffer.append( tax.getTaxonomyCode() );
4518 _popup_buffer.append( "]" );
4521 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4523 _popup_buffer.append( " " );
4525 _popup_buffer.append( tax.getScientificName() );
4528 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
4530 _popup_buffer.append( " (" );
4533 _popup_buffer.append( "(" );
4535 _popup_buffer.append( tax.getCommonName() );
4536 _popup_buffer.append( ")" );
4539 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
4541 _popup_buffer.append( " (" );
4544 _popup_buffer.append( "(" );
4546 _popup_buffer.append( tax.getAuthority() );
4547 _popup_buffer.append( ")" );
4550 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
4552 _popup_buffer.append( " [" );
4555 _popup_buffer.append( "[" );
4557 _popup_buffer.append( tax.getRank() );
4558 _popup_buffer.append( "]" );
4561 if ( tax.getSynonyms().size() > 0 ) {
4563 _popup_buffer.append( " " );
4565 _popup_buffer.append( "[" );
4567 for( final String syn : tax.getSynonyms() ) {
4568 if ( !ForesterUtil.isEmpty( syn ) ) {
4570 _popup_buffer.append( syn );
4571 if ( counter < tax.getSynonyms().size() ) {
4572 _popup_buffer.append( ", " );
4577 _popup_buffer.append( "]" );
4580 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
4581 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
4582 _popup_buffer.append( "[" );
4583 _popup_buffer.append( tax.getIdentifier().getProvider() );
4584 _popup_buffer.append( "] " );
4586 _popup_buffer.append( tax.getIdentifier().getValue() );
4590 if ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) ) {
4592 boolean enc_data = false;
4593 if ( _popup_buffer.length() > 0 ) {
4594 _popup_buffer.append( "\n" );
4596 final Sequence seq = node.getNodeData().getSequence();
4597 if ( seq.getAccession() != null ) {
4598 _popup_buffer.append( "[" );
4599 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
4600 _popup_buffer.append( seq.getAccession().getSource() );
4601 _popup_buffer.append( ":" );
4603 _popup_buffer.append( seq.getAccession().getValue() );
4604 _popup_buffer.append( "]" );
4607 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
4609 _popup_buffer.append( " [" );
4612 _popup_buffer.append( "[" );
4614 _popup_buffer.append( seq.getSymbol() );
4615 _popup_buffer.append( "]" );
4618 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
4620 _popup_buffer.append( " " );
4622 _popup_buffer.append( seq.getName() );
4625 if ( node.getNodeData().isHasDate() ) {
4627 if ( _popup_buffer.length() > 0 ) {
4628 _popup_buffer.append( "\n" );
4630 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
4632 if ( node.getNodeData().isHasDistribution() ) {
4634 if ( _popup_buffer.length() > 0 ) {
4635 _popup_buffer.append( "\n" );
4637 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
4639 if ( node.getBranchData().isHasConfidences() ) {
4640 final List<Confidence> confs = node.getBranchData().getConfidences();
4641 for( final Confidence confidence : confs ) {
4643 if ( _popup_buffer.length() > 0 ) {
4644 _popup_buffer.append( "\n" );
4646 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
4647 _popup_buffer.append( "[" );
4648 _popup_buffer.append( confidence.getType() );
4649 _popup_buffer.append( "] " );
4652 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
4654 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4657 if ( _popup_buffer.length() > 0 ) {
4658 if ( !getConfiguration().isUseNativeUI() ) {
4660 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
4661 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
4662 if ( isInFoundNodes( node ) ) {
4663 _rollover_popup.setForeground( getTreeColorSet().getFoundColor() );
4665 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4666 _rollover_popup.setForeground( getTaxonomyBasedColor( node ) );
4669 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
4673 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
4675 _rollover_popup.setText( _popup_buffer.toString() );
4676 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
4678 e.getLocationOnScreen().x + 10,
4679 e.getLocationOnScreen().y
4681 _node_desc_popup.show();
4685 catch ( final Exception ex ) {
4690 final private void showNodeEditFrame( final PhylogenyNode n ) {
4691 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4692 // pop up edit box for single node
4693 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
4694 _node_frame_index++;
4697 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4701 final private void showNodeFrame( final PhylogenyNode n ) {
4702 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4703 // pop up edit box for single node
4704 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
4705 _node_frame_index++;
4708 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4712 final void subTree( final PhylogenyNode node ) {
4713 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4714 JOptionPane.showMessageDialog( this,
4715 "Cannot get a sub/super tree in unrooted display",
4716 "Attempt to get sub/super tree in unrooted display",
4717 JOptionPane.WARNING_MESSAGE );
4720 if ( node.isExternal() ) {
4721 JOptionPane.showMessageDialog( this,
4722 "Cannot get a subtree of a external node",
4723 "Attempt to get subtree of external node",
4724 JOptionPane.WARNING_MESSAGE );
4727 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
4728 JOptionPane.showMessageDialog( this,
4729 "Cannot get a subtree of the root node",
4730 "Attempt to get subtree of root node",
4731 JOptionPane.WARNING_MESSAGE );
4734 _nodes_in_preorder = null;
4735 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
4736 _sub_phylogenies[ _subtree_index ] = _phylogeny;
4737 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
4739 _phylogeny = subTree( node, _phylogeny );
4740 updateSubSuperTreeButton();
4742 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
4745 _main_panel.getControlPanel().showWhole();
4749 final boolean isCurrentTreeIsSubtree() {
4750 return ( _subtree_index > 0 );
4753 final private static Phylogeny subTree( final PhylogenyNode new_root, final Phylogeny source_phy ) {
4754 final Phylogeny new_phy = new Phylogeny();
4755 new_phy.setRooted( true );
4756 new_phy.setName( source_phy.getName() );
4757 new_phy.setDescription( source_phy.getDescription() );
4758 new_phy.setType( source_phy.getType() );
4759 new_phy.setDistanceUnit( source_phy.getDistanceUnit() );
4760 new_phy.setConfidence( source_phy.getConfidence() );
4761 new_phy.setIdentifier( source_phy.getIdentifier() );
4762 new_phy.setRoot( new_root.copyNodeDataShallow() );
4764 for( final PhylogenyNode n : new_root.getDescendants() ) {
4765 new_phy.getRoot().setChildNode( i++, n );
4770 final void superTree() {
4771 _nodes_in_preorder = null;
4772 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
4773 for( final PhylogenyNode n : temp_root.getDescendants() ) {
4774 n.setParent( temp_root );
4776 _sub_phylogenies[ _subtree_index ] = null;
4777 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
4778 _phylogeny = _sub_phylogenies[ --_subtree_index ];
4779 updateSubSuperTreeButton();
4782 final void swap( final PhylogenyNode node ) {
4783 if ( !node.isExternal() ) {
4784 _phylogeny.swapChildren( node );
4785 _nodes_in_preorder = null;
4790 final private void switchDisplaygetPhylogenyGraphicsType() {
4791 switch ( getPhylogenyGraphicsType() ) {
4793 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4794 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4797 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4798 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4801 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4802 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4805 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4806 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4809 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4810 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4813 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4814 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4817 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4818 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4821 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4822 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4825 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
4827 if ( getControlPanel().getDynamicallyHideData() != null ) {
4828 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4829 getControlPanel().getDynamicallyHideData().setEnabled( false );
4832 getControlPanel().getDynamicallyHideData().setEnabled( true );
4835 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4836 getControlPanel().setDrawPhylogramEnabled( true );
4839 getControlPanel().setDrawPhylogramEnabled( false );
4841 if ( getMainPanel().getMainFrame() == null ) {
4842 // Must be "E" applet version.
4843 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
4844 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4847 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4851 final void taxColor() {
4852 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4856 Util.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
4857 _control_panel.setColorBranches( true );
4858 if ( _control_panel.getColorBranchesCb() != null ) {
4859 _control_panel.getColorBranchesCb().setSelected( true );
4865 final void updateOvSettings() {
4866 switch ( getOptions().getOvPlacement() ) {
4868 setOvXPosition( OV_BORDER );
4869 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
4870 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
4873 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
4874 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
4875 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
4878 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
4879 setOvYPosition( OV_BORDER );
4880 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
4883 setOvXPosition( OV_BORDER );
4884 setOvYPosition( OV_BORDER );
4885 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
4890 final void updateOvSizes() {
4891 if ( ( getWidth() > 1.05 * getVisibleRect().width ) || ( getHeight() > 1.05 * getVisibleRect().height ) ) {
4893 float l = getLongestExtNodeInfo();
4894 final float w_ratio = getOvMaxWidth() / getWidth();
4896 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4897 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
4899 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4900 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
4903 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
4905 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
4906 if ( ov_xdist < 0.0 ) {
4909 if ( ydist < 0.0 ) {
4912 setOvXDistance( ov_xdist );
4913 final double height = _phylogeny.getHeight();
4915 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
4916 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4919 setOvXcorrectionFactor( 0 );
4927 final void updateSubSuperTreeButton() {
4928 if ( _subtree_index < 1 ) {
4929 getControlPanel().deactivateButtonToReturnToSuperTree();
4932 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
4936 final void zoomInDomainStructure() {
4937 if ( _domain_structure_width < 2000 ) {
4938 _domain_structure_width *= 1.2;
4942 final void zoomOutDomainStructure() {
4943 if ( _domain_structure_width > 20 ) {
4944 _domain_structure_width *= 0.8;
4948 final private static void drawString( final int i, final double x, final double y, final Graphics2D g ) {
4949 g.drawString( String.valueOf( i ), ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
4952 final private static void drawString( final String str, final double x, final double y, final Graphics2D g ) {
4953 g.drawString( str, ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
4956 final private static boolean isSequenceEmpty( final Sequence seq ) {
4957 return ( seq.getAccession() == null ) && ForesterUtil.isEmpty( seq.getName() )
4958 && ForesterUtil.isEmpty( seq.getSymbol() );
4961 final private static boolean isTaxonomyEmpty( final Taxonomy tax ) {
4962 return ( ( tax.getIdentifier() == null ) && ForesterUtil.isEmpty( tax.getTaxonomyCode() )
4963 && ForesterUtil.isEmpty( tax.getCommonName() ) && ForesterUtil.isEmpty( tax.getScientificName() ) && tax
4964 .getSynonyms().isEmpty() );
4967 final private static boolean plusPressed( final int key_code ) {
4968 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
4969 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
4972 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
4973 _statistics_for_vector_data = statistics_for_expression_values;
4976 DescriptiveStatistics getStatisticsForExpressionValues() {
4977 return _statistics_for_vector_data;
4980 final private class SubtreeColorizationActionListener implements ActionListener {
4982 JColorChooser _chooser;
4983 PhylogenyNode _node;
4985 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
4991 public void actionPerformed( final ActionEvent e ) {
4992 final Color c = _chooser.getColor();
4994 colorizeSubtree( c, _node );
4999 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
5000 getMainPanel().setImageMap( image_map );
5003 public synchronized Hashtable<String, BufferedImage> getImageMap() {
5004 return getMainPanel().getImageMap();