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: https://sites.google.com/site/cmzmasek/home/software/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.FontMetrics;
34 import java.awt.GradientPaint;
35 import java.awt.Graphics;
36 import java.awt.Graphics2D;
37 import java.awt.Point;
38 import java.awt.Rectangle;
39 import java.awt.RenderingHints;
40 import java.awt.Stroke;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.ActionListener;
43 import java.awt.event.FocusAdapter;
44 import java.awt.event.FocusEvent;
45 import java.awt.event.InputEvent;
46 import java.awt.event.KeyAdapter;
47 import java.awt.event.KeyEvent;
48 import java.awt.event.MouseEvent;
49 import java.awt.event.MouseWheelEvent;
50 import java.awt.event.MouseWheelListener;
51 import java.awt.font.FontRenderContext;
52 import java.awt.font.TextAttribute;
53 import java.awt.font.TextLayout;
54 import java.awt.geom.AffineTransform;
55 import java.awt.geom.Arc2D;
56 import java.awt.geom.CubicCurve2D;
57 import java.awt.geom.Ellipse2D;
58 import java.awt.geom.Line2D;
59 import java.awt.geom.Path2D;
60 import java.awt.geom.QuadCurve2D;
61 import java.awt.geom.Rectangle2D;
62 import java.awt.image.BufferedImage;
63 import java.awt.print.PageFormat;
64 import java.awt.print.Printable;
65 import java.awt.print.PrinterException;
67 import java.io.IOException;
68 import java.io.UnsupportedEncodingException;
70 import java.net.URISyntaxException;
71 import java.net.URLEncoder;
72 import java.text.AttributedString;
73 import java.text.DecimalFormat;
74 import java.text.DecimalFormatSymbols;
75 import java.text.NumberFormat;
76 import java.util.ArrayList;
77 import java.util.Collections;
78 import java.util.HashMap;
79 import java.util.HashSet;
80 import java.util.Hashtable;
81 import java.util.List;
84 import java.util.SortedSet;
86 import javax.swing.BorderFactory;
87 import javax.swing.JColorChooser;
88 import javax.swing.JDialog;
89 import javax.swing.JMenuItem;
90 import javax.swing.JOptionPane;
91 import javax.swing.JPanel;
92 import javax.swing.JPopupMenu;
93 import javax.swing.JTextArea;
94 import javax.swing.Popup;
95 import javax.swing.PopupFactory;
97 import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON;
98 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
99 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
100 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
101 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
102 import org.forester.archaeopteryx.Options.PHYLOGENY_DISPLAY_TYPE;
103 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
104 import org.forester.archaeopteryx.phylogeny.data.RenderableMsaSequence;
105 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
106 import org.forester.archaeopteryx.tools.Blast;
107 import org.forester.archaeopteryx.tools.ImageLoader;
108 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
109 import org.forester.io.writers.SequenceWriter;
110 import org.forester.phylogeny.Phylogeny;
111 import org.forester.phylogeny.PhylogenyMethods;
112 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
113 import org.forester.phylogeny.PhylogenyNode;
114 import org.forester.phylogeny.data.Accession;
115 import org.forester.phylogeny.data.Annotation;
116 import org.forester.phylogeny.data.BranchColor;
117 import org.forester.phylogeny.data.Confidence;
118 import org.forester.phylogeny.data.DomainArchitecture;
119 import org.forester.phylogeny.data.Event;
120 import org.forester.phylogeny.data.NodeDataField;
121 import org.forester.phylogeny.data.NodeVisualData;
122 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
123 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
124 import org.forester.phylogeny.data.PhylogenyDataUtil;
125 import org.forester.phylogeny.data.PropertiesList;
126 import org.forester.phylogeny.data.Property;
127 import org.forester.phylogeny.data.ProteinDomain;
128 import org.forester.phylogeny.data.Sequence;
129 import org.forester.phylogeny.data.SequenceRelation;
130 import org.forester.phylogeny.data.Taxonomy;
131 import org.forester.phylogeny.data.Uri;
132 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
133 import org.forester.phylogeny.iterators.PreorderTreeIterator;
134 import org.forester.util.BasicDescriptiveStatistics;
135 import org.forester.util.DescriptiveStatistics;
136 import org.forester.util.ForesterConstants;
137 import org.forester.util.ForesterUtil;
138 import org.forester.util.SequenceAccessionTools;
139 import org.forester.util.TaxonomyUtil;
141 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
143 final private class NodeColorizationActionListener implements ActionListener {
145 List<PhylogenyNode> _additional_nodes = null;
146 JColorChooser _chooser = null;
147 PhylogenyNode _node = null;
149 NodeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
154 NodeColorizationActionListener( final JColorChooser chooser,
155 final PhylogenyNode node,
156 final List<PhylogenyNode> additional_nodes ) {
159 _additional_nodes = additional_nodes;
163 public void actionPerformed( final ActionEvent e ) {
164 final Color c = _chooser.getColor();
166 colorizeNodes( c, _node, _additional_nodes );
171 final private class SubtreeColorizationActionListener implements ActionListener {
173 List<PhylogenyNode> _additional_nodes = null;
174 JColorChooser _chooser = null;
175 PhylogenyNode _node = null;
177 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
182 SubtreeColorizationActionListener( final JColorChooser chooser,
183 final PhylogenyNode node,
184 final List<PhylogenyNode> additional_nodes ) {
187 _additional_nodes = additional_nodes;
191 public void actionPerformed( final ActionEvent e ) {
192 final Color c = _chooser.getColor();
194 colorizeSubtree( c, _node, _additional_nodes );
198 public final static boolean SPECIAL_DOMAIN_COLORING = true;
199 final static Cursor ARROW_CURSOR = Cursor
200 .getPredefinedCursor( Cursor.DEFAULT_CURSOR );
201 final static Cursor CUT_CURSOR = Cursor
202 .getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
203 final static Cursor HAND_CURSOR = Cursor
204 .getPredefinedCursor( Cursor.HAND_CURSOR );
205 final static Cursor MOVE_CURSOR = Cursor
206 .getPredefinedCursor( Cursor.MOVE_CURSOR );
207 final static Cursor WAIT_CURSOR = Cursor
208 .getPredefinedCursor( Cursor.WAIT_CURSOR );
209 final private static double _180_OVER_PI = 180.0 / Math.PI;
210 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI
212 private final static int CONFIDENCE_LEFT_MARGIN = 4;
213 private final static int EURO_D = 10;
214 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
215 private final static NumberFormat FORMATTER_CONFIDENCE;
216 private static final float HALF_PI = ( float ) ( Math.PI
218 private final static int LIMIT_FOR_HQ_RENDERING = 2000;
219 private final static int MAX_NODE_FRAMES = 10;
220 private final static int MAX_SUBTREES = 100;
221 private final static int MIN_ROOT_LENGTH = 3;
222 private final static int MOVE = 20;
223 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
224 private static final float ONEHALF_PI = ( float ) ( 1.5
226 private static final short OV_BORDER = 10;
227 private final static double OVERVIEW_FOUND_NODE_BOX_SIZE = 2;
228 private final static double OVERVIEW_FOUND_NODE_BOX_SIZE_HALF = 1;
229 private static final float PI = ( float ) ( Math.PI );
230 final private static Font POPUP_FONT = new Font( Configuration
231 .getDefaultFontFamilyName(), Font.PLAIN, 12 );
232 private static final float ROUNDED_D = 8;
233 private final static long serialVersionUID = -978349745916505029L;
234 private static final BasicStroke STROKE_0025 = new BasicStroke( 0.025f );
235 private static final BasicStroke STROKE_005 = new BasicStroke( 0.05f );
236 private static final BasicStroke STROKE_01 = new BasicStroke( 0.1f );
237 private static final BasicStroke STROKE_025 = new BasicStroke( 0.25f );
238 private static final BasicStroke STROKE_05 = new BasicStroke( 0.5f );
239 private static final BasicStroke STROKE_075 = new BasicStroke( 0.75f );
240 private static final BasicStroke STROKE_1 = new BasicStroke( 1f );
241 private static final BasicStroke STROKE_2 = new BasicStroke( 2f );
242 private static final BasicStroke STROKE_01_DASHED = new BasicStroke( 0.1f,
243 BasicStroke.CAP_SQUARE,
244 BasicStroke.JOIN_ROUND,
249 private static final BasicStroke STROKE_005_DASHED = new BasicStroke( 0.05f,
250 BasicStroke.CAP_SQUARE,
251 BasicStroke.JOIN_ROUND,
256 private static final BasicStroke STROKE_001_DASHED = new BasicStroke( 0.01f,
257 BasicStroke.CAP_SQUARE,
258 BasicStroke.JOIN_ROUND,
263 private static final double TWO_PI = 2 * Math.PI;
264 private final static int WIGGLE = 2;
265 private static final String SHOW_ONLY_THIS_CONF_TYPE = null; //TODO remove me
266 HashMap<Long, Short> _nodeid_dist_to_leaf = new HashMap<Long, Short>();
267 final private Arc2D _arc = new Arc2D.Double();
268 private AffineTransform _at;
269 private int _circ_max_depth;
270 final private Set<Long> _collapsed_external_nodeid_set = new HashSet<Long>();
271 private JColorChooser _color_chooser = null;
272 private Configuration _configuration = null;
273 private ControlPanel _control_panel = null;
274 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
275 private Set<Long> _current_external_nodes = null;
276 private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
277 private int _current_external_nodes_data_buffer_change_counter = 0;
278 private int _domain_structure_e_value_thr_exp = AptxConstants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
279 private double _domain_structure_width = AptxConstants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
280 private int _dynamic_hiding_factor = 0;
281 private boolean _edited = false;
282 private final Ellipse2D _ellipse = new Ellipse2D.Float();
283 private int _external_node_index = 0;
284 private Set<Long> _found_nodes_0 = null;
285 private Set<Long> _found_nodes_1 = null;
286 private final FontRenderContext _frc = new FontRenderContext( null,
289 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
290 private PhylogenyNode _highlight_node = null;
291 private boolean _in_ov = false;
292 private boolean _in_ov_rect = false;
293 private float _last_drag_point_x = 0;
294 private float _last_drag_point_y = 0;
295 private final Line2D _line = new Line2D.Float();
296 private int _longest_ext_node_info = 0;
297 private PhylogenyNode _ext_node_with_longest_txt_info = null;
298 private MainPanel _main_panel = null;
299 private double _max_distance_to_root = -1;
300 private Popup _node_desc_popup;
301 private int _node_frame_index = 0;
302 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
303 private JPopupMenu _node_popup_menu = null;
304 private JMenuItem _node_popup_menu_items[] = null;
305 private PhylogenyNode[] _nodes_in_preorder = null;
306 private Options _options = null;
307 private float _ov_max_height = 0;
308 private float _ov_max_width = 0;
309 private boolean _ov_on = false;
310 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
311 private final Rectangle _ov_virtual_rectangle = new Rectangle();
312 private float _ov_x_correction_factor = 0.0f;
313 private float _ov_x_distance = 0;
314 private int _ov_x_position = 0;
315 private float _ov_y_distance = 0;
316 private int _ov_y_position = 0;
317 private int _ov_y_start = 0;
318 private final boolean _phy_has_branch_lengths;
319 private Phylogeny _phylogeny = null;
320 private final Path2D.Float _polygon = new Path2D.Float();
321 private final StringBuffer _popup_buffer = new StringBuffer();
322 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
323 private Sequence _query_sequence = null;
324 private final Rectangle2D _rectangle = new Rectangle2D.Float();
325 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
326 RenderingHints.VALUE_RENDER_DEFAULT );
327 private JTextArea _rollover_popup;
328 private PhylogenyNode _root;
329 private final StringBuilder _sb = new StringBuilder();
330 private double _scale_distance = 0.0;
331 private String _scale_label = null;
332 private DescriptiveStatistics _statistics_for_vector_data;
333 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
334 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
335 private int _subtree_index = 0;
336 private File _treefile = null;
337 private float _urt_factor = 1;
338 private float _urt_factor_ov = 1;
339 final private HashMap<Long, Double> _urt_nodeid_angle_map = new HashMap<Long, Double>();
340 final private HashMap<Long, Integer> _urt_nodeid_index_map = new HashMap<Long, Integer>();
341 private double _urt_starting_angle = ( float ) ( Math.PI
343 private float _x_correction_factor = 0.0f;
344 private float _x_distance = 0.0f;
345 private float _y_distance = 0.0f;
346 private int _length_of_longest_text;
347 private int _longest_domain;
348 private Map<String, AttributedString> _attributed_string_map = null;
349 private int _depth_collapse_level = -1;
350 private int _rank_collapse_level = -1;
352 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
353 dfs.setDecimalSeparator( '.' );
354 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
355 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
358 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
359 requestFocusInWindow();
360 addKeyListener( new KeyAdapter() {
363 public void keyPressed( final KeyEvent key_event ) {
364 keyPressedCalls( key_event );
365 requestFocusInWindow();
368 addFocusListener( new FocusAdapter() {
371 public void focusGained( final FocusEvent e ) {
372 requestFocusInWindow();
375 if ( ( t == null ) || t.isEmpty() ) {
376 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
378 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
380 _configuration = configuration;
382 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
384 // if ( !_phylogeny.isEmpty() ) {
385 _phylogeny.recalculateNumberOfExternalDescendants( true );
388 setBackground( getTreeColorSet().getBackgroundColor() );
389 final MouseListener mouse_listener = new MouseListener( this );
390 addMouseListener( mouse_listener );
391 addMouseMotionListener( mouse_listener );
392 addMouseWheelListener( this );
393 calculateScaleDistance();
394 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
395 FORMATTER_BRANCH_LENGTH
396 .setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() );
400 final public void actionPerformed( final ActionEvent e ) {
401 boolean done = false;
402 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
403 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
404 // NOTE: index corresponds to the indices of click-to options
405 // in the control panel.
406 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
407 // Set this as the new default click-to action
408 _main_panel.getControlPanel().setClickToAction( index );
409 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
410 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
411 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
416 requestFocusInWindow();
419 public synchronized Hashtable<String, BufferedImage> getImageMap() {
420 return getMainPanel().getImageMap();
423 final public MainPanel getMainPanel() {
428 * Get a pointer to the phylogeny
430 * @return a pointer to the phylogeny
432 public final Phylogeny getPhylogeny() {
436 public final TreeColorSet getTreeColorSet() {
437 return getMainPanel().getTreeColorSet();
441 final public void mouseWheelMoved( final MouseWheelEvent e ) {
442 final int notches = e.getWheelRotation();
443 if ( inOvVirtualRectangle( e ) ) {
444 if ( !isInOvRect() ) {
450 if ( isInOvRect() ) {
451 setInOvRect( false );
455 if ( e.isControlDown() && e.isShiftDown() ) {
457 getTreeFontSet().increaseFontSize();
460 getTreeFontSet().decreaseFontSize( 1, false );
462 getControlPanel().displayedPhylogenyMightHaveChanged( true );
463 resetPreferredSize();
467 else if ( e.isShiftDown() && e.isAltDown() ) {
469 for( int i = 0; i < ( -notches ); ++i ) {
470 getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR, AptxConstants.WHEEL_ZOOM_IN_FACTOR );
471 getControlPanel().displayedPhylogenyMightHaveChanged( false );
475 for( int i = 0; i < notches; ++i ) {
476 getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
477 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
478 getControlPanel().displayedPhylogenyMightHaveChanged( false );
482 else if ( e.isShiftDown() ) {
483 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
484 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
486 for( int i = 0; i < ( -notches ); ++i ) {
487 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
488 getControlPanel().displayedPhylogenyMightHaveChanged( false );
492 for( int i = 0; i < notches; ++i ) {
493 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
494 if ( getStartingAngle() < 0 ) {
495 setStartingAngle( TWO_PI + getStartingAngle() );
497 getControlPanel().displayedPhylogenyMightHaveChanged( false );
503 for( int i = 0; i < ( -notches ); ++i ) {
504 getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
505 getControlPanel().displayedPhylogenyMightHaveChanged( false );
509 for( int i = 0; i < notches; ++i ) {
510 getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
511 getControlPanel().displayedPhylogenyMightHaveChanged( false );
518 for( int i = 0; i < ( -notches ); ++i ) {
519 getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
520 AptxConstants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
521 getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
522 getControlPanel().displayedPhylogenyMightHaveChanged( false );
526 for( int i = 0; i < notches; ++i ) {
527 getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
528 getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
529 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
530 getControlPanel().displayedPhylogenyMightHaveChanged( false );
535 requestFocusInWindow();
540 final public void paintComponent( final Graphics g ) {
541 // Dimension currentSize = getSize();
542 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
543 // call the 'java.awt.Component.createImage(...)' method to get an
545 // offscreenImage = createImage( currentSize.width, currentSize.height );
546 // offscreenGraphics = offscreenImage.getGraphics();
547 // offscreenDimension = currentSize;
549 // super.paintComponent( g ); //why?
550 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
551 final Graphics2D g2d = ( Graphics2D ) g;
552 g2d.setRenderingHints( _rendering_hints );
553 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
554 //g.drawImage( offscreenImage, 0, 0, this );
558 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
559 throws PrinterException {
560 if ( page_index > 0 ) {
561 return ( NO_SUCH_PAGE );
564 final Graphics2D g2d = ( Graphics2D ) g;
565 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
566 // Turn off double buffering !?
567 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
568 // Turn double buffering back on !?
569 return ( PAGE_EXISTS );
573 public final void setEdited( final boolean edited ) {
577 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
578 getMainPanel().setImageMap( image_map );
582 * Set a phylogeny tree.
585 * an instance of a Phylogeny
587 public final void setTree( final Phylogeny t ) {
588 setNodeInPreorderToNull();
592 public final void setWaitCursor() {
593 setCursor( WAIT_CURSOR );
598 public void update( final Graphics g ) {
602 private void abbreviateScientificName( final String sn, final StringBuilder sb ) {
603 final String[] a = sn.split( "\\s+" );
604 sb.append( a[ 0 ].substring( 0, 1 ) );
605 sb.append( a[ 1 ].substring( 0, 2 ) );
606 if ( a.length > 2 ) {
607 for( int i = 2; i < a.length; i++ ) {
614 final private void addEmptyNode( final PhylogenyNode node ) {
615 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
616 errorMessageNoCutCopyPasteInUnrootedDisplay();
619 final String label = createASimpleTextRepresentationOfANode( node );
621 if ( ForesterUtil.isEmpty( label ) ) {
622 msg = "How to add the new, empty node?";
625 msg = "How to add the new, empty node to node" + label + "?";
627 final Object[] options = { "As sibling", "As descendant", "Cancel" };
628 final int r = JOptionPane.showOptionDialog( this,
630 "Addition of Empty New Node",
631 JOptionPane.CLOSED_OPTION,
632 JOptionPane.QUESTION_MESSAGE,
636 boolean add_as_sibling = true;
638 add_as_sibling = false;
643 final Phylogeny phy = new Phylogeny();
644 phy.setRoot( new PhylogenyNode() );
645 phy.setRooted( true );
646 if ( add_as_sibling ) {
647 if ( node.isRoot() ) {
648 JOptionPane.showMessageDialog( this,
649 "Cannot add sibling to root",
650 "Attempt to add sibling to root",
651 JOptionPane.ERROR_MESSAGE );
654 phy.addAsSibling( node );
657 phy.addAsChild( node );
659 setNodeInPreorderToNull();
660 _phylogeny.externalNodesHaveChanged();
661 _phylogeny.clearHashIdToNodeMap();
662 _phylogeny.recalculateNumberOfExternalDescendants( true );
663 resetNodeIdToDistToLeafMap();
668 final private void addToCurrentExternalNodes( final long i ) {
669 if ( _current_external_nodes == null ) {
670 _current_external_nodes = new HashSet<Long>();
672 _current_external_nodes.add( i );
675 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
676 final boolean is_vertical,
678 final boolean to_pdf,
679 final boolean to_graphics_file ) {
680 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
681 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
682 g.setColor( Color.BLACK );
684 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
685 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE )
686 || ( action == NodeClickAction.ADD_NEW_NODE ) ) && ( getCutOrCopiedTree() != null )
687 && ( getCopiedAndPastedNodes() != null ) && !to_pdf && !to_graphics_file
688 && getCopiedAndPastedNodes().contains( node.getId() ) ) {
689 g.setColor( getTreeColorSet().getFoundColor0() );
691 else if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
692 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
695 g.setColor( getTreeColorSet().getBranchColorForPdf() );
698 g.setColor( getTreeColorSet().getBranchColor() );
702 final private void blast( final PhylogenyNode node ) {
703 if ( !isCanBlast( node ) ) {
704 JOptionPane.showMessageDialog( this,
705 "Insufficient information present",
707 JOptionPane.INFORMATION_MESSAGE );
711 final String query = Blast.obtainQueryForBlast( node );
712 System.out.println( "query for BLAST is: " + query );
714 if ( !ForesterUtil.isEmpty( query ) ) {
715 if ( node.getNodeData().isHasSequence() ) {
716 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
717 if ( node.getNodeData().getSequence().getType().toLowerCase()
718 .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
725 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
727 .seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) {
736 if ( SequenceAccessionTools.isProteinDbQuery( query ) ) {
746 Blast.openNcbiBlastWeb( query, type == 'n', this );
748 catch ( final Exception e ) {
755 private final int calcDynamicHidingFactor() {
756 return ( int ) ( 0.5 + ( getFontMetricsForLargeDefaultFont().getHeight() / ( 1.5 * getYdistance() ) ) );
759 final private int calcLengthOfLongestText() {
760 final StringBuilder sb = new StringBuilder();
761 if ( _ext_node_with_longest_txt_info != null ) {
762 nodeDataAsSB( _ext_node_with_longest_txt_info, sb );
763 if ( _ext_node_with_longest_txt_info.getNodeData().isHasTaxonomy() ) {
764 nodeTaxonomyDataAsSB( _ext_node_with_longest_txt_info.getNodeData().getTaxonomy(), sb );
767 return getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
771 * Calculate the length of the distance between the given node and its
777 * @return the distance value
779 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
780 if ( getControlPanel().isDrawPhylogram() ) {
781 if ( node.getDistanceToParent() < 0.0 ) {
784 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
787 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
788 return getXdistance();
790 return getXdistance() * factor;
794 final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
795 Color c = getTreeColorSet().getAnnotationColor();
796 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
797 final StringBuilder sb = new StringBuilder();
798 for( final Annotation a : ann ) {
799 sb.append( !ForesterUtil.isEmpty( a.getRefValue() ) ? a.getRefValue() : a.getDesc() );
801 final String ann_str = sb.toString();
802 if ( !ForesterUtil.isEmpty( ann_str ) ) {
803 c = getControlPanel().getAnnotationColors().get( ann_str );
805 c = AptxUtil.calculateColorFromString( ann_str, false );
806 getControlPanel().getAnnotationColors().put( ann_str, c );
809 c = getTreeColorSet().getAnnotationColor();
816 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
817 if ( getControlPanel().isDrawPhylogram() ) {
818 if ( node.getDistanceToParent() < 0.0 ) {
821 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
824 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
825 return getOvXDistance();
827 return getOvXDistance() * factor;
831 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
832 JOptionPane.showMessageDialog( this,
833 "Cannot launch web browser for " + type_type + " data of this node",
834 "Cannot launch web browser",
835 JOptionPane.WARNING_MESSAGE );
838 private void changeNodeFont( final PhylogenyNode node ) {
839 final FontChooser fc = new FontChooser();
841 if ( ( node.getNodeData().getNodeVisualData() != null ) && !node.getNodeData().getNodeVisualData().isEmpty() ) {
842 f = node.getNodeData().getNodeVisualData().getFont();
848 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
850 List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
851 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
852 nodes = getFoundNodesAsListOfPhylogenyNodes();
854 if ( !nodes.contains( node ) ) {
857 final int count = nodes.size();
858 String title = "Change the font for ";
863 title += ( count + " nodes" );
865 fc.showDialog( this, title );
866 if ( ( fc.getFont() != null ) && !ForesterUtil.isEmpty( fc.getFont().getFamily().trim() ) ) {
867 for( final PhylogenyNode n : nodes ) {
868 if ( n.getNodeData().getNodeVisualData() == null ) {
869 n.getNodeData().setNodeVisualData( new NodeVisualData() );
871 final NodeVisualData vd = n.getNodeData().getNodeVisualData();
872 final Font ff = fc.getFont();
873 vd.setFontName( ff.getFamily().trim() );
874 int s = ff.getSize();
878 if ( s > Byte.MAX_VALUE ) {
882 vd.setFontStyle( ff.getStyle() );
884 if ( _control_panel.getUseVisualStylesCb() != null ) {
885 getControlPanel().getUseVisualStylesCb().setSelected( true );
892 final private void colorizeNodes( final Color c,
893 final PhylogenyNode node,
894 final List<PhylogenyNode> additional_nodes ) {
895 _control_panel.setColorBranches( true );
896 if ( _control_panel.getUseVisualStylesCb() != null ) {
897 _control_panel.getUseVisualStylesCb().setSelected( true );
899 if ( node != null ) {
900 colorizeNodesHelper( c, node );
902 if ( additional_nodes != null ) {
903 for( final PhylogenyNode n : additional_nodes ) {
904 colorizeNodesHelper( c, n );
910 final private void colorizeSubtree( final Color c,
911 final PhylogenyNode node,
912 final List<PhylogenyNode> additional_nodes ) {
913 _control_panel.setColorBranches( true );
914 if ( _control_panel.getUseVisualStylesCb() != null ) {
915 _control_panel.getUseVisualStylesCb().setSelected( true );
917 if ( node != null ) {
918 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
919 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
922 if ( additional_nodes != null ) {
923 for( final PhylogenyNode an : additional_nodes ) {
924 for( final PreorderTreeIterator it = new PreorderTreeIterator( an ); it.hasNext(); ) {
925 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
932 private void colorNodeFont( final PhylogenyNode node ) {
933 _color_chooser.setPreviewPanel( new JPanel() );
934 NodeColorizationActionListener al;
936 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
937 final List<PhylogenyNode> additional_nodes = getFoundNodesAsListOfPhylogenyNodes();
938 al = new NodeColorizationActionListener( _color_chooser, node, additional_nodes );
939 count = additional_nodes.size();
940 if ( !additional_nodes.contains( node ) ) {
945 al = new NodeColorizationActionListener( _color_chooser, node );
947 String title = "Change the (node and font) color for ";
952 title += ( count + " nodes" );
954 final JDialog dialog = JColorChooser.createDialog( this, title, true, _color_chooser, al, null );
956 dialog.setVisible( true );
959 final private void colorSubtree( final PhylogenyNode node ) {
960 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
961 JOptionPane.showMessageDialog( this,
962 "Cannot colorize subtree in unrooted display type",
963 "Attempt to colorize subtree in unrooted display",
964 JOptionPane.WARNING_MESSAGE );
967 _color_chooser.setPreviewPanel( new JPanel() );
968 final SubtreeColorizationActionListener al;
969 final boolean color_found = getOptions().isColorAllFoundNodesWhenColoringSubtree();
970 if ( color_found && ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) ) {
971 final List<PhylogenyNode> additional_nodes = getFoundNodesAsListOfPhylogenyNodes();
972 al = new SubtreeColorizationActionListener( _color_chooser, node, additional_nodes );
975 al = new SubtreeColorizationActionListener( _color_chooser, node );
977 final JDialog dialog = JColorChooser.createDialog( this,
978 "Subtree colorization",
984 dialog.setVisible( true );
987 final private void copySubtree( final PhylogenyNode node ) {
988 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
989 errorMessageNoCutCopyPasteInUnrootedDisplay();
992 setNodeInPreorderToNull();
993 setCutOrCopiedTree( _phylogeny.copy( node ) );
994 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
995 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
996 for( final PhylogenyNode n : nodes ) {
997 node_ids.add( n.getId() );
999 node_ids.add( node.getId() );
1000 setCopiedAndPastedNodes( node_ids );
1004 final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
1005 final String tax = PhylogenyMethods.getSpecies( node );
1006 String label = node.getName();
1007 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
1008 label = label + " " + tax;
1010 else if ( !ForesterUtil.isEmpty( tax ) ) {
1016 if ( !ForesterUtil.isEmpty( label ) ) {
1017 label = " [" + label + "]";
1022 final private void cutSubtree( final PhylogenyNode node ) {
1023 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1024 errorMessageNoCutCopyPasteInUnrootedDisplay();
1027 if ( node.isRoot() ) {
1028 JOptionPane.showMessageDialog( this,
1029 "Cannot cut entire tree as subtree",
1030 "Attempt to cut entire tree",
1031 JOptionPane.ERROR_MESSAGE );
1034 final String label = createASimpleTextRepresentationOfANode( node );
1035 final int r = JOptionPane.showConfirmDialog( null,
1036 "Cut subtree" + label + "?",
1037 "Confirm Cutting of Subtree",
1038 JOptionPane.YES_NO_OPTION );
1039 if ( r != JOptionPane.OK_OPTION ) {
1042 setNodeInPreorderToNull();
1043 setCopiedAndPastedNodes( null );
1044 setCutOrCopiedTree( _phylogeny.copy( node ) );
1045 _phylogeny.deleteSubtree( node, true );
1046 _phylogeny.clearHashIdToNodeMap();
1047 _phylogeny.recalculateNumberOfExternalDescendants( true );
1048 resetNodeIdToDistToLeafMap();
1053 final private void cycleColors() {
1054 getMainPanel().getTreeColorSet().cycleColorScheme();
1055 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
1056 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
1060 final private void decreaseOvSize() {
1061 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
1062 setOvMaxWidth( getOvMaxWidth() - 5 );
1063 setOvMaxHeight( getOvMaxHeight() - 5 );
1065 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1069 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
1070 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1071 errorMessageNoCutCopyPasteInUnrootedDisplay();
1074 if ( node.isRoot() && ( node.getNumberOfDescendants() != 1 ) ) {
1075 JOptionPane.showMessageDialog( this,
1076 "Cannot delete entire tree",
1077 "Attempt to delete entire tree",
1078 JOptionPane.ERROR_MESSAGE );
1081 final String label = createASimpleTextRepresentationOfANode( node );
1082 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
1083 final int r = JOptionPane.showOptionDialog( this,
1084 "Delete" + label + "?",
1085 "Delete Node/Subtree",
1086 JOptionPane.CLOSED_OPTION,
1087 JOptionPane.QUESTION_MESSAGE,
1091 setNodeInPreorderToNull();
1092 boolean node_only = true;
1096 else if ( r != 0 ) {
1100 PhylogenyMethods.removeNode( node, _phylogeny );
1103 _phylogeny.deleteSubtree( node, true );
1105 _phylogeny.externalNodesHaveChanged();
1106 _phylogeny.clearHashIdToNodeMap();
1107 _phylogeny.recalculateNumberOfExternalDescendants( true );
1108 resetNodeIdToDistToLeafMap();
1113 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
1114 makePopupMenus( node );
1115 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
1116 _node_popup_menu.show( this, x, y );
1119 final private void drawArc( final double x,
1122 final double heigth,
1123 final double start_angle,
1124 final double arc_angle,
1125 final Graphics2D g ) {
1126 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
1130 final private void drawLine( final double x1,
1134 final Graphics2D g ) {
1135 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
1138 _line.setLine( x1, y1, x2, y2 );
1142 final private void drawOval( final double x,
1145 final double heigth,
1146 final Graphics2D g ) {
1147 _ellipse.setFrame( x, y, width, heigth );
1151 final private void drawOvalFilled( final double x,
1154 final double heigth,
1155 final Graphics2D g ) {
1156 _ellipse.setFrame( x, y, width, heigth );
1160 final private void drawOvalGradient( final float x,
1165 final Color color_1,
1166 final Color color_2,
1167 final Color color_border ) {
1168 _ellipse.setFrame( x, y, width, heigth );
1169 g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) );
1171 if ( color_border != null ) {
1172 g.setPaint( color_border );
1177 final private void drawRect( final float x,
1181 final Graphics2D g ) {
1182 _rectangle.setFrame( x, y, width, heigth );
1183 g.draw( _rectangle );
1186 final private void drawRectFilled( final double x,
1189 final double heigth,
1190 final Graphics2D g ) {
1191 _rectangle.setFrame( x, y, width, heigth );
1192 g.fill( _rectangle );
1195 final private void drawRectGradient( final float x,
1200 final Color color_1,
1201 final Color color_2,
1202 final Color color_border ) {
1203 _rectangle.setFrame( x, y, width, heigth );
1204 g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) );
1205 g.fill( _rectangle );
1206 if ( color_border != null ) {
1207 g.setPaint( color_border );
1208 g.draw( _rectangle );
1212 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
1213 final List<Uri> us = new ArrayList<Uri>();
1214 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
1215 for( final Uri uri : t.getUris() ) {
1220 for( final Uri uri : us ) {
1221 if ( uri != null ) {
1222 final String uri_str = uri.getValue().toString().toLowerCase();
1223 if ( getImageMap().containsKey( uri_str ) ) {
1224 final BufferedImage bi = getImageMap().get( uri_str );
1225 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
1226 double scaling_factor = 1;
1227 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
1228 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
1229 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
1231 // y = y - ( 0.9 * getYdistance() );
1232 final double hs = bi.getHeight() * scaling_factor;
1233 double ws = ( bi.getWidth() * scaling_factor ) + offset;
1234 final double my_y = y - ( 0.5 * hs );
1235 final int x_w = ( int ) ( x + ws + 0.5 );
1236 final int y_h = ( int ) ( my_y + hs + 0.5 );
1237 if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) {
1239 ( int ) ( x + 0.5 + offset ),
1240 ( int ) ( my_y + 0.5 ),
1261 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
1262 JOptionPane.showMessageDialog( this,
1263 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
1264 "Attempt to cut/copy/paste/add/delete in unrooted display",
1265 JOptionPane.ERROR_MESSAGE );
1268 private final Color getColorForFoundNode( final PhylogenyNode n ) {
1269 if ( isInCurrentExternalNodes( n ) ) {
1270 return getTreeColorSet().getFoundColor0();
1272 else if ( isInFoundNodes0( n ) && !isInFoundNodes1( n ) ) {
1273 return getTreeColorSet().getFoundColor0();
1275 else if ( !isInFoundNodes0( n ) && isInFoundNodes1( n ) ) {
1276 return getTreeColorSet().getFoundColor1();
1279 return getTreeColorSet().getFoundColor0and1();
1283 final private Set<Long> getCopiedAndPastedNodes() {
1284 return getMainPanel().getCopiedAndPastedNodes();
1287 final private Set<Long> getCurrentExternalNodes() {
1288 return _current_external_nodes;
1291 final private Phylogeny getCutOrCopiedTree() {
1292 return getMainPanel().getCutOrCopiedTree();
1295 private FontMetrics getFontMetricsForLargeDefaultFont() {
1296 return getTreeFontSet().getFontMetricsLarge();
1299 final private float getLastDragPointX() {
1300 return _last_drag_point_x;
1303 final private float getLastDragPointY() {
1304 return _last_drag_point_y;
1307 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
1308 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
1309 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
1310 _nodeid_dist_to_leaf.put( node.getId(), m );
1314 return _nodeid_dist_to_leaf.get( node.getId() );
1318 final private double getMaxDistanceToRoot() {
1319 if ( _max_distance_to_root < 0 ) {
1320 recalculateMaxDistanceToRoot();
1322 return _max_distance_to_root;
1325 final private float getOvMaxHeight() {
1326 return _ov_max_height;
1329 final private float getOvMaxWidth() {
1330 return _ov_max_width;
1333 final private float getOvXcorrectionFactor() {
1334 return _ov_x_correction_factor;
1337 final private float getOvXDistance() {
1338 return _ov_x_distance;
1341 final private int getOvXPosition() {
1342 return _ov_x_position;
1345 final private float getOvYDistance() {
1346 return _ov_y_distance;
1349 final private int getOvYPosition() {
1350 return _ov_y_position;
1353 final private int getOvYStart() {
1357 final private List<Accession> getPdbAccs( final PhylogenyNode node ) {
1358 final List<Accession> pdb_ids = new ArrayList<Accession>();
1359 if ( node.getNodeData().isHasSequence() ) {
1360 final Sequence seq = node.getNodeData().getSequence();
1361 if ( !ForesterUtil.isEmpty( seq.getCrossReferences() ) ) {
1362 final SortedSet<Accession> cross_refs = seq.getCrossReferences();
1363 for( final Accession acc : cross_refs ) {
1364 if ( acc.getSource().equalsIgnoreCase( "pdb" ) ) {
1373 final private double getScaleDistance() {
1374 return _scale_distance;
1377 final private String getScaleLabel() {
1378 return _scale_label;
1381 final private TreeFontSet getTreeFontSet() {
1382 return getMainPanel().getTreeFontSet();
1385 final private float getUrtFactor() {
1389 final private float getUrtFactorOv() {
1390 return _urt_factor_ov;
1393 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
1396 showNodeFrame( node );
1411 colorSubtree( node );
1413 case COLOR_NODE_FONT:
1414 colorNodeFont( node );
1416 case CHANGE_NODE_FONT:
1417 changeNodeFont( node );
1435 copySubtree( node );
1438 pasteSubtree( node );
1440 case DELETE_NODE_OR_SUBTREE:
1441 deleteNodeOrSubtree( node );
1444 addEmptyNode( node );
1446 case EDIT_NODE_DATA:
1447 showNodeEditFrame( node );
1452 case SORT_DESCENDENTS:
1453 sortDescendants( node );
1455 case GET_EXT_DESC_DATA:
1456 showExtDescNodeData( node );
1458 case UNCOLLAPSE_ALL:
1459 uncollapseAll( node );
1462 orderSubtree( node );
1465 throw new IllegalArgumentException( "unknown action: " + action );
1469 final private void increaseCurrentExternalNodesDataBufferChangeCounter() {
1470 _current_external_nodes_data_buffer_change_counter++;
1473 final private void increaseOvSize() {
1474 if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth()
1476 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
1477 .getHeight() / 2 ) ) ) {
1478 setOvMaxWidth( getOvMaxWidth() + 5 );
1479 setOvMaxHeight( getOvMaxHeight() + 5 );
1481 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1485 final private void init() {
1486 _color_chooser = new JColorChooser();
1487 _rollover_popup = new JTextArea();
1488 _rollover_popup.setFont( POPUP_FONT );
1489 resetNodeIdToDistToLeafMap();
1491 setTreeFile( null );
1493 initializeOvSettings();
1494 resetDepthCollapseDepthValue();
1495 resetRankCollapseRankValue();
1496 setStartingAngle( ( TWO_PI * 3 ) / 4 );
1497 final ImageLoader il = new ImageLoader( this );
1498 new Thread( il ).start();
1501 final private void initializeOvSettings() {
1502 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
1503 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
1506 final private boolean inOvVirtualRectangle( final int x, final int y ) {
1507 return ( ( x >= ( getOvVirtualRectangle().x - 1 ) )
1508 && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) )
1509 && ( y >= ( getOvVirtualRectangle().y - 1 ) )
1510 && ( y <= ( getOvVirtualRectangle().y + getOvVirtualRectangle().height + 1 ) ) );
1513 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
1514 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
1517 final private boolean isCanBlast( final PhylogenyNode node ) {
1518 if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) {
1521 return Blast.isContainsQueryForBlast( node );
1524 final private String isCanOpenSeqWeb( final PhylogenyNode node ) {
1525 final Accession a = SequenceAccessionTools.obtainAccessorFromDataFields( node );
1527 return a.getValue();
1532 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
1533 if ( node.getNodeData().isHasTaxonomy() && ( ( !ForesterUtil
1534 .isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
1535 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
1536 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) )
1537 || ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
1538 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) ) ) ) {
1546 final private boolean isInCurrentExternalNodes( final PhylogenyNode node ) {
1547 return ( ( getCurrentExternalNodes() != null ) && getCurrentExternalNodes().contains( node.getId() ) );
1550 private boolean isInFoundNodes( final PhylogenyNode n ) {
1551 return isInFoundNodes0( n ) || isInFoundNodes1( n );
1554 final private boolean isInFoundNodes0( final PhylogenyNode node ) {
1555 return ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) );
1558 final private boolean isInFoundNodes1( final PhylogenyNode node ) {
1559 return ( ( getFoundNodes1() != null ) && getFoundNodes1().contains( node.getId() ) );
1562 final private boolean isInOv() {
1566 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
1568 if ( getControlPanel().isShowTaxonomyImages() ) {
1569 y_dist = 40 + ( int ) getYdistance();
1571 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) )
1572 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) )
1573 || ( ( node.getParent() != null ) && ( node.getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
1576 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
1577 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) )
1578 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) )
1579 || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) )
1580 || ( node.getXcoord() > ( getVisibleRect().getMaxX() + 20 ) ) );
1583 final private boolean isNonLinedUpCladogram() {
1584 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
1587 final private void keyPressedCalls( final KeyEvent e ) {
1588 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
1589 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
1590 if ( !isInOvRect() ) {
1591 setInOvRect( true );
1594 else if ( isInOvRect() ) {
1595 setInOvRect( false );
1598 if ( e.isAltDown() ) {
1599 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1600 || ( e.getKeyCode() == KeyEvent.VK_C ) || ( e.getKeyCode() == KeyEvent.VK_BACK_SPACE ) ) {
1601 getControlPanel().showWhole();
1603 else if ( e.isShiftDown()
1604 && ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) ) {
1605 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
1606 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1608 else if ( e.isShiftDown() && plusPressed( e.getKeyCode() ) ) {
1609 getMainPanel().getTreeFontSet().increaseFontSize();
1610 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1612 else if ( e.getKeyCode() == KeyEvent.VK_O ) {
1613 getControlPanel().orderPressed( this );
1615 else if ( e.getKeyCode() == KeyEvent.VK_R ) {
1616 getControlPanel().returnedToSuperTreePressed();
1618 else if ( e.getKeyCode() == KeyEvent.VK_U ) {
1619 getControlPanel().uncollapseAll( this );
1620 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1622 else if ( e.getKeyCode() == KeyEvent.VK_UP ) {
1623 getMainPanel().getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1624 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1626 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1627 getMainPanel().getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
1628 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1630 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1631 getMainPanel().getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
1632 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1633 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1635 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1636 getMainPanel().getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
1637 AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1638 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1640 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1641 getMainPanel().getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
1642 getMainPanel().getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
1643 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1644 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1646 else if ( plusPressed( e.getKeyCode() ) ) {
1647 getMainPanel().getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
1648 AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1649 getMainPanel().getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1650 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1654 if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
1655 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
1659 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1662 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1666 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1670 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1671 scroll_position.x = scroll_position.x + dx;
1672 scroll_position.y = scroll_position.y + dy;
1673 if ( scroll_position.x <= 0 ) {
1674 scroll_position.x = 0;
1677 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1678 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1679 if ( scroll_position.x >= max_x ) {
1680 scroll_position.x = max_x;
1683 if ( scroll_position.y <= 0 ) {
1684 scroll_position.y = 0;
1687 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1688 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1689 if ( scroll_position.y >= max_y ) {
1690 scroll_position.y = max_y;
1694 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1696 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
1697 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1698 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1699 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1700 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1703 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
1704 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1705 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1706 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1707 if ( getStartingAngle() < 0 ) {
1708 setStartingAngle( TWO_PI + getStartingAngle() );
1710 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1713 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
1714 boolean selected = false;
1715 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
1716 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1720 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1722 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
1725 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
1726 switchDisplaygetPhylogenyGraphicsType();
1729 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
1733 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
1734 MainFrame.cycleOverview( getOptions(), this );
1737 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
1740 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
1744 if ( e.getKeyCode() == KeyEvent.VK_HOME
1745 || e.getKeyCode() == KeyEvent.VK_ESCAPE ) {
1746 getControlPanel().showWhole();
1748 else if ( e.getKeyCode() == KeyEvent.VK_PAGE_UP ) {
1749 getMainPanel().getTreeFontSet().increaseFontSize();
1750 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1752 else if ( e.getKeyCode() == KeyEvent.VK_PAGE_DOWN ) {
1753 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
1754 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1759 final private void makePopupMenus( final PhylogenyNode node ) {
1760 _node_popup_menu = new JPopupMenu();
1761 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
1762 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
1763 for( int i = 0; i < clickto_names.size(); i++ ) {
1764 final String title = clickto_names.get( i );
1765 _node_popup_menu_items[ i ] = new JMenuItem( title );
1766 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
1767 final String id = isCanOpenSeqWeb( node );
1768 if ( !ForesterUtil.isEmpty( id ) ) {
1769 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + id + "]" );
1770 _node_popup_menu_items[ i ].setEnabled( true );
1773 _node_popup_menu_items[ i ].setEnabled( false );
1776 else if ( title.equals( Configuration.clickto_options[ Configuration.open_pdb_web ][ 0 ] ) ) {
1777 final List<Accession> accs = getPdbAccs( node );
1778 _node_popup_menu_items[ i ] = new JMenuItem( title );
1779 if ( !ForesterUtil.isEmpty( accs ) ) {
1780 if ( accs.size() == 1 ) {
1781 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1782 + TreePanelUtil.pdbAccToString( accs, 0 ) + "]" );
1783 _node_popup_menu_items[ i ].setEnabled( true );
1785 else if ( accs.size() == 2 ) {
1786 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1787 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1788 + TreePanelUtil.pdbAccToString( accs, 1 ) + "]" );
1789 _node_popup_menu_items[ i ].setEnabled( true );
1791 else if ( accs.size() == 3 ) {
1792 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1793 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1794 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
1795 + TreePanelUtil.pdbAccToString( accs, 2 ) + "]" );
1796 _node_popup_menu_items[ i ].setEnabled( true );
1799 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1800 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1801 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
1802 + TreePanelUtil.pdbAccToString( accs, 2 ) + ", + " + ( accs.size() - 3 ) + " more]" );
1803 _node_popup_menu_items[ i ].setEnabled( true );
1807 _node_popup_menu_items[ i ].setEnabled( false );
1810 else if ( title.startsWith( Configuration.clickto_options[ Configuration.get_ext_desc_data ][ 0 ] ) ) {
1811 _node_popup_menu_items[ i ]
1812 .setText( Configuration.clickto_options[ Configuration.get_ext_desc_data ][ 0 ] + ": "
1813 + getOptions().getExtDescNodeDataToReturn().toString() );
1815 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
1816 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
1818 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
1819 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
1821 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
1822 if ( !getOptions().isEditable() ) {
1825 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
1827 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
1828 if ( !getOptions().isEditable() ) {
1831 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
1833 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
1834 if ( !getOptions().isEditable() ) {
1837 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
1839 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
1840 if ( !getOptions().isEditable() ) {
1843 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
1845 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
1846 if ( !getOptions().isEditable() ) {
1850 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
1851 if ( !getOptions().isEditable() ) {
1855 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
1856 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
1858 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
1859 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
1861 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
1862 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
1864 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
1865 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
1867 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
1868 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
1870 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
1871 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
1873 else if ( title.equals( Configuration.clickto_options[ Configuration.uncollapse_all ][ 0 ] ) ) {
1874 _node_popup_menu_items[ i ].setEnabled( isCanUncollapseAll( node ) );
1876 _node_popup_menu_items[ i ].addActionListener( this );
1877 _node_popup_menu.add( _node_popup_menu_items[ i ] );
1881 private final void nodeDataAsSB( final PhylogenyNode node, final StringBuilder sb ) {
1882 if ( node != null ) {
1883 if ( getControlPanel().isShowNodeNames() && ( !ForesterUtil.isEmpty( node.getName() ) ) ) {
1884 if ( sb.length() > 0 ) {
1887 sb.append( node.getName() );
1889 if ( node.getNodeData().isHasSequence() ) {
1890 if ( getControlPanel().isShowSeqSymbols()
1891 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
1892 if ( sb.length() > 0 ) {
1895 sb.append( node.getNodeData().getSequence().getSymbol() );
1897 if ( getControlPanel().isShowGeneNames()
1898 && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) {
1899 if ( sb.length() > 0 ) {
1902 sb.append( node.getNodeData().getSequence().getGeneName() );
1904 if ( getControlPanel().isShowSeqNames()
1905 && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
1906 if ( sb.length() > 0 ) {
1909 sb.append( node.getNodeData().getSequence().getName() );
1911 if ( getControlPanel().isShowSequenceAcc()
1912 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
1913 if ( sb.length() > 0 ) {
1916 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
1917 sb.append( node.getNodeData().getSequence().getAccession().getSource() );
1920 sb.append( node.getNodeData().getSequence().getAccession().getValue() );
1923 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
1924 if ( sb.length() > 0 ) {
1927 sb.append( propertiesToString( node ) );
1932 private final void nodeTaxonomyDataAsSB( final Taxonomy taxonomy, final StringBuilder sb ) {
1933 if ( _control_panel.isShowTaxonomyRank() && !ForesterUtil.isEmpty( taxonomy.getRank() ) ) {
1935 sb.append( taxonomy.getRank() );
1938 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
1939 sb.append( taxonomy.getTaxonomyCode() );
1942 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
1943 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
1944 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1945 if ( getOptions().isAbbreviateScientificTaxonNames()
1946 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1947 abbreviateScientificName( taxonomy.getScientificName(), sb );
1950 sb.append( taxonomy.getScientificName() );
1953 sb.append( taxonomy.getCommonName() );
1956 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
1957 if ( getOptions().isAbbreviateScientificTaxonNames()
1958 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1959 abbreviateScientificName( taxonomy.getScientificName(), sb );
1962 sb.append( taxonomy.getScientificName() );
1966 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1967 sb.append( taxonomy.getCommonName() );
1971 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
1972 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
1973 if ( getOptions().isAbbreviateScientificTaxonNames()
1974 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1975 abbreviateScientificName( taxonomy.getScientificName(), sb );
1978 sb.append( taxonomy.getScientificName() );
1983 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
1984 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1985 sb.append( taxonomy.getCommonName() );
1991 private final String obtainTitleForExtDescNodeData() {
1992 return getOptions().getExtDescNodeDataToReturn().toString();
1995 final private void openPdbWeb( final PhylogenyNode node ) {
1996 final List<Accession> pdb_ids = getPdbAccs( node );
1997 if ( ForesterUtil.isEmpty( pdb_ids ) ) {
1998 cannotOpenBrowserWarningMessage( "PDB" );
2001 final List<String> uri_strs = TreePanelUtil.createUrisForPdbWeb( node, pdb_ids, getConfiguration(), this );
2002 if ( !ForesterUtil.isEmpty( uri_strs ) ) {
2003 for( final String uri_str : uri_strs ) {
2005 AptxUtil.launchWebBrowser( new URI( uri_str ),
2008 catch ( final IOException e ) {
2009 AptxUtil.showErrorMessage( this, e.toString() );
2010 e.printStackTrace();
2012 catch ( final URISyntaxException e ) {
2013 AptxUtil.showErrorMessage( this, e.toString() );
2014 e.printStackTrace();
2019 cannotOpenBrowserWarningMessage( "PDB" );
2023 final private void openSeqWeb( final PhylogenyNode node ) {
2024 if ( ForesterUtil.isEmpty( isCanOpenSeqWeb( node ) ) ) {
2025 cannotOpenBrowserWarningMessage( "sequence" );
2028 final String uri_str = TreePanelUtil.createUriForSeqWeb( node, getConfiguration(), this );
2029 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2031 AptxUtil.launchWebBrowser( new URI( uri_str ),
2035 catch ( final IOException e ) {
2036 AptxUtil.showErrorMessage( this, e.toString() );
2037 e.printStackTrace();
2039 catch ( final URISyntaxException e ) {
2040 AptxUtil.showErrorMessage( this, e.toString() );
2041 e.printStackTrace();
2045 cannotOpenBrowserWarningMessage( "sequence" );
2049 final private void openTaxWeb( final PhylogenyNode node ) {
2050 if ( !isCanOpenTaxWeb( node ) ) {
2051 cannotOpenBrowserWarningMessage( "taxonomic" );
2054 String uri_str = null;
2055 final Taxonomy tax = node.getNodeData().getTaxonomy();
2056 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2057 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
2059 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
2061 catch ( final URISyntaxException e ) {
2062 AptxUtil.showErrorMessage( this, e.toString() );
2064 e.printStackTrace();
2067 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2068 && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
2069 && ( tax.getIdentifier().getProvider().equalsIgnoreCase( "ncbi" )
2070 || tax.getIdentifier().getProvider().equalsIgnoreCase( "uniprot" ) ) ) {
2072 uri_str = "http://www.uniprot.org/taxonomy/"
2073 + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF_8 );
2075 catch ( final UnsupportedEncodingException e ) {
2076 AptxUtil.showErrorMessage( this, e.toString() );
2077 e.printStackTrace();
2080 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
2082 uri_str = "http://www.uniprot.org/taxonomy/?query="
2083 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF_8 );
2085 catch ( final UnsupportedEncodingException e ) {
2086 AptxUtil.showErrorMessage( this, e.toString() );
2087 e.printStackTrace();
2090 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
2092 uri_str = "http://www.uniprot.org/taxonomy/?query="
2093 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF_8 );
2095 catch ( final UnsupportedEncodingException e ) {
2096 AptxUtil.showErrorMessage( this, e.toString() );
2097 e.printStackTrace();
2100 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
2102 uri_str = "http://www.uniprot.org/taxonomy/?query="
2103 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF_8 );
2105 catch ( final UnsupportedEncodingException e ) {
2106 AptxUtil.showErrorMessage( this, e.toString() );
2107 e.printStackTrace();
2110 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2112 AptxUtil.launchWebBrowser( new URI( uri_str ),
2115 catch ( final IOException e ) {
2116 AptxUtil.showErrorMessage( this, e.toString() );
2117 e.printStackTrace();
2119 catch ( final URISyntaxException e ) {
2120 AptxUtil.showErrorMessage( this, e.toString() );
2121 e.printStackTrace();
2125 cannotOpenBrowserWarningMessage( "taxonomic" );
2129 final private void paintBranchLength( final Graphics2D g,
2130 final PhylogenyNode node,
2131 final boolean to_pdf,
2132 final boolean to_graphics_file ) {
2133 g.setFont( getTreeFontSet().getSmallFont() );
2134 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2135 g.setColor( Color.BLACK );
2138 g.setColor( getTreeColorSet().getBranchLengthColor() );
2140 if ( !node.isRoot() ) {
2141 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2142 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2143 node.getParent().getXcoord() + EURO_D,
2144 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2147 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2148 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2149 node.getParent().getXcoord() + ROUNDED_D,
2150 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2154 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2155 node.getParent().getXcoord() + 3,
2156 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2161 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2163 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2168 final private void paintBranchLite( final Graphics2D g,
2173 final PhylogenyNode node ) {
2174 g.setColor( getTreeColorSet().getOvColor() );
2175 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2176 drawLine( x1, y1, x2, y2, g );
2178 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2179 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2180 ( g ).draw( _quad_curve );
2182 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2183 final float dx = x2 - x1;
2184 final float dy = y2 - y1;
2185 _cubic_curve.setCurve( x1,
2193 ( g ).draw( _cubic_curve );
2196 final float x2a = x2;
2197 final float x1a = x1;
2198 // draw the vertical line
2199 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
2200 drawLine( x1, y1, x1, y2, g );
2202 // draw the horizontal line
2203 drawLine( x1a, y2, x2a, y2, g );
2208 * Paint a branch which consists of a vertical and a horizontal bar
2209 * @param is_ind_found_nodes
2211 final private void paintBranchRectangular( final Graphics2D g,
2216 final PhylogenyNode node,
2217 final boolean to_pdf,
2218 final boolean to_graphics_file ) {
2219 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
2220 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2221 drawLine( x1, y1, x2, y2, g );
2223 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2224 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2225 g.draw( _quad_curve );
2227 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2228 final float dx = x2 - x1;
2229 final float dy = y2 - y1;
2230 _cubic_curve.setCurve( x1,
2238 g.draw( _cubic_curve );
2241 final float x2a = x2;
2242 final float x1a = x1;
2244 if ( node.isFirstChildNode() || node.isLastChildNode()
2245 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2246 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2247 if ( !to_graphics_file && !to_pdf
2248 && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) )
2249 && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) )
2250 || ( ( y2 > ( getVisibleRect().getMaxY() + 20 ) )
2251 && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) {
2255 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2256 float x2c = x1 + EURO_D;
2260 drawLine( x1, y1, x2c, y2, g );
2262 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2264 y2_r = y2 - ROUNDED_D;
2268 drawLine( x1, y1, x1, y2_r, g );
2271 y2_r = y2 + ROUNDED_D;
2275 drawLine( x1, y1, x1, y2_r, g );
2279 drawLine( x1, y1, x1, y2, g );
2283 // draw the horizontal line
2284 if ( !to_graphics_file && !to_pdf && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) )
2285 || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) {
2289 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
2290 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2291 x1_r = x1a + ROUNDED_D;
2293 drawLine( x1_r, y2, x2a, y2, g );
2296 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2297 final float x1c = x1a + EURO_D;
2299 drawLine( x1c, y2, x2a, y2, g );
2303 drawLine( x1a, y2, x2a, y2, g );
2307 final double w = PhylogenyMethods.getBranchWidthValue( node );
2308 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2309 x1_r = x1a + ROUNDED_D;
2311 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
2314 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2315 final float x1c = x1a + EURO_D;
2317 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
2321 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
2324 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2329 final double diff = y2 - y2_r;
2330 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
2333 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
2338 if ( node.isExternal() ) {
2339 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file );
2343 final private double paintCirculars( final PhylogenyNode n,
2344 final Phylogeny phy,
2345 final float center_x,
2346 final float center_y,
2347 final double radius,
2348 final boolean radial_labels,
2350 final boolean to_pdf,
2351 final boolean to_graphics_file ) {
2352 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
2353 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
2354 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
2356 return _urt_nodeid_angle_map.get( n.getId() );
2359 final List<PhylogenyNode> descs = n.getDescendants();
2361 for( final PhylogenyNode desc : descs ) {
2362 sum += paintCirculars( desc,
2373 if ( !n.isRoot() ) {
2374 r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
2376 final double theta = sum / descs.size();
2377 n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) );
2378 n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) );
2379 _urt_nodeid_angle_map.put( n.getId(), theta );
2380 for( final PhylogenyNode desc : descs ) {
2381 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
2387 final private void paintCircularsLite( final PhylogenyNode n,
2388 final Phylogeny phy,
2392 final Graphics2D g ) {
2393 if ( n.isExternal() ) {
2397 final List<PhylogenyNode> descs = n.getDescendants();
2398 for( final PhylogenyNode desc : descs ) {
2399 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
2402 if ( !n.isRoot() ) {
2403 r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
2405 final double theta = _urt_nodeid_angle_map.get( n.getId() );
2406 n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) );
2407 n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) );
2408 for( final PhylogenyNode desc : descs ) {
2409 paintBranchCircularLite( n, desc, g );
2414 final private void paintCollapsedNode( final Graphics2D g,
2415 final PhylogenyNode node,
2416 final boolean to_graphics_file,
2417 final boolean to_pdf,
2418 final boolean is_in_found_nodes ) {
2420 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2423 else if ( is_in_found_nodes ) {
2424 c = getColorForFoundNode( node );
2426 else if ( getControlPanel().isColorAccordingToSequence() ) {
2427 c = getSequenceBasedColor( node );
2429 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2430 c = getTaxonomyBasedColor( node );
2432 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
2433 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2434 c = PhylogenyMethods.getBranchColorValue( node );
2436 else if ( to_pdf ) {
2437 g.setColor( getTreeColorSet().getBranchColorForPdf() );
2440 c = getTreeColorSet().getCollapseFillColor();
2442 double d = node.getAllExternalDescendants().size();
2445 if ( getControlPanel().isDrawPhylogram() ) {
2447 d = 0.75 * _y_distance;
2450 d = 0.25 * Math.log10( d ) * _y_distance;
2452 final float half_box_size = 0.5f * getOptions().getDefaultNodeShapeSize();
2453 if ( d < half_box_size ) {
2457 final float xx = node.getXcoord() - ( getOptions().getDefaultNodeShapeSize() );
2458 xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1;
2459 _polygon.moveTo( xxx, node.getYcoord() + 0.5 );
2460 _polygon.lineTo( xxx, node.getYcoord() - 0.5 );
2461 s = _options.isCollapsedWithAverageHeigh()
2462 ? PhylogenyMethods.calculateAverageTreeHeight( node ) * _x_correction_factor : 1;
2463 _polygon.lineTo( node.getXcoord() + s, node.getYcoord() - d );
2464 _polygon.lineTo( node.getXcoord() + s, node.getYcoord() + d );
2465 _polygon.closePath();
2472 d = ( Math.log10( d ) * _y_distance ) / 2.5;
2474 final int box_size = getOptions().getDefaultNodeShapeSize() + 1;
2475 if ( d < box_size ) {
2478 final float xx = node.getXcoord() - ( 2 * box_size );
2479 xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1;
2481 _polygon.moveTo( xxx, node.getYcoord() );
2482 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d );
2483 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d );
2484 _polygon.closePath();
2486 if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) {
2490 else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.NONE ) {
2491 g.setColor( getBackground() );
2496 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2497 g.setPaint( new GradientPaint( xxx,
2501 ( float ) ( node.getYcoord() - d ),
2508 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes, s );
2511 final private void paintConfidenceValues( final Graphics2D g,
2512 final PhylogenyNode node,
2513 final boolean to_pdf,
2514 final boolean to_graphics_file ) {
2515 final List<Confidence> confidences = node.getBranchData().getConfidences();
2516 boolean not_first = false;
2517 Collections.sort( confidences );
2518 final StringBuilder sb = new StringBuilder();
2519 for( final Confidence confidence : confidences ) {
2520 if ( ForesterUtil.isEmpty( SHOW_ONLY_THIS_CONF_TYPE ) || ( !ForesterUtil.isEmpty( confidence.getType() )
2521 && confidence.getType().equalsIgnoreCase( SHOW_ONLY_THIS_CONF_TYPE ) ) ) {
2522 final double value = confidence.getValue();
2523 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2524 if ( value < getOptions().getMinConfidenceValue() ) {
2533 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil
2534 .round( value, getOptions().getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2535 if ( getOptions().isShowConfidenceStddev() ) {
2536 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2538 sb.append( FORMATTER_CONFIDENCE
2539 .format( ForesterUtil.round( confidence.getStandardDeviation(),
2541 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2548 if ( sb.length() > 0 ) {
2549 final float parent_x = node.getParent().getXcoord();
2550 float x = node.getXcoord();
2551 g.setFont( getTreeFontSet().getSmallFont() );
2552 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2555 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2558 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2559 g.setColor( Color.BLACK );
2562 g.setColor( getTreeColorSet().getConfidenceColor() );
2564 final String conf_str = sb.toString();
2565 TreePanel.drawString( conf_str,
2566 parent_x + ( ( x - parent_x
2567 - getTreeFontSet().getFontMetricsSmall().stringWidth( conf_str ) ) / 2 ),
2568 ( node.getYcoord() + getTreeFontSet().getSmallMaxAscent() ) - 1,
2573 final private void paintGainedAndLostCharacters( final Graphics2D g,
2574 final PhylogenyNode node,
2575 final String gained,
2576 final String lost ) {
2577 if ( node.getParent() != null ) {
2578 final float parent_x = node.getParent().getXcoord();
2579 final float x = node.getXcoord();
2580 g.setFont( getTreeFontSet().getLargeFont() );
2581 g.setColor( getTreeColorSet().getGainedCharactersColor() );
2582 if ( AptxConstants.SPECIAL_CUSTOM ) {
2583 g.setColor( Color.BLUE );
2585 TreePanel.drawString( gained,
2586 parent_x + ( ( x - parent_x
2587 - getFontMetricsForLargeDefaultFont().stringWidth( gained ) ) / 2 ),
2588 ( node.getYcoord() - getFontMetricsForLargeDefaultFont().getMaxDescent() ),
2590 g.setColor( getTreeColorSet().getLostCharactersColor() );
2591 TreePanel.drawString( lost,
2592 parent_x + ( ( x - parent_x
2593 - getFontMetricsForLargeDefaultFont().stringWidth( lost ) ) / 2 ),
2594 ( node.getYcoord() + getFontMetricsForLargeDefaultFont().getMaxAscent() ),
2599 private void paintMolecularSequences( final Graphics2D g, final PhylogenyNode node, final boolean to_pdf ) {
2600 final RenderableMsaSequence rs = RenderableMsaSequence
2601 .createInstance( node.getNodeData().getSequence().getMolecularSequence(),
2602 node.getNodeData().getSequence().getType(),
2603 getConfiguration() );
2605 final int default_height = 8;
2606 final float y = getYdistance();
2607 final int h = ( y / 2 ) < default_height ? ForesterUtil.roundToInt( y * 2 ) : default_height;
2608 rs.setRenderingHeight( h > 1 ? h : 1 );
2609 if ( getControlPanel().isDrawPhylogram() ) {
2610 rs.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() ) + _length_of_longest_text ),
2611 node.getYcoord() - ( h / 2.0f ),
2617 rs.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text,
2618 node.getYcoord() - ( h / 2.0f ),
2627 * Draw a box at the indicated node.
2634 final private void paintNodeBox( final float x,
2636 final PhylogenyNode node,
2638 final boolean to_pdf,
2639 final boolean to_graphics_file ) {
2640 if ( node.isCollapse() ) {
2643 // if this node should be highlighted, do so
2644 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
2645 g.setColor( getTreeColorSet().getFoundColor0() );
2646 drawOval( x - 8, y - 8, 16, 16, g );
2647 drawOval( x - 9, y - 8, 17, 17, g );
2648 drawOval( x - 9, y - 9, 18, 18, g );
2650 if ( ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) )
2651 || ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() )
2652 || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() )
2653 || ( getOptions().isShowDefaultNodeShapesForMarkedNodes()
2654 && ( node.getNodeData().getNodeVisualData() != null )
2655 && ( !node.getNodeData().getNodeVisualData().isEmpty() ) )
2656 || ( getControlPanel().isUseVisualStyles()
2657 && ( ( node.getNodeData().getNodeVisualData() != null )
2658 && ( ( node.getNodeData().getNodeVisualData().getNodeColor() != null )
2659 || ( node.getNodeData().getNodeVisualData()
2660 .getSize() != NodeVisualData.DEFAULT_SIZE )
2661 || ( node.getNodeData().getNodeVisualData().getFillType() != NodeFill.DEFAULT )
2662 || ( node.getNodeData().getNodeVisualData()
2663 .getShape() != NodeShape.DEFAULT ) ) ) )
2664 || ( getControlPanel().isEvents() && node.isHasAssignedEvent()
2665 && ( node.getNodeData().getEvent().isDuplication()
2666 || node.getNodeData().getEvent().isSpeciation()
2667 || node.getNodeData().getEvent().isSpeciationOrDuplication() ) ) ) {
2668 NodeVisualData vis = null;
2669 if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
2670 && ( !node.getNodeData().getNodeVisualData().isEmpty() ) ) {
2671 vis = node.getNodeData().getNodeVisualData();
2673 float box_size = getOptions().getDefaultNodeShapeSize();
2674 if ( ( vis != null ) && ( vis.getSize() != NodeVisualData.DEFAULT_SIZE ) ) {
2675 box_size = vis.getSize();
2677 final float half_box_size = box_size / 2.0f;
2678 Color outline_color = null;
2679 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2680 outline_color = Color.BLACK;
2682 else if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
2683 outline_color = getColorForFoundNode( node );
2685 else if ( vis != null ) {
2686 if ( vis.getNodeColor() != null ) {
2687 outline_color = vis.getNodeColor();
2689 else if ( vis.getFontColor() != null ) {
2690 outline_color = vis.getFontColor();
2693 else if ( getControlPanel().isEvents() && TreePanelUtil.isHasAssignedEvent( node ) ) {
2694 final Event event = node.getNodeData().getEvent();
2695 if ( event.isDuplication() ) {
2696 outline_color = getTreeColorSet().getDuplicationBoxColor();
2698 else if ( event.isSpeciation() ) {
2699 outline_color = getTreeColorSet().getSpecBoxColor();
2701 else if ( event.isSpeciationOrDuplication() ) {
2702 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
2705 if ( outline_color == null ) {
2706 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
2707 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
2708 outline_color = getTreeColorSet().getBranchColorForPdf();
2711 NodeShape shape = null;
2712 if ( vis != null ) {
2713 if ( vis.getShape() == NodeShape.CIRCLE ) {
2714 shape = NodeShape.CIRCLE;
2716 else if ( vis.getShape() == NodeShape.RECTANGLE ) {
2717 shape = NodeShape.RECTANGLE;
2720 if ( shape == null ) {
2721 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
2722 shape = NodeShape.CIRCLE;
2724 else if ( getOptions().getDefaultNodeShape() == NodeShape.RECTANGLE ) {
2725 shape = NodeShape.RECTANGLE;
2728 NodeFill fill = null;
2729 if ( vis != null ) {
2730 if ( vis.getFillType() == NodeFill.SOLID ) {
2731 fill = NodeFill.SOLID;
2733 else if ( vis.getFillType() == NodeFill.NONE ) {
2734 fill = NodeFill.NONE;
2736 else if ( vis.getFillType() == NodeFill.GRADIENT ) {
2737 fill = NodeFill.GRADIENT;
2740 if ( fill == null ) {
2741 if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) {
2742 fill = NodeFill.SOLID;
2744 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
2745 fill = NodeFill.NONE;
2747 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2748 fill = NodeFill.GRADIENT;
2751 Color vis_fill_color = null;
2752 if ( ( vis != null ) && ( vis.getNodeColor() != null ) ) {
2753 vis_fill_color = vis.getNodeColor();
2755 if ( shape == NodeShape.CIRCLE ) {
2756 if ( fill == NodeFill.GRADIENT ) {
2757 drawOvalGradient( x - half_box_size,
2762 to_pdf ? Color.WHITE : outline_color,
2763 to_pdf ? outline_color : getBackground(),
2766 else if ( fill == NodeFill.NONE ) {
2767 Color background = getBackground();
2769 background = Color.WHITE;
2771 drawOvalGradient( x - half_box_size,
2780 else if ( fill == NodeVisualData.NodeFill.SOLID ) {
2781 if ( vis_fill_color != null ) {
2782 g.setColor( vis_fill_color );
2785 g.setColor( outline_color );
2787 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2790 else if ( shape == NodeVisualData.NodeShape.RECTANGLE ) {
2791 if ( fill == NodeVisualData.NodeFill.GRADIENT ) {
2792 drawRectGradient( x - half_box_size,
2797 to_pdf ? Color.WHITE : outline_color,
2798 to_pdf ? outline_color : getBackground(),
2801 else if ( fill == NodeVisualData.NodeFill.NONE ) {
2802 Color background = getBackground();
2804 background = Color.WHITE;
2806 drawRectGradient( x - half_box_size,
2815 else if ( fill == NodeVisualData.NodeFill.SOLID ) {
2816 if ( vis_fill_color != null ) {
2817 g.setColor( vis_fill_color );
2820 g.setColor( outline_color );
2822 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2828 final private int paintNodeData( final Graphics2D g,
2829 final PhylogenyNode node,
2830 final boolean to_graphics_file,
2831 final boolean to_pdf,
2832 final boolean is_in_found_nodes,
2833 final double add ) {
2834 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
2837 if ( getControlPanel().isWriteBranchLengthValues()
2838 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2839 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
2840 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
2841 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
2842 paintBranchLength( g, node, to_pdf, to_graphics_file );
2844 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
2852 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
2853 if ( getControlPanel().isShowTaxonomyImages() && ( getImageMap() != null ) && !getImageMap().isEmpty()
2854 && node.getNodeData().isHasTaxonomy() && ( ( node.getNodeData().getTaxonomy().getUris() != null )
2855 && !node.getNodeData().getTaxonomy().getUris().isEmpty() ) ) {
2856 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
2858 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
2859 || getControlPanel().isShowTaxonomyCommonNames() || getControlPanel().isShowTaxonomyRank() )
2860 && node.getNodeData().isHasTaxonomy() ) {
2861 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
2863 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
2864 final boolean saw_species = _sb.length() > 0;
2866 nodeDataAsSB( node, _sb );
2867 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
2868 if ( ( _sb.length() == 0 ) && !saw_species ) {
2869 if ( getOptions().isShowAbbreviatedLabelsForCollapsedNodes()
2870 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
2871 || getControlPanel().isShowSeqNames() || getControlPanel().isShowNodeNames() ) ) {
2872 final PhylogenyNode first = PhylogenyMethods.getFirstExternalNode( node );
2873 final PhylogenyNode last = PhylogenyMethods.getLastExternalNode( node );
2874 if ( getControlPanel().isShowTaxonomyCode() && first.getNodeData().isHasTaxonomy()
2875 && last.getNodeData().isHasTaxonomy()
2876 && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getTaxonomyCode() )
2877 && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
2878 addLabelForCollapsed( first.getNodeData().getTaxonomy().getTaxonomyCode(),
2879 last.getNodeData().getTaxonomy().getTaxonomyCode(),
2880 node.getAllExternalDescendants().size() );
2882 else if ( getControlPanel().isShowTaxonomyScientificNames() && first.getNodeData().isHasTaxonomy()
2883 && last.getNodeData().isHasTaxonomy()
2884 && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getScientificName() )
2885 && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getScientificName() ) ) {
2886 addLabelForCollapsed( first.getNodeData().getTaxonomy().getScientificName(),
2887 last.getNodeData().getTaxonomy().getScientificName(),
2888 node.getAllExternalDescendants().size() );
2890 else if ( getControlPanel().isShowSeqNames() && first.getNodeData().isHasSequence()
2891 && last.getNodeData().isHasSequence()
2892 && !ForesterUtil.isEmpty( first.getNodeData().getSequence().getName() )
2893 && !ForesterUtil.isEmpty( last.getNodeData().getSequence().getName() ) ) {
2894 addLabelForCollapsed( first.getNodeData().getSequence().getName(),
2895 last.getNodeData().getSequence().getName(),
2896 node.getAllExternalDescendants().size() );
2898 else if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( first.getName() )
2899 && !ForesterUtil.isEmpty( last.getName() ) ) {
2900 addLabelForCollapsed( first.getName(),
2902 node.getAllExternalDescendants().size() );
2906 else if ( ( _sb.length() > 0 ) || saw_species ) {
2907 // _sb.setLength( 0 );
2909 _sb.append( node.getAllExternalDescendants().size() );
2914 // _sb.setLength( 0 );
2916 // nodeDataAsSB( node, _sb );
2917 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
2918 float down_shift_factor = 3.0f;
2919 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
2920 down_shift_factor = 1;
2923 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
2924 && ( node.isExternal() || node.isCollapse() ) ) {
2925 pos_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
2926 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x + ( 2 * TreePanel.MOVE ) + getXdistance()
2930 pos_x = node.getXcoord() + x + 2 + half_box_size;
2933 if ( !using_visual_font ) {
2934 pos_y = ( node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ) );
2937 pos_y = ( node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / down_shift_factor ) );
2939 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
2940 && ( node.isExternal() || node.isCollapse() ) ) {
2941 drawConnection( node.getXcoord(), pos_x - x, node.getYcoord(), 5, 20, g, to_pdf );
2942 if ( node.isCollapse() ) {
2946 final String sb_str = _sb.toString();
2947 // GUILHEM_BEG ______________
2948 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
2949 && ( _query_sequence != null ) ) {
2950 x = paintSequenceRelation( g, node, x, half_box_size, pos_x, pos_y, sb_str );
2952 // GUILHEM_END _____________
2953 if ( sb_str.length() > 0 ) {
2954 if ( !isAllowAttributedStrings() ) {
2955 TreePanel.drawString( sb_str, pos_x, pos_y, g );
2958 drawStringX( sb_str, pos_x, pos_y, g );
2961 if ( _sb.length() > 0 ) {
2962 if ( !using_visual_font && !is_in_found_nodes ) {
2963 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
2966 x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
2969 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
2970 && ( node.getNodeData().getSequence().getAnnotations() != null )
2971 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
2972 final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
2973 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2974 g.setColor( Color.BLACK );
2976 else if ( getControlPanel().isColorAccordingToAnnotation() ) {
2977 g.setColor( calculateColorForAnnotation( ann ) );
2979 final String ann_str = TreePanelUtil.createAnnotationString( ann,
2980 getOptions().isShowAnnotationRefSource() );
2981 TreePanel.drawString( ann_str,
2982 node.getXcoord() + x + 3 + half_box_size,
2984 + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ),
2987 _sb.append( ann_str );
2988 if ( _sb.length() > 0 ) {
2989 if ( !using_visual_font && !is_in_found_nodes ) {
2990 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
2993 x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
2997 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2998 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2999 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3000 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
3001 && node.getNodeData().isHasBinaryCharacters() ) {
3002 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3003 g.setColor( Color.BLACK );
3006 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
3008 if ( getControlPanel().isShowBinaryCharacters() ) {
3009 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
3011 node.getXcoord() + x + 1 + half_box_size,
3012 node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
3013 / down_shift_factor ),
3015 paintGainedAndLostCharacters( g,
3017 node.getNodeData().getBinaryCharacters()
3018 .getGainedCharactersAsStringBuffer().toString(),
3019 node.getNodeData().getBinaryCharacters()
3020 .getLostCharactersAsStringBuffer().toString() );
3023 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
3024 node.getXcoord() + x + 4 + half_box_size,
3025 node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
3026 / down_shift_factor ),
3028 paintGainedAndLostCharacters( g,
3030 "+" + node.getNodeData().getBinaryCharacters().getGainedCount(),
3031 "-" + node.getNodeData().getBinaryCharacters().getLostCount() );
3038 private final int paintSequenceRelation( final Graphics2D g,
3039 final PhylogenyNode node,
3041 final int half_box_size,
3044 final String sb_str ) {
3045 int nodeTextBoundsWidth = 0;
3046 if ( sb_str.length() > 0 ) {
3047 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
3048 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
3050 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
3051 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
3052 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
3053 g.setColor( getTreeColorSet().getBackgroundColor() );
3057 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
3058 for( final SequenceRelation seqRelation : seqRelations ) {
3059 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence )
3060 || seqRelation.getRef1().isEqual( _query_sequence ) )
3061 && seqRelation.getType()
3062 .equals( getControlPanel().getSequenceRelationTypeBox().getSelectedItem() );
3063 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
3064 final double linePosX = node.getXcoord() + 2 + half_box_size;
3065 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence()
3066 || ( seqRelation.getConfidence() == null ) ) ? null
3067 : " (" + seqRelation.getConfidence().getValue() + ")";
3068 if ( sConfidence != null ) {
3069 float confidenceX = pos_x;
3070 if ( sb_str.length() > 0 ) {
3071 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
3072 + CONFIDENCE_LEFT_MARGIN;
3074 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
3075 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
3076 .getBounds().getWidth();
3077 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
3078 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
3081 if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
3083 if ( nodeTextBoundsWidth == 0 ) {
3084 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
3087 nodeTextBoundsWidth += 2;
3089 g.drawLine( ( int ) linePosX + 1,
3091 ( int ) linePosX + x + nodeTextBoundsWidth,
3092 3 + ( int ) pos_y );
3101 private final void drawConnection( final float x1,
3104 final int dist_left,
3105 final int dist_right,
3107 final boolean pdf ) {
3108 if ( ( ( x1 + dist_left ) < ( x2 - dist_right ) ) ) {
3109 final Stroke strok = g.getStroke();
3111 if ( strok == STROKE_005 ) {
3112 g.setStroke( STROKE_001_DASHED );
3114 else if ( strok == STROKE_01 ) {
3115 g.setStroke( STROKE_005_DASHED );
3118 g.setStroke( STROKE_01_DASHED );
3122 g.setColor( lighter( col ) );
3124 drawLine( x1 + dist_left, y, x2 - dist_right, y, g );
3125 g.setStroke( strok );
3132 public static Color lighter( final Color color ) {
3133 if ( ( color.getRed() == 0 ) && ( color.getGreen() == 0 ) && ( color.getBlue() == 0 ) ) {
3134 return new Color( 200, 200, 200 );
3141 private final void addLabelForCollapsed( final String first, final String last, final int size ) {
3142 _sb.append( first.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? first
3143 : first.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
3144 _sb.append( " ... " );
3145 _sb.append( last.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? last
3146 : last.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
3147 _sb.append( " (" + size + ")" );
3150 private final boolean isAllowAttributedStrings() {
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 ) {
3166 if ( node.getNodeData().isHasTaxonomy()
3167 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
3168 || getControlPanel().isShowTaxonomyCommonNames() ) ) {
3169 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3170 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3171 _sb.append( taxonomy.getTaxonomyCode() );
3174 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3175 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3176 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3177 _sb.append( taxonomy.getScientificName() );
3179 _sb.append( taxonomy.getCommonName() );
3182 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3183 _sb.append( taxonomy.getScientificName() );
3186 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3187 _sb.append( taxonomy.getCommonName() );
3191 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3192 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3193 _sb.append( taxonomy.getScientificName() );
3197 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3198 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3199 _sb.append( taxonomy.getCommonName() );
3204 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3206 _sb.append( node.getAllExternalDescendants().size() );
3209 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3210 if ( _sb.length() > 0 ) {
3213 _sb.append( node.getName() );
3215 if ( node.getNodeData().isHasSequence() ) {
3216 if ( getControlPanel().isShowSequenceAcc()
3217 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3218 if ( _sb.length() > 0 ) {
3221 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3222 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3225 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3227 if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3228 if ( _sb.length() > 0 ) {
3231 _sb.append( node.getNodeData().getSequence().getName() );
3234 //g.setFont( getTreeFontSet().getLargeFont() );
3235 //if ( is_in_found_nodes ) {
3236 // g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3238 if ( _sb.length() > 1 ) {
3239 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
3240 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
3241 final String sb_str = _sb.toString();
3243 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3244 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
3247 m = ( float ) ( ur_angle % TWO_PI );
3249 _at = g.getTransform();
3250 boolean need_to_reset = false;
3251 final float x_coord = node.getXcoord();
3253 if ( !using_visual_font ) {
3254 y_coord = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / 3.0f );
3257 y_coord = node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / 3.0f );
3259 if ( radial_labels ) {
3260 need_to_reset = true;
3261 boolean left = false;
3262 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3266 g.rotate( m, x_coord, node.getYcoord() );
3268 if ( !using_visual_font ) {
3269 g.translate( -( getFontMetricsForLargeDefaultFont().getStringBounds( sb_str, g ).getWidth() ),
3273 g.translate( -( getFontMetrics( g.getFont() ).getStringBounds( sb_str, g ).getWidth() ), 0 );
3278 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3279 need_to_reset = true;
3280 if ( !using_visual_font ) {
3281 g.translate( -getFontMetricsForLargeDefaultFont().getStringBounds( sb_str, g ).getWidth(), 0 );
3284 g.translate( -getFontMetrics( g.getFont() ).getStringBounds( sb_str, g ).getWidth(), 0 );
3288 TreePanel.drawString( sb_str, x_coord, y_coord, g );
3289 if ( need_to_reset ) {
3290 g.setTransform( _at );
3295 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
3296 if ( node.isCollapse() ) {
3299 if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
3300 g.setColor( getColorForFoundNode( node ) );
3301 drawRectFilled( node.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3302 node.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3303 OVERVIEW_FOUND_NODE_BOX_SIZE,
3304 OVERVIEW_FOUND_NODE_BOX_SIZE,
3308 if ( !node.isExternal() && !node.isCollapse() ) {
3309 boolean first_child = true;
3311 //final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3312 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3313 final PhylogenyNode child_node = node.getChildNode( i );
3314 final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3315 if ( first_child ) {
3316 first_child = false;
3317 y2 = node.getYSecondary() - ( getOvYDistance()
3318 * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3321 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3323 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
3324 new_x = x2 + node.getXSecondary();
3325 final float diff_y = node.getYSecondary() - y2;
3326 final float diff_x = node.getXSecondary() - new_x;
3327 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
3328 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
3330 child_node.setXSecondary( new_x );
3331 child_node.setYSecondary( y2 );
3332 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3337 final private void paintNodeRectangular( final Graphics2D g,
3338 final PhylogenyNode node,
3339 final boolean to_pdf,
3340 final boolean dynamically_hide,
3341 final int dynamic_hiding_factor,
3342 final boolean to_graphics_file,
3343 final boolean disallow_shortcutting ) {
3344 final boolean is_in_found_nodes = isInFoundNodes( node ) || isInCurrentExternalNodes( node );
3345 if ( node.isCollapse() ) {
3346 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) ) {
3347 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3351 if ( node.isExternal() ) {
3352 ++_external_node_index;
3354 // Confidence values
3355 if ( getControlPanel().isShowConfidenceValues() && !node.isExternal() && !node.isRoot()
3356 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
3357 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3358 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3359 && node.getBranchData().isHasConfidences() ) {
3360 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
3362 // Draw a line to root:
3363 if ( node.isRoot() && _phylogeny.isRooted() ) {
3364 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
3367 float new_x_min = Float.MAX_VALUE;
3368 float min_dist = 1.5f;
3369 if ( !disallow_shortcutting ) {
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 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3384 final PhylogenyNode child_node = node.getChildNode( i );
3385 final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3386 if ( first_child ) {
3387 first_child = false;
3388 y2 = node.getYcoord() - ( _y_distance
3389 * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3392 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3394 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
3395 new_x = x2 + node.getXcoord();
3396 if ( dynamically_hide && ( x2 < new_x_min ) ) {
3399 final float diff_y = node.getYcoord() - y2;
3400 final float diff_x = node.getXcoord() - new_x;
3401 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
3402 || ( diff_x < -min_dist ) ) {
3403 paintBranchRectangular( g,
3412 child_node.setXcoord( new_x );
3413 child_node.setYcoord( y2 );
3414 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3416 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file );
3418 if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
3419 && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
3420 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
3421 paintMolecularSequences( g, node, to_pdf );
3423 if ( dynamically_hide && !is_in_found_nodes && ( ( node.isExternal()
3424 && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) )
3425 || ( !node.isExternal() && ( ( new_x_min < 20 )
3426 || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getFontMetricsForLargeDefaultFont()
3427 .getHeight() ) ) ) ) ) {
3430 final int x = paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes, 0 );
3431 paintNodeWithRenderableData( x, g, node, to_graphics_file, to_pdf );
3434 final private void paintNodeWithRenderableData( final int x,
3436 final PhylogenyNode node,
3437 final boolean to_graphics_file,
3438 final boolean to_pdf ) {
3439 if ( isNodeDataInvisible( node ) && !( to_graphics_file || to_pdf ) ) {
3442 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
3445 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3446 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) && ( node.getNodeData()
3447 .getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
3448 RenderableDomainArchitecture rds = null;
3450 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
3452 catch ( final ClassCastException cce ) {
3453 cce.printStackTrace();
3455 if ( rds != null ) {
3456 final int default_height = 7;
3457 float y = getYdistance();
3458 if ( getControlPanel().isDynamicallyHideData() ) {
3459 y = getTreeFontSet().getFontMetricsLarge().getHeight();
3461 final int h = y < default_height ? ForesterUtil.roundToInt( y ) : default_height;
3462 rds.setRenderingHeight( h > 1 ? h : 2 );
3463 if ( getControlPanel().isDrawPhylogram() ) {
3464 if ( getOptions().isLineUpRendarableNodeData() ) {
3465 if ( getOptions().isRightLineUpDomains() ) {
3466 rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3467 + _length_of_longest_text
3468 + ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ) ),
3469 node.getYcoord() - ( h / 2.0f ),
3475 rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3476 + _length_of_longest_text ), node.getYcoord() - ( h / 2.0f ), g, this, to_pdf );
3480 rds.render( node.getXcoord() + x, node.getYcoord() - ( h / 2.0f ), g, this, to_pdf );
3484 if ( getOptions().isRightLineUpDomains() ) {
3485 rds.render( ( ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text )
3486 - 20 ) + ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ),
3487 node.getYcoord() - ( h / 2.0f ),
3493 rds.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text,
3494 node.getYcoord() - ( h / 2.0f ),
3502 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
3503 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
3504 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
3505 getStatisticsForExpressionValues(),
3506 getConfiguration() );
3508 double domain_add = 0;
3509 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3510 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
3511 domain_add = _domain_structure_width + 10;
3513 if ( getControlPanel().isDrawPhylogram() ) {
3514 rv.render( ( float ) ( node.getXcoord() + x + domain_add ), node.getYcoord() - 3, g, this, to_pdf );
3517 rv.render( ( float ) ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text
3518 + domain_add ), node.getYcoord() - 3, g, this, to_pdf );
3522 //if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
3523 // && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
3524 // && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
3525 // paintMolecularSequences( g, node, to_pdf );
3529 final private void paintOvRectangle( final Graphics2D g ) {
3530 final float w_ratio = ( ( float ) getWidth() ) / getVisibleRect().width;
3531 final float h_ratio = ( ( float ) getHeight() ) / getVisibleRect().height;
3532 final float x_ratio = ( ( float ) getWidth() ) / getVisibleRect().x;
3533 final float y_ratio = ( ( float ) getHeight() ) / getVisibleRect().y;
3534 final float width = getOvMaxWidth() / w_ratio;
3535 final float height = getOvMaxHeight() / h_ratio;
3536 final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio );
3537 final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio );
3538 g.setColor( getTreeColorSet().getFoundColor0() );
3539 getOvRectangle().setRect( x, y, width, height );
3540 final Stroke s = g.getStroke();
3541 g.setStroke( STROKE_1 );
3542 if ( ( width < 6 ) && ( height < 6 ) ) {
3543 drawRectFilled( x, y, 6, 6, g );
3544 getOvVirtualRectangle().setRect( x, y, 6, 6 );
3546 else if ( width < 6 ) {
3547 drawRectFilled( x, y, 6, height, g );
3548 getOvVirtualRectangle().setRect( x, y, 6, height );
3550 else if ( height < 6 ) {
3551 drawRectFilled( x, y, width, 6, g );
3552 getOvVirtualRectangle().setRect( x, y, width, 6 );
3555 drawRect( x, y, width, height, g );
3556 if ( isInOvRect() ) {
3557 drawRect( x + 1, y + 1, width - 2, height - 2, g );
3559 getOvVirtualRectangle().setRect( x, y, width, height );
3564 final private void paintPhylogenyLite( final Graphics2D g ) {
3565 _phylogeny.getRoot().setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition()
3566 + ( MOVE / ( getVisibleRect().width / getOvRectangle().getWidth() ) ) ) );
3567 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
3568 final Stroke s = g.getStroke();
3569 g.setStroke( STROKE_05 );
3570 for( final PhylogenyNode element : _nodes_in_preorder ) {
3571 paintNodeLite( g, element );
3574 paintOvRectangle( g );
3578 * Paint the root branch. (Differs from others because it will always be a
3579 * single horizontal line).
3580 * @param to_graphics_file
3582 * @return new x1 value
3584 final private void paintRootBranch( final Graphics2D g,
3587 final PhylogenyNode root,
3588 final boolean to_pdf,
3589 final boolean to_graphics_file ) {
3590 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
3591 float d = getXdistance();
3592 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
3593 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
3595 if ( d < MIN_ROOT_LENGTH ) {
3596 d = MIN_ROOT_LENGTH;
3598 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
3599 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
3602 final double w = PhylogenyMethods.getBranchWidthValue( root );
3603 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
3605 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file );
3608 final private void paintScale( final Graphics2D g,
3611 final boolean to_pdf,
3612 final boolean to_graphics_file ) {
3614 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
3616 final int y2 = y1 - 8;
3617 final int y3 = y1 - 4;
3618 g.setFont( getTreeFontSet().getSmallFont() );
3619 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3620 g.setColor( Color.BLACK );
3623 g.setColor( getTreeColorSet().getBranchLengthColor() );
3625 final Stroke s = g.getStroke();
3626 g.setStroke( STROKE_1 );
3627 drawLine( x1, y1, x1, y2, g );
3628 drawLine( x2, y1, x2, y2, g );
3629 drawLine( x1, y3, x2, y3, g );
3630 if ( getScaleLabel() != null ) {
3631 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
3636 final private int paintTaxonomy( final Graphics2D g,
3637 final PhylogenyNode node,
3638 final boolean is_in_found_nodes,
3639 final boolean to_pdf,
3640 final boolean to_graphics_file,
3641 final float x_shift ) {
3642 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3643 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
3644 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getTaxonomyColor() );
3645 float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
3646 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM && node.isExternal() ) {
3647 start_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3648 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift + ( 2 * TreePanel.MOVE ) + getXdistance()
3652 if ( !using_visual_font ) {
3653 start_y = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
3654 / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) );
3657 start_y = node.getYcoord()
3658 + ( getFontMetrics( g.getFont() ).getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) );
3661 nodeTaxonomyDataAsSB( taxonomy, _sb );
3662 final String label = _sb.toString();
3664 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
3665 && ( node.getNodeData().isHasSequence() )
3666 && node.getNodeData().getSequence().equals( _query_sequence ) ) {
3667 // invert font color and background color to show that this is the query sequence
3668 final Rectangle2D nodeTextBounds = new TextLayout( label,
3670 new FontRenderContext( null, false, false ) )
3672 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
3673 g.setColor( getTreeColorSet().getBackgroundColor() );
3676 TreePanel.drawString( label, start_x, start_y, g );
3677 if ( !using_visual_font && !is_in_found_nodes ) {
3678 return getFontMetricsForLargeDefaultFont().stringWidth( label );
3680 return getFontMetrics( g.getFont() ).stringWidth( label );
3683 final private void paintUnrooted( final PhylogenyNode n,
3684 final double low_angle,
3685 final double high_angle,
3686 final boolean radial_labels,
3688 final boolean to_pdf,
3689 final boolean to_graphics_file ) {
3691 n.setXcoord( getWidth() / 2 );
3692 n.setYcoord( getHeight() / 2 );
3694 if ( n.isExternal() ) {
3695 paintNodeDataUnrootedCirc( g,
3700 ( high_angle + low_angle ) / 2,
3701 isInFoundNodes( n ) || isInCurrentExternalNodes( n ) );
3704 final float num_enclosed = n.getNumberOfExternalNodes();
3705 final float x = n.getXcoord();
3706 final float y = n.getYcoord();
3707 double current_angle = low_angle;
3708 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
3709 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
3710 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
3711 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
3712 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3713 final PhylogenyNode desc = n.getChildNode( i );
3714 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
3715 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
3716 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
3717 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
3720 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
3723 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
3726 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3727 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3729 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3730 if ( desc.getDistanceToParent() < 0 ) {
3734 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
3738 length = getUrtFactor();
3740 final double mid_angle = current_angle + ( arc_size / 2 );
3741 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
3742 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
3743 desc.setXcoord( new_x );
3744 desc.setYcoord( new_y );
3745 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
3746 current_angle += arc_size;
3747 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
3748 drawLine( x, y, new_x, new_y, g );
3749 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file );
3752 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file );
3756 final private void paintUnrootedLite( final PhylogenyNode n,
3757 final double low_angle,
3758 final double high_angle,
3760 final float urt_ov_factor ) {
3762 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) );
3763 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) );
3764 n.setXSecondary( x_pos );
3765 n.setYSecondary( y_pos );
3767 if ( n.isExternal() ) {
3770 final float num_enclosed = n.getNumberOfExternalNodes();
3771 final float x = n.getXSecondary();
3772 final float y = n.getYSecondary();
3773 double current_angle = low_angle;
3774 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3775 final PhylogenyNode desc = n.getChildNode( i );
3776 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3777 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3779 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3780 if ( desc.getDistanceToParent() < 0 ) {
3784 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
3788 length = urt_ov_factor;
3790 final double mid_angle = current_angle + ( arc_size / 2 );
3791 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
3792 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
3793 desc.setXSecondary( new_x );
3794 desc.setYSecondary( new_y );
3795 if ( isInFoundNodes( desc ) || isInCurrentExternalNodes( desc ) ) {
3796 g.setColor( getColorForFoundNode( desc ) );
3797 drawRectFilled( desc.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3798 desc.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3799 OVERVIEW_FOUND_NODE_BOX_SIZE,
3800 OVERVIEW_FOUND_NODE_BOX_SIZE,
3802 g.setColor( getTreeColorSet().getOvColor() );
3804 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
3805 current_angle += arc_size;
3806 drawLine( x, y, new_x, new_y, g );
3810 final private void pasteSubtree( final PhylogenyNode node ) {
3811 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3812 errorMessageNoCutCopyPasteInUnrootedDisplay();
3815 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
3816 JOptionPane.showMessageDialog( this,
3817 "No tree in buffer (need to copy or cut a subtree first)",
3818 "Attempt to paste with empty buffer",
3819 JOptionPane.ERROR_MESSAGE );
3822 final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
3823 final Object[] options = { "As sibling", "As descendant", "Cancel" };
3824 final int r = JOptionPane.showOptionDialog( this,
3825 "How to paste subtree" + label + "?",
3827 JOptionPane.CLOSED_OPTION,
3828 JOptionPane.QUESTION_MESSAGE,
3832 boolean paste_as_sibling = true;
3834 paste_as_sibling = false;
3836 else if ( r != 0 ) {
3839 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
3840 buffer_phy.setAllNodesToNotCollapse();
3841 PhylogenyMethods.preOrderReId( buffer_phy );
3842 buffer_phy.setRooted( true );
3843 boolean need_to_show_whole = false;
3844 if ( paste_as_sibling ) {
3845 if ( node.isRoot() ) {
3846 JOptionPane.showMessageDialog( this,
3847 "Cannot paste sibling to root",
3848 "Attempt to paste sibling to root",
3849 JOptionPane.ERROR_MESSAGE );
3852 buffer_phy.addAsSibling( node );
3855 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
3856 need_to_show_whole = true;
3857 _phylogeny = buffer_phy;
3860 buffer_phy.addAsChild( node );
3863 if ( getCopiedAndPastedNodes() == null ) {
3864 setCopiedAndPastedNodes( new HashSet<Long>() );
3866 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
3867 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
3868 for( final PhylogenyNode n : nodes ) {
3869 node_ids.add( n.getId() );
3871 node_ids.add( node.getId() );
3872 getCopiedAndPastedNodes().addAll( node_ids );
3873 setNodeInPreorderToNull();
3874 _phylogeny.externalNodesHaveChanged();
3875 _phylogeny.clearHashIdToNodeMap();
3876 _phylogeny.recalculateNumberOfExternalDescendants( true );
3877 resetNodeIdToDistToLeafMap();
3879 if ( need_to_show_whole ) {
3880 getControlPanel().showWhole();
3885 private final StringBuffer propertiesToString( final PhylogenyNode node ) {
3887 return node.getNodeData().getProperties().asText();
3890 private void setColor( final Graphics2D g,
3891 final PhylogenyNode node,
3892 final boolean to_graphics_file,
3893 final boolean to_pdf,
3894 final boolean is_in_found_nodes,
3895 final Color default_color ) {
3896 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3897 g.setColor( Color.BLACK );
3899 else if ( is_in_found_nodes ) {
3900 g.setColor( getColorForFoundNode( node ) );
3902 else if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
3903 && ( node.getNodeData().getNodeVisualData().getFontColor() != null ) ) {
3904 g.setColor( node.getNodeData().getNodeVisualData().getFontColor() );
3906 else if ( getControlPanel().isColorAccordingToSequence() ) {
3907 g.setColor( getSequenceBasedColor( node ) );
3909 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3910 g.setColor( getTaxonomyBasedColor( node ) );
3912 else if ( getControlPanel().isColorAccordingToAnnotation()
3913 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null )
3914 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
3915 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
3917 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
3918 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3919 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3921 else if ( to_pdf ) {
3922 g.setColor( Color.BLACK );
3925 g.setColor( default_color );
3929 final private void setCopiedAndPastedNodes( final Set<Long> nodeIds ) {
3930 getMainPanel().setCopiedAndPastedNodes( nodeIds );
3933 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
3934 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
3937 private boolean setFont( final Graphics2D g, final PhylogenyNode node, final boolean is_in_found_nodes ) {
3938 Font visual_font = null;
3939 if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null ) ) {
3940 visual_font = node.getNodeData().getNodeVisualData().getFont();
3941 g.setFont( visual_font != null ? visual_font : getTreeFontSet().getLargeFont() );
3944 g.setFont( getTreeFontSet().getLargeFont() );
3946 if ( is_in_found_nodes ) {
3947 g.setFont( g.getFont().deriveFont( Font.BOLD ) );
3949 return visual_font != null;
3952 final private void setInOv( final boolean in_ov ) {
3956 final private void setOvMaxHeight( final float ov_max_height ) {
3957 _ov_max_height = ov_max_height;
3960 final private void setOvMaxWidth( final float ov_max_width ) {
3961 _ov_max_width = ov_max_width;
3964 final private void setOvXcorrectionFactor( final float f ) {
3965 _ov_x_correction_factor = f;
3968 final private void setOvXDistance( final float ov_x_distance ) {
3969 _ov_x_distance = ov_x_distance;
3972 final private void setOvXPosition( final int ov_x_position ) {
3973 _ov_x_position = ov_x_position;
3976 final private void setOvYDistance( final float ov_y_distance ) {
3977 _ov_y_distance = ov_y_distance;
3980 final private void setOvYPosition( final int ov_y_position ) {
3981 _ov_y_position = ov_y_position;
3984 final private void setOvYStart( final int ov_y_start ) {
3985 _ov_y_start = ov_y_start;
3988 final private void setScaleDistance( final double scale_distance ) {
3989 _scale_distance = scale_distance;
3992 final private void setScaleLabel( final String scale_label ) {
3993 _scale_label = scale_label;
3996 private final void setupStroke( final Graphics2D g ) {
3997 if ( getYdistance() < 0.0001 ) {
3998 g.setStroke( STROKE_0025 );
4000 if ( getYdistance() < 0.001 ) {
4001 g.setStroke( STROKE_005 );
4003 else if ( getYdistance() < 0.01 ) {
4004 g.setStroke( STROKE_01 );
4006 else if ( getYdistance() < 0.5 ) {
4007 g.setStroke( STROKE_025 );
4009 else if ( getYdistance() < 1 ) {
4010 g.setStroke( STROKE_05 );
4012 else if ( getYdistance() < 2 ) {
4013 g.setStroke( STROKE_075 );
4015 else if ( ( getYdistance() < 20 ) || !getConfiguration().isAllowThickStrokes() ) {
4016 g.setStroke( STROKE_1 );
4019 g.setStroke( STROKE_2 );
4023 final private void setUpUrtFactor() {
4024 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
4025 : getVisibleRect().height;
4026 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4027 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
4030 final int max_depth = _circ_max_depth;
4031 if ( max_depth > 0 ) {
4032 setUrtFactor( d / ( 2 * max_depth ) );
4035 setUrtFactor( d / 2 );
4038 setUrtFactorOv( getUrtFactor() );
4041 final private void setUrtFactor( final float urt_factor ) {
4042 _urt_factor = urt_factor;
4045 final private void setUrtFactorOv( final float urt_factor_ov ) {
4046 _urt_factor_ov = urt_factor_ov;
4049 private void showExtDescNodeData( final PhylogenyNode node ) {
4050 final List<String> data = new ArrayList<String>();
4051 final List<PhylogenyNode> nodes = node.getAllExternalDescendants();
4052 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
4053 for( final PhylogenyNode n : getFoundNodesAsListOfPhylogenyNodes() ) {
4054 if ( !nodes.contains( n ) ) {
4059 for( final PhylogenyNode n : nodes ) {
4060 switch ( getOptions().getExtDescNodeDataToReturn() ) {
4062 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
4063 data.add( n.getName() );
4067 if ( n.getNodeData().isHasSequence()
4068 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
4069 data.add( n.getNodeData().getSequence().getName() );
4073 if ( n.getNodeData().isHasSequence()
4074 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
4075 data.add( n.getNodeData().getSequence().getGeneName() );
4078 case SEQUENCE_SYMBOL:
4079 if ( n.getNodeData().isHasSequence()
4080 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
4081 data.add( n.getNodeData().getSequence().getSymbol() );
4084 case SEQUENCE_MOL_SEQ_FASTA:
4085 final StringBuilder sb = new StringBuilder();
4086 if ( n.getNodeData().isHasSequence()
4087 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
4088 final StringBuilder ann = new StringBuilder();
4089 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
4090 ann.append( n.getName() );
4093 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
4094 ann.append( "SYM=" );
4095 ann.append( n.getNodeData().getSequence().getSymbol() );
4098 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
4099 ann.append( "NAME=" );
4100 ann.append( n.getNodeData().getSequence().getName() );
4103 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
4104 ann.append( "GN=" );
4105 ann.append( n.getNodeData().getSequence().getGeneName() );
4108 if ( n.getNodeData().getSequence().getAccession() != null ) {
4109 ann.append( "ACC=" );
4110 ann.append( n.getNodeData().getSequence().getAccession().asText() );
4113 if ( n.getNodeData().isHasTaxonomy() ) {
4114 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
4115 ann.append( "TAXID=" );
4116 ann.append( n.getNodeData().getTaxonomy().getTaxonomyCode() );
4119 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
4120 ann.append( "SN=" );
4121 ann.append( n.getNodeData().getTaxonomy().getScientificName() );
4126 if ( ann.charAt( ann.length() - 1 ) == '|' ) {
4127 ann_str = ann.substring( 0, ann.length() - 1 );
4130 ann_str = ann.toString();
4132 sb.append( SequenceWriter.toFasta( ann_str,
4133 n.getNodeData().getSequence().getMolecularSequence(),
4135 data.add( sb.toString() );
4139 if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
4140 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
4141 data.add( n.getNodeData().getSequence().getAccession().toString() );
4144 case TAXONOMY_SCIENTIFIC_NAME:
4145 if ( n.getNodeData().isHasTaxonomy()
4146 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
4147 data.add( n.getNodeData().getTaxonomy().getScientificName() );
4151 if ( n.getNodeData().isHasTaxonomy()
4152 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
4153 data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
4157 case DOMAINS_COLLAPSED_PER_PROTEIN:
4158 if ( n.getNodeData().isHasSequence()
4159 && ( n.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4160 final DomainArchitecture da = n.getNodeData().getSequence().getDomainArchitecture();
4161 final Set<String> s = new HashSet<String>();
4162 for( int i = 0; i < da.getDomains().size(); ++i ) {
4163 final ProteinDomain d = da.getDomain( i );
4164 if ( d.getConfidence() <= Math.pow( 10, getDomainStructureEvalueThresholdExp() ) ) {
4165 final String name = d.getName();
4166 if ( !( s.contains( name ) ) ) {
4169 .getExtDescNodeDataToReturn() == NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN ) {
4177 case SEQ_ANNOTATIONS:
4178 if ( n.getNodeData().isHasSequence() ) {
4179 if ( n.getNodeData().isHasSequence()
4180 && ( n.getNodeData().getSequence().getAnnotations() != null ) ) {
4181 final SortedSet<Annotation> a = n.getNodeData().getSequence().getAnnotations();
4182 for( int i = 0; i < a.size(); ++i ) {
4183 data.add( n.getNodeData().getSequence().getAnnotation( i ).toString() );
4189 if ( n.getNodeData().isHasSequence() ) {
4190 if ( n.getNodeData().isHasSequence()
4191 && ( n.getNodeData().getSequence().getAnnotations() != null ) ) {
4192 final SortedSet<Annotation> a = n.getNodeData().getSequence().getAnnotations();
4193 for( int i = 0; i < a.size(); ++i ) {
4194 final Annotation ann = n.getNodeData().getSequence().getAnnotation( i );
4195 final String ref = ann.getRef();
4196 if ( ref.toUpperCase().startsWith( "GO:" ) ) {
4204 TreePanelUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
4207 throw new IllegalArgumentException( "unknown data element: "
4208 + getOptions().getExtDescNodeDataToReturn() );
4211 final StringBuilder sb = new StringBuilder();
4212 final int size = TreePanelUtil.nodeDataIntoStringBuffer( data, getOptions(), sb );
4213 if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
4214 || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
4215 if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
4216 System.out.println( sb );
4218 if ( sb.length() < 1 ) {
4219 clearCurrentExternalNodesDataBuffer();
4222 setCurrentExternalNodesDataBuffer( sb );
4225 else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
4226 if ( sb.length() < 1 ) {
4227 TreePanelUtil.showInformationMessage( this,
4228 "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")",
4229 "Descendants of selected node do not contain selected data" );
4230 clearCurrentExternalNodesDataBuffer();
4233 setCurrentExternalNodesDataBuffer( sb );
4235 if ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() ) {
4236 title = ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.UNKNOWN ? "Data"
4237 : obtainTitleForExtDescNodeData() ) + " for " + data.size() + " nodes, unique entries: "
4241 title = ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.UNKNOWN ? "Data"
4242 : obtainTitleForExtDescNodeData() ) + " for " + data.size() + "/"
4243 + node.getNumberOfExternalNodes() + " external descendats of node " + node
4244 + ", unique entries: " + size;
4246 final String s = sb.toString().trim();
4248 getMainPanel().getMainFrame().showTextFrame( s, title );
4254 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
4256 if ( ( node.getName().length() > 0 )
4257 || ( node.getNodeData().isHasTaxonomy()
4258 && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
4259 || ( node.getNodeData().isHasSequence()
4260 && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) )
4261 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
4262 || node.getBranchData().isHasConfidences() ) {
4263 _popup_buffer.setLength( 0 );
4265 if ( node.getName().length() > 0 ) {
4267 _popup_buffer.append( node.getName() );
4269 if ( node.getNodeData().isHasTaxonomy()
4270 && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
4272 boolean enc_data = false;
4273 final Taxonomy tax = node.getNodeData().getTaxonomy();
4274 if ( _popup_buffer.length() > 0 ) {
4275 _popup_buffer.append( "\n" );
4277 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4278 _popup_buffer.append( "[" );
4279 _popup_buffer.append( tax.getTaxonomyCode() );
4280 _popup_buffer.append( "]" );
4283 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4285 _popup_buffer.append( " " );
4287 _popup_buffer.append( tax.getScientificName() );
4290 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
4292 _popup_buffer.append( " (" );
4295 _popup_buffer.append( "(" );
4297 _popup_buffer.append( tax.getCommonName() );
4298 _popup_buffer.append( ")" );
4301 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
4303 _popup_buffer.append( " (" );
4306 _popup_buffer.append( "(" );
4308 _popup_buffer.append( tax.getAuthority() );
4309 _popup_buffer.append( ")" );
4312 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
4314 _popup_buffer.append( " [" );
4317 _popup_buffer.append( "[" );
4319 _popup_buffer.append( tax.getRank() );
4320 _popup_buffer.append( "]" );
4323 if ( tax.getSynonyms().size() > 0 ) {
4325 _popup_buffer.append( " " );
4327 _popup_buffer.append( "[" );
4329 for( final String syn : tax.getSynonyms() ) {
4330 if ( !ForesterUtil.isEmpty( syn ) ) {
4332 _popup_buffer.append( syn );
4333 if ( counter < tax.getSynonyms().size() ) {
4334 _popup_buffer.append( ", " );
4339 _popup_buffer.append( "]" );
4342 if ( ( tax.getIdentifier() != null )
4343 && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
4344 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
4345 _popup_buffer.append( "[" );
4346 _popup_buffer.append( tax.getIdentifier().getProvider() );
4347 _popup_buffer.append( "] " );
4349 _popup_buffer.append( tax.getIdentifier().getValue() );
4353 if ( node.getNodeData().isHasSequence()
4354 && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) ) {
4356 boolean enc_data = false;
4357 if ( _popup_buffer.length() > 0 ) {
4358 _popup_buffer.append( "\n" );
4360 final Sequence seq = node.getNodeData().getSequence();
4361 if ( seq.getAccession() != null ) {
4362 _popup_buffer.append( "[" );
4363 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
4364 _popup_buffer.append( seq.getAccession().getSource() );
4365 _popup_buffer.append( ":" );
4367 _popup_buffer.append( seq.getAccession().getValue() );
4368 _popup_buffer.append( "]" );
4371 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
4373 _popup_buffer.append( " [" );
4376 _popup_buffer.append( "[" );
4378 _popup_buffer.append( seq.getSymbol() );
4379 _popup_buffer.append( "]" );
4382 if ( !ForesterUtil.isEmpty( seq.getGeneName() ) ) {
4384 _popup_buffer.append( " [" );
4387 _popup_buffer.append( "[" );
4389 _popup_buffer.append( seq.getGeneName() );
4390 _popup_buffer.append( "]" );
4393 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
4395 _popup_buffer.append( " " );
4397 _popup_buffer.append( seq.getName() );
4400 if ( node.getNodeData().isHasDate() ) {
4402 if ( _popup_buffer.length() > 0 ) {
4403 _popup_buffer.append( "\n" );
4405 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
4407 if ( node.getNodeData().isHasDistribution() ) {
4409 if ( _popup_buffer.length() > 0 ) {
4410 _popup_buffer.append( "\n" );
4412 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
4414 if ( node.getBranchData().isHasConfidences() ) {
4415 final List<Confidence> confs = node.getBranchData().getConfidences();
4416 for( final Confidence confidence : confs ) {
4418 if ( _popup_buffer.length() > 0 ) {
4419 _popup_buffer.append( "\n" );
4421 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
4422 _popup_buffer.append( "[" );
4423 _popup_buffer.append( confidence.getType() );
4424 _popup_buffer.append( "] " );
4426 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
4428 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4429 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
4430 _popup_buffer.append( " (sd=" );
4431 _popup_buffer.append( FORMATTER_CONFIDENCE
4432 .format( ForesterUtil.round( confidence.getStandardDeviation(),
4434 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4435 _popup_buffer.append( ")" );
4439 if ( node.getNodeData().isHasProperties() ) {
4440 if ( _popup_buffer.length() > 0 ) {
4441 _popup_buffer.append( "\n" );
4443 _popup_buffer.append(node.getNodeData().getProperties().asText());
4446 if ( _popup_buffer.length() > 0 ) {
4447 if ( !getConfiguration().isUseNativeUI() ) {
4449 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
4450 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
4451 if ( isInFoundNodes0( node ) && !isInFoundNodes1( node ) ) {
4452 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0() );
4454 else if ( !isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
4455 _rollover_popup.setForeground( getTreeColorSet().getFoundColor1() );
4457 else if ( isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
4458 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0and1() );
4461 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
4465 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
4467 _rollover_popup.setText( _popup_buffer.toString() );
4468 _node_desc_popup = PopupFactory.getSharedInstance()
4471 e.getLocationOnScreen().x + 10,
4472 e.getLocationOnScreen().y - ( lines * 20 ) );
4473 _node_desc_popup.show();
4477 catch ( final Exception ex ) {
4482 final private void showNodeEditFrame( final PhylogenyNode n ) {
4483 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4484 // pop up edit box for single node
4485 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
4486 _node_frame_index++;
4489 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4493 final private void showNodeFrame( final PhylogenyNode n ) {
4494 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4495 // pop up edit box for single node
4496 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
4497 _node_frame_index++;
4500 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4504 final private void switchDisplaygetPhylogenyGraphicsType() {
4505 switch ( getPhylogenyGraphicsType() ) {
4507 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4508 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4511 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4512 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4515 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4516 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4519 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4520 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4523 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4524 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4527 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4528 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4531 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4532 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4535 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4536 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4539 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
4541 if ( getControlPanel().getDynamicallyHideData() != null ) {
4542 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4543 getControlPanel().getDynamicallyHideData().setEnabled( false );
4546 getControlPanel().getDynamicallyHideData().setEnabled( true );
4549 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4550 getControlPanel().setDrawPhylogramEnabled( true );
4553 getControlPanel().setDrawPhylogramEnabled( false );
4556 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4560 final void calcMaxDepth() {
4561 if ( _phylogeny != null ) {
4562 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4567 * Set parameters for printing the displayed tree
4570 final void calcParametersForPainting( final int x, final int y ) {
4571 // updateStyle(); not needed?
4572 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4574 calculateLongestExtNodeInfo();
4575 if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
4576 && ( getTreeFontSet().getLargeFont().getSize() > ( 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
4577 while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) )
4578 && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) {
4579 getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(), true );
4580 calculateLongestExtNodeInfo();
4584 while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) ) && ( getTreeFontSet().getLargeFont()
4585 .getSize() <= ( getTreeFontSet().getLargeFontMemory().getSize()
4586 - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
4587 getMainPanel().getTreeFontSet().increaseFontSize();
4588 calculateLongestExtNodeInfo();
4591 //_length_of_longest_text = calcLengthOfLongestText();
4592 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4593 final int max_depth = PhylogenyMethods.calculateMaxDepthConsiderCollapsed( _phylogeny ) + 1;
4594 if ( ext_nodes == 1 ) {
4595 ext_nodes = max_depth;
4596 if ( ext_nodes < 1 ) {
4603 if ( !isNonLinedUpCladogram() ) {
4604 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
4605 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
4608 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
4609 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
4611 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
4612 if ( xdist < 0.0 ) {
4615 if ( ov_xdist < 0.0 ) {
4618 if ( ydist < 0.0 ) {
4621 setXdistance( xdist );
4622 setYdistance( ydist );
4623 setOvXDistance( ov_xdist );
4624 final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() );
4625 //final double height = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4627 final float corr = ( float ) ( ( x - ( 2.0 * TreePanel.MOVE ) - getLongestExtNodeInfo()
4628 - getXdistance() ) / height );
4629 setXcorrectionFactor( corr > 0 ? corr : 0 );
4630 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
4631 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4634 setXcorrectionFactor( 0 );
4635 setOvXcorrectionFactor( 0 );
4637 _circ_max_depth = max_depth;
4640 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
4641 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4642 // int dynamic_hiding_factor = calcDynamicHidingFactor();
4643 // if ( dynamic_hiding_factor > 1 ) {
4644 // while ( dynamic_hiding_factor > 1
4645 // && getTreeFontSet()._fm_large.getHeight() > TreeFontSet.SMALL_FONTS_BASE ) {
4646 // getTreeFontSet().decreaseFontSize( 1, true );
4647 // dynamic_hiding_factor = calcDynamicHidingFactor();
4650 // else if ( getTreeFontSet().isDecreasedSizeBySystem() ) {
4651 // while ( dynamic_hiding_factor < 1 && getTreeFontSet()._fm_large.getHeight() < 12 ) {
4652 // getTreeFontSet().increaseFontSize();
4653 // dynamic_hiding_factor = calcDynamicHidingFactor();
4661 final void calculateLongestExtNodeInfo() {
4662 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
4665 int max_possible_length = ForesterUtil
4666 .roundToInt( ( getSize().getWidth() - ( 2 * MOVE ) ) * AptxConstants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
4667 if ( max_possible_length < 20 ) {
4668 max_possible_length = 20;
4671 int longest_txt = 0;
4672 _longest_domain = 0;
4673 PhylogenyNode longest_txt_node = _phylogeny.getFirstExternalNode();
4674 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
4676 if ( node.isCollapse() ) {
4679 final StringBuilder sb = new StringBuilder();
4680 nodeDataAsSB( node, sb );
4681 if ( node.getNodeData().isHasTaxonomy() ) {
4682 nodeTaxonomyDataAsSB( node.getNodeData().getTaxonomy(), sb );
4684 final int txt = sb.length();
4685 if ( txt > longest_txt ) {
4687 longest_txt_node = node;
4689 boolean use_vis = false;
4690 final Graphics2D g = ( Graphics2D ) getGraphics();
4691 if ( getControlPanel().isUseVisualStyles() ) {
4692 use_vis = setFont( g, node, false );
4695 sum = getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
4698 sum = getFontMetrics( g.getFont() ).stringWidth( sb.toString() );
4700 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
4701 sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getBinaryCharacters()
4702 .getGainedCharactersAsStringBuffer().toString() );
4704 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
4705 && ( node.getNodeData().getVector().size() > 0 ) ) {
4706 if ( getConfiguration() != null ) {
4707 sum += getConfiguration().getVectorDataWidth() + 10;
4710 sum += RenderableVector.VECTOR_DEFAULT_WIDTH + 10;
4713 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4714 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4716 // TODO this might need some clean up
4717 final DomainArchitecture d = node.getNodeData().getSequence().getDomainArchitecture();
4718 sum += ( ( _domain_structure_width
4719 / ( ( RenderableDomainArchitecture ) d ).getOriginalSize().getWidth() ) * d.getTotalLength() )
4721 if ( d.getTotalLength() > _longest_domain ) {
4722 _longest_domain = d.getTotalLength();
4725 if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
4726 && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
4727 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
4729 sum += RenderableMsaSequence.DEFAULT_WIDTH + 30;
4731 if ( sum >= max_possible_length ) {
4732 _longest_ext_node_info = max_possible_length;
4733 // return; //FIXME why?
4735 if ( sum > longest ) {
4739 _ext_node_with_longest_txt_info = longest_txt_node;
4740 if ( longest >= max_possible_length ) {
4741 _longest_ext_node_info = max_possible_length;
4744 _longest_ext_node_info = longest;
4746 _length_of_longest_text = calcLengthOfLongestText();
4749 final void calculateScaleDistance() {
4750 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
4753 final double height = getMaxDistanceToRoot();
4755 if ( ( height <= 0.5 ) ) {
4756 setScaleDistance( 0.01 );
4758 else if ( height <= 5.0 ) {
4759 setScaleDistance( 0.1 );
4761 else if ( height <= 50.0 ) {
4762 setScaleDistance( 1 );
4764 else if ( height <= 500.0 ) {
4765 setScaleDistance( 10 );
4768 setScaleDistance( 100 );
4772 setScaleDistance( 0.0 );
4774 String scale_label = String.valueOf( getScaleDistance() );
4775 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
4776 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
4778 setScaleLabel( scale_label );
4781 final Color calculateSequenceBasedColor( final Sequence seq ) {
4782 if ( ForesterUtil.isEmpty( seq.getName() ) ) {
4783 return getTreeColorSet().getSequenceColor();
4786 final String seq_name = seq.getName();
4787 c = getControlPanel().getSequenceColors().get( seq_name );
4789 c = AptxUtil.calculateColorFromString( seq_name, false );
4790 getControlPanel().getSequenceColors().put( seq_name, c );
4795 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
4796 if ( getOptions().isColorByTaxonomicGroup() ) {
4797 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4799 String group = null;
4801 group = TaxonomyUtil.getTaxGroupByTaxCode( tax.getTaxonomyCode() );
4803 catch ( final Exception e ) {
4806 if ( !ex && !ForesterUtil.isEmpty( group ) ) {
4807 final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group );
4813 return getTreeColorSet().getTaxonomyColor();
4816 if ( ForesterUtil.isEmpty( tax.getTaxonomyCode() ) && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4817 return getTreeColorSet().getTaxonomyColor();
4820 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4821 c = getControlPanel().getSpeciesColors().get( tax.getTaxonomyCode() );
4823 if ( ( c == null ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4824 c = getControlPanel().getSpeciesColors().get( tax.getScientificName() );
4827 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4828 c = AptxUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
4829 getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c );
4832 c = AptxUtil.calculateColorFromString( tax.getScientificName(), true );
4833 getControlPanel().getSpeciesColors().put( tax.getScientificName(), c );
4842 void clearCurrentExternalNodesDataBuffer() {
4843 setCurrentExternalNodesDataBuffer( new StringBuilder() );
4847 * Collapse the tree from the given node
4852 final void collapse( final PhylogenyNode node ) {
4853 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4854 JOptionPane.showMessageDialog( this,
4855 "Cannot collapse in unrooted display type",
4856 "Attempt to collapse in unrooted display",
4857 JOptionPane.WARNING_MESSAGE );
4860 if ( !node.isExternal() && !node.isRoot() ) {
4861 final boolean collapse = !node.isCollapse();
4862 TreePanelUtil.collapseSubtree( node, collapse );
4863 updateSetOfCollapsedExternalNodes();
4864 _phylogeny.recalculateNumberOfExternalDescendants( true );
4865 resetNodeIdToDistToLeafMap();
4866 calculateLongestExtNodeInfo();
4867 setNodeInPreorderToNull();
4868 _control_panel.displayedPhylogenyMightHaveChanged( true );
4869 resetPreferredSize();
4871 _main_panel.adjustJScrollPane();
4876 final void uncollapseAll( final PhylogenyNode node ) {
4877 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4878 JOptionPane.showMessageDialog( this,
4879 "Cannot uncollapse in unrooted display type",
4880 "Attempt to uncollapse in unrooted display",
4881 JOptionPane.WARNING_MESSAGE );
4884 if ( !node.isExternal() ) {
4885 TreePanelUtil.uncollapseSubtree( node );
4886 updateSetOfCollapsedExternalNodes();
4887 _phylogeny.recalculateNumberOfExternalDescendants( true );
4888 resetNodeIdToDistToLeafMap();
4889 calculateLongestExtNodeInfo();
4890 setNodeInPreorderToNull();
4891 _control_panel.displayedPhylogenyMightHaveChanged( true );
4892 resetPreferredSize();
4894 _main_panel.adjustJScrollPane();
4899 final void collapseSpeciesSpecificSubtrees() {
4900 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4904 TreePanelUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
4905 updateSetOfCollapsedExternalNodes();
4906 _phylogeny.recalculateNumberOfExternalDescendants( true );
4907 resetNodeIdToDistToLeafMap();
4908 calculateLongestExtNodeInfo();
4909 setNodeInPreorderToNull();
4910 resetPreferredSize();
4911 resetDepthCollapseDepthValue();
4912 resetRankCollapseRankValue();
4913 _main_panel.adjustJScrollPane();
4914 getControlPanel().showWhole();
4918 final void colorRank( final String rank ) {
4919 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4923 AptxUtil.removeBranchColors( _phylogeny );
4924 final int colorizations = TreePanelUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
4925 if ( colorizations > 0 ) {
4926 _control_panel.setColorBranches( true );
4927 if ( _control_panel.getUseVisualStylesCb() != null ) {
4928 _control_panel.getUseVisualStylesCb().setSelected( true );
4930 if ( _control_panel.getColorAccSpeciesCb() != null ) {
4931 _control_panel.getColorAccSpeciesCb().setSelected( false );
4933 _options.setColorLabelsSameAsParentBranch( true );
4934 if ( getMainPanel().getMainFrame()._color_labels_same_as_parent_branch != null ) {
4935 getMainPanel().getMainFrame()._color_labels_same_as_parent_branch.setSelected( true );
4937 _control_panel.repaint();
4941 if ( colorizations > 0 ) {
4942 String msg = "Taxonomy colorization via " + rank + " completed:\n";
4943 if ( colorizations > 1 ) {
4944 msg += "colorized " + colorizations + " subtrees";
4947 msg += "colorized one subtree";
4950 JOptionPane.showMessageDialog( this,
4952 "Taxonomy Rank-Colorization Completed (" + rank + ")",
4953 JOptionPane.INFORMATION_MESSAGE );
4956 String msg = "Could not taxonomy rank-colorize any subtree via " + rank + ".\n";
4957 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
4958 msg += "select a different rank (e.g. phylum, genus, ...)\n";
4960 msg += "execute:\n";
4961 msg += "1. \"" + MainFrame.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
4962 msg += "2. \"" + MainFrame.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
4963 JOptionPane.showMessageDialog( this,
4965 "Taxonomy Rank-Colorization Failed",
4966 JOptionPane.WARNING_MESSAGE );
4970 final void confColor() {
4971 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4975 AptxUtil.removeBranchColors( _phylogeny );
4976 TreePanelUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
4977 _control_panel.setColorBranches( true );
4978 if ( _control_panel.getUseVisualStylesCb() != null ) {
4979 _control_panel.getUseVisualStylesCb().setSelected( true );
4985 final void decreaseDomainStructureEvalueThresholdExp() {
4986 if ( _domain_structure_e_value_thr_exp > -20 ) {
4987 _domain_structure_e_value_thr_exp -= 1;
4992 * Find the node, if any, at the given location
4996 * @return pointer to the node at x,y, null if not found
4998 final PhylogenyNode findNode( final int x, final int y ) {
4999 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
5002 final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE;
5003 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
5004 final PhylogenyNode node = iter.next();
5005 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
5006 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
5007 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
5008 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
5009 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
5016 final Configuration getConfiguration() {
5017 return _configuration;
5020 final ControlPanel getControlPanel() {
5021 return _control_panel;
5024 String getCurrentExternalNodesDataBufferAsString() {
5025 return _current_external_nodes_data_buffer.toString();
5028 int getCurrentExternalNodesDataBufferChangeCounter() {
5029 return _current_external_nodes_data_buffer_change_counter;
5032 final int getDomainStructureEvalueThresholdExp() {
5033 return _domain_structure_e_value_thr_exp;
5036 final Set<Long> getFoundNodes0() {
5037 return _found_nodes_0;
5040 final Set<Long> getFoundNodes1() {
5041 return _found_nodes_1;
5044 List<PhylogenyNode> getFoundNodesAsListOfPhylogenyNodes() {
5045 final List<PhylogenyNode> additional_nodes = new ArrayList<PhylogenyNode>();
5046 if ( getFoundNodes0() != null ) {
5047 for( final Long id : getFoundNodes0() ) {
5048 final PhylogenyNode n = _phylogeny.getNode( id );
5050 additional_nodes.add( n );
5054 if ( getFoundNodes1() != null ) {
5055 for( final Long id : getFoundNodes1() ) {
5056 if ( ( getFoundNodes0() == null ) || !getFoundNodes0().contains( id ) ) {
5057 final PhylogenyNode n = _phylogeny.getNode( id );
5059 additional_nodes.add( n );
5064 return additional_nodes;
5067 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
5068 if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
5069 return ( PhylogenyMethods.getBranchColorValue( node ) );
5072 return ( getTreeColorSet().getBranchColor() );
5076 final int getLongestExtNodeInfo() {
5077 return _longest_ext_node_info;
5080 final Options getOptions() {
5081 if ( _options == null ) {
5082 _options = getControlPanel().getOptions();
5087 final Rectangle2D getOvRectangle() {
5088 return _ov_rectangle;
5091 final Rectangle getOvVirtualRectangle() {
5092 return _ov_virtual_rectangle;
5095 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
5096 return _graphics_type;
5099 final Color getSequenceBasedColor( final PhylogenyNode node ) {
5100 if ( node.getNodeData().isHasSequence() ) {
5101 return calculateSequenceBasedColor( node.getNodeData().getSequence() );
5103 // return non-colorized color
5104 return getTreeColorSet().getSequenceColor();
5107 final double getStartingAngle() {
5108 return _urt_starting_angle;
5111 DescriptiveStatistics getStatisticsForExpressionValues() {
5112 return _statistics_for_vector_data;
5115 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
5116 if ( node.isExternal() && node.getNodeData().isHasTaxonomy() ) {
5117 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
5119 // return non-colorized color
5120 return getTreeColorSet().getTaxonomyColor();
5123 final File getTreeFile() {
5127 final float getXcorrectionFactor() {
5128 return _x_correction_factor;
5131 final float getXdistance() {
5135 final float getYdistance() {
5139 final void increaseDomainStructureEvalueThresholdExp() {
5140 if ( _domain_structure_e_value_thr_exp < 3 ) {
5141 _domain_structure_e_value_thr_exp += 1;
5145 final void initNodeData() {
5146 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
5149 double _max_original_domain_structure_width = 0.0;
5150 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
5151 if ( node.getNodeData().isHasSequence()
5152 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
5153 RenderableDomainArchitecture rds = null;
5154 if ( !( node.getNodeData().getSequence()
5155 .getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
5156 if ( SPECIAL_DOMAIN_COLORING ) {
5157 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence()
5158 .getDomainArchitecture(), node.getName() );
5161 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence()
5162 .getDomainArchitecture() );
5164 node.getNodeData().getSequence().setDomainArchitecture( rds );
5167 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
5169 if ( getControlPanel().isShowDomainArchitectures() ) {
5170 final double dsw = rds.getOriginalSize().getWidth();
5171 if ( dsw > _max_original_domain_structure_width ) {
5172 _max_original_domain_structure_width = dsw;
5177 if ( getControlPanel().isShowDomainArchitectures() ) {
5178 final float ds_factor_width = ( float ) ( _domain_structure_width / _max_original_domain_structure_width );
5179 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
5180 if ( node.getNodeData().isHasSequence()
5181 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
5182 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
5183 .getSequence().getDomainArchitecture();
5184 rds.setRenderingFactorWidth( ds_factor_width );
5185 rds.setParameter( _domain_structure_e_value_thr_exp );
5191 final boolean inOv( final MouseEvent e ) {
5192 return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) )
5193 && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) )
5194 && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) )
5195 && ( e.getY() < ( ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) );
5198 final boolean inOvRectangle( final MouseEvent e ) {
5199 return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) )
5200 && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) )
5201 && ( e.getY() >= ( getOvRectangle().getY() - 1 ) )
5202 && ( e.getY() <= ( getOvRectangle().getY() + getOvRectangle().getHeight() + 1 ) ) );
5207 final boolean isCanCollapse() {
5208 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5211 final boolean isCanUncollapseAll( final PhylogenyNode node ) {
5212 if ( node.isExternal() || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
5215 if ( node.isCollapse() ) {
5218 final PhylogenyNodeIterator it = new PreorderTreeIterator( node );
5219 while ( it.hasNext() ) {
5220 if ( it.next().isCollapse() ) {
5227 final boolean isCanColorSubtree() {
5228 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5231 final boolean isCanCopy() {
5232 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
5235 final boolean isCanCut( final PhylogenyNode node ) {
5236 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
5237 && !node.isRoot() );
5240 final boolean isCanDelete() {
5241 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
5244 final boolean isCanPaste() {
5245 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
5246 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
5249 final boolean isCanReroot() {
5250 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
5253 final boolean isCanSubtree( final PhylogenyNode node ) {
5254 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal()
5255 && ( !node.isRoot() || ( _subtree_index > 0 ) ) );
5258 final boolean isCurrentTreeIsSubtree() {
5259 return ( _subtree_index > 0 );
5262 final boolean isEdited() {
5266 final boolean isInOvRect() {
5270 final boolean isOvOn() {
5274 final boolean isPhyHasBranchLengths() {
5275 return _phy_has_branch_lengths;
5278 final void midpointRoot() {
5279 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
5282 if ( !_phylogeny.isRerootable() ) {
5283 JOptionPane.showMessageDialog( this,
5284 "This is not rerootable",
5286 JOptionPane.WARNING_MESSAGE );
5289 setNodeInPreorderToNull();
5291 PhylogenyMethods.midpointRoot( _phylogeny );
5292 resetNodeIdToDistToLeafMap();
5298 final void mouseClicked( final MouseEvent e ) {
5299 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
5300 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
5301 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
5302 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) )
5304 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) )
5312 final double max_x = getWidth() - getVisibleRect().width;
5313 final double max_y = getHeight() - getVisibleRect().height;
5320 getMainPanel().getCurrentScrollPane().getViewport()
5321 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
5322 setInOvRect( true );
5326 final PhylogenyNode node = findNode( e.getX(), e.getY() );
5327 if ( node != null ) {
5328 if ( !node.isRoot() && node.getParent().isCollapse() ) {
5331 _highlight_node = node;
5332 // Check if shift key is down
5333 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
5334 // Yes, so add to _found_nodes
5335 if ( getFoundNodes0() == null ) {
5336 setFoundNodes0( new HashSet<Long>() );
5338 getFoundNodes0().add( node.getId() );
5339 // Check if control key is down
5341 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
5342 // Yes, so pop-up menu
5343 displayNodePopupMenu( node, e.getX(), e.getY() );
5344 // Handle unadorned click
5347 // Check for right mouse button
5348 if ( e.getModifiers() == 4 ) {
5349 displayNodePopupMenu( node, e.getX(), e.getY() );
5352 // if not in _found_nodes, clear _found_nodes
5353 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
5358 // no node was clicked
5359 _highlight_node = null;
5365 final void mouseDragInBrowserPanel( final MouseEvent e ) {
5366 setCursor( MOVE_CURSOR );
5367 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
5368 scroll_position.x -= ( e.getX() - getLastDragPointX() );
5369 scroll_position.y -= ( e.getY() - getLastDragPointY() );
5370 if ( scroll_position.x < 0 ) {
5371 scroll_position.x = 0;
5374 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
5375 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
5376 if ( scroll_position.x > max_x ) {
5377 scroll_position.x = max_x;
5380 if ( scroll_position.y < 0 ) {
5381 scroll_position.y = 0;
5384 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
5385 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
5386 if ( scroll_position.y > max_y ) {
5387 scroll_position.y = max_y;
5390 if ( isOvOn() || getOptions().isShowScale() ) {
5393 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
5396 final void mouseDragInOvRectangle( final MouseEvent e ) {
5397 setCursor( HAND_CURSOR );
5398 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
5399 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
5400 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
5401 double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) );
5402 double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) );
5403 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
5404 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
5405 if ( scroll_position.x <= 0 ) {
5406 scroll_position.x = 0;
5410 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
5411 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
5412 if ( scroll_position.x >= max_x ) {
5414 scroll_position.x = max_x;
5417 if ( scroll_position.y <= 0 ) {
5419 scroll_position.y = 0;
5422 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
5423 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
5424 if ( scroll_position.y >= max_y ) {
5426 scroll_position.y = max_y;
5430 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
5431 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
5432 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
5435 final void mouseMoved( final MouseEvent e ) {
5436 requestFocusInWindow();
5437 if ( _current_external_nodes != null ) {
5438 _current_external_nodes = null;
5441 if ( getControlPanel().isNodeDescPopup() ) {
5442 if ( _node_desc_popup != null ) {
5443 _node_desc_popup.hide();
5444 _node_desc_popup = null;
5447 if ( getOptions().isShowOverview() && isOvOn() ) {
5448 if ( inOvVirtualRectangle( e ) ) {
5449 if ( !isInOvRect() ) {
5450 setInOvRect( true );
5455 if ( isInOvRect() ) {
5456 setInOvRect( false );
5461 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
5470 final PhylogenyNode node = findNode( e.getX(), e.getY() );
5471 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
5472 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.GET_EXT_DESC_DATA ) ) {
5473 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
5474 addToCurrentExternalNodes( n.getId() );
5476 setCursor( HAND_CURSOR );
5479 else if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
5480 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
5481 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
5482 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
5483 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
5484 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
5485 setCursor( CUT_CURSOR );
5488 setCursor( HAND_CURSOR );
5489 if ( getControlPanel().isNodeDescPopup() ) {
5490 showNodeDataPopup( e, node );
5495 setCursor( ARROW_CURSOR );
5500 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
5501 setCursor( ARROW_CURSOR );
5504 final void multiplyUrtFactor( final float f ) {
5510 final void paintBranchCircular( final PhylogenyNode p,
5511 final PhylogenyNode c,
5513 final boolean radial_labels,
5514 final boolean to_pdf,
5515 final boolean to_graphics_file ) {
5516 final double angle = _urt_nodeid_angle_map.get( c.getId() );
5517 final double root_x = _root.getXcoord();
5518 final double root_y = _root.getYcoord();
5519 final double dx = root_x - p.getXcoord();
5520 final double dy = root_y - p.getYcoord();
5521 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
5522 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
5523 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
5524 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
5525 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
5526 final double r2 = 2.0 * parent_radius;
5527 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
5529 drawLine( c.getXcoord(),
5531 root_x + ( Math.cos( angle ) * parent_radius ),
5532 root_y + ( Math.sin( angle ) * parent_radius ),
5534 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file );
5535 if ( c.isExternal() ) {
5536 final boolean is_in_found_nodes = isInFoundNodes0( c ) || isInFoundNodes1( c )
5537 || isInCurrentExternalNodes( c );
5538 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
5539 && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
5542 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
5546 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
5547 final double angle = _urt_nodeid_angle_map.get( c.getId() );
5548 final double root_x = _root.getXSecondary();
5549 final double root_y = _root.getYSecondary();
5550 final double dx = root_x - p.getXSecondary();
5551 final double dy = root_y - p.getYSecondary();
5552 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
5553 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
5554 g.setColor( getTreeColorSet().getOvColor() );
5555 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
5556 final double r2 = 2.0 * parent_radius;
5557 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
5559 drawLine( c.getXSecondary(),
5561 root_x + ( Math.cos( angle ) * parent_radius ),
5562 root_y + ( Math.sin( angle ) * parent_radius ),
5564 if ( isInFoundNodes( c ) || isInCurrentExternalNodes( c ) ) {
5565 g.setColor( getColorForFoundNode( c ) );
5566 drawRectFilled( c.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
5567 c.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
5568 OVERVIEW_FOUND_NODE_BOX_SIZE,
5569 OVERVIEW_FOUND_NODE_BOX_SIZE,
5574 final void paintCircular( final Phylogeny phy,
5575 final double starting_angle,
5580 final boolean to_pdf,
5581 final boolean to_graphics_file ) {
5582 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
5583 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
5584 _root = phy.getRoot();
5585 _root.setXcoord( center_x );
5586 _root.setYcoord( center_y );
5587 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
5588 double current_angle = starting_angle;
5590 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
5591 final PhylogenyNode n = it.next();
5592 if ( !n.isCollapse() ) {
5593 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
5594 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
5595 _urt_nodeid_angle_map.put( n.getId(), current_angle );
5596 _urt_nodeid_index_map.put( n.getId(), i++ );
5597 current_angle += ( TWO_PI / circ_num_ext_nodes );
5601 System.out.println( "is collapse" + n.getName() );
5604 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
5605 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file );
5608 final void paintCircularLite( final Phylogeny phy,
5609 final double starting_angle,
5613 final Graphics2D g ) {
5614 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
5615 _root = phy.getRoot();
5616 _root.setXSecondary( center_x );
5617 _root.setYSecondary( center_y );
5618 double current_angle = starting_angle;
5619 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
5620 final PhylogenyNode n = it.next();
5621 n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
5622 n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
5623 _urt_nodeid_angle_map.put( n.getId(), current_angle );
5624 current_angle += ( TWO_PI / circ_num_ext_nodes );
5626 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
5629 final void paintPhylogeny( final Graphics2D g,
5630 final boolean to_pdf,
5631 final boolean to_graphics_file,
5632 final int graphics_file_width,
5633 final int graphics_file_height,
5634 final int graphics_file_x,
5635 final int graphics_file_y ) {
5636 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
5639 if ( _control_panel.isShowSequenceRelations() ) {
5640 _query_sequence = _control_panel.getSelectedQuerySequence();
5642 // Color the background
5644 final Rectangle r = getVisibleRect();
5645 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
5646 g.setColor( getTreeColorSet().getBackgroundColor() );
5647 if ( !to_graphics_file ) {
5651 if ( getOptions().isPrintBlackAndWhite() ) {
5652 g.setColor( Color.WHITE );
5654 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
5658 if ( !to_graphics_file ) {
5659 g.setPaint( new GradientPaint( r.x,
5661 getTreeColorSet().getBackgroundColor(),
5664 getTreeColorSet().getBackgroundColorGradientBottom() ) );
5668 g.setPaint( new GradientPaint( graphics_file_x,
5670 getTreeColorSet().getBackgroundColor(),
5672 graphics_file_y + graphics_file_height,
5673 getTreeColorSet().getBackgroundColorGradientBottom() ) );
5674 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
5680 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
5682 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
5683 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5684 _external_node_index = 0;
5685 // Position starting X of tree
5686 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/ ) {
5687 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
5689 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
5690 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE
5691 + ( _phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor() ) ) );
5694 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
5696 // Position starting Y of tree
5697 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
5698 + ( TreePanel.MOVE / 2.0f ) );
5699 final int dynamic_hiding_factor = calcDynamicHidingFactor();
5700 if ( getControlPanel().isDynamicallyHideData() ) {
5701 if ( dynamic_hiding_factor > 1 ) {
5702 getControlPanel().setDynamicHidingIsOn( true );
5705 getControlPanel().setDynamicHidingIsOn( false );
5708 if ( _nodes_in_preorder == null ) {
5709 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
5711 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
5712 _nodes_in_preorder[ i++ ] = it.next();
5715 final boolean disallow_shortcutting = ( dynamic_hiding_factor < 40 )
5716 || getControlPanel().isUseVisualStyles() || getOptions().isShowDefaultNodeShapesForMarkedNodes()
5717 || ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() )
5718 || ( ( getFoundNodes1() != null ) && !getFoundNodes1().isEmpty() )
5719 || ( ( getCurrentExternalNodes() != null ) && !getCurrentExternalNodes().isEmpty() )
5720 || to_graphics_file || to_pdf;
5721 for( final PhylogenyNode element : _nodes_in_preorder ) {
5722 paintNodeRectangular( g,
5725 getControlPanel().isDynamicallyHideData() && ( dynamic_hiding_factor > 1 ),
5726 dynamic_hiding_factor,
5728 disallow_shortcutting );
5730 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
5731 if ( !( to_graphics_file || to_pdf ) ) {
5734 getVisibleRect().y + getVisibleRect().height,
5739 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
5742 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5743 paintPhylogenyLite( g );
5746 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5747 if ( getControlPanel().getDynamicallyHideData() != null ) {
5748 getControlPanel().setDynamicHidingIsOn( false );
5750 final double angle = getStartingAngle();
5751 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
5752 _dynamic_hiding_factor = 0;
5753 if ( getControlPanel().isDynamicallyHideData() ) {
5754 _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5
5755 * getPhylogeny().getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
5757 if ( getControlPanel().getDynamicallyHideData() != null ) {
5758 if ( _dynamic_hiding_factor > 1 ) {
5759 getControlPanel().setDynamicHidingIsOn( true );
5762 getControlPanel().setDynamicHidingIsOn( false );
5765 paintUnrooted( _phylogeny.getRoot(),
5767 ( float ) ( angle + ( 2 * Math.PI ) ),
5772 if ( getOptions().isShowScale() ) {
5773 if ( !( to_graphics_file || to_pdf ) ) {
5776 getVisibleRect().y + getVisibleRect().height,
5781 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
5784 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5785 g.setColor( getTreeColorSet().getOvColor() );
5786 paintUnrootedLite( _phylogeny.getRoot(),
5788 angle + ( 2 * Math.PI ),
5790 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
5791 paintOvRectangle( g );
5794 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
5795 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() )
5796 / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
5797 final int d = radius + MOVE + getLongestExtNodeInfo();
5798 _dynamic_hiding_factor = 0;
5799 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
5800 _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5
5801 * getPhylogeny().getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
5803 if ( getControlPanel().getDynamicallyHideData() != null ) {
5804 if ( _dynamic_hiding_factor > 1 ) {
5805 getControlPanel().setDynamicHidingIsOn( true );
5808 getControlPanel().setDynamicHidingIsOn( false );
5811 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
5812 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5813 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
5814 : getOvMaxWidth() / 2 );
5815 double x_scale = 1.0;
5816 double y_scale = 1.0;
5817 int x_pos = getVisibleRect().x + getOvXPosition();
5818 int y_pos = getVisibleRect().y + getOvYPosition();
5819 if ( getWidth() > getHeight() ) {
5820 x_scale = ( double ) getHeight() / getWidth();
5821 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
5824 y_scale = ( double ) getWidth() / getHeight();
5825 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
5827 _at = g.getTransform();
5828 g.scale( x_scale, y_scale );
5829 paintCircularLite( _phylogeny,
5833 ( int ) ( radius_ov - ( getLongestExtNodeInfo()
5834 / ( getVisibleRect().width / getOvRectangle().getWidth() ) ) ),
5836 g.setTransform( _at );
5837 paintOvRectangle( g );
5842 final void recalculateMaxDistanceToRoot() {
5843 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
5844 if ( getPhylogeny().getRoot().getDistanceToParent() > 0 ) {
5845 _max_distance_to_root += getPhylogeny().getRoot().getDistanceToParent();
5850 * Remove all edit-node frames
5852 final void removeAllEditNodeJFrames() {
5853 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
5854 if ( _node_frames[ i ] != null ) {
5855 _node_frames[ i ].dispose();
5856 _node_frames[ i ] = null;
5859 _node_frame_index = 0;
5863 * Remove a node-edit frame.
5865 final void removeEditNodeFrame( final int i ) {
5866 _node_frame_index--;
5867 _node_frames[ i ] = null;
5868 if ( i < _node_frame_index ) {
5869 for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) {
5870 _node_frames[ j ] = _node_frames[ j + 1 ];
5872 _node_frames[ _node_frame_index ] = null;
5876 final void reRoot( final PhylogenyNode node ) {
5877 if ( !getPhylogeny().isRerootable() ) {
5878 JOptionPane.showMessageDialog( this,
5879 "This is not rerootable",
5881 JOptionPane.WARNING_MESSAGE );
5884 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5885 JOptionPane.showMessageDialog( this,
5886 "Cannot reroot in unrooted display type",
5887 "Attempt to reroot tree in unrooted display",
5888 JOptionPane.WARNING_MESSAGE );
5891 getPhylogeny().reRoot( node );
5892 getPhylogeny().recalculateNumberOfExternalDescendants( true );
5893 resetNodeIdToDistToLeafMap();
5894 setNodeInPreorderToNull();
5895 resetPreferredSize();
5896 getMainPanel().adjustJScrollPane();
5899 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
5900 getControlPanel().showWhole();
5904 final void resetNodeIdToDistToLeafMap() {
5905 _nodeid_dist_to_leaf = new HashMap<Long, Short>();
5908 final void resetPreferredSize() {
5909 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
5915 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
5916 if ( getControlPanel().isDrawPhylogram() ) {
5917 x = TreePanel.MOVE + getLongestExtNodeInfo()
5918 + ForesterUtil.roundToInt( ( getXcorrectionFactor()
5919 * getPhylogeny().calculateHeight( !_options.isCollapsedWithAverageHeigh() ) )
5923 if ( !isNonLinedUpCladogram() ) {
5924 x = TreePanel.MOVE + getLongestExtNodeInfo() + ForesterUtil
5925 .roundToInt( getXdistance() * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
5928 x = TreePanel.MOVE + getLongestExtNodeInfo() + ForesterUtil
5929 .roundToInt( getXdistance() * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
5932 setPreferredSize( new Dimension( x, y ) );
5935 final void selectNode( final PhylogenyNode node ) {
5936 if ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) ) {
5937 getFoundNodes0().remove( node.getId() );
5938 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
5939 if ( getFoundNodes0().size() < 1 ) {
5940 getControlPanel().searchReset0();
5944 getControlPanel().getSearchFoundCountsLabel0().setVisible( true );
5945 getControlPanel().getSearchResetButton0().setEnabled( true );
5946 getControlPanel().getSearchResetButton0().setVisible( true );
5947 if ( getFoundNodes0() == null ) {
5948 setFoundNodes0( new HashSet<Long>() );
5950 getFoundNodes0().add( node.getId() );
5951 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
5955 final void setArrowCursor() {
5956 setCursor( ARROW_CURSOR );
5960 final void setControlPanel( final ControlPanel atv_control ) {
5961 _control_panel = atv_control;
5964 void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
5965 increaseCurrentExternalNodesDataBufferChangeCounter();
5966 _current_external_nodes_data_buffer = sb;
5969 final void setFoundNodes0( final Set<Long> found_nodes ) {
5970 _found_nodes_0 = found_nodes;
5973 final void setFoundNodes1( final Set<Long> found_nodes ) {
5974 _found_nodes_1 = found_nodes;
5977 final void setInOvRect( final boolean in_ov_rect ) {
5978 _in_ov_rect = in_ov_rect;
5981 final void setLargeFonts() {
5982 getTreeFontSet().largeFonts();
5985 final void setLastMouseDragPointX( final float x ) {
5986 _last_drag_point_x = x;
5989 final void setLastMouseDragPointY( final float y ) {
5990 _last_drag_point_y = y;
5993 final void setMediumFonts() {
5994 getTreeFontSet().mediumFonts();
5997 final void setNodeInPreorderToNull() {
5998 _nodes_in_preorder = null;
6001 final void setOvOn( final boolean ov_on ) {
6005 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
6006 _graphics_type = graphics_type;
6010 final void setSmallFonts() {
6011 getTreeFontSet().smallFonts();
6014 final void setStartingAngle( final double starting_angle ) {
6015 _urt_starting_angle = starting_angle;
6018 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
6019 _statistics_for_vector_data = statistics_for_expression_values;
6022 final void setSuperTinyFonts() {
6023 getTreeFontSet().superTinyFonts();
6026 final void setTextAntialias() {
6027 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
6028 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
6029 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
6032 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
6035 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
6036 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
6038 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
6040 // catch ( final Throwable e ) {
6041 // _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
6045 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
6046 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
6050 final void setTinyFonts() {
6051 getTreeFontSet().tinyFonts();
6054 final void setTreeFile( final File treefile ) {
6055 _treefile = treefile;
6058 final void setXcorrectionFactor( final float f ) {
6059 _x_correction_factor = f;
6062 final void setXdistance( final float x ) {
6066 final void setYdistance( final float y ) {
6070 final void sortDescendants( final PhylogenyNode node ) {
6071 if ( !node.isExternal() ) {
6072 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
6073 if ( getControlPanel().isShowTaxonomyScientificNames() || getControlPanel().isShowTaxonomyCode() ) {
6074 pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
6076 else if ( getControlPanel().isShowSeqNames() || getControlPanel().isShowSeqSymbols()
6077 || getControlPanel().isShowGeneNames() ) {
6078 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
6080 PhylogenyMethods.sortNodeDescendents( node, pri );
6081 setNodeInPreorderToNull();
6082 _phylogeny.externalNodesHaveChanged();
6083 _phylogeny.clearHashIdToNodeMap();
6084 _phylogeny.recalculateNumberOfExternalDescendants( true );
6085 resetNodeIdToDistToLeafMap();
6091 final void subTree( final PhylogenyNode node ) {
6092 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
6093 JOptionPane.showMessageDialog( this,
6094 "Cannot get a sub/super tree in unrooted display",
6095 "Attempt to get sub/super tree in unrooted display",
6096 JOptionPane.WARNING_MESSAGE );
6099 if ( node.isExternal() ) {
6100 JOptionPane.showMessageDialog( this,
6101 "Cannot get a subtree of a external node",
6102 "Attempt to get subtree of external node",
6103 JOptionPane.WARNING_MESSAGE );
6106 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
6107 JOptionPane.showMessageDialog( this,
6108 "Cannot get a subtree of the root node",
6109 "Attempt to get subtree of root node",
6110 JOptionPane.WARNING_MESSAGE );
6113 setNodeInPreorderToNull();
6114 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
6115 _sub_phylogenies[ _subtree_index ] = _phylogeny;
6116 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
6118 _phylogeny = TreePanelUtil.subTree( node, _phylogeny );
6119 if ( _phylogeny.getRoot().isCollapse() ) {
6120 _phylogeny.getRoot().setCollapse( false );
6122 _phylogeny.externalNodesHaveChanged();
6123 _phylogeny.clearHashIdToNodeMap();
6124 _phylogeny.recalculateNumberOfExternalDescendants( true );
6125 updateSubSuperTreeButton();
6126 getMainPanel().getControlPanel().search0();
6127 getMainPanel().getControlPanel().search1();
6128 resetRankCollapseRankValue();
6129 resetDepthCollapseDepthValue();
6130 getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
6131 getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay();
6132 getMainPanel().getControlPanel().updateRankCollapseRankDisplay();
6134 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
6137 _main_panel.getControlPanel().showWhole();
6141 final void superTree() {
6142 setNodeInPreorderToNull();
6143 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
6144 for( final PhylogenyNode n : temp_root.getDescendants() ) {
6145 n.setParent( temp_root );
6147 _sub_phylogenies[ _subtree_index ] = null;
6148 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
6149 _phylogeny = _sub_phylogenies[ --_subtree_index ];
6150 _phylogeny.externalNodesHaveChanged();
6151 _phylogeny.clearHashIdToNodeMap();
6152 _phylogeny.recalculateNumberOfExternalDescendants( true );
6153 getMainPanel().getControlPanel().search0();
6154 getMainPanel().getControlPanel().search1();
6155 resetRankCollapseRankValue();
6156 resetDepthCollapseDepthValue();
6157 getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
6158 getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay();
6159 getMainPanel().getControlPanel().updateRankCollapseRankDisplay();
6160 updateSubSuperTreeButton();
6163 final void orderSubtree( final PhylogenyNode node ) {
6164 if ( node.isExternal() ) {
6167 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
6168 if ( getControlPanel().isShowTaxonomyScientificNames() || getControlPanel().isShowTaxonomyCode() ) {
6169 pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
6171 else if ( getControlPanel().isShowSeqNames() || getControlPanel().isShowSeqSymbols()
6172 || getControlPanel().isShowGeneNames() ) {
6173 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
6175 PhylogenyMethods.orderAppearanceX( node, true, pri );
6176 setNodeInPreorderToNull();
6177 getPhylogeny().externalNodesHaveChanged();
6178 getPhylogeny().clearHashIdToNodeMap();
6179 getPhylogeny().recalculateNumberOfExternalDescendants( true );
6180 resetNodeIdToDistToLeafMap();
6182 getControlPanel().displayedPhylogenyMightHaveChanged( true );
6186 final void swap( final PhylogenyNode node ) {
6187 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
6190 if ( node.getNumberOfDescendants() > 2 ) {
6191 JOptionPane.showMessageDialog( this,
6192 "Cannot swap descendants of nodes with more than 2 descendants",
6193 "Cannot swap descendants",
6194 JOptionPane.ERROR_MESSAGE );
6197 if ( !node.isExternal() ) {
6198 node.swapChildren();
6199 setNodeInPreorderToNull();
6200 _phylogeny.externalNodesHaveChanged();
6201 _phylogeny.clearHashIdToNodeMap();
6202 _phylogeny.recalculateNumberOfExternalDescendants( true );
6203 resetNodeIdToDistToLeafMap();
6209 final void taxColor() {
6210 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
6214 TreePanelUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
6215 _control_panel.setColorBranches( true );
6216 if ( _control_panel.getUseVisualStylesCb() != null ) {
6217 _control_panel.getUseVisualStylesCb().setSelected( true );
6224 final void updateOvSettings() {
6225 switch ( getOptions().getOvPlacement() ) {
6227 setOvXPosition( OV_BORDER );
6228 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
6229 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
6232 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
6233 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
6234 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
6237 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
6238 setOvYPosition( OV_BORDER );
6239 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
6242 setOvXPosition( OV_BORDER );
6243 setOvYPosition( OV_BORDER );
6244 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
6249 final void updateOvSizes() {
6250 if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) )
6251 || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) {
6253 float l = getLongestExtNodeInfo();
6254 final float w_ratio = getOvMaxWidth() / getWidth();
6256 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
6257 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
6259 if ( !isNonLinedUpCladogram() ) {
6260 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
6263 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
6265 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
6266 if ( ov_xdist < 0.0 ) {
6269 if ( ydist < 0.0 ) {
6272 setOvXDistance( ov_xdist );
6273 final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() );
6275 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
6276 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
6279 setOvXcorrectionFactor( 0 );
6287 void updateSetOfCollapsedExternalNodes() {
6288 final Phylogeny phy = getPhylogeny();
6289 _collapsed_external_nodeid_set.clear();
6290 if ( phy != null ) {
6291 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
6292 final PhylogenyNode ext_node = it.next();
6293 PhylogenyNode n = ext_node;
6294 while ( !n.isRoot() ) {
6295 if ( n.isCollapse() ) {
6296 _collapsed_external_nodeid_set.add( ext_node.getId() );
6297 ext_node.setCollapse( true );
6306 final void updateSubSuperTreeButton() {
6307 if ( _subtree_index < 1 ) {
6308 getControlPanel().deactivateButtonToReturnToSuperTree();
6311 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
6315 final void updateButtonToUncollapseAll() {
6316 if ( PhylogenyMethods.isHasCollapsedNodes( _phylogeny ) ) {
6317 getControlPanel().activateButtonToUncollapseAll();
6320 getControlPanel().deactivateButtonToUncollapseAll();
6324 final void zoomInDomainStructure() {
6325 if ( _domain_structure_width < 2000 ) {
6326 _domain_structure_width *= 1.2;
6330 final void zoomOutDomainStructure() {
6331 if ( _domain_structure_width > 20 ) {
6332 _domain_structure_width *= 0.8;
6336 private final static void colorizeNodesHelper( final Color c, final PhylogenyNode node ) {
6337 if ( node.getNodeData().getNodeVisualData() == null ) {
6338 node.getNodeData().setNodeVisualData( new NodeVisualData() );
6340 node.getNodeData().getNodeVisualData().setFontColor( new Color( c.getRed(), c.getGreen(), c.getBlue() ) );
6343 final private static void drawString( final String str, final float x, final float y, final Graphics2D g ) {
6344 g.drawString( str, x, y );
6347 final private void drawStringX( final String str, final float x, final float y, final Graphics2D g ) {
6350 if ( getAttributedStringMap() == null /*&& getAttributedStringMap().containsKey(str) */ ) {
6351 final AttributedString as = new AttributedString( str );
6352 //Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);
6353 as.addAttribute( TextAttribute.FONT, g.getFont() );
6354 as.addAttribute( TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 3 );
6355 as.addAttribute( TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 3, 4 );
6356 as.addAttribute( TextAttribute.FOREGROUND, Color.BLUE, 1, 2 );
6357 as.addAttribute( TextAttribute.FOREGROUND, Color.PINK, 3, 5 );
6358 as.addAttribute( TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 2, 4 );
6359 g.drawString( as.getIterator(), x, y );
6362 g.drawString( str, x, y );
6366 private final Map<String, AttributedString> getAttributedStringMap() {
6367 return _attributed_string_map;
6370 private final void setAttributedStringMap( final Map<String, AttributedString> attributed_string_map ) {
6371 _attributed_string_map = attributed_string_map;
6374 final private static boolean plusPressed( final int key_code ) {
6375 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
6376 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON )
6377 || ( key_code == KeyEvent.VK_1 ) );
6380 public void decreaseDepthCollapseLevel() {
6381 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6382 if ( _depth_collapse_level <= 1 ) {
6383 _depth_collapse_level = PhylogenyMethods.calculateMaxDepth( _phylogeny );
6387 --_depth_collapse_level;
6388 PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level );
6393 public void increaseDepthCollapseLevel() {
6394 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6395 final int max = PhylogenyMethods.calculateMaxDepth( _phylogeny );
6396 if ( _depth_collapse_level >= max ) {
6397 _depth_collapse_level = 1;
6400 ++_depth_collapse_level;
6402 PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level );
6406 public void decreaseRankCollapseLevel() {
6407 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6408 final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny );
6409 if ( ranks.length > 1 ) {
6410 if ( _rank_collapse_level <= 0 ) {
6411 _rank_collapse_level = ranks.length - 1;
6415 --_rank_collapse_level;
6416 PhylogenyMethods.collapseToRank( _phylogeny,
6417 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6423 public void increaseRankCollapseLevel() {
6424 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6425 final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny );
6426 if ( ranks.length > 1 ) {
6427 if ( _rank_collapse_level >= ( ranks.length - 1 ) ) {
6428 _rank_collapse_level = 0;
6429 PhylogenyMethods.collapseToRank( _phylogeny,
6430 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6432 else if ( _rank_collapse_level == ( ranks.length - 2 ) ) {
6433 ++_rank_collapse_level;
6437 ++_rank_collapse_level;
6438 PhylogenyMethods.collapseToRank( _phylogeny,
6439 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6445 private final static int mapToAbsoluteRankLevel( final String present_ranks_sorted[],
6446 final int rank_collapse_level ) {
6447 final String rank_str = present_ranks_sorted[ rank_collapse_level ];
6448 if ( !TaxonomyUtil.RANK_TO_INT.containsKey( rank_str ) ) {
6449 throw new IllegalStateException( "unexpected exception: cannot find rank " + rank_str );
6451 return TaxonomyUtil.RANK_TO_INT.get( rank_str );
6454 private final void uncollapseAll() {
6455 final PhylogenyNodeIterator it = new PreorderTreeIterator( _phylogeny );
6456 while ( it.hasNext() ) {
6457 it.next().setCollapse( false );
6461 final int resetDepthCollapseDepthValue() {
6462 return _depth_collapse_level = -1;
6465 final int getDepthCollapseDepthValue() {
6466 return _depth_collapse_level;
6469 final void setDepthCollapseDepthValue( final int depth_collapse_level ) {
6470 _depth_collapse_level = depth_collapse_level;
6473 final int resetRankCollapseRankValue() {
6474 return _rank_collapse_level = -1;
6477 final int getRankCollapseRankValue() {
6478 return _rank_collapse_level;
6481 final void setRankCollapseRankValue( final int rank_collapse_level ) {
6482 _rank_collapse_level = rank_collapse_level;