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.phylogeny.data.RenderableDomainArchitecture;
103 import org.forester.archaeopteryx.phylogeny.data.RenderableMsaSequence;
104 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
105 import org.forester.archaeopteryx.tools.Blast;
106 import org.forester.archaeopteryx.tools.ImageLoader;
107 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
108 import org.forester.io.writers.SequenceWriter;
109 import org.forester.phylogeny.Phylogeny;
110 import org.forester.phylogeny.PhylogenyMethods;
111 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
112 import org.forester.phylogeny.PhylogenyNode;
113 import org.forester.phylogeny.data.Accession;
114 import org.forester.phylogeny.data.Annotation;
115 import org.forester.phylogeny.data.BranchColor;
116 import org.forester.phylogeny.data.Confidence;
117 import org.forester.phylogeny.data.DomainArchitecture;
118 import org.forester.phylogeny.data.Event;
119 import org.forester.phylogeny.data.NodeDataField;
120 import org.forester.phylogeny.data.NodeVisualData;
121 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
122 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
123 import org.forester.phylogeny.data.PhylogenyDataUtil;
124 import org.forester.phylogeny.data.ProteinDomain;
125 import org.forester.phylogeny.data.Sequence;
126 import org.forester.phylogeny.data.SequenceRelation;
127 import org.forester.phylogeny.data.Taxonomy;
128 import org.forester.phylogeny.data.Uri;
129 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
130 import org.forester.phylogeny.iterators.PreorderTreeIterator;
131 import org.forester.util.DescriptiveStatistics;
132 import org.forester.util.ForesterConstants;
133 import org.forester.util.ForesterUtil;
134 import org.forester.util.SequenceAccessionTools;
135 import org.forester.util.TaxonomyUtil;
137 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
139 final private class NodeColorizationActionListener implements ActionListener {
141 List<PhylogenyNode> _additional_nodes = null;
142 JColorChooser _chooser = null;
143 PhylogenyNode _node = null;
145 NodeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
150 NodeColorizationActionListener( final JColorChooser chooser,
151 final PhylogenyNode node,
152 final List<PhylogenyNode> additional_nodes ) {
155 _additional_nodes = additional_nodes;
159 public void actionPerformed( final ActionEvent e ) {
160 final Color c = _chooser.getColor();
162 colorizeNodes( c, _node, _additional_nodes );
167 final private class SubtreeColorizationActionListener implements ActionListener {
169 List<PhylogenyNode> _additional_nodes = null;
170 JColorChooser _chooser = null;
171 PhylogenyNode _node = null;
173 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
178 SubtreeColorizationActionListener( final JColorChooser chooser,
179 final PhylogenyNode node,
180 final List<PhylogenyNode> additional_nodes ) {
183 _additional_nodes = additional_nodes;
187 public void actionPerformed( final ActionEvent e ) {
188 final Color c = _chooser.getColor();
190 colorizeSubtree( c, _node, _additional_nodes );
194 public final static boolean SPECIAL_DOMAIN_COLORING = true;
195 final static Cursor ARROW_CURSOR = Cursor
196 .getPredefinedCursor( Cursor.DEFAULT_CURSOR );
197 final static Cursor CUT_CURSOR = Cursor
198 .getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
199 final static Cursor HAND_CURSOR = Cursor
200 .getPredefinedCursor( Cursor.HAND_CURSOR );
201 final static Cursor MOVE_CURSOR = Cursor
202 .getPredefinedCursor( Cursor.MOVE_CURSOR );
203 final static Cursor WAIT_CURSOR = Cursor
204 .getPredefinedCursor( Cursor.WAIT_CURSOR );
205 final private static double _180_OVER_PI = 180.0 / Math.PI;
206 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI
208 private final static int CONFIDENCE_LEFT_MARGIN = 4;
209 private final static int EURO_D = 10;
210 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
211 private final static NumberFormat FORMATTER_CONFIDENCE;
212 private static final float HALF_PI = ( float ) ( Math.PI
214 private final static int LIMIT_FOR_HQ_RENDERING = 2000;
215 private final static int MAX_NODE_FRAMES = 10;
216 private final static int MAX_SUBTREES = 100;
217 private final static int MIN_ROOT_LENGTH = 3;
218 private final static int MOVE = 20;
219 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
220 private static final float ONEHALF_PI = ( float ) ( 1.5
222 private static final short OV_BORDER = 10;
223 private final static double OVERVIEW_FOUND_NODE_BOX_SIZE = 2;
224 private final static double OVERVIEW_FOUND_NODE_BOX_SIZE_HALF = 1;
225 private static final float PI = ( float ) ( Math.PI );
226 final private static Font POPUP_FONT = new Font( Configuration
227 .getDefaultFontFamilyName(), Font.PLAIN, 12 );
228 private static final float ROUNDED_D = 8;
229 private final static long serialVersionUID = -978349745916505029L;
230 private static final BasicStroke STROKE_0025 = new BasicStroke( 0.025f );
231 private static final BasicStroke STROKE_005 = new BasicStroke( 0.05f );
232 private static final BasicStroke STROKE_01 = new BasicStroke( 0.1f );
233 private static final BasicStroke STROKE_025 = new BasicStroke( 0.25f );
234 private static final BasicStroke STROKE_05 = new BasicStroke( 0.5f );
235 private static final BasicStroke STROKE_075 = new BasicStroke( 0.75f );
236 private static final BasicStroke STROKE_1 = new BasicStroke( 1f );
237 private static final BasicStroke STROKE_2 = new BasicStroke( 2f );
238 private static final BasicStroke STROKE_01_DASHED = new BasicStroke( 0.1f,
239 BasicStroke.CAP_SQUARE,
240 BasicStroke.JOIN_ROUND,
245 private static final BasicStroke STROKE_005_DASHED = new BasicStroke( 0.05f,
246 BasicStroke.CAP_SQUARE,
247 BasicStroke.JOIN_ROUND,
252 private static final BasicStroke STROKE_001_DASHED = new BasicStroke( 0.01f,
253 BasicStroke.CAP_SQUARE,
254 BasicStroke.JOIN_ROUND,
259 private static final double TWO_PI = 2 * Math.PI;
260 private final static int WIGGLE = 2;
261 private static final String SHOW_ONLY_THIS_CONF_TYPE = null; //TODO remove me
262 HashMap<Long, Short> _nodeid_dist_to_leaf = new HashMap<Long, Short>();
263 final private Arc2D _arc = new Arc2D.Double();
264 private AffineTransform _at;
265 private int _circ_max_depth;
266 final private Set<Long> _collapsed_external_nodeid_set = new HashSet<Long>();
267 private JColorChooser _color_chooser = null;
268 private Configuration _configuration = null;
269 private ControlPanel _control_panel = null;
270 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
271 private Set<Long> _current_external_nodes = null;
272 private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
273 private int _current_external_nodes_data_buffer_change_counter = 0;
274 private int _domain_structure_e_value_thr_exp = AptxConstants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
275 private double _domain_structure_width = AptxConstants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
276 private int _dynamic_hiding_factor = 0;
277 private boolean _edited = false;
278 private final Ellipse2D _ellipse = new Ellipse2D.Float();
279 private int _external_node_index = 0;
280 private Set<Long> _found_nodes_0 = null;
281 private Set<Long> _found_nodes_1 = null;
282 private final FontRenderContext _frc = new FontRenderContext( null,
285 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
286 private PhylogenyNode _highlight_node = null;
287 private boolean _in_ov = false;
288 private boolean _in_ov_rect = false;
289 private float _last_drag_point_x = 0;
290 private float _last_drag_point_y = 0;
291 private final Line2D _line = new Line2D.Float();
292 private int _longest_ext_node_info = 0;
293 private PhylogenyNode _ext_node_with_longest_txt_info = null;
294 private MainPanel _main_panel = null;
295 private double _max_distance_to_root = -1;
296 private Popup _node_desc_popup;
297 private int _node_frame_index = 0;
298 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
299 private JPopupMenu _node_popup_menu = null;
300 private JMenuItem _node_popup_menu_items[] = null;
301 private PhylogenyNode[] _nodes_in_preorder = null;
302 private Options _options = null;
303 private float _ov_max_height = 0;
304 private float _ov_max_width = 0;
305 private boolean _ov_on = false;
306 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
307 private final Rectangle _ov_virtual_rectangle = new Rectangle();
308 private float _ov_x_correction_factor = 0.0f;
309 private float _ov_x_distance = 0;
310 private int _ov_x_position = 0;
311 private float _ov_y_distance = 0;
312 private int _ov_y_position = 0;
313 private int _ov_y_start = 0;
314 private final boolean _phy_has_branch_lengths;
315 private Phylogeny _phylogeny = null;
316 private final Path2D.Float _polygon = new Path2D.Float();
317 private final StringBuffer _popup_buffer = new StringBuffer();
318 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
319 private Sequence _query_sequence = null;
320 private final Rectangle2D _rectangle = new Rectangle2D.Float();
321 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
322 RenderingHints.VALUE_RENDER_DEFAULT );
323 private JTextArea _rollover_popup;
324 private PhylogenyNode _root;
325 private final StringBuilder _sb = new StringBuilder();
326 private double _scale_distance = 0.0;
327 private String _scale_label = null;
328 private DescriptiveStatistics _statistics_for_vector_data;
329 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
330 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
331 private int _subtree_index = 0;
332 private File _treefile = null;
333 private float _urt_factor = 1;
334 private float _urt_factor_ov = 1;
335 final private HashMap<Long, Double> _urt_nodeid_angle_map = new HashMap<Long, Double>();
336 final private HashMap<Long, Integer> _urt_nodeid_index_map = new HashMap<Long, Integer>();
337 private double _urt_starting_angle = ( float ) ( Math.PI
339 private float _x_correction_factor = 0.0f;
340 private float _x_distance = 0.0f;
341 private float _y_distance = 0.0f;
342 private int _length_of_longest_text;
343 private int _longest_domain;
344 private Map<String, AttributedString> _attributed_string_map = null;
345 private int _depth_collapse_level = -1;
346 private int _rank_collapse_level = -1;
348 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
349 dfs.setDecimalSeparator( '.' );
350 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
351 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
354 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
355 requestFocusInWindow();
356 addKeyListener( new KeyAdapter() {
359 public void keyPressed( final KeyEvent key_event ) {
360 keyPressedCalls( key_event );
361 requestFocusInWindow();
364 addFocusListener( new FocusAdapter() {
367 public void focusGained( final FocusEvent e ) {
368 requestFocusInWindow();
371 if ( ( t == null ) || t.isEmpty() ) {
372 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
374 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
376 _configuration = configuration;
378 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
380 // if ( !_phylogeny.isEmpty() ) {
381 _phylogeny.recalculateNumberOfExternalDescendants( true );
383 setBackground( getTreeColorSet().getBackgroundColor() );
384 final MouseListener mouse_listener = new MouseListener( this );
385 addMouseListener( mouse_listener );
386 addMouseMotionListener( mouse_listener );
387 addMouseWheelListener( this );
388 calculateScaleDistance();
389 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
390 FORMATTER_BRANCH_LENGTH
391 .setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() );
395 final public void actionPerformed( final ActionEvent e ) {
396 boolean done = false;
397 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
398 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
399 // NOTE: index corresponds to the indices of click-to options
400 // in the control panel.
401 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
402 // Set this as the new default click-to action
403 _main_panel.getControlPanel().setClickToAction( index );
404 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
405 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
406 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
411 requestFocusInWindow();
414 public synchronized Hashtable<String, BufferedImage> getImageMap() {
415 return getMainPanel().getImageMap();
418 final public MainPanel getMainPanel() {
423 * Get a pointer to the phylogeny
425 * @return a pointer to the phylogeny
427 public final Phylogeny getPhylogeny() {
431 public final TreeColorSet getTreeColorSet() {
432 return getMainPanel().getTreeColorSet();
436 final public void mouseWheelMoved( final MouseWheelEvent e ) {
437 final int notches = e.getWheelRotation();
438 if ( inOvVirtualRectangle( e ) ) {
439 if ( !isInOvRect() ) {
445 if ( isInOvRect() ) {
446 setInOvRect( false );
450 if ( e.isControlDown() && e.isShiftDown() ) {
452 getTreeFontSet().increaseFontSize();
455 getTreeFontSet().decreaseFontSize( 1, false );
457 getControlPanel().displayedPhylogenyMightHaveChanged( true );
458 resetPreferredSize();
462 else if ( e.isShiftDown() && e.isAltDown() ) {
464 for( int i = 0; i < ( -notches ); ++i ) {
465 getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR, AptxConstants.WHEEL_ZOOM_IN_FACTOR );
466 getControlPanel().displayedPhylogenyMightHaveChanged( false );
470 for( int i = 0; i < notches; ++i ) {
471 getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
472 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
473 getControlPanel().displayedPhylogenyMightHaveChanged( false );
477 else if ( e.isShiftDown() ) {
478 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
479 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
481 for( int i = 0; i < ( -notches ); ++i ) {
482 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
483 getControlPanel().displayedPhylogenyMightHaveChanged( false );
487 for( int i = 0; i < notches; ++i ) {
488 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
489 if ( getStartingAngle() < 0 ) {
490 setStartingAngle( TWO_PI + getStartingAngle() );
492 getControlPanel().displayedPhylogenyMightHaveChanged( false );
498 for( int i = 0; i < ( -notches ); ++i ) {
499 getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
500 getControlPanel().displayedPhylogenyMightHaveChanged( false );
504 for( int i = 0; i < notches; ++i ) {
505 getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
506 getControlPanel().displayedPhylogenyMightHaveChanged( false );
513 for( int i = 0; i < ( -notches ); ++i ) {
514 getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
515 AptxConstants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
516 getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
517 getControlPanel().displayedPhylogenyMightHaveChanged( false );
521 for( int i = 0; i < notches; ++i ) {
522 getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
523 getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
524 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
525 getControlPanel().displayedPhylogenyMightHaveChanged( false );
530 requestFocusInWindow();
535 final public void paintComponent( final Graphics g ) {
536 // Dimension currentSize = getSize();
537 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
538 // call the 'java.awt.Component.createImage(...)' method to get an
540 // offscreenImage = createImage( currentSize.width, currentSize.height );
541 // offscreenGraphics = offscreenImage.getGraphics();
542 // offscreenDimension = currentSize;
544 // super.paintComponent( g ); //why?
545 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
546 final Graphics2D g2d = ( Graphics2D ) g;
547 g2d.setRenderingHints( _rendering_hints );
548 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
549 //g.drawImage( offscreenImage, 0, 0, this );
553 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
554 throws PrinterException {
555 if ( page_index > 0 ) {
556 return ( NO_SUCH_PAGE );
559 final Graphics2D g2d = ( Graphics2D ) g;
560 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
561 // Turn off double buffering !?
562 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
563 // Turn double buffering back on !?
564 return ( PAGE_EXISTS );
568 public final void setEdited( final boolean edited ) {
572 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
573 getMainPanel().setImageMap( image_map );
577 * Set a phylogeny tree.
580 * an instance of a Phylogeny
582 public final void setTree( final Phylogeny t ) {
583 setNodeInPreorderToNull();
587 public final void setWaitCursor() {
588 setCursor( WAIT_CURSOR );
593 public void update( final Graphics g ) {
597 private void abbreviateScientificName( final String sn, final StringBuilder sb ) {
598 final String[] a = sn.split( "\\s+" );
599 sb.append( a[ 0 ].substring( 0, 1 ) );
600 sb.append( a[ 1 ].substring( 0, 2 ) );
601 if ( a.length > 2 ) {
602 for( int i = 2; i < a.length; i++ ) {
609 final private void addEmptyNode( final PhylogenyNode node ) {
610 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
611 errorMessageNoCutCopyPasteInUnrootedDisplay();
614 final String label = createASimpleTextRepresentationOfANode( node );
616 if ( ForesterUtil.isEmpty( label ) ) {
617 msg = "How to add the new, empty node?";
620 msg = "How to add the new, empty node to node" + label + "?";
622 final Object[] options = { "As sibling", "As descendant", "Cancel" };
623 final int r = JOptionPane.showOptionDialog( this,
625 "Addition of Empty New Node",
626 JOptionPane.CLOSED_OPTION,
627 JOptionPane.QUESTION_MESSAGE,
631 boolean add_as_sibling = true;
633 add_as_sibling = false;
638 final Phylogeny phy = new Phylogeny();
639 phy.setRoot( new PhylogenyNode() );
640 phy.setRooted( true );
641 if ( add_as_sibling ) {
642 if ( node.isRoot() ) {
643 JOptionPane.showMessageDialog( this,
644 "Cannot add sibling to root",
645 "Attempt to add sibling to root",
646 JOptionPane.ERROR_MESSAGE );
649 phy.addAsSibling( node );
652 phy.addAsChild( node );
654 setNodeInPreorderToNull();
655 _phylogeny.externalNodesHaveChanged();
656 _phylogeny.clearHashIdToNodeMap();
657 _phylogeny.recalculateNumberOfExternalDescendants( true );
658 resetNodeIdToDistToLeafMap();
663 final private void addToCurrentExternalNodes( final long i ) {
664 if ( _current_external_nodes == null ) {
665 _current_external_nodes = new HashSet<Long>();
667 _current_external_nodes.add( i );
670 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
671 final boolean is_vertical,
673 final boolean to_pdf,
674 final boolean to_graphics_file ) {
675 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
676 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
677 g.setColor( Color.BLACK );
679 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
680 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE )
681 || ( action == NodeClickAction.ADD_NEW_NODE ) ) && ( getCutOrCopiedTree() != null )
682 && ( getCopiedAndPastedNodes() != null ) && !to_pdf && !to_graphics_file
683 && getCopiedAndPastedNodes().contains( node.getId() ) ) {
684 g.setColor( getTreeColorSet().getFoundColor0() );
686 else if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
687 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
690 g.setColor( getTreeColorSet().getBranchColorForPdf() );
693 g.setColor( getTreeColorSet().getBranchColor() );
697 final private void blast( final PhylogenyNode node ) {
698 if ( !isCanBlast( node ) ) {
699 JOptionPane.showMessageDialog( this,
700 "Insufficient information present",
702 JOptionPane.INFORMATION_MESSAGE );
706 final String query = Blast.obtainQueryForBlast( node );
707 System.out.println( "query for BLAST is: " + query );
709 if ( !ForesterUtil.isEmpty( query ) ) {
710 if ( node.getNodeData().isHasSequence() ) {
711 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
712 if ( node.getNodeData().getSequence().getType().toLowerCase()
713 .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
720 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
722 .seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) {
731 if ( SequenceAccessionTools.isProteinDbQuery( query ) ) {
739 Blast.openNcbiBlastWeb( query, type == 'n', this );
741 catch ( final Exception e ) {
748 private final int calcDynamicHidingFactor() {
749 return ( int ) ( 0.5 + ( getFontMetricsForLargeDefaultFont().getHeight() / ( 1.5 * getYdistance() ) ) );
752 final private int calcLengthOfLongestText() {
753 final StringBuilder sb = new StringBuilder();
754 if ( _ext_node_with_longest_txt_info != null ) {
755 nodeDataAsSB( _ext_node_with_longest_txt_info, sb );
756 if ( _ext_node_with_longest_txt_info.getNodeData().isHasTaxonomy() ) {
757 nodeTaxonomyDataAsSB( _ext_node_with_longest_txt_info.getNodeData().getTaxonomy(), sb );
760 return getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
764 * Calculate the length of the distance between the given node and its
770 * @return the distance value
772 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
773 if ( getControlPanel().isDrawPhylogram() ) {
774 if ( node.getDistanceToParent() < 0.0 ) {
777 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
780 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
781 return getXdistance();
783 return getXdistance() * factor;
787 final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
788 Color c = getTreeColorSet().getAnnotationColor();
789 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
790 final StringBuilder sb = new StringBuilder();
791 for( final Annotation a : ann ) {
792 sb.append( !ForesterUtil.isEmpty( a.getRefValue() ) ? a.getRefValue() : a.getDesc() );
794 final String ann_str = sb.toString();
795 if ( !ForesterUtil.isEmpty( ann_str ) ) {
796 c = getControlPanel().getAnnotationColors().get( ann_str );
798 c = AptxUtil.calculateColorFromString( ann_str, false );
799 getControlPanel().getAnnotationColors().put( ann_str, c );
802 c = getTreeColorSet().getAnnotationColor();
809 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
810 if ( getControlPanel().isDrawPhylogram() ) {
811 if ( node.getDistanceToParent() < 0.0 ) {
814 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
817 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
818 return getOvXDistance();
820 return getOvXDistance() * factor;
824 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
825 JOptionPane.showMessageDialog( this,
826 "Cannot launch web browser for " + type_type + " data of this node",
827 "Cannot launch web browser",
828 JOptionPane.WARNING_MESSAGE );
831 private void changeNodeFont( final PhylogenyNode node ) {
832 final FontChooser fc = new FontChooser();
834 if ( ( node.getNodeData().getNodeVisualData() != null ) && !node.getNodeData().getNodeVisualData().isEmpty() ) {
835 f = node.getNodeData().getNodeVisualData().getFont();
841 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
843 List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
844 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
845 nodes = getFoundNodesAsListOfPhylogenyNodes();
847 if ( !nodes.contains( node ) ) {
850 final int count = nodes.size();
851 String title = "Change the font for ";
856 title += ( count + " nodes" );
858 fc.showDialog( this, title );
859 if ( ( fc.getFont() != null ) && !ForesterUtil.isEmpty( fc.getFont().getFamily().trim() ) ) {
860 for( final PhylogenyNode n : nodes ) {
861 if ( n.getNodeData().getNodeVisualData() == null ) {
862 n.getNodeData().setNodeVisualData( new NodeVisualData() );
864 final NodeVisualData vd = n.getNodeData().getNodeVisualData();
865 final Font ff = fc.getFont();
866 vd.setFontName( ff.getFamily().trim() );
867 int s = ff.getSize();
871 if ( s > Byte.MAX_VALUE ) {
875 vd.setFontStyle( ff.getStyle() );
877 if ( _control_panel.getUseVisualStylesCb() != null ) {
878 getControlPanel().getUseVisualStylesCb().setSelected( true );
885 final private void colorizeNodes( final Color c,
886 final PhylogenyNode node,
887 final List<PhylogenyNode> additional_nodes ) {
888 _control_panel.setColorBranches( true );
889 if ( _control_panel.getUseVisualStylesCb() != null ) {
890 _control_panel.getUseVisualStylesCb().setSelected( true );
892 if ( node != null ) {
893 colorizeNodesHelper( c, node );
895 if ( additional_nodes != null ) {
896 for( final PhylogenyNode n : additional_nodes ) {
897 colorizeNodesHelper( c, n );
903 final private void colorizeSubtree( final Color c,
904 final PhylogenyNode node,
905 final List<PhylogenyNode> additional_nodes ) {
906 _control_panel.setColorBranches( true );
907 if ( _control_panel.getUseVisualStylesCb() != null ) {
908 _control_panel.getUseVisualStylesCb().setSelected( true );
910 if ( node != null ) {
911 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
912 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
915 if ( additional_nodes != null ) {
916 for( final PhylogenyNode an : additional_nodes ) {
917 for( final PreorderTreeIterator it = new PreorderTreeIterator( an ); it.hasNext(); ) {
918 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
925 private void colorNodeFont( final PhylogenyNode node ) {
926 _color_chooser.setPreviewPanel( new JPanel() );
927 NodeColorizationActionListener al;
929 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
930 final List<PhylogenyNode> additional_nodes = getFoundNodesAsListOfPhylogenyNodes();
931 al = new NodeColorizationActionListener( _color_chooser, node, additional_nodes );
932 count = additional_nodes.size();
933 if ( !additional_nodes.contains( node ) ) {
938 al = new NodeColorizationActionListener( _color_chooser, node );
940 String title = "Change the (node and font) color for ";
945 title += ( count + " nodes" );
947 final JDialog dialog = JColorChooser.createDialog( this, title, true, _color_chooser, al, null );
949 dialog.setVisible( true );
952 final private void colorSubtree( final PhylogenyNode node ) {
953 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
954 JOptionPane.showMessageDialog( this,
955 "Cannot colorize subtree in unrooted display type",
956 "Attempt to colorize subtree in unrooted display",
957 JOptionPane.WARNING_MESSAGE );
960 _color_chooser.setPreviewPanel( new JPanel() );
961 final SubtreeColorizationActionListener al;
962 final boolean color_found = getOptions().isColorAllFoundNodesWhenColoringSubtree();
963 if ( color_found && ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) ) {
964 final List<PhylogenyNode> additional_nodes = getFoundNodesAsListOfPhylogenyNodes();
965 al = new SubtreeColorizationActionListener( _color_chooser, node, additional_nodes );
968 al = new SubtreeColorizationActionListener( _color_chooser, node );
970 final JDialog dialog = JColorChooser.createDialog( this,
971 "Subtree colorization",
977 dialog.setVisible( true );
980 final private void copySubtree( final PhylogenyNode node ) {
981 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
982 errorMessageNoCutCopyPasteInUnrootedDisplay();
985 setNodeInPreorderToNull();
986 setCutOrCopiedTree( _phylogeny.copy( node ) );
987 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
988 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
989 for( final PhylogenyNode n : nodes ) {
990 node_ids.add( n.getId() );
992 node_ids.add( node.getId() );
993 setCopiedAndPastedNodes( node_ids );
997 final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
998 final String tax = PhylogenyMethods.getSpecies( node );
999 String label = node.getName();
1000 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
1001 label = label + " " + tax;
1003 else if ( !ForesterUtil.isEmpty( tax ) ) {
1009 if ( !ForesterUtil.isEmpty( label ) ) {
1010 label = " [" + label + "]";
1015 final private void cutSubtree( final PhylogenyNode node ) {
1016 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1017 errorMessageNoCutCopyPasteInUnrootedDisplay();
1020 if ( node.isRoot() ) {
1021 JOptionPane.showMessageDialog( this,
1022 "Cannot cut entire tree as subtree",
1023 "Attempt to cut entire tree",
1024 JOptionPane.ERROR_MESSAGE );
1027 final String label = createASimpleTextRepresentationOfANode( node );
1028 final int r = JOptionPane.showConfirmDialog( null,
1029 "Cut subtree" + label + "?",
1030 "Confirm Cutting of Subtree",
1031 JOptionPane.YES_NO_OPTION );
1032 if ( r != JOptionPane.OK_OPTION ) {
1035 setNodeInPreorderToNull();
1036 setCopiedAndPastedNodes( null );
1037 setCutOrCopiedTree( _phylogeny.copy( node ) );
1038 _phylogeny.deleteSubtree( node, true );
1039 _phylogeny.clearHashIdToNodeMap();
1040 _phylogeny.recalculateNumberOfExternalDescendants( true );
1041 resetNodeIdToDistToLeafMap();
1046 final private void cycleColors() {
1047 getMainPanel().getTreeColorSet().cycleColorScheme();
1048 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
1049 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
1053 final private void decreaseOvSize() {
1054 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
1055 setOvMaxWidth( getOvMaxWidth() - 5 );
1056 setOvMaxHeight( getOvMaxHeight() - 5 );
1058 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1062 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
1063 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1064 errorMessageNoCutCopyPasteInUnrootedDisplay();
1067 if ( node.isRoot() && ( node.getNumberOfDescendants() != 1 ) ) {
1068 JOptionPane.showMessageDialog( this,
1069 "Cannot delete entire tree",
1070 "Attempt to delete entire tree",
1071 JOptionPane.ERROR_MESSAGE );
1074 final String label = createASimpleTextRepresentationOfANode( node );
1075 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
1076 final int r = JOptionPane.showOptionDialog( this,
1077 "Delete" + label + "?",
1078 "Delete Node/Subtree",
1079 JOptionPane.CLOSED_OPTION,
1080 JOptionPane.QUESTION_MESSAGE,
1084 setNodeInPreorderToNull();
1085 boolean node_only = true;
1089 else if ( r != 0 ) {
1093 PhylogenyMethods.removeNode( node, _phylogeny );
1096 _phylogeny.deleteSubtree( node, true );
1098 _phylogeny.externalNodesHaveChanged();
1099 _phylogeny.clearHashIdToNodeMap();
1100 _phylogeny.recalculateNumberOfExternalDescendants( true );
1101 resetNodeIdToDistToLeafMap();
1106 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
1107 makePopupMenus( node );
1108 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
1109 _node_popup_menu.show( this, x, y );
1112 final private void drawArc( final double x,
1115 final double heigth,
1116 final double start_angle,
1117 final double arc_angle,
1118 final Graphics2D g ) {
1119 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
1123 final private void drawLine( final double x1,
1127 final Graphics2D g ) {
1128 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
1131 _line.setLine( x1, y1, x2, y2 );
1135 final private void drawOval( final double x,
1138 final double heigth,
1139 final Graphics2D g ) {
1140 _ellipse.setFrame( x, y, width, heigth );
1144 final private void drawOvalFilled( final double x,
1147 final double heigth,
1148 final Graphics2D g ) {
1149 _ellipse.setFrame( x, y, width, heigth );
1153 final private void drawOvalGradient( final float x,
1158 final Color color_1,
1159 final Color color_2,
1160 final Color color_border ) {
1161 _ellipse.setFrame( x, y, width, heigth );
1162 g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) );
1164 if ( color_border != null ) {
1165 g.setPaint( color_border );
1170 final private void drawRect( final float x,
1174 final Graphics2D g ) {
1175 _rectangle.setFrame( x, y, width, heigth );
1176 g.draw( _rectangle );
1179 final private void drawRectFilled( final double x,
1182 final double heigth,
1183 final Graphics2D g ) {
1184 _rectangle.setFrame( x, y, width, heigth );
1185 g.fill( _rectangle );
1188 final private void drawRectGradient( final float x,
1193 final Color color_1,
1194 final Color color_2,
1195 final Color color_border ) {
1196 _rectangle.setFrame( x, y, width, heigth );
1197 g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) );
1198 g.fill( _rectangle );
1199 if ( color_border != null ) {
1200 g.setPaint( color_border );
1201 g.draw( _rectangle );
1205 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
1206 final List<Uri> us = new ArrayList<Uri>();
1207 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
1208 for( final Uri uri : t.getUris() ) {
1213 for( final Uri uri : us ) {
1214 if ( uri != null ) {
1215 final String uri_str = uri.getValue().toString().toLowerCase();
1216 if ( getImageMap().containsKey( uri_str ) ) {
1217 final BufferedImage bi = getImageMap().get( uri_str );
1218 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
1219 double scaling_factor = 1;
1220 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
1221 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
1222 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
1224 // y = y - ( 0.9 * getYdistance() );
1225 final double hs = bi.getHeight() * scaling_factor;
1226 double ws = ( bi.getWidth() * scaling_factor ) + offset;
1227 final double my_y = y - ( 0.5 * hs );
1228 final int x_w = ( int ) ( x + ws + 0.5 );
1229 final int y_h = ( int ) ( my_y + hs + 0.5 );
1230 if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) {
1232 ( int ) ( x + 0.5 + offset ),
1233 ( int ) ( my_y + 0.5 ),
1254 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
1255 JOptionPane.showMessageDialog( this,
1256 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
1257 "Attempt to cut/copy/paste/add/delete in unrooted display",
1258 JOptionPane.ERROR_MESSAGE );
1261 private final Color getColorForFoundNode( final PhylogenyNode n ) {
1262 if ( isInCurrentExternalNodes( n ) ) {
1263 return getTreeColorSet().getFoundColor0();
1265 else if ( isInFoundNodes0( n ) && !isInFoundNodes1( n ) ) {
1266 return getTreeColorSet().getFoundColor0();
1268 else if ( !isInFoundNodes0( n ) && isInFoundNodes1( n ) ) {
1269 return getTreeColorSet().getFoundColor1();
1272 return getTreeColorSet().getFoundColor0and1();
1276 final private Set<Long> getCopiedAndPastedNodes() {
1277 return getMainPanel().getCopiedAndPastedNodes();
1280 final private Set<Long> getCurrentExternalNodes() {
1281 return _current_external_nodes;
1284 final private Phylogeny getCutOrCopiedTree() {
1285 return getMainPanel().getCutOrCopiedTree();
1288 private FontMetrics getFontMetricsForLargeDefaultFont() {
1289 return getTreeFontSet().getFontMetricsLarge();
1292 final private float getLastDragPointX() {
1293 return _last_drag_point_x;
1296 final private float getLastDragPointY() {
1297 return _last_drag_point_y;
1301 final private double getMaxDistanceToRoot() {
1302 if ( _max_distance_to_root < 0 ) {
1303 recalculateMaxDistanceToRoot();
1305 return _max_distance_to_root;
1308 final private float getOvMaxHeight() {
1309 return _ov_max_height;
1312 final private float getOvMaxWidth() {
1313 return _ov_max_width;
1316 final private float getOvXcorrectionFactor() {
1317 return _ov_x_correction_factor;
1320 final private float getOvXDistance() {
1321 return _ov_x_distance;
1324 final private int getOvXPosition() {
1325 return _ov_x_position;
1328 final private float getOvYDistance() {
1329 return _ov_y_distance;
1332 final private int getOvYPosition() {
1333 return _ov_y_position;
1336 final private int getOvYStart() {
1340 final private List<Accession> getPdbAccs( final PhylogenyNode node ) {
1341 final List<Accession> pdb_ids = new ArrayList<Accession>();
1342 if ( node.getNodeData().isHasSequence() ) {
1343 final Sequence seq = node.getNodeData().getSequence();
1344 if ( !ForesterUtil.isEmpty( seq.getCrossReferences() ) ) {
1345 final SortedSet<Accession> cross_refs = seq.getCrossReferences();
1346 for( final Accession acc : cross_refs ) {
1347 if ( acc.getSource().equalsIgnoreCase( "pdb" ) ) {
1356 final private double getScaleDistance() {
1357 return _scale_distance;
1360 final private String getScaleLabel() {
1361 return _scale_label;
1364 final private TreeFontSet getTreeFontSet() {
1365 return getMainPanel().getTreeFontSet();
1368 final private float getUrtFactor() {
1372 final private float getUrtFactorOv() {
1373 return _urt_factor_ov;
1376 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
1379 showNodeFrame( node );
1394 colorSubtree( node );
1396 case COLOR_NODE_FONT:
1397 colorNodeFont( node );
1399 case CHANGE_NODE_FONT:
1400 changeNodeFont( node );
1418 copySubtree( node );
1421 pasteSubtree( node );
1423 case DELETE_NODE_OR_SUBTREE:
1424 deleteNodeOrSubtree( node );
1427 addEmptyNode( node );
1429 case EDIT_NODE_DATA:
1430 showNodeEditFrame( node );
1435 case SORT_DESCENDENTS:
1436 sortDescendants( node );
1438 case GET_EXT_DESC_DATA:
1439 showExtDescNodeData( node );
1441 case UNCOLLAPSE_ALL:
1442 uncollapseAll( node );
1445 orderSubtree( node );
1448 throw new IllegalArgumentException( "unknown action: " + action );
1452 final private void increaseCurrentExternalNodesDataBufferChangeCounter() {
1453 _current_external_nodes_data_buffer_change_counter++;
1456 final private void increaseOvSize() {
1457 if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth()
1459 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
1460 .getHeight() / 2 ) ) ) {
1461 setOvMaxWidth( getOvMaxWidth() + 5 );
1462 setOvMaxHeight( getOvMaxHeight() + 5 );
1464 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1468 final private void init() {
1469 _color_chooser = new JColorChooser();
1470 _rollover_popup = new JTextArea();
1471 _rollover_popup.setFont( POPUP_FONT );
1472 resetNodeIdToDistToLeafMap();
1474 setTreeFile( null );
1476 initializeOvSettings();
1477 resetDepthCollapseDepthValue();
1478 resetRankCollapseRankValue();
1479 setStartingAngle( ( TWO_PI * 3 ) / 4 );
1480 final ImageLoader il = new ImageLoader( this );
1481 new Thread( il ).start();
1484 final private void initializeOvSettings() {
1485 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
1486 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
1489 final private boolean inOvVirtualRectangle( final int x, final int y ) {
1490 return ( ( x >= ( getOvVirtualRectangle().x - 1 ) )
1491 && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) )
1492 && ( y >= ( getOvVirtualRectangle().y - 1 ) )
1493 && ( y <= ( getOvVirtualRectangle().y + getOvVirtualRectangle().height + 1 ) ) );
1496 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
1497 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
1500 final private boolean isCanBlast( final PhylogenyNode node ) {
1501 if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) {
1504 return Blast.isContainsQueryForBlast( node );
1507 final private String isCanOpenSeqWeb( final PhylogenyNode node ) {
1508 final Accession a = SequenceAccessionTools.obtainAccessorFromDataFields( node );
1510 return a.getValue();
1515 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
1516 if ( node.getNodeData().isHasTaxonomy() && ( ( !ForesterUtil
1517 .isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
1518 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
1519 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) )
1520 || ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
1521 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) ) ) ) {
1529 final private boolean isInCurrentExternalNodes( final PhylogenyNode node ) {
1530 return ( ( getCurrentExternalNodes() != null ) && getCurrentExternalNodes().contains( node.getId() ) );
1533 private boolean isInFoundNodes( final PhylogenyNode n ) {
1534 return isInFoundNodes0( n ) || isInFoundNodes1( n );
1537 final private boolean isInFoundNodes0( final PhylogenyNode node ) {
1538 return ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) );
1541 final private boolean isInFoundNodes1( final PhylogenyNode node ) {
1542 return ( ( getFoundNodes1() != null ) && getFoundNodes1().contains( node.getId() ) );
1545 final private boolean isInOv() {
1549 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
1551 if ( getControlPanel().isShowTaxonomyImages() ) {
1552 y_dist = 40 + ( int ) getYdistance();
1554 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) )
1555 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) )
1556 || ( ( node.getParent() != null ) && ( node.getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
1559 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
1560 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) )
1561 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) )
1562 || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) )
1563 || ( node.getXcoord() > ( getVisibleRect().getMaxX() + 20 ) ) );
1566 final private boolean isNonLinedUpCladogram() {
1567 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
1570 final private void keyPressedCalls( final KeyEvent e ) {
1571 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
1572 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
1573 if ( !isInOvRect() ) {
1574 setInOvRect( true );
1577 else if ( isInOvRect() ) {
1578 setInOvRect( false );
1581 if ( e.isAltDown() ) {
1582 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1583 || ( e.getKeyCode() == KeyEvent.VK_C ) || ( e.getKeyCode() == KeyEvent.VK_BACK_SPACE ) ) {
1584 getControlPanel().showWhole();
1586 else if ( e.isShiftDown()
1587 && ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) ) {
1588 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
1589 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1591 else if ( e.isShiftDown() && plusPressed( e.getKeyCode() ) ) {
1592 getMainPanel().getTreeFontSet().increaseFontSize();
1593 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1595 else if ( e.getKeyCode() == KeyEvent.VK_O ) {
1596 getControlPanel().orderPressed( this );
1598 else if ( e.getKeyCode() == KeyEvent.VK_R ) {
1599 getControlPanel().returnedToSuperTreePressed();
1601 else if ( e.getKeyCode() == KeyEvent.VK_U ) {
1602 getControlPanel().uncollapseAll( this );
1603 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1605 else if ( e.getKeyCode() == KeyEvent.VK_UP ) {
1606 getMainPanel().getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1607 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1609 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1610 getMainPanel().getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
1611 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1613 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1614 getMainPanel().getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
1615 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1616 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1618 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1619 getMainPanel().getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
1620 AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1621 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1623 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1624 getMainPanel().getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
1625 getMainPanel().getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
1626 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1627 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1629 else if ( plusPressed( e.getKeyCode() ) ) {
1630 getMainPanel().getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
1631 AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1632 getMainPanel().getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1633 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1637 if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
1638 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
1642 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1645 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1649 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1653 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1654 scroll_position.x = scroll_position.x + dx;
1655 scroll_position.y = scroll_position.y + dy;
1656 if ( scroll_position.x <= 0 ) {
1657 scroll_position.x = 0;
1660 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1661 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1662 if ( scroll_position.x >= max_x ) {
1663 scroll_position.x = max_x;
1666 if ( scroll_position.y <= 0 ) {
1667 scroll_position.y = 0;
1670 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1671 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1672 if ( scroll_position.y >= max_y ) {
1673 scroll_position.y = max_y;
1677 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1679 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
1680 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1681 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1682 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1683 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1686 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
1687 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1688 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1689 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1690 if ( getStartingAngle() < 0 ) {
1691 setStartingAngle( TWO_PI + getStartingAngle() );
1693 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1696 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
1697 boolean selected = false;
1698 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
1699 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1703 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1705 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
1708 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
1709 switchDisplaygetPhylogenyGraphicsType();
1712 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
1716 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
1717 MainFrame.cycleOverview( getOptions(), this );
1720 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
1723 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
1727 if ( e.getKeyCode() == KeyEvent.VK_HOME || e.getKeyCode() == KeyEvent.VK_ESCAPE ) {
1728 getControlPanel().showWhole();
1730 else if ( e.getKeyCode() == KeyEvent.VK_PAGE_UP ) {
1731 getMainPanel().getTreeFontSet().increaseFontSize();
1732 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1734 else if ( e.getKeyCode() == KeyEvent.VK_PAGE_DOWN ) {
1735 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
1736 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1741 final private void makePopupMenus( final PhylogenyNode node ) {
1742 _node_popup_menu = new JPopupMenu();
1743 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
1744 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
1745 for( int i = 0; i < clickto_names.size(); i++ ) {
1746 final String title = clickto_names.get( i );
1747 _node_popup_menu_items[ i ] = new JMenuItem( title );
1748 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
1749 final String id = isCanOpenSeqWeb( node );
1750 if ( !ForesterUtil.isEmpty( id ) ) {
1751 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + id + "]" );
1752 _node_popup_menu_items[ i ].setEnabled( true );
1755 _node_popup_menu_items[ i ].setEnabled( false );
1758 else if ( title.equals( Configuration.clickto_options[ Configuration.open_pdb_web ][ 0 ] ) ) {
1759 final List<Accession> accs = getPdbAccs( node );
1760 _node_popup_menu_items[ i ] = new JMenuItem( title );
1761 if ( !ForesterUtil.isEmpty( accs ) ) {
1762 if ( accs.size() == 1 ) {
1763 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1764 + TreePanelUtil.pdbAccToString( accs, 0 ) + "]" );
1765 _node_popup_menu_items[ i ].setEnabled( true );
1767 else if ( accs.size() == 2 ) {
1768 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1769 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1770 + TreePanelUtil.pdbAccToString( accs, 1 ) + "]" );
1771 _node_popup_menu_items[ i ].setEnabled( true );
1773 else if ( accs.size() == 3 ) {
1774 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1775 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1776 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
1777 + TreePanelUtil.pdbAccToString( accs, 2 ) + "]" );
1778 _node_popup_menu_items[ i ].setEnabled( true );
1781 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1782 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1783 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
1784 + TreePanelUtil.pdbAccToString( accs, 2 ) + ", + " + ( accs.size() - 3 ) + " more]" );
1785 _node_popup_menu_items[ i ].setEnabled( true );
1789 _node_popup_menu_items[ i ].setEnabled( false );
1792 else if ( title.startsWith( Configuration.clickto_options[ Configuration.get_ext_desc_data ][ 0 ] ) ) {
1793 _node_popup_menu_items[ i ]
1794 .setText( Configuration.clickto_options[ Configuration.get_ext_desc_data ][ 0 ] + ": "
1795 + getOptions().getExtDescNodeDataToReturn().toString() );
1797 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
1798 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
1800 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
1801 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
1803 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
1804 if ( !getOptions().isEditable() ) {
1807 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
1809 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
1810 if ( !getOptions().isEditable() ) {
1813 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
1815 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
1816 if ( !getOptions().isEditable() ) {
1819 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
1821 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
1822 if ( !getOptions().isEditable() ) {
1825 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
1827 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
1828 if ( !getOptions().isEditable() ) {
1832 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
1833 if ( !getOptions().isEditable() ) {
1837 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
1838 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
1840 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
1841 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
1843 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
1844 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
1846 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
1847 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
1849 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
1850 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
1852 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
1853 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
1855 else if ( title.equals( Configuration.clickto_options[ Configuration.uncollapse_all ][ 0 ] ) ) {
1856 _node_popup_menu_items[ i ].setEnabled( isCanUncollapseAll( node ) );
1858 _node_popup_menu_items[ i ].addActionListener( this );
1859 _node_popup_menu.add( _node_popup_menu_items[ i ] );
1863 private final void nodeDataAsSB( final PhylogenyNode node, final StringBuilder sb ) {
1864 if ( node != null ) {
1865 if ( getControlPanel().isShowNodeNames() && ( !ForesterUtil.isEmpty( node.getName() ) ) ) {
1866 if ( sb.length() > 0 ) {
1869 sb.append( node.getName() );
1871 if ( node.getNodeData().isHasSequence() ) {
1872 if ( getControlPanel().isShowSeqSymbols()
1873 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
1874 if ( sb.length() > 0 ) {
1877 sb.append( node.getNodeData().getSequence().getSymbol() );
1879 if ( getControlPanel().isShowGeneNames()
1880 && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) {
1881 if ( sb.length() > 0 ) {
1884 sb.append( node.getNodeData().getSequence().getGeneName() );
1886 if ( getControlPanel().isShowSeqNames()
1887 && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
1888 if ( sb.length() > 0 ) {
1891 sb.append( node.getNodeData().getSequence().getName() );
1893 if ( getControlPanel().isShowSequenceAcc()
1894 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
1895 if ( sb.length() > 0 ) {
1898 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
1899 sb.append( node.getNodeData().getSequence().getAccession().getSource() );
1902 sb.append( node.getNodeData().getSequence().getAccession().getValue() );
1905 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
1906 if ( sb.length() > 0 ) {
1909 sb.append( propertiesToString( node ) );
1914 private final void nodeTaxonomyDataAsSB( final Taxonomy taxonomy, final StringBuilder sb ) {
1915 if ( _control_panel.isShowTaxonomyRank() && !ForesterUtil.isEmpty( taxonomy.getRank() ) ) {
1917 sb.append( taxonomy.getRank() );
1920 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
1921 sb.append( taxonomy.getTaxonomyCode() );
1924 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
1925 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
1926 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1927 if ( getOptions().isAbbreviateScientificTaxonNames()
1928 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1929 abbreviateScientificName( taxonomy.getScientificName(), sb );
1932 sb.append( taxonomy.getScientificName() );
1935 sb.append( taxonomy.getCommonName() );
1938 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
1939 if ( getOptions().isAbbreviateScientificTaxonNames()
1940 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1941 abbreviateScientificName( taxonomy.getScientificName(), sb );
1944 sb.append( taxonomy.getScientificName() );
1948 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1949 sb.append( taxonomy.getCommonName() );
1953 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
1954 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
1955 if ( getOptions().isAbbreviateScientificTaxonNames()
1956 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1957 abbreviateScientificName( taxonomy.getScientificName(), sb );
1960 sb.append( taxonomy.getScientificName() );
1965 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
1966 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1967 sb.append( taxonomy.getCommonName() );
1973 private final String obtainTitleForExtDescNodeData() {
1974 return getOptions().getExtDescNodeDataToReturn().toString();
1977 final private void openPdbWeb( final PhylogenyNode node ) {
1978 final List<Accession> pdb_ids = getPdbAccs( node );
1979 if ( ForesterUtil.isEmpty( pdb_ids ) ) {
1980 cannotOpenBrowserWarningMessage( "PDB" );
1983 final List<String> uri_strs = TreePanelUtil.createUrisForPdbWeb( node, pdb_ids, getConfiguration(), this );
1984 if ( !ForesterUtil.isEmpty( uri_strs ) ) {
1985 for( final String uri_str : uri_strs ) {
1987 AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_seq" );
1989 catch ( final IOException e ) {
1990 AptxUtil.showErrorMessage( this, e.toString() );
1991 e.printStackTrace();
1993 catch ( final URISyntaxException e ) {
1994 AptxUtil.showErrorMessage( this, e.toString() );
1995 e.printStackTrace();
2000 cannotOpenBrowserWarningMessage( "PDB" );
2004 final private void openSeqWeb( final PhylogenyNode node ) {
2005 if ( ForesterUtil.isEmpty( isCanOpenSeqWeb( node ) ) ) {
2006 cannotOpenBrowserWarningMessage( "sequence" );
2009 final String uri_str = TreePanelUtil.createUriForSeqWeb( node, getConfiguration(), this );
2010 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2012 AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_seq" );
2014 catch ( final IOException e ) {
2015 AptxUtil.showErrorMessage( this, e.toString() );
2016 e.printStackTrace();
2018 catch ( final URISyntaxException e ) {
2019 AptxUtil.showErrorMessage( this, e.toString() );
2020 e.printStackTrace();
2024 cannotOpenBrowserWarningMessage( "sequence" );
2028 final private void openTaxWeb( final PhylogenyNode node ) {
2029 if ( !isCanOpenTaxWeb( node ) ) {
2030 cannotOpenBrowserWarningMessage( "taxonomic" );
2033 String uri_str = null;
2034 final Taxonomy tax = node.getNodeData().getTaxonomy();
2035 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2036 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
2038 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
2040 catch ( final URISyntaxException e ) {
2041 AptxUtil.showErrorMessage( this, e.toString() );
2043 e.printStackTrace();
2046 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2047 && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
2048 && ( tax.getIdentifier().getProvider().equalsIgnoreCase( "ncbi" )
2049 || tax.getIdentifier().getProvider().equalsIgnoreCase( "uniprot" ) ) ) {
2051 uri_str = "http://www.uniprot.org/taxonomy/"
2052 + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF_8 );
2054 catch ( final UnsupportedEncodingException e ) {
2055 AptxUtil.showErrorMessage( this, e.toString() );
2056 e.printStackTrace();
2059 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
2061 uri_str = "http://www.uniprot.org/taxonomy/?query="
2062 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF_8 );
2064 catch ( final UnsupportedEncodingException e ) {
2065 AptxUtil.showErrorMessage( this, e.toString() );
2066 e.printStackTrace();
2069 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
2071 uri_str = "http://www.uniprot.org/taxonomy/?query="
2072 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF_8 );
2074 catch ( final UnsupportedEncodingException e ) {
2075 AptxUtil.showErrorMessage( this, e.toString() );
2076 e.printStackTrace();
2079 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
2081 uri_str = "http://www.uniprot.org/taxonomy/?query="
2082 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF_8 );
2084 catch ( final UnsupportedEncodingException e ) {
2085 AptxUtil.showErrorMessage( this, e.toString() );
2086 e.printStackTrace();
2089 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2091 AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_tax" );
2093 catch ( final IOException e ) {
2094 AptxUtil.showErrorMessage( this, e.toString() );
2095 e.printStackTrace();
2097 catch ( final URISyntaxException e ) {
2098 AptxUtil.showErrorMessage( this, e.toString() );
2099 e.printStackTrace();
2103 cannotOpenBrowserWarningMessage( "taxonomic" );
2107 final private void paintBranchLength( final Graphics2D g,
2108 final PhylogenyNode node,
2109 final boolean to_pdf,
2110 final boolean to_graphics_file ) {
2111 g.setFont( getTreeFontSet().getSmallFont() );
2112 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2113 g.setColor( Color.BLACK );
2116 g.setColor( getTreeColorSet().getBranchLengthColor() );
2118 if ( !node.isRoot() ) {
2119 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2120 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2121 node.getParent().getXcoord() + EURO_D,
2122 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2125 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2126 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2127 node.getParent().getXcoord() + ROUNDED_D,
2128 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2132 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2133 node.getParent().getXcoord() + 3,
2134 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2139 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2141 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2146 final private void paintBranchLite( final Graphics2D g,
2151 final PhylogenyNode node ) {
2152 g.setColor( getTreeColorSet().getOvColor() );
2153 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2154 drawLine( x1, y1, x2, y2, g );
2156 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2157 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2158 ( g ).draw( _quad_curve );
2160 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2161 final float dx = x2 - x1;
2162 final float dy = y2 - y1;
2163 _cubic_curve.setCurve( x1,
2171 ( g ).draw( _cubic_curve );
2174 final float x2a = x2;
2175 final float x1a = x1;
2176 // draw the vertical line
2177 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
2178 drawLine( x1, y1, x1, y2, g );
2180 // draw the horizontal line
2181 drawLine( x1a, y2, x2a, y2, g );
2186 * Paint a branch which consists of a vertical and a horizontal bar
2187 * @param is_ind_found_nodes
2189 final private void paintBranchRectangular( final Graphics2D g,
2194 final PhylogenyNode node,
2195 final boolean to_pdf,
2196 final boolean to_graphics_file ) {
2197 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
2198 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2199 drawLine( x1, y1, x2, y2, g );
2201 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2202 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2203 g.draw( _quad_curve );
2205 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2206 final float dx = x2 - x1;
2207 final float dy = y2 - y1;
2208 _cubic_curve.setCurve( x1,
2216 g.draw( _cubic_curve );
2219 final float x2a = x2;
2220 final float x1a = x1;
2222 if ( node.isFirstChildNode() || node.isLastChildNode()
2223 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2224 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2225 if ( !to_graphics_file && !to_pdf
2226 && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) )
2227 && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) )
2228 || ( ( y2 > ( getVisibleRect().getMaxY() + 20 ) )
2229 && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) {
2233 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2234 float x2c = x1 + EURO_D;
2238 drawLine( x1, y1, x2c, y2, g );
2240 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2242 y2_r = y2 - ROUNDED_D;
2246 drawLine( x1, y1, x1, y2_r, g );
2249 y2_r = y2 + ROUNDED_D;
2253 drawLine( x1, y1, x1, y2_r, g );
2257 drawLine( x1, y1, x1, y2, g );
2261 // draw the horizontal line
2262 if ( !to_graphics_file && !to_pdf && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) )
2263 || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) {
2267 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
2268 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2269 x1_r = x1a + ROUNDED_D;
2271 drawLine( x1_r, y2, x2a, y2, g );
2274 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2275 final float x1c = x1a + EURO_D;
2277 drawLine( x1c, y2, x2a, y2, g );
2281 drawLine( x1a, y2, x2a, y2, g );
2285 final double w = PhylogenyMethods.getBranchWidthValue( node );
2286 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2287 x1_r = x1a + ROUNDED_D;
2289 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
2292 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2293 final float x1c = x1a + EURO_D;
2295 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
2299 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
2302 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2307 final double diff = y2 - y2_r;
2308 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
2311 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
2316 if ( node.isExternal() ) {
2317 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file );
2321 final private double paintCirculars( final PhylogenyNode n,
2322 final Phylogeny phy,
2323 final float center_x,
2324 final float center_y,
2325 final double radius,
2326 final boolean radial_labels,
2328 final boolean to_pdf,
2329 final boolean to_graphics_file ) {
2330 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
2331 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
2332 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
2334 return _urt_nodeid_angle_map.get( n.getId() );
2337 final List<PhylogenyNode> descs = n.getDescendants();
2339 for( final PhylogenyNode desc : descs ) {
2340 sum += paintCirculars( desc,
2351 if ( !n.isRoot() ) {
2352 r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
2354 final double theta = sum / descs.size();
2355 n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) );
2356 n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) );
2357 _urt_nodeid_angle_map.put( n.getId(), theta );
2358 for( final PhylogenyNode desc : descs ) {
2359 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
2365 final private void paintCircularsLite( final PhylogenyNode n,
2366 final Phylogeny phy,
2370 final Graphics2D g ) {
2371 if ( n.isExternal() ) {
2375 final List<PhylogenyNode> descs = n.getDescendants();
2376 for( final PhylogenyNode desc : descs ) {
2377 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
2380 if ( !n.isRoot() ) {
2381 r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
2383 final double theta = _urt_nodeid_angle_map.get( n.getId() );
2384 n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) );
2385 n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) );
2386 for( final PhylogenyNode desc : descs ) {
2387 paintBranchCircularLite( n, desc, g );
2392 final private void paintCollapsedNode( final Graphics2D g,
2393 final PhylogenyNode node,
2394 final boolean to_graphics_file,
2395 final boolean to_pdf,
2396 final boolean is_in_found_nodes ) {
2398 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2401 else if ( is_in_found_nodes ) {
2402 c = getColorForFoundNode( node );
2404 else if ( getControlPanel().isColorAccordingToSequence() ) {
2405 c = getSequenceBasedColor( node );
2407 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2408 c = getTaxonomyBasedColor( node );
2410 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
2411 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2412 c = PhylogenyMethods.getBranchColorValue( node );
2414 else if ( to_pdf ) {
2415 g.setColor( getTreeColorSet().getBranchColorForPdf() );
2418 c = getTreeColorSet().getCollapseFillColor();
2420 double d = node.getAllExternalDescendants().size();
2423 if ( getControlPanel().isDrawPhylogram() ) {
2425 d = 0.75 * _y_distance;
2428 d = 0.25 * Math.log10( d ) * _y_distance;
2430 final float half_box_size = 0.5f * getOptions().getDefaultNodeShapeSize();
2431 if ( d < half_box_size ) {
2435 final float xx = node.getXcoord() - ( getOptions().getDefaultNodeShapeSize() );
2436 xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1;
2437 _polygon.moveTo( xxx, node.getYcoord() + 0.5 );
2438 _polygon.lineTo( xxx, node.getYcoord() - 0.5 );
2439 s = _options.isCollapsedWithAverageHeigh()
2440 ? PhylogenyMethods.calculateAverageTreeHeight( node ) * _x_correction_factor : 1;
2441 _polygon.lineTo( node.getXcoord() + s, node.getYcoord() - d );
2442 _polygon.lineTo( node.getXcoord() + s, node.getYcoord() + d );
2443 _polygon.closePath();
2450 d = ( Math.log10( d ) * _y_distance ) / 2.5;
2452 final int box_size = getOptions().getDefaultNodeShapeSize() + 1;
2453 if ( d < box_size ) {
2456 final float xx = node.getXcoord() - ( 2 * box_size );
2457 xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1;
2459 _polygon.moveTo( xxx, node.getYcoord() );
2460 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d );
2461 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d );
2462 _polygon.closePath();
2464 if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) {
2468 else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.NONE ) {
2469 g.setColor( getBackground() );
2474 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2475 g.setPaint( new GradientPaint( xxx,
2479 ( float ) ( node.getYcoord() - d ),
2486 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes, s );
2489 final private void paintConfidenceValues( final Graphics2D g,
2490 final PhylogenyNode node,
2491 final boolean to_pdf,
2492 final boolean to_graphics_file ) {
2493 final List<Confidence> confidences = node.getBranchData().getConfidences();
2494 boolean not_first = false;
2495 Collections.sort( confidences );
2496 final StringBuilder sb = new StringBuilder();
2497 for( final Confidence confidence : confidences ) {
2498 if ( ForesterUtil.isEmpty( SHOW_ONLY_THIS_CONF_TYPE ) || ( !ForesterUtil.isEmpty( confidence.getType() )
2499 && confidence.getType().equalsIgnoreCase( SHOW_ONLY_THIS_CONF_TYPE ) ) ) {
2500 final double value = confidence.getValue();
2501 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2502 if ( value < getOptions().getMinConfidenceValue() ) {
2511 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil
2512 .round( value, getOptions().getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2513 if ( getOptions().isShowConfidenceStddev() ) {
2514 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2516 sb.append( FORMATTER_CONFIDENCE
2517 .format( ForesterUtil.round( confidence.getStandardDeviation(),
2519 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2526 if ( sb.length() > 0 ) {
2527 final float parent_x = node.getParent().getXcoord();
2528 float x = node.getXcoord();
2529 g.setFont( getTreeFontSet().getSmallFont() );
2530 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2533 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2536 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2537 g.setColor( Color.BLACK );
2540 g.setColor( getTreeColorSet().getConfidenceColor() );
2542 final String conf_str = sb.toString();
2543 TreePanel.drawString( conf_str,
2544 parent_x + ( ( x - parent_x
2545 - getTreeFontSet().getFontMetricsSmall().stringWidth( conf_str ) ) / 2 ),
2546 ( node.getYcoord() + getTreeFontSet().getSmallMaxAscent() ) - 1,
2551 final private void paintGainedAndLostCharacters( final Graphics2D g,
2552 final PhylogenyNode node,
2553 final String gained,
2554 final String lost ) {
2555 if ( node.getParent() != null ) {
2556 final float parent_x = node.getParent().getXcoord();
2557 final float x = node.getXcoord();
2558 g.setFont( getTreeFontSet().getLargeFont() );
2559 g.setColor( getTreeColorSet().getGainedCharactersColor() );
2560 if ( AptxConstants.SPECIAL_CUSTOM ) {
2561 g.setColor( Color.BLUE );
2563 TreePanel.drawString( gained,
2564 parent_x + ( ( x - parent_x
2565 - getFontMetricsForLargeDefaultFont().stringWidth( gained ) ) / 2 ),
2566 ( node.getYcoord() - getFontMetricsForLargeDefaultFont().getMaxDescent() ),
2568 g.setColor( getTreeColorSet().getLostCharactersColor() );
2571 parent_x + ( ( x - parent_x - getFontMetricsForLargeDefaultFont().stringWidth( lost ) )
2573 ( node.getYcoord() + getFontMetricsForLargeDefaultFont().getMaxAscent() ),
2578 private void paintMolecularSequences( final Graphics2D g, final PhylogenyNode node, final boolean to_pdf ) {
2579 final RenderableMsaSequence rs = RenderableMsaSequence
2580 .createInstance( node.getNodeData().getSequence().getMolecularSequence(),
2581 node.getNodeData().getSequence().getType(),
2582 getConfiguration() );
2584 final int default_height = 8;
2585 final float y = getYdistance();
2586 final int h = ( y / 2 ) < default_height ? ForesterUtil.roundToInt( y * 2 ) : default_height;
2587 rs.setRenderingHeight( h > 1 ? h : 1 );
2588 if ( getControlPanel().isDrawPhylogram() ) {
2589 rs.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() ) + _length_of_longest_text ),
2590 node.getYcoord() - ( h / 2.0f ),
2596 rs.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text,
2597 node.getYcoord() - ( h / 2.0f ),
2606 * Draw a box at the indicated node.
2613 final private void paintNodeBox( final float x,
2615 final PhylogenyNode node,
2617 final boolean to_pdf,
2618 final boolean to_graphics_file ) {
2619 if ( node.isCollapse() ) {
2622 // if this node should be highlighted, do so
2623 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
2624 g.setColor( getTreeColorSet().getFoundColor0() );
2625 drawOval( x - 8, y - 8, 16, 16, g );
2626 drawOval( x - 9, y - 8, 17, 17, g );
2627 drawOval( x - 9, y - 9, 18, 18, g );
2629 if ( ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) )
2630 || ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() )
2631 || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() )
2632 || ( getOptions().isShowDefaultNodeShapesForMarkedNodes()
2633 && ( node.getNodeData().getNodeVisualData() != null )
2634 && ( !node.getNodeData().getNodeVisualData().isEmpty() ) )
2635 || ( getControlPanel().isUseVisualStyles() && ( ( node.getNodeData().getNodeVisualData() != null )
2636 && ( ( node.getNodeData().getNodeVisualData().getNodeColor() != null )
2637 || ( node.getNodeData().getNodeVisualData().getSize() != NodeVisualData.DEFAULT_SIZE )
2638 || ( node.getNodeData().getNodeVisualData().getFillType() != NodeFill.DEFAULT )
2639 || ( node.getNodeData().getNodeVisualData().getShape() != NodeShape.DEFAULT ) ) ) )
2640 || ( getControlPanel().isEvents() && node.isHasAssignedEvent()
2641 && ( node.getNodeData().getEvent().isDuplication()
2642 || node.getNodeData().getEvent().isSpeciation()
2643 || node.getNodeData().getEvent().isSpeciationOrDuplication() ) ) ) {
2644 NodeVisualData vis = null;
2645 if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
2646 && ( !node.getNodeData().getNodeVisualData().isEmpty() ) ) {
2647 vis = node.getNodeData().getNodeVisualData();
2649 float box_size = getOptions().getDefaultNodeShapeSize();
2650 if ( ( vis != null ) && ( vis.getSize() != NodeVisualData.DEFAULT_SIZE ) ) {
2651 box_size = vis.getSize();
2653 final float half_box_size = box_size / 2.0f;
2654 Color outline_color = null;
2655 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2656 outline_color = Color.BLACK;
2658 else if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
2659 outline_color = getColorForFoundNode( node );
2661 else if ( vis != null ) {
2662 if ( vis.getNodeColor() != null ) {
2663 outline_color = vis.getNodeColor();
2665 else if ( vis.getFontColor() != null ) {
2666 outline_color = vis.getFontColor();
2669 else if ( getControlPanel().isEvents() && TreePanelUtil.isHasAssignedEvent( node ) ) {
2670 final Event event = node.getNodeData().getEvent();
2671 if ( event.isDuplication() ) {
2672 outline_color = getTreeColorSet().getDuplicationBoxColor();
2674 else if ( event.isSpeciation() ) {
2675 outline_color = getTreeColorSet().getSpecBoxColor();
2677 else if ( event.isSpeciationOrDuplication() ) {
2678 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
2681 if ( outline_color == null ) {
2682 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
2683 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
2684 outline_color = getTreeColorSet().getBranchColorForPdf();
2687 NodeShape shape = null;
2688 if ( vis != null ) {
2689 if ( vis.getShape() == NodeShape.CIRCLE ) {
2690 shape = NodeShape.CIRCLE;
2692 else if ( vis.getShape() == NodeShape.RECTANGLE ) {
2693 shape = NodeShape.RECTANGLE;
2696 if ( shape == null ) {
2697 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
2698 shape = NodeShape.CIRCLE;
2700 else if ( getOptions().getDefaultNodeShape() == NodeShape.RECTANGLE ) {
2701 shape = NodeShape.RECTANGLE;
2704 NodeFill fill = null;
2705 if ( vis != null ) {
2706 if ( vis.getFillType() == NodeFill.SOLID ) {
2707 fill = NodeFill.SOLID;
2709 else if ( vis.getFillType() == NodeFill.NONE ) {
2710 fill = NodeFill.NONE;
2712 else if ( vis.getFillType() == NodeFill.GRADIENT ) {
2713 fill = NodeFill.GRADIENT;
2716 if ( fill == null ) {
2717 if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) {
2718 fill = NodeFill.SOLID;
2720 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
2721 fill = NodeFill.NONE;
2723 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2724 fill = NodeFill.GRADIENT;
2727 Color vis_fill_color = null;
2728 if ( ( vis != null ) && ( vis.getNodeColor() != null ) ) {
2729 vis_fill_color = vis.getNodeColor();
2731 if ( shape == NodeShape.CIRCLE ) {
2732 if ( fill == NodeFill.GRADIENT ) {
2733 drawOvalGradient( x - half_box_size,
2738 to_pdf ? Color.WHITE : outline_color,
2739 to_pdf ? outline_color : getBackground(),
2742 else if ( fill == NodeFill.NONE ) {
2743 Color background = getBackground();
2745 background = Color.WHITE;
2747 drawOvalGradient( x - half_box_size,
2756 else if ( fill == NodeVisualData.NodeFill.SOLID ) {
2757 if ( vis_fill_color != null ) {
2758 g.setColor( vis_fill_color );
2761 g.setColor( outline_color );
2763 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2766 else if ( shape == NodeVisualData.NodeShape.RECTANGLE ) {
2767 if ( fill == NodeVisualData.NodeFill.GRADIENT ) {
2768 drawRectGradient( x - half_box_size,
2773 to_pdf ? Color.WHITE : outline_color,
2774 to_pdf ? outline_color : getBackground(),
2777 else if ( fill == NodeVisualData.NodeFill.NONE ) {
2778 Color background = getBackground();
2780 background = Color.WHITE;
2782 drawRectGradient( x - half_box_size,
2791 else if ( fill == NodeVisualData.NodeFill.SOLID ) {
2792 if ( vis_fill_color != null ) {
2793 g.setColor( vis_fill_color );
2796 g.setColor( outline_color );
2798 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2804 final private int paintNodeData( final Graphics2D g,
2805 final PhylogenyNode node,
2806 final boolean to_graphics_file,
2807 final boolean to_pdf,
2808 final boolean is_in_found_nodes,
2809 final double add ) {
2810 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
2813 if ( getControlPanel().isWriteBranchLengthValues()
2814 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2815 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
2816 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
2817 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
2818 paintBranchLength( g, node, to_pdf, to_graphics_file );
2820 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
2823 if ( !getControlPanel().isShowExternalData() && ( node.isExternal() || node.isCollapse() ) ) {
2831 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
2832 if ( getControlPanel().isShowTaxonomyImages() && ( getImageMap() != null ) && !getImageMap().isEmpty()
2833 && node.getNodeData().isHasTaxonomy() && ( ( node.getNodeData().getTaxonomy().getUris() != null )
2834 && !node.getNodeData().getTaxonomy().getUris().isEmpty() ) ) {
2835 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
2837 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
2838 || getControlPanel().isShowTaxonomyCommonNames() || getControlPanel().isShowTaxonomyRank() )
2839 && node.getNodeData().isHasTaxonomy() ) {
2840 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
2842 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
2843 final boolean saw_species = _sb.length() > 0;
2845 nodeDataAsSB( node, _sb );
2846 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
2847 if ( ( _sb.length() == 0 ) && !saw_species ) {
2848 if ( getOptions().isShowAbbreviatedLabelsForCollapsedNodes()
2849 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
2850 || getControlPanel().isShowSeqNames() || getControlPanel().isShowNodeNames() ) ) {
2851 final PhylogenyNode first = PhylogenyMethods.getFirstExternalNode( node );
2852 final PhylogenyNode last = PhylogenyMethods.getLastExternalNode( node );
2853 if ( getControlPanel().isShowTaxonomyCode() && first.getNodeData().isHasTaxonomy()
2854 && last.getNodeData().isHasTaxonomy()
2855 && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getTaxonomyCode() )
2856 && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
2857 addLabelForCollapsed( first.getNodeData().getTaxonomy().getTaxonomyCode(),
2858 last.getNodeData().getTaxonomy().getTaxonomyCode(),
2859 node.getAllExternalDescendants().size() );
2861 else if ( getControlPanel().isShowTaxonomyScientificNames() && first.getNodeData().isHasTaxonomy()
2862 && last.getNodeData().isHasTaxonomy()
2863 && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getScientificName() )
2864 && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getScientificName() ) ) {
2865 addLabelForCollapsed( first.getNodeData().getTaxonomy().getScientificName(),
2866 last.getNodeData().getTaxonomy().getScientificName(),
2867 node.getAllExternalDescendants().size() );
2869 else if ( getControlPanel().isShowSeqNames() && first.getNodeData().isHasSequence()
2870 && last.getNodeData().isHasSequence()
2871 && !ForesterUtil.isEmpty( first.getNodeData().getSequence().getName() )
2872 && !ForesterUtil.isEmpty( last.getNodeData().getSequence().getName() ) ) {
2873 addLabelForCollapsed( first.getNodeData().getSequence().getName(),
2874 last.getNodeData().getSequence().getName(),
2875 node.getAllExternalDescendants().size() );
2877 else if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( first.getName() )
2878 && !ForesterUtil.isEmpty( last.getName() ) ) {
2879 addLabelForCollapsed( first.getName(),
2881 node.getAllExternalDescendants().size() );
2885 else if ( ( _sb.length() > 0 ) || saw_species ) {
2886 // _sb.setLength( 0 );
2888 _sb.append( node.getAllExternalDescendants().size() );
2893 // _sb.setLength( 0 );
2895 // nodeDataAsSB( node, _sb );
2896 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
2897 float down_shift_factor = 3.0f;
2898 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
2899 down_shift_factor = 1;
2902 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
2903 && ( node.isExternal() || node.isCollapse() ) ) {
2904 pos_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
2905 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x + ( 2 * TreePanel.MOVE ) + getXdistance()
2909 pos_x = node.getXcoord() + x + 2 + half_box_size;
2912 if ( !using_visual_font ) {
2913 pos_y = ( node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ) );
2916 pos_y = ( node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / down_shift_factor ) );
2918 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
2919 && ( node.isExternal() || node.isCollapse() ) ) {
2920 drawConnection( node.getXcoord(), pos_x - x, node.getYcoord(), 5, 20, g, to_pdf );
2921 if ( node.isCollapse() ) {
2925 final String sb_str = _sb.toString();
2926 // GUILHEM_BEG ______________
2927 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
2928 && ( _query_sequence != null ) ) {
2929 x = paintSequenceRelation( g, node, x, half_box_size, pos_x, pos_y, sb_str );
2931 // GUILHEM_END _____________
2932 if ( sb_str.length() > 0 ) {
2933 if ( !isAllowAttributedStrings() ) {
2934 TreePanel.drawString( sb_str, pos_x, pos_y, g );
2937 drawStringX( sb_str, pos_x, pos_y, g );
2940 if ( _sb.length() > 0 ) {
2941 if ( !using_visual_font && !is_in_found_nodes ) {
2942 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
2945 x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
2948 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
2949 && ( node.getNodeData().getSequence().getAnnotations() != null )
2950 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
2951 final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
2952 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2953 g.setColor( Color.BLACK );
2955 else if ( getControlPanel().isColorAccordingToAnnotation() ) {
2956 g.setColor( calculateColorForAnnotation( ann ) );
2958 final String ann_str = TreePanelUtil.createAnnotationString( ann,
2959 getOptions().isShowAnnotationRefSource() );
2960 TreePanel.drawString( ann_str,
2961 node.getXcoord() + x + 3 + half_box_size,
2963 + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ),
2966 _sb.append( ann_str );
2967 if ( _sb.length() > 0 ) {
2968 if ( !using_visual_font && !is_in_found_nodes ) {
2969 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
2972 x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
2976 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2977 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2978 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2979 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
2980 && node.getNodeData().isHasBinaryCharacters() ) {
2981 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2982 g.setColor( Color.BLACK );
2985 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
2987 if ( getControlPanel().isShowBinaryCharacters() ) {
2988 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
2990 node.getXcoord() + x + 1 + half_box_size,
2991 node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
2992 / down_shift_factor ),
2994 paintGainedAndLostCharacters( g,
2996 node.getNodeData().getBinaryCharacters()
2997 .getGainedCharactersAsStringBuffer().toString(),
2998 node.getNodeData().getBinaryCharacters()
2999 .getLostCharactersAsStringBuffer().toString() );
3002 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
3003 node.getXcoord() + x + 4 + half_box_size,
3004 node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
3005 / down_shift_factor ),
3007 paintGainedAndLostCharacters( g,
3009 "+" + node.getNodeData().getBinaryCharacters().getGainedCount(),
3010 "-" + node.getNodeData().getBinaryCharacters().getLostCount() );
3017 private final int paintSequenceRelation( final Graphics2D g,
3018 final PhylogenyNode node,
3020 final int half_box_size,
3023 final String sb_str ) {
3024 int nodeTextBoundsWidth = 0;
3025 if ( sb_str.length() > 0 ) {
3026 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
3027 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
3029 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
3030 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
3031 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
3032 g.setColor( getTreeColorSet().getBackgroundColor() );
3036 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
3037 for( final SequenceRelation seqRelation : seqRelations ) {
3038 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence )
3039 || seqRelation.getRef1().isEqual( _query_sequence ) )
3040 && seqRelation.getType()
3041 .equals( getControlPanel().getSequenceRelationTypeBox().getSelectedItem() );
3042 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
3043 final double linePosX = node.getXcoord() + 2 + half_box_size;
3044 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence()
3045 || ( seqRelation.getConfidence() == null ) ) ? null
3046 : " (" + seqRelation.getConfidence().getValue() + ")";
3047 if ( sConfidence != null ) {
3048 float confidenceX = pos_x;
3049 if ( sb_str.length() > 0 ) {
3050 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
3051 + CONFIDENCE_LEFT_MARGIN;
3053 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
3054 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
3055 .getBounds().getWidth();
3056 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
3057 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
3060 if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
3062 if ( nodeTextBoundsWidth == 0 ) {
3063 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
3066 nodeTextBoundsWidth += 2;
3068 g.drawLine( ( int ) linePosX + 1,
3070 ( int ) linePosX + x + nodeTextBoundsWidth,
3071 3 + ( int ) pos_y );
3080 private final void drawConnection( final float x1,
3083 final int dist_left,
3084 final int dist_right,
3086 final boolean pdf ) {
3087 if ( ( ( x1 + dist_left ) < ( x2 - dist_right ) ) ) {
3088 final Stroke strok = g.getStroke();
3090 if ( strok == STROKE_005 ) {
3091 g.setStroke( STROKE_001_DASHED );
3093 else if ( strok == STROKE_01 ) {
3094 g.setStroke( STROKE_005_DASHED );
3097 g.setStroke( STROKE_01_DASHED );
3101 g.setColor( lighter( col ) );
3103 drawLine( x1 + dist_left, y, x2 - dist_right, y, g );
3104 g.setStroke( strok );
3111 public static Color lighter( final Color color ) {
3112 if ( ( color.getRed() == 0 ) && ( color.getGreen() == 0 ) && ( color.getBlue() == 0 ) ) {
3113 return new Color( 200, 200, 200 );
3120 private final void addLabelForCollapsed( final String first, final String last, final int size ) {
3121 _sb.append( first.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? first
3122 : first.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
3123 _sb.append( " ... " );
3124 _sb.append( last.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? last
3125 : last.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
3126 _sb.append( " (" + size + ")" );
3129 private final boolean isAllowAttributedStrings() {
3133 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
3134 final PhylogenyNode node,
3135 final boolean to_pdf,
3136 final boolean to_graphics_file,
3137 final boolean radial_labels,
3138 final double ur_angle,
3139 final boolean is_in_found_nodes ) {
3140 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
3145 if ( node.getNodeData().isHasTaxonomy()
3146 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
3147 || getControlPanel().isShowTaxonomyCommonNames() ) ) {
3148 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3149 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3150 _sb.append( taxonomy.getTaxonomyCode() );
3153 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3154 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3155 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3156 _sb.append( taxonomy.getScientificName() );
3158 _sb.append( taxonomy.getCommonName() );
3161 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3162 _sb.append( taxonomy.getScientificName() );
3165 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3166 _sb.append( taxonomy.getCommonName() );
3170 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3171 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3172 _sb.append( taxonomy.getScientificName() );
3176 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3177 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3178 _sb.append( taxonomy.getCommonName() );
3183 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3185 _sb.append( node.getAllExternalDescendants().size() );
3188 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3189 if ( _sb.length() > 0 ) {
3192 _sb.append( node.getName() );
3194 if ( node.getNodeData().isHasSequence() ) {
3195 if ( getControlPanel().isShowSequenceAcc()
3196 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3197 if ( _sb.length() > 0 ) {
3200 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3201 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3204 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3206 if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3207 if ( _sb.length() > 0 ) {
3210 _sb.append( node.getNodeData().getSequence().getName() );
3213 //g.setFont( getTreeFontSet().getLargeFont() );
3214 //if ( is_in_found_nodes ) {
3215 // g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3217 if ( _sb.length() > 1 ) {
3218 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
3219 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
3220 final String sb_str = _sb.toString();
3222 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3223 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
3226 m = ( float ) ( ur_angle % TWO_PI );
3228 _at = g.getTransform();
3229 boolean need_to_reset = false;
3230 final float x_coord = node.getXcoord();
3232 if ( !using_visual_font ) {
3233 y_coord = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / 3.0f );
3236 y_coord = node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / 3.0f );
3238 if ( radial_labels ) {
3239 need_to_reset = true;
3240 boolean left = false;
3241 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3245 g.rotate( m, x_coord, node.getYcoord() );
3247 if ( !using_visual_font ) {
3248 g.translate( -( getFontMetricsForLargeDefaultFont().getStringBounds( sb_str, g ).getWidth() ),
3252 g.translate( -( getFontMetrics( g.getFont() ).getStringBounds( sb_str, g ).getWidth() ), 0 );
3257 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3258 need_to_reset = true;
3259 if ( !using_visual_font ) {
3260 g.translate( -getFontMetricsForLargeDefaultFont().getStringBounds( sb_str, g ).getWidth(), 0 );
3263 g.translate( -getFontMetrics( g.getFont() ).getStringBounds( sb_str, g ).getWidth(), 0 );
3267 TreePanel.drawString( sb_str, x_coord, y_coord, g );
3268 if ( need_to_reset ) {
3269 g.setTransform( _at );
3274 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
3275 if ( node.isCollapse() ) {
3278 if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
3279 g.setColor( getColorForFoundNode( node ) );
3280 drawRectFilled( node.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3281 node.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3282 OVERVIEW_FOUND_NODE_BOX_SIZE,
3283 OVERVIEW_FOUND_NODE_BOX_SIZE,
3287 if ( !node.isExternal() && !node.isCollapse() ) {
3288 boolean first_child = true;
3290 //final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3291 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3292 final PhylogenyNode child_node = node.getChildNode( i );
3293 final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3294 if ( first_child ) {
3295 first_child = false;
3296 y2 = node.getYSecondary() - ( getOvYDistance()
3297 * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3300 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3302 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
3303 new_x = x2 + node.getXSecondary();
3304 final float diff_y = node.getYSecondary() - y2;
3305 final float diff_x = node.getXSecondary() - new_x;
3306 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
3307 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
3309 child_node.setXSecondary( new_x );
3310 child_node.setYSecondary( y2 );
3311 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3316 final private void paintNodeRectangular( final Graphics2D g,
3317 final PhylogenyNode node,
3318 final boolean to_pdf,
3319 final boolean dynamically_hide,
3320 final int dynamic_hiding_factor,
3321 final boolean to_graphics_file,
3322 final boolean disallow_shortcutting ) {
3323 final boolean is_in_found_nodes = isInFoundNodes( node ) || isInCurrentExternalNodes( node );
3324 if ( node.isCollapse() ) {
3325 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) ) {
3326 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3330 if ( node.isExternal() ) {
3331 ++_external_node_index;
3333 // Confidence values
3334 if ( getControlPanel().isShowConfidenceValues() && !node.isExternal() && !node.isRoot()
3335 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
3336 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3337 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3338 && node.getBranchData().isHasConfidences() ) {
3339 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
3341 // Draw a line to root:
3342 if ( node.isRoot() && _phylogeny.isRooted() ) {
3343 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
3346 float new_x_min = Float.MAX_VALUE;
3347 float min_dist = 1.5f;
3348 if ( !disallow_shortcutting ) {
3349 if ( dynamic_hiding_factor > 4000 ) {
3352 else if ( dynamic_hiding_factor > 1000 ) {
3355 else if ( dynamic_hiding_factor > 100 ) {
3359 if ( !node.isExternal() && !node.isCollapse() ) {
3360 boolean first_child = true;
3362 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3363 final PhylogenyNode child_node = node.getChildNode( i );
3364 final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3365 if ( first_child ) {
3366 first_child = false;
3367 y2 = node.getYcoord() - ( _y_distance
3368 * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3371 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3373 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
3374 new_x = x2 + node.getXcoord();
3375 if ( dynamically_hide && ( x2 < new_x_min ) ) {
3378 final float diff_y = node.getYcoord() - y2;
3379 final float diff_x = node.getXcoord() - new_x;
3380 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
3381 || ( diff_x < -min_dist ) ) {
3382 paintBranchRectangular( g,
3391 child_node.setXcoord( new_x );
3392 child_node.setYcoord( y2 );
3393 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3395 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file );
3397 if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
3398 && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
3399 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
3400 paintMolecularSequences( g, node, to_pdf );
3402 if ( dynamically_hide && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) )
3403 || ( !node.isExternal() && ( ( new_x_min < 20 )
3404 || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getFontMetricsForLargeDefaultFont()
3405 .getHeight() ) ) ) ) ) {
3408 final int x = paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes, 0 );
3409 paintNodeWithRenderableData( x, g, node, to_graphics_file, to_pdf );
3412 final private void paintNodeWithRenderableData( final int x,
3414 final PhylogenyNode node,
3415 final boolean to_graphics_file,
3416 final boolean to_pdf ) {
3417 if ( isNodeDataInvisible( node ) && !( to_graphics_file || to_pdf ) ) {
3420 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
3423 if ( ( !getControlPanel().isShowExternalData() && node.isExternal() ) ) {
3426 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3427 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) && ( node.getNodeData()
3428 .getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
3429 RenderableDomainArchitecture rds = null;
3431 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
3433 catch ( final ClassCastException cce ) {
3434 cce.printStackTrace();
3436 if ( rds != null ) {
3437 final int default_height = 7;
3438 float y = getYdistance();
3439 if ( getControlPanel().isDynamicallyHideData() ) {
3440 y = getTreeFontSet().getFontMetricsLarge().getHeight();
3442 final int h = y < default_height ? ForesterUtil.roundToInt( y ) : default_height;
3443 rds.setRenderingHeight( h > 1 ? h : 2 );
3444 if ( getControlPanel().isDrawPhylogram() ) {
3445 if ( getOptions().isLineUpRendarableNodeData() ) {
3446 if ( getOptions().isRightLineUpDomains() ) {
3447 rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3448 + _length_of_longest_text
3449 + ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ) ),
3450 node.getYcoord() - ( h / 2.0f ),
3456 rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3457 + _length_of_longest_text ), node.getYcoord() - ( h / 2.0f ), g, this, to_pdf );
3461 rds.render( node.getXcoord() + x, node.getYcoord() - ( h / 2.0f ), g, this, to_pdf );
3465 if ( getOptions().isRightLineUpDomains() ) {
3466 rds.render( ( ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text )
3467 - 20 ) + ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ),
3468 node.getYcoord() - ( h / 2.0f ),
3474 rds.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text,
3475 node.getYcoord() - ( h / 2.0f ),
3483 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
3484 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
3485 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
3486 getStatisticsForExpressionValues(),
3487 getConfiguration() );
3489 double domain_add = 0;
3490 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3491 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
3492 domain_add = _domain_structure_width + 10;
3494 if ( getControlPanel().isDrawPhylogram() ) {
3495 rv.render( ( float ) ( node.getXcoord() + x + domain_add ), node.getYcoord() - 3, g, this, to_pdf );
3498 rv.render( ( float ) ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text
3499 + domain_add ), node.getYcoord() - 3, g, this, to_pdf );
3503 //if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
3504 // && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
3505 // && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
3506 // paintMolecularSequences( g, node, to_pdf );
3510 final private void paintOvRectangle( final Graphics2D g ) {
3511 final float w_ratio = ( ( float ) getWidth() ) / getVisibleRect().width;
3512 final float h_ratio = ( ( float ) getHeight() ) / getVisibleRect().height;
3513 final float x_ratio = ( ( float ) getWidth() ) / getVisibleRect().x;
3514 final float y_ratio = ( ( float ) getHeight() ) / getVisibleRect().y;
3515 final float width = getOvMaxWidth() / w_ratio;
3516 final float height = getOvMaxHeight() / h_ratio;
3517 final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio );
3518 final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio );
3519 g.setColor( getTreeColorSet().getFoundColor0() );
3520 getOvRectangle().setRect( x, y, width, height );
3521 final Stroke s = g.getStroke();
3522 g.setStroke( STROKE_1 );
3523 if ( ( width < 6 ) && ( height < 6 ) ) {
3524 drawRectFilled( x, y, 6, 6, g );
3525 getOvVirtualRectangle().setRect( x, y, 6, 6 );
3527 else if ( width < 6 ) {
3528 drawRectFilled( x, y, 6, height, g );
3529 getOvVirtualRectangle().setRect( x, y, 6, height );
3531 else if ( height < 6 ) {
3532 drawRectFilled( x, y, width, 6, g );
3533 getOvVirtualRectangle().setRect( x, y, width, 6 );
3536 drawRect( x, y, width, height, g );
3537 if ( isInOvRect() ) {
3538 drawRect( x + 1, y + 1, width - 2, height - 2, g );
3540 getOvVirtualRectangle().setRect( x, y, width, height );
3545 final private void paintPhylogenyLite( final Graphics2D g ) {
3546 _phylogeny.getRoot().setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition()
3547 + ( MOVE / ( getVisibleRect().width / getOvRectangle().getWidth() ) ) ) );
3548 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
3549 final Stroke s = g.getStroke();
3550 g.setStroke( STROKE_05 );
3551 for( final PhylogenyNode element : _nodes_in_preorder ) {
3552 paintNodeLite( g, element );
3555 paintOvRectangle( g );
3559 * Paint the root branch. (Differs from others because it will always be a
3560 * single horizontal line).
3561 * @param to_graphics_file
3563 * @return new x1 value
3565 final private void paintRootBranch( final Graphics2D g,
3568 final PhylogenyNode root,
3569 final boolean to_pdf,
3570 final boolean to_graphics_file ) {
3571 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
3572 float d = getXdistance();
3573 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
3574 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
3576 if ( d < MIN_ROOT_LENGTH ) {
3577 d = MIN_ROOT_LENGTH;
3579 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
3580 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
3583 final double w = PhylogenyMethods.getBranchWidthValue( root );
3584 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
3586 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file );
3589 final private void paintScale( final Graphics2D g,
3592 final boolean to_pdf,
3593 final boolean to_graphics_file ) {
3595 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
3597 final int y2 = y1 - 8;
3598 final int y3 = y1 - 4;
3599 g.setFont( getTreeFontSet().getSmallFont() );
3600 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3601 g.setColor( Color.BLACK );
3604 g.setColor( getTreeColorSet().getBranchLengthColor() );
3606 final Stroke s = g.getStroke();
3607 g.setStroke( STROKE_1 );
3608 drawLine( x1, y1, x1, y2, g );
3609 drawLine( x2, y1, x2, y2, g );
3610 drawLine( x1, y3, x2, y3, g );
3611 if ( getScaleLabel() != null ) {
3612 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
3617 final private int paintTaxonomy( final Graphics2D g,
3618 final PhylogenyNode node,
3619 final boolean is_in_found_nodes,
3620 final boolean to_pdf,
3621 final boolean to_graphics_file,
3622 final float x_shift ) {
3623 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3624 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
3625 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getTaxonomyColor() );
3626 float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
3627 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
3628 && node.isExternal() ) {
3629 start_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3630 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift + ( 2 * TreePanel.MOVE ) + getXdistance()
3634 if ( !using_visual_font ) {
3635 start_y = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
3636 / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) );
3639 start_y = node.getYcoord()
3640 + ( getFontMetrics( g.getFont() ).getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) );
3643 nodeTaxonomyDataAsSB( taxonomy, _sb );
3644 final String label = _sb.toString();
3646 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
3647 && ( node.getNodeData().isHasSequence() )
3648 && node.getNodeData().getSequence().equals( _query_sequence ) ) {
3649 // invert font color and background color to show that this is the query sequence
3650 final Rectangle2D nodeTextBounds = new TextLayout( label,
3652 new FontRenderContext( null, false, false ) )
3654 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
3655 g.setColor( getTreeColorSet().getBackgroundColor() );
3658 TreePanel.drawString( label, start_x, start_y, g );
3659 if ( !using_visual_font && !is_in_found_nodes ) {
3660 return getFontMetricsForLargeDefaultFont().stringWidth( label );
3662 return getFontMetrics( g.getFont() ).stringWidth( label );
3665 final private void paintUnrooted( final PhylogenyNode n,
3666 final double low_angle,
3667 final double high_angle,
3668 final boolean radial_labels,
3670 final boolean to_pdf,
3671 final boolean to_graphics_file ) {
3673 n.setXcoord( getWidth() / 2 );
3674 n.setYcoord( getHeight() / 2 );
3676 if ( n.isExternal() ) {
3677 paintNodeDataUnrootedCirc( g,
3682 ( high_angle + low_angle ) / 2,
3683 isInFoundNodes( n ) || isInCurrentExternalNodes( n ) );
3686 final float num_enclosed = n.getNumberOfExternalNodes();
3687 final float x = n.getXcoord();
3688 final float y = n.getYcoord();
3689 double current_angle = low_angle;
3690 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
3691 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
3692 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
3693 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
3694 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3695 final PhylogenyNode desc = n.getChildNode( i );
3696 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
3697 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
3698 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
3699 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
3702 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
3705 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
3708 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3709 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3711 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3712 if ( desc.getDistanceToParent() < 0 ) {
3716 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
3720 length = getUrtFactor();
3722 final double mid_angle = current_angle + ( arc_size / 2 );
3723 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
3724 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
3725 desc.setXcoord( new_x );
3726 desc.setYcoord( new_y );
3727 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
3728 current_angle += arc_size;
3729 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
3730 drawLine( x, y, new_x, new_y, g );
3731 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file );
3734 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file );
3738 final private void paintUnrootedLite( final PhylogenyNode n,
3739 final double low_angle,
3740 final double high_angle,
3742 final float urt_ov_factor ) {
3744 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) );
3745 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) );
3746 n.setXSecondary( x_pos );
3747 n.setYSecondary( y_pos );
3749 if ( n.isExternal() ) {
3752 final float num_enclosed = n.getNumberOfExternalNodes();
3753 final float x = n.getXSecondary();
3754 final float y = n.getYSecondary();
3755 double current_angle = low_angle;
3756 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3757 final PhylogenyNode desc = n.getChildNode( i );
3758 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3759 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3761 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3762 if ( desc.getDistanceToParent() < 0 ) {
3766 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
3770 length = urt_ov_factor;
3772 final double mid_angle = current_angle + ( arc_size / 2 );
3773 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
3774 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
3775 desc.setXSecondary( new_x );
3776 desc.setYSecondary( new_y );
3777 if ( isInFoundNodes( desc ) || isInCurrentExternalNodes( desc ) ) {
3778 g.setColor( getColorForFoundNode( desc ) );
3779 drawRectFilled( desc.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3780 desc.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3781 OVERVIEW_FOUND_NODE_BOX_SIZE,
3782 OVERVIEW_FOUND_NODE_BOX_SIZE,
3784 g.setColor( getTreeColorSet().getOvColor() );
3786 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
3787 current_angle += arc_size;
3788 drawLine( x, y, new_x, new_y, g );
3792 final private void pasteSubtree( final PhylogenyNode node ) {
3793 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3794 errorMessageNoCutCopyPasteInUnrootedDisplay();
3797 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
3798 JOptionPane.showMessageDialog( this,
3799 "No tree in buffer (need to copy or cut a subtree first)",
3800 "Attempt to paste with empty buffer",
3801 JOptionPane.ERROR_MESSAGE );
3804 final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
3805 final Object[] options = { "As sibling", "As descendant", "Cancel" };
3806 final int r = JOptionPane.showOptionDialog( this,
3807 "How to paste subtree" + label + "?",
3809 JOptionPane.CLOSED_OPTION,
3810 JOptionPane.QUESTION_MESSAGE,
3814 boolean paste_as_sibling = true;
3816 paste_as_sibling = false;
3818 else if ( r != 0 ) {
3821 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
3822 buffer_phy.setAllNodesToNotCollapse();
3823 PhylogenyMethods.preOrderReId( buffer_phy );
3824 buffer_phy.setRooted( true );
3825 boolean need_to_show_whole = false;
3826 if ( paste_as_sibling ) {
3827 if ( node.isRoot() ) {
3828 JOptionPane.showMessageDialog( this,
3829 "Cannot paste sibling to root",
3830 "Attempt to paste sibling to root",
3831 JOptionPane.ERROR_MESSAGE );
3834 buffer_phy.addAsSibling( node );
3837 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
3838 need_to_show_whole = true;
3839 _phylogeny = buffer_phy;
3842 buffer_phy.addAsChild( node );
3845 if ( getCopiedAndPastedNodes() == null ) {
3846 setCopiedAndPastedNodes( new HashSet<Long>() );
3848 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
3849 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
3850 for( final PhylogenyNode n : nodes ) {
3851 node_ids.add( n.getId() );
3853 node_ids.add( node.getId() );
3854 getCopiedAndPastedNodes().addAll( node_ids );
3855 setNodeInPreorderToNull();
3856 _phylogeny.externalNodesHaveChanged();
3857 _phylogeny.clearHashIdToNodeMap();
3858 _phylogeny.recalculateNumberOfExternalDescendants( true );
3859 resetNodeIdToDistToLeafMap();
3861 if ( need_to_show_whole ) {
3862 getControlPanel().showWhole();
3867 private final StringBuffer propertiesToString( final PhylogenyNode node ) {
3868 return node.getNodeData().getProperties().asText();
3871 private void setColor( final Graphics2D g,
3872 final PhylogenyNode node,
3873 final boolean to_graphics_file,
3874 final boolean to_pdf,
3875 final boolean is_in_found_nodes,
3876 final Color default_color ) {
3877 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3878 g.setColor( Color.BLACK );
3880 else if ( is_in_found_nodes ) {
3881 g.setColor( getColorForFoundNode( node ) );
3883 else if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
3884 && ( node.getNodeData().getNodeVisualData().getFontColor() != null ) ) {
3885 g.setColor( node.getNodeData().getNodeVisualData().getFontColor() );
3887 else if ( getControlPanel().isColorAccordingToSequence() ) {
3888 g.setColor( getSequenceBasedColor( node ) );
3890 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3891 g.setColor( getTaxonomyBasedColor( node ) );
3893 else if ( getControlPanel().isColorAccordingToAnnotation()
3894 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null )
3895 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
3896 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
3898 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
3899 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3900 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3902 else if ( to_pdf ) {
3903 g.setColor( Color.BLACK );
3906 g.setColor( default_color );
3910 final private void setCopiedAndPastedNodes( final Set<Long> nodeIds ) {
3911 getMainPanel().setCopiedAndPastedNodes( nodeIds );
3914 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
3915 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
3918 private boolean setFont( final Graphics2D g, final PhylogenyNode node, final boolean is_in_found_nodes ) {
3919 Font visual_font = null;
3920 if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null ) ) {
3921 visual_font = node.getNodeData().getNodeVisualData().getFont();
3922 g.setFont( visual_font != null ? visual_font : getTreeFontSet().getLargeFont() );
3925 g.setFont( getTreeFontSet().getLargeFont() );
3927 if ( is_in_found_nodes ) {
3928 g.setFont( g.getFont().deriveFont( Font.BOLD ) );
3930 return visual_font != null;
3933 final private void setInOv( final boolean in_ov ) {
3937 final private void setOvMaxHeight( final float ov_max_height ) {
3938 _ov_max_height = ov_max_height;
3941 final private void setOvMaxWidth( final float ov_max_width ) {
3942 _ov_max_width = ov_max_width;
3945 final private void setOvXcorrectionFactor( final float f ) {
3946 _ov_x_correction_factor = f;
3949 final private void setOvXDistance( final float ov_x_distance ) {
3950 _ov_x_distance = ov_x_distance;
3953 final private void setOvXPosition( final int ov_x_position ) {
3954 _ov_x_position = ov_x_position;
3957 final private void setOvYDistance( final float ov_y_distance ) {
3958 _ov_y_distance = ov_y_distance;
3961 final private void setOvYPosition( final int ov_y_position ) {
3962 _ov_y_position = ov_y_position;
3965 final private void setOvYStart( final int ov_y_start ) {
3966 _ov_y_start = ov_y_start;
3969 final private void setScaleDistance( final double scale_distance ) {
3970 _scale_distance = scale_distance;
3973 final private void setScaleLabel( final String scale_label ) {
3974 _scale_label = scale_label;
3977 private final void setupStroke( final Graphics2D g ) {
3978 if ( getYdistance() < 0.0001 ) {
3979 g.setStroke( STROKE_0025 );
3981 if ( getYdistance() < 0.001 ) {
3982 g.setStroke( STROKE_005 );
3984 else if ( getYdistance() < 0.01 ) {
3985 g.setStroke( STROKE_01 );
3987 else if ( getYdistance() < 0.5 ) {
3988 g.setStroke( STROKE_025 );
3990 else if ( getYdistance() < 1 ) {
3991 g.setStroke( STROKE_05 );
3993 else if ( getYdistance() < 2 ) {
3994 g.setStroke( STROKE_075 );
3996 else if ( ( getYdistance() < 20 ) || !getConfiguration().isAllowThickStrokes() ) {
3997 g.setStroke( STROKE_1 );
4000 g.setStroke( STROKE_2 );
4004 final private void setUpUrtFactor() {
4005 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
4006 : getVisibleRect().height;
4007 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4008 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
4011 final int max_depth = _circ_max_depth;
4012 if ( max_depth > 0 ) {
4013 setUrtFactor( d / ( 2 * max_depth ) );
4016 setUrtFactor( d / 2 );
4019 setUrtFactorOv( getUrtFactor() );
4022 final private void setUrtFactor( final float urt_factor ) {
4023 _urt_factor = urt_factor;
4026 final private void setUrtFactorOv( final float urt_factor_ov ) {
4027 _urt_factor_ov = urt_factor_ov;
4030 private void showExtDescNodeData( final PhylogenyNode node ) {
4031 final List<String> data = new ArrayList<String>();
4032 final List<PhylogenyNode> nodes = node.getAllExternalDescendants();
4033 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
4034 for( final PhylogenyNode n : getFoundNodesAsListOfPhylogenyNodes() ) {
4035 if ( !nodes.contains( n ) ) {
4040 for( final PhylogenyNode n : nodes ) {
4041 switch ( getOptions().getExtDescNodeDataToReturn() ) {
4043 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
4044 data.add( n.getName() );
4048 if ( n.getNodeData().isHasSequence()
4049 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
4050 data.add( n.getNodeData().getSequence().getName() );
4054 if ( n.getNodeData().isHasSequence()
4055 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
4056 data.add( n.getNodeData().getSequence().getGeneName() );
4059 case SEQUENCE_SYMBOL:
4060 if ( n.getNodeData().isHasSequence()
4061 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
4062 data.add( n.getNodeData().getSequence().getSymbol() );
4065 case SEQUENCE_MOL_SEQ_FASTA:
4066 final StringBuilder sb = new StringBuilder();
4067 if ( n.getNodeData().isHasSequence()
4068 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
4069 final StringBuilder ann = new StringBuilder();
4070 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
4071 ann.append( n.getName() );
4074 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
4075 ann.append( "SYM=" );
4076 ann.append( n.getNodeData().getSequence().getSymbol() );
4079 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
4080 ann.append( "NAME=" );
4081 ann.append( n.getNodeData().getSequence().getName() );
4084 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
4085 ann.append( "GN=" );
4086 ann.append( n.getNodeData().getSequence().getGeneName() );
4089 if ( n.getNodeData().getSequence().getAccession() != null ) {
4090 ann.append( "ACC=" );
4091 ann.append( n.getNodeData().getSequence().getAccession().asText() );
4094 if ( n.getNodeData().isHasTaxonomy() ) {
4095 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
4096 ann.append( "TAXID=" );
4097 ann.append( n.getNodeData().getTaxonomy().getTaxonomyCode() );
4100 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
4101 ann.append( "SN=" );
4102 ann.append( n.getNodeData().getTaxonomy().getScientificName() );
4107 if ( ann.charAt( ann.length() - 1 ) == '|' ) {
4108 ann_str = ann.substring( 0, ann.length() - 1 );
4111 ann_str = ann.toString();
4113 sb.append( SequenceWriter.toFasta( ann_str,
4114 n.getNodeData().getSequence().getMolecularSequence(),
4116 data.add( sb.toString() );
4120 if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
4121 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
4122 data.add( n.getNodeData().getSequence().getAccession().toString() );
4125 case TAXONOMY_SCIENTIFIC_NAME:
4126 if ( n.getNodeData().isHasTaxonomy()
4127 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
4128 data.add( n.getNodeData().getTaxonomy().getScientificName() );
4132 if ( n.getNodeData().isHasTaxonomy()
4133 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
4134 data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
4138 case DOMAINS_COLLAPSED_PER_PROTEIN:
4139 if ( n.getNodeData().isHasSequence()
4140 && ( n.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4141 final DomainArchitecture da = n.getNodeData().getSequence().getDomainArchitecture();
4142 final Set<String> s = new HashSet<String>();
4143 for( int i = 0; i < da.getDomains().size(); ++i ) {
4144 final ProteinDomain d = da.getDomain( i );
4145 if ( d.getConfidence() <= Math.pow( 10, getDomainStructureEvalueThresholdExp() ) ) {
4146 final String name = d.getName();
4147 if ( !( s.contains( name ) ) ) {
4150 .getExtDescNodeDataToReturn() == NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN ) {
4158 case SEQ_ANNOTATIONS:
4159 if ( n.getNodeData().isHasSequence() ) {
4160 if ( n.getNodeData().isHasSequence()
4161 && ( n.getNodeData().getSequence().getAnnotations() != null ) ) {
4162 final SortedSet<Annotation> a = n.getNodeData().getSequence().getAnnotations();
4163 for( int i = 0; i < a.size(); ++i ) {
4164 data.add( n.getNodeData().getSequence().getAnnotation( i ).toString() );
4170 if ( n.getNodeData().isHasSequence() ) {
4171 if ( n.getNodeData().isHasSequence()
4172 && ( n.getNodeData().getSequence().getAnnotations() != null ) ) {
4173 final SortedSet<Annotation> a = n.getNodeData().getSequence().getAnnotations();
4174 for( int i = 0; i < a.size(); ++i ) {
4175 final Annotation ann = n.getNodeData().getSequence().getAnnotation( i );
4176 final String ref = ann.getRef();
4177 if ( ref.toUpperCase().startsWith( "GO:" ) ) {
4185 TreePanelUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
4188 throw new IllegalArgumentException( "unknown data element: "
4189 + getOptions().getExtDescNodeDataToReturn() );
4192 final StringBuilder sb = new StringBuilder();
4193 final int size = TreePanelUtil.nodeDataIntoStringBuffer( data, getOptions(), sb );
4194 if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
4195 || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
4196 if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
4197 System.out.println( sb );
4199 if ( sb.length() < 1 ) {
4200 clearCurrentExternalNodesDataBuffer();
4203 setCurrentExternalNodesDataBuffer( sb );
4206 else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
4207 if ( sb.length() < 1 ) {
4208 TreePanelUtil.showInformationMessage( this,
4209 "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")",
4210 "Descendants of selected node do not contain selected data" );
4211 clearCurrentExternalNodesDataBuffer();
4214 setCurrentExternalNodesDataBuffer( sb );
4216 if ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() ) {
4217 title = ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.UNKNOWN ? "Data"
4218 : obtainTitleForExtDescNodeData() ) + " for " + data.size() + " nodes, unique entries: "
4222 title = ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.UNKNOWN ? "Data"
4223 : obtainTitleForExtDescNodeData() ) + " for " + data.size() + "/"
4224 + node.getNumberOfExternalNodes() + " external descendats of node " + node
4225 + ", unique entries: " + size;
4227 final String s = sb.toString().trim();
4228 getMainPanel().getMainFrame().showTextFrame( s, title );
4233 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
4235 if ( ( node.getName().length() > 0 )
4236 || ( node.getNodeData().isHasTaxonomy()
4237 && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
4238 || ( node.getNodeData().isHasSequence()
4239 && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) )
4240 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
4241 || node.getBranchData().isHasConfidences() ) {
4242 _popup_buffer.setLength( 0 );
4244 if ( node.getName().length() > 0 ) {
4246 _popup_buffer.append( node.getName() );
4248 if ( node.getNodeData().isHasTaxonomy()
4249 && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
4251 boolean enc_data = false;
4252 final Taxonomy tax = node.getNodeData().getTaxonomy();
4253 if ( _popup_buffer.length() > 0 ) {
4254 _popup_buffer.append( "\n" );
4256 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4257 _popup_buffer.append( "[" );
4258 _popup_buffer.append( tax.getTaxonomyCode() );
4259 _popup_buffer.append( "]" );
4262 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4264 _popup_buffer.append( " " );
4266 _popup_buffer.append( tax.getScientificName() );
4269 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
4271 _popup_buffer.append( " (" );
4274 _popup_buffer.append( "(" );
4276 _popup_buffer.append( tax.getCommonName() );
4277 _popup_buffer.append( ")" );
4280 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
4282 _popup_buffer.append( " (" );
4285 _popup_buffer.append( "(" );
4287 _popup_buffer.append( tax.getAuthority() );
4288 _popup_buffer.append( ")" );
4291 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
4293 _popup_buffer.append( " [" );
4296 _popup_buffer.append( "[" );
4298 _popup_buffer.append( tax.getRank() );
4299 _popup_buffer.append( "]" );
4302 if ( tax.getSynonyms().size() > 0 ) {
4304 _popup_buffer.append( " " );
4306 _popup_buffer.append( "[" );
4308 for( final String syn : tax.getSynonyms() ) {
4309 if ( !ForesterUtil.isEmpty( syn ) ) {
4311 _popup_buffer.append( syn );
4312 if ( counter < tax.getSynonyms().size() ) {
4313 _popup_buffer.append( ", " );
4318 _popup_buffer.append( "]" );
4321 if ( ( tax.getIdentifier() != null )
4322 && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
4323 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
4324 _popup_buffer.append( "[" );
4325 _popup_buffer.append( tax.getIdentifier().getProvider() );
4326 _popup_buffer.append( "] " );
4328 _popup_buffer.append( tax.getIdentifier().getValue() );
4332 if ( node.getNodeData().isHasSequence()
4333 && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) ) {
4335 boolean enc_data = false;
4336 if ( _popup_buffer.length() > 0 ) {
4337 _popup_buffer.append( "\n" );
4339 final Sequence seq = node.getNodeData().getSequence();
4340 if ( seq.getAccession() != null ) {
4341 _popup_buffer.append( "[" );
4342 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
4343 _popup_buffer.append( seq.getAccession().getSource() );
4344 _popup_buffer.append( ":" );
4346 _popup_buffer.append( seq.getAccession().getValue() );
4347 _popup_buffer.append( "]" );
4350 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
4352 _popup_buffer.append( " [" );
4355 _popup_buffer.append( "[" );
4357 _popup_buffer.append( seq.getSymbol() );
4358 _popup_buffer.append( "]" );
4361 if ( !ForesterUtil.isEmpty( seq.getGeneName() ) ) {
4363 _popup_buffer.append( " [" );
4366 _popup_buffer.append( "[" );
4368 _popup_buffer.append( seq.getGeneName() );
4369 _popup_buffer.append( "]" );
4372 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
4374 _popup_buffer.append( " " );
4376 _popup_buffer.append( seq.getName() );
4379 if ( node.getNodeData().isHasDate() ) {
4381 if ( _popup_buffer.length() > 0 ) {
4382 _popup_buffer.append( "\n" );
4384 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
4386 if ( node.getNodeData().isHasDistribution() ) {
4388 if ( _popup_buffer.length() > 0 ) {
4389 _popup_buffer.append( "\n" );
4391 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
4393 if ( node.getBranchData().isHasConfidences() ) {
4394 final List<Confidence> confs = node.getBranchData().getConfidences();
4395 for( final Confidence confidence : confs ) {
4397 if ( _popup_buffer.length() > 0 ) {
4398 _popup_buffer.append( "\n" );
4400 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
4401 _popup_buffer.append( "[" );
4402 _popup_buffer.append( confidence.getType() );
4403 _popup_buffer.append( "] " );
4405 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
4407 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4408 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
4409 _popup_buffer.append( " (sd=" );
4410 _popup_buffer.append( FORMATTER_CONFIDENCE
4411 .format( ForesterUtil.round( confidence.getStandardDeviation(),
4413 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4414 _popup_buffer.append( ")" );
4418 if ( node.getNodeData().isHasProperties() ) {
4419 if ( _popup_buffer.length() > 0 ) {
4420 _popup_buffer.append( "\n" );
4422 _popup_buffer.append( node.getNodeData().getProperties().asText() );
4424 if ( _popup_buffer.length() > 0 ) {
4425 if ( !getConfiguration().isUseNativeUI() ) {
4427 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
4428 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
4429 if ( isInFoundNodes0( node ) && !isInFoundNodes1( node ) ) {
4430 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0() );
4432 else if ( !isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
4433 _rollover_popup.setForeground( getTreeColorSet().getFoundColor1() );
4435 else if ( isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
4436 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0and1() );
4439 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
4443 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
4445 _rollover_popup.setText( _popup_buffer.toString() );
4446 _node_desc_popup = PopupFactory.getSharedInstance()
4449 e.getLocationOnScreen().x + 10,
4450 e.getLocationOnScreen().y - ( lines * 20 ) );
4451 _node_desc_popup.show();
4455 catch ( final Exception ex ) {
4460 final private void showNodeEditFrame( final PhylogenyNode n ) {
4461 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4462 // pop up edit box for single node
4463 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
4464 _node_frame_index++;
4467 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4471 final private void showNodeFrame( final PhylogenyNode n ) {
4472 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4473 // pop up edit box for single node
4474 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
4475 _node_frame_index++;
4478 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4482 final private void switchDisplaygetPhylogenyGraphicsType() {
4483 switch ( getPhylogenyGraphicsType() ) {
4485 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4486 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4489 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4490 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4493 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4494 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4497 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4498 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4501 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4502 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4505 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4506 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4509 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4510 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4513 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4514 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4517 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
4519 if ( getControlPanel().getDynamicallyHideData() != null ) {
4520 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4521 getControlPanel().getDynamicallyHideData().setEnabled( false );
4524 getControlPanel().getDynamicallyHideData().setEnabled( true );
4527 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4528 getControlPanel().setDrawPhylogramEnabled( true );
4531 getControlPanel().setDrawPhylogramEnabled( false );
4533 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4536 final void calcMaxDepth() {
4537 if ( _phylogeny != null ) {
4538 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4543 * Set parameters for printing the displayed tree
4546 final void calcParametersForPainting( final int x, final int y ) {
4547 // updateStyle(); not needed?
4548 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4550 calculateLongestExtNodeInfo();
4551 if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
4552 && ( getTreeFontSet().getLargeFont().getSize() > ( 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
4553 while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) )
4554 && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) {
4555 getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(), true );
4556 calculateLongestExtNodeInfo();
4560 while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) ) && ( getTreeFontSet().getLargeFont()
4561 .getSize() <= ( getTreeFontSet().getLargeFontMemory().getSize()
4562 - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
4563 getMainPanel().getTreeFontSet().increaseFontSize();
4564 calculateLongestExtNodeInfo();
4567 //_length_of_longest_text = calcLengthOfLongestText();
4568 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4569 final int max_depth = PhylogenyMethods.calculateMaxDepthConsiderCollapsed( _phylogeny ) + 1;
4570 if ( ext_nodes == 1 ) {
4571 ext_nodes = max_depth;
4572 if ( ext_nodes < 1 ) {
4579 if ( !isNonLinedUpCladogram() ) {
4580 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
4581 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
4584 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
4585 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
4587 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
4588 if ( xdist < 0.0 ) {
4591 if ( ov_xdist < 0.0 ) {
4594 if ( ydist < 0.0 ) {
4597 setXdistance( xdist );
4598 setYdistance( ydist );
4599 setOvXDistance( ov_xdist );
4600 final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() );
4601 //final double height = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4603 final float corr = ( float ) ( ( x - ( 2.0 * TreePanel.MOVE ) - getLongestExtNodeInfo()
4604 - getXdistance() ) / height );
4605 setXcorrectionFactor( corr > 0 ? corr : 0 );
4606 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
4607 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4610 setXcorrectionFactor( 0 );
4611 setOvXcorrectionFactor( 0 );
4613 _circ_max_depth = max_depth;
4616 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
4617 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4618 // int dynamic_hiding_factor = calcDynamicHidingFactor();
4619 // if ( dynamic_hiding_factor > 1 ) {
4620 // while ( dynamic_hiding_factor > 1
4621 // && getTreeFontSet()._fm_large.getHeight() > TreeFontSet.SMALL_FONTS_BASE ) {
4622 // getTreeFontSet().decreaseFontSize( 1, true );
4623 // dynamic_hiding_factor = calcDynamicHidingFactor();
4626 // else if ( getTreeFontSet().isDecreasedSizeBySystem() ) {
4627 // while ( dynamic_hiding_factor < 1 && getTreeFontSet()._fm_large.getHeight() < 12 ) {
4628 // getTreeFontSet().increaseFontSize();
4629 // dynamic_hiding_factor = calcDynamicHidingFactor();
4637 final void calculateLongestExtNodeInfo() {
4638 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
4641 int max_possible_length = ForesterUtil
4642 .roundToInt( ( getSize().getWidth() - ( 2 * MOVE ) ) * AptxConstants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
4643 if ( max_possible_length < 20 ) {
4644 max_possible_length = 20;
4647 int longest_txt = 0;
4648 _longest_domain = 0;
4649 PhylogenyNode longest_txt_node = _phylogeny.getFirstExternalNode();
4650 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
4652 if ( node.isCollapse() ) {
4655 final StringBuilder sb = new StringBuilder();
4656 nodeDataAsSB( node, sb );
4657 if ( node.getNodeData().isHasTaxonomy() ) {
4658 nodeTaxonomyDataAsSB( node.getNodeData().getTaxonomy(), sb );
4660 final int txt = sb.length();
4661 if ( txt > longest_txt ) {
4663 longest_txt_node = node;
4665 boolean use_vis = false;
4666 final Graphics2D g = ( Graphics2D ) getGraphics();
4667 if ( getControlPanel().isUseVisualStyles() ) {
4668 use_vis = setFont( g, node, false );
4671 sum = getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
4674 sum = getFontMetrics( g.getFont() ).stringWidth( sb.toString() );
4676 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
4677 sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getBinaryCharacters()
4678 .getGainedCharactersAsStringBuffer().toString() );
4680 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
4681 && ( node.getNodeData().getVector().size() > 0 ) ) {
4682 if ( getConfiguration() != null ) {
4683 sum += getConfiguration().getVectorDataWidth() + 10;
4686 sum += RenderableVector.VECTOR_DEFAULT_WIDTH + 10;
4689 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4690 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4692 // TODO this might need some clean up
4693 final DomainArchitecture d = node.getNodeData().getSequence().getDomainArchitecture();
4694 sum += ( ( _domain_structure_width
4695 / ( ( RenderableDomainArchitecture ) d ).getOriginalSize().getWidth() ) * d.getTotalLength() )
4697 if ( d.getTotalLength() > _longest_domain ) {
4698 _longest_domain = d.getTotalLength();
4701 if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
4702 && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
4703 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
4705 sum += RenderableMsaSequence.DEFAULT_WIDTH + 30;
4707 if ( sum >= max_possible_length ) {
4708 _longest_ext_node_info = max_possible_length;
4709 // return; //FIXME why?
4711 if ( sum > longest ) {
4715 _ext_node_with_longest_txt_info = longest_txt_node;
4716 if ( longest >= max_possible_length ) {
4717 _longest_ext_node_info = max_possible_length;
4720 _longest_ext_node_info = longest;
4722 _length_of_longest_text = calcLengthOfLongestText();
4725 final void calculateScaleDistance() {
4726 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
4729 final double height = getMaxDistanceToRoot();
4731 if ( ( height <= 0.5 ) ) {
4732 setScaleDistance( 0.01 );
4734 else if ( height <= 5.0 ) {
4735 setScaleDistance( 0.1 );
4737 else if ( height <= 50.0 ) {
4738 setScaleDistance( 1 );
4740 else if ( height <= 500.0 ) {
4741 setScaleDistance( 10 );
4744 setScaleDistance( 100 );
4748 setScaleDistance( 0.0 );
4750 String scale_label = String.valueOf( getScaleDistance() );
4751 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
4752 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
4754 setScaleLabel( scale_label );
4757 final Color calculateSequenceBasedColor( final Sequence seq ) {
4758 if ( ForesterUtil.isEmpty( seq.getName() ) ) {
4759 return getTreeColorSet().getSequenceColor();
4762 final String seq_name = seq.getName();
4763 c = getControlPanel().getSequenceColors().get( seq_name );
4765 c = AptxUtil.calculateColorFromString( seq_name, false );
4766 getControlPanel().getSequenceColors().put( seq_name, c );
4771 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
4772 if ( getOptions().isColorByTaxonomicGroup() ) {
4773 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4775 String group = null;
4777 group = TaxonomyUtil.getTaxGroupByTaxCode( tax.getTaxonomyCode() );
4779 catch ( final Exception e ) {
4782 if ( !ex && !ForesterUtil.isEmpty( group ) ) {
4783 final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group );
4789 return getTreeColorSet().getTaxonomyColor();
4792 if ( ForesterUtil.isEmpty( tax.getTaxonomyCode() ) && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4793 return getTreeColorSet().getTaxonomyColor();
4796 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4797 c = getControlPanel().getSpeciesColors().get( tax.getTaxonomyCode() );
4799 if ( ( c == null ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4800 c = getControlPanel().getSpeciesColors().get( tax.getScientificName() );
4803 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4804 c = AptxUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
4805 getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c );
4808 c = AptxUtil.calculateColorFromString( tax.getScientificName(), true );
4809 getControlPanel().getSpeciesColors().put( tax.getScientificName(), c );
4816 void clearCurrentExternalNodesDataBuffer() {
4817 setCurrentExternalNodesDataBuffer( new StringBuilder() );
4821 * Collapse the tree from the given node
4826 final void collapse( final PhylogenyNode node ) {
4827 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4828 JOptionPane.showMessageDialog( this,
4829 "Cannot collapse in unrooted display type",
4830 "Attempt to collapse in unrooted display",
4831 JOptionPane.WARNING_MESSAGE );
4834 if ( !node.isExternal() && !node.isRoot() ) {
4835 final boolean collapse = !node.isCollapse();
4836 TreePanelUtil.collapseSubtree( node, collapse );
4837 updateSetOfCollapsedExternalNodes();
4838 _phylogeny.recalculateNumberOfExternalDescendants( true );
4839 resetNodeIdToDistToLeafMap();
4840 calculateLongestExtNodeInfo();
4841 setNodeInPreorderToNull();
4842 _control_panel.displayedPhylogenyMightHaveChanged( true );
4843 resetPreferredSize();
4845 _main_panel.adjustJScrollPane();
4850 final void uncollapseAll( final PhylogenyNode node ) {
4851 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4852 JOptionPane.showMessageDialog( this,
4853 "Cannot uncollapse in unrooted display type",
4854 "Attempt to uncollapse in unrooted display",
4855 JOptionPane.WARNING_MESSAGE );
4858 if ( !node.isExternal() ) {
4859 TreePanelUtil.uncollapseSubtree( node );
4860 updateSetOfCollapsedExternalNodes();
4861 _phylogeny.recalculateNumberOfExternalDescendants( true );
4862 resetNodeIdToDistToLeafMap();
4863 calculateLongestExtNodeInfo();
4864 setNodeInPreorderToNull();
4865 _control_panel.displayedPhylogenyMightHaveChanged( true );
4866 resetPreferredSize();
4868 _main_panel.adjustJScrollPane();
4873 final void collapseSpeciesSpecificSubtrees() {
4874 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4878 TreePanelUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
4879 updateSetOfCollapsedExternalNodes();
4880 _phylogeny.recalculateNumberOfExternalDescendants( true );
4881 resetNodeIdToDistToLeafMap();
4882 calculateLongestExtNodeInfo();
4883 setNodeInPreorderToNull();
4884 resetPreferredSize();
4885 resetDepthCollapseDepthValue();
4886 resetRankCollapseRankValue();
4887 _main_panel.adjustJScrollPane();
4888 getControlPanel().showWhole();
4892 final void colorRank( final String rank ) {
4893 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4897 AptxUtil.removeBranchColors( _phylogeny );
4898 final int colorizations = TreePanelUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
4899 if ( colorizations > 0 ) {
4900 _control_panel.setColorBranches( true );
4901 if ( _control_panel.getUseVisualStylesCb() != null ) {
4902 _control_panel.getUseVisualStylesCb().setSelected( true );
4904 if ( _control_panel.getColorAccSpeciesCb() != null ) {
4905 _control_panel.getColorAccSpeciesCb().setSelected( false );
4907 _options.setColorLabelsSameAsParentBranch( true );
4908 if ( getMainPanel().getMainFrame()._color_labels_same_as_parent_branch != null ) {
4909 getMainPanel().getMainFrame()._color_labels_same_as_parent_branch.setSelected( true );
4911 _control_panel.repaint();
4915 if ( colorizations > 0 ) {
4916 String msg = "Taxonomy colorization via " + rank + " completed:\n";
4917 if ( colorizations > 1 ) {
4918 msg += "colorized " + colorizations + " subtrees";
4921 msg += "colorized one subtree";
4924 JOptionPane.showMessageDialog( this,
4926 "Taxonomy Rank-Colorization Completed (" + rank + ")",
4927 JOptionPane.INFORMATION_MESSAGE );
4930 String msg = "Could not taxonomy rank-colorize any subtree via " + rank + ".\n";
4931 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
4932 msg += "select a different rank (e.g. phylum, genus, ...)\n";
4934 msg += "execute:\n";
4935 msg += "1. \"" + MainFrame.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
4936 msg += "2. \"" + MainFrame.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
4937 JOptionPane.showMessageDialog( this,
4939 "Taxonomy Rank-Colorization Failed",
4940 JOptionPane.WARNING_MESSAGE );
4944 final void confColor() {
4945 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4949 AptxUtil.removeBranchColors( _phylogeny );
4950 TreePanelUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
4951 _control_panel.setColorBranches( true );
4952 if ( _control_panel.getUseVisualStylesCb() != null ) {
4953 _control_panel.getUseVisualStylesCb().setSelected( true );
4959 final void decreaseDomainStructureEvalueThresholdExp() {
4960 if ( _domain_structure_e_value_thr_exp > -20 ) {
4961 _domain_structure_e_value_thr_exp -= 1;
4966 * Find the node, if any, at the given location
4970 * @return pointer to the node at x,y, null if not found
4972 final PhylogenyNode findNode( final int x, final int y ) {
4973 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
4976 final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE;
4977 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
4978 final PhylogenyNode node = iter.next();
4979 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
4980 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
4981 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
4982 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
4983 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
4990 final Configuration getConfiguration() {
4991 return _configuration;
4994 final ControlPanel getControlPanel() {
4995 return _control_panel;
4998 String getCurrentExternalNodesDataBufferAsString() {
4999 return _current_external_nodes_data_buffer.toString();
5002 int getCurrentExternalNodesDataBufferChangeCounter() {
5003 return _current_external_nodes_data_buffer_change_counter;
5006 final int getDomainStructureEvalueThresholdExp() {
5007 return _domain_structure_e_value_thr_exp;
5010 final Set<Long> getFoundNodes0() {
5011 return _found_nodes_0;
5014 final Set<Long> getFoundNodes1() {
5015 return _found_nodes_1;
5018 List<PhylogenyNode> getFoundNodesAsListOfPhylogenyNodes() {
5019 final List<PhylogenyNode> additional_nodes = new ArrayList<PhylogenyNode>();
5020 if ( getFoundNodes0() != null ) {
5021 for( final Long id : getFoundNodes0() ) {
5022 final PhylogenyNode n = _phylogeny.getNode( id );
5024 additional_nodes.add( n );
5028 if ( getFoundNodes1() != null ) {
5029 for( final Long id : getFoundNodes1() ) {
5030 if ( ( getFoundNodes0() == null ) || !getFoundNodes0().contains( id ) ) {
5031 final PhylogenyNode n = _phylogeny.getNode( id );
5033 additional_nodes.add( n );
5038 return additional_nodes;
5041 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
5042 if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
5043 return ( PhylogenyMethods.getBranchColorValue( node ) );
5046 return ( getTreeColorSet().getBranchColor() );
5050 final int getLongestExtNodeInfo() {
5051 return _longest_ext_node_info;
5054 final Options getOptions() {
5055 if ( _options == null ) {
5056 _options = getControlPanel().getOptions();
5061 final Rectangle2D getOvRectangle() {
5062 return _ov_rectangle;
5065 final Rectangle getOvVirtualRectangle() {
5066 return _ov_virtual_rectangle;
5069 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
5070 return _graphics_type;
5073 final Color getSequenceBasedColor( final PhylogenyNode node ) {
5074 if ( node.getNodeData().isHasSequence() ) {
5075 return calculateSequenceBasedColor( node.getNodeData().getSequence() );
5077 // return non-colorized color
5078 return getTreeColorSet().getSequenceColor();
5081 final double getStartingAngle() {
5082 return _urt_starting_angle;
5085 DescriptiveStatistics getStatisticsForExpressionValues() {
5086 return _statistics_for_vector_data;
5089 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
5090 if ( node.isExternal() && node.getNodeData().isHasTaxonomy() ) {
5091 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
5093 // return non-colorized color
5094 return getTreeColorSet().getTaxonomyColor();
5097 final File getTreeFile() {
5101 final float getXcorrectionFactor() {
5102 return _x_correction_factor;
5105 final float getXdistance() {
5109 final float getYdistance() {
5113 final void increaseDomainStructureEvalueThresholdExp() {
5114 if ( _domain_structure_e_value_thr_exp < 3 ) {
5115 _domain_structure_e_value_thr_exp += 1;
5119 final void initNodeData() {
5120 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
5123 double _max_original_domain_structure_width = 0.0;
5124 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
5125 if ( node.getNodeData().isHasSequence()
5126 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
5127 RenderableDomainArchitecture rds = null;
5128 if ( !( node.getNodeData().getSequence()
5129 .getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
5130 if ( SPECIAL_DOMAIN_COLORING ) {
5131 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence()
5132 .getDomainArchitecture(), node.getName() );
5135 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence()
5136 .getDomainArchitecture() );
5138 node.getNodeData().getSequence().setDomainArchitecture( rds );
5141 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
5143 if ( getControlPanel().isShowDomainArchitectures() ) {
5144 final double dsw = rds.getOriginalSize().getWidth();
5145 if ( dsw > _max_original_domain_structure_width ) {
5146 _max_original_domain_structure_width = dsw;
5151 if ( getControlPanel().isShowDomainArchitectures() ) {
5152 final float ds_factor_width = ( float ) ( _domain_structure_width / _max_original_domain_structure_width );
5153 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
5154 if ( node.getNodeData().isHasSequence()
5155 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
5156 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
5157 .getSequence().getDomainArchitecture();
5158 rds.setRenderingFactorWidth( ds_factor_width );
5159 rds.setParameter( _domain_structure_e_value_thr_exp );
5165 final boolean inOv( final MouseEvent e ) {
5166 return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) )
5167 && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) )
5168 && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) )
5169 && ( e.getY() < ( ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) );
5172 final boolean inOvRectangle( final MouseEvent e ) {
5173 return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) )
5174 && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) )
5175 && ( e.getY() >= ( getOvRectangle().getY() - 1 ) )
5176 && ( e.getY() <= ( getOvRectangle().getY() + getOvRectangle().getHeight() + 1 ) ) );
5179 final boolean isCanCollapse() {
5180 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5183 final boolean isCanUncollapseAll( final PhylogenyNode node ) {
5184 if ( node.isExternal() || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
5187 if ( node.isCollapse() ) {
5190 final PhylogenyNodeIterator it = new PreorderTreeIterator( node );
5191 while ( it.hasNext() ) {
5192 if ( it.next().isCollapse() ) {
5199 final boolean isCanColorSubtree() {
5200 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5203 final boolean isCanCopy() {
5204 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
5207 final boolean isCanCut( final PhylogenyNode node ) {
5208 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
5209 && !node.isRoot() );
5212 final boolean isCanDelete() {
5213 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
5216 final boolean isCanPaste() {
5217 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
5218 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
5221 final boolean isCanReroot() {
5222 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
5225 final boolean isCanSubtree( final PhylogenyNode node ) {
5226 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal()
5227 && ( !node.isRoot() || ( _subtree_index > 0 ) ) );
5230 final boolean isCurrentTreeIsSubtree() {
5231 return ( _subtree_index > 0 );
5234 final boolean isEdited() {
5238 final boolean isInOvRect() {
5242 final boolean isOvOn() {
5246 final boolean isPhyHasBranchLengths() {
5247 return _phy_has_branch_lengths;
5250 final void midpointRoot() {
5251 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
5254 if ( !_phylogeny.isRerootable() ) {
5255 JOptionPane.showMessageDialog( this,
5256 "This is not rerootable",
5258 JOptionPane.WARNING_MESSAGE );
5261 setNodeInPreorderToNull();
5263 PhylogenyMethods.midpointRoot( _phylogeny );
5264 resetNodeIdToDistToLeafMap();
5270 final void mouseClicked( final MouseEvent e ) {
5271 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
5272 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
5273 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
5274 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) )
5276 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) )
5284 final double max_x = getWidth() - getVisibleRect().width;
5285 final double max_y = getHeight() - getVisibleRect().height;
5292 getMainPanel().getCurrentScrollPane().getViewport()
5293 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
5294 setInOvRect( true );
5298 final PhylogenyNode node = findNode( e.getX(), e.getY() );
5299 if ( node != null ) {
5300 if ( !node.isRoot() && node.getParent().isCollapse() ) {
5303 _highlight_node = node;
5304 // Check if shift key is down
5305 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
5306 // Yes, so add to _found_nodes
5307 if ( getFoundNodes0() == null ) {
5308 setFoundNodes0( new HashSet<Long>() );
5310 getFoundNodes0().add( node.getId() );
5311 // Check if control key is down
5313 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
5314 // Yes, so pop-up menu
5315 displayNodePopupMenu( node, e.getX(), e.getY() );
5316 // Handle unadorned click
5319 // Check for right mouse button
5320 if ( e.getModifiers() == 4 ) {
5321 displayNodePopupMenu( node, e.getX(), e.getY() );
5324 // if not in _found_nodes, clear _found_nodes
5325 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
5330 // no node was clicked
5331 _highlight_node = null;
5337 final void mouseDragInBrowserPanel( final MouseEvent e ) {
5338 setCursor( MOVE_CURSOR );
5339 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
5340 scroll_position.x -= ( e.getX() - getLastDragPointX() );
5341 scroll_position.y -= ( e.getY() - getLastDragPointY() );
5342 if ( scroll_position.x < 0 ) {
5343 scroll_position.x = 0;
5346 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
5347 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
5348 if ( scroll_position.x > max_x ) {
5349 scroll_position.x = max_x;
5352 if ( scroll_position.y < 0 ) {
5353 scroll_position.y = 0;
5356 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
5357 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
5358 if ( scroll_position.y > max_y ) {
5359 scroll_position.y = max_y;
5362 if ( isOvOn() || getOptions().isShowScale() ) {
5365 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
5368 final void mouseDragInOvRectangle( final MouseEvent e ) {
5369 setCursor( HAND_CURSOR );
5370 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
5371 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
5372 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
5373 double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) );
5374 double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) );
5375 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
5376 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
5377 if ( scroll_position.x <= 0 ) {
5378 scroll_position.x = 0;
5382 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
5383 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
5384 if ( scroll_position.x >= max_x ) {
5386 scroll_position.x = max_x;
5389 if ( scroll_position.y <= 0 ) {
5391 scroll_position.y = 0;
5394 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
5395 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
5396 if ( scroll_position.y >= max_y ) {
5398 scroll_position.y = max_y;
5402 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
5403 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
5404 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
5407 final void mouseMoved( final MouseEvent e ) {
5408 requestFocusInWindow();
5409 if ( _current_external_nodes != null ) {
5410 _current_external_nodes = null;
5413 if ( getControlPanel().isNodeDescPopup() ) {
5414 if ( _node_desc_popup != null ) {
5415 _node_desc_popup.hide();
5416 _node_desc_popup = null;
5419 if ( getOptions().isShowOverview() && isOvOn() ) {
5420 if ( inOvVirtualRectangle( e ) ) {
5421 if ( !isInOvRect() ) {
5422 setInOvRect( true );
5427 if ( isInOvRect() ) {
5428 setInOvRect( false );
5433 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
5442 final PhylogenyNode node = findNode( e.getX(), e.getY() );
5443 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
5444 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.GET_EXT_DESC_DATA ) ) {
5445 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
5446 addToCurrentExternalNodes( n.getId() );
5448 setCursor( HAND_CURSOR );
5451 else if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
5452 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
5453 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
5454 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
5455 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
5456 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
5457 setCursor( CUT_CURSOR );
5460 setCursor( HAND_CURSOR );
5461 if ( getControlPanel().isNodeDescPopup() ) {
5462 showNodeDataPopup( e, node );
5467 setCursor( ARROW_CURSOR );
5472 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
5473 setCursor( ARROW_CURSOR );
5476 final void multiplyUrtFactor( final float f ) {
5480 final void paintBranchCircular( final PhylogenyNode p,
5481 final PhylogenyNode c,
5483 final boolean radial_labels,
5484 final boolean to_pdf,
5485 final boolean to_graphics_file ) {
5486 final double angle = _urt_nodeid_angle_map.get( c.getId() );
5487 final double root_x = _root.getXcoord();
5488 final double root_y = _root.getYcoord();
5489 final double dx = root_x - p.getXcoord();
5490 final double dy = root_y - p.getYcoord();
5491 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
5492 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
5493 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
5494 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
5495 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
5496 final double r2 = 2.0 * parent_radius;
5497 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
5499 drawLine( c.getXcoord(),
5501 root_x + ( Math.cos( angle ) * parent_radius ),
5502 root_y + ( Math.sin( angle ) * parent_radius ),
5504 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file );
5505 if ( c.isExternal() ) {
5506 final boolean is_in_found_nodes = isInFoundNodes0( c ) || isInFoundNodes1( c )
5507 || isInCurrentExternalNodes( c );
5508 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
5509 && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
5512 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
5516 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
5517 final double angle = _urt_nodeid_angle_map.get( c.getId() );
5518 final double root_x = _root.getXSecondary();
5519 final double root_y = _root.getYSecondary();
5520 final double dx = root_x - p.getXSecondary();
5521 final double dy = root_y - p.getYSecondary();
5522 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
5523 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
5524 g.setColor( getTreeColorSet().getOvColor() );
5525 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
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.getXSecondary(),
5531 root_x + ( Math.cos( angle ) * parent_radius ),
5532 root_y + ( Math.sin( angle ) * parent_radius ),
5534 if ( isInFoundNodes( c ) || isInCurrentExternalNodes( c ) ) {
5535 g.setColor( getColorForFoundNode( c ) );
5536 drawRectFilled( c.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
5537 c.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
5538 OVERVIEW_FOUND_NODE_BOX_SIZE,
5539 OVERVIEW_FOUND_NODE_BOX_SIZE,
5544 final void paintCircular( final Phylogeny phy,
5545 final double starting_angle,
5550 final boolean to_pdf,
5551 final boolean to_graphics_file ) {
5552 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
5553 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
5554 _root = phy.getRoot();
5555 _root.setXcoord( center_x );
5556 _root.setYcoord( center_y );
5557 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
5558 double current_angle = starting_angle;
5560 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
5561 final PhylogenyNode n = it.next();
5562 if ( !n.isCollapse() ) {
5563 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
5564 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
5565 _urt_nodeid_angle_map.put( n.getId(), current_angle );
5566 _urt_nodeid_index_map.put( n.getId(), i++ );
5567 current_angle += ( TWO_PI / circ_num_ext_nodes );
5571 System.out.println( "is collapse" + n.getName() );
5574 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
5575 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file );
5578 final void paintCircularLite( final Phylogeny phy,
5579 final double starting_angle,
5583 final Graphics2D g ) {
5584 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
5585 _root = phy.getRoot();
5586 _root.setXSecondary( center_x );
5587 _root.setYSecondary( center_y );
5588 double current_angle = starting_angle;
5589 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
5590 final PhylogenyNode n = it.next();
5591 n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
5592 n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
5593 _urt_nodeid_angle_map.put( n.getId(), current_angle );
5594 current_angle += ( TWO_PI / circ_num_ext_nodes );
5596 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
5599 final void paintPhylogeny( final Graphics2D g,
5600 final boolean to_pdf,
5601 final boolean to_graphics_file,
5602 final int graphics_file_width,
5603 final int graphics_file_height,
5604 final int graphics_file_x,
5605 final int graphics_file_y ) {
5606 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
5609 if ( _control_panel.isShowSequenceRelations() ) {
5610 _query_sequence = _control_panel.getSelectedQuerySequence();
5612 // Color the background
5614 final Rectangle r = getVisibleRect();
5615 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
5616 g.setColor( getTreeColorSet().getBackgroundColor() );
5617 if ( !to_graphics_file ) {
5621 if ( getOptions().isPrintBlackAndWhite() ) {
5622 g.setColor( Color.WHITE );
5624 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
5628 if ( !to_graphics_file ) {
5629 g.setPaint( new GradientPaint( r.x,
5631 getTreeColorSet().getBackgroundColor(),
5634 getTreeColorSet().getBackgroundColorGradientBottom() ) );
5638 g.setPaint( new GradientPaint( graphics_file_x,
5640 getTreeColorSet().getBackgroundColor(),
5642 graphics_file_y + graphics_file_height,
5643 getTreeColorSet().getBackgroundColorGradientBottom() ) );
5644 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
5650 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
5652 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
5653 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5654 _external_node_index = 0;
5655 // Position starting X of tree
5656 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/ ) {
5657 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
5659 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
5660 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE
5661 + ( _phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor() ) ) );
5664 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
5666 // Position starting Y of tree
5667 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
5668 + ( TreePanel.MOVE / 2.0f ) );
5669 final int dynamic_hiding_factor = calcDynamicHidingFactor();
5670 if ( getControlPanel().isDynamicallyHideData() ) {
5671 if ( dynamic_hiding_factor > 1 ) {
5672 getControlPanel().setDynamicHidingIsOn( true );
5675 getControlPanel().setDynamicHidingIsOn( false );
5678 if ( _nodes_in_preorder == null ) {
5679 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
5681 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
5682 _nodes_in_preorder[ i++ ] = it.next();
5685 final boolean disallow_shortcutting = ( dynamic_hiding_factor < 40 )
5686 /* || getControlPanel().isUseVisualStyles() || getOptions().isShowDefaultNodeShapesForMarkedNodes()*/ //TODO check if this is really not needed.
5687 || to_graphics_file || to_pdf;
5688 for( final PhylogenyNode element : _nodes_in_preorder ) {
5689 paintNodeRectangular( g,
5692 getControlPanel().isDynamicallyHideData() && ( dynamic_hiding_factor > 1 ),
5693 dynamic_hiding_factor,
5695 disallow_shortcutting );
5697 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
5698 if ( !( to_graphics_file || to_pdf ) ) {
5701 getVisibleRect().y + getVisibleRect().height,
5706 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
5709 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5710 paintPhylogenyLite( g );
5713 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5714 if ( getControlPanel().getDynamicallyHideData() != null ) {
5715 getControlPanel().setDynamicHidingIsOn( false );
5717 final double angle = getStartingAngle();
5718 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
5719 _dynamic_hiding_factor = 0;
5720 if ( getControlPanel().isDynamicallyHideData() ) {
5721 _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5
5722 * getPhylogeny().getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
5724 if ( getControlPanel().getDynamicallyHideData() != null ) {
5725 if ( _dynamic_hiding_factor > 1 ) {
5726 getControlPanel().setDynamicHidingIsOn( true );
5729 getControlPanel().setDynamicHidingIsOn( false );
5732 paintUnrooted( _phylogeny.getRoot(),
5734 ( float ) ( angle + ( 2 * Math.PI ) ),
5739 if ( getOptions().isShowScale() ) {
5740 if ( !( to_graphics_file || to_pdf ) ) {
5743 getVisibleRect().y + getVisibleRect().height,
5748 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
5751 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5752 g.setColor( getTreeColorSet().getOvColor() );
5753 paintUnrootedLite( _phylogeny.getRoot(),
5755 angle + ( 2 * Math.PI ),
5757 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
5758 paintOvRectangle( g );
5761 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
5762 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() )
5763 / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
5764 final int d = radius + MOVE + getLongestExtNodeInfo();
5765 _dynamic_hiding_factor = 0;
5766 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
5767 _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5
5768 * getPhylogeny().getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
5770 if ( getControlPanel().getDynamicallyHideData() != null ) {
5771 if ( _dynamic_hiding_factor > 1 ) {
5772 getControlPanel().setDynamicHidingIsOn( true );
5775 getControlPanel().setDynamicHidingIsOn( false );
5778 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
5779 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5780 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
5781 : getOvMaxWidth() / 2 );
5782 double x_scale = 1.0;
5783 double y_scale = 1.0;
5784 int x_pos = getVisibleRect().x + getOvXPosition();
5785 int y_pos = getVisibleRect().y + getOvYPosition();
5786 if ( getWidth() > getHeight() ) {
5787 x_scale = ( double ) getHeight() / getWidth();
5788 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
5791 y_scale = ( double ) getWidth() / getHeight();
5792 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
5794 _at = g.getTransform();
5795 g.scale( x_scale, y_scale );
5796 paintCircularLite( _phylogeny,
5800 ( int ) ( radius_ov - ( getLongestExtNodeInfo()
5801 / ( getVisibleRect().width / getOvRectangle().getWidth() ) ) ),
5803 g.setTransform( _at );
5804 paintOvRectangle( g );
5809 final void recalculateMaxDistanceToRoot() {
5810 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
5811 if ( getPhylogeny().getRoot().getDistanceToParent() > 0 ) {
5812 _max_distance_to_root += getPhylogeny().getRoot().getDistanceToParent();
5817 * Remove all edit-node frames
5819 final void removeAllEditNodeJFrames() {
5820 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
5821 if ( _node_frames[ i ] != null ) {
5822 _node_frames[ i ].dispose();
5823 _node_frames[ i ] = null;
5826 _node_frame_index = 0;
5830 * Remove a node-edit frame.
5832 final void removeEditNodeFrame( final int i ) {
5833 _node_frame_index--;
5834 _node_frames[ i ] = null;
5835 if ( i < _node_frame_index ) {
5836 for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) {
5837 _node_frames[ j ] = _node_frames[ j + 1 ];
5839 _node_frames[ _node_frame_index ] = null;
5843 final void reRoot( final PhylogenyNode node ) {
5844 if ( !getPhylogeny().isRerootable() ) {
5845 JOptionPane.showMessageDialog( this,
5846 "This is not rerootable",
5848 JOptionPane.WARNING_MESSAGE );
5851 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5852 JOptionPane.showMessageDialog( this,
5853 "Cannot reroot in unrooted display type",
5854 "Attempt to reroot tree in unrooted display",
5855 JOptionPane.WARNING_MESSAGE );
5858 getPhylogeny().reRoot( node );
5859 getPhylogeny().recalculateNumberOfExternalDescendants( true );
5860 resetNodeIdToDistToLeafMap();
5861 setNodeInPreorderToNull();
5862 resetPreferredSize();
5863 getMainPanel().adjustJScrollPane();
5866 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
5867 getControlPanel().showWhole();
5871 final void resetNodeIdToDistToLeafMap() {
5872 _nodeid_dist_to_leaf = new HashMap<Long, Short>();
5875 final void resetPreferredSize() {
5876 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
5882 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
5883 if ( getControlPanel().isDrawPhylogram() ) {
5884 x = TreePanel.MOVE + getLongestExtNodeInfo()
5885 + ForesterUtil.roundToInt( ( getXcorrectionFactor()
5886 * getPhylogeny().calculateHeight( !_options.isCollapsedWithAverageHeigh() ) )
5890 if ( !isNonLinedUpCladogram() ) {
5891 x = TreePanel.MOVE + getLongestExtNodeInfo() + ForesterUtil
5892 .roundToInt( getXdistance() * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
5895 x = TreePanel.MOVE + getLongestExtNodeInfo() + ForesterUtil
5896 .roundToInt( getXdistance() * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
5899 setPreferredSize( new Dimension( x, y ) );
5902 final void selectNode( final PhylogenyNode node ) {
5903 if ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) ) {
5904 getFoundNodes0().remove( node.getId() );
5905 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
5906 if ( getFoundNodes0().size() < 1 ) {
5907 getControlPanel().searchReset0();
5911 getControlPanel().getSearchFoundCountsLabel0().setVisible( true );
5912 getControlPanel().getSearchResetButton0().setEnabled( true );
5913 getControlPanel().getSearchResetButton0().setVisible( true );
5914 if ( getFoundNodes0() == null ) {
5915 setFoundNodes0( new HashSet<Long>() );
5917 getFoundNodes0().add( node.getId() );
5918 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
5922 final void setArrowCursor() {
5923 setCursor( ARROW_CURSOR );
5927 final void setControlPanel( final ControlPanel atv_control ) {
5928 _control_panel = atv_control;
5931 void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
5932 increaseCurrentExternalNodesDataBufferChangeCounter();
5933 _current_external_nodes_data_buffer = sb;
5936 final void setFoundNodes0( final Set<Long> found_nodes ) {
5937 _found_nodes_0 = found_nodes;
5940 final void setFoundNodes1( final Set<Long> found_nodes ) {
5941 _found_nodes_1 = found_nodes;
5944 final void setInOvRect( final boolean in_ov_rect ) {
5945 _in_ov_rect = in_ov_rect;
5948 final void setLargeFonts() {
5949 getTreeFontSet().largeFonts();
5952 final void setLastMouseDragPointX( final float x ) {
5953 _last_drag_point_x = x;
5956 final void setLastMouseDragPointY( final float y ) {
5957 _last_drag_point_y = y;
5960 final void setMediumFonts() {
5961 getTreeFontSet().mediumFonts();
5964 final void setNodeInPreorderToNull() {
5965 _nodes_in_preorder = null;
5968 final void setOvOn( final boolean ov_on ) {
5972 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
5973 _graphics_type = graphics_type;
5977 final void setSmallFonts() {
5978 getTreeFontSet().smallFonts();
5981 final void setStartingAngle( final double starting_angle ) {
5982 _urt_starting_angle = starting_angle;
5985 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
5986 _statistics_for_vector_data = statistics_for_expression_values;
5989 final void setSuperTinyFonts() {
5990 getTreeFontSet().superTinyFonts();
5993 final void setTextAntialias() {
5994 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
5995 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
5996 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
5999 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
6002 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
6003 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
6005 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
6007 // catch ( final Throwable e ) {
6008 // _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
6012 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
6013 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
6017 final void setTinyFonts() {
6018 getTreeFontSet().tinyFonts();
6021 final void setTreeFile( final File treefile ) {
6022 _treefile = treefile;
6025 final void setXcorrectionFactor( final float f ) {
6026 _x_correction_factor = f;
6029 final void setXdistance( final float x ) {
6033 final void setYdistance( final float y ) {
6037 final void sortDescendants( final PhylogenyNode node ) {
6038 if ( !node.isExternal() ) {
6039 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
6040 if ( getControlPanel().isShowTaxonomyScientificNames() || getControlPanel().isShowTaxonomyCode() ) {
6041 pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
6043 else if ( getControlPanel().isShowSeqNames() || getControlPanel().isShowSeqSymbols()
6044 || getControlPanel().isShowGeneNames() ) {
6045 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
6047 PhylogenyMethods.sortNodeDescendents( node, pri );
6048 setNodeInPreorderToNull();
6049 _phylogeny.externalNodesHaveChanged();
6050 _phylogeny.clearHashIdToNodeMap();
6051 _phylogeny.recalculateNumberOfExternalDescendants( true );
6052 resetNodeIdToDistToLeafMap();
6058 final void subTree( final PhylogenyNode node ) {
6059 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
6060 JOptionPane.showMessageDialog( this,
6061 "Cannot get a sub/super tree in unrooted display",
6062 "Attempt to get sub/super tree in unrooted display",
6063 JOptionPane.WARNING_MESSAGE );
6066 if ( node.isExternal() ) {
6067 JOptionPane.showMessageDialog( this,
6068 "Cannot get a subtree of a external node",
6069 "Attempt to get subtree of external node",
6070 JOptionPane.WARNING_MESSAGE );
6073 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
6074 JOptionPane.showMessageDialog( this,
6075 "Cannot get a subtree of the root node",
6076 "Attempt to get subtree of root node",
6077 JOptionPane.WARNING_MESSAGE );
6080 setNodeInPreorderToNull();
6081 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
6082 _sub_phylogenies[ _subtree_index ] = _phylogeny;
6083 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
6085 _phylogeny = TreePanelUtil.subTree( node, _phylogeny );
6086 if ( _phylogeny.getRoot().isCollapse() ) {
6087 _phylogeny.getRoot().setCollapse( false );
6089 _phylogeny.externalNodesHaveChanged();
6090 _phylogeny.clearHashIdToNodeMap();
6091 _phylogeny.recalculateNumberOfExternalDescendants( true );
6092 updateSubSuperTreeButton();
6093 getMainPanel().getControlPanel().search0();
6094 getMainPanel().getControlPanel().search1();
6095 resetRankCollapseRankValue();
6096 resetDepthCollapseDepthValue();
6097 getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
6098 getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay();
6099 getMainPanel().getControlPanel().updateRankCollapseRankDisplay();
6101 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
6104 _main_panel.getControlPanel().showWhole();
6108 final void superTree() {
6109 setNodeInPreorderToNull();
6110 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
6111 for( final PhylogenyNode n : temp_root.getDescendants() ) {
6112 n.setParent( temp_root );
6114 _sub_phylogenies[ _subtree_index ] = null;
6115 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
6116 _phylogeny = _sub_phylogenies[ --_subtree_index ];
6117 _phylogeny.externalNodesHaveChanged();
6118 _phylogeny.clearHashIdToNodeMap();
6119 _phylogeny.recalculateNumberOfExternalDescendants( true );
6120 getMainPanel().getControlPanel().search0();
6121 getMainPanel().getControlPanel().search1();
6122 resetRankCollapseRankValue();
6123 resetDepthCollapseDepthValue();
6124 getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
6125 getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay();
6126 getMainPanel().getControlPanel().updateRankCollapseRankDisplay();
6127 updateSubSuperTreeButton();
6130 final void orderSubtree( final PhylogenyNode node ) {
6131 if ( node.isExternal() ) {
6134 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
6135 if ( getControlPanel().isShowTaxonomyScientificNames() || getControlPanel().isShowTaxonomyCode() ) {
6136 pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
6138 else if ( getControlPanel().isShowSeqNames() || getControlPanel().isShowSeqSymbols()
6139 || getControlPanel().isShowGeneNames() ) {
6140 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
6142 PhylogenyMethods.orderAppearanceX( node, true, pri );
6143 setNodeInPreorderToNull();
6144 getPhylogeny().externalNodesHaveChanged();
6145 getPhylogeny().clearHashIdToNodeMap();
6146 getPhylogeny().recalculateNumberOfExternalDescendants( true );
6147 resetNodeIdToDistToLeafMap();
6149 getControlPanel().displayedPhylogenyMightHaveChanged( true );
6153 final void swap( final PhylogenyNode node ) {
6154 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
6157 if ( node.getNumberOfDescendants() > 2 ) {
6158 JOptionPane.showMessageDialog( this,
6159 "Cannot swap descendants of nodes with more than 2 descendants",
6160 "Cannot swap descendants",
6161 JOptionPane.ERROR_MESSAGE );
6164 if ( !node.isExternal() ) {
6165 node.swapChildren();
6166 setNodeInPreorderToNull();
6167 _phylogeny.externalNodesHaveChanged();
6168 _phylogeny.clearHashIdToNodeMap();
6169 _phylogeny.recalculateNumberOfExternalDescendants( true );
6170 resetNodeIdToDistToLeafMap();
6176 final void taxColor() {
6177 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
6181 TreePanelUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
6182 _control_panel.setColorBranches( true );
6183 if ( _control_panel.getUseVisualStylesCb() != null ) {
6184 _control_panel.getUseVisualStylesCb().setSelected( true );
6191 final void updateOvSettings() {
6192 switch ( getOptions().getOvPlacement() ) {
6194 setOvXPosition( OV_BORDER );
6195 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
6196 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
6199 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
6200 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
6201 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
6204 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
6205 setOvYPosition( OV_BORDER );
6206 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
6209 setOvXPosition( OV_BORDER );
6210 setOvYPosition( OV_BORDER );
6211 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
6216 final void updateOvSizes() {
6217 if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) )
6218 || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) {
6220 float l = getLongestExtNodeInfo();
6221 final float w_ratio = getOvMaxWidth() / getWidth();
6223 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
6224 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
6226 if ( !isNonLinedUpCladogram() ) {
6227 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
6230 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
6232 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
6233 if ( ov_xdist < 0.0 ) {
6236 if ( ydist < 0.0 ) {
6239 setOvXDistance( ov_xdist );
6240 final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() );
6242 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
6243 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
6246 setOvXcorrectionFactor( 0 );
6254 void updateSetOfCollapsedExternalNodes() {
6255 final Phylogeny phy = getPhylogeny();
6256 _collapsed_external_nodeid_set.clear();
6257 if ( phy != null ) {
6258 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
6259 final PhylogenyNode ext_node = it.next();
6260 PhylogenyNode n = ext_node;
6261 while ( !n.isRoot() ) {
6262 if ( n.isCollapse() ) {
6263 _collapsed_external_nodeid_set.add( ext_node.getId() );
6264 ext_node.setCollapse( true );
6273 final void updateSubSuperTreeButton() {
6274 if ( _subtree_index < 1 ) {
6275 getControlPanel().deactivateButtonToReturnToSuperTree();
6278 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
6282 final void updateButtonToUncollapseAll() {
6283 if ( PhylogenyMethods.isHasCollapsedNodes( _phylogeny ) ) {
6284 getControlPanel().activateButtonToUncollapseAll();
6287 getControlPanel().deactivateButtonToUncollapseAll();
6291 final void zoomInDomainStructure() {
6292 if ( _domain_structure_width < 2000 ) {
6293 _domain_structure_width *= 1.2;
6297 final void zoomOutDomainStructure() {
6298 if ( _domain_structure_width > 20 ) {
6299 _domain_structure_width *= 0.8;
6303 private final static void colorizeNodesHelper( final Color c, final PhylogenyNode node ) {
6304 if ( node.getNodeData().getNodeVisualData() == null ) {
6305 node.getNodeData().setNodeVisualData( new NodeVisualData() );
6307 node.getNodeData().getNodeVisualData().setFontColor( new Color( c.getRed(), c.getGreen(), c.getBlue() ) );
6310 final private static void drawString( final String str, final float x, final float y, final Graphics2D g ) {
6311 g.drawString( str, x, y );
6314 final private void drawStringX( final String str, final float x, final float y, final Graphics2D g ) {
6317 if ( getAttributedStringMap() == null /*&& getAttributedStringMap().containsKey(str) */ ) {
6318 final AttributedString as = new AttributedString( str );
6319 //Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);
6320 as.addAttribute( TextAttribute.FONT, g.getFont() );
6321 as.addAttribute( TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 3 );
6322 as.addAttribute( TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 3, 4 );
6323 as.addAttribute( TextAttribute.FOREGROUND, Color.BLUE, 1, 2 );
6324 as.addAttribute( TextAttribute.FOREGROUND, Color.PINK, 3, 5 );
6325 as.addAttribute( TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 2, 4 );
6326 g.drawString( as.getIterator(), x, y );
6329 g.drawString( str, x, y );
6333 private final Map<String, AttributedString> getAttributedStringMap() {
6334 return _attributed_string_map;
6337 private final void setAttributedStringMap( final Map<String, AttributedString> attributed_string_map ) {
6338 _attributed_string_map = attributed_string_map;
6341 final private static boolean plusPressed( final int key_code ) {
6342 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
6343 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON )
6344 || ( key_code == KeyEvent.VK_1 ) );
6347 public void decreaseDepthCollapseLevel() {
6348 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6349 if ( _depth_collapse_level <= 1 ) {
6350 _depth_collapse_level = PhylogenyMethods.calculateMaxDepth( _phylogeny );
6354 --_depth_collapse_level;
6355 PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level );
6360 public void increaseDepthCollapseLevel() {
6361 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6362 final int max = PhylogenyMethods.calculateMaxDepth( _phylogeny );
6363 if ( _depth_collapse_level >= max ) {
6364 _depth_collapse_level = 1;
6367 ++_depth_collapse_level;
6369 PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level );
6373 public void decreaseRankCollapseLevel() {
6374 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6375 final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny );
6376 if ( ranks.length > 1 ) {
6377 if ( _rank_collapse_level <= 0 ) {
6378 _rank_collapse_level = ranks.length - 1;
6382 --_rank_collapse_level;
6383 PhylogenyMethods.collapseToRank( _phylogeny,
6384 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6390 public void increaseRankCollapseLevel() {
6391 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6392 final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny );
6393 if ( ranks.length > 1 ) {
6394 if ( _rank_collapse_level >= ( ranks.length - 1 ) ) {
6395 _rank_collapse_level = 0;
6396 PhylogenyMethods.collapseToRank( _phylogeny,
6397 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6399 else if ( _rank_collapse_level == ( ranks.length - 2 ) ) {
6400 ++_rank_collapse_level;
6404 ++_rank_collapse_level;
6405 PhylogenyMethods.collapseToRank( _phylogeny,
6406 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6412 private final static int mapToAbsoluteRankLevel( final String present_ranks_sorted[],
6413 final int rank_collapse_level ) {
6414 final String rank_str = present_ranks_sorted[ rank_collapse_level ];
6415 if ( !TaxonomyUtil.RANK_TO_INT.containsKey( rank_str ) ) {
6416 throw new IllegalStateException( "unexpected exception: cannot find rank " + rank_str );
6418 return TaxonomyUtil.RANK_TO_INT.get( rank_str );
6421 private final void uncollapseAll() {
6422 final PhylogenyNodeIterator it = new PreorderTreeIterator( _phylogeny );
6423 while ( it.hasNext() ) {
6424 it.next().setCollapse( false );
6428 final int resetDepthCollapseDepthValue() {
6429 return _depth_collapse_level = -1;
6432 final int getDepthCollapseDepthValue() {
6433 return _depth_collapse_level;
6436 final void setDepthCollapseDepthValue( final int depth_collapse_level ) {
6437 _depth_collapse_level = depth_collapse_level;
6440 final int resetRankCollapseRankValue() {
6441 return _rank_collapse_level = -1;
6444 final int getRankCollapseRankValue() {
6445 return _rank_collapse_level;
6448 final void setRankCollapseRankValue( final int rank_collapse_level ) {
6449 _rank_collapse_level = rank_collapse_level;