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.Iterator;
82 import java.util.List;
85 import java.util.SortedSet;
87 import javax.swing.BorderFactory;
88 import javax.swing.JColorChooser;
89 import javax.swing.JDialog;
90 import javax.swing.JMenuItem;
91 import javax.swing.JOptionPane;
92 import javax.swing.JPanel;
93 import javax.swing.JPopupMenu;
94 import javax.swing.JTextArea;
95 import javax.swing.Popup;
96 import javax.swing.PopupFactory;
98 import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON;
99 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
100 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
101 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
102 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
103 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
104 import org.forester.archaeopteryx.phylogeny.data.RenderableMsaSequence;
105 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
106 import org.forester.archaeopteryx.tools.Blast;
107 import org.forester.archaeopteryx.tools.ImageLoader;
108 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
109 import org.forester.io.writers.SequenceWriter;
110 import org.forester.phylogeny.Phylogeny;
111 import org.forester.phylogeny.PhylogenyMethods;
112 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
113 import org.forester.phylogeny.PhylogenyNode;
114 import org.forester.phylogeny.data.Accession;
115 import org.forester.phylogeny.data.Annotation;
116 import org.forester.phylogeny.data.BranchColor;
117 import org.forester.phylogeny.data.Confidence;
118 import org.forester.phylogeny.data.DomainArchitecture;
119 import org.forester.phylogeny.data.Event;
120 import org.forester.phylogeny.data.NodeDataField;
121 import org.forester.phylogeny.data.NodeVisualData;
122 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
123 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
124 import org.forester.phylogeny.data.PhylogenyDataUtil;
125 import org.forester.phylogeny.data.ProteinDomain;
126 import org.forester.phylogeny.data.Sequence;
127 import org.forester.phylogeny.data.SequenceRelation;
128 import org.forester.phylogeny.data.Taxonomy;
129 import org.forester.phylogeny.data.Uri;
130 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
131 import org.forester.phylogeny.iterators.PreorderTreeIterator;
132 import org.forester.util.DescriptiveStatistics;
133 import org.forester.util.ForesterConstants;
134 import org.forester.util.ForesterUtil;
135 import org.forester.util.SequenceAccessionTools;
136 import org.forester.util.TaxonomyUtil;
138 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
140 final private class NodeColorizationActionListener implements ActionListener {
142 List<PhylogenyNode> _additional_nodes = null;
143 JColorChooser _chooser = null;
144 PhylogenyNode _node = null;
146 NodeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
151 NodeColorizationActionListener( final JColorChooser chooser,
152 final PhylogenyNode node,
153 final List<PhylogenyNode> additional_nodes ) {
156 _additional_nodes = additional_nodes;
160 public void actionPerformed( final ActionEvent e ) {
161 final Color c = _chooser.getColor();
163 colorizeNodes( c, _node, _additional_nodes );
168 final private class SubtreeColorizationActionListener implements ActionListener {
170 List<PhylogenyNode> _additional_nodes = null;
171 JColorChooser _chooser = null;
172 PhylogenyNode _node = null;
174 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
179 SubtreeColorizationActionListener( final JColorChooser chooser,
180 final PhylogenyNode node,
181 final List<PhylogenyNode> additional_nodes ) {
184 _additional_nodes = additional_nodes;
188 public void actionPerformed( final ActionEvent e ) {
189 final Color c = _chooser.getColor();
191 colorizeSubtree( c, _node, _additional_nodes );
195 public final static boolean SPECIAL_DOMAIN_COLORING = true;
196 final static Cursor ARROW_CURSOR = Cursor
197 .getPredefinedCursor( Cursor.DEFAULT_CURSOR );
198 final static Cursor CUT_CURSOR = Cursor
199 .getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
200 final static Cursor HAND_CURSOR = Cursor
201 .getPredefinedCursor( Cursor.HAND_CURSOR );
202 final static Cursor MOVE_CURSOR = Cursor
203 .getPredefinedCursor( Cursor.MOVE_CURSOR );
204 final static Cursor WAIT_CURSOR = Cursor
205 .getPredefinedCursor( Cursor.WAIT_CURSOR );
206 final private static double _180_OVER_PI = 180.0 / Math.PI;
207 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI
209 private final static int CONFIDENCE_LEFT_MARGIN = 4;
210 private final static int EURO_D = 10;
211 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
212 private final static NumberFormat FORMATTER_CONFIDENCE;
213 private static final float HALF_PI = ( float ) ( Math.PI
215 private final static int LIMIT_FOR_HQ_RENDERING = 2000;
216 private final static int MAX_NODE_FRAMES = 10;
217 private final static int MAX_SUBTREES = 100;
218 private final static int MIN_ROOT_LENGTH = 3;
219 private final static int MOVE = 20;
220 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
221 private static final float ONEHALF_PI = ( float ) ( 1.5
223 private static final short OV_BORDER = 10;
224 private final static double OVERVIEW_FOUND_NODE_BOX_SIZE = 2;
225 private final static double OVERVIEW_FOUND_NODE_BOX_SIZE_HALF = 1;
226 private static final float PI = ( float ) ( Math.PI );
227 final private static Font POPUP_FONT = new Font( Configuration
228 .getDefaultFontFamilyName(), Font.PLAIN, 12 );
229 private static final float ROUNDED_D = 8;
230 private final static long serialVersionUID = -978349745916505029L;
231 private static final BasicStroke STROKE_0025 = new BasicStroke( 0.025f );
232 private static final BasicStroke STROKE_005 = new BasicStroke( 0.05f );
233 private static final BasicStroke STROKE_01 = new BasicStroke( 0.1f );
234 private static final BasicStroke STROKE_025 = new BasicStroke( 0.25f );
235 private static final BasicStroke STROKE_05 = new BasicStroke( 0.5f );
236 private static final BasicStroke STROKE_075 = new BasicStroke( 0.75f );
237 private static final BasicStroke STROKE_1 = new BasicStroke( 1f );
238 private static final BasicStroke STROKE_2 = new BasicStroke( 2f );
239 private static final BasicStroke STROKE_01_DASHED = new BasicStroke( 0.1f,
240 BasicStroke.CAP_SQUARE,
241 BasicStroke.JOIN_ROUND,
246 private static final BasicStroke STROKE_005_DASHED = new BasicStroke( 0.05f,
247 BasicStroke.CAP_SQUARE,
248 BasicStroke.JOIN_ROUND,
253 private static final BasicStroke STROKE_001_DASHED = new BasicStroke( 0.01f,
254 BasicStroke.CAP_SQUARE,
255 BasicStroke.JOIN_ROUND,
260 private static final double TWO_PI = 2 * Math.PI;
261 private final static int WIGGLE = 3;
262 private static final String SHOW_ONLY_THIS_CONF_TYPE = null; //TODO remove me
263 HashMap<Long, Short> _nodeid_dist_to_leaf = new HashMap<Long, Short>();
264 final private Arc2D _arc = new Arc2D.Double();
265 private AffineTransform _at;
266 private int _clicked_x;
267 private int _circ_max_depth;
268 final private Set<Long> _collapsed_external_nodeid_set = new HashSet<Long>();
269 private JColorChooser _color_chooser = null;
270 private Configuration _configuration = null;
271 private ControlPanel _control_panel = null;
272 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
273 private Set<Long> _current_external_nodes = null;
274 private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
275 private int _current_external_nodes_data_buffer_change_counter = 0;
276 private int _domain_structure_e_value_thr_exp = AptxConstants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
277 private double _domain_structure_width = AptxConstants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
278 private int _dynamic_hiding_factor = 0;
279 private boolean _edited = false;
280 private final Ellipse2D _ellipse = new Ellipse2D.Float();
281 private int _external_node_index = 0;
282 private Set<Long> _found_nodes_0 = null;
283 private Set<Long> _found_nodes_1 = null;
284 private final FontRenderContext _frc = new FontRenderContext( null,
287 private float _furthest_node_x;
288 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
289 private PhylogenyNode _highlight_node = null;
290 private boolean _in_ov = false;
291 private boolean _in_ov_rect = false;
292 private float _last_drag_point_x = 0;
293 private float _last_drag_point_y = 0;
294 private final Line2D _line = new Line2D.Float();
295 private int _longest_ext_node_info = 0;
296 private PhylogenyNode _ext_node_with_longest_txt_info = null;
297 private MainPanel _main_panel = null;
298 private double _max_distance_to_root = -1;
299 private Popup _node_desc_popup;
300 private int _node_frame_index = 0;
301 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
302 private JPopupMenu _node_popup_menu = null;
303 private JMenuItem _node_popup_menu_items[] = null;
304 private PhylogenyNode[] _nodes_in_preorder = null;
305 private Options _options = null;
306 private float _ov_max_height = 0;
307 private float _ov_max_width = 0;
308 private boolean _ov_on = false;
309 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
310 private final Rectangle _ov_virtual_rectangle = new Rectangle();
311 private float _ov_x_correction_factor = 0.0f;
312 private float _ov_x_distance = 0;
313 private int _ov_x_position = 0;
314 private float _ov_y_distance = 0;
315 private int _ov_y_position = 0;
316 private int _ov_y_start = 0;
317 private boolean _partition_tree = false;
318 private float _partition_threshold = 0;
319 private final boolean _phy_has_branch_lengths;
320 private Phylogeny _phylogeny = null;
321 private final Path2D.Float _polygon = new Path2D.Float();
322 private final StringBuffer _popup_buffer = new StringBuffer();
323 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
324 private Sequence _query_sequence = null;
325 private final Rectangle2D _rectangle = new Rectangle2D.Float();
326 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
327 RenderingHints.VALUE_RENDER_DEFAULT );
328 private JTextArea _rollover_popup;
329 private PhylogenyNode _root;
330 private float _root_x;
331 private final StringBuilder _sb = new StringBuilder();
332 private double _scale_distance = 0.0;
333 private String _scale_label = null;
334 private DescriptiveStatistics _statistics_for_vector_data;
335 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
336 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
337 private int _subtree_index = 0;
338 private File _treefile = null;
339 private float _urt_factor = 1;
340 private float _urt_factor_ov = 1;
341 final private HashMap<Long, Double> _urt_nodeid_angle_map = new HashMap<Long, Double>();
342 final private HashMap<Long, Integer> _urt_nodeid_index_map = new HashMap<Long, Integer>();
343 private double _urt_starting_angle = ( float ) ( Math.PI
345 private float _x_correction_factor = 0.0f;
346 private float _x_distance = 0.0f;
347 private float _y_distance = 0.0f;
348 private int _length_of_longest_text;
349 private int _longest_domain;
350 private Map<String, AttributedString> _attributed_string_map = null;
351 private int _depth_collapse_level = -1;
352 private int _rank_collapse_level = -1;
357 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
358 dfs.setDecimalSeparator( '.' );
359 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
360 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
363 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
364 requestFocusInWindow();
365 addKeyListener( new KeyAdapter() {
368 public void keyPressed( final KeyEvent key_event ) {
369 keyPressedCalls( key_event );
370 requestFocusInWindow();
373 addFocusListener( new FocusAdapter() {
376 public void focusGained( final FocusEvent e ) {
377 requestFocusInWindow();
380 if ( ( t == null ) || t.isEmpty() ) {
381 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
383 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
385 _configuration = configuration;
387 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
389 // if ( !_phylogeny.isEmpty() ) {
390 _phylogeny.recalculateNumberOfExternalDescendants( true );
392 setBackground( getTreeColorSet().getBackgroundColor() );
393 final MouseListener mouse_listener = new MouseListener( this );
394 addMouseListener( mouse_listener );
395 addMouseMotionListener( mouse_listener );
396 addMouseWheelListener( this );
397 calculateScaleDistance();
398 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
399 FORMATTER_BRANCH_LENGTH
400 .setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() );
404 final public void actionPerformed( final ActionEvent e ) {
405 boolean done = false;
406 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
407 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
408 // NOTE: index corresponds to the indices of click-to options
409 // in the control panel.
410 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
411 // Set this as the new default click-to action
412 _main_panel.getControlPanel().setClickToAction( index );
413 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
414 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
415 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
420 requestFocusInWindow();
423 public synchronized Hashtable<String, BufferedImage> getImageMap() {
424 return getMainPanel().getImageMap();
427 final public MainPanel getMainPanel() {
432 * Get a pointer to the phylogeny
434 * @return a pointer to the phylogeny
436 public final Phylogeny getPhylogeny() {
440 public final TreeColorSet getTreeColorSet() {
441 return getMainPanel().getTreeColorSet();
445 final public void mouseWheelMoved( final MouseWheelEvent e ) {
446 final int notches = e.getWheelRotation();
447 if ( inOvVirtualRectangle( e ) ) {
448 if ( !isInOvRect() ) {
454 if ( isInOvRect() ) {
455 setInOvRect( false );
459 if ( e.isControlDown() && e.isShiftDown() ) {
461 getTreeFontSet().increaseFontSize();
464 getTreeFontSet().decreaseFontSize( 1, false );
466 getControlPanel().displayedPhylogenyMightHaveChanged( true );
467 resetPreferredSize();
471 else if ( e.isShiftDown() && e.isAltDown() ) {
473 for( int i = 0; i < ( -notches ); ++i ) {
474 getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR, AptxConstants.WHEEL_ZOOM_IN_FACTOR );
475 getControlPanel().displayedPhylogenyMightHaveChanged( false );
479 for( int i = 0; i < notches; ++i ) {
480 getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
481 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
482 getControlPanel().displayedPhylogenyMightHaveChanged( false );
486 else if ( e.isShiftDown() ) {
487 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
488 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
490 for( int i = 0; i < ( -notches ); ++i ) {
491 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
492 getControlPanel().displayedPhylogenyMightHaveChanged( false );
496 for( int i = 0; i < notches; ++i ) {
497 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
498 if ( getStartingAngle() < 0 ) {
499 setStartingAngle( TWO_PI + getStartingAngle() );
501 getControlPanel().displayedPhylogenyMightHaveChanged( false );
507 for( int i = 0; i < ( -notches ); ++i ) {
508 getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
509 getControlPanel().displayedPhylogenyMightHaveChanged( false );
513 for( int i = 0; i < notches; ++i ) {
514 getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
515 getControlPanel().displayedPhylogenyMightHaveChanged( false );
522 for( int i = 0; i < ( -notches ); ++i ) {
523 getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
524 AptxConstants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
525 getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
526 getControlPanel().displayedPhylogenyMightHaveChanged( false );
530 for( int i = 0; i < notches; ++i ) {
531 getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
532 getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
533 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
534 getControlPanel().displayedPhylogenyMightHaveChanged( false );
539 requestFocusInWindow();
544 final public void paintComponent( final Graphics g ) {
545 final Graphics2D g2d = ( Graphics2D ) g;
546 g2d.setRenderingHints( _rendering_hints );
547 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
551 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
552 throws PrinterException {
553 if ( page_index > 0 ) {
554 return ( NO_SUCH_PAGE );
557 final Graphics2D g2d = ( Graphics2D ) g;
558 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
559 // Turn off double buffering !?
560 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
561 // Turn double buffering back on !?
562 return ( PAGE_EXISTS );
566 public final void setEdited( final boolean edited ) {
570 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
571 getMainPanel().setImageMap( image_map );
575 * Set a phylogeny tree.
578 * an instance of a Phylogeny
580 public final void setTree( final Phylogeny t ) {
581 setNodeInPreorderToNull();
585 public final void setWaitCursor() {
586 setCursor( WAIT_CURSOR );
591 public void update( final Graphics g ) {
595 private void abbreviateScientificName( final String sn, final StringBuilder sb ) {
596 final String[] a = sn.split( "\\s+" );
597 sb.append( a[ 0 ].substring( 0, 1 ) );
598 sb.append( a[ 1 ].substring( 0, 2 ) );
599 if ( a.length > 2 ) {
600 for( int i = 2; i < a.length; i++ ) {
607 final private void addEmptyNode( final PhylogenyNode node ) {
608 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
609 errorMessageNoCutCopyPasteInUnrootedDisplay();
612 final String label = createASimpleTextRepresentationOfANode( node );
614 if ( ForesterUtil.isEmpty( label ) ) {
615 msg = "How to add the new, empty node?";
618 msg = "How to add the new, empty node to node" + label + "?";
620 final Object[] options = { "As sibling", "As descendant", "Cancel" };
621 final int r = JOptionPane.showOptionDialog( this,
623 "Addition of Empty New Node",
624 JOptionPane.CLOSED_OPTION,
625 JOptionPane.QUESTION_MESSAGE,
629 boolean add_as_sibling = true;
631 add_as_sibling = false;
636 final Phylogeny phy = new Phylogeny();
637 phy.setRoot( new PhylogenyNode() );
638 phy.setRooted( true );
639 if ( add_as_sibling ) {
640 if ( node.isRoot() ) {
641 JOptionPane.showMessageDialog( this,
642 "Cannot add sibling to root",
643 "Attempt to add sibling to root",
644 JOptionPane.ERROR_MESSAGE );
647 phy.addAsSibling( node );
650 phy.addAsChild( node );
652 setNodeInPreorderToNull();
653 _phylogeny.externalNodesHaveChanged();
654 _phylogeny.clearHashIdToNodeMap();
655 _phylogeny.recalculateNumberOfExternalDescendants( true );
656 resetNodeIdToDistToLeafMap();
661 final private void addToCurrentExternalNodes( final long i ) {
662 if ( _current_external_nodes == null ) {
663 _current_external_nodes = new HashSet<Long>();
665 _current_external_nodes.add( i );
668 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
669 final boolean is_vertical,
671 final boolean to_pdf,
672 final boolean to_graphics_file ) {
673 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
674 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
675 g.setColor( Color.BLACK );
677 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
678 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE )
679 || ( action == NodeClickAction.ADD_NEW_NODE ) ) && ( getCutOrCopiedTree() != null )
680 && ( getCopiedAndPastedNodes() != null ) && !to_pdf && !to_graphics_file
681 && getCopiedAndPastedNodes().contains( node.getId() ) ) {
682 g.setColor( getTreeColorSet().getFoundColor0() );
684 else if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
685 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
688 g.setColor( getTreeColorSet().getBranchColorForPdf() );
691 g.setColor( getTreeColorSet().getBranchColor() );
695 final private void blast( final PhylogenyNode node ) {
696 if ( !isCanBlast( node ) ) {
697 JOptionPane.showMessageDialog( this,
698 "Insufficient information present",
700 JOptionPane.INFORMATION_MESSAGE );
704 final String query = Blast.obtainQueryForBlast( node );
705 System.out.println( "query for BLAST is: " + query );
707 if ( !ForesterUtil.isEmpty( query ) ) {
708 if ( node.getNodeData().isHasSequence() ) {
709 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
710 if ( node.getNodeData().getSequence().getType().toLowerCase()
711 .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
718 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
720 .seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) {
729 if ( SequenceAccessionTools.isProteinDbQuery( query ) ) {
737 Blast.openNcbiBlastWeb( query, type == 'n', this );
739 catch ( final Exception e ) {
746 private final int calcDynamicHidingFactor() {
747 return ( int ) ( 0.5 + ( getFontMetricsForLargeDefaultFont().getHeight() / ( 1.5 * getYdistance() ) ) );
750 final private int calcLengthOfLongestText() {
751 final StringBuilder sb = new StringBuilder();
752 if ( _ext_node_with_longest_txt_info != null ) {
753 nodeDataAsSB( _ext_node_with_longest_txt_info, sb );
754 if ( _ext_node_with_longest_txt_info.getNodeData().isHasTaxonomy() ) {
755 nodeTaxonomyDataAsSB( _ext_node_with_longest_txt_info.getNodeData().getTaxonomy(), sb );
758 return getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
762 * Calculate the length of the distance between the given node and its
768 * @return the distance value
770 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
771 if ( getControlPanel().isDrawPhylogram() ) {
772 if ( node.getDistanceToParent() < 0.0 ) {
775 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
778 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
779 return getXdistance();
781 return getXdistance() * factor;
785 final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
786 Color c = getTreeColorSet().getAnnotationColor();
787 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
788 final StringBuilder sb = new StringBuilder();
789 for( final Annotation a : ann ) {
790 sb.append( !ForesterUtil.isEmpty( a.getRefValue() ) ? a.getRefValue() : a.getDesc() );
792 final String ann_str = sb.toString();
793 if ( !ForesterUtil.isEmpty( ann_str ) ) {
794 c = getControlPanel().getAnnotationColors().get( ann_str );
796 c = AptxUtil.calculateColorFromString( ann_str, false );
797 getControlPanel().getAnnotationColors().put( ann_str, c );
800 c = getTreeColorSet().getAnnotationColor();
807 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
808 if ( getControlPanel().isDrawPhylogram() ) {
809 if ( node.getDistanceToParent() < 0.0 ) {
812 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
815 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
816 return getOvXDistance();
818 return getOvXDistance() * factor;
822 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
823 JOptionPane.showMessageDialog( this,
824 "Cannot launch web browser for " + type_type + " data of this node",
825 "Cannot launch web browser",
826 JOptionPane.WARNING_MESSAGE );
829 private void changeNodeFont( final PhylogenyNode node ) {
830 final FontChooser fc = new FontChooser();
832 if ( ( node.getNodeData().getNodeVisualData() != null ) && !node.getNodeData().getNodeVisualData().isEmpty() ) {
833 f = node.getNodeData().getNodeVisualData().getFont();
839 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
841 List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
842 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
843 nodes = getFoundNodesAsListOfPhylogenyNodes();
845 if ( !nodes.contains( node ) ) {
848 final int count = nodes.size();
849 String title = "Change the font for ";
854 title += ( count + " nodes" );
856 fc.showDialog( this, title );
857 if ( ( fc.getFont() != null ) && !ForesterUtil.isEmpty( fc.getFont().getFamily().trim() ) ) {
858 for( final PhylogenyNode n : nodes ) {
859 if ( n.getNodeData().getNodeVisualData() == null ) {
860 n.getNodeData().setNodeVisualData( new NodeVisualData() );
862 final NodeVisualData vd = n.getNodeData().getNodeVisualData();
863 final Font ff = fc.getFont();
864 vd.setFontName( ff.getFamily().trim() );
865 int s = ff.getSize();
869 if ( s > Byte.MAX_VALUE ) {
873 vd.setFontStyle( ff.getStyle() );
875 if ( _control_panel.getUseVisualStylesCb() != null ) {
876 getControlPanel().getUseVisualStylesCb().setSelected( true );
883 final private void colorizeNodes( final Color c,
884 final PhylogenyNode node,
885 final List<PhylogenyNode> additional_nodes ) {
886 _control_panel.setColorBranches( true );
887 if ( _control_panel.getUseVisualStylesCb() != null ) {
888 _control_panel.getUseVisualStylesCb().setSelected( true );
890 if ( node != null ) {
891 colorizeNodesHelper( c, node );
893 if ( additional_nodes != null ) {
894 for( final PhylogenyNode n : additional_nodes ) {
895 colorizeNodesHelper( c, n );
901 final private void colorizeSubtree( final Color c,
902 final PhylogenyNode node,
903 final List<PhylogenyNode> additional_nodes ) {
904 _control_panel.setColorBranches( true );
905 if ( _control_panel.getUseVisualStylesCb() != null ) {
906 _control_panel.getUseVisualStylesCb().setSelected( true );
908 if ( node != null ) {
909 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
910 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
913 if ( additional_nodes != null ) {
914 for( final PhylogenyNode an : additional_nodes ) {
915 for( final PreorderTreeIterator it = new PreorderTreeIterator( an ); it.hasNext(); ) {
916 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
923 private void colorNodeFont( final PhylogenyNode node ) {
924 _color_chooser.setPreviewPanel( new JPanel() );
925 NodeColorizationActionListener al;
927 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
928 final List<PhylogenyNode> additional_nodes = getFoundNodesAsListOfPhylogenyNodes();
929 al = new NodeColorizationActionListener( _color_chooser, node, additional_nodes );
930 count = additional_nodes.size();
931 if ( !additional_nodes.contains( node ) ) {
936 al = new NodeColorizationActionListener( _color_chooser, node );
938 String title = "Change the (node and font) color for ";
943 title += ( count + " nodes" );
945 final JDialog dialog = JColorChooser.createDialog( this, title, true, _color_chooser, al, null );
947 dialog.setVisible( true );
950 final private void colorSubtree( final PhylogenyNode node ) {
951 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
952 JOptionPane.showMessageDialog( this,
953 "Cannot colorize subtree in unrooted display type",
954 "Attempt to colorize subtree in unrooted display",
955 JOptionPane.WARNING_MESSAGE );
958 _color_chooser.setPreviewPanel( new JPanel() );
959 final SubtreeColorizationActionListener al;
960 final boolean color_found = getOptions().isColorAllFoundNodesWhenColoringSubtree();
961 if ( color_found && ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) ) {
962 final List<PhylogenyNode> additional_nodes = getFoundNodesAsListOfPhylogenyNodes();
963 al = new SubtreeColorizationActionListener( _color_chooser, node, additional_nodes );
966 al = new SubtreeColorizationActionListener( _color_chooser, node );
968 final JDialog dialog = JColorChooser.createDialog( this,
969 "Subtree colorization",
975 dialog.setVisible( true );
978 final private void copySubtree( final PhylogenyNode node ) {
979 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
980 errorMessageNoCutCopyPasteInUnrootedDisplay();
983 setNodeInPreorderToNull();
984 setCutOrCopiedTree( _phylogeny.copy( node ) );
985 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
986 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
987 for( final PhylogenyNode n : nodes ) {
988 node_ids.add( n.getId() );
990 node_ids.add( node.getId() );
991 setCopiedAndPastedNodes( node_ids );
995 final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
996 final String tax = PhylogenyMethods.getSpecies( node );
997 String label = node.getName();
998 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
999 label = label + " " + tax;
1001 else if ( !ForesterUtil.isEmpty( tax ) ) {
1007 if ( !ForesterUtil.isEmpty( label ) ) {
1008 label = " [" + label + "]";
1013 final private void cutSubtree( final PhylogenyNode node ) {
1014 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1015 errorMessageNoCutCopyPasteInUnrootedDisplay();
1018 if ( node.isRoot() ) {
1019 JOptionPane.showMessageDialog( this,
1020 "Cannot cut entire tree as subtree",
1021 "Attempt to cut entire tree",
1022 JOptionPane.ERROR_MESSAGE );
1025 final String label = createASimpleTextRepresentationOfANode( node );
1026 final int r = JOptionPane.showConfirmDialog( null,
1027 "Cut subtree" + label + "?",
1028 "Confirm Cutting of Subtree",
1029 JOptionPane.YES_NO_OPTION );
1030 if ( r != JOptionPane.OK_OPTION ) {
1033 setNodeInPreorderToNull();
1034 setCopiedAndPastedNodes( null );
1035 setCutOrCopiedTree( _phylogeny.copy( node ) );
1036 _phylogeny.deleteSubtree( node, true );
1037 _phylogeny.clearHashIdToNodeMap();
1038 _phylogeny.recalculateNumberOfExternalDescendants( true );
1039 resetNodeIdToDistToLeafMap();
1044 final private void cycleColors() {
1045 getMainPanel().getTreeColorSet().cycleColorScheme();
1046 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
1047 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
1051 final private void decreaseOvSize() {
1052 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
1053 setOvMaxWidth( getOvMaxWidth() - 5 );
1054 setOvMaxHeight( getOvMaxHeight() - 5 );
1056 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1060 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
1061 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1062 errorMessageNoCutCopyPasteInUnrootedDisplay();
1065 if ( node.isRoot() && ( node.getNumberOfDescendants() != 1 ) ) {
1066 JOptionPane.showMessageDialog( this,
1067 "Cannot delete entire tree",
1068 "Attempt to delete entire tree",
1069 JOptionPane.ERROR_MESSAGE );
1072 final String label = createASimpleTextRepresentationOfANode( node );
1073 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
1074 final int r = JOptionPane.showOptionDialog( this,
1075 "Delete" + label + "?",
1076 "Delete Node/Subtree",
1077 JOptionPane.CLOSED_OPTION,
1078 JOptionPane.QUESTION_MESSAGE,
1082 setNodeInPreorderToNull();
1083 boolean node_only = true;
1087 else if ( r != 0 ) {
1091 PhylogenyMethods.removeNode( node, _phylogeny );
1094 _phylogeny.deleteSubtree( node, true );
1096 _phylogeny.externalNodesHaveChanged();
1097 _phylogeny.clearHashIdToNodeMap();
1098 _phylogeny.recalculateNumberOfExternalDescendants( true );
1099 resetNodeIdToDistToLeafMap();
1104 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
1105 makePopupMenus( node );
1106 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
1107 _node_popup_menu.show( this, x, y );
1110 final private void drawArc( final double x,
1113 final double heigth,
1114 final double start_angle,
1115 final double arc_angle,
1116 final Graphics2D g ) {
1117 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
1121 final private void drawLine( final double x1,
1125 final Graphics2D g ) {
1126 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
1129 _line.setLine( x1, y1, x2, y2 );
1133 final private void drawOval( final double x,
1136 final double heigth,
1137 final Graphics2D g ) {
1138 _ellipse.setFrame( x, y, width, heigth );
1142 final private void drawOvalFilled( final double x,
1145 final double heigth,
1146 final Graphics2D g ) {
1147 _ellipse.setFrame( x, y, width, heigth );
1151 final private void drawOvalGradient( final float x,
1156 final Color color_1,
1157 final Color color_2,
1158 final Color color_border ) {
1159 _ellipse.setFrame( x, y, width, heigth );
1160 g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) );
1162 if ( color_border != null ) {
1163 g.setPaint( color_border );
1168 final private void drawRect( final float x,
1172 final Graphics2D g ) {
1173 _rectangle.setFrame( x, y, width, heigth );
1174 g.draw( _rectangle );
1177 final private void drawRectFilled( final double x,
1180 final double heigth,
1181 final Graphics2D g ) {
1182 _rectangle.setFrame( x, y, width, heigth );
1183 g.fill( _rectangle );
1186 final private void drawRectGradient( final float x,
1191 final Color color_1,
1192 final Color color_2,
1193 final Color color_border ) {
1194 _rectangle.setFrame( x, y, width, heigth );
1195 g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) );
1196 g.fill( _rectangle );
1197 if ( color_border != null ) {
1198 g.setPaint( color_border );
1199 g.draw( _rectangle );
1203 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
1204 final List<Uri> us = new ArrayList<Uri>();
1205 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
1206 for( final Uri uri : t.getUris() ) {
1211 for( final Uri uri : us ) {
1212 if ( uri != null ) {
1213 final String uri_str = uri.getValue().toString().toLowerCase();
1214 if ( getImageMap().containsKey( uri_str ) ) {
1215 final BufferedImage bi = getImageMap().get( uri_str );
1216 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
1217 double scaling_factor = 1;
1218 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
1219 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
1220 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
1222 // y = y - ( 0.9 * getYdistance() );
1223 final double hs = bi.getHeight() * scaling_factor;
1224 double ws = ( bi.getWidth() * scaling_factor ) + offset;
1225 final double my_y = y - ( 0.5 * hs );
1226 final int x_w = ( int ) ( x + ws + 0.5 );
1227 final int y_h = ( int ) ( my_y + hs + 0.5 );
1228 if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) {
1230 ( int ) ( x + 0.5 + offset ),
1231 ( int ) ( my_y + 0.5 ),
1252 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
1253 JOptionPane.showMessageDialog( this,
1254 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
1255 "Attempt to cut/copy/paste/add/delete in unrooted display",
1256 JOptionPane.ERROR_MESSAGE );
1259 private final Color getColorForFoundNode( final PhylogenyNode n ) {
1260 if ( isInCurrentExternalNodes( n ) ) {
1261 return getTreeColorSet().getFoundColor0();
1263 else if ( isInFoundNodes0( n ) && !isInFoundNodes1( n ) ) {
1264 return getTreeColorSet().getFoundColor0();
1266 else if ( !isInFoundNodes0( n ) && isInFoundNodes1( n ) ) {
1267 return getTreeColorSet().getFoundColor1();
1270 return getTreeColorSet().getFoundColor0and1();
1274 final private Set<Long> getCopiedAndPastedNodes() {
1275 return getMainPanel().getCopiedAndPastedNodes();
1278 final private Set<Long> getCurrentExternalNodes() {
1279 return _current_external_nodes;
1282 final private Phylogeny getCutOrCopiedTree() {
1283 return getMainPanel().getCutOrCopiedTree();
1286 private FontMetrics getFontMetricsForLargeDefaultFont() {
1287 return getTreeFontSet().getFontMetricsLarge();
1290 final private float getLastDragPointX() {
1291 return _last_drag_point_x;
1294 final private float getLastDragPointY() {
1295 return _last_drag_point_y;
1298 final private double getMaxDistanceToRoot() {
1299 if ( _max_distance_to_root < 0 ) {
1300 recalculateMaxDistanceToRoot();
1302 return _max_distance_to_root;
1305 final private float getOvMaxHeight() {
1306 return _ov_max_height;
1309 final private float getOvMaxWidth() {
1310 return _ov_max_width;
1313 final private float getOvXcorrectionFactor() {
1314 return _ov_x_correction_factor;
1317 final private float getOvXDistance() {
1318 return _ov_x_distance;
1321 final private int getOvXPosition() {
1322 return _ov_x_position;
1325 final private float getOvYDistance() {
1326 return _ov_y_distance;
1329 final private int getOvYPosition() {
1330 return _ov_y_position;
1333 final private int getOvYStart() {
1337 final private List<Accession> getPdbAccs( final PhylogenyNode node ) {
1338 final List<Accession> pdb_ids = new ArrayList<Accession>();
1339 if ( node.getNodeData().isHasSequence() ) {
1340 final Sequence seq = node.getNodeData().getSequence();
1341 if ( !ForesterUtil.isEmpty( seq.getCrossReferences() ) ) {
1342 final SortedSet<Accession> cross_refs = seq.getCrossReferences();
1343 for( final Accession acc : cross_refs ) {
1344 if ( acc.getSource().equalsIgnoreCase( "pdb" ) ) {
1353 final private double getScaleDistance() {
1354 return _scale_distance;
1357 final private String getScaleLabel() {
1358 return _scale_label;
1361 final private TreeFontSet getTreeFontSet() {
1362 return getMainPanel().getTreeFontSet();
1365 final public float getThreshold() {
1366 return _partition_threshold;
1369 final private float getUrtFactor() {
1373 final private float getUrtFactorOv() {
1374 return _urt_factor_ov;
1377 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
1380 showNodeFrame( node );
1395 colorSubtree( node );
1397 case COLOR_NODE_FONT:
1398 colorNodeFont( node );
1400 case CHANGE_NODE_FONT:
1401 changeNodeFont( node );
1419 copySubtree( node );
1422 pasteSubtree( node );
1424 case DELETE_NODE_OR_SUBTREE:
1425 deleteNodeOrSubtree( node );
1428 addEmptyNode( node );
1430 case EDIT_NODE_DATA:
1431 showNodeEditFrame( node );
1436 case SORT_DESCENDENTS:
1437 sortDescendants( node );
1439 case GET_EXT_DESC_DATA:
1440 showExtDescNodeData( node, '_' );
1442 case UNCOLLAPSE_ALL:
1443 uncollapseAll( node );
1446 orderSubtree( node );
1449 throw new IllegalArgumentException( "unknown action: " + action );
1453 final private void increaseCurrentExternalNodesDataBufferChangeCounter() {
1454 _current_external_nodes_data_buffer_change_counter++;
1457 final private void increaseOvSize() {
1458 if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth()
1460 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
1461 .getHeight() / 2 ) ) ) {
1462 setOvMaxWidth( getOvMaxWidth() + 5 );
1463 setOvMaxHeight( getOvMaxHeight() + 5 );
1465 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1469 final private void init() {
1470 _color_chooser = new JColorChooser();
1471 _rollover_popup = new JTextArea();
1472 _rollover_popup.setFont( POPUP_FONT );
1473 resetNodeIdToDistToLeafMap();
1475 setTreeFile( null );
1477 initializeOvSettings();
1478 resetDepthCollapseDepthValue();
1479 resetRankCollapseRankValue();
1480 setStartingAngle( ( TWO_PI * 3 ) / 4 );
1481 final ImageLoader il = new ImageLoader( this );
1482 new Thread( il ).start();
1485 final private void initializeOvSettings() {
1486 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
1487 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
1490 final private boolean inOvVirtualRectangle( final int x, final int y ) {
1491 return ( ( x >= ( getOvVirtualRectangle().x - 1 ) )
1492 && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) )
1493 && ( y >= ( getOvVirtualRectangle().y - 1 ) )
1494 && ( y <= ( getOvVirtualRectangle().y + getOvVirtualRectangle().height + 1 ) ) );
1497 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
1498 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
1501 final private boolean isCanBlast( final PhylogenyNode node ) {
1502 if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) {
1505 return Blast.isContainsQueryForBlast( node );
1508 final private String isCanOpenSeqWeb( final PhylogenyNode node ) {
1509 final Accession a = SequenceAccessionTools.obtainAccessorFromDataFields( node );
1511 return a.getValue();
1516 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
1517 if ( node.getNodeData().isHasTaxonomy() && ( ( !ForesterUtil
1518 .isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
1519 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
1520 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) )
1521 || ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
1522 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) ) ) ) {
1530 final private boolean isInCurrentExternalNodes( final PhylogenyNode node ) {
1531 return ( ( getCurrentExternalNodes() != null ) && getCurrentExternalNodes().contains( node.getId() ) );
1534 private boolean isInFoundNodes( final PhylogenyNode n ) {
1535 return isInFoundNodes0( n ) || isInFoundNodes1( n );
1538 final private boolean isInFoundNodes0( final PhylogenyNode node ) {
1539 return ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) );
1542 final private boolean isInFoundNodes1( final PhylogenyNode node ) {
1543 return ( ( getFoundNodes1() != null ) && getFoundNodes1().contains( node.getId() ) );
1546 final private boolean isInOv() {
1550 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
1552 if ( getControlPanel().isShowTaxonomyImages() ) {
1553 y_dist = 40 + ( int ) getYdistance();
1555 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) )
1556 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) )
1557 || ( ( node.getParent() != null ) && ( node.getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
1560 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
1561 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) )
1562 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) )
1563 || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) )
1564 || ( node.getXcoord() > ( getVisibleRect().getMaxX() + 20 ) ) );
1567 final private boolean isNonLinedUpCladogram() {
1568 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
1571 final private void keyPressedCalls( final KeyEvent e ) {
1572 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
1573 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
1574 if ( !isInOvRect() ) {
1575 setInOvRect( true );
1578 else if ( isInOvRect() ) {
1579 setInOvRect( false );
1582 if ( e.isAltDown() ) {
1583 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1584 || ( e.getKeyCode() == KeyEvent.VK_C ) || ( e.getKeyCode() == KeyEvent.VK_BACK_SPACE ) ) {
1585 getControlPanel().showWhole();
1587 else if ( e.isShiftDown()
1588 && ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) ) {
1589 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
1590 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1592 else if ( e.isShiftDown() && plusPressed( e.getKeyCode() ) ) {
1593 getMainPanel().getTreeFontSet().increaseFontSize();
1594 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1596 else if ( e.getKeyCode() == KeyEvent.VK_O ) {
1597 getControlPanel().orderPressed( this );
1599 else if ( e.getKeyCode() == KeyEvent.VK_R ) {
1600 getControlPanel().returnedToSuperTreePressed();
1602 else if ( e.getKeyCode() == KeyEvent.VK_U ) {
1603 getControlPanel().uncollapseAll( this );
1604 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1606 else if ( e.getKeyCode() == KeyEvent.VK_UP ) {
1607 getMainPanel().getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1608 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1610 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1611 getMainPanel().getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
1612 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1614 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1615 getMainPanel().getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
1616 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1617 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1619 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1620 getMainPanel().getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
1621 AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1622 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1624 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1625 getMainPanel().getControlPanel().zoomOutY( AptxConstants.WHEEL_ZOOM_OUT_FACTOR );
1626 getMainPanel().getControlPanel().zoomOutX( AptxConstants.WHEEL_ZOOM_OUT_FACTOR,
1627 AptxConstants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1628 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1630 else if ( plusPressed( e.getKeyCode() ) ) {
1631 getMainPanel().getControlPanel().zoomInX( AptxConstants.WHEEL_ZOOM_IN_FACTOR,
1632 AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1633 getMainPanel().getControlPanel().zoomInY( AptxConstants.WHEEL_ZOOM_IN_FACTOR );
1634 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1638 if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
1639 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
1643 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1646 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1650 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1654 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1655 scroll_position.x = scroll_position.x + dx;
1656 scroll_position.y = scroll_position.y + dy;
1657 if ( scroll_position.x <= 0 ) {
1658 scroll_position.x = 0;
1661 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1662 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1663 if ( scroll_position.x >= max_x ) {
1664 scroll_position.x = max_x;
1667 if ( scroll_position.y <= 0 ) {
1668 scroll_position.y = 0;
1671 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1672 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1673 if ( scroll_position.y >= max_y ) {
1674 scroll_position.y = max_y;
1678 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1680 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
1681 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1682 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1683 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1684 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1687 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
1688 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1689 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1690 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1691 if ( getStartingAngle() < 0 ) {
1692 setStartingAngle( TWO_PI + getStartingAngle() );
1694 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1697 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
1698 boolean selected = false;
1699 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
1700 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1704 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1706 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
1709 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
1710 switchDisplaygetPhylogenyGraphicsType();
1713 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
1717 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
1718 MainFrame.cycleOverview( getOptions(), this );
1721 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
1724 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
1728 if ( e.getKeyCode() == KeyEvent.VK_HOME || e.getKeyCode() == KeyEvent.VK_ESCAPE ) {
1729 getControlPanel().showWhole();
1731 else if ( e.getKeyCode() == KeyEvent.VK_PAGE_UP ) {
1732 getMainPanel().getTreeFontSet().increaseFontSize();
1733 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1735 else if ( e.getKeyCode() == KeyEvent.VK_PAGE_DOWN ) {
1736 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
1737 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1742 final private void makePopupMenus( final PhylogenyNode node ) {
1743 _node_popup_menu = new JPopupMenu();
1744 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
1745 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
1746 for( int i = 0; i < clickto_names.size(); i++ ) {
1747 final String title = clickto_names.get( i );
1748 _node_popup_menu_items[ i ] = new JMenuItem( title );
1749 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
1750 final String id = isCanOpenSeqWeb( node );
1751 if ( !ForesterUtil.isEmpty( id ) ) {
1752 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + id + "]" );
1753 _node_popup_menu_items[ i ].setEnabled( true );
1756 _node_popup_menu_items[ i ].setEnabled( false );
1759 else if ( title.equals( Configuration.clickto_options[ Configuration.open_pdb_web ][ 0 ] ) ) {
1760 final List<Accession> accs = getPdbAccs( node );
1761 _node_popup_menu_items[ i ] = new JMenuItem( title );
1762 if ( !ForesterUtil.isEmpty( accs ) ) {
1763 if ( accs.size() == 1 ) {
1764 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1765 + TreePanelUtil.pdbAccToString( accs, 0 ) + "]" );
1766 _node_popup_menu_items[ i ].setEnabled( true );
1768 else if ( accs.size() == 2 ) {
1769 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1770 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1771 + TreePanelUtil.pdbAccToString( accs, 1 ) + "]" );
1772 _node_popup_menu_items[ i ].setEnabled( true );
1774 else if ( accs.size() == 3 ) {
1775 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1776 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1777 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
1778 + TreePanelUtil.pdbAccToString( accs, 2 ) + "]" );
1779 _node_popup_menu_items[ i ].setEnabled( true );
1782 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
1783 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
1784 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
1785 + TreePanelUtil.pdbAccToString( accs, 2 ) + ", + " + ( accs.size() - 3 ) + " more]" );
1786 _node_popup_menu_items[ i ].setEnabled( true );
1790 _node_popup_menu_items[ i ].setEnabled( false );
1793 else if ( title.startsWith( Configuration.clickto_options[ Configuration.get_ext_desc_data ][ 0 ] ) ) {
1794 _node_popup_menu_items[ i ]
1795 .setText( Configuration.clickto_options[ Configuration.get_ext_desc_data ][ 0 ] + ": "
1796 + getOptions().getExtDescNodeDataToReturn().toString() );
1798 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
1799 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
1801 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
1802 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
1804 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
1805 if ( !getOptions().isEditable() ) {
1808 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
1810 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
1811 if ( !getOptions().isEditable() ) {
1814 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
1816 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
1817 if ( !getOptions().isEditable() ) {
1820 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
1822 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
1823 if ( !getOptions().isEditable() ) {
1826 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
1828 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
1829 if ( !getOptions().isEditable() ) {
1833 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
1834 if ( !getOptions().isEditable() ) {
1838 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
1839 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
1841 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
1842 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
1844 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
1845 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
1847 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
1848 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
1850 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
1851 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
1853 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
1854 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
1856 else if ( title.equals( Configuration.clickto_options[ Configuration.uncollapse_all ][ 0 ] ) ) {
1857 _node_popup_menu_items[ i ].setEnabled( isCanUncollapseAll( node ) );
1859 _node_popup_menu_items[ i ].addActionListener( this );
1860 _node_popup_menu.add( _node_popup_menu_items[ i ] );
1864 private final void nodeDataAsSB( final PhylogenyNode node, final StringBuilder sb ) {
1865 if ( node != null ) {
1866 if ( getControlPanel().isShowNodeNames() && ( !ForesterUtil.isEmpty( node.getName() ) ) ) {
1867 if ( sb.length() > 0 ) {
1870 sb.append( node.getName() );
1872 if ( node.getNodeData().isHasSequence() ) {
1873 if ( getControlPanel().isShowSeqSymbols()
1874 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
1875 if ( sb.length() > 0 ) {
1878 sb.append( node.getNodeData().getSequence().getSymbol() );
1880 if ( getControlPanel().isShowGeneNames()
1881 && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) {
1882 if ( sb.length() > 0 ) {
1885 sb.append( node.getNodeData().getSequence().getGeneName() );
1887 if ( getControlPanel().isShowSeqNames()
1888 && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
1889 if ( sb.length() > 0 ) {
1892 sb.append( node.getNodeData().getSequence().getName() );
1894 if ( getControlPanel().isShowSequenceAcc()
1895 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
1896 if ( sb.length() > 0 ) {
1899 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
1900 sb.append( node.getNodeData().getSequence().getAccession().getSource() );
1903 sb.append( node.getNodeData().getSequence().getAccession().getValue() );
1906 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
1907 if ( sb.length() > 0 ) {
1910 sb.append( propertiesToString( node ) );
1915 private final void nodeTaxonomyDataAsSB( final Taxonomy taxonomy, final StringBuilder sb ) {
1916 if ( _control_panel.isShowTaxonomyRank() && !ForesterUtil.isEmpty( taxonomy.getRank() ) ) {
1918 sb.append( taxonomy.getRank() );
1921 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
1922 sb.append( taxonomy.getTaxonomyCode() );
1925 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
1926 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
1927 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1928 if ( getOptions().isAbbreviateScientificTaxonNames()
1929 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1930 abbreviateScientificName( taxonomy.getScientificName(), sb );
1933 sb.append( taxonomy.getScientificName() );
1936 sb.append( taxonomy.getCommonName() );
1939 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
1940 if ( getOptions().isAbbreviateScientificTaxonNames()
1941 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1942 abbreviateScientificName( taxonomy.getScientificName(), sb );
1945 sb.append( taxonomy.getScientificName() );
1949 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1950 sb.append( taxonomy.getCommonName() );
1954 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
1955 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
1956 if ( getOptions().isAbbreviateScientificTaxonNames()
1957 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
1958 abbreviateScientificName( taxonomy.getScientificName(), sb );
1961 sb.append( taxonomy.getScientificName() );
1966 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
1967 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
1968 sb.append( taxonomy.getCommonName() );
1974 private final String obtainTitleForExtDescNodeData() {
1975 return getOptions().getExtDescNodeDataToReturn().toString();
1978 final private void openPdbWeb( final PhylogenyNode node ) {
1979 final List<Accession> pdb_ids = getPdbAccs( node );
1980 if ( ForesterUtil.isEmpty( pdb_ids ) ) {
1981 cannotOpenBrowserWarningMessage( "PDB" );
1984 final List<String> uri_strs = TreePanelUtil.createUrisForPdbWeb( node, pdb_ids, getConfiguration(), this );
1985 if ( !ForesterUtil.isEmpty( uri_strs ) ) {
1986 for( final String uri_str : uri_strs ) {
1988 AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_seq" );
1990 catch ( final IOException e ) {
1991 AptxUtil.showErrorMessage( this, e.toString() );
1992 e.printStackTrace();
1994 catch ( final URISyntaxException e ) {
1995 AptxUtil.showErrorMessage( this, e.toString() );
1996 e.printStackTrace();
2001 cannotOpenBrowserWarningMessage( "PDB" );
2005 final private void openSeqWeb( final PhylogenyNode node ) {
2006 if ( ForesterUtil.isEmpty( isCanOpenSeqWeb( node ) ) ) {
2007 cannotOpenBrowserWarningMessage( "sequence" );
2010 final String uri_str = TreePanelUtil.createUriForSeqWeb( node, getConfiguration(), this );
2011 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2013 AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_seq" );
2015 catch ( final IOException e ) {
2016 AptxUtil.showErrorMessage( this, e.toString() );
2017 e.printStackTrace();
2019 catch ( final URISyntaxException e ) {
2020 AptxUtil.showErrorMessage( this, e.toString() );
2021 e.printStackTrace();
2025 cannotOpenBrowserWarningMessage( "sequence" );
2029 final private void openTaxWeb( final PhylogenyNode node ) {
2030 if ( !isCanOpenTaxWeb( node ) ) {
2031 cannotOpenBrowserWarningMessage( "taxonomic" );
2034 String uri_str = null;
2035 final Taxonomy tax = node.getNodeData().getTaxonomy();
2036 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2037 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
2039 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
2041 catch ( final URISyntaxException e ) {
2042 AptxUtil.showErrorMessage( this, e.toString() );
2044 e.printStackTrace();
2047 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2048 && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
2049 && ( tax.getIdentifier().getProvider().equalsIgnoreCase( "ncbi" )
2050 || tax.getIdentifier().getProvider().equalsIgnoreCase( "uniprot" ) ) ) {
2052 uri_str = "http://www.uniprot.org/taxonomy/"
2053 + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF_8 );
2055 catch ( final UnsupportedEncodingException e ) {
2056 AptxUtil.showErrorMessage( this, e.toString() );
2057 e.printStackTrace();
2060 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
2062 uri_str = "http://www.uniprot.org/taxonomy/?query="
2063 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF_8 );
2065 catch ( final UnsupportedEncodingException e ) {
2066 AptxUtil.showErrorMessage( this, e.toString() );
2067 e.printStackTrace();
2070 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
2072 uri_str = "http://www.uniprot.org/taxonomy/?query="
2073 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF_8 );
2075 catch ( final UnsupportedEncodingException e ) {
2076 AptxUtil.showErrorMessage( this, e.toString() );
2077 e.printStackTrace();
2080 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
2082 uri_str = "http://www.uniprot.org/taxonomy/?query="
2083 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF_8 );
2085 catch ( final UnsupportedEncodingException e ) {
2086 AptxUtil.showErrorMessage( this, e.toString() );
2087 e.printStackTrace();
2090 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2092 AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_tax" );
2094 catch ( final IOException e ) {
2095 AptxUtil.showErrorMessage( this, e.toString() );
2096 e.printStackTrace();
2098 catch ( final URISyntaxException e ) {
2099 AptxUtil.showErrorMessage( this, e.toString() );
2100 e.printStackTrace();
2104 cannotOpenBrowserWarningMessage( "taxonomic" );
2108 final private void paintBranchLength( final Graphics2D g,
2109 final PhylogenyNode node,
2110 final boolean to_pdf,
2111 final boolean to_graphics_file ) {
2112 g.setFont( getTreeFontSet().getSmallFont() );
2113 if ( to_pdf || ( to_graphics_file && getOptions().isPrintBlackAndWhite() ) ) {
2114 g.setColor( Color.BLACK );
2117 g.setColor( getTreeColorSet().getBranchLengthColor() );
2119 if ( !node.isRoot() ) {
2120 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2121 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2122 node.getParent().getXcoord() + EURO_D,
2123 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2126 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2127 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2128 node.getParent().getXcoord() + ROUNDED_D,
2129 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2133 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2134 node.getParent().getXcoord() + 3,
2135 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2140 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ),
2142 node.getYcoord() - getTreeFontSet().getSmallMaxDescent(),
2147 final private void paintBranchLite( final Graphics2D g,
2152 final PhylogenyNode node ) {
2153 g.setColor( getTreeColorSet().getOvColor() );
2154 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2155 drawLine( x1, y1, x2, y2, g );
2157 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2158 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2159 ( g ).draw( _quad_curve );
2161 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2162 final float dx = x2 - x1;
2163 final float dy = y2 - y1;
2164 _cubic_curve.setCurve( x1,
2172 ( g ).draw( _cubic_curve );
2175 final float x2a = x2;
2176 final float x1a = x1;
2177 // draw the vertical line
2178 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
2179 drawLine( x1, y1, x1, y2, g );
2181 // draw the horizontal line
2182 drawLine( x1a, y2, x2a, y2, g );
2187 * Paint a branch which consists of a vertical and a horizontal bar
2188 * @param is_ind_found_nodes
2190 final private void paintBranchRectangular( final Graphics2D g,
2195 final PhylogenyNode node,
2196 final boolean to_pdf,
2197 final boolean to_graphics_file ) {
2198 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
2199 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2200 drawLine( x1, y1, x2, y2, g );
2202 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2203 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2204 g.draw( _quad_curve );
2206 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2207 final float dx = x2 - x1;
2208 final float dy = y2 - y1;
2209 _cubic_curve.setCurve( x1,
2217 g.draw( _cubic_curve );
2220 final float x2a = x2;
2221 final float x1a = x1;
2223 if ( node.isFirstChildNode() || node.isLastChildNode()
2224 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2225 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2226 if ( !to_graphics_file && !to_pdf
2227 && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) )
2228 && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) )
2229 || ( ( y2 > ( getVisibleRect().getMaxY() + 20 ) )
2230 && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) {
2234 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2235 float x2c = x1 + EURO_D;
2239 drawLine( x1, y1, x2c, y2, g );
2241 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2243 y2_r = y2 - ROUNDED_D;
2247 drawLine( x1, y1, x1, y2_r, g );
2250 y2_r = y2 + ROUNDED_D;
2254 drawLine( x1, y1, x1, y2_r, g );
2258 drawLine( x1, y1, x1, y2, g );
2262 // draw the horizontal line
2263 if ( !to_graphics_file && !to_pdf && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) )
2264 || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) {
2268 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
2269 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2270 x1_r = x1a + ROUNDED_D;
2272 drawLine( x1_r, y2, x2a, y2, g );
2275 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2276 final float x1c = x1a + EURO_D;
2278 drawLine( x1c, y2, x2a, y2, g );
2282 drawLine( x1a, y2, x2a, y2, g );
2286 final double w = PhylogenyMethods.getBranchWidthValue( node );
2287 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2288 x1_r = x1a + ROUNDED_D;
2290 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
2293 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2294 final float x1c = x1a + EURO_D;
2296 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
2300 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
2303 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2308 final double diff = y2 - y2_r;
2309 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
2312 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
2317 if ( node.isExternal() ) {
2318 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file );
2322 final private double paintCirculars( final PhylogenyNode n,
2323 final Phylogeny phy,
2324 final float center_x,
2325 final float center_y,
2326 final double radius,
2327 final boolean radial_labels,
2329 final boolean to_pdf,
2330 final boolean to_graphics_file ) {
2331 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
2332 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
2333 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
2335 return _urt_nodeid_angle_map.get( n.getId() );
2338 final List<PhylogenyNode> descs = n.getDescendants();
2340 for( final PhylogenyNode desc : descs ) {
2341 sum += paintCirculars( desc,
2352 if ( !n.isRoot() ) {
2353 r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
2355 final double theta = sum / descs.size();
2356 n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) );
2357 n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) );
2358 _urt_nodeid_angle_map.put( n.getId(), theta );
2359 for( final PhylogenyNode desc : descs ) {
2360 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
2366 final private void paintCircularsLite( final PhylogenyNode n,
2367 final Phylogeny phy,
2371 final Graphics2D g ) {
2372 if ( n.isExternal() ) {
2376 final List<PhylogenyNode> descs = n.getDescendants();
2377 for( final PhylogenyNode desc : descs ) {
2378 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
2381 if ( !n.isRoot() ) {
2382 r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
2384 final double theta = _urt_nodeid_angle_map.get( n.getId() );
2385 n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) );
2386 n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) );
2387 for( final PhylogenyNode desc : descs ) {
2388 paintBranchCircularLite( n, desc, g );
2393 final private void paintCollapsedNode( final Graphics2D g,
2394 final PhylogenyNode node,
2395 final boolean to_graphics_file,
2396 final boolean to_pdf,
2397 final boolean is_in_found_nodes ) {
2403 if ( _found_nodes_0 != null || _found_nodes_1 != null ) {
2404 res = calcFoundNodesInSubtree( node );
2406 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2411 // else if ( is_in_found_nodes ) {
2412 // c = getColorForFoundNode( node );
2414 // else if ( getControlPanel().isColorAccordingToSequence() ) {
2415 // c = getSequenceBasedColor( node );
2417 // else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2418 // c = getTaxonomyBasedColor( node );
2420 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
2421 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2422 c = PhylogenyMethods.getBranchColorValue( node );
2424 else if ( to_pdf ) {
2425 g.setColor( getTreeColorSet().getBranchColorForPdf() );
2428 c = getTreeColorSet().getCollapseFillColor();
2430 double d = node.getAllExternalDescendants().size();
2433 if ( getControlPanel().isDrawPhylogram() ) {
2435 d = 0.75 * _y_distance;
2438 d = 0.25 * Math.log10( d ) * _y_distance;
2440 final float half_box_size = 0.5f * getOptions().getDefaultNodeShapeSize();
2441 if ( d < half_box_size ) {
2445 final float xx = node.getXcoord() - ( getOptions().getDefaultNodeShapeSize() );
2446 xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1;
2447 _polygon.moveTo( xxx, node.getYcoord() + 0.5 );
2448 _polygon.lineTo( xxx, node.getYcoord() - 0.5 );
2449 s = _options.isCollapsedWithAverageHeigh()
2450 ? PhylogenyMethods.calculateAverageTreeHeight( node ) * _x_correction_factor : 1;
2451 _polygon.lineTo( node.getXcoord() + s, node.getYcoord() - d );
2452 _polygon.lineTo( node.getXcoord() + s, node.getYcoord() + d );
2453 _polygon.closePath();
2460 d = ( Math.log10( d ) * _y_distance ) / 2.5;
2462 final int box_size = getOptions().getDefaultNodeShapeSize() + 1;
2463 if ( d < box_size ) {
2466 final float xx = node.getXcoord() - ( 2 * box_size );
2467 xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1;
2469 _polygon.moveTo( xxx, node.getYcoord() );
2470 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d );
2471 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d );
2472 _polygon.closePath();
2474 if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) {
2478 else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.NONE ) {
2479 g.setColor( getBackground() );
2484 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2485 g.setPaint( new GradientPaint( xxx,
2489 ( float ) ( node.getYcoord() - d ),
2496 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes, s );
2499 final private void paintConfidenceValues( final Graphics2D g,
2500 final PhylogenyNode node,
2501 final boolean to_pdf,
2502 final boolean to_graphics_file ) {
2503 final List<Confidence> confidences = node.getBranchData().getConfidences();
2504 boolean not_first = false;
2505 Collections.sort( confidences );
2506 final StringBuilder sb = new StringBuilder();
2507 for( final Confidence confidence : confidences ) {
2508 if ( ForesterUtil.isEmpty( SHOW_ONLY_THIS_CONF_TYPE ) || ( !ForesterUtil.isEmpty( confidence.getType() )
2509 && confidence.getType().equalsIgnoreCase( SHOW_ONLY_THIS_CONF_TYPE ) ) ) {
2510 final double value = confidence.getValue();
2511 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2512 if ( value < getOptions().getMinConfidenceValue() ) {
2521 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil
2522 .round( value, getOptions().getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2523 if ( getOptions().isShowConfidenceStddev() ) {
2524 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2526 sb.append( FORMATTER_CONFIDENCE
2527 .format( ForesterUtil.round( confidence.getStandardDeviation(),
2529 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2536 if ( sb.length() > 0 ) {
2537 final float parent_x = node.getParent().getXcoord();
2538 float x = node.getXcoord();
2539 g.setFont( getTreeFontSet().getSmallFont() );
2540 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2543 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2546 if ( to_pdf || ( to_graphics_file && getOptions().isPrintBlackAndWhite() ) ) {
2547 g.setColor( Color.BLACK );
2550 g.setColor( getTreeColorSet().getConfidenceColor() );
2552 final String conf_str = sb.toString();
2553 TreePanel.drawString( conf_str,
2554 parent_x + ( ( x - parent_x
2555 - getTreeFontSet().getFontMetricsSmall().stringWidth( conf_str ) ) / 2 ),
2556 ( node.getYcoord() + getTreeFontSet().getSmallMaxAscent() ) - 1,
2561 final private void paintGainedAndLostCharacters( final Graphics2D g,
2562 final PhylogenyNode node,
2563 final String gained,
2564 final String lost ) {
2565 if ( node.getParent() != null ) {
2566 final float parent_x = node.getParent().getXcoord();
2567 final float x = node.getXcoord();
2568 g.setFont( getTreeFontSet().getLargeFont() );
2569 g.setColor( getTreeColorSet().getGainedCharactersColor() );
2570 if ( AptxConstants.SPECIAL_CUSTOM ) {
2571 g.setColor( Color.BLUE );
2573 TreePanel.drawString( gained,
2574 parent_x + ( ( x - parent_x
2575 - getFontMetricsForLargeDefaultFont().stringWidth( gained ) ) / 2 ),
2576 ( node.getYcoord() - getFontMetricsForLargeDefaultFont().getMaxDescent() ),
2578 g.setColor( getTreeColorSet().getLostCharactersColor() );
2581 parent_x + ( ( x - parent_x - getFontMetricsForLargeDefaultFont().stringWidth( lost ) )
2583 ( node.getYcoord() + getFontMetricsForLargeDefaultFont().getMaxAscent() ),
2588 private void paintMolecularSequences( final Graphics2D g, final PhylogenyNode node, final boolean to_pdf ) {
2589 final RenderableMsaSequence rs = RenderableMsaSequence
2590 .createInstance( node.getNodeData().getSequence().getMolecularSequence(),
2591 node.getNodeData().getSequence().getType(),
2592 getConfiguration() );
2594 final int default_height = 8;
2595 final float y = getYdistance();
2596 final int h = ( y / 2 ) < default_height ? ForesterUtil.roundToInt( y * 2 ) : default_height;
2597 rs.setRenderingHeight( h > 1 ? h : 1 );
2598 if ( getControlPanel().isDrawPhylogram() ) {
2599 rs.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() ) + _length_of_longest_text ),
2600 node.getYcoord() - ( h / 2.0f ),
2606 rs.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text,
2607 node.getYcoord() - ( h / 2.0f ),
2616 * Draw a box at the indicated node.
2623 final private void paintNodeBox( final float x,
2625 final PhylogenyNode node,
2627 final boolean to_pdf,
2628 final boolean to_graphics_file ) {
2629 if ( node.isCollapse() ) {
2632 // if this node should be highlighted, do so
2633 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
2634 g.setColor( getTreeColorSet().getFoundColor0() );
2635 drawOval( x - 8, y - 8, 16, 16, g );
2636 drawOval( x - 9, y - 8, 17, 17, g );
2637 drawOval( x - 9, y - 9, 18, 18, g );
2639 if ( ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) )
2640 || ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() )
2641 || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() )
2642 || ( getOptions().isShowDefaultNodeShapesForMarkedNodes()
2643 && ( node.getNodeData().getNodeVisualData() != null )
2644 && ( !node.getNodeData().getNodeVisualData().isEmpty() ) )
2645 || ( getControlPanel().isUseVisualStyles() && ( ( node.getNodeData().getNodeVisualData() != null )
2646 && ( ( node.getNodeData().getNodeVisualData().getNodeColor() != null )
2647 || ( node.getNodeData().getNodeVisualData().getSize() != NodeVisualData.DEFAULT_SIZE )
2648 || ( node.getNodeData().getNodeVisualData().getFillType() != NodeFill.DEFAULT )
2649 || ( node.getNodeData().getNodeVisualData().getShape() != NodeShape.DEFAULT ) ) ) )
2650 || ( getControlPanel().isEvents() && node.isHasAssignedEvent()
2651 && ( node.getNodeData().getEvent().isDuplication()
2652 || node.getNodeData().getEvent().isSpeciation()
2653 || node.getNodeData().getEvent().isSpeciationOrDuplication() ) ) ) {
2654 NodeVisualData vis = null;
2655 if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
2656 && ( !node.getNodeData().getNodeVisualData().isEmpty() ) ) {
2657 vis = node.getNodeData().getNodeVisualData();
2659 float box_size = getOptions().getDefaultNodeShapeSize();
2660 if ( ( vis != null ) && ( vis.getSize() != NodeVisualData.DEFAULT_SIZE ) ) {
2661 box_size = vis.getSize();
2663 final float half_box_size = box_size / 2.0f;
2664 Color outline_color = null;
2665 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2666 outline_color = Color.BLACK;
2668 else if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
2669 outline_color = getColorForFoundNode( node );
2671 else if ( vis != null ) {
2672 if ( vis.getNodeColor() != null ) {
2673 outline_color = vis.getNodeColor();
2675 else if ( vis.getFontColor() != null ) {
2676 outline_color = vis.getFontColor();
2679 else if ( getControlPanel().isEvents() && TreePanelUtil.isHasAssignedEvent( node ) ) {
2680 final Event event = node.getNodeData().getEvent();
2681 if ( event.isDuplication() ) {
2682 outline_color = getTreeColorSet().getDuplicationBoxColor();
2684 else if ( event.isSpeciation() ) {
2685 outline_color = getTreeColorSet().getSpecBoxColor();
2687 else if ( event.isSpeciationOrDuplication() ) {
2688 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
2691 if ( outline_color == null ) {
2692 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
2693 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
2694 outline_color = getTreeColorSet().getBranchColorForPdf();
2697 NodeShape shape = null;
2698 if ( vis != null ) {
2699 if ( vis.getShape() == NodeShape.CIRCLE ) {
2700 shape = NodeShape.CIRCLE;
2702 else if ( vis.getShape() == NodeShape.RECTANGLE ) {
2703 shape = NodeShape.RECTANGLE;
2706 if ( shape == null ) {
2707 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
2708 shape = NodeShape.CIRCLE;
2710 else if ( getOptions().getDefaultNodeShape() == NodeShape.RECTANGLE ) {
2711 shape = NodeShape.RECTANGLE;
2714 NodeFill fill = null;
2715 if ( vis != null ) {
2716 if ( vis.getFillType() == NodeFill.SOLID ) {
2717 fill = NodeFill.SOLID;
2719 else if ( vis.getFillType() == NodeFill.NONE ) {
2720 fill = NodeFill.NONE;
2722 else if ( vis.getFillType() == NodeFill.GRADIENT ) {
2723 fill = NodeFill.GRADIENT;
2726 if ( fill == null ) {
2727 if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) {
2728 fill = NodeFill.SOLID;
2730 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
2731 fill = NodeFill.NONE;
2733 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2734 fill = NodeFill.GRADIENT;
2737 Color vis_fill_color = null;
2738 if ( ( vis != null ) && ( vis.getNodeColor() != null ) ) {
2739 vis_fill_color = vis.getNodeColor();
2741 if ( shape == NodeShape.CIRCLE ) {
2742 if ( fill == NodeFill.GRADIENT ) {
2743 drawOvalGradient( x - half_box_size,
2748 to_pdf ? Color.WHITE : outline_color,
2749 to_pdf ? outline_color : getBackground(),
2752 else if ( fill == NodeFill.NONE ) {
2753 Color background = getBackground();
2755 background = Color.WHITE;
2757 drawOvalGradient( x - half_box_size,
2766 else if ( fill == NodeVisualData.NodeFill.SOLID ) {
2767 if ( vis_fill_color != null ) {
2768 g.setColor( vis_fill_color );
2771 g.setColor( outline_color );
2773 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2776 else if ( shape == NodeVisualData.NodeShape.RECTANGLE ) {
2777 if ( fill == NodeVisualData.NodeFill.GRADIENT ) {
2778 drawRectGradient( x - half_box_size,
2783 to_pdf ? Color.WHITE : outline_color,
2784 to_pdf ? outline_color : getBackground(),
2787 else if ( fill == NodeVisualData.NodeFill.NONE ) {
2788 Color background = getBackground();
2790 background = Color.WHITE;
2792 drawRectGradient( x - half_box_size,
2801 else if ( fill == NodeVisualData.NodeFill.SOLID ) {
2802 if ( vis_fill_color != null ) {
2803 g.setColor( vis_fill_color );
2806 g.setColor( outline_color );
2808 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2814 final private int paintNodeData( final Graphics2D g,
2815 final PhylogenyNode node,
2816 final boolean to_graphics_file,
2817 final boolean to_pdf,
2818 final boolean is_in_found_nodes,
2819 final double add ) {
2820 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
2823 if ( getControlPanel().isWriteBranchLengthValues()
2824 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2825 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
2826 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
2827 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
2828 paintBranchLength( g, node, to_pdf, to_graphics_file );
2830 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
2833 if ( !getControlPanel().isShowExternalData() && ( node.isExternal() || node.isCollapse() ) ) {
2841 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
2842 if ( getControlPanel().isShowTaxonomyImages() && ( getImageMap() != null ) && !getImageMap().isEmpty()
2843 && node.getNodeData().isHasTaxonomy() && ( ( node.getNodeData().getTaxonomy().getUris() != null )
2844 && !node.getNodeData().getTaxonomy().getUris().isEmpty() ) ) {
2845 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
2847 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
2848 || getControlPanel().isShowTaxonomyCommonNames() || getControlPanel().isShowTaxonomyRank() )
2849 && node.getNodeData().isHasTaxonomy() ) {
2850 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
2852 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
2853 final boolean saw_species = _sb.length() > 0;
2855 nodeDataAsSB( node, _sb );
2856 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
2857 if ( ( _sb.length() == 0 ) && !saw_species ) {
2858 if ( getOptions().isShowAbbreviatedLabelsForCollapsedNodes()
2859 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
2860 || getControlPanel().isShowSeqNames() || getControlPanel().isShowNodeNames() ) ) {
2861 final PhylogenyNode first = PhylogenyMethods.getFirstExternalNode( node );
2862 final PhylogenyNode last = PhylogenyMethods.getLastExternalNode( node );
2863 if ( getControlPanel().isShowTaxonomyCode() && first.getNodeData().isHasTaxonomy()
2864 && last.getNodeData().isHasTaxonomy()
2865 && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getTaxonomyCode() )
2866 && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
2867 addLabelForCollapsed( first.getNodeData().getTaxonomy().getTaxonomyCode(),
2868 last.getNodeData().getTaxonomy().getTaxonomyCode(),
2869 node.getAllExternalDescendants().size(),
2872 else if ( getControlPanel().isShowTaxonomyScientificNames() && first.getNodeData().isHasTaxonomy()
2873 && last.getNodeData().isHasTaxonomy()
2874 && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getScientificName() )
2875 && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getScientificName() ) ) {
2876 addLabelForCollapsed( first.getNodeData().getTaxonomy().getScientificName(),
2877 last.getNodeData().getTaxonomy().getScientificName(),
2878 node.getAllExternalDescendants().size(),
2881 else if ( getControlPanel().isShowSeqNames() && first.getNodeData().isHasSequence()
2882 && last.getNodeData().isHasSequence()
2883 && !ForesterUtil.isEmpty( first.getNodeData().getSequence().getName() )
2884 && !ForesterUtil.isEmpty( last.getNodeData().getSequence().getName() ) ) {
2885 addLabelForCollapsed( first.getNodeData().getSequence().getName(),
2886 last.getNodeData().getSequence().getName(),
2887 node.getAllExternalDescendants().size(),
2890 else if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( first.getName() )
2891 && !ForesterUtil.isEmpty( last.getName() ) ) {
2892 addLabelForCollapsed( first.getName(),
2894 node.getAllExternalDescendants().size(),
2899 else if ( ( _sb.length() > 0 ) || saw_species ) {
2900 // _sb.setLength( 0 );
2902 _sb.append( node.getAllExternalDescendants().size() );
2904 if ( _found_nodes_0 != null || _found_nodes_1 != null ) {
2905 int[] res = calcFoundNodesInSubtree( node );
2906 if ( res[ 0 ] > 0 ) {
2908 _sb.append( res[ 0 ] );
2910 _sb.append( res[ 1 ] );
2917 // _sb.setLength( 0 );
2919 // nodeDataAsSB( node, _sb );
2920 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
2921 float down_shift_factor = 3.0f;
2922 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
2923 down_shift_factor = 1;
2926 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
2927 && ( node.isExternal() || node.isCollapse() ) ) {
2928 pos_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
2929 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x + ( 2 * TreePanel.MOVE ) + getXdistance()
2933 pos_x = node.getXcoord() + x + 2 + half_box_size;
2936 if ( !using_visual_font ) {
2937 pos_y = ( node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ) );
2940 pos_y = ( node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / down_shift_factor ) );
2942 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
2943 && ( node.isExternal() || node.isCollapse() ) ) {
2944 drawConnection( node.getXcoord(), pos_x - x, node.getYcoord(), 5, 20, g, to_pdf );
2945 if ( node.isCollapse() ) {
2949 final String sb_str = _sb.toString();
2950 // GUILHEM_BEG ______________
2951 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
2952 && ( _query_sequence != null ) ) {
2953 x = paintSequenceRelation( g, node, x, half_box_size, pos_x, pos_y, sb_str );
2955 // GUILHEM_END _____________
2956 if ( sb_str.length() > 0 ) {
2957 if ( !isAllowAttributedStrings() ) {
2958 TreePanel.drawString( sb_str, pos_x, pos_y, g );
2961 drawStringX( sb_str, pos_x, pos_y, g );
2964 if ( _sb.length() > 0 ) {
2965 if ( !using_visual_font && !is_in_found_nodes ) {
2966 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
2969 x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
2972 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
2973 && ( node.getNodeData().getSequence().getAnnotations() != null )
2974 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
2975 final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
2976 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2977 g.setColor( Color.BLACK );
2979 else if ( getControlPanel().isColorAccordingToAnnotation() ) {
2980 g.setColor( calculateColorForAnnotation( ann ) );
2982 final String ann_str = TreePanelUtil.createAnnotationString( ann,
2983 getOptions().isShowAnnotationRefSource() );
2984 TreePanel.drawString( ann_str,
2985 node.getXcoord() + x + 3 + half_box_size,
2987 + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ),
2990 _sb.append( ann_str );
2991 if ( _sb.length() > 0 ) {
2992 if ( !using_visual_font && !is_in_found_nodes ) {
2993 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
2996 x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
3000 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3001 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
3002 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3003 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
3004 && node.getNodeData().isHasBinaryCharacters() ) {
3005 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3006 g.setColor( Color.BLACK );
3009 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
3011 if ( getControlPanel().isShowBinaryCharacters() ) {
3012 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
3014 node.getXcoord() + x + 1 + half_box_size,
3015 node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
3016 / down_shift_factor ),
3018 paintGainedAndLostCharacters( g,
3020 node.getNodeData().getBinaryCharacters()
3021 .getGainedCharactersAsStringBuffer().toString(),
3022 node.getNodeData().getBinaryCharacters()
3023 .getLostCharactersAsStringBuffer().toString() );
3026 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
3027 node.getXcoord() + x + 4 + half_box_size,
3028 node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
3029 / down_shift_factor ),
3031 paintGainedAndLostCharacters( g,
3033 "+" + node.getNodeData().getBinaryCharacters().getGainedCount(),
3034 "-" + node.getNodeData().getBinaryCharacters().getLostCount() );
3041 private final int paintSequenceRelation( final Graphics2D g,
3042 final PhylogenyNode node,
3044 final int half_box_size,
3047 final String sb_str ) {
3048 int nodeTextBoundsWidth = 0;
3049 if ( sb_str.length() > 0 ) {
3050 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
3051 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
3053 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
3054 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
3055 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
3056 g.setColor( getTreeColorSet().getBackgroundColor() );
3060 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
3061 for( final SequenceRelation seqRelation : seqRelations ) {
3062 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence )
3063 || seqRelation.getRef1().isEqual( _query_sequence ) )
3064 && seqRelation.getType()
3065 .equals( getControlPanel().getSequenceRelationTypeBox().getSelectedItem() );
3066 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
3067 final double linePosX = node.getXcoord() + 2 + half_box_size;
3068 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence()
3069 || ( seqRelation.getConfidence() == null ) ) ? null
3070 : " (" + seqRelation.getConfidence().getValue() + ")";
3071 if ( sConfidence != null ) {
3072 float confidenceX = pos_x;
3073 if ( sb_str.length() > 0 ) {
3074 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
3075 + CONFIDENCE_LEFT_MARGIN;
3077 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
3078 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
3079 .getBounds().getWidth();
3080 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
3081 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
3084 if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
3086 if ( nodeTextBoundsWidth == 0 ) {
3087 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
3090 nodeTextBoundsWidth += 2;
3092 g.drawLine( ( int ) linePosX + 1,
3094 ( int ) linePosX + x + nodeTextBoundsWidth,
3095 3 + ( int ) pos_y );
3104 private final void drawConnection( final float x1,
3107 final int dist_left,
3108 final int dist_right,
3110 final boolean pdf ) {
3111 if ( ( ( x1 + dist_left ) < ( x2 - dist_right ) ) ) {
3112 final Stroke strok = g.getStroke();
3114 if ( strok == STROKE_005 ) {
3115 g.setStroke( STROKE_001_DASHED );
3117 else if ( strok == STROKE_01 ) {
3118 g.setStroke( STROKE_005_DASHED );
3121 g.setStroke( STROKE_01_DASHED );
3125 g.setColor( lighter( col ) );
3127 drawLine( x1 + dist_left, y, x2 - dist_right, y, g );
3128 g.setStroke( strok );
3135 public static Color lighter( final Color color ) {
3136 if ( ( color.getRed() == 0 ) && ( color.getGreen() == 0 ) && ( color.getBlue() == 0 ) ) {
3137 return new Color( 200, 200, 200 );
3144 private final void addLabelForCollapsed( final String first,
3147 final PhylogenyNode node ) {
3148 _sb.append( first.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? first
3149 : first.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
3150 _sb.append( " ... " );
3151 _sb.append( last.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? last
3152 : last.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
3153 _sb.append( " (" + size + ")" );
3154 if ( _found_nodes_0 != null || _found_nodes_1 != null ) {
3157 int[] res = calcFoundNodesInSubtree( node );
3158 if ( res[ 0 ] > 0 ) {
3160 _sb.append( res[ 0 ] );
3162 _sb.append( res[ 1 ] );
3168 private final int[] calcFoundNodesInSubtree( final PhylogenyNode node ) {
3169 final List<PhylogenyNode> all_descs = PhylogenyMethods.getAllDescendants( node );
3170 int res[] = new int[ 2 ];
3173 for( final PhylogenyNode desc : all_descs ) {
3174 if ( desc.isHasNodeData() ) {
3175 if ( ( _found_nodes_0 != null && _found_nodes_0.contains( desc.getId() ) )
3176 || ( _found_nodes_1 != null && _found_nodes_1.contains( desc.getId() ) ) ) {
3187 private final boolean isAllowAttributedStrings() {
3191 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
3192 final PhylogenyNode node,
3193 final boolean to_pdf,
3194 final boolean to_graphics_file,
3195 final boolean radial_labels,
3196 final double ur_angle,
3197 final boolean is_in_found_nodes ) {
3198 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
3203 if ( node.getNodeData().isHasTaxonomy()
3204 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
3205 || getControlPanel().isShowTaxonomyCommonNames() ) ) {
3206 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3207 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3208 _sb.append( taxonomy.getTaxonomyCode() );
3211 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3212 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3213 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3214 _sb.append( taxonomy.getScientificName() );
3216 _sb.append( taxonomy.getCommonName() );
3219 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3220 _sb.append( taxonomy.getScientificName() );
3223 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3224 _sb.append( taxonomy.getCommonName() );
3228 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3229 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3230 _sb.append( taxonomy.getScientificName() );
3234 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3235 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3236 _sb.append( taxonomy.getCommonName() );
3241 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3243 _sb.append( node.getAllExternalDescendants().size() );
3246 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3247 if ( _sb.length() > 0 ) {
3250 _sb.append( node.getName() );
3252 if ( node.getNodeData().isHasSequence() ) {
3253 if ( getControlPanel().isShowSequenceAcc()
3254 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3255 if ( _sb.length() > 0 ) {
3258 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3259 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3262 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3264 if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3265 if ( _sb.length() > 0 ) {
3268 _sb.append( node.getNodeData().getSequence().getName() );
3271 //g.setFont( getTreeFontSet().getLargeFont() );
3272 //if ( is_in_found_nodes ) {
3273 // g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3275 if ( _sb.length() > 1 ) {
3276 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
3277 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
3278 final String sb_str = _sb.toString();
3280 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3281 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
3284 m = ( float ) ( ur_angle % TWO_PI );
3286 _at = g.getTransform();
3287 boolean need_to_reset = false;
3288 final float x_coord = node.getXcoord();
3290 if ( !using_visual_font ) {
3291 y_coord = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / 3.0f );
3294 y_coord = node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / 3.0f );
3296 if ( radial_labels ) {
3297 need_to_reset = true;
3298 boolean left = false;
3299 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3303 g.rotate( m, x_coord, node.getYcoord() );
3305 if ( !using_visual_font ) {
3306 g.translate( -( getFontMetricsForLargeDefaultFont().getStringBounds( sb_str, g ).getWidth() ),
3310 g.translate( -( getFontMetrics( g.getFont() ).getStringBounds( sb_str, g ).getWidth() ), 0 );
3315 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3316 need_to_reset = true;
3317 if ( !using_visual_font ) {
3318 g.translate( -getFontMetricsForLargeDefaultFont().getStringBounds( sb_str, g ).getWidth(), 0 );
3321 g.translate( -getFontMetrics( g.getFont() ).getStringBounds( sb_str, g ).getWidth(), 0 );
3325 TreePanel.drawString( sb_str, x_coord, y_coord, g );
3326 if ( need_to_reset ) {
3327 g.setTransform( _at );
3332 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
3333 if ( node.isCollapse() ) {
3336 if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
3337 g.setColor( getColorForFoundNode( node ) );
3338 drawRectFilled( node.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3339 node.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3340 OVERVIEW_FOUND_NODE_BOX_SIZE,
3341 OVERVIEW_FOUND_NODE_BOX_SIZE,
3345 if ( !node.isExternal() && !node.isCollapse() ) {
3346 boolean first_child = true;
3348 //final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3349 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3350 final PhylogenyNode child_node = node.getChildNode( i );
3351 final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3352 if ( first_child ) {
3353 first_child = false;
3354 y2 = node.getYSecondary() - ( getOvYDistance()
3355 * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3358 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3360 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
3361 new_x = x2 + node.getXSecondary();
3362 final float diff_y = node.getYSecondary() - y2;
3363 final float diff_x = node.getXSecondary() - new_x;
3364 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
3365 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
3367 child_node.setXSecondary( new_x );
3368 child_node.setYSecondary( y2 );
3369 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3374 final private void paintNodeRectangular( final Graphics2D g,
3375 final PhylogenyNode node,
3376 final boolean to_pdf,
3377 final boolean dynamically_hide,
3378 final int dynamic_hiding_factor,
3379 final boolean to_graphics_file,
3380 final boolean disallow_shortcutting ) {
3381 final boolean is_in_found_nodes = isInFoundNodes( node ) || isInCurrentExternalNodes( node );
3382 if ( node.isCollapse() ) {
3383 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) ) {
3384 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3388 if ( node.isExternal() ) {
3389 ++_external_node_index;
3391 // Confidence values
3392 if ( getControlPanel().isShowConfidenceValues() && !node.isExternal() && !node.isRoot()
3393 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
3394 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3395 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3396 && node.getBranchData().isHasConfidences() ) {
3397 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
3399 // Draw a line to root:
3400 if ( node.isRoot() && _phylogeny.isRooted() ) {
3401 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
3404 float new_x_min = Float.MAX_VALUE;
3405 float min_dist = 1.5f;
3406 if ( !disallow_shortcutting ) {
3407 if ( dynamic_hiding_factor > 4000 ) {
3410 else if ( dynamic_hiding_factor > 1000 ) {
3413 else if ( dynamic_hiding_factor > 100 ) {
3417 if ( !node.isExternal() && !node.isCollapse() ) {
3418 boolean first_child = true;
3420 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3421 final PhylogenyNode child_node = node.getChildNode( i );
3422 final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3423 if ( first_child ) {
3424 first_child = false;
3425 y2 = node.getYcoord() - ( _y_distance
3426 * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3429 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3431 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
3432 new_x = x2 + node.getXcoord();
3433 if ( dynamically_hide && ( x2 < new_x_min ) ) {
3436 final float diff_y = node.getYcoord() - y2;
3437 final float diff_x = node.getXcoord() - new_x;
3438 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
3439 || ( diff_x < -min_dist ) ) {
3440 paintBranchRectangular( g,
3449 child_node.setXcoord( new_x );
3450 child_node.setYcoord( y2 );
3451 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3453 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file );
3455 if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
3456 && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
3457 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
3458 paintMolecularSequences( g, node, to_pdf );
3460 if ( dynamically_hide && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) )
3461 || ( !node.isExternal() && ( ( new_x_min < 20 )
3462 || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getFontMetricsForLargeDefaultFont()
3463 .getHeight() ) ) ) ) ) {
3466 final int x = paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes, 0 );
3467 paintNodeWithRenderableData( x, g, node, to_graphics_file, to_pdf );
3470 final private void paintNodeWithRenderableData( final int x,
3472 final PhylogenyNode node,
3473 final boolean to_graphics_file,
3474 final boolean to_pdf ) {
3475 if ( isNodeDataInvisible( node ) && !( to_graphics_file || to_pdf ) ) {
3478 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
3481 if ( ( !getControlPanel().isShowExternalData() && node.isExternal() ) ) {
3484 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3485 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) && ( node.getNodeData()
3486 .getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
3487 RenderableDomainArchitecture rds = null;
3489 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
3491 catch ( final ClassCastException cce ) {
3492 cce.printStackTrace();
3494 if ( rds != null ) {
3495 final int default_height = 7;
3496 float y = getYdistance();
3497 if ( getControlPanel().isDynamicallyHideData() ) {
3498 y = getTreeFontSet().getFontMetricsLarge().getHeight();
3500 final int h = y < default_height ? ForesterUtil.roundToInt( y ) : default_height;
3501 rds.setRenderingHeight( h > 1 ? h : 2 );
3502 if ( getControlPanel().isDrawPhylogram() ) {
3503 if ( getOptions().isLineUpRendarableNodeData() ) {
3504 if ( getOptions().isRightLineUpDomains() ) {
3505 rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3506 + _length_of_longest_text + 50 //TODO why plus 50?
3507 + ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ) ),
3508 node.getYcoord() - ( h / 2.0f ),
3514 rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3515 + _length_of_longest_text + 50 ),
3516 node.getYcoord() - ( h / 2.0f ),
3523 rds.render( node.getXcoord() + x, node.getYcoord() - ( h / 2.0f ), g, this, to_pdf );
3527 if ( getOptions().isRightLineUpDomains() ) {
3528 rds.render( ( ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text )
3529 - 20 ) + ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ),
3530 node.getYcoord() - ( h / 2.0f ),
3536 rds.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text,
3537 node.getYcoord() - ( h / 2.0f ),
3545 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
3546 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
3547 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
3548 getStatisticsForExpressionValues(),
3549 getConfiguration() );
3551 double domain_add = 0;
3552 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3553 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
3554 domain_add = _domain_structure_width + 10;
3556 if ( getControlPanel().isDrawPhylogram() ) {
3557 rv.render( ( float ) ( node.getXcoord() + x + domain_add ), node.getYcoord() - 3, g, this, to_pdf );
3560 rv.render( ( float ) ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text
3561 + domain_add ), node.getYcoord() - 3, g, this, to_pdf );
3565 //if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
3566 // && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
3567 // && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
3568 // paintMolecularSequences( g, node, to_pdf );
3572 final private void paintOvRectangle( final Graphics2D g ) {
3573 final float w_ratio = ( ( float ) getWidth() ) / getVisibleRect().width;
3574 final float h_ratio = ( ( float ) getHeight() ) / getVisibleRect().height;
3575 final float x_ratio = ( ( float ) getWidth() ) / getVisibleRect().x;
3576 final float y_ratio = ( ( float ) getHeight() ) / getVisibleRect().y;
3577 final float width = getOvMaxWidth() / w_ratio;
3578 final float height = getOvMaxHeight() / h_ratio;
3579 final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio );
3580 final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio );
3581 g.setColor( getTreeColorSet().getFoundColor0() );
3582 getOvRectangle().setRect( x, y, width, height );
3583 final Stroke s = g.getStroke();
3584 g.setStroke( STROKE_1 );
3585 if ( ( width < 6 ) && ( height < 6 ) ) {
3586 drawRectFilled( x, y, 6, 6, g );
3587 getOvVirtualRectangle().setRect( x, y, 6, 6 );
3589 else if ( width < 6 ) {
3590 drawRectFilled( x, y, 6, height, g );
3591 getOvVirtualRectangle().setRect( x, y, 6, height );
3593 else if ( height < 6 ) {
3594 drawRectFilled( x, y, width, 6, g );
3595 getOvVirtualRectangle().setRect( x, y, width, 6 );
3598 drawRect( x, y, width, height, g );
3599 if ( isInOvRect() ) {
3600 drawRect( x + 1, y + 1, width - 2, height - 2, g );
3602 getOvVirtualRectangle().setRect( x, y, width, height );
3607 final private void paintPhylogenyLite( final Graphics2D g ) {
3608 _phylogeny.getRoot().setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition()
3609 + ( MOVE / ( getVisibleRect().width / getOvRectangle().getWidth() ) ) ) );
3610 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
3611 final Stroke s = g.getStroke();
3612 g.setStroke( STROKE_05 );
3613 for( final PhylogenyNode element : _nodes_in_preorder ) {
3614 paintNodeLite( g, element );
3617 paintOvRectangle( g );
3621 * Paint the root branch. (Differs from others because it will always be a
3622 * single horizontal line).
3623 * @param to_graphics_file
3625 * @return new x1 value
3627 final private void paintRootBranch( final Graphics2D g,
3630 final PhylogenyNode root,
3631 final boolean to_pdf,
3632 final boolean to_graphics_file ) {
3633 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
3634 float d = getXdistance();
3635 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
3636 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
3638 if ( d < MIN_ROOT_LENGTH ) {
3639 d = MIN_ROOT_LENGTH;
3641 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
3642 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
3645 final double w = PhylogenyMethods.getBranchWidthValue( root );
3646 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
3648 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file );
3651 final private void paintScale( final Graphics2D g,
3654 final boolean to_pdf,
3655 final boolean to_graphics_file ) {
3657 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
3659 final int y2 = y1 - 8;
3660 final int y3 = y1 - 4;
3661 g.setFont( getTreeFontSet().getSmallFont() );
3662 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3663 g.setColor( Color.BLACK );
3666 g.setColor( getTreeColorSet().getBranchLengthColor() );
3668 final Stroke s = g.getStroke();
3669 g.setStroke( STROKE_1 );
3670 drawLine( x1, y1, x1, y2, g );
3671 drawLine( x2, y1, x2, y2, g );
3672 drawLine( x1, y3, x2, y3, g );
3673 if ( getScaleLabel() != null ) {
3674 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
3679 final private int paintTaxonomy( final Graphics2D g,
3680 final PhylogenyNode node,
3681 final boolean is_in_found_nodes,
3682 final boolean to_pdf,
3683 final boolean to_graphics_file,
3684 final float x_shift ) {
3685 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3686 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
3687 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getTaxonomyColor() );
3688 float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
3689 if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
3690 && node.isExternal() ) {
3691 start_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
3692 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift + ( 2 * TreePanel.MOVE ) + getXdistance()
3696 if ( !using_visual_font ) {
3697 start_y = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
3698 / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) );
3701 start_y = node.getYcoord()
3702 + ( getFontMetrics( g.getFont() ).getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) );
3705 nodeTaxonomyDataAsSB( taxonomy, _sb );
3706 final String label = _sb.toString();
3708 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
3709 && ( node.getNodeData().isHasSequence() )
3710 && node.getNodeData().getSequence().equals( _query_sequence ) ) {
3711 // invert font color and background color to show that this is the query sequence
3712 final Rectangle2D nodeTextBounds = new TextLayout( label,
3714 new FontRenderContext( null, false, false ) )
3716 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
3717 g.setColor( getTreeColorSet().getBackgroundColor() );
3720 TreePanel.drawString( label, start_x, start_y, g );
3721 if ( !using_visual_font && !is_in_found_nodes ) {
3722 return getFontMetricsForLargeDefaultFont().stringWidth( label );
3724 return getFontMetrics( g.getFont() ).stringWidth( label );
3727 final private void paintUnrooted( final PhylogenyNode n,
3728 final double low_angle,
3729 final double high_angle,
3730 final boolean radial_labels,
3732 final boolean to_pdf,
3733 final boolean to_graphics_file ) {
3735 n.setXcoord( getWidth() / 2 );
3736 n.setYcoord( getHeight() / 2 );
3738 if ( n.isExternal() ) {
3739 paintNodeDataUnrootedCirc( g,
3744 ( high_angle + low_angle ) / 2,
3745 isInFoundNodes( n ) || isInCurrentExternalNodes( n ) );
3748 final float num_enclosed = n.getNumberOfExternalNodes();
3749 final float x = n.getXcoord();
3750 final float y = n.getYcoord();
3751 double current_angle = low_angle;
3752 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
3753 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
3754 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
3755 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
3756 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3757 final PhylogenyNode desc = n.getChildNode( i );
3758 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
3759 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
3760 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
3761 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
3764 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
3767 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
3770 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3771 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3773 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3774 if ( desc.getDistanceToParent() < 0 ) {
3778 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
3782 length = getUrtFactor();
3784 final double mid_angle = current_angle + ( arc_size / 2 );
3785 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
3786 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
3787 desc.setXcoord( new_x );
3788 desc.setYcoord( new_y );
3789 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
3790 current_angle += arc_size;
3791 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
3792 drawLine( x, y, new_x, new_y, g );
3793 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file );
3796 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file );
3800 final private void paintUnrootedLite( final PhylogenyNode n,
3801 final double low_angle,
3802 final double high_angle,
3804 final float urt_ov_factor ) {
3806 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) );
3807 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) );
3808 n.setXSecondary( x_pos );
3809 n.setYSecondary( y_pos );
3811 if ( n.isExternal() ) {
3814 final float num_enclosed = n.getNumberOfExternalNodes();
3815 final float x = n.getXSecondary();
3816 final float y = n.getYSecondary();
3817 double current_angle = low_angle;
3818 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3819 final PhylogenyNode desc = n.getChildNode( i );
3820 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3821 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3823 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3824 if ( desc.getDistanceToParent() < 0 ) {
3828 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
3832 length = urt_ov_factor;
3834 final double mid_angle = current_angle + ( arc_size / 2 );
3835 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
3836 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
3837 desc.setXSecondary( new_x );
3838 desc.setYSecondary( new_y );
3839 if ( isInFoundNodes( desc ) || isInCurrentExternalNodes( desc ) ) {
3840 g.setColor( getColorForFoundNode( desc ) );
3841 drawRectFilled( desc.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3842 desc.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
3843 OVERVIEW_FOUND_NODE_BOX_SIZE,
3844 OVERVIEW_FOUND_NODE_BOX_SIZE,
3846 g.setColor( getTreeColorSet().getOvColor() );
3848 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
3849 current_angle += arc_size;
3850 drawLine( x, y, new_x, new_y, g );
3854 final private void pasteSubtree( final PhylogenyNode node ) {
3855 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3856 errorMessageNoCutCopyPasteInUnrootedDisplay();
3859 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
3860 JOptionPane.showMessageDialog( this,
3861 "No tree in buffer (need to copy or cut a subtree first)",
3862 "Attempt to paste with empty buffer",
3863 JOptionPane.ERROR_MESSAGE );
3866 final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
3867 final Object[] options = { "As sibling", "As descendant", "Cancel" };
3868 final int r = JOptionPane.showOptionDialog( this,
3869 "How to paste subtree" + label + "?",
3871 JOptionPane.CLOSED_OPTION,
3872 JOptionPane.QUESTION_MESSAGE,
3876 boolean paste_as_sibling = true;
3878 paste_as_sibling = false;
3880 else if ( r != 0 ) {
3883 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
3884 buffer_phy.setAllNodesToNotCollapse();
3885 PhylogenyMethods.preOrderReId( buffer_phy );
3886 buffer_phy.setRooted( true );
3887 boolean need_to_show_whole = false;
3888 if ( paste_as_sibling ) {
3889 if ( node.isRoot() ) {
3890 JOptionPane.showMessageDialog( this,
3891 "Cannot paste sibling to root",
3892 "Attempt to paste sibling to root",
3893 JOptionPane.ERROR_MESSAGE );
3896 buffer_phy.addAsSibling( node );
3899 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
3900 need_to_show_whole = true;
3901 _phylogeny = buffer_phy;
3904 buffer_phy.addAsChild( node );
3907 if ( getCopiedAndPastedNodes() == null ) {
3908 setCopiedAndPastedNodes( new HashSet<Long>() );
3910 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
3911 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
3912 for( final PhylogenyNode n : nodes ) {
3913 node_ids.add( n.getId() );
3915 node_ids.add( node.getId() );
3916 getCopiedAndPastedNodes().addAll( node_ids );
3917 setNodeInPreorderToNull();
3918 _phylogeny.externalNodesHaveChanged();
3919 _phylogeny.clearHashIdToNodeMap();
3920 _phylogeny.recalculateNumberOfExternalDescendants( true );
3921 resetNodeIdToDistToLeafMap();
3923 if ( need_to_show_whole ) {
3924 getControlPanel().showWhole();
3929 private final StringBuffer propertiesToString( final PhylogenyNode node ) {
3930 return node.getNodeData().getProperties().asText();
3933 private void setColor( final Graphics2D g,
3934 final PhylogenyNode node,
3935 final boolean to_graphics_file,
3936 final boolean to_pdf,
3937 final boolean is_in_found_nodes,
3938 final Color default_color ) {
3939 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3940 g.setColor( Color.BLACK );
3942 else if ( is_in_found_nodes ) {
3943 g.setColor( getColorForFoundNode( node ) );
3945 else if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
3946 && ( node.getNodeData().getNodeVisualData().getFontColor() != null ) ) {
3947 g.setColor( node.getNodeData().getNodeVisualData().getFontColor() );
3949 else if ( getControlPanel().isColorAccordingToSequence() ) {
3950 g.setColor( getSequenceBasedColor( node ) );
3952 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3953 g.setColor( getTaxonomyBasedColor( node ) );
3955 else if ( getControlPanel().isColorAccordingToAnnotation()
3956 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null )
3957 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
3958 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
3960 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
3961 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3962 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3964 else if ( to_pdf ) {
3965 g.setColor( Color.BLACK );
3968 g.setColor( default_color );
3972 final private void setCopiedAndPastedNodes( final Set<Long> nodeIds ) {
3973 getMainPanel().setCopiedAndPastedNodes( nodeIds );
3976 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
3977 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
3980 private boolean setFont( final Graphics2D g, final PhylogenyNode node, final boolean is_in_found_nodes ) {
3981 Font visual_font = null;
3982 if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null ) ) {
3983 visual_font = node.getNodeData().getNodeVisualData().getFont();
3984 g.setFont( visual_font != null ? visual_font : getTreeFontSet().getLargeFont() );
3987 g.setFont( getTreeFontSet().getLargeFont() );
3989 if ( is_in_found_nodes ) {
3990 g.setFont( g.getFont().deriveFont( Font.BOLD ) );
3992 return visual_font != null;
3995 final private void setInOv( final boolean in_ov ) {
3999 final private void setOvMaxHeight( final float ov_max_height ) {
4000 _ov_max_height = ov_max_height;
4003 final private void setOvMaxWidth( final float ov_max_width ) {
4004 _ov_max_width = ov_max_width;
4007 final private void setOvXcorrectionFactor( final float f ) {
4008 _ov_x_correction_factor = f;
4011 final private void setOvXDistance( final float ov_x_distance ) {
4012 _ov_x_distance = ov_x_distance;
4015 final private void setOvXPosition( final int ov_x_position ) {
4016 _ov_x_position = ov_x_position;
4019 final private void setOvYDistance( final float ov_y_distance ) {
4020 _ov_y_distance = ov_y_distance;
4023 final private void setOvYPosition( final int ov_y_position ) {
4024 _ov_y_position = ov_y_position;
4027 final private void setOvYStart( final int ov_y_start ) {
4028 _ov_y_start = ov_y_start;
4031 final private void setScaleDistance( final double scale_distance ) {
4032 _scale_distance = scale_distance;
4035 final private void setScaleLabel( final String scale_label ) {
4036 _scale_label = scale_label;
4039 private final void setupStroke( final Graphics2D g ) {
4040 if ( getYdistance() < 0.0001 ) {
4041 g.setStroke( STROKE_0025 );
4043 if ( getYdistance() < 0.001 ) {
4044 g.setStroke( STROKE_005 );
4046 else if ( getYdistance() < 0.01 ) {
4047 g.setStroke( STROKE_01 );
4049 else if ( getYdistance() < 0.5 ) {
4050 g.setStroke( STROKE_025 );
4052 else if ( getYdistance() < 1 ) {
4053 g.setStroke( STROKE_05 );
4055 else if ( getYdistance() < 2 ) {
4056 g.setStroke( STROKE_075 );
4058 else if ( ( getYdistance() < 20 ) || !getConfiguration().isAllowThickStrokes() ) {
4059 g.setStroke( STROKE_1 );
4062 g.setStroke( STROKE_2 );
4066 final private void setUpUrtFactor() {
4067 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
4068 : getVisibleRect().height;
4069 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4070 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
4073 final int max_depth = _circ_max_depth;
4074 if ( max_depth > 0 ) {
4075 setUrtFactor( d / ( 2 * max_depth ) );
4078 setUrtFactor( d / 2 );
4081 setUrtFactorOv( getUrtFactor() );
4084 final private void setUrtFactor( final float urt_factor ) {
4085 _urt_factor = urt_factor;
4088 final private void setUrtFactorOv( final float urt_factor_ov ) {
4089 _urt_factor_ov = urt_factor_ov;
4092 private void showExtDescNodeData( final PhylogenyNode node, final char separator ) {
4093 final List<String> data = new ArrayList<String>();
4094 final List<PhylogenyNode> nodes = node.getAllExternalDescendants();
4095 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
4096 for( final PhylogenyNode n : getFoundNodesAsListOfPhylogenyNodes() ) {
4097 if ( !nodes.contains( n ) ) {
4102 for( final PhylogenyNode n : nodes ) {
4103 switch ( getOptions().getExtDescNodeDataToReturn() ) {
4105 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
4106 data.add( n.getName() );
4110 if ( n.getNodeData().isHasSequence()
4111 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
4112 data.add( n.getNodeData().getSequence().getName() );
4116 if ( n.getNodeData().isHasSequence()
4117 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
4118 data.add( n.getNodeData().getSequence().getGeneName() );
4121 case SEQUENCE_SYMBOL:
4122 if ( n.getNodeData().isHasSequence()
4123 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
4124 data.add( n.getNodeData().getSequence().getSymbol() );
4127 case SEQUENCE_MOL_SEQ_FASTA:
4128 final StringBuilder sb = new StringBuilder();
4129 if ( n.getNodeData().isHasSequence()
4130 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
4131 final StringBuilder ann = new StringBuilder();
4132 if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( n.getName() ) ) {
4133 ann.append( n.getName() );
4134 ann.append( separator );
4136 if ( n.getNodeData().isHasTaxonomy() ) {
4137 if ( getControlPanel().isShowTaxonomyCode()
4138 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
4139 ann.append( n.getNodeData().getTaxonomy().getTaxonomyCode() );
4140 ann.append( separator );
4142 if ( getControlPanel().isShowTaxonomyScientificNames()
4143 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
4144 ann.append( n.getNodeData().getTaxonomy().getScientificName() );
4145 ann.append( separator );
4147 if ( getControlPanel().isShowTaxonomyCommonNames()
4148 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getCommonName() ) ) {
4149 ann.append( n.getNodeData().getTaxonomy().getCommonName() );
4150 ann.append( separator );
4153 if ( getControlPanel().isShowSeqSymbols()
4154 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
4155 ann.append( n.getNodeData().getSequence().getSymbol() );
4156 ann.append( separator );
4158 if ( getControlPanel().isShowSeqNames()
4159 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
4160 ann.append( n.getNodeData().getSequence().getName() );
4161 ann.append( separator );
4163 if ( getControlPanel().isShowGeneNames()
4164 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
4165 ann.append( n.getNodeData().getSequence().getGeneName() );
4166 ann.append( separator );
4168 if ( getControlPanel().isShowSequenceAcc()
4169 && n.getNodeData().getSequence().getAccession() != null ) {
4170 ann.append( n.getNodeData().getSequence().getAccession().asText() );
4171 ann.append( separator );
4174 final String ann_str;
4175 if ( ann.length() > 0 && ann.charAt( ann.length() - 1 ) == separator ) {
4176 ann_str = ann.substring( 0, ann.length() - 1 );
4179 ann_str = ann.toString();
4181 sb.append( SequenceWriter.toFasta( ann_str,
4182 n.getNodeData().getSequence().getMolecularSequence(),
4184 data.add( sb.toString() );
4188 if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
4189 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
4190 data.add( n.getNodeData().getSequence().getAccession().toString() );
4193 case TAXONOMY_SCIENTIFIC_NAME:
4194 if ( n.getNodeData().isHasTaxonomy()
4195 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
4196 data.add( n.getNodeData().getTaxonomy().getScientificName() );
4200 if ( n.getNodeData().isHasTaxonomy()
4201 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
4202 data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
4206 case DOMAINS_COLLAPSED_PER_PROTEIN:
4207 if ( n.getNodeData().isHasSequence()
4208 && ( n.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4209 final DomainArchitecture da = n.getNodeData().getSequence().getDomainArchitecture();
4210 final Set<String> s = new HashSet<String>();
4211 for( int i = 0; i < da.getDomains().size(); ++i ) {
4212 final ProteinDomain d = da.getDomain( i );
4213 if ( d.getConfidence() <= Math.pow( 10, getDomainStructureEvalueThresholdExp() ) ) {
4214 final String name = d.getName();
4215 if ( !( s.contains( name ) ) ) {
4218 .getExtDescNodeDataToReturn() == NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN ) {
4226 case SEQ_ANNOTATIONS:
4227 if ( n.getNodeData().isHasSequence() ) {
4228 if ( n.getNodeData().isHasSequence()
4229 && ( n.getNodeData().getSequence().getAnnotations() != null ) ) {
4230 final SortedSet<Annotation> a = n.getNodeData().getSequence().getAnnotations();
4231 for( int i = 0; i < a.size(); ++i ) {
4232 data.add( n.getNodeData().getSequence().getAnnotation( i ).toString() );
4238 if ( n.getNodeData().isHasSequence() ) {
4239 if ( n.getNodeData().isHasSequence()
4240 && ( n.getNodeData().getSequence().getAnnotations() != null ) ) {
4241 final SortedSet<Annotation> a = n.getNodeData().getSequence().getAnnotations();
4242 for( int i = 0; i < a.size(); ++i ) {
4243 final Annotation ann = n.getNodeData().getSequence().getAnnotation( i );
4244 final String ref = ann.getRef();
4245 if ( ref.toUpperCase().startsWith( "GO:" ) ) {
4253 TreePanelUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
4256 throw new IllegalArgumentException( "unknown data element: "
4257 + getOptions().getExtDescNodeDataToReturn() );
4260 final StringBuilder sb = new StringBuilder();
4261 final int size = TreePanelUtil.nodeDataIntoStringBuffer( data, getOptions(), sb );
4262 if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
4263 || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
4264 if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
4265 System.out.println( sb );
4267 if ( sb.length() < 1 ) {
4268 clearCurrentExternalNodesDataBuffer();
4271 setCurrentExternalNodesDataBuffer( sb );
4274 else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
4275 if ( sb.length() < 1 ) {
4276 TreePanelUtil.showInformationMessage( this,
4277 "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")",
4278 "Descendants of selected node do not contain selected data" );
4279 clearCurrentExternalNodesDataBuffer();
4282 setCurrentExternalNodesDataBuffer( sb );
4284 if ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() ) {
4285 title = ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.UNKNOWN ? "Data"
4286 : obtainTitleForExtDescNodeData() ) + " for " + data.size() + " nodes, unique entries: "
4290 title = ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.UNKNOWN ? "Data"
4291 : obtainTitleForExtDescNodeData() ) + " for " + data.size() + "/"
4292 + node.getNumberOfExternalNodes() + " external descendats of node " + node
4293 + ", unique entries: " + size;
4295 final String s = sb.toString().trim();
4296 getMainPanel().getMainFrame().showTextFrame( s, title );
4301 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
4303 if ( ( node.getName().length() > 0 )
4304 || ( node.getNodeData().isHasTaxonomy()
4305 && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
4306 || ( node.getNodeData().isHasSequence()
4307 && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) )
4308 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
4309 || node.getBranchData().isHasConfidences() ) {
4310 _popup_buffer.setLength( 0 );
4312 if ( node.getName().length() > 0 ) {
4314 _popup_buffer.append( node.getName() );
4316 if ( node.getNodeData().isHasTaxonomy()
4317 && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
4319 boolean enc_data = false;
4320 final Taxonomy tax = node.getNodeData().getTaxonomy();
4321 if ( _popup_buffer.length() > 0 ) {
4322 _popup_buffer.append( "\n" );
4324 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4325 _popup_buffer.append( "[" );
4326 _popup_buffer.append( tax.getTaxonomyCode() );
4327 _popup_buffer.append( "]" );
4330 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4332 _popup_buffer.append( " " );
4334 _popup_buffer.append( tax.getScientificName() );
4337 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
4339 _popup_buffer.append( " (" );
4342 _popup_buffer.append( "(" );
4344 _popup_buffer.append( tax.getCommonName() );
4345 _popup_buffer.append( ")" );
4348 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
4350 _popup_buffer.append( " (" );
4353 _popup_buffer.append( "(" );
4355 _popup_buffer.append( tax.getAuthority() );
4356 _popup_buffer.append( ")" );
4359 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
4361 _popup_buffer.append( " [" );
4364 _popup_buffer.append( "[" );
4366 _popup_buffer.append( tax.getRank() );
4367 _popup_buffer.append( "]" );
4370 if ( tax.getSynonyms().size() > 0 ) {
4372 _popup_buffer.append( " " );
4374 _popup_buffer.append( "[" );
4376 for( final String syn : tax.getSynonyms() ) {
4377 if ( !ForesterUtil.isEmpty( syn ) ) {
4379 _popup_buffer.append( syn );
4380 if ( counter < tax.getSynonyms().size() ) {
4381 _popup_buffer.append( ", " );
4386 _popup_buffer.append( "]" );
4389 if ( ( tax.getIdentifier() != null )
4390 && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
4391 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
4392 _popup_buffer.append( "[" );
4393 _popup_buffer.append( tax.getIdentifier().getProvider() );
4394 _popup_buffer.append( "] " );
4396 _popup_buffer.append( tax.getIdentifier().getValue() );
4400 if ( node.getNodeData().isHasSequence()
4401 && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) ) {
4403 boolean enc_data = false;
4404 if ( _popup_buffer.length() > 0 ) {
4405 _popup_buffer.append( "\n" );
4407 final Sequence seq = node.getNodeData().getSequence();
4408 if ( seq.getAccession() != null ) {
4409 _popup_buffer.append( "[" );
4410 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
4411 _popup_buffer.append( seq.getAccession().getSource() );
4412 _popup_buffer.append( ":" );
4414 _popup_buffer.append( seq.getAccession().getValue() );
4415 _popup_buffer.append( "]" );
4418 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
4420 _popup_buffer.append( " [" );
4423 _popup_buffer.append( "[" );
4425 _popup_buffer.append( seq.getSymbol() );
4426 _popup_buffer.append( "]" );
4429 if ( !ForesterUtil.isEmpty( seq.getGeneName() ) ) {
4431 _popup_buffer.append( " [" );
4434 _popup_buffer.append( "[" );
4436 _popup_buffer.append( seq.getGeneName() );
4437 _popup_buffer.append( "]" );
4440 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
4442 _popup_buffer.append( " " );
4444 _popup_buffer.append( seq.getName() );
4447 if ( node.getNodeData().isHasDate() ) {
4449 if ( _popup_buffer.length() > 0 ) {
4450 _popup_buffer.append( "\n" );
4452 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
4454 if ( node.getNodeData().isHasDistribution() ) {
4456 if ( _popup_buffer.length() > 0 ) {
4457 _popup_buffer.append( "\n" );
4459 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
4461 if ( node.getBranchData().isHasConfidences() ) {
4462 final List<Confidence> confs = node.getBranchData().getConfidences();
4463 for( final Confidence confidence : confs ) {
4465 if ( _popup_buffer.length() > 0 ) {
4466 _popup_buffer.append( "\n" );
4468 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
4469 _popup_buffer.append( "[" );
4470 _popup_buffer.append( confidence.getType() );
4471 _popup_buffer.append( "] " );
4473 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
4475 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4476 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
4477 _popup_buffer.append( " (sd=" );
4478 _popup_buffer.append( FORMATTER_CONFIDENCE
4479 .format( ForesterUtil.round( confidence.getStandardDeviation(),
4481 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4482 _popup_buffer.append( ")" );
4486 if ( node.getNodeData().isHasProperties() ) {
4487 if ( _popup_buffer.length() > 0 ) {
4488 _popup_buffer.append( "\n" );
4490 _popup_buffer.append( node.getNodeData().getProperties().asText() );
4492 if ( _popup_buffer.length() > 0 ) {
4493 if ( !getConfiguration().isUseNativeUI() ) {
4495 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
4496 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
4497 if ( isInFoundNodes0( node ) && !isInFoundNodes1( node ) ) {
4498 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0() );
4500 else if ( !isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
4501 _rollover_popup.setForeground( getTreeColorSet().getFoundColor1() );
4503 else if ( isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
4504 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0and1() );
4507 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
4511 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
4513 _rollover_popup.setText( _popup_buffer.toString() );
4514 _node_desc_popup = PopupFactory.getSharedInstance()
4517 e.getLocationOnScreen().x + 10,
4518 e.getLocationOnScreen().y - ( lines * 20 ) );
4519 _node_desc_popup.show();
4523 catch ( final Exception ex ) {
4528 final private void showNodeEditFrame( final PhylogenyNode n ) {
4529 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4530 // pop up edit box for single node
4531 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
4532 _node_frame_index++;
4535 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4539 final private void showNodeFrame( final PhylogenyNode n ) {
4540 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4541 // pop up edit box for single node
4542 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
4543 _node_frame_index++;
4546 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4550 final private void switchDisplaygetPhylogenyGraphicsType() {
4551 switch ( getPhylogenyGraphicsType() ) {
4553 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4554 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4557 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4558 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4561 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4562 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4565 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4566 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4569 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4570 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4573 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4574 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4577 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4578 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4581 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4582 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4585 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
4587 if ( getControlPanel().getDynamicallyHideData() != null ) {
4588 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4589 getControlPanel().getDynamicallyHideData().setEnabled( false );
4592 getControlPanel().getDynamicallyHideData().setEnabled( true );
4595 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4596 getControlPanel().setDrawPhylogramEnabled( true );
4599 getControlPanel().setDrawPhylogramEnabled( false );
4601 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4604 final void calcMaxDepth() {
4605 if ( _phylogeny != null ) {
4606 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4611 * Set parameters for printing the displayed tree
4614 final void calcParametersForPainting( final int x, final int y ) {
4615 // updateStyle(); not needed?
4616 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4618 calculateLongestExtNodeInfo();
4619 if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
4620 && ( getTreeFontSet().getLargeFont().getSize() > ( 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
4621 while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) )
4622 && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) {
4623 getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(), true );
4624 calculateLongestExtNodeInfo();
4628 while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) ) && ( getTreeFontSet().getLargeFont()
4629 .getSize() <= ( getTreeFontSet().getLargeFontMemory().getSize()
4630 - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
4631 getMainPanel().getTreeFontSet().increaseFontSize();
4632 calculateLongestExtNodeInfo();
4635 //_length_of_longest_text = calcLengthOfLongestText();
4636 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4637 final int max_depth = PhylogenyMethods.calculateMaxDepthConsiderCollapsed( _phylogeny ) + 1;
4638 if ( ext_nodes == 1 ) {
4639 ext_nodes = max_depth;
4640 if ( ext_nodes < 1 ) {
4647 if ( !isNonLinedUpCladogram() ) {
4648 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
4649 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
4652 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
4653 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
4655 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
4656 if ( xdist < 0.0 ) {
4659 if ( ov_xdist < 0.0 ) {
4662 if ( ydist < 0.0 ) {
4665 setXdistance( xdist );
4666 setYdistance( ydist );
4667 setOvXDistance( ov_xdist );
4668 final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() );
4669 //final double height = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4671 final float corr = ( float ) ( ( x - ( 2.0 * TreePanel.MOVE ) - getLongestExtNodeInfo()
4672 - getXdistance() ) / height );
4673 setXcorrectionFactor( corr > 0 ? corr : 0 );
4674 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
4675 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4678 setXcorrectionFactor( 0 );
4679 setOvXcorrectionFactor( 0 );
4681 _circ_max_depth = max_depth;
4684 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
4685 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4686 // int dynamic_hiding_factor = calcDynamicHidingFactor();
4687 // if ( dynamic_hiding_factor > 1 ) {
4688 // while ( dynamic_hiding_factor > 1
4689 // && getTreeFontSet()._fm_large.getHeight() > TreeFontSet.SMALL_FONTS_BASE ) {
4690 // getTreeFontSet().decreaseFontSize( 1, true );
4691 // dynamic_hiding_factor = calcDynamicHidingFactor();
4694 // else if ( getTreeFontSet().isDecreasedSizeBySystem() ) {
4695 // while ( dynamic_hiding_factor < 1 && getTreeFontSet()._fm_large.getHeight() < 12 ) {
4696 // getTreeFontSet().increaseFontSize();
4697 // dynamic_hiding_factor = calcDynamicHidingFactor();
4705 final void calculateLongestExtNodeInfo() {
4706 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
4709 int max_possible_length = ForesterUtil
4710 .roundToInt( ( getSize().getWidth() - ( 2 * MOVE ) ) * AptxConstants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
4711 if ( max_possible_length < 20 ) {
4712 max_possible_length = 20;
4715 int longest_txt = 0;
4716 _longest_domain = 0;
4717 PhylogenyNode longest_txt_node = _phylogeny.getFirstExternalNode();
4718 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
4720 if ( node.isCollapse() ) {
4723 final StringBuilder sb = new StringBuilder();
4724 nodeDataAsSB( node, sb );
4725 if ( node.getNodeData().isHasTaxonomy() ) {
4726 nodeTaxonomyDataAsSB( node.getNodeData().getTaxonomy(), sb );
4728 final int txt = sb.length();
4729 if ( txt > longest_txt ) {
4731 longest_txt_node = node;
4733 boolean use_vis = false;
4734 final Graphics2D g = ( Graphics2D ) getGraphics();
4735 if ( g != null && getControlPanel().isUseVisualStyles() ) {
4736 use_vis = setFont( g, node, false );
4739 sum = getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
4742 sum = getFontMetrics( g.getFont() ).stringWidth( sb.toString() );
4744 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
4745 sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getBinaryCharacters()
4746 .getGainedCharactersAsStringBuffer().toString() );
4748 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
4749 && ( node.getNodeData().getVector().size() > 0 ) ) {
4750 if ( getConfiguration() != null ) {
4751 sum += getConfiguration().getVectorDataWidth() + 10;
4754 sum += RenderableVector.VECTOR_DEFAULT_WIDTH + 10;
4757 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4758 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4760 // TODO this might need some clean up
4761 final DomainArchitecture d = node.getNodeData().getSequence().getDomainArchitecture();
4762 sum += ( ( _domain_structure_width
4763 / ( ( RenderableDomainArchitecture ) d ).getOriginalSize().getWidth() ) * d.getTotalLength() )
4765 if ( d.getTotalLength() > _longest_domain ) {
4766 _longest_domain = d.getTotalLength();
4769 if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
4770 && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
4771 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
4773 sum += RenderableMsaSequence.DEFAULT_WIDTH + 30;
4775 if ( sum >= max_possible_length ) {
4776 _longest_ext_node_info = max_possible_length;
4777 // return; //FIXME why?
4779 if ( sum > longest ) {
4783 _ext_node_with_longest_txt_info = longest_txt_node;
4784 if ( longest >= max_possible_length ) {
4785 _longest_ext_node_info = max_possible_length;
4788 _longest_ext_node_info = longest;
4790 _length_of_longest_text = calcLengthOfLongestText();
4793 final void calculateScaleDistance() {
4794 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
4797 final double height = getMaxDistanceToRoot();
4799 if ( ( height <= 0.5 ) ) {
4800 setScaleDistance( 0.01 );
4802 else if ( height <= 5.0 ) {
4803 setScaleDistance( 0.1 );
4805 else if ( height <= 50.0 ) {
4806 setScaleDistance( 1 );
4808 else if ( height <= 500.0 ) {
4809 setScaleDistance( 10 );
4812 setScaleDistance( 100 );
4816 setScaleDistance( 0.0 );
4818 String scale_label = String.valueOf( getScaleDistance() );
4819 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
4820 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
4822 setScaleLabel( scale_label );
4825 final Color calculateSequenceBasedColor( final Sequence seq ) {
4826 if ( ForesterUtil.isEmpty( seq.getName() ) ) {
4827 return getTreeColorSet().getSequenceColor();
4830 final String seq_name = seq.getName();
4831 c = getControlPanel().getSequenceColors().get( seq_name );
4833 c = AptxUtil.calculateColorFromString( seq_name, false );
4834 getControlPanel().getSequenceColors().put( seq_name, c );
4839 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
4840 if ( getOptions().isColorByTaxonomicGroup() ) {
4841 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4843 String group = null;
4845 group = TaxonomyUtil.getTaxGroupByTaxCode( tax.getTaxonomyCode() );
4847 catch ( final Exception e ) {
4850 if ( !ex && !ForesterUtil.isEmpty( group ) ) {
4851 final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group );
4857 return getTreeColorSet().getTaxonomyColor();
4860 if ( ForesterUtil.isEmpty( tax.getTaxonomyCode() ) && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4861 return getTreeColorSet().getTaxonomyColor();
4864 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4865 c = getControlPanel().getSpeciesColors().get( tax.getTaxonomyCode() );
4867 if ( ( c == null ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4868 c = getControlPanel().getSpeciesColors().get( tax.getScientificName() );
4871 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4872 c = AptxUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
4873 getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c );
4876 c = AptxUtil.calculateColorFromString( tax.getScientificName(), true );
4877 getControlPanel().getSpeciesColors().put( tax.getScientificName(), c );
4884 void clearCurrentExternalNodesDataBuffer() {
4885 setCurrentExternalNodesDataBuffer( new StringBuilder() );
4889 * Collapse the tree from the given node
4894 final void collapse( final PhylogenyNode node ) {
4895 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4896 JOptionPane.showMessageDialog( this,
4897 "Cannot collapse in unrooted display type",
4898 "Attempt to collapse in unrooted display",
4899 JOptionPane.WARNING_MESSAGE );
4902 if ( !node.isExternal() && !node.isRoot() ) {
4903 final boolean collapse = !node.isCollapse();
4904 TreePanelUtil.collapseSubtree( node, collapse );
4905 updateSetOfCollapsedExternalNodes();
4906 _phylogeny.recalculateNumberOfExternalDescendants( true );
4907 resetNodeIdToDistToLeafMap();
4908 calculateLongestExtNodeInfo();
4909 setNodeInPreorderToNull();
4910 _control_panel.displayedPhylogenyMightHaveChanged( true );
4911 resetPreferredSize();
4913 _main_panel.adjustJScrollPane();
4918 final void uncollapseAll( final PhylogenyNode node ) {
4919 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4920 JOptionPane.showMessageDialog( this,
4921 "Cannot uncollapse in unrooted display type",
4922 "Attempt to uncollapse in unrooted display",
4923 JOptionPane.WARNING_MESSAGE );
4926 if ( !node.isExternal() ) {
4927 TreePanelUtil.uncollapseSubtree( node );
4928 updateSetOfCollapsedExternalNodes();
4929 _phylogeny.recalculateNumberOfExternalDescendants( true );
4930 resetNodeIdToDistToLeafMap();
4931 calculateLongestExtNodeInfo();
4932 setNodeInPreorderToNull();
4933 _control_panel.displayedPhylogenyMightHaveChanged( true );
4934 resetPreferredSize();
4936 _main_panel.adjustJScrollPane();
4941 final void collapseSpeciesSpecificSubtrees() {
4942 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4946 TreePanelUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
4947 updateSetOfCollapsedExternalNodes();
4948 _phylogeny.recalculateNumberOfExternalDescendants( true );
4949 resetNodeIdToDistToLeafMap();
4950 calculateLongestExtNodeInfo();
4951 setNodeInPreorderToNull();
4952 resetPreferredSize();
4953 resetDepthCollapseDepthValue();
4954 resetRankCollapseRankValue();
4955 _main_panel.adjustJScrollPane();
4956 getControlPanel().showWhole();
4960 final void colorRank( final String rank ) {
4961 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4965 AptxUtil.removeBranchColors( _phylogeny );
4966 final int colorizations = TreePanelUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
4967 if ( colorizations > 0 ) {
4968 _control_panel.setColorBranches( true );
4969 if ( _control_panel.getUseVisualStylesCb() != null ) {
4970 _control_panel.getUseVisualStylesCb().setSelected( true );
4972 if ( _control_panel.getColorAccSpeciesCb() != null ) {
4973 _control_panel.getColorAccSpeciesCb().setSelected( false );
4975 _options.setColorLabelsSameAsParentBranch( true );
4976 if ( getMainPanel().getMainFrame()._color_labels_same_as_parent_branch != null ) {
4977 getMainPanel().getMainFrame()._color_labels_same_as_parent_branch.setSelected( true );
4979 _control_panel.repaint();
4983 if ( colorizations > 0 ) {
4984 String msg = "Taxonomy colorization via " + rank + " completed:\n";
4985 if ( colorizations > 1 ) {
4986 msg += "colorized " + colorizations + " subtrees";
4989 msg += "colorized one subtree";
4992 JOptionPane.showMessageDialog( this,
4994 "Taxonomy Rank-Colorization Completed (" + rank + ")",
4995 JOptionPane.INFORMATION_MESSAGE );
4998 String msg = "Could not taxonomy rank-colorize any subtree via " + rank + ".\n";
4999 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
5000 msg += "select a different rank (e.g. phylum, genus, ...)\n";
5002 msg += "execute:\n";
5003 msg += "1. \"" + MainFrame.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
5004 msg += "2. \"" + MainFrame.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
5005 JOptionPane.showMessageDialog( this,
5007 "Taxonomy Rank-Colorization Failed",
5008 JOptionPane.WARNING_MESSAGE );
5012 final void confColor() {
5013 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
5017 AptxUtil.removeBranchColors( _phylogeny );
5018 TreePanelUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
5019 _control_panel.setColorBranches( true );
5020 if ( _control_panel.getUseVisualStylesCb() != null ) {
5021 _control_panel.getUseVisualStylesCb().setSelected( true );
5027 final void decreaseDomainStructureEvalueThresholdExp() {
5028 if ( _domain_structure_e_value_thr_exp > -20 ) {
5029 _domain_structure_e_value_thr_exp -= 1;
5034 * Find the node, if any, at the given location
5038 * @return pointer to the node at x,y, null if not found
5040 public final PhylogenyNode findNode( final int x, final int y ) {
5041 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
5044 final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE;
5045 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
5046 final PhylogenyNode node = iter.next();
5047 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
5048 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
5049 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
5050 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
5051 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
5058 final Configuration getConfiguration() {
5059 return _configuration;
5062 final ControlPanel getControlPanel() {
5063 return _control_panel;
5066 String getCurrentExternalNodesDataBufferAsString() {
5067 return _current_external_nodes_data_buffer.toString();
5070 int getCurrentExternalNodesDataBufferChangeCounter() {
5071 return _current_external_nodes_data_buffer_change_counter;
5074 final int getDomainStructureEvalueThresholdExp() {
5075 return _domain_structure_e_value_thr_exp;
5078 public final Set<Long> getFoundNodes0() {
5079 return _found_nodes_0;
5082 public final Set<Long> getFoundNodes1() {
5083 return _found_nodes_1;
5086 public List<PhylogenyNode> getFoundNodesAsListOfPhylogenyNodes() {
5087 final List<PhylogenyNode> additional_nodes = new ArrayList<PhylogenyNode>();
5088 if ( getFoundNodes0() != null ) {
5089 for( final Long id : getFoundNodes0() ) {
5090 final PhylogenyNode n = _phylogeny.getNode( id );
5092 additional_nodes.add( n );
5096 if ( getFoundNodes1() != null ) {
5097 for( final Long id : getFoundNodes1() ) {
5098 if ( ( getFoundNodes0() == null ) || !getFoundNodes0().contains( id ) ) {
5099 final PhylogenyNode n = _phylogeny.getNode( id );
5101 additional_nodes.add( n );
5106 return additional_nodes;
5109 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
5110 if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
5111 return ( PhylogenyMethods.getBranchColorValue( node ) );
5114 return ( getTreeColorSet().getBranchColor() );
5118 final int getLongestExtNodeInfo() {
5119 return _longest_ext_node_info;
5122 final Options getOptions() {
5123 if ( _options == null ) {
5124 _options = getControlPanel().getOptions();
5129 final Rectangle2D getOvRectangle() {
5130 return _ov_rectangle;
5133 final Rectangle getOvVirtualRectangle() {
5134 return _ov_virtual_rectangle;
5137 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
5138 return _graphics_type;
5141 final Color getSequenceBasedColor( final PhylogenyNode node ) {
5142 if ( node.getNodeData().isHasSequence() ) {
5143 return calculateSequenceBasedColor( node.getNodeData().getSequence() );
5145 // return non-colorized color
5146 return getTreeColorSet().getSequenceColor();
5149 final double getStartingAngle() {
5150 return _urt_starting_angle;
5153 DescriptiveStatistics getStatisticsForExpressionValues() {
5154 return _statistics_for_vector_data;
5157 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
5158 if ( node.isExternal() && node.getNodeData().isHasTaxonomy() ) {
5159 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
5161 // return non-colorized color
5162 return getTreeColorSet().getTaxonomyColor();
5165 public final File getTreeFile() {
5169 final float getXcorrectionFactor() {
5170 return _x_correction_factor;
5173 final float getXdistance() {
5177 final float getYdistance() {
5181 final void increaseDomainStructureEvalueThresholdExp() {
5182 if ( _domain_structure_e_value_thr_exp < 3 ) {
5183 _domain_structure_e_value_thr_exp += 1;
5187 final void initNodeData() {
5188 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
5191 double _max_original_domain_structure_width = 0.0;
5192 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
5193 if ( node.getNodeData().isHasSequence()
5194 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
5195 RenderableDomainArchitecture rds = null;
5196 if ( !( node.getNodeData().getSequence()
5197 .getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
5198 if ( SPECIAL_DOMAIN_COLORING ) {
5199 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence()
5200 .getDomainArchitecture(), node.getName() );
5203 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence()
5204 .getDomainArchitecture() );
5206 node.getNodeData().getSequence().setDomainArchitecture( rds );
5209 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
5211 if ( getControlPanel().isShowDomainArchitectures() ) {
5212 final double dsw = rds.getOriginalSize().getWidth();
5213 if ( dsw > _max_original_domain_structure_width ) {
5214 _max_original_domain_structure_width = dsw;
5219 if ( getControlPanel().isShowDomainArchitectures() ) {
5220 final float ds_factor_width = ( float ) ( _domain_structure_width / _max_original_domain_structure_width );
5221 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
5222 if ( node.getNodeData().isHasSequence()
5223 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
5224 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
5225 .getSequence().getDomainArchitecture();
5226 rds.setRenderingFactorWidth( ds_factor_width );
5227 rds.setParameter( _domain_structure_e_value_thr_exp );
5233 final boolean inOv( final MouseEvent e ) {
5234 return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) )
5235 && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) )
5236 && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) )
5237 && ( e.getY() < ( ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) );
5240 final boolean inOvRectangle( final MouseEvent e ) {
5241 return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) )
5242 && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) )
5243 && ( e.getY() >= ( getOvRectangle().getY() - 1 ) )
5244 && ( e.getY() <= ( getOvRectangle().getY() + getOvRectangle().getHeight() + 1 ) ) );
5247 final boolean isCanCollapse() {
5248 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5251 final boolean isCanUncollapseAll( final PhylogenyNode node ) {
5252 if ( node.isExternal() || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
5255 if ( node.isCollapse() ) {
5258 final PhylogenyNodeIterator it = new PreorderTreeIterator( node );
5259 while ( it.hasNext() ) {
5260 if ( it.next().isCollapse() ) {
5267 final boolean isCanColorSubtree() {
5268 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5271 final boolean isCanCopy() {
5272 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
5275 final boolean isCanCut( final PhylogenyNode node ) {
5276 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
5277 && !node.isRoot() );
5280 final boolean isCanDelete() {
5281 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
5284 final boolean isCanPaste() {
5285 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
5286 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
5289 final boolean isCanReroot() {
5290 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
5293 final boolean isCanSubtree( final PhylogenyNode node ) {
5294 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal()
5295 && ( !node.isRoot() || ( _subtree_index > 0 ) ) );
5298 public final boolean isCurrentTreeIsSubtree() {
5299 return ( _subtree_index > 0 );
5302 final boolean isEdited() {
5306 final boolean isInOvRect() {
5310 final boolean isOvOn() {
5314 final boolean isPhyHasBranchLengths() {
5315 return _phy_has_branch_lengths;
5318 final void midpointRoot() {
5319 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
5322 if ( !_phylogeny.isRerootable() ) {
5323 JOptionPane.showMessageDialog( this,
5324 "This is not rerootable",
5326 JOptionPane.WARNING_MESSAGE );
5329 setNodeInPreorderToNull();
5331 PhylogenyMethods.midpointRoot( _phylogeny );
5332 resetNodeIdToDistToLeafMap();
5338 final void mouseClicked( final MouseEvent e ) {
5339 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
5340 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
5341 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
5342 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) )
5344 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) )
5352 final double max_x = getWidth() - getVisibleRect().width;
5353 final double max_y = getHeight() - getVisibleRect().height;
5360 getMainPanel().getCurrentScrollPane().getViewport()
5361 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
5362 setInOvRect( true );
5366 final PhylogenyNode node = findNode( e.getX(), e.getY() );
5367 if ( node != null ) {
5368 if ( !node.isRoot() && node.getParent().isCollapse() ) {
5371 _highlight_node = node;
5372 // Check if shift key is down
5373 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
5374 // Yes, so add to _found_nodes
5375 if ( getFoundNodes0() == null ) {
5376 setFoundNodes0( new HashSet<Long>() );
5378 getFoundNodes0().add( node.getId() );
5379 // Check if control key is down
5381 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
5382 // Yes, so pop-up menu
5383 displayNodePopupMenu( node, e.getX(), e.getY() );
5384 // Handle unadorned click
5387 // Check for right mouse button
5388 if ( e.getModifiers() == 4 ) {
5389 displayNodePopupMenu( node, e.getX(), e.getY() );
5392 // if not in _found_nodes, clear _found_nodes
5393 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
5398 // no node was clicked so partition tree instead
5399 _highlight_node = null;
5401 _clicked_x = e.getX();
5402 if (!getPhylogeny().isEmpty()) {
5404 PhylogenyNode furthestNode = PhylogenyMethods.calculateNodeWithMaxDistanceToRoot( _phylogeny );
5405 _furthest_node_x = furthestNode.getXcoord();
5406 _root_x = _phylogeny.getRoot().getXcoord();
5408 // don't bother if 0 distance tree or clicked x lies outside of tree
5409 if (_furthest_node_x != _root_x && !(_clicked_x < _root_x || _clicked_x > _furthest_node_x))
5411 _partition_tree = true;
5422 final void mouseDragInBrowserPanel( final MouseEvent e ) {
5423 setCursor( MOVE_CURSOR );
5424 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
5425 scroll_position.x -= ( e.getX() - getLastDragPointX() );
5426 scroll_position.y -= ( e.getY() - getLastDragPointY() );
5427 if ( scroll_position.x < 0 ) {
5428 scroll_position.x = 0;
5431 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
5432 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
5433 if ( scroll_position.x > max_x ) {
5434 scroll_position.x = max_x;
5437 if ( scroll_position.y < 0 ) {
5438 scroll_position.y = 0;
5441 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
5442 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
5443 if ( scroll_position.y > max_y ) {
5444 scroll_position.y = max_y;
5447 if ( isOvOn() || getOptions().isShowScale() ) {
5450 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
5453 final void mouseDragInOvRectangle( final MouseEvent e ) {
5454 setCursor( HAND_CURSOR );
5455 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
5456 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
5457 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
5458 double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) );
5459 double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) );
5460 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
5461 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
5462 if ( scroll_position.x <= 0 ) {
5463 scroll_position.x = 0;
5467 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
5468 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
5469 if ( scroll_position.x >= max_x ) {
5471 scroll_position.x = max_x;
5474 if ( scroll_position.y <= 0 ) {
5476 scroll_position.y = 0;
5479 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
5480 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
5481 if ( scroll_position.y >= max_y ) {
5483 scroll_position.y = max_y;
5487 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
5488 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
5489 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
5492 final void mouseMoved( final MouseEvent e ) {
5493 requestFocusInWindow();
5494 if ( _current_external_nodes != null ) {
5495 _current_external_nodes = null;
5498 if ( getControlPanel().isNodeDescPopup() ) {
5499 if ( _node_desc_popup != null ) {
5500 _node_desc_popup.hide();
5501 _node_desc_popup = null;
5504 if ( getOptions().isShowOverview() && isOvOn() ) {
5505 if ( inOvVirtualRectangle( e ) ) {
5506 if ( !isInOvRect() ) {
5507 setInOvRect( true );
5512 if ( isInOvRect() ) {
5513 setInOvRect( false );
5518 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
5527 final PhylogenyNode node = findNode( e.getX(), e.getY() );
5528 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
5529 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.GET_EXT_DESC_DATA ) ) {
5530 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
5531 addToCurrentExternalNodes( n.getId() );
5533 setCursor( HAND_CURSOR );
5536 else if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
5537 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
5538 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
5539 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
5540 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
5541 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
5542 setCursor( CUT_CURSOR );
5545 setCursor( HAND_CURSOR );
5546 if ( getControlPanel().isNodeDescPopup() ) {
5547 showNodeDataPopup( e, node );
5552 setCursor( ARROW_CURSOR );
5557 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
5558 setCursor( ARROW_CURSOR );
5561 final void multiplyUrtFactor( final float f ) {
5565 final void paintBranchCircular( final PhylogenyNode p,
5566 final PhylogenyNode c,
5568 final boolean radial_labels,
5569 final boolean to_pdf,
5570 final boolean to_graphics_file ) {
5571 final double angle = _urt_nodeid_angle_map.get( c.getId() );
5572 final double root_x = _root.getXcoord();
5573 final double root_y = _root.getYcoord();
5574 final double dx = root_x - p.getXcoord();
5575 final double dy = root_y - p.getYcoord();
5576 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
5577 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
5578 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
5579 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
5580 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
5581 final double r2 = 2.0 * parent_radius;
5582 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
5584 drawLine( c.getXcoord(),
5586 root_x + ( Math.cos( angle ) * parent_radius ),
5587 root_y + ( Math.sin( angle ) * parent_radius ),
5589 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file );
5590 if ( c.isExternal() ) {
5591 final boolean is_in_found_nodes = isInFoundNodes0( c ) || isInFoundNodes1( c )
5592 || isInCurrentExternalNodes( c );
5593 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
5594 && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
5597 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
5601 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
5602 final double angle = _urt_nodeid_angle_map.get( c.getId() );
5603 final double root_x = _root.getXSecondary();
5604 final double root_y = _root.getYSecondary();
5605 final double dx = root_x - p.getXSecondary();
5606 final double dy = root_y - p.getYSecondary();
5607 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
5608 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
5609 g.setColor( getTreeColorSet().getOvColor() );
5610 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
5611 final double r2 = 2.0 * parent_radius;
5612 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
5614 drawLine( c.getXSecondary(),
5616 root_x + ( Math.cos( angle ) * parent_radius ),
5617 root_y + ( Math.sin( angle ) * parent_radius ),
5619 if ( isInFoundNodes( c ) || isInCurrentExternalNodes( c ) ) {
5620 g.setColor( getColorForFoundNode( c ) );
5621 drawRectFilled( c.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
5622 c.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
5623 OVERVIEW_FOUND_NODE_BOX_SIZE,
5624 OVERVIEW_FOUND_NODE_BOX_SIZE,
5629 final void paintCircular( final Phylogeny phy,
5630 final double starting_angle,
5635 final boolean to_pdf,
5636 final boolean to_graphics_file ) {
5637 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
5638 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
5639 _root = phy.getRoot();
5640 _root.setXcoord( center_x );
5641 _root.setYcoord( center_y );
5642 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
5643 double current_angle = starting_angle;
5645 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
5646 final PhylogenyNode n = it.next();
5647 if ( !n.isCollapse() ) {
5648 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
5649 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
5650 _urt_nodeid_angle_map.put( n.getId(), current_angle );
5651 _urt_nodeid_index_map.put( n.getId(), i++ );
5652 current_angle += ( TWO_PI / circ_num_ext_nodes );
5656 System.out.println( "is collapse" + n.getName() );
5659 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
5660 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file );
5663 final void paintCircularLite( final Phylogeny phy,
5664 final double starting_angle,
5668 final Graphics2D g ) {
5669 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
5670 _root = phy.getRoot();
5671 _root.setXSecondary( center_x );
5672 _root.setYSecondary( center_y );
5673 double current_angle = starting_angle;
5674 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
5675 final PhylogenyNode n = it.next();
5676 n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
5677 n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
5678 _urt_nodeid_angle_map.put( n.getId(), current_angle );
5679 current_angle += ( TWO_PI / circ_num_ext_nodes );
5681 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
5684 public final void paintFile( final Graphics2D g,
5685 final boolean to_pdf,
5686 final int graphics_file_width,
5687 final int graphics_file_height,
5688 final int graphics_file_x,
5689 final int graphics_file_y ) {
5690 paintPhylogeny(g,to_pdf,true,graphics_file_width,graphics_file_height,graphics_file_x,graphics_file_y);
5692 final void paintPhylogeny( final Graphics2D g,
5693 final boolean to_pdf,
5694 final boolean to_graphics_file,
5695 final int graphics_file_width,
5696 final int graphics_file_height,
5697 final int graphics_file_x,
5698 final int graphics_file_y ) {
5700 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
5703 if ( _control_panel.isShowSequenceRelations() ) {
5704 _query_sequence = _control_panel.getSelectedQuerySequence();
5706 // Color the background
5708 final Rectangle r = getVisibleRect();
5709 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
5710 g.setColor( getTreeColorSet().getBackgroundColor() );
5711 if ( !to_graphics_file ) {
5715 if ( getOptions().isPrintBlackAndWhite() ) {
5716 g.setColor( Color.WHITE );
5718 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
5722 if ( !to_graphics_file ) {
5723 g.setPaint( new GradientPaint( r.x,
5725 getTreeColorSet().getBackgroundColor(),
5728 getTreeColorSet().getBackgroundColorGradientBottom() ) );
5732 g.setPaint( new GradientPaint( graphics_file_x,
5734 getTreeColorSet().getBackgroundColor(),
5736 graphics_file_y + graphics_file_height,
5737 getTreeColorSet().getBackgroundColorGradientBottom() ) );
5738 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
5744 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
5746 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
5747 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5748 _external_node_index = 0;
5749 // Position starting X of tree
5750 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/ ) {
5751 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
5753 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
5754 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE
5755 + ( _phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor() ) ) );
5758 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
5760 // Position starting Y of tree
5761 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
5762 + ( TreePanel.MOVE / 2.0f ) );
5763 final int dynamic_hiding_factor = calcDynamicHidingFactor();
5764 if ( getControlPanel().isDynamicallyHideData() ) {
5765 if ( dynamic_hiding_factor > 1 ) {
5766 getControlPanel().setDynamicHidingIsOn( true );
5769 getControlPanel().setDynamicHidingIsOn( false );
5772 if ( _nodes_in_preorder == null ) {
5773 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
5775 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
5776 _nodes_in_preorder[ i++ ] = it.next();
5779 final boolean disallow_shortcutting = ( dynamic_hiding_factor < 40 )
5780 /* || getControlPanel().isUseVisualStyles() || getOptions().isShowDefaultNodeShapesForMarkedNodes()*/ //TODO check if this is really not needed.
5781 || to_graphics_file || to_pdf;
5782 for( final PhylogenyNode element : _nodes_in_preorder ) {
5783 paintNodeRectangular( g,
5786 getControlPanel().isDynamicallyHideData() && ( dynamic_hiding_factor > 1 ),
5787 dynamic_hiding_factor,
5789 disallow_shortcutting );
5791 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
5792 if ( !( to_graphics_file || to_pdf ) ) {
5795 getVisibleRect().y + getVisibleRect().height,
5800 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
5803 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5804 paintPhylogenyLite( g );
5807 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5808 if ( getControlPanel().getDynamicallyHideData() != null ) {
5809 getControlPanel().setDynamicHidingIsOn( false );
5811 final double angle = getStartingAngle();
5812 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
5813 _dynamic_hiding_factor = 0;
5814 if ( getControlPanel().isDynamicallyHideData() ) {
5815 _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5
5816 * getPhylogeny().getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
5818 if ( getControlPanel().getDynamicallyHideData() != null ) {
5819 if ( _dynamic_hiding_factor > 1 ) {
5820 getControlPanel().setDynamicHidingIsOn( true );
5823 getControlPanel().setDynamicHidingIsOn( false );
5826 paintUnrooted( _phylogeny.getRoot(),
5828 ( float ) ( angle + ( 2 * Math.PI ) ),
5833 if ( getOptions().isShowScale() ) {
5834 if ( !( to_graphics_file || to_pdf ) ) {
5837 getVisibleRect().y + getVisibleRect().height,
5842 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
5845 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5846 g.setColor( getTreeColorSet().getOvColor() );
5847 paintUnrootedLite( _phylogeny.getRoot(),
5849 angle + ( 2 * Math.PI ),
5851 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
5852 paintOvRectangle( g );
5855 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
5856 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() )
5857 / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
5858 final int d = radius + MOVE + getLongestExtNodeInfo();
5859 _dynamic_hiding_factor = 0;
5860 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
5861 _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5
5862 * getPhylogeny().getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
5864 if ( getControlPanel().getDynamicallyHideData() != null ) {
5865 if ( _dynamic_hiding_factor > 1 ) {
5866 getControlPanel().setDynamicHidingIsOn( true );
5869 getControlPanel().setDynamicHidingIsOn( false );
5872 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
5873 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
5874 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
5875 : getOvMaxWidth() / 2 );
5876 double x_scale = 1.0;
5877 double y_scale = 1.0;
5878 int x_pos = getVisibleRect().x + getOvXPosition();
5879 int y_pos = getVisibleRect().y + getOvYPosition();
5880 if ( getWidth() > getHeight() ) {
5881 x_scale = ( double ) getHeight() / getWidth();
5882 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
5885 y_scale = ( double ) getWidth() / getHeight();
5886 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
5888 _at = g.getTransform();
5889 g.scale( x_scale, y_scale );
5890 paintCircularLite( _phylogeny,
5894 ( int ) ( radius_ov - ( getLongestExtNodeInfo()
5895 / ( getVisibleRect().width / getOvRectangle().getWidth() ) ) ),
5897 g.setTransform( _at );
5898 paintOvRectangle( g );
5903 if (_partition_tree) {
5904 g.setColor( Color.BLACK );
5905 _partition_threshold = (_clicked_x - _root_x) / (_furthest_node_x - _root_x);
5906 drawLine( _clicked_x, 0, _clicked_x, getHeight(),g);
5911 final void recalculateMaxDistanceToRoot() {
5912 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
5913 if ( getPhylogeny().getRoot().getDistanceToParent() > 0 ) {
5914 _max_distance_to_root += getPhylogeny().getRoot().getDistanceToParent();
5919 * Remove all edit-node frames
5921 final void removeAllEditNodeJFrames() {
5922 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
5923 if ( _node_frames[ i ] != null ) {
5924 _node_frames[ i ].dispose();
5925 _node_frames[ i ] = null;
5928 _node_frame_index = 0;
5932 * Remove a node-edit frame.
5934 final void removeEditNodeFrame( final int i ) {
5935 _node_frame_index--;
5936 _node_frames[ i ] = null;
5937 if ( i < _node_frame_index ) {
5938 for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) {
5939 _node_frames[ j ] = _node_frames[ j + 1 ];
5941 _node_frames[ _node_frame_index ] = null;
5945 final void reRoot( final PhylogenyNode node ) {
5946 if ( !getPhylogeny().isRerootable() ) {
5947 JOptionPane.showMessageDialog( this,
5948 "This is not rerootable",
5950 JOptionPane.WARNING_MESSAGE );
5953 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5954 JOptionPane.showMessageDialog( this,
5955 "Cannot reroot in unrooted display type",
5956 "Attempt to reroot tree in unrooted display",
5957 JOptionPane.WARNING_MESSAGE );
5960 getPhylogeny().reRoot( node );
5961 getPhylogeny().recalculateNumberOfExternalDescendants( true );
5962 resetNodeIdToDistToLeafMap();
5963 setNodeInPreorderToNull();
5964 resetPreferredSize();
5965 getMainPanel().adjustJScrollPane();
5968 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
5969 getControlPanel().showWhole();
5973 final void resetNodeIdToDistToLeafMap() {
5974 _nodeid_dist_to_leaf = new HashMap<Long, Short>();
5977 final void resetPreferredSize() {
5978 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
5984 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
5985 if ( getControlPanel().isDrawPhylogram() ) {
5986 x = TreePanel.MOVE + getLongestExtNodeInfo()
5987 + ForesterUtil.roundToInt( ( getXcorrectionFactor()
5988 * getPhylogeny().calculateHeight( !_options.isCollapsedWithAverageHeigh() ) )
5992 if ( !isNonLinedUpCladogram() ) {
5993 x = TreePanel.MOVE + getLongestExtNodeInfo() + ForesterUtil
5994 .roundToInt( getXdistance() * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
5997 x = TreePanel.MOVE + getLongestExtNodeInfo() + ForesterUtil
5998 .roundToInt( getXdistance() * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
6001 setPreferredSize( new Dimension( x, y ) );
6004 final void selectNode( final PhylogenyNode node ) {
6005 if ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) ) {
6006 getFoundNodes0().remove( node.getId() );
6007 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
6008 if ( getFoundNodes0().size() < 1 ) {
6009 getControlPanel().searchReset0();
6013 getControlPanel().getSearchFoundCountsLabel0().setVisible( true );
6014 getControlPanel().getSearchResetButton0().setEnabled( true );
6015 getControlPanel().getSearchResetButton0().setVisible( true );
6016 if ( getFoundNodes0() == null ) {
6017 setFoundNodes0( new HashSet<Long>() );
6019 getFoundNodes0().add( node.getId() );
6020 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
6024 final void setArrowCursor() {
6025 setCursor( ARROW_CURSOR );
6029 final void setControlPanel( final ControlPanel atv_control ) {
6030 _control_panel = atv_control;
6033 void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
6034 increaseCurrentExternalNodesDataBufferChangeCounter();
6035 _current_external_nodes_data_buffer = sb;
6038 public final void setFoundNodes0( final Set<Long> found_nodes ) {
6039 _found_nodes_0 = found_nodes;
6042 public final void setFoundNodes1( final Set<Long> found_nodes ) {
6043 _found_nodes_1 = found_nodes;
6046 final void setInOvRect( final boolean in_ov_rect ) {
6047 _in_ov_rect = in_ov_rect;
6050 final void setLargeFonts() {
6051 getTreeFontSet().largeFonts();
6054 final void setLastMouseDragPointX( final float x ) {
6055 _last_drag_point_x = x;
6058 final void setLastMouseDragPointY( final float y ) {
6059 _last_drag_point_y = y;
6062 final void setMediumFonts() {
6063 getTreeFontSet().mediumFonts();
6066 final void setNodeInPreorderToNull() {
6067 _nodes_in_preorder = null;
6070 final void setOvOn( final boolean ov_on ) {
6074 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
6075 _graphics_type = graphics_type;
6079 final void setSmallFonts() {
6080 getTreeFontSet().smallFonts();
6083 final void setStartingAngle( final double starting_angle ) {
6084 _urt_starting_angle = starting_angle;
6087 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
6088 _statistics_for_vector_data = statistics_for_expression_values;
6091 final void setSuperTinyFonts() {
6092 getTreeFontSet().superTinyFonts();
6095 final void setTextAntialias() {
6096 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
6097 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
6098 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
6101 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
6104 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
6105 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
6107 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
6109 // catch ( final Throwable e ) {
6110 // _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
6114 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
6115 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
6119 final void setTinyFonts() {
6120 getTreeFontSet().tinyFonts();
6123 public final void setTreeFile( final File treefile ) {
6124 _treefile = treefile;
6127 final void setXcorrectionFactor( final float f ) {
6128 _x_correction_factor = f;
6131 final void setXdistance( final float x ) {
6135 final void setYdistance( final float y ) {
6139 final void sortDescendants( final PhylogenyNode node ) {
6140 if ( !node.isExternal() ) {
6141 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
6142 if ( getControlPanel().isShowTaxonomyScientificNames() || getControlPanel().isShowTaxonomyCode() ) {
6143 pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
6145 else if ( getControlPanel().isShowSeqNames() || getControlPanel().isShowSeqSymbols()
6146 || getControlPanel().isShowGeneNames() ) {
6147 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
6149 PhylogenyMethods.sortNodeDescendents( node, pri );
6150 setNodeInPreorderToNull();
6151 _phylogeny.externalNodesHaveChanged();
6152 _phylogeny.clearHashIdToNodeMap();
6153 _phylogeny.recalculateNumberOfExternalDescendants( true );
6154 resetNodeIdToDistToLeafMap();
6160 final void subTree( final PhylogenyNode node ) {
6161 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
6162 JOptionPane.showMessageDialog( this,
6163 "Cannot get a sub/super tree in unrooted display",
6164 "Attempt to get sub/super tree in unrooted display",
6165 JOptionPane.WARNING_MESSAGE );
6168 if ( node.isExternal() ) {
6169 JOptionPane.showMessageDialog( this,
6170 "Cannot get a subtree of a external node",
6171 "Attempt to get subtree of external node",
6172 JOptionPane.WARNING_MESSAGE );
6175 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
6176 JOptionPane.showMessageDialog( this,
6177 "Cannot get a subtree of the root node",
6178 "Attempt to get subtree of root node",
6179 JOptionPane.WARNING_MESSAGE );
6182 setNodeInPreorderToNull();
6183 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
6184 _sub_phylogenies[ _subtree_index ] = _phylogeny;
6185 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
6187 _phylogeny = TreePanelUtil.subTree( node, _phylogeny );
6188 if ( _phylogeny.getRoot().isCollapse() ) {
6189 _phylogeny.getRoot().setCollapse( false );
6191 _phylogeny.externalNodesHaveChanged();
6192 _phylogeny.clearHashIdToNodeMap();
6193 _phylogeny.recalculateNumberOfExternalDescendants( true );
6194 updateSubSuperTreeButton();
6195 getMainPanel().getControlPanel().search0();
6196 getMainPanel().getControlPanel().search1();
6197 resetRankCollapseRankValue();
6198 resetDepthCollapseDepthValue();
6199 getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
6200 getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay();
6201 getMainPanel().getControlPanel().updateRankCollapseRankDisplay();
6203 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
6206 _main_panel.getControlPanel().showWhole();
6210 final void superTree() {
6211 setNodeInPreorderToNull();
6212 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
6213 for( final PhylogenyNode n : temp_root.getDescendants() ) {
6214 n.setParent( temp_root );
6216 _sub_phylogenies[ _subtree_index ] = null;
6217 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
6218 _phylogeny = _sub_phylogenies[ --_subtree_index ];
6219 _phylogeny.externalNodesHaveChanged();
6220 _phylogeny.clearHashIdToNodeMap();
6221 _phylogeny.recalculateNumberOfExternalDescendants( true );
6222 getMainPanel().getControlPanel().search0();
6223 getMainPanel().getControlPanel().search1();
6224 resetRankCollapseRankValue();
6225 resetDepthCollapseDepthValue();
6226 getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
6227 getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay();
6228 getMainPanel().getControlPanel().updateRankCollapseRankDisplay();
6229 updateSubSuperTreeButton();
6232 final void orderSubtree( final PhylogenyNode node ) {
6233 if ( node.isExternal() ) {
6236 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
6237 if ( getControlPanel().isShowTaxonomyScientificNames() || getControlPanel().isShowTaxonomyCode() ) {
6238 pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
6240 else if ( getControlPanel().isShowSeqNames() || getControlPanel().isShowSeqSymbols()
6241 || getControlPanel().isShowGeneNames() ) {
6242 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
6244 PhylogenyMethods.orderAppearanceX( node, true, pri );
6245 setNodeInPreorderToNull();
6246 getPhylogeny().externalNodesHaveChanged();
6247 getPhylogeny().clearHashIdToNodeMap();
6248 getPhylogeny().recalculateNumberOfExternalDescendants( true );
6249 resetNodeIdToDistToLeafMap();
6251 getControlPanel().displayedPhylogenyMightHaveChanged( true );
6255 final void swap( final PhylogenyNode node ) {
6256 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
6259 if ( node.getNumberOfDescendants() > 2 ) {
6260 JOptionPane.showMessageDialog( this,
6261 "Cannot swap descendants of nodes with more than 2 descendants",
6262 "Cannot swap descendants",
6263 JOptionPane.ERROR_MESSAGE );
6266 if ( !node.isExternal() ) {
6267 node.swapChildren();
6268 setNodeInPreorderToNull();
6269 _phylogeny.externalNodesHaveChanged();
6270 _phylogeny.clearHashIdToNodeMap();
6271 _phylogeny.recalculateNumberOfExternalDescendants( true );
6272 resetNodeIdToDistToLeafMap();
6278 final void taxColor() {
6279 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
6283 TreePanelUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
6284 _control_panel.setColorBranches( true );
6285 if ( _control_panel.getUseVisualStylesCb() != null ) {
6286 _control_panel.getUseVisualStylesCb().setSelected( true );
6293 final void updateOvSettings() {
6294 switch ( getOptions().getOvPlacement() ) {
6296 setOvXPosition( OV_BORDER );
6297 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
6298 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
6301 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
6302 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
6303 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
6306 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
6307 setOvYPosition( OV_BORDER );
6308 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
6311 setOvXPosition( OV_BORDER );
6312 setOvYPosition( OV_BORDER );
6313 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
6318 final void updateOvSizes() {
6319 if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) )
6320 || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) {
6322 float l = getLongestExtNodeInfo();
6323 final float w_ratio = getOvMaxWidth() / getWidth();
6325 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
6326 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
6328 if ( !isNonLinedUpCladogram() ) {
6329 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
6332 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
6334 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
6335 if ( ov_xdist < 0.0 ) {
6338 if ( ydist < 0.0 ) {
6341 setOvXDistance( ov_xdist );
6342 final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() );
6344 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
6345 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
6348 setOvXcorrectionFactor( 0 );
6356 void updateSetOfCollapsedExternalNodes() {
6357 final Phylogeny phy = getPhylogeny();
6358 _collapsed_external_nodeid_set.clear();
6359 if ( phy != null ) {
6360 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
6361 final PhylogenyNode ext_node = it.next();
6362 PhylogenyNode n = ext_node;
6363 while ( !n.isRoot() ) {
6364 if ( n.isCollapse() ) {
6365 _collapsed_external_nodeid_set.add( ext_node.getId() );
6366 ext_node.setCollapse( true );
6375 final void updateSubSuperTreeButton() {
6376 if ( _subtree_index < 1 ) {
6377 getControlPanel().deactivateButtonToReturnToSuperTree();
6380 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
6384 final void updateButtonToUncollapseAll() {
6385 if ( PhylogenyMethods.isHasCollapsedNodes( _phylogeny ) ) {
6386 getControlPanel().activateButtonToUncollapseAll();
6389 getControlPanel().deactivateButtonToUncollapseAll();
6393 final void zoomInDomainStructure() {
6394 if ( _domain_structure_width < 2000 ) {
6395 _domain_structure_width *= 1.2;
6399 final void zoomOutDomainStructure() {
6400 if ( _domain_structure_width > 20 ) {
6401 _domain_structure_width *= 0.8;
6405 private final static void colorizeNodesHelper( final Color c, final PhylogenyNode node ) {
6406 if ( node.getNodeData().getNodeVisualData() == null ) {
6407 node.getNodeData().setNodeVisualData( new NodeVisualData() );
6409 node.getNodeData().getNodeVisualData().setFontColor( new Color( c.getRed(), c.getGreen(), c.getBlue() ) );
6412 final private static void drawString( final String str, final float x, final float y, final Graphics2D g ) {
6413 g.drawString( str, x, y );
6416 final private void drawStringX( final String str, final float x, final float y, final Graphics2D g ) {
6419 if ( getAttributedStringMap() == null /*&& getAttributedStringMap().containsKey(str) */ ) {
6420 final AttributedString as = new AttributedString( str );
6421 //Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);
6422 as.addAttribute( TextAttribute.FONT, g.getFont() );
6423 as.addAttribute( TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 3 );
6424 as.addAttribute( TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 3, 4 );
6425 as.addAttribute( TextAttribute.FOREGROUND, Color.BLUE, 1, 2 );
6426 as.addAttribute( TextAttribute.FOREGROUND, Color.PINK, 3, 5 );
6427 as.addAttribute( TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 2, 4 );
6428 g.drawString( as.getIterator(), x, y );
6431 g.drawString( str, x, y );
6435 private final Map<String, AttributedString> getAttributedStringMap() {
6436 return _attributed_string_map;
6439 private final void setAttributedStringMap( final Map<String, AttributedString> attributed_string_map ) {
6440 _attributed_string_map = attributed_string_map;
6443 final private static boolean plusPressed( final int key_code ) {
6444 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
6445 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON )
6446 || ( key_code == KeyEvent.VK_1 ) );
6449 public void decreaseDepthCollapseLevel() {
6450 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6451 if ( _depth_collapse_level <= 1 ) {
6452 _depth_collapse_level = PhylogenyMethods.calculateMaxDepth( _phylogeny );
6456 --_depth_collapse_level;
6457 PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level );
6462 public void increaseDepthCollapseLevel() {
6463 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6464 final int max = PhylogenyMethods.calculateMaxDepth( _phylogeny );
6465 if ( _depth_collapse_level >= max ) {
6466 _depth_collapse_level = 1;
6469 ++_depth_collapse_level;
6471 PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level );
6475 public void decreaseRankCollapseLevel() {
6476 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6477 final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny );
6478 if ( ranks.length > 1 ) {
6479 if ( _rank_collapse_level <= 0 ) {
6480 _rank_collapse_level = ranks.length - 1;
6484 --_rank_collapse_level;
6485 PhylogenyMethods.collapseToRank( _phylogeny,
6486 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6492 public void increaseRankCollapseLevel() {
6493 if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) {
6494 final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny );
6495 if ( ranks.length > 1 ) {
6496 if ( _rank_collapse_level >= ( ranks.length - 1 ) ) {
6497 _rank_collapse_level = 0;
6498 PhylogenyMethods.collapseToRank( _phylogeny,
6499 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6501 else if ( _rank_collapse_level == ( ranks.length - 2 ) ) {
6502 ++_rank_collapse_level;
6506 ++_rank_collapse_level;
6507 PhylogenyMethods.collapseToRank( _phylogeny,
6508 mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) );
6514 private final static int mapToAbsoluteRankLevel( final String present_ranks_sorted[],
6515 final int rank_collapse_level ) {
6516 final String rank_str = present_ranks_sorted[ rank_collapse_level ];
6517 if ( !TaxonomyUtil.RANK_TO_INT.containsKey( rank_str ) ) {
6518 throw new IllegalStateException( "unexpected exception: cannot find rank " + rank_str );
6520 return TaxonomyUtil.RANK_TO_INT.get( rank_str );
6523 private final void uncollapseAll() {
6524 final PhylogenyNodeIterator it = new PreorderTreeIterator( _phylogeny );
6525 while ( it.hasNext() ) {
6526 it.next().setCollapse( false );
6530 final int resetDepthCollapseDepthValue() {
6531 return _depth_collapse_level = -1;
6534 final int getDepthCollapseDepthValue() {
6535 return _depth_collapse_level;
6538 final void setDepthCollapseDepthValue( final int depth_collapse_level ) {
6539 _depth_collapse_level = depth_collapse_level;
6542 final int resetRankCollapseRankValue() {
6543 return _rank_collapse_level = -1;
6546 final int getRankCollapseRankValue() {
6547 return _rank_collapse_level;
6550 final void setRankCollapseRankValue( final int rank_collapse_level ) {
6551 _rank_collapse_level = rank_collapse_level;