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.GradientPaint;
34 import java.awt.Graphics;
35 import java.awt.Graphics2D;
36 import java.awt.Point;
37 import java.awt.Polygon;
38 import java.awt.Rectangle;
39 import java.awt.RenderingHints;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.FocusAdapter;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.InputEvent;
45 import java.awt.event.KeyAdapter;
46 import java.awt.event.KeyEvent;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseWheelEvent;
49 import java.awt.event.MouseWheelListener;
50 import java.awt.font.FontRenderContext;
51 import java.awt.font.TextLayout;
52 import java.awt.geom.AffineTransform;
53 import java.awt.geom.Arc2D;
54 import java.awt.geom.CubicCurve2D;
55 import java.awt.geom.Ellipse2D;
56 import java.awt.geom.Line2D;
57 import java.awt.geom.QuadCurve2D;
58 import java.awt.geom.Rectangle2D;
59 import java.awt.image.BufferedImage;
60 import java.awt.print.PageFormat;
61 import java.awt.print.Printable;
62 import java.awt.print.PrinterException;
64 import java.io.IOException;
65 import java.io.UnsupportedEncodingException;
67 import java.net.URISyntaxException;
68 import java.net.URLEncoder;
69 import java.text.DecimalFormat;
70 import java.text.DecimalFormatSymbols;
71 import java.text.NumberFormat;
72 import java.util.ArrayList;
73 import java.util.Collections;
74 import java.util.HashMap;
75 import java.util.HashSet;
76 import java.util.Hashtable;
77 import java.util.List;
79 import java.util.SortedSet;
81 import javax.swing.BorderFactory;
82 import javax.swing.JApplet;
83 import javax.swing.JColorChooser;
84 import javax.swing.JDialog;
85 import javax.swing.JMenuItem;
86 import javax.swing.JOptionPane;
87 import javax.swing.JPanel;
88 import javax.swing.JPopupMenu;
89 import javax.swing.JTextArea;
90 import javax.swing.Popup;
91 import javax.swing.PopupFactory;
93 import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON;
94 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
95 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
96 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
97 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
98 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
99 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
100 import org.forester.archaeopteryx.tools.Blast;
101 import org.forester.archaeopteryx.tools.ImageLoader;
102 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
103 import org.forester.phylogeny.Phylogeny;
104 import org.forester.phylogeny.PhylogenyMethods;
105 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
106 import org.forester.phylogeny.PhylogenyNode;
107 import org.forester.phylogeny.data.Annotation;
108 import org.forester.phylogeny.data.BranchColor;
109 import org.forester.phylogeny.data.Confidence;
110 import org.forester.phylogeny.data.Event;
111 import org.forester.phylogeny.data.NodeData.NODE_DATA;
112 import org.forester.phylogeny.data.NodeVisualization;
113 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
114 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
115 import org.forester.phylogeny.data.PhylogenyDataUtil;
116 import org.forester.phylogeny.data.PropertiesMap;
117 import org.forester.phylogeny.data.Property;
118 import org.forester.phylogeny.data.Sequence;
119 import org.forester.phylogeny.data.SequenceRelation;
120 import org.forester.phylogeny.data.Taxonomy;
121 import org.forester.phylogeny.data.Uri;
122 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
123 import org.forester.phylogeny.iterators.PreorderTreeIterator;
124 import org.forester.util.BasicDescriptiveStatistics;
125 import org.forester.util.DescriptiveStatistics;
126 import org.forester.util.ForesterConstants;
127 import org.forester.util.ForesterUtil;
128 import org.forester.util.SequenceIdParser;
130 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
132 private static final float PI = ( float ) ( Math.PI );
133 private static final double TWO_PI = 2 * Math.PI;
134 private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
135 private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
136 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
137 private static final short OV_BORDER = 10;
138 final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
139 final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
140 final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
141 final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
142 final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
143 private final static long serialVersionUID = -978349745916505029L;
144 private final static int EURO_D = 10;
145 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
146 private final static int MIN_ROOT_LENGTH = 3;
147 private final static int MAX_SUBTREES = 100;
148 private final static int MAX_NODE_FRAMES = 10;
149 private final static int MOVE = 20;
150 private final static NumberFormat FORMATTER_CONFIDENCE;
151 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
152 private final static int WIGGLE = 2;
153 private final static int LIMIT_FOR_HQ_RENDERING = 1000;
154 private final static int CONFIDENCE_LEFT_MARGIN = 4;
155 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
156 RenderingHints.VALUE_RENDER_DEFAULT );
157 private File _treefile = null;
158 private Configuration _configuration = null;
159 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
160 private int _node_frame_index = 0;
161 private Phylogeny _phylogeny = null;
162 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
163 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
164 private int _subtree_index = 0;
165 private MainPanel _main_panel = null;
166 private Set<Integer> _found_nodes = null;
167 private PhylogenyNode _highlight_node = null;
168 private JPopupMenu _node_popup_menu = null;
169 private JMenuItem _node_popup_menu_items[] = null;
170 private int _longest_ext_node_info = 0;
171 private float _x_correction_factor = 0.0f;
172 private float _ov_x_correction_factor = 0.0f;
173 private float _x_distance = 0.0f;
174 private float _y_distance = 0.0f;
175 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
176 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
177 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
178 private float _last_drag_point_x = 0;
179 private float _last_drag_point_y = 0;
180 private ControlPanel _control_panel = null;
181 private int _external_node_index = 0;
182 private final Polygon _polygon = new Polygon();
183 private final StringBuilder _sb = new StringBuilder();
184 private JColorChooser _color_chooser = null;
185 private double _scale_distance = 0.0;
186 private String _scale_label = null;
187 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
188 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
189 private final Line2D _line = new Line2D.Float();
190 private final Ellipse2D _ellipse = new Ellipse2D.Float();
191 private final Rectangle2D _rectangle = new Rectangle2D.Float();
192 private Options _options = null;
193 private float _ov_max_width = 0;
194 private float _ov_max_height = 0;
195 private int _ov_x_position = 0;
196 private int _ov_y_position = 0;
197 private int _ov_y_start = 0;
198 private float _ov_y_distance = 0;
199 private float _ov_x_distance = 0;
200 private boolean _ov_on = false;
201 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
202 private float _urt_factor = 1;
203 private float _urt_factor_ov = 1;
204 private final boolean _phy_has_branch_lengths;
205 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
206 private boolean _in_ov_rect = false;
207 private boolean _in_ov = false;
208 private final Rectangle _ov_virtual_rectangle = new Rectangle();
209 final private static double _180_OVER_PI = 180.0 / Math.PI;
210 private static final float ROUNDED_D = 8;
211 private int _circ_max_depth;
212 private PhylogenyNode _root;
213 final private Arc2D _arc = new Arc2D.Double();
214 final private HashMap<Integer, Double> _urt_nodeid_angle_map = new HashMap<Integer, Double>();
215 final private HashMap<Integer, Integer> _urt_nodeid_index_map = new HashMap<Integer, Integer>();
216 final private Set<Integer> _collapsed_external_nodeid_set = new HashSet<Integer>();
217 HashMap<Integer, Short> _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
218 private AffineTransform _at;
219 private double _max_distance_to_root = -1;
220 private int _dynamic_hiding_factor = 0;
221 private boolean _edited = false;
222 private Popup _node_desc_popup;
223 private JTextArea _rollover_popup;
224 private final StringBuffer _popup_buffer = new StringBuffer();
225 final private static Font POPUP_FONT = new Font( Configuration
226 .getDefaultFontFamilyName(),
229 private Sequence _query_sequence = null;
230 private final FontRenderContext _frc = new FontRenderContext( null,
233 // expression values menu:
234 private DescriptiveStatistics _statistics_for_vector_data;
235 private PhylogenyNode[] _nodes_in_preorder = null;
236 private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
237 private int _current_external_nodes_data_buffer_change_counter = 0;
238 private Set<Integer> _current_external_nodes = null;
239 // private Image offscreenImage;
240 // private Graphics offscreenGraphics;
241 // private Dimension offscreenDimension;
243 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
244 dfs.setDecimalSeparator( '.' );
245 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
246 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
249 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
250 requestFocusInWindow();
251 addKeyListener( new KeyAdapter() {
254 public void keyPressed( final KeyEvent key_event ) {
255 keyPressedCalls( key_event );
256 requestFocusInWindow();
259 addFocusListener( new FocusAdapter() {
262 public void focusGained( final FocusEvent e ) {
263 requestFocusInWindow();
266 if ( ( t == null ) || t.isEmpty() ) {
267 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
269 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
271 _configuration = configuration;
273 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
275 // if ( !_phylogeny.isEmpty() ) {
276 _phylogeny.recalculateNumberOfExternalDescendants( true );
277 checkForVectorProperties( _phylogeny );
279 setBackground( getTreeColorSet().getBackgroundColor() );
280 final MouseListener mouse_listener = new MouseListener( this );
281 addMouseListener( mouse_listener );
282 addMouseMotionListener( mouse_listener );
283 addMouseWheelListener( this );
284 calculateScaleDistance();
285 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
286 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
287 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
291 final public void actionPerformed( final ActionEvent e ) {
292 boolean done = false;
293 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
294 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
295 // NOTE: index corresponds to the indices of click-to options
296 // in the control panel.
297 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
298 // Set this as the new default click-to action
299 _main_panel.getControlPanel().setClickToAction( index );
300 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
301 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
302 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
307 requestFocusInWindow();
310 public synchronized Hashtable<String, BufferedImage> getImageMap() {
311 return getMainPanel().getImageMap();
314 final public MainPanel getMainPanel() {
319 * Get a pointer to the phylogeny
321 * @return a pointer to the phylogeny
323 public final Phylogeny getPhylogeny() {
328 final public void mouseWheelMoved( final MouseWheelEvent e ) {
329 final int notches = e.getWheelRotation();
330 if ( inOvVirtualRectangle( e ) ) {
331 if ( !isInOvRect() ) {
337 if ( isInOvRect() ) {
338 setInOvRect( false );
342 if ( e.isControlDown() ) {
344 getTreeFontSet().increaseFontSize();
345 getControlPanel().displayedPhylogenyMightHaveChanged( true );
348 getTreeFontSet().decreaseFontSize( 1, false );
349 getControlPanel().displayedPhylogenyMightHaveChanged( true );
352 else if ( e.isShiftDown() ) {
353 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
354 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
356 for( int i = 0; i < ( -notches ); ++i ) {
357 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
358 getControlPanel().displayedPhylogenyMightHaveChanged( false );
362 for( int i = 0; i < notches; ++i ) {
363 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
364 if ( getStartingAngle() < 0 ) {
365 setStartingAngle( TWO_PI + getStartingAngle() );
367 getControlPanel().displayedPhylogenyMightHaveChanged( false );
373 for( int i = 0; i < ( -notches ); ++i ) {
374 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
375 getControlPanel().displayedPhylogenyMightHaveChanged( false );
379 for( int i = 0; i < notches; ++i ) {
380 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
381 getControlPanel().displayedPhylogenyMightHaveChanged( false );
388 for( int i = 0; i < ( -notches ); ++i ) {
389 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
390 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
391 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
392 getControlPanel().displayedPhylogenyMightHaveChanged( false );
396 for( int i = 0; i < notches; ++i ) {
397 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
398 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
399 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
400 getControlPanel().displayedPhylogenyMightHaveChanged( false );
405 requestFocusInWindow();
410 final public void paintComponent( final Graphics g ) {
411 // Dimension currentSize = getSize();
412 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
413 // call the 'java.awt.Component.createImage(...)' method to get an
415 // offscreenImage = createImage( currentSize.width, currentSize.height );
416 // offscreenGraphics = offscreenImage.getGraphics();
417 // offscreenDimension = currentSize;
419 // super.paintComponent( g ); //why?
420 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
421 final Graphics2D g2d = ( Graphics2D ) g;
422 g2d.setRenderingHints( _rendering_hints );
423 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
424 //g.drawImage( offscreenImage, 0, 0, this );
428 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
429 throws PrinterException {
430 if ( page_index > 0 ) {
431 return ( NO_SUCH_PAGE );
434 final Graphics2D g2d = ( Graphics2D ) g;
435 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
436 // Turn off double buffering !?
437 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
438 // Turn double buffering back on !?
439 return ( PAGE_EXISTS );
443 public final void setEdited( final boolean edited ) {
447 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
448 getMainPanel().setImageMap( image_map );
452 * Set a phylogeny tree.
455 * an instance of a Phylogeny
457 public final void setTree( final Phylogeny t ) {
458 setNodeInPreorderToNull();
462 public final void setWaitCursor() {
463 setCursor( WAIT_CURSOR );
468 public void update( final Graphics g ) {
472 final void calcMaxDepth() {
473 if ( _phylogeny != null ) {
474 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
479 * Set parameters for printing the displayed tree
484 final void calcParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
485 // updateStyle(); not needed?
486 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
488 if ( recalc_longest_ext_node_info ) {
489 calculateLongestExtNodeInfo();
490 if ( getOptions().isAllowFontSizeChange() ) {
491 if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
492 && ( getTreeFontSet().getLargeFont().getSize() > 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) {
493 while ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
494 && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) {
495 getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(),
497 calculateLongestExtNodeInfo();
501 while ( ( getLongestExtNodeInfo() < ( x * 0.5 ) )
502 && ( getTreeFontSet().getLargeFont().getSize() <= getTreeFontSet().getLargeFontMemory()
503 .getSize() - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) {
504 getMainPanel().getTreeFontSet().increaseFontSize();
505 calculateLongestExtNodeInfo();
510 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
511 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
512 if ( ext_nodes == 1 ) {
513 ext_nodes = max_depth;
514 if ( ext_nodes < 1 ) {
521 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
522 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
523 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
526 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
527 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
529 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
533 if ( ov_xdist < 0.0 ) {
539 setXdistance( xdist );
540 setYdistance( ydist );
541 setOvXDistance( ov_xdist );
542 final double height = _phylogeny.getHeight();
544 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
545 setXcorrectionFactor( corr > 0 ? corr : 0 );
546 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
547 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
550 setXcorrectionFactor( 0 );
551 setOvXcorrectionFactor( 0 );
553 _circ_max_depth = max_depth;
556 if ( getOptions().isAllowFontSizeChange() ) {
557 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
558 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
559 // int dynamic_hiding_factor = calcDynamicHidingFactor();
560 // if ( dynamic_hiding_factor > 1 ) {
561 // while ( dynamic_hiding_factor > 1
562 // && getTreeFontSet()._fm_large.getHeight() > TreeFontSet.SMALL_FONTS_BASE ) {
563 // getTreeFontSet().decreaseFontSize( 1, true );
564 // dynamic_hiding_factor = calcDynamicHidingFactor();
567 // else if ( getTreeFontSet().isDecreasedSizeBySystem() ) {
568 // while ( dynamic_hiding_factor < 1 && getTreeFontSet()._fm_large.getHeight() < 12 ) {
569 // getTreeFontSet().increaseFontSize();
570 // dynamic_hiding_factor = calcDynamicHidingFactor();
579 final void calculateLongestExtNodeInfo() {
580 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
583 int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - MOVE )
584 * Constants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
585 if ( max_length < 40 ) {
589 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
591 if ( node.isCollapse() ) {
594 if ( getControlPanel().isShowNodeNames() ) {
595 sum += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
597 if ( node.getNodeData().isHasSequence() ) {
598 if ( getControlPanel().isShowSequenceAcc()
599 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
600 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
604 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
605 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
607 if ( getControlPanel().isShowGeneSymbols()
608 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
609 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
611 if ( getControlPanel().isShowAnnotation()
612 && ( node.getNodeData().getSequence().getAnnotations() != null )
613 && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
614 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAnnotation( 0 )
618 if ( getControlPanel().isShowDomainArchitectures()
619 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
620 sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() )
621 .getRenderingSize().getWidth();
624 if ( node.getNodeData().isHasTaxonomy() ) {
625 final Taxonomy tax = node.getNodeData().getTaxonomy();
626 if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
627 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getTaxonomyCode() + " " );
629 if ( getControlPanel().isShowTaxonomyScientificNames()
630 && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
631 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getScientificName() + " " );
633 if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
634 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getCommonName() + " ()" );
637 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
638 sum += getTreeFontSet()._fm_large.stringWidth( propertiesToString( node ).toString() );
640 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
641 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters()
642 .getGainedCharactersAsStringBuffer().toString() );
644 if ( sum >= max_length ) {
645 setLongestExtNodeInfo( max_length );
648 if ( sum > longest ) {
652 if ( longest >= max_length ) {
653 setLongestExtNodeInfo( max_length );
656 setLongestExtNodeInfo( longest );
660 final void calculateScaleDistance() {
661 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
664 final double height = getMaxDistanceToRoot();
666 if ( ( height <= 0.5 ) ) {
667 setScaleDistance( 0.01 );
669 else if ( height <= 5.0 ) {
670 setScaleDistance( 0.1 );
672 else if ( height <= 50.0 ) {
673 setScaleDistance( 1 );
675 else if ( height <= 500.0 ) {
676 setScaleDistance( 10 );
679 setScaleDistance( 100 );
683 setScaleDistance( 0.0 );
685 String scale_label = String.valueOf( getScaleDistance() );
686 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
687 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
689 setScaleLabel( scale_label );
692 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
693 String species = tax.getTaxonomyCode();
694 if ( ForesterUtil.isEmpty( species ) ) {
695 species = tax.getScientificName();
696 if ( ForesterUtil.isEmpty( species ) ) {
697 species = tax.getCommonName();
700 if ( ForesterUtil.isEmpty( species ) ) {
701 return getTreeColorSet().getTaxonomyColor();
703 // Look in species hash
704 Color c = getControlPanel().getSpeciesColors().get( species );
706 c = AptxUtil.calculateColorFromString( species );
707 getControlPanel().getSpeciesColors().put( species, c );
712 void checkForVectorProperties( final Phylogeny phy ) {
713 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
714 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
715 final PhylogenyNode node = iter.next();
716 if ( node.getNodeData().getProperties() != null ) {
717 final PropertiesMap pm = node.getNodeData().getProperties();
718 final double[] vector = new double[ pm.getProperties().size() ];
720 for( final String ref : pm.getProperties().keySet() ) {
721 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
722 final Property p = pm.getProperty( ref );
723 final String value_str = p.getValue();
724 final String index_str = ref
725 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
728 d = Double.parseDouble( value_str );
730 catch ( final NumberFormatException e ) {
731 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
732 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
737 i = Integer.parseInt( index_str );
739 catch ( final NumberFormatException e ) {
740 JOptionPane.showMessageDialog( this,
741 "Could not parse \"" + index_str
742 + "\" into index for vector data",
743 "Problem with Vector Data",
744 JOptionPane.ERROR_MESSAGE );
748 JOptionPane.showMessageDialog( this,
749 "Attempt to use negative index for vector data",
750 "Problem with Vector Data",
751 JOptionPane.ERROR_MESSAGE );
759 final List<Double> vector_l = new ArrayList<Double>( counter );
760 for( int i = 0; i < counter; ++i ) {
761 vector_l.add( vector[ i ] );
763 node.getNodeData().setVector( vector_l );
766 if ( stats.getN() > 0 ) {
767 _statistics_for_vector_data = stats;
771 void clearCurrentExternalNodesDataBuffer() {
772 setCurrentExternalNodesDataBuffer( new StringBuilder() );
776 * Collapse the tree from the given node
781 final void collapse( final PhylogenyNode node ) {
782 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
783 JOptionPane.showMessageDialog( this,
784 "Cannot collapse in unrooted display type",
785 "Attempt to collapse in unrooted display",
786 JOptionPane.WARNING_MESSAGE );
789 if ( !node.isExternal() && !node.isRoot() ) {
790 final boolean collapse = !node.isCollapse();
791 AptxUtil.collapseSubtree( node, collapse );
792 updateSetOfCollapsedExternalNodes();
793 _phylogeny.recalculateNumberOfExternalDescendants( true );
794 resetNodeIdToDistToLeafMap();
795 calculateLongestExtNodeInfo();
796 setNodeInPreorderToNull();
797 _control_panel.displayedPhylogenyMightHaveChanged( true );
798 resetPreferredSize();
800 _main_panel.adjustJScrollPane();
805 final void collapseSpeciesSpecificSubtrees() {
806 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
810 AptxUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
811 updateSetOfCollapsedExternalNodes();
812 _phylogeny.recalculateNumberOfExternalDescendants( true );
813 resetNodeIdToDistToLeafMap();
814 calculateLongestExtNodeInfo();
815 setNodeInPreorderToNull();
816 resetPreferredSize();
817 _main_panel.adjustJScrollPane();
822 final void colorRank( final String rank ) {
823 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
827 AptxUtil.removeBranchColors( _phylogeny );
828 final int colorizations = AptxUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
829 if ( colorizations > 0 ) {
830 _control_panel.setColorBranches( true );
831 if ( _control_panel.getColorBranchesCb() != null ) {
832 _control_panel.getColorBranchesCb().setSelected( true );
834 if ( _control_panel.getColorAccSpeciesCb() != null ) {
835 _control_panel.getColorAccSpeciesCb().setSelected( false );
837 _options.setColorLabelsSameAsParentBranch( true );
838 _control_panel.repaint();
842 if ( colorizations > 0 ) {
843 String msg = "Taxonomy colorization via " + rank + " completed:\n";
844 if ( colorizations > 1 ) {
845 msg += "colorized " + colorizations + " subtrees";
848 msg += "colorized one subtree";
851 JOptionPane.showMessageDialog( this,
853 "Taxonomy Colorization Completed (" + rank + ")",
854 JOptionPane.INFORMATION_MESSAGE );
857 String msg = "Could not taxonomy colorize any subtree via " + rank + ".\n";
858 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
859 msg += "select a different rank (e.g. phylum, genus, ...)\n";
862 msg += "1. \"" + MainFrameApplication.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
863 msg += "2. \"" + MainFrameApplication.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
864 JOptionPane.showMessageDialog( this, msg, "Taxonomy Colorization Failed", JOptionPane.WARNING_MESSAGE );
868 final void confColor() {
869 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
873 AptxUtil.removeBranchColors( _phylogeny );
874 AptxUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
875 _control_panel.setColorBranches( true );
876 if ( _control_panel.getColorBranchesCb() != null ) {
877 _control_panel.getColorBranchesCb().setSelected( true );
883 final void decreaseDomainStructureEvalueThreshold() {
884 if ( _domain_structure_e_value_thr_exp > -20 ) {
885 _domain_structure_e_value_thr_exp -= 1;
890 * Find the node, if any, at the given location
894 * @return pointer to the node at x,y, null if not found
896 final PhylogenyNode findNode( final int x, final int y ) {
897 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
900 final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE;
901 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
902 final PhylogenyNode node = iter.next();
903 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
904 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
905 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
906 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
907 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
914 final Configuration getConfiguration() {
915 return _configuration;
918 final ControlPanel getControlPanel() {
919 return _control_panel;
922 String getCurrentExternalNodesDataBufferAsString() {
923 return _current_external_nodes_data_buffer.toString();
926 int getCurrentExternalNodesDataBufferChangeCounter() {
927 return _current_external_nodes_data_buffer_change_counter;
930 final int getDomainStructureEvalueThreshold() {
931 return _domain_structure_e_value_thr_exp;
934 final Set<Integer> getFoundNodes() {
938 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
939 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
940 return ( PhylogenyMethods.getBranchColorValue( node ) );
943 return ( getTreeColorSet().getBranchColor() );
947 final int getLongestExtNodeInfo() {
948 return _longest_ext_node_info;
951 final Options getOptions() {
952 if ( _options == null ) {
953 _options = getControlPanel().getOptions();
958 final Rectangle2D getOvRectangle() {
959 return _ov_rectangle;
962 final Rectangle getOvVirtualRectangle() {
963 return _ov_virtual_rectangle;
966 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
967 return _graphics_type;
970 final double getStartingAngle() {
971 return _urt_starting_angle;
974 DescriptiveStatistics getStatisticsForExpressionValues() {
975 return _statistics_for_vector_data;
979 * Find a color for this species name.
982 * @return the species color
984 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
985 if ( node.getNodeData().isHasTaxonomy() ) {
986 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
988 // return non-colorized color
989 return getTreeColorSet().getTaxonomyColor();
993 * @return pointer to colorset for tree drawing
995 final TreeColorSet getTreeColorSet() {
996 return getMainPanel().getTreeColorSet();
999 final File getTreeFile() {
1003 final float getXcorrectionFactor() {
1004 return _x_correction_factor;
1007 final float getXdistance() {
1011 final float getYdistance() {
1015 final void increaseDomainStructureEvalueThreshold() {
1016 if ( _domain_structure_e_value_thr_exp < 3 ) {
1017 _domain_structure_e_value_thr_exp += 1;
1021 final void initNodeData() {
1022 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1025 double max_original_domain_structure_width = 0.0;
1026 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1027 if ( node.getNodeData().isHasSequence()
1028 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1029 RenderableDomainArchitecture rds = null;
1030 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
1031 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
1032 getConfiguration() );
1033 node.getNodeData().getSequence().setDomainArchitecture( rds );
1036 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1038 if ( getControlPanel().isShowDomainArchitectures() ) {
1039 final double dsw = rds.getOriginalSize().getWidth();
1040 if ( dsw > max_original_domain_structure_width ) {
1041 max_original_domain_structure_width = dsw;
1046 if ( getControlPanel().isShowDomainArchitectures() ) {
1047 final double ds_factor_width = _domain_structure_width / max_original_domain_structure_width;
1048 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1049 if ( node.getNodeData().isHasSequence()
1050 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1051 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1052 .getSequence().getDomainArchitecture();
1053 rds.setRenderingFactorWidth( ds_factor_width );
1054 rds.setParameter( _domain_structure_e_value_thr_exp );
1060 final boolean inOv( final MouseEvent e ) {
1061 return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) )
1062 && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) )
1063 && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) ) && ( e.getY() < ( ( getVisibleRect().y
1064 + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) );
1067 final boolean inOvRectangle( final MouseEvent e ) {
1068 return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) )
1069 && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) )
1070 && ( e.getY() >= ( getOvRectangle().getY() - 1 ) ) && ( e.getY() <= ( getOvRectangle().getY()
1071 + getOvRectangle().getHeight() + 1 ) ) );
1074 final boolean isApplet() {
1075 return getMainPanel() instanceof MainPanelApplets;
1078 final boolean isCanCollapse() {
1079 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1082 final boolean isCanColorSubtree() {
1083 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1086 final boolean isCanCopy() {
1087 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1090 final boolean isCanCut( final PhylogenyNode node ) {
1091 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1095 final boolean isCanDelete() {
1096 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1099 final boolean isCanPaste() {
1100 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1101 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1104 final boolean isCanReroot() {
1105 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1108 final boolean isCanSubtree( final PhylogenyNode node ) {
1109 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1110 .isRoot() || ( _subtree_index > 0 ) ) );
1113 final boolean isCurrentTreeIsSubtree() {
1114 return ( _subtree_index > 0 );
1117 final boolean isEdited() {
1121 final boolean isInOvRect() {
1125 final boolean isOvOn() {
1129 final boolean isPhyHasBranchLengths() {
1130 return _phy_has_branch_lengths;
1133 final void midpointRoot() {
1134 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1137 if ( !_phylogeny.isRerootable() ) {
1138 JOptionPane.showMessageDialog( this,
1139 "This is not rerootable",
1141 JOptionPane.WARNING_MESSAGE );
1144 setNodeInPreorderToNull();
1146 PhylogenyMethods.midpointRoot( _phylogeny );
1147 resetNodeIdToDistToLeafMap();
1153 final void mouseClicked( final MouseEvent e ) {
1154 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1155 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1156 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1157 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) )
1159 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) )
1167 final double max_x = getWidth() - getVisibleRect().width;
1168 final double max_y = getHeight() - getVisibleRect().height;
1175 getMainPanel().getCurrentScrollPane().getViewport()
1176 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1177 setInOvRect( true );
1181 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1182 if ( node != null ) {
1183 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1186 _highlight_node = node;
1187 // Check if shift key is down
1188 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1189 // Yes, so add to _found_nodes
1190 if ( getFoundNodes() == null ) {
1191 setFoundNodes( new HashSet<Integer>() );
1193 getFoundNodes().add( node.getId() );
1194 // Check if control key is down
1196 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1197 // Yes, so pop-up menu
1198 displayNodePopupMenu( node, e.getX(), e.getY() );
1199 // Handle unadorned click
1202 // Check for right mouse button
1203 if ( e.getModifiers() == 4 ) {
1204 displayNodePopupMenu( node, e.getX(), e.getY() );
1207 // if not in _found_nodes, clear _found_nodes
1208 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1213 // no node was clicked
1214 _highlight_node = null;
1220 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1221 setCursor( MOVE_CURSOR );
1222 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1223 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1224 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1225 if ( scroll_position.x < 0 ) {
1226 scroll_position.x = 0;
1229 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1230 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1231 if ( scroll_position.x > max_x ) {
1232 scroll_position.x = max_x;
1235 if ( scroll_position.y < 0 ) {
1236 scroll_position.y = 0;
1239 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1240 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1241 if ( scroll_position.y > max_y ) {
1242 scroll_position.y = max_y;
1245 if ( isOvOn() || getOptions().isShowScale() ) {
1248 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1251 final void mouseDragInOvRectangle( final MouseEvent e ) {
1252 setCursor( HAND_CURSOR );
1253 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1254 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1255 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1256 double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) );
1257 double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) );
1258 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1259 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1260 if ( scroll_position.x <= 0 ) {
1261 scroll_position.x = 0;
1265 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1266 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1267 if ( scroll_position.x >= max_x ) {
1269 scroll_position.x = max_x;
1272 if ( scroll_position.y <= 0 ) {
1274 scroll_position.y = 0;
1277 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1278 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1279 if ( scroll_position.y >= max_y ) {
1281 scroll_position.y = max_y;
1285 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1286 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1287 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1290 final void mouseMoved( final MouseEvent e ) {
1291 requestFocusInWindow();
1292 if ( _current_external_nodes != null ) {
1293 _current_external_nodes = null;
1296 if ( getControlPanel().isNodeDescPopup() ) {
1297 if ( _node_desc_popup != null ) {
1298 _node_desc_popup.hide();
1299 _node_desc_popup = null;
1302 if ( getOptions().isShowOverview() && isOvOn() ) {
1303 if ( inOvVirtualRectangle( e ) ) {
1304 if ( !isInOvRect() ) {
1305 setInOvRect( true );
1310 if ( isInOvRect() ) {
1311 setInOvRect( false );
1316 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
1325 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1326 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
1327 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.GET_EXT_DESC_DATA ) ) {
1328 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
1329 addToCurrentExternalNodes( n.getId() );
1331 setCursor( HAND_CURSOR );
1334 else if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
1335 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
1336 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
1337 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
1338 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
1339 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
1340 setCursor( CUT_CURSOR );
1343 setCursor( HAND_CURSOR );
1344 if ( getControlPanel().isNodeDescPopup() ) {
1345 showNodeDataPopup( e, node );
1350 setCursor( ARROW_CURSOR );
1355 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
1356 setCursor( ARROW_CURSOR );
1359 final void multiplyUrtFactor( final float f ) {
1363 final JApplet obtainApplet() {
1364 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1367 final void paintBranchCircular( final PhylogenyNode p,
1368 final PhylogenyNode c,
1370 final boolean radial_labels,
1371 final boolean to_pdf,
1372 final boolean to_graphics_file ) {
1373 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1374 final double root_x = _root.getXcoord();
1375 final double root_y = _root.getYcoord();
1376 final double dx = root_x - p.getXcoord();
1377 final double dy = root_y - p.getYcoord();
1378 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1379 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1380 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
1381 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
1382 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
1383 final double r2 = 2.0 * parent_radius;
1384 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1386 drawLine( c.getXcoord(),
1388 root_x + ( Math.cos( angle ) * parent_radius ),
1389 root_y + ( Math.sin( angle ) * parent_radius ),
1391 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c )
1392 || isInCurrentExternalNodes( c ) );
1393 if ( c.isExternal() ) {
1394 final boolean is_in_found_nodes = isInFoundNodes( c ) || isInCurrentExternalNodes( c );
1395 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
1396 && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
1399 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
1403 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
1404 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1405 final double root_x = _root.getXSecondary();
1406 final double root_y = _root.getYSecondary();
1407 final double dx = root_x - p.getXSecondary();
1408 final double dy = root_y - p.getYSecondary();
1409 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1410 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1411 g.setColor( getTreeColorSet().getOvColor() );
1412 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
1413 final double r2 = 2.0 * parent_radius;
1414 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1416 drawLine( c.getXSecondary(),
1418 root_x + ( Math.cos( angle ) * parent_radius ),
1419 root_y + ( Math.sin( angle ) * parent_radius ),
1421 if ( isInFoundNodes( c ) || isInCurrentExternalNodes( c ) ) {
1422 g.setColor( getTreeColorSet().getFoundColor() );
1423 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
1427 final void paintCircular( final Phylogeny phy,
1428 final double starting_angle,
1433 final boolean to_pdf,
1434 final boolean to_graphics_file ) {
1435 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
1436 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
1437 _root = phy.getRoot();
1438 _root.setXcoord( center_x );
1439 _root.setYcoord( center_y );
1440 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1441 double current_angle = starting_angle;
1443 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1444 final PhylogenyNode n = it.next();
1445 if ( !n.isCollapse() ) {
1446 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1447 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1448 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1449 _urt_nodeid_index_map.put( n.getId(), i++ );
1450 current_angle += ( TWO_PI / circ_num_ext_nodes );
1454 System.out.println( "is collapse" + n.getName() );
1457 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
1458 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file, isInFoundNodes( _root ) );
1461 final void paintCircularLite( final Phylogeny phy,
1462 final double starting_angle,
1466 final Graphics2D g ) {
1467 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
1468 _root = phy.getRoot();
1469 _root.setXSecondary( center_x );
1470 _root.setYSecondary( center_y );
1471 double current_angle = starting_angle;
1472 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1473 final PhylogenyNode n = it.next();
1474 n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1475 n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1476 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1477 current_angle += ( TWO_PI / circ_num_ext_nodes );
1479 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
1482 final void paintPhylogeny( final Graphics2D g,
1483 final boolean to_pdf,
1484 final boolean to_graphics_file,
1485 final int graphics_file_width,
1486 final int graphics_file_height,
1487 final int graphics_file_x,
1488 final int graphics_file_y ) {
1489 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1492 if ( _control_panel.isShowSequenceRelations() ) {
1493 _query_sequence = _control_panel.getSelectedQuerySequence();
1495 // Color the background
1497 final Rectangle r = getVisibleRect();
1498 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
1499 g.setColor( getTreeColorSet().getBackgroundColor() );
1500 if ( !to_graphics_file ) {
1504 if ( getOptions().isPrintBlackAndWhite() ) {
1505 g.setColor( Color.WHITE );
1507 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1511 if ( !to_graphics_file ) {
1512 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
1513 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
1517 g.setPaint( new GradientPaint( graphics_file_x,
1519 getTreeColorSet().getBackgroundColor(),
1521 graphics_file_y + graphics_file_height,
1522 getTreeColorSet().getBackgroundColorGradientBottom() ) );
1523 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1526 g.setStroke( new BasicStroke( 1 ) );
1529 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
1531 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1532 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1533 _external_node_index = 0;
1534 // Position starting X of tree
1535 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
1536 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
1538 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
1539 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
1540 .getDistanceToParent() * getXcorrectionFactor() ) ) );
1543 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
1545 // Position starting Y of tree
1546 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
1547 + ( TreePanel.MOVE / 2.0f ) );
1548 final int dynamic_hiding_factor = calcDynamicHidingFactor();
1549 if ( getControlPanel().isDynamicallyHideData() ) {
1550 if ( dynamic_hiding_factor > 1 ) {
1551 getControlPanel().setDynamicHidingIsOn( true );
1554 getControlPanel().setDynamicHidingIsOn( false );
1557 if ( _nodes_in_preorder == null ) {
1558 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
1560 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1561 _nodes_in_preorder[ i++ ] = it.next();
1564 //final PhylogenyNodeIterator it;
1565 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1566 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
1567 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1569 for( final PhylogenyNode element : _nodes_in_preorder ) {
1570 paintNodeRectangular( g, element, to_pdf, getControlPanel().isDynamicallyHideData()
1571 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1573 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
1574 if ( !( to_graphics_file || to_pdf ) ) {
1577 getVisibleRect().y + getVisibleRect().height,
1582 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1585 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1586 paintPhylogenyLite( g );
1589 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1590 if ( getControlPanel().getDynamicallyHideData() != null ) {
1591 getControlPanel().setDynamicHidingIsOn( false );
1593 final double angle = getStartingAngle();
1594 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1595 _dynamic_hiding_factor = 0;
1596 if ( getControlPanel().isDynamicallyHideData() ) {
1597 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
1598 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
1600 if ( getControlPanel().getDynamicallyHideData() != null ) {
1601 if ( _dynamic_hiding_factor > 1 ) {
1602 getControlPanel().setDynamicHidingIsOn( true );
1605 getControlPanel().setDynamicHidingIsOn( false );
1608 paintUnrooted( _phylogeny.getRoot(),
1610 ( float ) ( angle + ( 2 * Math.PI ) ),
1615 if ( getOptions().isShowScale() ) {
1616 if ( !( to_graphics_file || to_pdf ) ) {
1619 getVisibleRect().y + getVisibleRect().height,
1624 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1627 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1628 g.setColor( getTreeColorSet().getOvColor() );
1629 paintUnrootedLite( _phylogeny.getRoot(),
1631 angle + ( 2 * Math.PI ),
1633 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
1634 paintOvRectangle( g );
1637 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1638 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
1639 final int d = radius + MOVE + getLongestExtNodeInfo();
1640 _dynamic_hiding_factor = 0;
1641 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
1642 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
1643 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
1645 if ( getControlPanel().getDynamicallyHideData() != null ) {
1646 if ( _dynamic_hiding_factor > 1 ) {
1647 getControlPanel().setDynamicHidingIsOn( true );
1650 getControlPanel().setDynamicHidingIsOn( false );
1653 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
1654 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1655 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
1656 : getOvMaxWidth() / 2 );
1657 double x_scale = 1.0;
1658 double y_scale = 1.0;
1659 int x_pos = getVisibleRect().x + getOvXPosition();
1660 int y_pos = getVisibleRect().y + getOvYPosition();
1661 if ( getWidth() > getHeight() ) {
1662 x_scale = ( double ) getHeight() / getWidth();
1663 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
1666 y_scale = ( double ) getWidth() / getHeight();
1667 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
1669 _at = g.getTransform();
1670 g.scale( x_scale, y_scale );
1671 paintCircularLite( _phylogeny,
1675 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
1678 g.setTransform( _at );
1679 paintOvRectangle( g );
1684 final void recalculateMaxDistanceToRoot() {
1685 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
1689 * Remove all edit-node frames
1691 final void removeAllEditNodeJFrames() {
1692 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
1693 if ( _node_frames[ i ] != null ) {
1694 _node_frames[ i ].dispose();
1695 _node_frames[ i ] = null;
1698 _node_frame_index = 0;
1702 * Remove a node-edit frame.
1704 final void removeEditNodeFrame( final int i ) {
1705 _node_frame_index--;
1706 _node_frames[ i ] = null;
1707 if ( i < _node_frame_index ) {
1708 for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) {
1709 _node_frames[ j ] = _node_frames[ j + 1 ];
1711 _node_frames[ _node_frame_index ] = null;
1715 final void reRoot( final PhylogenyNode node ) {
1716 if ( !getPhylogeny().isRerootable() ) {
1717 JOptionPane.showMessageDialog( this,
1718 "This is not rerootable",
1720 JOptionPane.WARNING_MESSAGE );
1723 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1724 JOptionPane.showMessageDialog( this,
1725 "Cannot reroot in unrooted display type",
1726 "Attempt to reroot tree in unrooted display",
1727 JOptionPane.WARNING_MESSAGE );
1730 getPhylogeny().reRoot( node );
1731 getPhylogeny().recalculateNumberOfExternalDescendants( true );
1732 resetNodeIdToDistToLeafMap();
1733 setNodeInPreorderToNull();
1734 resetPreferredSize();
1735 getMainPanel().adjustJScrollPane();
1738 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1739 getControlPanel().showWhole();
1743 final void resetNodeIdToDistToLeafMap() {
1744 _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
1747 final void resetPreferredSize() {
1748 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
1754 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
1755 if ( getControlPanel().isDrawPhylogram() ) {
1757 + getLongestExtNodeInfo()
1759 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
1762 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
1764 + getLongestExtNodeInfo()
1765 + ForesterUtil.roundToInt( getXdistance()
1766 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
1770 + getLongestExtNodeInfo()
1771 + ForesterUtil.roundToInt( getXdistance()
1772 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
1775 setPreferredSize( new Dimension( x, y ) );
1778 final void selectNode( final PhylogenyNode node ) {
1779 if ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) ) {
1780 getFoundNodes().remove( node.getId() );
1781 getControlPanel().setSearchFoundCountsOnLabel( getFoundNodes().size() );
1782 if ( getFoundNodes().size() < 1 ) {
1783 getControlPanel().searchReset();
1787 getControlPanel().getSearchFoundCountsLabel().setVisible( true );
1788 getControlPanel().getSearchResetButton().setEnabled( true );
1789 getControlPanel().getSearchResetButton().setVisible( true );
1790 if ( getFoundNodes() == null ) {
1791 setFoundNodes( new HashSet<Integer>() );
1793 getFoundNodes().add( node.getId() );
1794 getControlPanel().setSearchFoundCountsOnLabel( getFoundNodes().size() );
1798 final void setArrowCursor() {
1799 setCursor( ARROW_CURSOR );
1803 final void setControlPanel( final ControlPanel atv_control ) {
1804 _control_panel = atv_control;
1807 void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
1808 increaseCurrentExternalNodesDataBufferChangeCounter();
1809 _current_external_nodes_data_buffer = sb;
1812 final void setFoundNodes( final Set<Integer> found_nodes ) {
1813 _found_nodes = found_nodes;
1816 final void setInOvRect( final boolean in_ov_rect ) {
1817 _in_ov_rect = in_ov_rect;
1820 final void setLargeFonts() {
1821 getTreeFontSet().largeFonts();
1824 final void setLastMouseDragPointX( final float x ) {
1825 _last_drag_point_x = x;
1828 final void setLastMouseDragPointY( final float y ) {
1829 _last_drag_point_y = y;
1832 final void setLongestExtNodeInfo( final int i ) {
1833 _longest_ext_node_info = i;
1836 final void setMediumFonts() {
1837 getTreeFontSet().mediumFonts();
1840 final void setNodeInPreorderToNull() {
1841 _nodes_in_preorder = null;
1844 final void setOvOn( final boolean ov_on ) {
1848 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
1849 _graphics_type = graphics_type;
1853 final void setSmallFonts() {
1854 getTreeFontSet().smallFonts();
1857 final void setStartingAngle( final double starting_angle ) {
1858 _urt_starting_angle = starting_angle;
1861 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
1862 _statistics_for_vector_data = statistics_for_expression_values;
1865 final void setSuperTinyFonts() {
1866 getTreeFontSet().superTinyFonts();
1869 final void setTextAntialias() {
1870 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
1871 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
1872 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
1875 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
1878 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
1879 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
1880 && !getMainPanel().getOptions().isShowDefaultNodeShapesInternal()
1881 && !getMainPanel().getOptions().isShowDefaultNodeShapesExternal()
1882 && ( ( getControlPanel() != null ) && !getControlPanel().isShowDomainArchitectures() ) ) {
1883 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1886 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
1889 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING,
1890 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
1892 catch ( final Throwable e ) {
1893 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
1897 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
1898 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1902 final void setTinyFonts() {
1903 getTreeFontSet().tinyFonts();
1906 final void setTreeFile( final File treefile ) {
1907 _treefile = treefile;
1910 final void setXcorrectionFactor( final float f ) {
1911 _x_correction_factor = f;
1914 final void setXdistance( final float x ) {
1918 final void setYdistance( final float y ) {
1922 final void sortDescendants( final PhylogenyNode node ) {
1923 if ( !node.isExternal() ) {
1924 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
1925 if ( ( !getControlPanel().isShowTaxonomyScientificNames() && !getControlPanel().isShowTaxonomyCode() && !getControlPanel()
1926 .isShowTaxonomyCommonNames() ) ) {
1927 if ( ( getControlPanel().isShowSequenceAcc() || getControlPanel().isShowGeneNames() || getControlPanel()
1928 .isShowGeneSymbols() ) ) {
1929 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
1931 else if ( getControlPanel().isShowNodeNames() ) {
1932 pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
1935 PhylogenyMethods.sortNodeDescendents( node, pri );
1936 setNodeInPreorderToNull();
1937 _phylogeny.externalNodesHaveChanged();
1938 _phylogeny.clearHashIdToNodeMap();
1939 _phylogeny.recalculateNumberOfExternalDescendants( true );
1940 resetNodeIdToDistToLeafMap();
1946 final void subTree( final PhylogenyNode node ) {
1947 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1948 JOptionPane.showMessageDialog( this,
1949 "Cannot get a sub/super tree in unrooted display",
1950 "Attempt to get sub/super tree in unrooted display",
1951 JOptionPane.WARNING_MESSAGE );
1954 if ( node.isExternal() ) {
1955 JOptionPane.showMessageDialog( this,
1956 "Cannot get a subtree of a external node",
1957 "Attempt to get subtree of external node",
1958 JOptionPane.WARNING_MESSAGE );
1961 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
1962 JOptionPane.showMessageDialog( this,
1963 "Cannot get a subtree of the root node",
1964 "Attempt to get subtree of root node",
1965 JOptionPane.WARNING_MESSAGE );
1968 setNodeInPreorderToNull();
1969 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
1970 _sub_phylogenies[ _subtree_index ] = _phylogeny;
1971 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
1973 _phylogeny = subTree( node, _phylogeny );
1974 updateSubSuperTreeButton();
1976 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
1979 _main_panel.getControlPanel().showWhole();
1983 final void superTree() {
1984 setNodeInPreorderToNull();
1985 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
1986 for( final PhylogenyNode n : temp_root.getDescendants() ) {
1987 n.setParent( temp_root );
1989 _sub_phylogenies[ _subtree_index ] = null;
1990 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
1991 _phylogeny = _sub_phylogenies[ --_subtree_index ];
1992 updateSubSuperTreeButton();
1995 final void swap( final PhylogenyNode node ) {
1996 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
1999 if ( node.getNumberOfDescendants() > 2 ) {
2000 JOptionPane.showMessageDialog( this,
2001 "Cannot swap descendants of nodes with more than 2 descendants",
2002 "Cannot swap descendants",
2003 JOptionPane.ERROR_MESSAGE );
2006 if ( !node.isExternal() ) {
2007 node.swapChildren();
2008 setNodeInPreorderToNull();
2009 _phylogeny.externalNodesHaveChanged();
2010 _phylogeny.clearHashIdToNodeMap();
2011 _phylogeny.recalculateNumberOfExternalDescendants( true );
2012 resetNodeIdToDistToLeafMap();
2018 final void taxColor() {
2019 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
2023 AptxUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
2024 _control_panel.setColorBranches( true );
2025 if ( _control_panel.getColorBranchesCb() != null ) {
2026 _control_panel.getColorBranchesCb().setSelected( true );
2033 final void updateOvSettings() {
2034 switch ( getOptions().getOvPlacement() ) {
2036 setOvXPosition( OV_BORDER );
2037 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
2038 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
2041 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
2042 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
2043 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
2046 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
2047 setOvYPosition( OV_BORDER );
2048 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2051 setOvXPosition( OV_BORDER );
2052 setOvYPosition( OV_BORDER );
2053 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2058 final void updateOvSizes() {
2059 if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) ) || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) {
2061 float l = getLongestExtNodeInfo();
2062 final float w_ratio = getOvMaxWidth() / getWidth();
2064 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
2065 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
2067 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
2068 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
2071 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
2073 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
2074 if ( ov_xdist < 0.0 ) {
2077 if ( ydist < 0.0 ) {
2080 setOvXDistance( ov_xdist );
2081 final double height = _phylogeny.getHeight();
2083 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
2084 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
2087 setOvXcorrectionFactor( 0 );
2095 void updateSetOfCollapsedExternalNodes() {
2096 final Phylogeny phy = getPhylogeny();
2097 _collapsed_external_nodeid_set.clear();
2098 if ( phy != null ) {
2099 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2100 final PhylogenyNode ext_node = it.next();
2101 PhylogenyNode n = ext_node;
2102 while ( !n.isRoot() ) {
2103 if ( n.isCollapse() ) {
2104 _collapsed_external_nodeid_set.add( ext_node.getId() );
2105 ext_node.setCollapse( true );
2114 final void updateSubSuperTreeButton() {
2115 if ( _subtree_index < 1 ) {
2116 getControlPanel().deactivateButtonToReturnToSuperTree();
2119 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
2123 final void zoomInDomainStructure() {
2124 if ( _domain_structure_width < 2000 ) {
2125 _domain_structure_width *= 1.2;
2129 final void zoomOutDomainStructure() {
2130 if ( _domain_structure_width > 20 ) {
2131 _domain_structure_width *= 0.8;
2135 private void abbreviateScientificName( final String sn ) {
2136 final String[] a = sn.split( "\\s+" );
2137 _sb.append( a[ 0 ].substring( 0, 1 ) );
2138 _sb.append( a[ 1 ].substring( 0, 2 ) );
2139 if ( a.length > 2 ) {
2140 for( int i = 2; i < a.length; i++ ) {
2142 _sb.append( a[ i ] );
2147 final private void addEmptyNode( final PhylogenyNode node ) {
2148 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2149 errorMessageNoCutCopyPasteInUnrootedDisplay();
2152 final String label = createASimpleTextRepresentationOfANode( node );
2154 if ( ForesterUtil.isEmpty( label ) ) {
2155 msg = "How to add the new, empty node?";
2158 msg = "How to add the new, empty node to node" + label + "?";
2160 final Object[] options = { "As sibling", "As descendant", "Cancel" };
2161 final int r = JOptionPane.showOptionDialog( this,
2163 "Addition of Empty New Node",
2164 JOptionPane.CLOSED_OPTION,
2165 JOptionPane.QUESTION_MESSAGE,
2169 boolean add_as_sibling = true;
2171 add_as_sibling = false;
2173 else if ( r != 0 ) {
2176 final Phylogeny phy = new Phylogeny();
2177 phy.setRoot( new PhylogenyNode() );
2178 phy.setRooted( true );
2179 if ( add_as_sibling ) {
2180 if ( node.isRoot() ) {
2181 JOptionPane.showMessageDialog( this,
2182 "Cannot add sibling to root",
2183 "Attempt to add sibling to root",
2184 JOptionPane.ERROR_MESSAGE );
2187 phy.addAsSibling( node );
2190 phy.addAsChild( node );
2192 setNodeInPreorderToNull();
2193 _phylogeny.externalNodesHaveChanged();
2194 _phylogeny.clearHashIdToNodeMap();
2195 _phylogeny.recalculateNumberOfExternalDescendants( true );
2196 resetNodeIdToDistToLeafMap();
2201 final private void addToCurrentExternalNodes( final int i ) {
2202 if ( _current_external_nodes == null ) {
2203 _current_external_nodes = new HashSet<Integer>();
2205 _current_external_nodes.add( i );
2208 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
2209 final boolean is_vertical,
2211 final boolean to_pdf,
2212 final boolean to_graphics_file ) {
2213 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
2214 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2215 g.setColor( Color.BLACK );
2217 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
2218 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
2219 && ( getCutOrCopiedTree() != null )
2220 && ( getCopiedAndPastedNodes() != null )
2222 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
2223 g.setColor( getTreeColorSet().getFoundColor() );
2225 else if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2226 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2228 else if ( to_pdf ) {
2229 g.setColor( getTreeColorSet().getBranchColorForPdf() );
2232 g.setColor( getTreeColorSet().getBranchColor() );
2236 final private void blast( final PhylogenyNode node ) {
2237 if ( !isCanBlast( node ) ) {
2238 JOptionPane.showMessageDialog( this,
2239 "Insufficient information present",
2241 JOptionPane.INFORMATION_MESSAGE );
2245 final String query = Blast.obtainQueryForBlast( node );
2246 System.out.println( "query for BLAST is: " + query );
2248 if ( !ForesterUtil.isEmpty( query ) ) {
2249 if ( node.getNodeData().isHasSequence() ) {
2250 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
2251 if ( node.getNodeData().getSequence().getType().toLowerCase()
2252 .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
2259 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2260 if ( ForesterUtil.seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2268 if ( type == '?' ) {
2269 if ( SequenceIdParser.isProtein( query ) ) {
2276 JApplet applet = null;
2278 applet = obtainApplet();
2281 Blast.openNcbiBlastWeb( query, type == 'n', applet, this );
2283 catch ( final Exception e ) {
2284 e.printStackTrace();
2286 if ( Constants.ALLOW_DDBJ_BLAST ) {
2288 System.out.println( "trying: " + query );
2289 final Blast s = new Blast();
2290 s.ddbjBlast( query );
2292 catch ( final Exception e ) {
2293 e.printStackTrace();
2300 private final int calcDynamicHidingFactor() {
2301 return ( int ) ( 0.5 + ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) ) );
2305 * Calculate the length of the distance between the given node and its
2311 * @return the distance value
2313 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
2314 if ( getControlPanel().isDrawPhylogram() ) {
2315 if ( node.getDistanceToParent() < 0.0 ) {
2318 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
2321 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2322 return getXdistance();
2324 return getXdistance() * factor;
2328 final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
2329 Color c = getTreeColorSet().getAnnotationColor();
2330 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
2331 final StringBuilder sb = new StringBuilder();
2332 for( final Annotation a : ann ) {
2333 sb.append( !ForesterUtil.isEmpty( a.getRef() ) ? a.getRef() : a.getDesc() );
2335 final String ann_str = sb.toString();
2336 if ( !ForesterUtil.isEmpty( ann_str ) ) {
2337 c = getControlPanel().getAnnotationColors().get( ann_str );
2339 c = AptxUtil.calculateColorFromString( ann_str );
2340 getControlPanel().getAnnotationColors().put( ann_str, c );
2343 c = getTreeColorSet().getAnnotationColor();
2350 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
2351 if ( getControlPanel().isDrawPhylogram() ) {
2352 if ( node.getDistanceToParent() < 0.0 ) {
2355 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
2358 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2359 return getOvXDistance();
2361 return getOvXDistance() * factor;
2365 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
2366 JOptionPane.showMessageDialog( this,
2367 "Cannot launch web browser for " + type_type + " data of this node",
2368 "Cannot launch web browser",
2369 JOptionPane.WARNING_MESSAGE );
2372 final private void colorizeSubtree( final Color c, final PhylogenyNode node ) {
2373 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2374 JOptionPane.showMessageDialog( this,
2375 "Cannot colorize subtree in unrooted display type",
2376 "Attempt to colorize subtree in unrooted display",
2377 JOptionPane.WARNING_MESSAGE );
2380 _control_panel.setColorBranches( true );
2381 if ( _control_panel.getColorBranchesCb() != null ) {
2382 _control_panel.getColorBranchesCb().setSelected( true );
2384 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
2385 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
2390 final private void colorSubtree( final PhylogenyNode node ) {
2391 Color intitial_color = null;
2392 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null )
2393 && ( ( ( !node.isRoot() && ( node.getParent().getNumberOfDescendants() < 3 ) ) ) || ( node.isRoot() ) ) ) {
2394 intitial_color = PhylogenyMethods.getBranchColorValue( node );
2397 intitial_color = getTreeColorSet().getBranchColor();
2399 _color_chooser.setColor( intitial_color );
2400 _color_chooser.setPreviewPanel( new JPanel() );
2401 final JDialog dialog = JColorChooser
2402 .createDialog( this,
2403 "Subtree colorization",
2406 new SubtreeColorizationActionListener( _color_chooser, node ),
2408 dialog.setVisible( true );
2411 final private void copySubtree( final PhylogenyNode node ) {
2412 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2413 errorMessageNoCutCopyPasteInUnrootedDisplay();
2416 setNodeInPreorderToNull();
2417 setCutOrCopiedTree( _phylogeny.copy( node ) );
2418 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
2419 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
2420 for( final PhylogenyNode n : nodes ) {
2421 node_ids.add( n.getId() );
2423 node_ids.add( node.getId() );
2424 setCopiedAndPastedNodes( node_ids );
2428 private String createAnnotationString( final SortedSet<Annotation> ann ) {
2429 final StringBuilder sb = new StringBuilder();
2430 boolean first = true;
2431 for( final Annotation a : ann ) {
2438 sb.append( a.asSimpleText() );
2440 final String ann_str = sb.toString();
2444 final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
2445 final String tax = PhylogenyMethods.getSpecies( node );
2446 String label = node.getName();
2447 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
2448 label = label + " " + tax;
2450 else if ( !ForesterUtil.isEmpty( tax ) ) {
2456 if ( !ForesterUtil.isEmpty( label ) ) {
2457 label = " [" + label + "]";
2462 final private void cutSubtree( final PhylogenyNode node ) {
2463 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2464 errorMessageNoCutCopyPasteInUnrootedDisplay();
2467 if ( node.isRoot() ) {
2468 JOptionPane.showMessageDialog( this,
2469 "Cannot cut entire tree as subtree",
2470 "Attempt to cut entire tree",
2471 JOptionPane.ERROR_MESSAGE );
2474 final String label = createASimpleTextRepresentationOfANode( node );
2475 final int r = JOptionPane.showConfirmDialog( null,
2476 "Cut subtree" + label + "?",
2477 "Confirm Cutting of Subtree",
2478 JOptionPane.YES_NO_OPTION );
2479 if ( r != JOptionPane.OK_OPTION ) {
2482 setNodeInPreorderToNull();
2483 setCopiedAndPastedNodes( null );
2484 setCutOrCopiedTree( _phylogeny.copy( node ) );
2485 _phylogeny.deleteSubtree( node, true );
2486 _phylogeny.clearHashIdToNodeMap();
2487 _phylogeny.recalculateNumberOfExternalDescendants( true );
2488 resetNodeIdToDistToLeafMap();
2493 final private void cycleColors() {
2494 getMainPanel().getTreeColorSet().cycleColorScheme();
2495 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
2496 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
2500 final private void decreaseOvSize() {
2501 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
2502 setOvMaxWidth( getOvMaxWidth() - 5 );
2503 setOvMaxHeight( getOvMaxHeight() - 5 );
2505 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2509 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
2510 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2511 errorMessageNoCutCopyPasteInUnrootedDisplay();
2514 if ( node.isRoot() && ( node.getNumberOfDescendants() != 1 ) ) {
2515 JOptionPane.showMessageDialog( this,
2516 "Cannot delete entire tree",
2517 "Attempt to delete entire tree",
2518 JOptionPane.ERROR_MESSAGE );
2521 final String label = createASimpleTextRepresentationOfANode( node );
2522 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
2523 final int r = JOptionPane.showOptionDialog( this,
2524 "Delete" + label + "?",
2525 "Delete Node/Subtree",
2526 JOptionPane.CLOSED_OPTION,
2527 JOptionPane.QUESTION_MESSAGE,
2531 setNodeInPreorderToNull();
2532 boolean node_only = true;
2536 else if ( r != 0 ) {
2540 PhylogenyMethods.removeNode( node, _phylogeny );
2543 _phylogeny.deleteSubtree( node, true );
2545 _phylogeny.externalNodesHaveChanged();
2546 _phylogeny.clearHashIdToNodeMap();
2547 _phylogeny.recalculateNumberOfExternalDescendants( true );
2548 resetNodeIdToDistToLeafMap();
2553 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
2554 makePopupMenus( node );
2555 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
2556 _node_popup_menu.show( this, x, y );
2559 final private void drawArc( final double x,
2562 final double heigth,
2563 final double start_angle,
2564 final double arc_angle,
2565 final Graphics2D g ) {
2566 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
2570 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
2571 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
2574 _line.setLine( x1, y1, x2, y2 );
2578 final private void drawOval( final double x,
2581 final double heigth,
2582 final Graphics2D g ) {
2583 _ellipse.setFrame( x, y, width, heigth );
2587 final private void drawOvalFilled( final double x,
2590 final double heigth,
2591 final Graphics2D g ) {
2592 _ellipse.setFrame( x, y, width, heigth );
2596 final private void drawOvalGradient( final double x,
2599 final double heigth,
2601 final Color color_1,
2602 final Color color_2,
2603 final Color color_border ) {
2604 _ellipse.setFrame( x, y, width, heigth );
2605 g.setPaint( new GradientPaint( ( float ) x,
2608 ( float ) ( x + width ),
2609 ( float ) ( y + heigth ),
2613 if ( color_border != null ) {
2614 g.setPaint( color_border );
2619 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
2620 _rectangle.setFrame( x, y, width, heigth );
2621 g.draw( _rectangle );
2624 final private void drawRectFilled( final double x,
2627 final double heigth,
2628 final Graphics2D g ) {
2629 _rectangle.setFrame( x, y, width, heigth );
2630 g.fill( _rectangle );
2633 final private void drawRectGradient( final double x,
2636 final double heigth,
2638 final Color color_1,
2639 final Color color_2,
2640 final Color color_border ) {
2641 _rectangle.setFrame( x, y, width, heigth );
2642 g.setPaint( new GradientPaint( ( float ) x,
2645 ( float ) ( x + width ),
2646 ( float ) ( y + heigth ),
2649 g.fill( _rectangle );
2650 if ( color_border != null ) {
2651 g.setPaint( color_border );
2652 g.draw( _rectangle );
2656 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
2657 final List<Uri> us = new ArrayList<Uri>();
2658 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
2659 for( final Uri uri : t.getUris() ) {
2664 for( final Uri uri : us ) {
2665 if ( uri != null ) {
2666 final String uri_str = uri.getValue().toString().toLowerCase();
2667 if ( getImageMap().containsKey( uri_str ) ) {
2668 final BufferedImage bi = getImageMap().get( uri_str );
2669 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
2670 double scaling_factor = 1;
2671 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
2672 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
2673 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
2675 // y = y - ( 0.9 * getYdistance() );
2676 final double hs = bi.getHeight() * scaling_factor;
2677 double ws = ( bi.getWidth() * scaling_factor ) + offset;
2678 final double my_y = y - ( 0.5 * hs );
2679 final int x_w = ( int ) ( x + ws + 0.5 );
2680 final int y_h = ( int ) ( my_y + hs + 0.5 );
2681 if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) {
2683 ( int ) ( x + 0.5 + offset ),
2684 ( int ) ( my_y + 0.5 ),
2705 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
2706 JOptionPane.showMessageDialog( this,
2707 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
2708 "Attempt to cut/copy/paste/add/delete in unrooted display",
2709 JOptionPane.ERROR_MESSAGE );
2712 final private Set<Integer> getCopiedAndPastedNodes() {
2713 return getMainPanel().getCopiedAndPastedNodes();
2716 final private Set<Integer> getCurrentExternalNodes() {
2717 return _current_external_nodes;
2720 final private Phylogeny getCutOrCopiedTree() {
2721 return getMainPanel().getCutOrCopiedTree();
2724 final private float getLastDragPointX() {
2725 return _last_drag_point_x;
2728 final private float getLastDragPointY() {
2729 return _last_drag_point_y;
2732 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
2733 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
2734 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
2735 _nodeid_dist_to_leaf.put( node.getId(), m );
2739 return _nodeid_dist_to_leaf.get( node.getId() );
2743 final private double getMaxDistanceToRoot() {
2744 if ( _max_distance_to_root < 0 ) {
2745 recalculateMaxDistanceToRoot();
2747 return _max_distance_to_root;
2750 final private float getOvMaxHeight() {
2751 return _ov_max_height;
2754 final private float getOvMaxWidth() {
2755 return _ov_max_width;
2758 final private float getOvXcorrectionFactor() {
2759 return _ov_x_correction_factor;
2762 final private float getOvXDistance() {
2763 return _ov_x_distance;
2766 final private int getOvXPosition() {
2767 return _ov_x_position;
2770 final private float getOvYDistance() {
2771 return _ov_y_distance;
2774 final private int getOvYPosition() {
2775 return _ov_y_position;
2778 final private int getOvYStart() {
2782 final private double getScaleDistance() {
2783 return _scale_distance;
2786 final private String getScaleLabel() {
2787 return _scale_label;
2790 final private TreeFontSet getTreeFontSet() {
2791 return getMainPanel().getTreeFontSet();
2794 final private float getUrtFactor() {
2798 final private float getUrtFactorOv() {
2799 return _urt_factor_ov;
2802 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
2805 showNodeFrame( node );
2820 colorSubtree( node );
2835 copySubtree( node );
2838 pasteSubtree( node );
2840 case DELETE_NODE_OR_SUBTREE:
2841 deleteNodeOrSubtree( node );
2844 addEmptyNode( node );
2846 case EDIT_NODE_DATA:
2847 showNodeEditFrame( node );
2852 case SORT_DESCENDENTS:
2853 sortDescendants( node );
2855 case GET_EXT_DESC_DATA:
2856 showExtDescNodeData( node );
2859 throw new IllegalArgumentException( "unknown action: " + action );
2863 final private void increaseCurrentExternalNodesDataBufferChangeCounter() {
2864 _current_external_nodes_data_buffer_change_counter++;
2867 final private void increaseOvSize() {
2868 if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) )
2869 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
2870 .getHeight() / 2 ) ) ) {
2871 setOvMaxWidth( getOvMaxWidth() + 5 );
2872 setOvMaxHeight( getOvMaxHeight() + 5 );
2874 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2878 final private void init() {
2879 _color_chooser = new JColorChooser();
2880 _rollover_popup = new JTextArea();
2881 _rollover_popup.setFont( POPUP_FONT );
2882 resetNodeIdToDistToLeafMap();
2884 setTreeFile( null );
2886 initializeOvSettings();
2887 setStartingAngle( ( TWO_PI * 3 ) / 4 );
2888 final ImageLoader il = new ImageLoader( this );
2889 new Thread( il ).start();
2892 final private void initializeOvSettings() {
2893 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
2894 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
2897 final private boolean inOvVirtualRectangle( final int x, final int y ) {
2898 return ( ( x >= ( getOvVirtualRectangle().x - 1 ) )
2899 && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) )
2900 && ( y >= ( getOvVirtualRectangle().y - 1 ) ) && ( y <= ( getOvVirtualRectangle().y
2901 + getOvVirtualRectangle().height + 1 ) ) );
2904 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
2905 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
2908 final private boolean isCanBlast( final PhylogenyNode node ) {
2909 if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) {
2912 return Blast.isContainsQueryForBlast( node );
2915 final private boolean isCanOpenSeqWeb( final PhylogenyNode node ) {
2916 if ( node.getNodeData().isHasSequence()
2917 && ( node.getNodeData().getSequence().getAccession() != null )
2918 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
2919 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
2920 && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource()
2921 .toLowerCase() ) ) {
2927 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
2928 if ( node.getNodeData().isHasTaxonomy()
2929 && ( ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
2930 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getProvider() )
2931 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && getConfiguration()
2932 .isHasWebLink( node.getNodeData().getTaxonomy().getIdentifier().getProvider().toLowerCase() ) )
2933 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
2934 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
2935 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
2936 .getNodeData().getTaxonomy().getIdentifier() != null )
2937 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && node
2938 .getNodeData().getTaxonomy().getIdentifier().getValue().startsWith( "http://" ) ) ) ) {
2946 final private boolean isInCurrentExternalNodes( final PhylogenyNode node ) {
2947 return ( ( getCurrentExternalNodes() != null ) && getCurrentExternalNodes().contains( node.getId() ) );
2950 final private boolean isInFoundNodes( final PhylogenyNode node ) {
2951 return ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) );
2954 final private boolean isInOv() {
2958 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
2960 if ( getControlPanel().isShowTaxonomyImages() ) {
2961 y_dist = 40 + ( int ) getYdistance();
2963 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) )
2964 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) ) || ( ( node.getParent() != null ) && ( node
2965 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
2968 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
2969 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) )
2970 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) )
2971 || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) ) || ( node.getXcoord() > ( getVisibleRect()
2972 .getMaxX() + 20 ) ) );
2975 final private boolean isNonLinedUpCladogram() {
2976 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
2979 final private boolean isUniformBranchLengthsForCladogram() {
2980 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
2983 final private void keyPressedCalls( final KeyEvent e ) {
2984 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
2985 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
2986 if ( !isInOvRect() ) {
2987 setInOvRect( true );
2990 else if ( isInOvRect() ) {
2991 setInOvRect( false );
2994 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
2995 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
2996 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
2997 getMainPanel().getTreeFontSet().mediumFonts();
2998 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3000 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
3001 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
3002 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3004 else if ( plusPressed( e.getKeyCode() ) ) {
3005 getMainPanel().getTreeFontSet().increaseFontSize();
3006 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3010 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
3011 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
3012 getControlPanel().showWhole();
3014 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
3015 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
3016 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
3017 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
3018 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3019 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3021 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
3022 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3023 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3025 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
3026 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3027 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3028 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3030 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
3031 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3032 Constants.WHEEL_ZOOM_IN_FACTOR );
3033 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3040 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
3043 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
3047 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
3051 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
3052 scroll_position.x = scroll_position.x + dx;
3053 scroll_position.y = scroll_position.y + dy;
3054 if ( scroll_position.x <= 0 ) {
3055 scroll_position.x = 0;
3058 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
3059 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
3060 if ( scroll_position.x >= max_x ) {
3061 scroll_position.x = max_x;
3064 if ( scroll_position.y <= 0 ) {
3065 scroll_position.y = 0;
3068 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
3069 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
3070 if ( scroll_position.y >= max_y ) {
3071 scroll_position.y = max_y;
3075 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
3078 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
3079 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3080 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3081 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3082 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3084 else if ( plusPressed( e.getKeyCode() ) ) {
3085 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3086 Constants.WHEEL_ZOOM_IN_FACTOR );
3087 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3088 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3090 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
3091 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3092 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3093 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
3094 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3097 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
3098 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3099 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3100 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
3101 if ( getStartingAngle() < 0 ) {
3102 setStartingAngle( TWO_PI + getStartingAngle() );
3104 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3107 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
3108 boolean selected = false;
3109 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
3110 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
3114 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
3116 if ( getMainPanel().getMainFrame() == null ) {
3117 // Must be "E" applet version.
3118 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
3119 if ( ae.getlabelDirectionCbmi() != null ) {
3120 ae.getlabelDirectionCbmi().setSelected( selected );
3124 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
3128 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
3129 switchDisplaygetPhylogenyGraphicsType();
3132 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
3136 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
3137 MainFrame.cycleOverview( getOptions(), this );
3140 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
3143 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
3150 final private void makePopupMenus( final PhylogenyNode node ) {
3151 _node_popup_menu = new JPopupMenu();
3152 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
3153 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
3154 for( int i = 0; i < clickto_names.size(); i++ ) {
3155 final String title = clickto_names.get( i );
3156 _node_popup_menu_items[ i ] = new JMenuItem( title );
3157 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
3158 _node_popup_menu_items[ i ].setEnabled( isCanOpenSeqWeb( node ) );
3160 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
3161 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
3163 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
3164 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
3166 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
3167 if ( !getOptions().isEditable() ) {
3170 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
3172 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
3173 if ( !getOptions().isEditable() ) {
3176 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
3178 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
3179 if ( !getOptions().isEditable() ) {
3182 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
3184 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
3185 if ( !getOptions().isEditable() ) {
3188 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
3190 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
3191 if ( !getOptions().isEditable() ) {
3195 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
3196 if ( !getOptions().isEditable() ) {
3200 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
3201 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
3203 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
3204 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
3206 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
3207 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
3209 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
3210 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
3212 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
3213 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
3215 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
3216 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
3218 _node_popup_menu_items[ i ].addActionListener( this );
3219 _node_popup_menu.add( _node_popup_menu_items[ i ] );
3223 private final String obtainTitleForExtDescNodeData() {
3224 switch ( getOptions().getExtDescNodeDataToReturn() ) {
3226 return "Node Names";
3228 return "Sequence Names";
3229 case SEQUENCE_SYMBOL:
3230 return "Sequence Symbols";
3231 case SEQUENCE_MOL_SEQ:
3232 return "Molecular Sequences";
3234 return "Sequence Accessors";
3235 case TAXONOMY_SCIENTIFIC_NAME:
3236 return "Scientific Names";
3238 return "Taxonomy Codes";
3240 return "User Selected Data";
3242 throw new IllegalArgumentException( "unknown data element: "
3243 + getOptions().getExtDescNodeDataToReturn() );
3247 final private void openSeqWeb( final PhylogenyNode node ) {
3248 if ( !isCanOpenSeqWeb( node ) ) {
3249 cannotOpenBrowserWarningMessage( "sequence" );
3252 String uri_str = null;
3253 final Sequence seq = node.getNodeData().getSequence();
3254 final String source = seq.getAccession().getSource().toLowerCase();
3256 if ( source.toLowerCase().equals( "ncbi" ) ) {
3257 url = Constants.NCBI_ALL_DATABASE_SEARCH;
3260 final WebLink weblink = getConfiguration().getWebLink( source );
3261 url = weblink.getUrl().toString();
3264 uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 );
3266 catch ( final UnsupportedEncodingException e ) {
3267 AptxUtil.showErrorMessage( this, e.toString() );
3268 e.printStackTrace();
3270 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3272 JApplet applet = null;
3274 applet = obtainApplet();
3276 AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_seq" );
3278 catch ( final IOException e ) {
3279 AptxUtil.showErrorMessage( this, e.toString() );
3280 e.printStackTrace();
3282 catch ( final URISyntaxException e ) {
3283 AptxUtil.showErrorMessage( this, e.toString() );
3284 e.printStackTrace();
3288 cannotOpenBrowserWarningMessage( "sequence" );
3292 final private void openTaxWeb( final PhylogenyNode node ) {
3293 if ( !isCanOpenTaxWeb( node ) ) {
3294 cannotOpenBrowserWarningMessage( "taxonomic" );
3297 String uri_str = null;
3298 final Taxonomy tax = node.getNodeData().getTaxonomy();
3299 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
3300 && getConfiguration().isHasWebLink( tax.getIdentifier().getProvider().toLowerCase() ) ) {
3301 final String type = tax.getIdentifier().getProvider().toLowerCase();
3302 final WebLink weblink = getConfiguration().getWebLink( type );
3304 uri_str = weblink.getUrl() + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
3306 catch ( final UnsupportedEncodingException e ) {
3307 AptxUtil.showErrorMessage( this, e.toString() );
3308 e.printStackTrace();
3311 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
3312 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
3314 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
3316 catch ( final URISyntaxException e ) {
3317 AptxUtil.showErrorMessage( this, e.toString() );
3319 e.printStackTrace();
3322 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
3324 uri_str = "http://www.eol.org/search?q="
3325 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
3327 catch ( final UnsupportedEncodingException e ) {
3328 AptxUtil.showErrorMessage( this, e.toString() );
3329 e.printStackTrace();
3332 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
3334 uri_str = "http://www.uniprot.org/taxonomy/?query="
3335 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
3337 catch ( final UnsupportedEncodingException e ) {
3338 AptxUtil.showErrorMessage( this, e.toString() );
3339 e.printStackTrace();
3342 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
3344 uri_str = "http://www.eol.org/search?q="
3345 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
3347 catch ( final UnsupportedEncodingException e ) {
3348 AptxUtil.showErrorMessage( this, e.toString() );
3349 e.printStackTrace();
3352 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3354 JApplet applet = null;
3356 applet = obtainApplet();
3358 AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_tax" );
3360 catch ( final IOException e ) {
3361 AptxUtil.showErrorMessage( this, e.toString() );
3362 e.printStackTrace();
3364 catch ( final URISyntaxException e ) {
3365 AptxUtil.showErrorMessage( this, e.toString() );
3366 e.printStackTrace();
3370 cannotOpenBrowserWarningMessage( "taxonomic" );
3374 final private void paintBranchLength( final Graphics2D g,
3375 final PhylogenyNode node,
3376 final boolean to_pdf,
3377 final boolean to_graphics_file ) {
3378 g.setFont( getTreeFontSet().getSmallFont() );
3379 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3380 g.setColor( Color.BLACK );
3383 g.setColor( getTreeColorSet().getBranchLengthColor() );
3385 if ( !node.isRoot() ) {
3386 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3387 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3388 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3390 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3391 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3392 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3395 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3396 .getXcoord() + 3, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3400 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
3401 - getTreeFontSet()._small_max_descent, g );
3405 final private void paintBranchLite( final Graphics2D g,
3410 final PhylogenyNode node ) {
3411 g.setColor( getTreeColorSet().getOvColor() );
3412 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3413 drawLine( x1, y1, x2, y2, g );
3415 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3416 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3417 ( g ).draw( _quad_curve );
3419 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3420 final float dx = x2 - x1;
3421 final float dy = y2 - y1;
3422 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3423 + ( dy * 0.8f ), x2, y2 );
3424 ( g ).draw( _cubic_curve );
3427 final float x2a = x2;
3428 final float x1a = x1;
3429 // draw the vertical line
3430 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
3431 drawLine( x1, y1, x1, y2, g );
3433 // draw the horizontal line
3434 drawLine( x1a, y2, x2a, y2, g );
3439 * Paint a branch which consists of a vertical and a horizontal bar
3440 * @param is_ind_found_nodes
3442 final private void paintBranchRectangular( final Graphics2D g,
3447 final PhylogenyNode node,
3448 final boolean to_pdf,
3449 final boolean to_graphics_file ) {
3450 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
3451 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3452 drawLine( x1, y1, x2, y2, g );
3454 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3455 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3456 g.draw( _quad_curve );
3458 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3459 final float dx = x2 - x1;
3460 final float dy = y2 - y1;
3461 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3462 + ( dy * 0.8f ), x2, y2 );
3463 g.draw( _cubic_curve );
3466 final float x2a = x2;
3467 final float x1a = x1;
3469 if ( node.isFirstChildNode() || node.isLastChildNode()
3470 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
3471 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3472 if ( !to_graphics_file
3474 && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) ) || ( ( y2 > ( getVisibleRect()
3475 .getMaxY() + 20 ) ) && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) {
3479 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3480 float x2c = x1 + EURO_D;
3484 drawLine( x1, y1, x2c, y2, g );
3486 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3488 y2_r = y2 - ROUNDED_D;
3492 drawLine( x1, y1, x1, y2_r, g );
3495 y2_r = y2 + ROUNDED_D;
3499 drawLine( x1, y1, x1, y2_r, g );
3503 drawLine( x1, y1, x1, y2, g );
3507 // draw the horizontal line
3508 if ( !to_graphics_file && !to_pdf
3509 && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) {
3513 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
3514 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3515 x1_r = x1a + ROUNDED_D;
3517 drawLine( x1_r, y2, x2a, y2, g );
3520 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3521 final float x1c = x1a + EURO_D;
3523 drawLine( x1c, y2, x2a, y2, g );
3527 drawLine( x1a, y2, x2a, y2, g );
3531 final double w = PhylogenyMethods.getBranchWidthValue( node );
3532 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3533 x1_r = x1a + ROUNDED_D;
3535 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
3538 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3539 final float x1c = x1a + EURO_D;
3541 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
3545 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
3548 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3553 final double diff = y2 - y2_r;
3554 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
3557 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
3562 if ( node.isExternal() ) {
3563 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node )
3564 || isInCurrentExternalNodes( node ) );
3568 final private double paintCirculars( final PhylogenyNode n,
3569 final Phylogeny phy,
3570 final float center_x,
3571 final float center_y,
3572 final double radius,
3573 final boolean radial_labels,
3575 final boolean to_pdf,
3576 final boolean to_graphics_file ) {
3577 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
3578 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
3579 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
3581 return _urt_nodeid_angle_map.get( n.getId() );
3584 final List<PhylogenyNode> descs = n.getDescendants();
3586 for( final PhylogenyNode desc : descs ) {
3587 sum += paintCirculars( desc,
3598 if ( !n.isRoot() ) {
3599 r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3601 final double theta = sum / descs.size();
3602 n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) );
3603 n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) );
3604 _urt_nodeid_angle_map.put( n.getId(), theta );
3605 for( final PhylogenyNode desc : descs ) {
3606 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
3612 final private void paintCircularsLite( final PhylogenyNode n,
3613 final Phylogeny phy,
3617 final Graphics2D g ) {
3618 if ( n.isExternal() ) {
3622 final List<PhylogenyNode> descs = n.getDescendants();
3623 for( final PhylogenyNode desc : descs ) {
3624 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
3627 if ( !n.isRoot() ) {
3628 r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3630 final double theta = _urt_nodeid_angle_map.get( n.getId() );
3631 n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) );
3632 n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) );
3633 for( final PhylogenyNode desc : descs ) {
3634 paintBranchCircularLite( n, desc, g );
3639 final private void paintCollapsedNode( final Graphics2D g,
3640 final PhylogenyNode node,
3641 final boolean to_graphics_file,
3642 final boolean to_pdf,
3643 final boolean is_in_found_nodes ) {
3645 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3648 else if ( is_in_found_nodes ) {
3649 c = getTreeColorSet().getFoundColor();
3651 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3652 c = getTaxonomyBasedColor( node );
3654 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3655 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3656 c = PhylogenyMethods.getBranchColorValue( node );
3659 c = getTreeColorSet().getCollapseFillColor();
3661 double d = node.getAllExternalDescendants().size();
3663 d = ( 3 * _y_distance ) / 3;
3666 d = ( Math.log10( d ) * _y_distance ) / 2.5;
3668 final int box_size = getOptions().getDefaultNodeShapeSize();
3669 if ( d < box_size ) {
3673 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() - box_size ),
3674 ForesterUtil.roundToInt( node.getYcoord() ) );
3675 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ),
3676 ForesterUtil.roundToInt( node.getYcoord() - d ) );
3677 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ),
3678 ForesterUtil.roundToInt( node.getYcoord() + d ) );
3679 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3681 g.fillPolygon( _polygon );
3683 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
3684 g.setColor( getBackground() );
3685 g.fillPolygon( _polygon );
3687 g.drawPolygon( _polygon );
3689 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
3690 g.setPaint( new GradientPaint( node.getXcoord() - box_size, node.getYcoord(), getBackground(), ( node
3691 .getXcoord() + box_size ), ( float ) ( node.getYcoord() - d ), c, false ) );
3696 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3699 final private void paintConfidenceValues( final Graphics2D g,
3700 final PhylogenyNode node,
3701 final boolean to_pdf,
3702 final boolean to_graphics_file ) {
3703 final List<Confidence> confidences = node.getBranchData().getConfidences();
3704 // if ( confidences.size() == 1 ) {
3705 // final double value = node.getBranchData().getConfidence( 0 ).getValue();
3706 // if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
3709 // conf_str = FORMATTER_CONFIDENCE.format( value );
3711 // else if ( confidences.size() > 1 ) {
3712 boolean one_ok = false;
3713 boolean not_first = false;
3714 Collections.sort( confidences );
3715 final StringBuilder sb = new StringBuilder();
3716 String conf_str = "";
3717 for( final Confidence confidence : confidences ) {
3718 final double value = confidence.getValue();
3719 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
3720 if ( value >= getOptions().getMinConfidenceValue() ) {
3729 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
3730 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
3731 if ( getOptions().isShowConfidenceStddev() ) {
3732 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
3734 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getStandardDeviation(),
3736 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
3743 conf_str = sb.toString();
3746 if ( conf_str.length() > 0 ) {
3747 final double parent_x = node.getParent().getXcoord();
3748 double x = node.getXcoord();
3749 g.setFont( getTreeFontSet().getSmallFont() );
3750 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3753 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3756 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3757 g.setColor( Color.BLACK );
3760 g.setColor( getTreeColorSet().getConfidenceColor() );
3763 .drawString( conf_str,
3765 + ( ( x - parent_x - getTreeFontSet()._fm_small.stringWidth( conf_str ) ) / 2 ),
3766 ( node.getYcoord() + getTreeFontSet()._small_max_ascent ) - 1,
3771 final private void paintFoundNode( final int x, final int y, final Graphics2D g ) {
3772 final int box_size = getOptions().getDefaultNodeShapeSize();
3773 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
3774 g.setColor( getTreeColorSet().getFoundColor() );
3775 g.fillRect( x - half_box_size, y - half_box_size, box_size, box_size );
3778 final private void paintGainedAndLostCharacters( final Graphics2D g,
3779 final PhylogenyNode node,
3780 final String gained,
3781 final String lost ) {
3782 if ( node.getParent() != null ) {
3783 final double parent_x = node.getParent().getXcoord();
3784 final double x = node.getXcoord();
3785 g.setFont( getTreeFontSet().getLargeFont() );
3786 g.setColor( getTreeColorSet().getGainedCharactersColor() );
3787 if ( Constants.SPECIAL_CUSTOM ) {
3788 g.setColor( Color.BLUE );
3791 .drawString( gained,
3792 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( gained ) ) / 2 ),
3793 ( node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent() ),
3795 g.setColor( getTreeColorSet().getLostCharactersColor() );
3796 TreePanel.drawString( lost,
3797 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( lost ) ) / 2 ),
3798 ( node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent() ),
3804 * Draw a box at the indicated node.
3811 final private void paintNodeBox( final double x,
3813 final PhylogenyNode node,
3815 final boolean to_pdf,
3816 final boolean to_graphics_file,
3817 final boolean is_in_found_nodes ) {
3818 if ( node.isCollapse() ) {
3821 // if this node should be highlighted, do so
3822 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
3823 g.setColor( getTreeColorSet().getFoundColor() );
3824 drawOval( x - 8, y - 8, 16, 16, g );
3825 drawOval( x - 9, y - 8, 17, 17, g );
3826 drawOval( x - 9, y - 9, 18, 18, g );
3828 if ( is_in_found_nodes ) {
3829 paintFoundNode( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ), g );
3832 Color outline_color = null;
3833 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3834 outline_color = Color.BLACK;
3836 else if ( getControlPanel().isEvents() && AptxUtil.isHasAssignedEvent( node ) ) {
3837 final Event event = node.getNodeData().getEvent();
3838 if ( event.isDuplication() ) {
3839 outline_color = getTreeColorSet().getDuplicationBoxColor();
3841 else if ( event.isSpeciation() ) {
3842 outline_color = getTreeColorSet().getSpecBoxColor();
3844 else if ( event.isSpeciationOrDuplication() ) {
3845 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
3848 else if ( getOptions().isTaxonomyColorizeNodeShapes() ) {
3849 outline_color = getTaxonomyBasedColor( node );
3852 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
3853 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
3854 outline_color = getTreeColorSet().getBranchColorForPdf();
3857 final int box_size = getOptions().getDefaultNodeShapeSize();
3858 final int half_box_size = box_size / 2;
3859 if ( ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() )
3860 || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() )
3861 || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) {
3862 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
3863 if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
3864 drawOvalGradient( x - half_box_size,
3869 to_pdf ? Color.WHITE : outline_color,
3870 to_pdf ? outline_color : getBackground(),
3873 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
3874 Color background = getBackground();
3876 background = Color.WHITE;
3878 drawOvalGradient( x - half_box_size,
3887 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3888 g.setColor( outline_color );
3889 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
3892 else if ( getOptions().getDefaultNodeShape() == NodeVisualization.NodeShape.RECTANGLE ) {
3893 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.GRADIENT ) {
3894 drawRectGradient( x - half_box_size,
3899 to_pdf ? Color.WHITE : outline_color,
3900 to_pdf ? outline_color : getBackground(),
3903 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
3904 Color background = getBackground();
3906 background = Color.WHITE;
3908 drawRectGradient( x - half_box_size,
3917 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3918 g.setColor( outline_color );
3919 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
3926 final private void paintNodeData( final Graphics2D g,
3927 final PhylogenyNode node,
3928 final boolean to_graphics_file,
3929 final boolean to_pdf,
3930 final boolean is_in_found_nodes ) {
3931 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
3934 if ( getOptions().isShowBranchLengthValues()
3935 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3936 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3937 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
3938 paintBranchLength( g, node, to_pdf, to_graphics_file );
3940 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
3944 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
3945 if ( getControlPanel().isShowTaxonomyImages()
3946 && ( getImageMap() != null )
3947 && !getImageMap().isEmpty()
3948 && node.getNodeData().isHasTaxonomy()
3949 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
3950 .getUris().isEmpty() ) ) {
3951 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
3953 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
3954 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
3955 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
3957 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3958 g.setColor( Color.BLACK );
3960 else if ( is_in_found_nodes ) {
3961 g.setColor( getTreeColorSet().getFoundColor() );
3963 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3964 g.setColor( getTaxonomyBasedColor( node ) );
3966 else if ( getControlPanel().isColorAccordingToAnnotation()
3967 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
3968 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
3969 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
3971 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3972 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3973 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3975 else if ( to_pdf ) {
3976 g.setColor( Color.BLACK );
3979 g.setColor( getTreeColorSet().getSequenceColor() );
3982 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3984 _sb.append( node.getAllExternalDescendants().size() );
3987 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3988 if ( _sb.length() > 0 ) {
3991 _sb.append( node.getName() );
3993 if ( node.getNodeData().isHasSequence() ) {
3994 if ( getControlPanel().isShowGeneSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
3995 if ( _sb.length() > 0 ) {
3998 _sb.append( node.getNodeData().getSequence().getSymbol() );
4000 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
4001 if ( _sb.length() > 0 ) {
4004 _sb.append( node.getNodeData().getSequence().getName() );
4006 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4007 if ( _sb.length() > 0 ) {
4010 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
4011 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
4014 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
4017 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
4018 if ( _sb.length() > 0 ) {
4021 _sb.append( propertiesToString( node ) );
4023 g.setFont( getTreeFontSet().getLargeFont() );
4024 if ( is_in_found_nodes ) {
4025 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
4027 double down_shift_factor = 3.0;
4028 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
4029 down_shift_factor = 1;
4031 final double pos_x = node.getXcoord() + x + 2 + half_box_size;
4032 final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
4033 final String sb_str = _sb.toString();
4034 // GUILHEM_BEG ______________
4035 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
4036 && ( _query_sequence != null ) ) {
4037 int nodeTextBoundsWidth = 0;
4038 if ( sb_str.length() > 0 ) {
4039 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
4040 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
4042 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
4043 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
4044 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
4045 g.setColor( getTreeColorSet().getBackgroundColor() );
4049 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
4050 for( final SequenceRelation seqRelation : seqRelations ) {
4051 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
4052 .getRef1().isEqual( _query_sequence ) )
4053 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
4054 .getSelectedItem() );
4055 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
4056 final double linePosX = node.getXcoord() + 2 + half_box_size;
4057 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
4058 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
4060 if ( sConfidence != null ) {
4061 double confidenceX = pos_x;
4062 if ( sb_str.length() > 0 ) {
4063 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
4064 + CONFIDENCE_LEFT_MARGIN;
4066 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
4067 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
4068 .getBounds().getWidth();
4069 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
4070 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
4073 if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
4075 if ( nodeTextBoundsWidth == 0 ) {
4076 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
4079 nodeTextBoundsWidth += 2;
4081 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
4082 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
4089 if ( sb_str.length() > 0 ) {
4090 TreePanel.drawString( sb_str, pos_x, pos_y, g );
4092 // GUILHEM_END _____________
4093 // COMMENTED_OUT_BY_GUILHEM_BEG _______________
4094 // TODO FIXME need to check this one!
4095 //if ( _sb.length() > 0 ) {
4096 // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
4097 // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4099 // COMMENTED_OUT_BY_GUILHEM_END ________________
4100 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
4101 && ( node.getNodeData().getSequence().getAnnotations() != null )
4102 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
4103 if ( _sb.length() > 0 ) {
4104 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
4106 final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
4107 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4108 g.setColor( Color.BLACK );
4110 else if ( getControlPanel().isColorAccordingToAnnotation() ) {
4111 g.setColor( calculateColorForAnnotation( ann ) );
4113 final String ann_str = createAnnotationString( ann );
4114 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
4115 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4117 _sb.append( ann_str );
4119 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
4120 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
4121 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
4122 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
4123 && node.getNodeData().isHasBinaryCharacters() ) {
4124 if ( _sb.length() > 0 ) {
4125 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
4127 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4128 g.setColor( Color.BLACK );
4131 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
4133 if ( getControlPanel().isShowBinaryCharacters() ) {
4134 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
4135 .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord()
4136 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4137 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
4138 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
4139 .getLostCharactersAsStringBuffer().toString() );
4142 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
4143 node.getXcoord() + x + 4 + half_box_size,
4145 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ),
4147 paintGainedAndLostCharacters( g, node, "+"
4148 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
4149 + node.getNodeData().getBinaryCharacters().getLostCount() );
4155 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
4156 final PhylogenyNode node,
4157 final boolean to_pdf,
4158 final boolean to_graphics_file,
4159 final boolean radial_labels,
4160 final double ur_angle,
4161 final boolean is_in_found_nodes ) {
4162 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
4165 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4166 g.setColor( Color.BLACK );
4168 else if ( is_in_found_nodes ) {
4169 g.setColor( getTreeColorSet().getFoundColor() );
4171 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4172 g.setColor( getTaxonomyBasedColor( node ) );
4174 else if ( getControlPanel().isColorAccordingToAnnotation()
4175 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
4176 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
4177 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
4180 g.setColor( getTreeColorSet().getSequenceColor() );
4184 if ( node.getNodeData().isHasTaxonomy()
4185 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
4186 .isShowTaxonomyCommonNames() ) ) {
4187 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4188 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4189 _sb.append( taxonomy.getTaxonomyCode() );
4192 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4193 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4194 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4195 _sb.append( taxonomy.getScientificName() );
4197 _sb.append( taxonomy.getCommonName() );
4200 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4201 _sb.append( taxonomy.getScientificName() );
4204 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4205 _sb.append( taxonomy.getCommonName() );
4209 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4210 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4211 _sb.append( taxonomy.getScientificName() );
4215 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4216 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4217 _sb.append( taxonomy.getCommonName() );
4222 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
4224 _sb.append( node.getAllExternalDescendants().size() );
4227 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
4228 if ( _sb.length() > 0 ) {
4231 _sb.append( node.getName() );
4233 if ( node.getNodeData().isHasSequence() ) {
4234 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4235 if ( _sb.length() > 0 ) {
4238 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
4239 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
4242 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
4244 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
4245 if ( _sb.length() > 0 ) {
4248 _sb.append( node.getNodeData().getSequence().getName() );
4251 g.setFont( getTreeFontSet().getLargeFont() );
4252 if ( is_in_found_nodes ) {
4253 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
4255 if ( _sb.length() > 1 ) {
4256 final String sb_str = _sb.toString();
4258 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4259 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
4262 m = ( float ) ( ur_angle % TWO_PI );
4264 _at = g.getTransform();
4265 boolean need_to_reset = false;
4266 final float x_coord = node.getXcoord();
4267 final float y_coord = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / 3.0f );
4268 if ( radial_labels ) {
4269 need_to_reset = true;
4270 boolean left = false;
4271 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4275 g.rotate( m, x_coord, node.getYcoord() );
4277 g.translate( -( getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth() ), 0 );
4281 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4282 need_to_reset = true;
4283 g.translate( -getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth(), 0 );
4286 TreePanel.drawString( sb_str, x_coord, y_coord, g );
4287 if ( need_to_reset ) {
4288 g.setTransform( _at );
4293 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
4294 if ( node.isCollapse() ) {
4295 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
4296 paintCollapsedNode( g, node, false, false, false );
4300 if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
4301 g.setColor( getTreeColorSet().getFoundColor() );
4302 drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
4305 if ( !node.isExternal() && !node.isCollapse() ) {
4306 boolean first_child = true;
4308 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4309 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4310 final PhylogenyNode child_node = node.getChildNode( i );
4312 if ( !isUniformBranchLengthsForCladogram() ) {
4313 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4316 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4318 if ( first_child ) {
4319 first_child = false;
4320 y2 = node.getYSecondary()
4321 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
4322 .getNumberOfExternalNodes() ) );
4325 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4327 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
4328 new_x = x2 + node.getXSecondary();
4329 final float diff_y = node.getYSecondary() - y2;
4330 final float diff_x = node.getXSecondary() - new_x;
4331 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
4332 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
4334 child_node.setXSecondary( new_x );
4335 child_node.setYSecondary( y2 );
4336 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4341 final private void paintNodeRectangular( final Graphics2D g,
4342 final PhylogenyNode node,
4343 final boolean to_pdf,
4344 final boolean dynamically_hide,
4345 final int dynamic_hiding_factor,
4346 final boolean to_graphics_file ) {
4347 final boolean is_in_found_nodes = isInFoundNodes( node ) || isInCurrentExternalNodes( node );
4348 if ( node.isCollapse() ) {
4349 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
4350 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4354 if ( node.isExternal() ) {
4355 ++_external_node_index;
4357 // Confidence values
4358 if ( getControlPanel().isShowConfidenceValues()
4359 && !node.isExternal()
4361 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
4362 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
4363 && node.getBranchData().isHasConfidences() ) {
4364 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
4366 // Draw a line to root:
4367 if ( node.isRoot() && _phylogeny.isRooted() ) {
4368 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
4371 float new_x_min = Float.MAX_VALUE;
4372 final boolean disallow_shortcutting = dynamic_hiding_factor < 40;
4373 float min_dist = 1.5f;
4374 if ( !disallow_shortcutting ) {
4375 // System.out.println( dynamic_hiding_factor );
4376 if ( dynamic_hiding_factor > 4000 ) {
4379 else if ( dynamic_hiding_factor > 1000 ) {
4382 else if ( dynamic_hiding_factor > 100 ) {
4386 if ( !node.isExternal() && !node.isCollapse() ) {
4387 boolean first_child = true;
4389 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4390 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4391 final PhylogenyNode child_node = node.getChildNode( i );
4393 if ( !isUniformBranchLengthsForCladogram() ) {
4394 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4397 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4399 if ( first_child ) {
4400 first_child = false;
4401 y2 = node.getYcoord()
4402 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
4405 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4407 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
4408 new_x = x2 + node.getXcoord();
4409 if ( dynamically_hide && ( x2 < new_x_min ) ) {
4412 final float diff_y = node.getYcoord() - y2;
4413 final float diff_x = node.getXcoord() - new_x;
4414 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
4415 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
4416 paintBranchRectangular( g,
4425 child_node.setXcoord( new_x );
4426 child_node.setYcoord( y2 );
4427 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4429 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node )
4430 || isInCurrentExternalNodes( node ) );
4432 if ( dynamically_hide
4433 && !is_in_found_nodes
4434 && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) ) || ( !node
4435 .isExternal() && ( ( new_x_min < 20 ) || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getTreeFontSet()._fm_large
4436 .getHeight() ) ) ) ) ) {
4439 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4440 paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
4443 final private void paintNodeWithRenderableData( final Graphics2D g,
4444 final PhylogenyNode node,
4445 final boolean to_graphics_file,
4446 final boolean to_pdf ) {
4447 if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
4450 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
4453 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4454 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4455 RenderableDomainArchitecture rds = null;
4456 if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
4458 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
4460 catch ( final ClassCastException cce ) {
4461 cce.printStackTrace();
4463 if ( rds != null ) {
4464 rds.setRenderingHeight( 6 );
4466 if ( node.getNodeData().isHasTaxonomy() ) {
4467 if ( getControlPanel().isShowTaxonomyCode()
4468 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
4469 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4473 if ( getControlPanel().isShowTaxonomyScientificNames()
4474 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) ) {
4475 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4476 .getScientificName()
4479 if ( getControlPanel().isShowTaxonomyCommonNames()
4480 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) ) {
4481 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4486 if ( node.getNodeData().isHasSequence() ) {
4487 if ( getControlPanel().isShowGeneNames()
4488 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) ) {
4489 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName()
4492 if ( getControlPanel().isShowGeneSymbols()
4493 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) ) {
4494 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol()
4497 if ( getControlPanel().isShowSequenceAcc()
4498 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4499 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence()
4500 .getAccession().toString()
4504 if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( node.getName() ) ) {
4505 x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
4507 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
4512 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
4513 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
4514 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
4515 getStatisticsForExpressionValues(),
4516 getConfiguration() );
4519 PhylogenyNode my_node = node;
4520 if ( !getControlPanel().isDrawPhylogram() ) {
4521 my_node = getPhylogeny().getFirstExternalNode();
4523 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
4524 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
4526 if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
4527 x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
4529 rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
4535 final private void paintOvRectangle( final Graphics2D g ) {
4536 final float w_ratio = ( float ) getWidth() / getVisibleRect().width;
4537 final float h_ratio = ( float ) getHeight() / getVisibleRect().height;
4538 final float x_ratio = ( float ) getWidth() / getVisibleRect().x;
4539 final float y_ratio = ( float ) getHeight() / getVisibleRect().y;
4540 final float width = getOvMaxWidth() / w_ratio;
4541 final float height = getOvMaxHeight() / h_ratio;
4542 final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio );
4543 final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio );
4544 g.setColor( getTreeColorSet().getFoundColor() );
4545 getOvRectangle().setRect( x, y, width, height );
4546 if ( ( width < 6 ) && ( height < 6 ) ) {
4547 drawRectFilled( x, y, 6, 6, g );
4548 getOvVirtualRectangle().setRect( x, y, 6, 6 );
4550 else if ( width < 6 ) {
4551 drawRectFilled( x, y, 6, height, g );
4552 getOvVirtualRectangle().setRect( x, y, 6, height );
4554 else if ( height < 6 ) {
4555 drawRectFilled( x, y, width, 6, g );
4556 getOvVirtualRectangle().setRect( x, y, width, 6 );
4559 drawRect( x, y, width, height, g );
4560 if ( isInOvRect() ) {
4561 drawRect( x + 1, y + 1, width - 2, height - 2, g );
4563 getOvVirtualRectangle().setRect( x, y, width, height );
4567 final private void paintPhylogenyLite( final Graphics2D g ) {
4570 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
4571 .getWidth() ) ) ) );
4572 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
4573 for( final PhylogenyNode element : _nodes_in_preorder ) {
4574 paintNodeLite( g, element );
4576 paintOvRectangle( g );
4580 * Paint the root branch. (Differs from others because it will always be a
4581 * single horizontal line).
4582 * @param to_graphics_file
4584 * @return new x1 value
4586 final private void paintRootBranch( final Graphics2D g,
4589 final PhylogenyNode root,
4590 final boolean to_pdf,
4591 final boolean to_graphics_file ) {
4592 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
4593 float d = getXdistance();
4594 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
4595 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
4597 if ( d < MIN_ROOT_LENGTH ) {
4598 d = MIN_ROOT_LENGTH;
4600 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
4601 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
4604 final double w = PhylogenyMethods.getBranchWidthValue( root );
4605 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
4607 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file, isInFoundNodes( root ) );
4610 final private void paintScale( final Graphics2D g,
4613 final boolean to_pdf,
4614 final boolean to_graphics_file ) {
4616 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
4618 final int y2 = y1 - 8;
4619 final int y3 = y1 - 4;
4620 g.setFont( getTreeFontSet().getSmallFont() );
4621 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4622 g.setColor( Color.BLACK );
4625 g.setColor( getTreeColorSet().getBranchLengthColor() );
4627 drawLine( x1, y1, x1, y2, g );
4628 drawLine( x2, y1, x2, y2, g );
4629 drawLine( x1, y3, x2, y3, g );
4630 if ( getScaleLabel() != null ) {
4631 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
4635 final private int paintTaxonomy( final Graphics2D g,
4636 final PhylogenyNode node,
4637 final boolean is_in_found_nodes,
4638 final boolean to_pdf,
4639 final boolean to_graphics_file,
4640 final double x_shift ) {
4641 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4642 g.setFont( getTreeFontSet().getLargeItalicFont() );
4643 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4644 g.setColor( Color.BLACK );
4646 else if ( is_in_found_nodes ) {
4647 g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
4648 g.setColor( getTreeColorSet().getFoundColor() );
4650 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4651 g.setColor( getTaxonomyBasedColor( node ) );
4653 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
4654 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
4655 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
4657 else if ( to_pdf ) {
4658 g.setColor( Color.BLACK );
4661 g.setColor( getTreeColorSet().getTaxonomyColor() );
4663 final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
4664 final double start_y = node.getYcoord()
4665 + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
4667 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4668 _sb.append( taxonomy.getTaxonomyCode() );
4671 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4672 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4673 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4674 if ( getOptions().isAbbreviateScientificTaxonNames()
4675 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4676 abbreviateScientificName( taxonomy.getScientificName() );
4679 _sb.append( taxonomy.getScientificName() );
4682 _sb.append( taxonomy.getCommonName() );
4685 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4686 if ( getOptions().isAbbreviateScientificTaxonNames()
4687 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4688 abbreviateScientificName( taxonomy.getScientificName() );
4691 _sb.append( taxonomy.getScientificName() );
4695 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4696 _sb.append( taxonomy.getCommonName() );
4700 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4701 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4702 if ( getOptions().isAbbreviateScientificTaxonNames()
4703 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4704 abbreviateScientificName( taxonomy.getScientificName() );
4707 _sb.append( taxonomy.getScientificName() );
4712 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4713 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4714 _sb.append( taxonomy.getCommonName() );
4718 final String label = _sb.toString();
4720 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
4721 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
4722 // invert font color and background color to show that this is the query sequence
4723 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
4727 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
4728 g.setColor( getTreeColorSet().getBackgroundColor() );
4731 TreePanel.drawString( label, start_x, start_y, g );
4732 if ( is_in_found_nodes ) {
4733 return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
4736 return getTreeFontSet()._fm_large_italic.stringWidth( label );
4740 final private void paintUnrooted( final PhylogenyNode n,
4741 final double low_angle,
4742 final double high_angle,
4743 final boolean radial_labels,
4745 final boolean to_pdf,
4746 final boolean to_graphics_file ) {
4748 n.setXcoord( getWidth() / 2 );
4749 n.setYcoord( getHeight() / 2 );
4751 if ( n.isExternal() ) {
4752 paintNodeDataUnrootedCirc( g,
4757 ( high_angle + low_angle ) / 2,
4758 isInFoundNodes( n ) || isInCurrentExternalNodes( n ) );
4761 final float num_enclosed = n.getNumberOfExternalNodes();
4762 final float x = n.getXcoord();
4763 final float y = n.getYcoord();
4764 double current_angle = low_angle;
4765 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
4766 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
4767 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
4768 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
4769 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4770 final PhylogenyNode desc = n.getChildNode( i );
4771 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
4772 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
4773 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
4774 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
4777 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
4780 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
4783 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4784 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4786 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4787 if ( desc.getDistanceToParent() < 0 ) {
4791 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
4795 length = getUrtFactor();
4797 final double mid_angle = current_angle + ( arc_size / 2 );
4798 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
4799 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
4800 desc.setXcoord( new_x );
4801 desc.setYcoord( new_y );
4802 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
4803 current_angle += arc_size;
4804 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
4805 drawLine( x, y, new_x, new_y, g );
4806 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc )
4807 || isInCurrentExternalNodes( desc ) );
4810 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file, isInFoundNodes( n ) );
4814 final private void paintUnrootedLite( final PhylogenyNode n,
4815 final double low_angle,
4816 final double high_angle,
4818 final float urt_ov_factor ) {
4820 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) );
4821 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) );
4822 n.setXSecondary( x_pos );
4823 n.setYSecondary( y_pos );
4825 if ( n.isExternal() ) {
4828 final float num_enclosed = n.getNumberOfExternalNodes();
4829 final float x = n.getXSecondary();
4830 final float y = n.getYSecondary();
4831 double current_angle = low_angle;
4832 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4833 final PhylogenyNode desc = n.getChildNode( i );
4834 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4835 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4837 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4838 if ( desc.getDistanceToParent() < 0 ) {
4842 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
4846 length = urt_ov_factor;
4848 final double mid_angle = current_angle + ( arc_size / 2 );
4849 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
4850 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
4851 desc.setXSecondary( new_x );
4852 desc.setYSecondary( new_y );
4853 if ( isInFoundNodes( desc ) || isInCurrentExternalNodes( desc ) ) {
4854 g.setColor( getTreeColorSet().getFoundColor() );
4855 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
4856 g.setColor( getTreeColorSet().getOvColor() );
4858 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
4859 current_angle += arc_size;
4860 drawLine( x, y, new_x, new_y, g );
4864 final private void pasteSubtree( final PhylogenyNode node ) {
4865 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4866 errorMessageNoCutCopyPasteInUnrootedDisplay();
4869 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
4870 JOptionPane.showMessageDialog( this,
4871 "No tree in buffer (need to copy or cut a subtree first)",
4872 "Attempt to paste with empty buffer",
4873 JOptionPane.ERROR_MESSAGE );
4876 final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
4877 final Object[] options = { "As sibling", "As descendant", "Cancel" };
4878 final int r = JOptionPane.showOptionDialog( this,
4879 "How to paste subtree" + label + "?",
4881 JOptionPane.CLOSED_OPTION,
4882 JOptionPane.QUESTION_MESSAGE,
4886 boolean paste_as_sibling = true;
4888 paste_as_sibling = false;
4890 else if ( r != 0 ) {
4893 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
4894 buffer_phy.setAllNodesToNotCollapse();
4895 PhylogenyMethods.preOrderReId( buffer_phy );
4896 buffer_phy.setRooted( true );
4897 boolean need_to_show_whole = false;
4898 if ( paste_as_sibling ) {
4899 if ( node.isRoot() ) {
4900 JOptionPane.showMessageDialog( this,
4901 "Cannot paste sibling to root",
4902 "Attempt to paste sibling to root",
4903 JOptionPane.ERROR_MESSAGE );
4906 buffer_phy.addAsSibling( node );
4909 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
4910 need_to_show_whole = true;
4911 _phylogeny = buffer_phy;
4914 buffer_phy.addAsChild( node );
4917 if ( getCopiedAndPastedNodes() == null ) {
4918 setCopiedAndPastedNodes( new HashSet<Integer>() );
4920 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
4921 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
4922 for( final PhylogenyNode n : nodes ) {
4923 node_ids.add( n.getId() );
4925 node_ids.add( node.getId() );
4926 getCopiedAndPastedNodes().addAll( node_ids );
4927 setNodeInPreorderToNull();
4928 _phylogeny.externalNodesHaveChanged();
4929 _phylogeny.clearHashIdToNodeMap();
4930 _phylogeny.recalculateNumberOfExternalDescendants( true );
4931 resetNodeIdToDistToLeafMap();
4933 if ( need_to_show_whole ) {
4934 getControlPanel().showWhole();
4939 private final StringBuffer propertiesToString( final PhylogenyNode node ) {
4940 final PropertiesMap properties = node.getNodeData().getProperties();
4941 final StringBuffer sb = new StringBuffer();
4942 boolean first = true;
4943 for( final String ref : properties.getPropertyRefs() ) {
4950 final Property p = properties.getProperty( ref );
4951 sb.append( getPartAfterColon( p.getRef() ) );
4953 sb.append( p.getValue() );
4954 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
4955 sb.append( getPartAfterColon( p.getUnit() ) );
4961 final private void setCopiedAndPastedNodes( final Set<Integer> nodeIds ) {
4962 getMainPanel().setCopiedAndPastedNodes( nodeIds );
4965 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
4966 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
4969 final private void setInOv( final boolean in_ov ) {
4973 final private void setOvMaxHeight( final float ov_max_height ) {
4974 _ov_max_height = ov_max_height;
4977 final private void setOvMaxWidth( final float ov_max_width ) {
4978 _ov_max_width = ov_max_width;
4981 final private void setOvXcorrectionFactor( final float f ) {
4982 _ov_x_correction_factor = f;
4985 final private void setOvXDistance( final float ov_x_distance ) {
4986 _ov_x_distance = ov_x_distance;
4989 final private void setOvXPosition( final int ov_x_position ) {
4990 _ov_x_position = ov_x_position;
4993 final private void setOvYDistance( final float ov_y_distance ) {
4994 _ov_y_distance = ov_y_distance;
4997 final private void setOvYPosition( final int ov_y_position ) {
4998 _ov_y_position = ov_y_position;
5001 final private void setOvYStart( final int ov_y_start ) {
5002 _ov_y_start = ov_y_start;
5005 final private void setScaleDistance( final double scale_distance ) {
5006 _scale_distance = scale_distance;
5009 final private void setScaleLabel( final String scale_label ) {
5010 _scale_label = scale_label;
5013 final private void setUpUrtFactor() {
5014 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
5015 : getVisibleRect().height;
5016 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
5017 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
5020 final int max_depth = _circ_max_depth;
5021 if ( max_depth > 0 ) {
5022 setUrtFactor( d / ( 2 * max_depth ) );
5025 setUrtFactor( d / 2 );
5028 setUrtFactorOv( getUrtFactor() );
5031 final private void setUrtFactor( final float urt_factor ) {
5032 _urt_factor = urt_factor;
5035 final private void setUrtFactorOv( final float urt_factor_ov ) {
5036 _urt_factor_ov = urt_factor_ov;
5039 private void showExtDescNodeData( final PhylogenyNode node ) {
5040 final List<String> data = new ArrayList<String>();
5041 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
5042 switch ( getOptions().getExtDescNodeDataToReturn() ) {
5044 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
5045 data.add( n.getName() );
5049 if ( n.getNodeData().isHasSequence()
5050 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
5051 data.add( n.getNodeData().getSequence().getName() );
5054 case SEQUENCE_SYMBOL:
5055 if ( n.getNodeData().isHasSequence()
5056 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
5057 data.add( n.getNodeData().getSequence().getSymbol() );
5060 case SEQUENCE_MOL_SEQ:
5061 if ( n.getNodeData().isHasSequence()
5062 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
5063 data.add( n.getNodeData().getSequence().getMolecularSequence() );
5067 if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
5068 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
5069 data.add( n.getNodeData().getSequence().getAccession().toString() );
5072 case TAXONOMY_SCIENTIFIC_NAME:
5073 if ( n.getNodeData().isHasTaxonomy()
5074 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
5075 data.add( n.getNodeData().getTaxonomy().getScientificName() );
5079 if ( n.getNodeData().isHasTaxonomy()
5080 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
5081 data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
5085 AptxUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
5088 throw new IllegalArgumentException( "unknown data element: "
5089 + getOptions().getExtDescNodeDataToReturn() );
5092 if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
5093 || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
5094 final StringBuilder sb = new StringBuilder();
5095 for( final String d : data ) {
5096 if ( !ForesterUtil.isEmpty( d ) ) {
5097 if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
5098 System.out.println( d );
5101 sb.append( ForesterUtil.LINE_SEPARATOR );
5104 if ( sb.length() < 1 ) {
5105 clearCurrentExternalNodesDataBuffer();
5108 setCurrentExternalNodesDataBuffer( sb );
5111 else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
5112 final StringBuilder sb = new StringBuilder();
5113 for( final String d : data ) {
5114 if ( !ForesterUtil.isEmpty( d ) ) {
5116 sb.append( ForesterUtil.LINE_SEPARATOR );
5119 if ( sb.length() < 1 ) {
5120 AptxUtil.showInformationMessage( this,
5121 "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")",
5122 "Descendants of selected node do not contain selected data" );
5123 clearCurrentExternalNodesDataBuffer();
5126 setCurrentExternalNodesDataBuffer( sb );
5127 final String title = "External Descendants "
5128 + ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
5129 : obtainTitleForExtDescNodeData() ) + " (" + data.size() + "/"
5130 + node.getNumberOfExternalNodes() + ") For Node " + node;
5131 final String s = sb.toString().trim();
5132 if ( getMainPanel().getMainFrame() == null ) {
5133 // Must be "E" applet version.
5134 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
5135 ae.showTextFrame( s, title );
5138 getMainPanel().getMainFrame().showTextFrame( s, title );
5144 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
5146 if ( ( node.getName().length() > 0 )
5147 || ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
5148 || ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) )
5149 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
5150 || node.getBranchData().isHasConfidences() ) {
5151 _popup_buffer.setLength( 0 );
5153 if ( node.getName().length() > 0 ) {
5155 _popup_buffer.append( node.getName() );
5157 if ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
5159 boolean enc_data = false;
5160 final Taxonomy tax = node.getNodeData().getTaxonomy();
5161 if ( _popup_buffer.length() > 0 ) {
5162 _popup_buffer.append( "\n" );
5164 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
5165 _popup_buffer.append( "[" );
5166 _popup_buffer.append( tax.getTaxonomyCode() );
5167 _popup_buffer.append( "]" );
5170 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
5172 _popup_buffer.append( " " );
5174 _popup_buffer.append( tax.getScientificName() );
5177 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
5179 _popup_buffer.append( " (" );
5182 _popup_buffer.append( "(" );
5184 _popup_buffer.append( tax.getCommonName() );
5185 _popup_buffer.append( ")" );
5188 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
5190 _popup_buffer.append( " (" );
5193 _popup_buffer.append( "(" );
5195 _popup_buffer.append( tax.getAuthority() );
5196 _popup_buffer.append( ")" );
5199 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
5201 _popup_buffer.append( " [" );
5204 _popup_buffer.append( "[" );
5206 _popup_buffer.append( tax.getRank() );
5207 _popup_buffer.append( "]" );
5210 if ( tax.getSynonyms().size() > 0 ) {
5212 _popup_buffer.append( " " );
5214 _popup_buffer.append( "[" );
5216 for( final String syn : tax.getSynonyms() ) {
5217 if ( !ForesterUtil.isEmpty( syn ) ) {
5219 _popup_buffer.append( syn );
5220 if ( counter < tax.getSynonyms().size() ) {
5221 _popup_buffer.append( ", " );
5226 _popup_buffer.append( "]" );
5229 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
5230 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
5231 _popup_buffer.append( "[" );
5232 _popup_buffer.append( tax.getIdentifier().getProvider() );
5233 _popup_buffer.append( "] " );
5235 _popup_buffer.append( tax.getIdentifier().getValue() );
5239 if ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) ) {
5241 boolean enc_data = false;
5242 if ( _popup_buffer.length() > 0 ) {
5243 _popup_buffer.append( "\n" );
5245 final Sequence seq = node.getNodeData().getSequence();
5246 if ( seq.getAccession() != null ) {
5247 _popup_buffer.append( "[" );
5248 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
5249 _popup_buffer.append( seq.getAccession().getSource() );
5250 _popup_buffer.append( ":" );
5252 _popup_buffer.append( seq.getAccession().getValue() );
5253 _popup_buffer.append( "]" );
5256 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
5258 _popup_buffer.append( " [" );
5261 _popup_buffer.append( "[" );
5263 _popup_buffer.append( seq.getSymbol() );
5264 _popup_buffer.append( "]" );
5267 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
5269 _popup_buffer.append( " " );
5271 _popup_buffer.append( seq.getName() );
5274 if ( node.getNodeData().isHasDate() ) {
5276 if ( _popup_buffer.length() > 0 ) {
5277 _popup_buffer.append( "\n" );
5279 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
5281 if ( node.getNodeData().isHasDistribution() ) {
5283 if ( _popup_buffer.length() > 0 ) {
5284 _popup_buffer.append( "\n" );
5286 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
5288 if ( node.getBranchData().isHasConfidences() ) {
5289 final List<Confidence> confs = node.getBranchData().getConfidences();
5290 for( final Confidence confidence : confs ) {
5292 if ( _popup_buffer.length() > 0 ) {
5293 _popup_buffer.append( "\n" );
5295 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
5296 _popup_buffer.append( "[" );
5297 _popup_buffer.append( confidence.getType() );
5298 _popup_buffer.append( "] " );
5301 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
5303 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5304 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5305 _popup_buffer.append( " (sd=" );
5306 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence
5307 .getStandardDeviation(), getOptions()
5308 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5309 _popup_buffer.append( ")" );
5313 if ( node.getNodeData().isHasProperties() ) {
5314 final PropertiesMap properties = node.getNodeData().getProperties();
5315 for( final String ref : properties.getPropertyRefs() ) {
5316 _popup_buffer.append( "\n" );
5317 final Property p = properties.getProperty( ref );
5318 _popup_buffer.append( getPartAfterColon( p.getRef() ) );
5319 _popup_buffer.append( "=" );
5320 _popup_buffer.append( p.getValue() );
5321 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
5322 _popup_buffer.append( getPartAfterColon( p.getUnit() ) );
5326 if ( _popup_buffer.length() > 0 ) {
5327 if ( !getConfiguration().isUseNativeUI() ) {
5329 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
5330 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
5331 if ( isInFoundNodes( node ) ) {
5332 _rollover_popup.setForeground( getTreeColorSet().getFoundColor() );
5334 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
5335 _rollover_popup.setForeground( getTaxonomyBasedColor( node ) );
5338 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
5342 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
5344 _rollover_popup.setText( _popup_buffer.toString() );
5345 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
5347 e.getLocationOnScreen().x + 10,
5348 e.getLocationOnScreen().y
5350 _node_desc_popup.show();
5354 catch ( final Exception ex ) {
5359 final private void showNodeEditFrame( final PhylogenyNode n ) {
5360 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5361 // pop up edit box for single node
5362 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
5363 _node_frame_index++;
5366 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5370 final private void showNodeFrame( final PhylogenyNode n ) {
5371 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5372 // pop up edit box for single node
5373 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
5374 _node_frame_index++;
5377 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5381 final private void switchDisplaygetPhylogenyGraphicsType() {
5382 switch ( getPhylogenyGraphicsType() ) {
5384 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5385 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5388 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5389 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5392 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5393 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5396 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5397 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5400 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5401 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5404 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5405 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5408 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5409 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5412 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5413 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5416 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
5418 if ( getControlPanel().getDynamicallyHideData() != null ) {
5419 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5420 getControlPanel().getDynamicallyHideData().setEnabled( false );
5423 getControlPanel().getDynamicallyHideData().setEnabled( true );
5426 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5427 getControlPanel().setDrawPhylogramEnabled( true );
5430 getControlPanel().setDrawPhylogramEnabled( false );
5432 if ( getMainPanel().getMainFrame() == null ) {
5433 // Must be "E" applet version.
5434 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
5435 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5438 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5442 final private static void drawString( final int i, final double x, final double y, final Graphics2D g ) {
5443 g.drawString( String.valueOf( i ), ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5446 final private static void drawString( final String str, final double x, final double y, final Graphics2D g ) {
5447 g.drawString( str, ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5450 final private static String getPartAfterColon( final String s ) {
5451 final int i = s.indexOf( ':' );
5452 if ( ( i < 1 ) || ( i == ( s.length() - 1 ) ) ) {
5455 return s.substring( i + 1, s.length() );
5458 final private static boolean isSequenceEmpty( final Sequence seq ) {
5459 return ( seq.getAccession() == null ) && ForesterUtil.isEmpty( seq.getName() )
5460 && ForesterUtil.isEmpty( seq.getSymbol() );
5463 final private static boolean isTaxonomyEmpty( final Taxonomy tax ) {
5464 return ( ( tax.getIdentifier() == null ) && ForesterUtil.isEmpty( tax.getTaxonomyCode() )
5465 && ForesterUtil.isEmpty( tax.getCommonName() ) && ForesterUtil.isEmpty( tax.getScientificName() ) && tax
5466 .getSynonyms().isEmpty() );
5469 final private static boolean plusPressed( final int key_code ) {
5470 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
5471 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
5474 final private static Phylogeny subTree( final PhylogenyNode new_root, final Phylogeny source_phy ) {
5475 final Phylogeny new_phy = new Phylogeny();
5476 new_phy.setRooted( true );
5477 new_phy.setName( source_phy.getName() );
5478 new_phy.setDescription( source_phy.getDescription() );
5479 new_phy.setType( source_phy.getType() );
5480 new_phy.setDistanceUnit( source_phy.getDistanceUnit() );
5481 new_phy.setConfidence( source_phy.getConfidence() );
5482 new_phy.setIdentifier( source_phy.getIdentifier() );
5483 new_phy.setRoot( new_root.copyNodeDataShallow() );
5485 for( final PhylogenyNode n : new_root.getDescendants() ) {
5486 new_phy.getRoot().setChildNode( i++, n );
5491 final private class SubtreeColorizationActionListener implements ActionListener {
5493 JColorChooser _chooser;
5494 PhylogenyNode _node;
5496 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
5502 public void actionPerformed( final ActionEvent e ) {
5503 final Color c = _chooser.getColor();
5505 colorizeSubtree( c, _node );