2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.archaeopteryx;
28 import java.awt.BasicStroke;
29 import java.awt.Color;
30 import java.awt.Cursor;
31 import java.awt.Dimension;
33 import java.awt.GradientPaint;
34 import java.awt.Graphics;
35 import java.awt.Graphics2D;
36 import java.awt.Point;
37 import java.awt.Polygon;
38 import java.awt.Rectangle;
39 import java.awt.RenderingHints;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.FocusAdapter;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.InputEvent;
45 import java.awt.event.KeyAdapter;
46 import java.awt.event.KeyEvent;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseWheelEvent;
49 import java.awt.event.MouseWheelListener;
50 import java.awt.font.FontRenderContext;
51 import java.awt.font.TextLayout;
52 import java.awt.geom.AffineTransform;
53 import java.awt.geom.Arc2D;
54 import java.awt.geom.CubicCurve2D;
55 import java.awt.geom.Ellipse2D;
56 import java.awt.geom.Line2D;
57 import java.awt.geom.QuadCurve2D;
58 import java.awt.geom.Rectangle2D;
59 import java.awt.image.BufferedImage;
60 import java.awt.print.PageFormat;
61 import java.awt.print.Printable;
62 import java.awt.print.PrinterException;
64 import java.io.IOException;
65 import java.io.UnsupportedEncodingException;
67 import java.net.URISyntaxException;
68 import java.net.URLEncoder;
69 import java.text.DecimalFormat;
70 import java.text.DecimalFormatSymbols;
71 import java.text.NumberFormat;
72 import java.util.ArrayList;
73 import java.util.Collections;
74 import java.util.HashMap;
75 import java.util.HashSet;
76 import java.util.Hashtable;
77 import java.util.List;
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 // TODO "rendering_hints" was static before. Need to make sure everything is OK with it not
156 // being static anymore (02/20/2009).
157 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
158 RenderingHints.VALUE_RENDER_DEFAULT );
159 private File _treefile = null;
160 private Configuration _configuration = null;
161 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
162 private int _node_frame_index = 0;
163 private Phylogeny _phylogeny = null;
164 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
165 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
166 private int _subtree_index = 0;
167 private MainPanel _main_panel = null;
168 private Set<Integer> _found_nodes = null;
169 private PhylogenyNode _highlight_node = null;
170 private JPopupMenu _node_popup_menu = null;
171 private JMenuItem _node_popup_menu_items[] = null;
172 private int _longest_ext_node_info = 0;
173 private float _x_correction_factor = 0.0f;
174 private float _ov_x_correction_factor = 0.0f;
175 private float _x_distance = 0.0f;
176 private float _y_distance = 0.0f;
177 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
178 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
179 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
180 private float _last_drag_point_x = 0;
181 private float _last_drag_point_y = 0;
182 private ControlPanel _control_panel = null;
183 private int _external_node_index = 0;
184 private final Polygon _polygon = new Polygon();
185 private final StringBuilder _sb = new StringBuilder();
186 private JColorChooser _color_chooser = null;
187 private double _scale_distance = 0.0;
188 private String _scale_label = null;
189 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
190 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
191 private final Line2D _line = new Line2D.Float();
192 private final Ellipse2D _ellipse = new Ellipse2D.Float();
193 private final Rectangle2D _rectangle = new Rectangle2D.Float();
194 private Options _options = null;
195 private float _ov_max_width = 0;
196 private float _ov_max_height = 0;
197 private int _ov_x_position = 0;
198 private int _ov_y_position = 0;
199 private int _ov_y_start = 0;
200 private float _ov_y_distance = 0;
201 private float _ov_x_distance = 0;
202 private boolean _ov_on = false;
203 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
204 private float _urt_factor = 1;
205 private float _urt_factor_ov = 1;
206 private final boolean _phy_has_branch_lengths;
207 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
208 private boolean _in_ov_rect = false;
209 private boolean _in_ov = false;
210 private final Rectangle _ov_virtual_rectangle = new Rectangle();
211 final private static double _180_OVER_PI = 180.0 / Math.PI;
212 private static final float ROUNDED_D = 8;
213 private int _circ_max_depth;
214 private PhylogenyNode _root;
215 final private Arc2D _arc = new Arc2D.Double();
216 final private HashMap<Integer, Double> _urt_nodeid_angle_map = new HashMap<Integer, Double>();
217 final private HashMap<Integer, Integer> _urt_nodeid_index_map = new HashMap<Integer, Integer>();
218 final private Set<Integer> _collapsed_external_nodeid_set = new HashSet<Integer>();
219 HashMap<Integer, Short> _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
220 private AffineTransform _at;
221 private double _max_distance_to_root = -1;
222 private int _dynamic_hiding_factor = 0;
223 private boolean _edited = false;
224 private Popup _node_desc_popup;
225 private JTextArea _rollover_popup;
226 private final StringBuffer _popup_buffer = new StringBuffer();
227 final private static Font POPUP_FONT = new Font( Configuration
228 .getDefaultFontFamilyName(),
231 private Sequence _query_sequence = null;
232 private final FontRenderContext _frc = new FontRenderContext( null,
235 // expression values menu:
236 private DescriptiveStatistics _statistics_for_vector_data;
237 private PhylogenyNode[] _nodes_in_preorder = null;
238 private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
239 private int _current_external_nodes_data_buffer_change_counter = 0;
240 // private Image offscreenImage;
241 // private Graphics offscreenGraphics;
242 // private Dimension offscreenDimension;
244 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
245 dfs.setDecimalSeparator( '.' );
246 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
247 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
250 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
251 requestFocusInWindow();
252 addKeyListener( new KeyAdapter() {
255 public void keyPressed( final KeyEvent key_event ) {
256 keyPressedCalls( key_event );
257 requestFocusInWindow();
260 addFocusListener( new FocusAdapter() {
263 public void focusGained( final FocusEvent e ) {
264 requestFocusInWindow();
267 if ( ( t == null ) || t.isEmpty() ) {
268 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
270 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
272 _configuration = configuration;
274 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
276 // if ( !_phylogeny.isEmpty() ) {
277 _phylogeny.recalculateNumberOfExternalDescendants( true );
278 checkForVectorProperties( _phylogeny );
280 setBackground( getTreeColorSet().getBackgroundColor() );
281 final MouseListener mouse_listener = new MouseListener( this );
282 addMouseListener( mouse_listener );
283 addMouseMotionListener( mouse_listener );
284 addMouseWheelListener( this );
285 calculateScaleDistance();
286 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
287 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
288 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
292 final public void actionPerformed( final ActionEvent e ) {
293 boolean done = false;
294 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
295 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
296 // NOTE: index corresponds to the indices of click-to options
297 // in the control panel.
298 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
299 // Set this as the new default click-to action
300 _main_panel.getControlPanel().setClickToAction( index );
301 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
302 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
303 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
308 requestFocusInWindow();
311 public void checkForVectorProperties( final Phylogeny phy ) {
312 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
313 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
314 final PhylogenyNode node = iter.next();
315 if ( node.getNodeData().getProperties() != null ) {
316 final PropertiesMap pm = node.getNodeData().getProperties();
317 final double[] vector = new double[ pm.getProperties().size() ];
319 for( final String ref : pm.getProperties().keySet() ) {
320 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
321 final Property p = pm.getProperty( ref );
322 final String value_str = p.getValue();
323 final String index_str = ref
324 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
327 d = Double.parseDouble( value_str );
329 catch ( final NumberFormatException e ) {
330 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
331 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
336 i = Integer.parseInt( index_str );
338 catch ( final NumberFormatException e ) {
339 JOptionPane.showMessageDialog( this,
340 "Could not parse \"" + index_str
341 + "\" into index for vector data",
342 "Problem with Vector Data",
343 JOptionPane.ERROR_MESSAGE );
347 JOptionPane.showMessageDialog( this,
348 "Attempt to use negative index for vector data",
349 "Problem with Vector Data",
350 JOptionPane.ERROR_MESSAGE );
358 final List<Double> vector_l = new ArrayList<Double>( counter );
359 for( int i = 0; i < counter; ++i ) {
360 vector_l.add( vector[ i ] );
362 node.getNodeData().setVector( vector_l );
365 if ( stats.getN() > 0 ) {
366 _statistics_for_vector_data = stats;
370 public synchronized Hashtable<String, BufferedImage> getImageMap() {
371 return getMainPanel().getImageMap();
374 final public MainPanel getMainPanel() {
379 * Get a pointer to the phylogeny
381 * @return a pointer to the phylogeny
383 public final Phylogeny getPhylogeny() {
388 final public void mouseWheelMoved( final MouseWheelEvent e ) {
389 final int notches = e.getWheelRotation();
390 if ( inOvVirtualRectangle( e ) ) {
391 if ( !isInOvRect() ) {
397 if ( isInOvRect() ) {
398 setInOvRect( false );
402 if ( e.isControlDown() ) {
404 getTreeFontSet().increaseFontSize();
405 getControlPanel().displayedPhylogenyMightHaveChanged( true );
408 getTreeFontSet().decreaseFontSize();
409 getControlPanel().displayedPhylogenyMightHaveChanged( true );
412 else if ( e.isShiftDown() ) {
413 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
414 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
416 for( int i = 0; i < ( -notches ); ++i ) {
417 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
418 getControlPanel().displayedPhylogenyMightHaveChanged( false );
422 for( int i = 0; i < notches; ++i ) {
423 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
424 if ( getStartingAngle() < 0 ) {
425 setStartingAngle( TWO_PI + getStartingAngle() );
427 getControlPanel().displayedPhylogenyMightHaveChanged( false );
433 for( int i = 0; i < ( -notches ); ++i ) {
434 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
435 getControlPanel().displayedPhylogenyMightHaveChanged( false );
439 for( int i = 0; i < notches; ++i ) {
440 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
441 getControlPanel().displayedPhylogenyMightHaveChanged( false );
448 for( int i = 0; i < ( -notches ); ++i ) {
449 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
450 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
451 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
452 getControlPanel().displayedPhylogenyMightHaveChanged( false );
456 for( int i = 0; i < notches; ++i ) {
457 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
458 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
459 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
460 getControlPanel().displayedPhylogenyMightHaveChanged( false );
465 requestFocusInWindow();
470 final public void paintComponent( final Graphics g ) {
471 // Dimension currentSize = getSize();
472 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
473 // call the 'java.awt.Component.createImage(...)' method to get an
475 // offscreenImage = createImage( currentSize.width, currentSize.height );
476 // offscreenGraphics = offscreenImage.getGraphics();
477 // offscreenDimension = currentSize;
479 // super.paintComponent( g ); //why?
480 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
481 final Graphics2D g2d = ( Graphics2D ) g;
482 g2d.setRenderingHints( _rendering_hints );
483 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
484 //g.drawImage( offscreenImage, 0, 0, this );
488 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
489 throws PrinterException {
490 if ( page_index > 0 ) {
491 return ( NO_SUCH_PAGE );
494 final Graphics2D g2d = ( Graphics2D ) g;
495 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
496 // Turn off double buffering !?
497 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
498 // Turn double buffering back on !?
499 return ( PAGE_EXISTS );
503 public final void setArrowCursor() {
504 setCursor( ARROW_CURSOR );
508 public final void setEdited( final boolean edited ) {
512 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
513 getMainPanel().setImageMap( image_map );
517 * Set parameters for printing the displayed tree
522 public final void setParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
523 // updateStyle(); not needed?
524 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
526 if ( recalc_longest_ext_node_info ) {
527 calculateLongestExtNodeInfo();
529 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
530 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
531 if ( ext_nodes == 1 ) {
532 ext_nodes = max_depth;
533 if ( ext_nodes < 1 ) {
540 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
541 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
542 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
545 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
546 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
548 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
552 if ( ov_xdist < 0.0 ) {
558 setXdistance( xdist );
559 setYdistance( ydist );
560 setOvXDistance( ov_xdist );
561 final double height = _phylogeny.getHeight();
563 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
564 setXcorrectionFactor( corr > 0 ? corr : 0 );
565 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
566 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
569 setXcorrectionFactor( 0 );
570 setOvXcorrectionFactor( 0 );
572 _circ_max_depth = max_depth;
578 * Set a phylogeny tree.
581 * an instance of a Phylogeny
583 public final void setTree( final Phylogeny t ) {
584 setNodeInPreorderToNull();
588 public final void setWaitCursor() {
589 setCursor( WAIT_CURSOR );
594 public void update( final Graphics g ) {
598 final void calcMaxDepth() {
599 if ( _phylogeny != null ) {
600 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
604 final void calculateLongestExtNodeInfo() {
605 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
608 int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - MOVE )
609 * Constants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
610 if ( max_length < 40 ) {
614 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
616 if ( node.isCollapse() ) {
619 if ( getControlPanel().isShowNodeNames() ) {
620 sum += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
622 if ( node.getNodeData().isHasSequence() ) {
623 if ( getControlPanel().isShowSequenceAcc()
624 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
625 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
629 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
630 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
632 if ( getControlPanel().isShowGeneSymbols()
633 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
634 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
636 if ( getControlPanel().isShowAnnotation()
637 && ( node.getNodeData().getSequence().getAnnotations() != null )
638 && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
639 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAnnotation( 0 )
643 if ( getControlPanel().isShowDomainArchitectures()
644 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
645 sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() )
646 .getRenderingSize().getWidth();
649 if ( node.getNodeData().isHasTaxonomy() ) {
650 final Taxonomy tax = node.getNodeData().getTaxonomy();
651 if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
652 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getTaxonomyCode() + " " );
654 if ( getControlPanel().isShowTaxonomyScientificNames()
655 && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
656 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getScientificName() + " " );
658 if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
659 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getCommonName() + " ()" );
662 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
663 sum += getTreeFontSet()._fm_large.stringWidth( propertiesToString( node ).toString() );
665 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
666 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters()
667 .getGainedCharactersAsStringBuffer().toString() );
669 if ( sum >= max_length ) {
670 setLongestExtNodeInfo( max_length );
673 if ( sum > longest ) {
677 if ( longest >= max_length ) {
678 setLongestExtNodeInfo( max_length );
681 setLongestExtNodeInfo( longest );
685 final void calculateScaleDistance() {
686 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
689 final double height = getMaxDistanceToRoot();
691 if ( ( height <= 0.5 ) ) {
692 setScaleDistance( 0.01 );
694 else if ( height <= 5.0 ) {
695 setScaleDistance( 0.1 );
697 else if ( height <= 50.0 ) {
698 setScaleDistance( 1 );
700 else if ( height <= 500.0 ) {
701 setScaleDistance( 10 );
704 setScaleDistance( 100 );
708 setScaleDistance( 0.0 );
710 String scale_label = String.valueOf( getScaleDistance() );
711 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
712 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
714 setScaleLabel( scale_label );
717 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
718 String species = tax.getTaxonomyCode();
719 if ( ForesterUtil.isEmpty( species ) ) {
720 species = tax.getScientificName();
721 if ( ForesterUtil.isEmpty( species ) ) {
722 species = tax.getCommonName();
725 if ( ForesterUtil.isEmpty( species ) ) {
726 return getTreeColorSet().getTaxonomyColor();
728 // Look in species hash
729 Color c = getControlPanel().getSpeciesColors().get( species );
731 c = AptxUtil.calculateColorFromString( species );
732 getControlPanel().getSpeciesColors().put( species, c );
737 void clearCurrentExternalNodesDataBuffer() {
738 setCurrentExternalNodesDataBuffer( new StringBuilder() );
742 * Collapse the tree from the given node
747 final void collapse( final PhylogenyNode node ) {
748 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
749 JOptionPane.showMessageDialog( this,
750 "Cannot collapse in unrooted display type",
751 "Attempt to collapse in unrooted display",
752 JOptionPane.WARNING_MESSAGE );
755 if ( !node.isExternal() && !node.isRoot() ) {
756 final boolean collapse = !node.isCollapse();
757 AptxUtil.collapseSubtree( node, collapse );
758 updateSetOfCollapsedExternalNodes();
759 _phylogeny.recalculateNumberOfExternalDescendants( true );
760 resetNodeIdToDistToLeafMap();
761 calculateLongestExtNodeInfo();
762 setNodeInPreorderToNull();
763 _control_panel.displayedPhylogenyMightHaveChanged( true );
764 resetPreferredSize();
766 _main_panel.adjustJScrollPane();
771 final void collapseSpeciesSpecificSubtrees() {
772 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
776 AptxUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
777 updateSetOfCollapsedExternalNodes();
778 _phylogeny.recalculateNumberOfExternalDescendants( true );
779 resetNodeIdToDistToLeafMap();
780 calculateLongestExtNodeInfo();
781 setNodeInPreorderToNull();
782 resetPreferredSize();
783 _main_panel.adjustJScrollPane();
788 final void colorRank( final String rank ) {
789 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
793 AptxUtil.removeBranchColors( _phylogeny );
794 final int colorizations = AptxUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
795 if ( colorizations > 0 ) {
796 _control_panel.setColorBranches( true );
797 if ( _control_panel.getColorBranchesCb() != null ) {
798 _control_panel.getColorBranchesCb().setSelected( true );
800 if ( _control_panel.getColorAccSpeciesCb() != null ) {
801 _control_panel.getColorAccSpeciesCb().setSelected( false );
803 _options.setColorLabelsSameAsParentBranch( true );
804 _control_panel.repaint();
808 if ( colorizations > 0 ) {
809 String msg = "Taxonomy colorization via " + rank + " completed:\n";
810 if ( colorizations > 1 ) {
811 msg += "colorized " + colorizations + " subtrees";
814 msg += "colorized one subtree";
816 JOptionPane.showMessageDialog( this,
818 "Taxonomy Colorization Completed (" + rank + ")",
819 JOptionPane.INFORMATION_MESSAGE );
822 String msg = "Could not taxonomy colorize any subtree via " + rank + ".\n";
823 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
824 msg += "select a different rank (e.g. phylum, genus, ...)\n";
827 msg += "1. \"" + MainFrameApplication.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
828 msg += "2. \"" + MainFrameApplication.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
829 JOptionPane.showMessageDialog( this, msg, "Taxonomy Colorization Failed", JOptionPane.WARNING_MESSAGE );
833 final void confColor() {
834 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
838 AptxUtil.removeBranchColors( _phylogeny );
839 AptxUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
840 _control_panel.setColorBranches( true );
841 if ( _control_panel.getColorBranchesCb() != null ) {
842 _control_panel.getColorBranchesCb().setSelected( true );
848 final void decreaseDomainStructureEvalueThreshold() {
849 if ( _domain_structure_e_value_thr_exp > -20 ) {
850 _domain_structure_e_value_thr_exp -= 1;
855 * Find the node, if any, at the given location
859 * @return pointer to the node at x,y, null if not found
861 final PhylogenyNode findNode( final int x, final int y ) {
862 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
865 final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE;
866 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
867 final PhylogenyNode node = iter.next();
868 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
869 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
870 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
871 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
872 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
879 final Configuration getConfiguration() {
880 return _configuration;
883 final ControlPanel getControlPanel() {
884 return _control_panel;
887 String getCurrentExternalNodesDataBufferAsString() {
888 return _current_external_nodes_data_buffer.toString();
891 int getCurrentExternalNodesDataBufferChangeCounter() {
892 return _current_external_nodes_data_buffer_change_counter;
895 final int getDomainStructureEvalueThreshold() {
896 return _domain_structure_e_value_thr_exp;
899 final Set<Integer> getFoundNodes() {
903 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
904 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
905 return ( PhylogenyMethods.getBranchColorValue( node ) );
908 return ( getTreeColorSet().getBranchColor() );
912 final int getLongestExtNodeInfo() {
913 return _longest_ext_node_info;
916 final Options getOptions() {
917 if ( _options == null ) {
918 _options = getControlPanel().getOptions();
923 final Rectangle2D getOvRectangle() {
924 return _ov_rectangle;
927 final Rectangle getOvVirtualRectangle() {
928 return _ov_virtual_rectangle;
931 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
932 return _graphics_type;
935 final double getStartingAngle() {
936 return _urt_starting_angle;
939 DescriptiveStatistics getStatisticsForExpressionValues() {
940 return _statistics_for_vector_data;
944 * Find a color for this species name.
947 * @return the species color
949 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
950 if ( node.getNodeData().isHasTaxonomy() ) {
951 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
953 // return non-colorized color
954 return getTreeColorSet().getTaxonomyColor();
958 * @return pointer to colorset for tree drawing
960 final TreeColorSet getTreeColorSet() {
961 return getMainPanel().getTreeColorSet();
964 final File getTreeFile() {
968 final float getXcorrectionFactor() {
969 return _x_correction_factor;
972 final float getXdistance() {
976 final float getYdistance() {
980 final void increaseDomainStructureEvalueThreshold() {
981 if ( _domain_structure_e_value_thr_exp < 3 ) {
982 _domain_structure_e_value_thr_exp += 1;
986 final void initNodeData() {
987 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
990 double max_original_domain_structure_width = 0.0;
991 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
992 if ( node.getNodeData().isHasSequence()
993 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
994 RenderableDomainArchitecture rds = null;
995 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
996 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
997 getConfiguration() );
998 node.getNodeData().getSequence().setDomainArchitecture( rds );
1001 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1003 if ( getControlPanel().isShowDomainArchitectures() ) {
1004 final double dsw = rds.getOriginalSize().getWidth();
1005 if ( dsw > max_original_domain_structure_width ) {
1006 max_original_domain_structure_width = dsw;
1011 if ( getControlPanel().isShowDomainArchitectures() ) {
1012 final double ds_factor_width = _domain_structure_width / max_original_domain_structure_width;
1013 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1014 if ( node.getNodeData().isHasSequence()
1015 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1016 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1017 .getSequence().getDomainArchitecture();
1018 rds.setRenderingFactorWidth( ds_factor_width );
1019 rds.setParameter( _domain_structure_e_value_thr_exp );
1025 final boolean inOv( final MouseEvent e ) {
1026 return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) )
1027 && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) )
1028 && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) ) && ( e.getY() < ( ( getVisibleRect().y
1029 + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) );
1032 final boolean inOvRectangle( final MouseEvent e ) {
1033 return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) )
1034 && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) )
1035 && ( e.getY() >= ( getOvRectangle().getY() - 1 ) ) && ( e.getY() <= ( getOvRectangle().getY()
1036 + getOvRectangle().getHeight() + 1 ) ) );
1039 final boolean isApplet() {
1040 return getMainPanel() instanceof MainPanelApplets;
1043 final boolean isCanCollapse() {
1044 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1047 final boolean isCanColorSubtree() {
1048 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1051 final boolean isCanCopy() {
1052 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1055 final boolean isCanCut( final PhylogenyNode node ) {
1056 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1060 final boolean isCanDelete() {
1061 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1064 final boolean isCanPaste() {
1065 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1066 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1069 final boolean isCanReroot() {
1070 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1073 final boolean isCanSubtree( final PhylogenyNode node ) {
1074 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1075 .isRoot() || ( _subtree_index > 0 ) ) );
1078 final boolean isCurrentTreeIsSubtree() {
1079 return ( _subtree_index > 0 );
1082 final boolean isEdited() {
1086 final boolean isInOvRect() {
1090 final boolean isOvOn() {
1094 final boolean isPhyHasBranchLengths() {
1095 return _phy_has_branch_lengths;
1098 final void midpointRoot() {
1099 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1102 if ( !_phylogeny.isRerootable() ) {
1103 JOptionPane.showMessageDialog( this,
1104 "This is not rerootable",
1106 JOptionPane.WARNING_MESSAGE );
1109 setNodeInPreorderToNull();
1111 PhylogenyMethods.midpointRoot( _phylogeny );
1112 resetNodeIdToDistToLeafMap();
1117 final void mouseClicked( final MouseEvent e ) {
1118 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1119 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1120 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1121 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) )
1123 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) )
1131 final double max_x = getWidth() - getVisibleRect().width;
1132 final double max_y = getHeight() - getVisibleRect().height;
1139 getMainPanel().getCurrentScrollPane().getViewport()
1140 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1141 setInOvRect( true );
1145 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1146 if ( node != null ) {
1147 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1150 _highlight_node = node;
1151 // Check if shift key is down
1152 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1153 // Yes, so add to _found_nodes
1154 if ( getFoundNodes() == null ) {
1155 setFoundNodes( new HashSet<Integer>() );
1157 getFoundNodes().add( node.getId() );
1158 // Check if control key is down
1160 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1161 // Yes, so pop-up menu
1162 displayNodePopupMenu( node, e.getX(), e.getY() );
1163 // Handle unadorned click
1166 // Check for right mouse button
1167 if ( e.getModifiers() == 4 ) {
1168 displayNodePopupMenu( node, e.getX(), e.getY() );
1171 // if not in _found_nodes, clear _found_nodes
1172 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1177 // no node was clicked
1178 _highlight_node = null;
1184 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1185 setCursor( MOVE_CURSOR );
1186 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1187 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1188 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1189 if ( scroll_position.x < 0 ) {
1190 scroll_position.x = 0;
1193 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1194 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1195 if ( scroll_position.x > max_x ) {
1196 scroll_position.x = max_x;
1199 if ( scroll_position.y < 0 ) {
1200 scroll_position.y = 0;
1203 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1204 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1205 if ( scroll_position.y > max_y ) {
1206 scroll_position.y = max_y;
1209 if ( isOvOn() || getOptions().isShowScale() ) {
1212 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1215 final void mouseDragInOvRectangle( final MouseEvent e ) {
1216 setCursor( HAND_CURSOR );
1217 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1218 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1219 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1220 double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) );
1221 double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) );
1222 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1223 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1224 if ( scroll_position.x <= 0 ) {
1225 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 ) {
1233 scroll_position.x = max_x;
1236 if ( scroll_position.y <= 0 ) {
1238 scroll_position.y = 0;
1241 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1242 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1243 if ( scroll_position.y >= max_y ) {
1245 scroll_position.y = max_y;
1249 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1250 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1251 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1254 final void mouseMoved( final MouseEvent e ) {
1255 requestFocusInWindow();
1256 if ( getControlPanel().isNodeDescPopup() ) {
1257 if ( _node_desc_popup != null ) {
1258 _node_desc_popup.hide();
1259 _node_desc_popup = null;
1262 if ( getOptions().isShowOverview() && isOvOn() ) {
1263 if ( inOvVirtualRectangle( e ) ) {
1264 if ( !isInOvRect() ) {
1265 setInOvRect( true );
1270 if ( isInOvRect() ) {
1271 setInOvRect( false );
1276 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
1285 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1286 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
1287 // cursor is over a tree node
1288 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
1289 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
1290 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
1291 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
1292 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
1293 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
1294 setCursor( CUT_CURSOR );
1297 setCursor( HAND_CURSOR );
1298 if ( getControlPanel().isNodeDescPopup() ) {
1299 showNodeDataPopup( e, node );
1304 setCursor( ARROW_CURSOR );
1309 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
1310 setCursor( ARROW_CURSOR );
1313 final void multiplyUrtFactor( final float f ) {
1317 final JApplet obtainApplet() {
1318 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1321 final void paintBranchCircular( final PhylogenyNode p,
1322 final PhylogenyNode c,
1324 final boolean radial_labels,
1325 final boolean to_pdf,
1326 final boolean to_graphics_file ) {
1327 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1328 final double root_x = _root.getXcoord();
1329 final double root_y = _root.getYcoord();
1330 final double dx = root_x - p.getXcoord();
1331 final double dy = root_y - p.getYcoord();
1332 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1333 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1334 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
1335 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
1336 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
1337 final double r2 = 2.0 * parent_radius;
1338 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1340 drawLine( c.getXcoord(),
1342 root_x + ( Math.cos( angle ) * parent_radius ),
1343 root_y + ( Math.sin( angle ) * parent_radius ),
1345 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c ) );
1346 if ( c.isExternal() ) {
1347 final boolean is_in_found_nodes = isInFoundNodes( c );
1348 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
1349 && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
1352 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
1356 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
1357 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1358 final double root_x = _root.getXSecondary();
1359 final double root_y = _root.getYSecondary();
1360 final double dx = root_x - p.getXSecondary();
1361 final double dy = root_y - p.getYSecondary();
1362 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1363 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1364 g.setColor( getTreeColorSet().getOvColor() );
1365 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
1366 final double r2 = 2.0 * parent_radius;
1367 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1369 drawLine( c.getXSecondary(),
1371 root_x + ( Math.cos( angle ) * parent_radius ),
1372 root_y + ( Math.sin( angle ) * parent_radius ),
1374 if ( isInFoundNodes( c ) ) {
1375 g.setColor( getTreeColorSet().getFoundColor() );
1376 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
1380 final void paintCircular( final Phylogeny phy,
1381 final double starting_angle,
1386 final boolean to_pdf,
1387 final boolean to_graphics_file ) {
1388 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
1389 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
1390 _root = phy.getRoot();
1391 _root.setXcoord( center_x );
1392 _root.setYcoord( center_y );
1393 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1394 double current_angle = starting_angle;
1396 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1397 final PhylogenyNode n = it.next();
1398 if ( !n.isCollapse() ) {
1399 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1400 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1401 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1402 _urt_nodeid_index_map.put( n.getId(), i++ );
1403 current_angle += ( TWO_PI / circ_num_ext_nodes );
1407 System.out.println( "is collapse" + n.getName() );
1410 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
1411 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file, isInFoundNodes( _root ) );
1414 final void paintCircularLite( final Phylogeny phy,
1415 final double starting_angle,
1419 final Graphics2D g ) {
1420 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
1421 _root = phy.getRoot();
1422 _root.setXSecondary( center_x );
1423 _root.setYSecondary( center_y );
1424 double current_angle = starting_angle;
1425 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1426 final PhylogenyNode n = it.next();
1427 n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1428 n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1429 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1430 current_angle += ( TWO_PI / circ_num_ext_nodes );
1432 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
1435 final void paintPhylogeny( final Graphics2D g,
1436 final boolean to_pdf,
1437 final boolean to_graphics_file,
1438 final int graphics_file_width,
1439 final int graphics_file_height,
1440 final int graphics_file_x,
1441 final int graphics_file_y ) {
1442 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1445 if ( _control_panel.isShowSequenceRelations() ) {
1446 _query_sequence = _control_panel.getSelectedQuerySequence();
1448 // Color the background
1450 final Rectangle r = getVisibleRect();
1451 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
1452 g.setColor( getTreeColorSet().getBackgroundColor() );
1453 if ( !to_graphics_file ) {
1457 if ( getOptions().isPrintBlackAndWhite() ) {
1458 g.setColor( Color.WHITE );
1460 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1464 if ( !to_graphics_file ) {
1465 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
1466 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
1470 g.setPaint( new GradientPaint( graphics_file_x,
1472 getTreeColorSet().getBackgroundColor(),
1474 graphics_file_y + graphics_file_height,
1475 getTreeColorSet().getBackgroundColorGradientBottom() ) );
1476 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1479 g.setStroke( new BasicStroke( 1 ) );
1482 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
1484 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1485 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1486 _external_node_index = 0;
1487 // Position starting X of tree
1488 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
1489 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
1491 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
1492 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
1493 .getDistanceToParent() * getXcorrectionFactor() ) ) );
1496 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
1498 // Position starting Y of tree
1499 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
1500 + ( TreePanel.MOVE / 2.0f ) );
1501 final int dynamic_hiding_factor = ( int ) ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) );
1502 if ( getControlPanel().isDynamicallyHideData() ) {
1503 if ( dynamic_hiding_factor > 1 ) {
1504 getControlPanel().setDynamicHidingIsOn( true );
1507 getControlPanel().setDynamicHidingIsOn( false );
1510 if ( _nodes_in_preorder == null ) {
1511 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
1513 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1514 _nodes_in_preorder[ i++ ] = it.next();
1517 //final PhylogenyNodeIterator it;
1518 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1519 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
1520 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1522 for( final PhylogenyNode element : _nodes_in_preorder ) {
1523 paintNodeRectangular( g, element, to_pdf, getControlPanel().isDynamicallyHideData()
1524 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1526 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
1527 if ( !( to_graphics_file || to_pdf ) ) {
1530 getVisibleRect().y + getVisibleRect().height,
1535 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1538 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1539 paintPhylogenyLite( g );
1542 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1543 if ( getControlPanel().getDynamicallyHideData() != null ) {
1544 getControlPanel().setDynamicHidingIsOn( false );
1546 final double angle = getStartingAngle();
1547 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1548 _dynamic_hiding_factor = 0;
1549 if ( getControlPanel().isDynamicallyHideData() ) {
1550 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
1551 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
1553 if ( getControlPanel().getDynamicallyHideData() != null ) {
1554 if ( _dynamic_hiding_factor > 1 ) {
1555 getControlPanel().setDynamicHidingIsOn( true );
1558 getControlPanel().setDynamicHidingIsOn( false );
1561 paintUnrooted( _phylogeny.getRoot(),
1563 ( float ) ( angle + ( 2 * Math.PI ) ),
1568 if ( getOptions().isShowScale() ) {
1569 if ( !( to_graphics_file || to_pdf ) ) {
1572 getVisibleRect().y + getVisibleRect().height,
1577 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1580 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1581 g.setColor( getTreeColorSet().getOvColor() );
1582 paintUnrootedLite( _phylogeny.getRoot(),
1584 angle + ( 2 * Math.PI ),
1586 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
1587 paintOvRectangle( g );
1590 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1591 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
1592 final int d = radius + MOVE + getLongestExtNodeInfo();
1593 _dynamic_hiding_factor = 0;
1594 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
1595 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
1596 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
1598 if ( getControlPanel().getDynamicallyHideData() != null ) {
1599 if ( _dynamic_hiding_factor > 1 ) {
1600 getControlPanel().setDynamicHidingIsOn( true );
1603 getControlPanel().setDynamicHidingIsOn( false );
1606 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
1607 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1608 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
1609 : getOvMaxWidth() / 2 );
1610 double x_scale = 1.0;
1611 double y_scale = 1.0;
1612 int x_pos = getVisibleRect().x + getOvXPosition();
1613 int y_pos = getVisibleRect().y + getOvYPosition();
1614 if ( getWidth() > getHeight() ) {
1615 x_scale = ( double ) getHeight() / getWidth();
1616 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
1619 y_scale = ( double ) getWidth() / getHeight();
1620 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
1622 _at = g.getTransform();
1623 g.scale( x_scale, y_scale );
1624 paintCircularLite( _phylogeny,
1628 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
1631 g.setTransform( _at );
1632 paintOvRectangle( g );
1637 final void recalculateMaxDistanceToRoot() {
1638 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
1642 * Remove all edit-node frames
1644 final void removeAllEditNodeJFrames() {
1645 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
1646 if ( _node_frames[ i ] != null ) {
1647 _node_frames[ i ].dispose();
1648 _node_frames[ i ] = null;
1651 _node_frame_index = 0;
1655 * Remove a node-edit frame.
1657 final void removeEditNodeFrame( final int i ) {
1658 _node_frame_index--;
1659 _node_frames[ i ] = null;
1660 if ( i < _node_frame_index ) {
1661 for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) {
1662 _node_frames[ j ] = _node_frames[ j + 1 ];
1664 _node_frames[ _node_frame_index ] = null;
1668 final void reRoot( final PhylogenyNode node ) {
1669 if ( !getPhylogeny().isRerootable() ) {
1670 JOptionPane.showMessageDialog( this,
1671 "This is not rerootable",
1673 JOptionPane.WARNING_MESSAGE );
1676 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1677 JOptionPane.showMessageDialog( this,
1678 "Cannot reroot in unrooted display type",
1679 "Attempt to reroot tree in unrooted display",
1680 JOptionPane.WARNING_MESSAGE );
1683 getPhylogeny().reRoot( node );
1684 getPhylogeny().recalculateNumberOfExternalDescendants( true );
1685 resetNodeIdToDistToLeafMap();
1686 setNodeInPreorderToNull();
1687 resetPreferredSize();
1688 getMainPanel().adjustJScrollPane();
1690 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1691 getControlPanel().showWhole();
1695 final void resetNodeIdToDistToLeafMap() {
1696 _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
1699 final void resetPreferredSize() {
1700 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
1706 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
1707 if ( getControlPanel().isDrawPhylogram() ) {
1709 + getLongestExtNodeInfo()
1711 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
1714 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
1716 + getLongestExtNodeInfo()
1717 + ForesterUtil.roundToInt( getXdistance()
1718 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
1722 + getLongestExtNodeInfo()
1723 + ForesterUtil.roundToInt( getXdistance()
1724 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
1727 setPreferredSize( new Dimension( x, y ) );
1730 final void selectNode( final PhylogenyNode node ) {
1731 if ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) ) {
1732 getFoundNodes().remove( node.getId() );
1733 getControlPanel().setSearchFoundCountsOnLabel( getFoundNodes().size() );
1734 if ( getFoundNodes().size() < 1 ) {
1735 getControlPanel().searchReset();
1739 getControlPanel().getSearchFoundCountsLabel().setVisible( true );
1740 getControlPanel().getSearchResetButton().setEnabled( true );
1741 getControlPanel().getSearchResetButton().setVisible( true );
1742 if ( getFoundNodes() == null ) {
1743 setFoundNodes( new HashSet<Integer>() );
1745 getFoundNodes().add( node.getId() );
1746 getControlPanel().setSearchFoundCountsOnLabel( getFoundNodes().size() );
1750 final void setControlPanel( final ControlPanel atv_control ) {
1751 _control_panel = atv_control;
1754 void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
1755 increaseCurrentExternalNodesDataBufferChangeCounter();
1756 _current_external_nodes_data_buffer = sb;
1757 System.out.println( sb.toString() ); //TODO ~~~~~~~~~~~~~~ REMOVEME
1760 final void setFoundNodes( final Set<Integer> found_nodes ) {
1761 _found_nodes = found_nodes;
1764 final void setInOvRect( final boolean in_ov_rect ) {
1765 _in_ov_rect = in_ov_rect;
1768 final void setLargeFonts() {
1769 getTreeFontSet().largeFonts();
1772 final void setLastMouseDragPointX( final float x ) {
1773 _last_drag_point_x = x;
1776 final void setLastMouseDragPointY( final float y ) {
1777 _last_drag_point_y = y;
1780 final void setLongestExtNodeInfo( final int i ) {
1781 _longest_ext_node_info = i;
1784 final void setMediumFonts() {
1785 getTreeFontSet().mediumFonts();
1788 final void setNodeInPreorderToNull() {
1789 _nodes_in_preorder = null;
1792 final void setOvOn( final boolean ov_on ) {
1796 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
1797 _graphics_type = graphics_type;
1801 final void setSmallFonts() {
1802 getTreeFontSet().smallFonts();
1805 final void setStartingAngle( final double starting_angle ) {
1806 _urt_starting_angle = starting_angle;
1809 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
1810 _statistics_for_vector_data = statistics_for_expression_values;
1813 final void setSuperTinyFonts() {
1814 getTreeFontSet().superTinyFonts();
1817 final void setTextAntialias() {
1818 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
1819 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
1820 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
1823 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
1826 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
1827 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
1828 && !getMainPanel().getOptions().isShowDefaultNodeShapes()
1829 && ( ( getControlPanel() != null ) && !getControlPanel().isShowDomainArchitectures() ) ) {
1830 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1833 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
1836 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING,
1837 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
1839 catch ( final Throwable e ) {
1840 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
1844 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
1845 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1849 final void setTinyFonts() {
1850 getTreeFontSet().tinyFonts();
1853 final void setTreeFile( final File treefile ) {
1854 _treefile = treefile;
1857 final void setXcorrectionFactor( final float f ) {
1858 _x_correction_factor = f;
1861 final void setXdistance( final float x ) {
1865 final void setYdistance( final float y ) {
1869 final void sortDescendants( final PhylogenyNode node ) {
1870 if ( !node.isExternal() ) {
1871 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
1872 if ( ( !getControlPanel().isShowTaxonomyScientificNames() && !getControlPanel().isShowTaxonomyCode() && !getControlPanel()
1873 .isShowTaxonomyCommonNames() ) ) {
1874 if ( ( getControlPanel().isShowSequenceAcc() || getControlPanel().isShowGeneNames() || getControlPanel()
1875 .isShowGeneSymbols() ) ) {
1876 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
1878 else if ( getControlPanel().isShowNodeNames() ) {
1879 pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
1882 PhylogenyMethods.sortNodeDescendents( node, pri );
1883 setNodeInPreorderToNull();
1884 _phylogeny.externalNodesHaveChanged();
1885 _phylogeny.clearHashIdToNodeMap();
1886 _phylogeny.recalculateNumberOfExternalDescendants( true );
1887 resetNodeIdToDistToLeafMap();
1893 final void subTree( final PhylogenyNode node ) {
1894 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1895 JOptionPane.showMessageDialog( this,
1896 "Cannot get a sub/super tree in unrooted display",
1897 "Attempt to get sub/super tree in unrooted display",
1898 JOptionPane.WARNING_MESSAGE );
1901 if ( node.isExternal() ) {
1902 JOptionPane.showMessageDialog( this,
1903 "Cannot get a subtree of a external node",
1904 "Attempt to get subtree of external node",
1905 JOptionPane.WARNING_MESSAGE );
1908 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
1909 JOptionPane.showMessageDialog( this,
1910 "Cannot get a subtree of the root node",
1911 "Attempt to get subtree of root node",
1912 JOptionPane.WARNING_MESSAGE );
1915 setNodeInPreorderToNull();
1916 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
1917 _sub_phylogenies[ _subtree_index ] = _phylogeny;
1918 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
1920 _phylogeny = subTree( node, _phylogeny );
1921 updateSubSuperTreeButton();
1923 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
1926 _main_panel.getControlPanel().showWhole();
1930 final void superTree() {
1931 setNodeInPreorderToNull();
1932 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
1933 for( final PhylogenyNode n : temp_root.getDescendants() ) {
1934 n.setParent( temp_root );
1936 _sub_phylogenies[ _subtree_index ] = null;
1937 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
1938 _phylogeny = _sub_phylogenies[ --_subtree_index ];
1939 updateSubSuperTreeButton();
1942 final void swap( final PhylogenyNode node ) {
1943 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
1946 if ( node.getNumberOfDescendants() > 2 ) {
1947 JOptionPane.showMessageDialog( this,
1948 "Cannot swap descendants of nodes with more than 2 descendants",
1949 "Cannot swap descendants",
1950 JOptionPane.ERROR_MESSAGE );
1953 if ( !node.isExternal() ) {
1954 node.swapChildren();
1955 setNodeInPreorderToNull();
1956 _phylogeny.externalNodesHaveChanged();
1957 _phylogeny.clearHashIdToNodeMap();
1958 _phylogeny.recalculateNumberOfExternalDescendants( true );
1959 resetNodeIdToDistToLeafMap();
1965 final void taxColor() {
1966 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1970 AptxUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
1971 _control_panel.setColorBranches( true );
1972 if ( _control_panel.getColorBranchesCb() != null ) {
1973 _control_panel.getColorBranchesCb().setSelected( true );
1979 final void updateOvSettings() {
1980 switch ( getOptions().getOvPlacement() ) {
1982 setOvXPosition( OV_BORDER );
1983 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
1984 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
1987 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
1988 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
1989 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
1992 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
1993 setOvYPosition( OV_BORDER );
1994 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
1997 setOvXPosition( OV_BORDER );
1998 setOvYPosition( OV_BORDER );
1999 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2004 final void updateOvSizes() {
2005 if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) ) || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) {
2007 float l = getLongestExtNodeInfo();
2008 final float w_ratio = getOvMaxWidth() / getWidth();
2010 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
2011 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
2013 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
2014 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
2017 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
2019 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
2020 if ( ov_xdist < 0.0 ) {
2023 if ( ydist < 0.0 ) {
2026 setOvXDistance( ov_xdist );
2027 final double height = _phylogeny.getHeight();
2029 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
2030 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
2033 setOvXcorrectionFactor( 0 );
2041 void updateSetOfCollapsedExternalNodes() {
2042 final Phylogeny phy = getPhylogeny();
2043 _collapsed_external_nodeid_set.clear();
2044 if ( phy != null ) {
2045 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2046 final PhylogenyNode ext_node = it.next();
2047 PhylogenyNode n = ext_node;
2048 while ( !n.isRoot() ) {
2049 if ( n.isCollapse() ) {
2050 _collapsed_external_nodeid_set.add( ext_node.getId() );
2051 ext_node.setCollapse( true );
2060 final void updateSubSuperTreeButton() {
2061 if ( _subtree_index < 1 ) {
2062 getControlPanel().deactivateButtonToReturnToSuperTree();
2065 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
2069 final void zoomInDomainStructure() {
2070 if ( _domain_structure_width < 2000 ) {
2071 _domain_structure_width *= 1.2;
2075 final void zoomOutDomainStructure() {
2076 if ( _domain_structure_width > 20 ) {
2077 _domain_structure_width *= 0.8;
2081 private void abbreviateScientificName( final String sn ) {
2082 final String[] a = sn.split( "\\s+" );
2083 _sb.append( a[ 0 ].substring( 0, 1 ) );
2084 _sb.append( a[ 1 ].substring( 0, 2 ) );
2085 if ( a.length > 2 ) {
2086 for( int i = 2; i < a.length; i++ ) {
2088 _sb.append( a[ i ] );
2093 final private void addEmptyNode( final PhylogenyNode node ) {
2094 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2095 errorMessageNoCutCopyPasteInUnrootedDisplay();
2098 final String label = createASimpleTextRepresentationOfANode( node );
2100 if ( ForesterUtil.isEmpty( label ) ) {
2101 msg = "How to add the new, empty node?";
2104 msg = "How to add the new, empty node to node" + label + "?";
2106 final Object[] options = { "As sibling", "As descendant", "Cancel" };
2107 final int r = JOptionPane.showOptionDialog( this,
2109 "Addition of Empty New Node",
2110 JOptionPane.CLOSED_OPTION,
2111 JOptionPane.QUESTION_MESSAGE,
2115 boolean add_as_sibling = true;
2117 add_as_sibling = false;
2119 else if ( r != 0 ) {
2122 final Phylogeny phy = new Phylogeny();
2123 phy.setRoot( new PhylogenyNode() );
2124 phy.setRooted( true );
2125 if ( add_as_sibling ) {
2126 if ( node.isRoot() ) {
2127 JOptionPane.showMessageDialog( this,
2128 "Cannot add sibling to root",
2129 "Attempt to add sibling to root",
2130 JOptionPane.ERROR_MESSAGE );
2133 phy.addAsSibling( node );
2136 phy.addAsChild( node );
2138 setNodeInPreorderToNull();
2139 _phylogeny.externalNodesHaveChanged();
2140 _phylogeny.clearHashIdToNodeMap();
2141 _phylogeny.recalculateNumberOfExternalDescendants( true );
2142 resetNodeIdToDistToLeafMap();
2147 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
2148 final boolean is_vertical,
2150 final boolean to_pdf,
2151 final boolean to_graphics_file ) {
2152 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
2153 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2154 g.setColor( Color.BLACK );
2156 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
2157 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
2158 && ( getCutOrCopiedTree() != null )
2159 && ( getCopiedAndPastedNodes() != null )
2161 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
2162 g.setColor( getTreeColorSet().getFoundColor() );
2164 else if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2165 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2167 else if ( to_pdf ) {
2168 g.setColor( getTreeColorSet().getBranchColorForPdf() );
2171 g.setColor( getTreeColorSet().getBranchColor() );
2175 final private void blast( final PhylogenyNode node ) {
2176 if ( !isCanBlast( node ) ) {
2177 JOptionPane.showMessageDialog( this,
2178 "Insufficient information present",
2180 JOptionPane.INFORMATION_MESSAGE );
2184 final String query = Blast.obtainQueryForBlast( node );
2185 System.out.println( "query for BLAST is: " + query );
2187 if ( !ForesterUtil.isEmpty( query ) ) {
2188 if ( node.getNodeData().isHasSequence() ) {
2189 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
2190 if ( node.getNodeData().getSequence().getType().toLowerCase()
2191 .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
2198 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2199 if ( ForesterUtil.seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2207 if ( type == '?' ) {
2208 if ( SequenceIdParser.isProtein( query ) ) {
2215 JApplet applet = null;
2217 applet = obtainApplet();
2220 Blast.openNcbiBlastWeb( query, type == 'n', applet, this );
2222 catch ( final Exception e ) {
2223 e.printStackTrace();
2225 if ( Constants.ALLOW_DDBJ_BLAST ) {
2227 System.out.println( "trying: " + query );
2228 final Blast s = new Blast();
2229 s.ddbjBlast( query );
2231 catch ( final Exception e ) {
2232 e.printStackTrace();
2240 * Calculate the length of the distance between the given node and its
2246 * @return the distance value
2248 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
2249 if ( getControlPanel().isDrawPhylogram() ) {
2250 if ( node.getDistanceToParent() < 0.0 ) {
2253 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
2256 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2257 return getXdistance();
2259 return getXdistance() * factor;
2263 final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
2264 Color c = getTreeColorSet().getAnnotationColor();
2265 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
2266 final StringBuilder sb = new StringBuilder();
2267 for( final Annotation a : ann ) {
2268 sb.append( !ForesterUtil.isEmpty( a.getRef() ) ? a.getRef() : a.getDesc() );
2270 final String ann_str = sb.toString();
2271 if ( !ForesterUtil.isEmpty( ann_str ) ) {
2272 c = getControlPanel().getAnnotationColors().get( ann_str );
2274 c = AptxUtil.calculateColorFromString( ann_str );
2275 getControlPanel().getAnnotationColors().put( ann_str, c );
2278 c = getTreeColorSet().getAnnotationColor();
2285 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
2286 if ( getControlPanel().isDrawPhylogram() ) {
2287 if ( node.getDistanceToParent() < 0.0 ) {
2290 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
2293 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2294 return getOvXDistance();
2296 return getOvXDistance() * factor;
2300 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
2301 JOptionPane.showMessageDialog( this,
2302 "Cannot launch web browser for " + type_type + " data of this node",
2303 "Cannot launch web browser",
2304 JOptionPane.WARNING_MESSAGE );
2307 final private void colorizeSubtree( final Color c, final PhylogenyNode node ) {
2308 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2309 JOptionPane.showMessageDialog( this,
2310 "Cannot colorize subtree in unrooted display type",
2311 "Attempt to colorize subtree in unrooted display",
2312 JOptionPane.WARNING_MESSAGE );
2315 _control_panel.setColorBranches( true );
2316 if ( _control_panel.getColorBranchesCb() != null ) {
2317 _control_panel.getColorBranchesCb().setSelected( true );
2319 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
2320 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
2325 final private void colorSubtree( final PhylogenyNode node ) {
2326 Color intitial_color = null;
2327 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null )
2328 && ( ( ( !node.isRoot() && ( node.getParent().getNumberOfDescendants() < 3 ) ) ) || ( node.isRoot() ) ) ) {
2329 intitial_color = PhylogenyMethods.getBranchColorValue( node );
2332 intitial_color = getTreeColorSet().getBranchColor();
2334 _color_chooser.setColor( intitial_color );
2335 _color_chooser.setPreviewPanel( new JPanel() );
2336 final JDialog dialog = JColorChooser
2337 .createDialog( this,
2338 "Subtree colorization",
2341 new SubtreeColorizationActionListener( _color_chooser, node ),
2343 dialog.setVisible( true );
2346 final private void copySubtree( final PhylogenyNode node ) {
2347 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2348 errorMessageNoCutCopyPasteInUnrootedDisplay();
2351 setNodeInPreorderToNull();
2352 setCutOrCopiedTree( _phylogeny.copy( node ) );
2353 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
2354 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
2355 for( final PhylogenyNode n : nodes ) {
2356 node_ids.add( n.getId() );
2358 node_ids.add( node.getId() );
2359 setCopiedAndPastedNodes( node_ids );
2363 private String createAnnotationString( final SortedSet<Annotation> ann ) {
2364 final StringBuilder sb = new StringBuilder();
2365 boolean first = true;
2366 for( final Annotation a : ann ) {
2373 sb.append( a.asSimpleText() );
2375 final String ann_str = sb.toString();
2379 final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
2380 final String tax = PhylogenyMethods.getSpecies( node );
2381 String label = node.getName();
2382 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
2383 label = label + " " + tax;
2385 else if ( !ForesterUtil.isEmpty( tax ) ) {
2391 if ( !ForesterUtil.isEmpty( label ) ) {
2392 label = " [" + label + "]";
2397 final private void cutSubtree( final PhylogenyNode node ) {
2398 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2399 errorMessageNoCutCopyPasteInUnrootedDisplay();
2402 if ( node.isRoot() ) {
2403 JOptionPane.showMessageDialog( this,
2404 "Cannot cut entire tree as subtree",
2405 "Attempt to cut entire tree",
2406 JOptionPane.ERROR_MESSAGE );
2409 final String label = createASimpleTextRepresentationOfANode( node );
2410 final int r = JOptionPane.showConfirmDialog( null,
2411 "Cut subtree" + label + "?",
2412 "Confirm Cutting of Subtree",
2413 JOptionPane.YES_NO_OPTION );
2414 if ( r != JOptionPane.OK_OPTION ) {
2417 setNodeInPreorderToNull();
2418 setCopiedAndPastedNodes( null );
2419 setCutOrCopiedTree( _phylogeny.copy( node ) );
2420 _phylogeny.deleteSubtree( node, true );
2421 _phylogeny.clearHashIdToNodeMap();
2422 _phylogeny.recalculateNumberOfExternalDescendants( true );
2423 resetNodeIdToDistToLeafMap();
2428 final private void cycleColors() {
2429 getMainPanel().getTreeColorSet().cycleColorScheme();
2430 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
2431 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
2435 final private void decreaseOvSize() {
2436 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
2437 setOvMaxWidth( getOvMaxWidth() - 5 );
2438 setOvMaxHeight( getOvMaxHeight() - 5 );
2440 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2444 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
2445 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2446 errorMessageNoCutCopyPasteInUnrootedDisplay();
2449 if ( node.isRoot() ) {
2450 JOptionPane.showMessageDialog( this,
2451 "Cannot delete entire tree",
2452 "Attempt to delete entire tree",
2453 JOptionPane.ERROR_MESSAGE );
2456 final String label = createASimpleTextRepresentationOfANode( node );
2457 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
2458 final int r = JOptionPane.showOptionDialog( this,
2459 "Delete" + label + "?",
2460 "Delete Node/Subtree",
2461 JOptionPane.CLOSED_OPTION,
2462 JOptionPane.QUESTION_MESSAGE,
2466 setNodeInPreorderToNull();
2467 boolean node_only = true;
2471 else if ( r != 0 ) {
2475 PhylogenyMethods.removeNode( node, _phylogeny );
2478 _phylogeny.deleteSubtree( node, true );
2480 _phylogeny.externalNodesHaveChanged();
2481 _phylogeny.clearHashIdToNodeMap();
2482 _phylogeny.recalculateNumberOfExternalDescendants( true );
2483 resetNodeIdToDistToLeafMap();
2488 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
2489 makePopupMenus( node );
2490 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
2491 _node_popup_menu.show( this, x, y );
2494 final private void drawArc( final double x,
2497 final double heigth,
2498 final double start_angle,
2499 final double arc_angle,
2500 final Graphics2D g ) {
2501 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
2505 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
2506 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
2509 _line.setLine( x1, y1, x2, y2 );
2513 final private void drawOval( final double x,
2516 final double heigth,
2517 final Graphics2D g ) {
2518 _ellipse.setFrame( x, y, width, heigth );
2522 final private void drawOvalFilled( final double x,
2525 final double heigth,
2526 final Graphics2D g ) {
2527 _ellipse.setFrame( x, y, width, heigth );
2531 final private void drawOvalGradient( final double x,
2534 final double heigth,
2536 final Color color_1,
2537 final Color color_2,
2538 final Color color_border ) {
2539 _ellipse.setFrame( x, y, width, heigth );
2540 g.setPaint( new GradientPaint( ( float ) x,
2543 ( float ) ( x + width ),
2544 ( float ) ( y + heigth ),
2548 if ( color_border != null ) {
2549 g.setPaint( color_border );
2554 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
2555 _rectangle.setFrame( x, y, width, heigth );
2556 g.draw( _rectangle );
2559 final private void drawRectFilled( final double x,
2562 final double heigth,
2563 final Graphics2D g ) {
2564 _rectangle.setFrame( x, y, width, heigth );
2565 g.fill( _rectangle );
2568 final private void drawRectGradient( final double x,
2571 final double heigth,
2573 final Color color_1,
2574 final Color color_2,
2575 final Color color_border ) {
2576 _rectangle.setFrame( x, y, width, heigth );
2577 g.setPaint( new GradientPaint( ( float ) x,
2580 ( float ) ( x + width ),
2581 ( float ) ( y + heigth ),
2584 g.fill( _rectangle );
2585 if ( color_border != null ) {
2586 g.setPaint( color_border );
2587 g.draw( _rectangle );
2591 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
2592 final List<Uri> us = new ArrayList<Uri>();
2593 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
2594 for( final Uri uri : t.getUris() ) {
2599 for( final Uri uri : us ) {
2600 if ( uri != null ) {
2601 final String uri_str = uri.getValue().toString().toLowerCase();
2602 if ( getImageMap().containsKey( uri_str ) ) {
2603 final BufferedImage bi = getImageMap().get( uri_str );
2604 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
2605 double scaling_factor = 1;
2606 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
2607 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
2608 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
2610 // y = y - ( 0.9 * getYdistance() );
2611 final double hs = bi.getHeight() * scaling_factor;
2612 double ws = ( bi.getWidth() * scaling_factor ) + offset;
2613 final double my_y = y - ( 0.5 * hs );
2614 final int x_w = ( int ) ( x + ws + 0.5 );
2615 final int y_h = ( int ) ( my_y + hs + 0.5 );
2616 if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) {
2618 ( int ) ( x + 0.5 + offset ),
2619 ( int ) ( my_y + 0.5 ),
2640 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
2641 JOptionPane.showMessageDialog( this,
2642 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
2643 "Attempt to cut/copy/paste/add/delete in unrooted display",
2644 JOptionPane.ERROR_MESSAGE );
2647 final private Set<Integer> getCopiedAndPastedNodes() {
2648 return getMainPanel().getCopiedAndPastedNodes();
2651 final private Phylogeny getCutOrCopiedTree() {
2652 return getMainPanel().getCutOrCopiedTree();
2655 final private float getLastDragPointX() {
2656 return _last_drag_point_x;
2659 final private float getLastDragPointY() {
2660 return _last_drag_point_y;
2663 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
2664 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
2665 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
2666 _nodeid_dist_to_leaf.put( node.getId(), m );
2670 return _nodeid_dist_to_leaf.get( node.getId() );
2674 final private double getMaxDistanceToRoot() {
2675 if ( _max_distance_to_root < 0 ) {
2676 recalculateMaxDistanceToRoot();
2678 return _max_distance_to_root;
2681 final private float getOvMaxHeight() {
2682 return _ov_max_height;
2685 final private float getOvMaxWidth() {
2686 return _ov_max_width;
2689 final private float getOvXcorrectionFactor() {
2690 return _ov_x_correction_factor;
2693 final private float getOvXDistance() {
2694 return _ov_x_distance;
2697 final private int getOvXPosition() {
2698 return _ov_x_position;
2701 final private float getOvYDistance() {
2702 return _ov_y_distance;
2705 final private int getOvYPosition() {
2706 return _ov_y_position;
2709 final private int getOvYStart() {
2713 final private double getScaleDistance() {
2714 return _scale_distance;
2717 final private String getScaleLabel() {
2718 return _scale_label;
2721 final private TreeFontSet getTreeFontSet() {
2722 return getMainPanel().getTreeFontSet();
2725 final private float getUrtFactor() {
2729 final private float getUrtFactorOv() {
2730 return _urt_factor_ov;
2733 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
2736 showNodeFrame( node );
2751 colorSubtree( node );
2766 copySubtree( node );
2769 pasteSubtree( node );
2771 case DELETE_NODE_OR_SUBTREE:
2772 deleteNodeOrSubtree( node );
2775 addEmptyNode( node );
2777 case EDIT_NODE_DATA:
2778 showNodeEditFrame( node );
2783 case SORT_DESCENDENTS:
2784 sortDescendants( node );
2786 case GET_EXT_DESC_DATA:
2787 showExtDescNodeData( node );
2790 throw new IllegalArgumentException( "unknown action: " + action );
2794 private void increaseCurrentExternalNodesDataBufferChangeCounter() {
2795 _current_external_nodes_data_buffer_change_counter++;
2796 System.out.println( _current_external_nodes_data_buffer_change_counter ); //TODO ~~~~~~~~~~~~~~ REMOVEME
2799 final private void increaseOvSize() {
2800 if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) )
2801 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
2802 .getHeight() / 2 ) ) ) {
2803 setOvMaxWidth( getOvMaxWidth() + 5 );
2804 setOvMaxHeight( getOvMaxHeight() + 5 );
2806 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2810 final private void init() {
2811 _color_chooser = new JColorChooser();
2812 _rollover_popup = new JTextArea();
2813 _rollover_popup.setFont( POPUP_FONT );
2814 resetNodeIdToDistToLeafMap();
2816 setTreeFile( null );
2818 initializeOvSettings();
2819 setStartingAngle( ( TWO_PI * 3 ) / 4 );
2820 final ImageLoader il = new ImageLoader( this );
2821 new Thread( il ).start();
2824 final private void initializeOvSettings() {
2825 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
2826 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
2829 final private boolean inOvVirtualRectangle( final int x, final int y ) {
2830 return ( ( x >= ( getOvVirtualRectangle().x - 1 ) )
2831 && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) )
2832 && ( y >= ( getOvVirtualRectangle().y - 1 ) ) && ( y <= ( getOvVirtualRectangle().y
2833 + getOvVirtualRectangle().height + 1 ) ) );
2836 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
2837 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
2840 final private boolean isCanBlast( final PhylogenyNode node ) {
2841 if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) {
2844 return Blast.isContainsQueryForBlast( node );
2847 final private boolean isCanOpenSeqWeb( final PhylogenyNode node ) {
2848 if ( node.getNodeData().isHasSequence()
2849 && ( node.getNodeData().getSequence().getAccession() != null )
2850 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
2851 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
2852 && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource()
2853 .toLowerCase() ) ) {
2859 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
2860 if ( node.getNodeData().isHasTaxonomy()
2861 && ( ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
2862 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getProvider() )
2863 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && getConfiguration()
2864 .isHasWebLink( node.getNodeData().getTaxonomy().getIdentifier().getProvider().toLowerCase() ) )
2865 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
2866 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
2867 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
2868 .getNodeData().getTaxonomy().getIdentifier() != null )
2869 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && node
2870 .getNodeData().getTaxonomy().getIdentifier().getValue().startsWith( "http://" ) ) ) ) {
2878 final private boolean isInFoundNodes( final PhylogenyNode node ) {
2879 return ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) );
2882 final private boolean isInOv() {
2886 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
2888 if ( getControlPanel().isShowTaxonomyImages() ) {
2889 y_dist = 40 + ( int ) getYdistance();
2891 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) )
2892 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) ) || ( ( node.getParent() != null ) && ( node
2893 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
2896 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
2897 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) )
2898 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) )
2899 || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) ) || ( node.getXcoord() > ( getVisibleRect()
2900 .getMaxX() + 20 ) ) );
2903 final private boolean isNonLinedUpCladogram() {
2904 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
2907 final private boolean isUniformBranchLengthsForCladogram() {
2908 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
2911 final private void keyPressedCalls( final KeyEvent e ) {
2912 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
2913 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
2914 if ( !isInOvRect() ) {
2915 setInOvRect( true );
2918 else if ( isInOvRect() ) {
2919 setInOvRect( false );
2922 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
2923 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
2924 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
2925 getMainPanel().getTreeFontSet().mediumFonts();
2926 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
2928 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
2929 getMainPanel().getTreeFontSet().decreaseFontSize();
2930 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
2932 else if ( plusPressed( e.getKeyCode() ) ) {
2933 getMainPanel().getTreeFontSet().increaseFontSize();
2934 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
2938 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
2939 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
2940 getControlPanel().showWhole();
2942 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
2943 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
2944 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
2945 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
2946 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
2947 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
2949 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
2950 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
2951 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
2953 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
2954 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
2955 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
2956 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
2958 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
2959 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
2960 Constants.WHEEL_ZOOM_IN_FACTOR );
2961 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
2968 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
2971 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
2975 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
2979 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
2980 scroll_position.x = scroll_position.x + dx;
2981 scroll_position.y = scroll_position.y + dy;
2982 if ( scroll_position.x <= 0 ) {
2983 scroll_position.x = 0;
2986 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
2987 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
2988 if ( scroll_position.x >= max_x ) {
2989 scroll_position.x = max_x;
2992 if ( scroll_position.y <= 0 ) {
2993 scroll_position.y = 0;
2996 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
2997 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
2998 if ( scroll_position.y >= max_y ) {
2999 scroll_position.y = max_y;
3003 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
3006 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
3007 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3008 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3009 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3010 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3012 else if ( plusPressed( e.getKeyCode() ) ) {
3013 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3014 Constants.WHEEL_ZOOM_IN_FACTOR );
3015 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3016 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3018 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
3019 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3020 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3021 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
3022 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3025 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
3026 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3027 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3028 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
3029 if ( getStartingAngle() < 0 ) {
3030 setStartingAngle( TWO_PI + getStartingAngle() );
3032 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3035 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
3036 boolean selected = false;
3037 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
3038 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
3042 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
3044 if ( getMainPanel().getMainFrame() == null ) {
3045 // Must be "E" applet version.
3046 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
3047 if ( ae.getlabelDirectionCbmi() != null ) {
3048 ae.getlabelDirectionCbmi().setSelected( selected );
3052 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
3056 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
3057 switchDisplaygetPhylogenyGraphicsType();
3060 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
3064 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
3065 MainFrame.cycleOverview( getOptions(), this );
3068 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
3071 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
3078 final private void makePopupMenus( final PhylogenyNode node ) {
3079 _node_popup_menu = new JPopupMenu();
3080 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
3081 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
3082 for( int i = 0; i < clickto_names.size(); i++ ) {
3083 final String title = clickto_names.get( i );
3084 _node_popup_menu_items[ i ] = new JMenuItem( title );
3085 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
3086 _node_popup_menu_items[ i ].setEnabled( isCanOpenSeqWeb( node ) );
3088 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
3089 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
3091 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
3092 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
3094 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
3095 if ( !getOptions().isEditable() ) {
3098 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
3100 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
3101 if ( !getOptions().isEditable() ) {
3104 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
3106 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
3107 if ( !getOptions().isEditable() ) {
3110 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
3112 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
3113 if ( !getOptions().isEditable() ) {
3116 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
3118 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
3119 if ( !getOptions().isEditable() ) {
3123 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
3124 if ( !getOptions().isEditable() ) {
3128 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
3129 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
3131 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
3132 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
3134 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
3135 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
3137 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
3138 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
3140 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
3141 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
3143 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
3144 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
3146 _node_popup_menu_items[ i ].addActionListener( this );
3147 _node_popup_menu.add( _node_popup_menu_items[ i ] );
3151 private final String obtainTitleForExtDescNodeData() {
3152 switch ( getOptions().getExtDescNodeDataToReturn() ) {
3154 return "Node Names";
3156 return "Sequence Names";
3157 case SEQUENCE_SYMBOL:
3158 return "Sequence Symbols";
3159 case SEQUENCE_MOL_SEQ:
3160 return "Molecular Sequences";
3162 return "Sequence Accessors";
3163 case TAXONOMY_SCIENTIFIC_NAME:
3164 return "Scientific Names";
3166 return "Taxonomy Codes";
3168 return "User Selected Data";
3170 throw new IllegalArgumentException( "unknown data element: "
3171 + getOptions().getExtDescNodeDataToReturn() );
3175 final private void openSeqWeb( final PhylogenyNode node ) {
3176 if ( !isCanOpenSeqWeb( node ) ) {
3177 cannotOpenBrowserWarningMessage( "sequence" );
3180 String uri_str = null;
3181 final Sequence seq = node.getNodeData().getSequence();
3182 final String source = seq.getAccession().getSource().toLowerCase();
3184 if ( source.toLowerCase().equals( "ncbi" ) ) {
3185 url = Constants.NCBI_ALL_DATABASE_SEARCH;
3188 final WebLink weblink = getConfiguration().getWebLink( source );
3189 url = weblink.getUrl().toString();
3192 uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 );
3194 catch ( final UnsupportedEncodingException e ) {
3195 AptxUtil.showErrorMessage( this, e.toString() );
3196 e.printStackTrace();
3198 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3200 JApplet applet = null;
3202 applet = obtainApplet();
3204 AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_seq" );
3206 catch ( final IOException e ) {
3207 AptxUtil.showErrorMessage( this, e.toString() );
3208 e.printStackTrace();
3210 catch ( final URISyntaxException e ) {
3211 AptxUtil.showErrorMessage( this, e.toString() );
3212 e.printStackTrace();
3216 cannotOpenBrowserWarningMessage( "sequence" );
3220 final private void openTaxWeb( final PhylogenyNode node ) {
3221 if ( !isCanOpenTaxWeb( node ) ) {
3222 cannotOpenBrowserWarningMessage( "taxonomic" );
3225 String uri_str = null;
3226 final Taxonomy tax = node.getNodeData().getTaxonomy();
3227 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
3228 && getConfiguration().isHasWebLink( tax.getIdentifier().getProvider().toLowerCase() ) ) {
3229 final String type = tax.getIdentifier().getProvider().toLowerCase();
3230 final WebLink weblink = getConfiguration().getWebLink( type );
3232 uri_str = weblink.getUrl() + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
3234 catch ( final UnsupportedEncodingException e ) {
3235 AptxUtil.showErrorMessage( this, e.toString() );
3236 e.printStackTrace();
3239 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
3240 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
3242 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
3244 catch ( final URISyntaxException e ) {
3245 AptxUtil.showErrorMessage( this, e.toString() );
3247 e.printStackTrace();
3250 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
3252 uri_str = "http://www.eol.org/search?q="
3253 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
3255 catch ( final UnsupportedEncodingException e ) {
3256 AptxUtil.showErrorMessage( this, e.toString() );
3257 e.printStackTrace();
3260 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
3262 uri_str = "http://www.uniprot.org/taxonomy/?query="
3263 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
3265 catch ( final UnsupportedEncodingException e ) {
3266 AptxUtil.showErrorMessage( this, e.toString() );
3267 e.printStackTrace();
3270 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
3272 uri_str = "http://www.eol.org/search?q="
3273 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
3275 catch ( final UnsupportedEncodingException e ) {
3276 AptxUtil.showErrorMessage( this, e.toString() );
3277 e.printStackTrace();
3280 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3282 JApplet applet = null;
3284 applet = obtainApplet();
3286 AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_tax" );
3288 catch ( final IOException e ) {
3289 AptxUtil.showErrorMessage( this, e.toString() );
3290 e.printStackTrace();
3292 catch ( final URISyntaxException e ) {
3293 AptxUtil.showErrorMessage( this, e.toString() );
3294 e.printStackTrace();
3298 cannotOpenBrowserWarningMessage( "taxonomic" );
3302 final private void paintBranchLength( final Graphics2D g,
3303 final PhylogenyNode node,
3304 final boolean to_pdf,
3305 final boolean to_graphics_file ) {
3306 g.setFont( getTreeFontSet().getSmallFont() );
3307 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3308 g.setColor( Color.BLACK );
3311 g.setColor( getTreeColorSet().getBranchLengthColor() );
3313 if ( !node.isRoot() ) {
3314 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3315 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3316 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3318 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3319 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3320 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3323 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3324 .getXcoord() + 3, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3328 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
3329 - getTreeFontSet()._small_max_descent, g );
3333 final private void paintBranchLite( final Graphics2D g,
3338 final PhylogenyNode node ) {
3339 g.setColor( getTreeColorSet().getOvColor() );
3340 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3341 drawLine( x1, y1, x2, y2, g );
3343 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3344 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3345 ( g ).draw( _quad_curve );
3347 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3348 final float dx = x2 - x1;
3349 final float dy = y2 - y1;
3350 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3351 + ( dy * 0.8f ), x2, y2 );
3352 ( g ).draw( _cubic_curve );
3355 final float x2a = x2;
3356 final float x1a = x1;
3357 // draw the vertical line
3358 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
3359 drawLine( x1, y1, x1, y2, g );
3361 // draw the horizontal line
3362 drawLine( x1a, y2, x2a, y2, g );
3367 * Paint a branch which consists of a vertical and a horizontal bar
3368 * @param is_ind_found_nodes
3370 final private void paintBranchRectangular( final Graphics2D g,
3375 final PhylogenyNode node,
3376 final boolean to_pdf,
3377 final boolean to_graphics_file ) {
3378 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
3379 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3380 drawLine( x1, y1, x2, y2, g );
3382 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3383 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3384 g.draw( _quad_curve );
3386 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3387 final float dx = x2 - x1;
3388 final float dy = y2 - y1;
3389 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3390 + ( dy * 0.8f ), x2, y2 );
3391 g.draw( _cubic_curve );
3394 final float x2a = x2;
3395 final float x1a = x1;
3397 if ( node.isFirstChildNode() || node.isLastChildNode()
3398 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
3399 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3400 if ( !to_graphics_file
3402 && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) ) || ( ( y2 > ( getVisibleRect()
3403 .getMaxY() + 20 ) ) && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) {
3407 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3408 float x2c = x1 + EURO_D;
3412 drawLine( x1, y1, x2c, y2, g );
3414 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3416 y2_r = y2 - ROUNDED_D;
3420 drawLine( x1, y1, x1, y2_r, g );
3423 y2_r = y2 + ROUNDED_D;
3427 drawLine( x1, y1, x1, y2_r, g );
3431 drawLine( x1, y1, x1, y2, g );
3435 // draw the horizontal line
3436 if ( !to_graphics_file && !to_pdf
3437 && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) {
3441 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
3442 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3443 x1_r = x1a + ROUNDED_D;
3445 drawLine( x1_r, y2, x2a, y2, g );
3448 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3449 final float x1c = x1a + EURO_D;
3451 drawLine( x1c, y2, x2a, y2, g );
3455 drawLine( x1a, y2, x2a, y2, g );
3459 final double w = PhylogenyMethods.getBranchWidthValue( node );
3460 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3461 x1_r = x1a + ROUNDED_D;
3463 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
3466 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3467 final float x1c = x1a + EURO_D;
3469 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
3473 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
3476 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3481 final double diff = y2 - y2_r;
3482 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
3485 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
3490 if ( node.isExternal() ) {
3491 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
3495 final private double paintCirculars( final PhylogenyNode n,
3496 final Phylogeny phy,
3497 final float center_x,
3498 final float center_y,
3499 final double radius,
3500 final boolean radial_labels,
3502 final boolean to_pdf,
3503 final boolean to_graphics_file ) {
3504 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
3505 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
3506 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
3508 return _urt_nodeid_angle_map.get( n.getId() );
3511 final List<PhylogenyNode> descs = n.getDescendants();
3513 for( final PhylogenyNode desc : descs ) {
3514 sum += paintCirculars( desc,
3525 if ( !n.isRoot() ) {
3526 r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3528 final double theta = sum / descs.size();
3529 n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) );
3530 n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) );
3531 _urt_nodeid_angle_map.put( n.getId(), theta );
3532 for( final PhylogenyNode desc : descs ) {
3533 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
3539 final private void paintCircularsLite( final PhylogenyNode n,
3540 final Phylogeny phy,
3544 final Graphics2D g ) {
3545 if ( n.isExternal() ) {
3549 final List<PhylogenyNode> descs = n.getDescendants();
3550 for( final PhylogenyNode desc : descs ) {
3551 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
3554 if ( !n.isRoot() ) {
3555 r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3557 final double theta = _urt_nodeid_angle_map.get( n.getId() );
3558 n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) );
3559 n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) );
3560 for( final PhylogenyNode desc : descs ) {
3561 paintBranchCircularLite( n, desc, g );
3566 final private void paintCollapsedNode( final Graphics2D g,
3567 final PhylogenyNode node,
3568 final boolean to_graphics_file,
3569 final boolean to_pdf,
3570 final boolean is_in_found_nodes ) {
3572 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3575 else if ( is_in_found_nodes ) {
3576 c = getTreeColorSet().getFoundColor();
3578 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3579 c = getTaxonomyBasedColor( node );
3581 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3582 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3583 c = PhylogenyMethods.getBranchColorValue( node );
3586 c = getTreeColorSet().getCollapseFillColor();
3588 double d = node.getAllExternalDescendants().size();
3590 d = ( 3 * _y_distance ) / 3;
3593 d = ( Math.log10( d ) * _y_distance ) / 2.5;
3595 final int box_size = getOptions().getDefaultNodeShapeSize();
3596 if ( d < box_size ) {
3600 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() - box_size ),
3601 ForesterUtil.roundToInt( node.getYcoord() ) );
3602 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ),
3603 ForesterUtil.roundToInt( node.getYcoord() - d ) );
3604 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ),
3605 ForesterUtil.roundToInt( node.getYcoord() + d ) );
3606 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3608 g.fillPolygon( _polygon );
3610 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
3611 g.setColor( getBackground() );
3612 g.fillPolygon( _polygon );
3614 g.drawPolygon( _polygon );
3616 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
3617 g.setPaint( new GradientPaint( node.getXcoord() - box_size, node.getYcoord(), getBackground(), ( node
3618 .getXcoord() + box_size ), ( float ) ( node.getYcoord() - d ), c, false ) );
3623 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3626 final private void paintConfidenceValues( final Graphics2D g,
3627 final PhylogenyNode node,
3628 final boolean to_pdf,
3629 final boolean to_graphics_file ) {
3630 final List<Confidence> confidences = node.getBranchData().getConfidences();
3631 // if ( confidences.size() == 1 ) {
3632 // final double value = node.getBranchData().getConfidence( 0 ).getValue();
3633 // if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
3636 // conf_str = FORMATTER_CONFIDENCE.format( value );
3638 // else if ( confidences.size() > 1 ) {
3639 boolean one_ok = false;
3640 boolean not_first = false;
3641 Collections.sort( confidences );
3642 final StringBuilder sb = new StringBuilder();
3643 String conf_str = "";
3644 for( final Confidence confidence : confidences ) {
3645 final double value = confidence.getValue();
3646 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
3647 if ( value >= getOptions().getMinConfidenceValue() ) {
3656 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
3657 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
3658 if ( getOptions().isShowConfidenceStddev() ) {
3659 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
3661 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getStandardDeviation(),
3663 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
3670 conf_str = sb.toString();
3673 if ( conf_str.length() > 0 ) {
3674 final double parent_x = node.getParent().getXcoord();
3675 double x = node.getXcoord();
3676 g.setFont( getTreeFontSet().getSmallFont() );
3677 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3680 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3683 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3684 g.setColor( Color.BLACK );
3687 g.setColor( getTreeColorSet().getConfidenceColor() );
3690 .drawString( conf_str,
3692 + ( ( x - parent_x - getTreeFontSet()._fm_small.stringWidth( conf_str ) ) / 2 ),
3693 ( node.getYcoord() + getTreeFontSet()._small_max_ascent ) - 1,
3698 final private void paintFoundNode( final int x, final int y, final Graphics2D g ) {
3699 final int box_size = getOptions().getDefaultNodeShapeSize();
3700 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
3701 g.setColor( getTreeColorSet().getFoundColor() );
3702 g.fillRect( x - half_box_size, y - half_box_size, box_size, box_size );
3705 final private void paintGainedAndLostCharacters( final Graphics2D g,
3706 final PhylogenyNode node,
3707 final String gained,
3708 final String lost ) {
3709 if ( node.getParent() != null ) {
3710 final double parent_x = node.getParent().getXcoord();
3711 final double x = node.getXcoord();
3712 g.setFont( getTreeFontSet().getLargeFont() );
3713 g.setColor( getTreeColorSet().getGainedCharactersColor() );
3714 if ( Constants.SPECIAL_CUSTOM ) {
3715 g.setColor( Color.BLUE );
3718 .drawString( gained,
3719 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( gained ) ) / 2 ),
3720 ( node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent() ),
3722 g.setColor( getTreeColorSet().getLostCharactersColor() );
3723 TreePanel.drawString( lost,
3724 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( lost ) ) / 2 ),
3725 ( node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent() ),
3731 * Draw a box at the indicated node.
3738 final private void paintNodeBox( final double x,
3740 final PhylogenyNode node,
3742 final boolean to_pdf,
3743 final boolean to_graphics_file,
3744 final boolean is_in_found_nodes ) {
3745 if ( node.isCollapse() ) {
3748 // if this node should be highlighted, do so
3749 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
3750 g.setColor( getTreeColorSet().getFoundColor() );
3751 drawOval( x - 8, y - 8, 16, 16, g );
3752 drawOval( x - 9, y - 8, 17, 17, g );
3753 drawOval( x - 9, y - 9, 18, 18, g );
3755 if ( is_in_found_nodes ) {
3756 paintFoundNode( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ), g );
3759 Color outline_color = null;
3760 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3761 outline_color = Color.BLACK;
3763 else if ( getControlPanel().isEvents() && AptxUtil.isHasAssignedEvent( node ) ) {
3764 final Event event = node.getNodeData().getEvent();
3765 if ( event.isDuplication() ) {
3766 outline_color = getTreeColorSet().getDuplicationBoxColor();
3768 else if ( event.isSpeciation() ) {
3769 outline_color = getTreeColorSet().getSpecBoxColor();
3771 else if ( event.isSpeciationOrDuplication() ) {
3772 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
3775 else if ( getOptions().isTaxonomyColorizeNodeShapes() ) {
3776 outline_color = getTaxonomyBasedColor( node );
3779 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
3780 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
3781 outline_color = getTreeColorSet().getBranchColorForPdf();
3784 final int box_size = getOptions().getDefaultNodeShapeSize();
3785 final int half_box_size = box_size / 2;
3786 if ( getOptions().isShowDefaultNodeShapes() || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) {
3787 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
3788 if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
3789 drawOvalGradient( x - half_box_size,
3794 to_pdf ? Color.WHITE : outline_color,
3795 to_pdf ? outline_color : getBackground(),
3798 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
3799 Color background = getBackground();
3801 background = Color.WHITE;
3803 drawOvalGradient( x - half_box_size,
3812 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3813 g.setColor( outline_color );
3814 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
3817 else if ( getOptions().getDefaultNodeShape() == NodeVisualization.NodeShape.RECTANGLE ) {
3818 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.GRADIENT ) {
3819 drawRectGradient( x - half_box_size,
3824 to_pdf ? Color.WHITE : outline_color,
3825 to_pdf ? outline_color : getBackground(),
3828 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
3829 Color background = getBackground();
3831 background = Color.WHITE;
3833 drawRectGradient( x - half_box_size,
3842 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3843 g.setColor( outline_color );
3844 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
3851 final private void paintNodeData( final Graphics2D g,
3852 final PhylogenyNode node,
3853 final boolean to_graphics_file,
3854 final boolean to_pdf,
3855 final boolean is_in_found_nodes ) {
3856 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
3859 if ( getOptions().isShowBranchLengthValues()
3860 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3861 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3862 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
3863 paintBranchLength( g, node, to_pdf, to_graphics_file );
3865 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
3869 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
3870 if ( getControlPanel().isShowTaxonomyImages()
3871 && ( getImageMap() != null )
3872 && !getImageMap().isEmpty()
3873 && node.getNodeData().isHasTaxonomy()
3874 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
3875 .getUris().isEmpty() ) ) {
3876 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
3878 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
3879 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
3880 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
3882 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3883 g.setColor( Color.BLACK );
3885 else if ( is_in_found_nodes ) {
3886 g.setColor( getTreeColorSet().getFoundColor() );
3888 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3889 g.setColor( getTaxonomyBasedColor( node ) );
3891 else if ( getControlPanel().isColorAccordingToAnnotation()
3892 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
3893 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
3894 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
3896 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3897 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3898 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3900 else if ( to_pdf ) {
3901 g.setColor( Color.BLACK );
3904 g.setColor( getTreeColorSet().getSequenceColor() );
3907 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3909 _sb.append( node.getAllExternalDescendants().size() );
3912 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3913 if ( _sb.length() > 0 ) {
3916 _sb.append( node.getName() );
3918 if ( node.getNodeData().isHasSequence() ) {
3919 if ( getControlPanel().isShowGeneSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
3920 if ( _sb.length() > 0 ) {
3923 _sb.append( node.getNodeData().getSequence().getSymbol() );
3925 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3926 if ( _sb.length() > 0 ) {
3929 _sb.append( node.getNodeData().getSequence().getName() );
3931 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3932 if ( _sb.length() > 0 ) {
3935 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3936 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3939 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3942 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
3943 if ( _sb.length() > 0 ) {
3946 _sb.append( propertiesToString( node ) );
3948 g.setFont( getTreeFontSet().getLargeFont() );
3949 if ( is_in_found_nodes ) {
3950 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3952 double down_shift_factor = 3.0;
3953 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
3954 down_shift_factor = 1;
3956 final double pos_x = node.getXcoord() + x + 2 + half_box_size;
3957 final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
3958 final String sb_str = _sb.toString();
3959 // GUILHEM_BEG ______________
3960 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
3961 && ( _query_sequence != null ) ) {
3962 int nodeTextBoundsWidth = 0;
3963 if ( sb_str.length() > 0 ) {
3964 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
3965 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
3967 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
3968 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
3969 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
3970 g.setColor( getTreeColorSet().getBackgroundColor() );
3974 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
3975 for( final SequenceRelation seqRelation : seqRelations ) {
3976 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
3977 .getRef1().isEqual( _query_sequence ) )
3978 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
3979 .getSelectedItem() );
3980 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
3981 final double linePosX = node.getXcoord() + 2 + half_box_size;
3982 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
3983 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
3985 if ( sConfidence != null ) {
3986 double confidenceX = pos_x;
3987 if ( sb_str.length() > 0 ) {
3988 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
3989 + CONFIDENCE_LEFT_MARGIN;
3991 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
3992 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
3993 .getBounds().getWidth();
3994 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
3995 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
3998 if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
4000 if ( nodeTextBoundsWidth == 0 ) {
4001 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
4004 nodeTextBoundsWidth += 2;
4006 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
4007 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
4014 if ( sb_str.length() > 0 ) {
4015 TreePanel.drawString( sb_str, pos_x, pos_y, g );
4017 // GUILHEM_END _____________
4018 // COMMENTED_OUT_BY_GUILHEM_BEG _______________
4019 // TODO FIXME need to check this one!
4020 //if ( _sb.length() > 0 ) {
4021 // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
4022 // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4024 // COMMENTED_OUT_BY_GUILHEM_END ________________
4025 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
4026 && ( node.getNodeData().getSequence().getAnnotations() != null )
4027 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
4028 if ( _sb.length() > 0 ) {
4029 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
4031 final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
4032 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4033 g.setColor( Color.BLACK );
4035 else if ( getControlPanel().isColorAccordingToAnnotation() ) {
4036 g.setColor( calculateColorForAnnotation( ann ) );
4038 final String ann_str = createAnnotationString( ann );
4039 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
4040 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4042 _sb.append( ann_str );
4044 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
4045 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
4046 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
4047 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
4048 && node.getNodeData().isHasBinaryCharacters() ) {
4049 if ( _sb.length() > 0 ) {
4050 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
4052 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4053 g.setColor( Color.BLACK );
4056 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
4058 if ( getControlPanel().isShowBinaryCharacters() ) {
4059 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
4060 .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord()
4061 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4062 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
4063 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
4064 .getLostCharactersAsStringBuffer().toString() );
4067 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
4068 node.getXcoord() + x + 4 + half_box_size,
4070 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ),
4072 paintGainedAndLostCharacters( g, node, "+"
4073 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
4074 + node.getNodeData().getBinaryCharacters().getLostCount() );
4080 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
4081 final PhylogenyNode node,
4082 final boolean to_pdf,
4083 final boolean to_graphics_file,
4084 final boolean radial_labels,
4085 final double ur_angle,
4086 final boolean is_in_found_nodes ) {
4087 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
4090 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4091 g.setColor( Color.BLACK );
4093 else if ( is_in_found_nodes ) {
4094 g.setColor( getTreeColorSet().getFoundColor() );
4096 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4097 g.setColor( getTaxonomyBasedColor( node ) );
4099 else if ( getControlPanel().isColorAccordingToAnnotation()
4100 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
4101 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
4102 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
4105 g.setColor( getTreeColorSet().getSequenceColor() );
4109 if ( node.getNodeData().isHasTaxonomy()
4110 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
4111 .isShowTaxonomyCommonNames() ) ) {
4112 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4113 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4114 _sb.append( taxonomy.getTaxonomyCode() );
4117 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4118 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4119 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4120 _sb.append( taxonomy.getScientificName() );
4122 _sb.append( taxonomy.getCommonName() );
4125 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4126 _sb.append( taxonomy.getScientificName() );
4129 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4130 _sb.append( taxonomy.getCommonName() );
4134 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4135 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4136 _sb.append( taxonomy.getScientificName() );
4140 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4141 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4142 _sb.append( taxonomy.getCommonName() );
4147 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
4149 _sb.append( node.getAllExternalDescendants().size() );
4152 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
4153 if ( _sb.length() > 0 ) {
4156 _sb.append( node.getName() );
4158 if ( node.getNodeData().isHasSequence() ) {
4159 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4160 if ( _sb.length() > 0 ) {
4163 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
4164 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
4167 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
4169 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
4170 if ( _sb.length() > 0 ) {
4173 _sb.append( node.getNodeData().getSequence().getName() );
4176 g.setFont( getTreeFontSet().getLargeFont() );
4177 if ( is_in_found_nodes ) {
4178 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
4180 if ( _sb.length() > 1 ) {
4181 final String sb_str = _sb.toString();
4183 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4184 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
4187 m = ( float ) ( ur_angle % TWO_PI );
4189 _at = g.getTransform();
4190 boolean need_to_reset = false;
4191 final float x_coord = node.getXcoord();
4192 final float y_coord = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / 3.0f );
4193 if ( radial_labels ) {
4194 need_to_reset = true;
4195 boolean left = false;
4196 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4200 g.rotate( m, x_coord, node.getYcoord() );
4202 g.translate( -( getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth() ), 0 );
4206 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4207 need_to_reset = true;
4208 g.translate( -getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth(), 0 );
4211 TreePanel.drawString( sb_str, x_coord, y_coord, g );
4212 if ( need_to_reset ) {
4213 g.setTransform( _at );
4218 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
4219 if ( node.isCollapse() ) {
4220 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
4221 paintCollapsedNode( g, node, false, false, false );
4225 if ( isInFoundNodes( node ) ) {
4226 g.setColor( getTreeColorSet().getFoundColor() );
4227 drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
4230 if ( !node.isExternal() && !node.isCollapse() ) {
4231 boolean first_child = true;
4233 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4234 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4235 final PhylogenyNode child_node = node.getChildNode( i );
4237 if ( !isUniformBranchLengthsForCladogram() ) {
4238 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4241 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4243 if ( first_child ) {
4244 first_child = false;
4245 y2 = node.getYSecondary()
4246 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
4247 .getNumberOfExternalNodes() ) );
4250 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4252 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
4253 new_x = x2 + node.getXSecondary();
4254 final float diff_y = node.getYSecondary() - y2;
4255 final float diff_x = node.getXSecondary() - new_x;
4256 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
4257 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
4259 child_node.setXSecondary( new_x );
4260 child_node.setYSecondary( y2 );
4261 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4266 final private void paintNodeRectangular( final Graphics2D g,
4267 final PhylogenyNode node,
4268 final boolean to_pdf,
4269 final boolean dynamically_hide,
4270 final int dynamic_hiding_factor,
4271 final boolean to_graphics_file ) {
4272 final boolean is_in_found_nodes = isInFoundNodes( node );
4273 if ( node.isCollapse() ) {
4274 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
4275 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4279 if ( node.isExternal() ) {
4280 ++_external_node_index;
4282 // Confidence values
4283 if ( getControlPanel().isShowConfidenceValues()
4284 && !node.isExternal()
4286 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
4287 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
4288 && node.getBranchData().isHasConfidences() ) {
4289 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
4291 // Draw a line to root:
4292 if ( node.isRoot() && _phylogeny.isRooted() ) {
4293 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
4296 float new_x_min = Float.MAX_VALUE;
4297 final boolean disallow_shortcutting = dynamic_hiding_factor < 40;
4298 float min_dist = 1.5f;
4299 if ( !disallow_shortcutting ) {
4300 // System.out.println( dynamic_hiding_factor );
4301 if ( dynamic_hiding_factor > 4000 ) {
4304 else if ( dynamic_hiding_factor > 1000 ) {
4307 else if ( dynamic_hiding_factor > 100 ) {
4311 if ( !node.isExternal() && !node.isCollapse() ) {
4312 boolean first_child = true;
4314 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4315 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4316 final PhylogenyNode child_node = node.getChildNode( i );
4318 if ( !isUniformBranchLengthsForCladogram() ) {
4319 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4322 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4324 if ( first_child ) {
4325 first_child = false;
4326 y2 = node.getYcoord()
4327 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
4330 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4332 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
4333 new_x = x2 + node.getXcoord();
4334 if ( dynamically_hide && ( x2 < new_x_min ) ) {
4337 final float diff_y = node.getYcoord() - y2;
4338 final float diff_x = node.getXcoord() - new_x;
4339 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
4340 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
4341 paintBranchRectangular( g,
4350 child_node.setXcoord( new_x );
4351 child_node.setYcoord( y2 );
4352 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4354 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
4356 if ( dynamically_hide
4357 && !is_in_found_nodes
4358 && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) ) || ( !node
4359 .isExternal() && ( ( new_x_min < 20 ) || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getTreeFontSet()._fm_large
4360 .getHeight() ) ) ) ) ) {
4363 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4364 paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
4367 final private void paintNodeWithRenderableData( final Graphics2D g,
4368 final PhylogenyNode node,
4369 final boolean to_graphics_file,
4370 final boolean to_pdf ) {
4371 if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
4374 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
4377 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4378 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4379 RenderableDomainArchitecture rds = null;
4380 if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
4382 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
4384 catch ( final ClassCastException cce ) {
4385 cce.printStackTrace();
4387 if ( rds != null ) {
4388 rds.setRenderingHeight( 6 );
4390 if ( node.getNodeData().isHasTaxonomy() ) {
4391 if ( getControlPanel().isShowTaxonomyCode()
4392 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
4393 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4397 if ( getControlPanel().isShowTaxonomyScientificNames()
4398 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) ) {
4399 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4400 .getScientificName()
4403 if ( getControlPanel().isShowTaxonomyCommonNames()
4404 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) ) {
4405 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4410 if ( node.getNodeData().isHasSequence() ) {
4411 if ( getControlPanel().isShowGeneNames()
4412 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) ) {
4413 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName()
4416 if ( getControlPanel().isShowGeneSymbols()
4417 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) ) {
4418 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol()
4421 if ( getControlPanel().isShowSequenceAcc()
4422 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4423 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence()
4424 .getAccession().toString()
4428 if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( node.getName() ) ) {
4429 x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
4431 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
4436 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
4437 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
4438 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
4439 getStatisticsForExpressionValues(),
4440 getConfiguration() );
4443 PhylogenyNode my_node = node;
4444 if ( !getControlPanel().isDrawPhylogram() ) {
4445 my_node = getPhylogeny().getFirstExternalNode();
4447 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
4448 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
4450 if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
4451 x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
4453 rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
4459 final private void paintOvRectangle( final Graphics2D g ) {
4460 final float w_ratio = ( float ) getWidth() / getVisibleRect().width;
4461 final float h_ratio = ( float ) getHeight() / getVisibleRect().height;
4462 final float x_ratio = ( float ) getWidth() / getVisibleRect().x;
4463 final float y_ratio = ( float ) getHeight() / getVisibleRect().y;
4464 final float width = getOvMaxWidth() / w_ratio;
4465 final float height = getOvMaxHeight() / h_ratio;
4466 final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio );
4467 final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio );
4468 g.setColor( getTreeColorSet().getFoundColor() );
4469 getOvRectangle().setRect( x, y, width, height );
4470 if ( ( width < 6 ) && ( height < 6 ) ) {
4471 drawRectFilled( x, y, 6, 6, g );
4472 getOvVirtualRectangle().setRect( x, y, 6, 6 );
4474 else if ( width < 6 ) {
4475 drawRectFilled( x, y, 6, height, g );
4476 getOvVirtualRectangle().setRect( x, y, 6, height );
4478 else if ( height < 6 ) {
4479 drawRectFilled( x, y, width, 6, g );
4480 getOvVirtualRectangle().setRect( x, y, width, 6 );
4483 drawRect( x, y, width, height, g );
4484 if ( isInOvRect() ) {
4485 drawRect( x + 1, y + 1, width - 2, height - 2, g );
4487 getOvVirtualRectangle().setRect( x, y, width, height );
4491 final private void paintPhylogenyLite( final Graphics2D g ) {
4492 //System.out.println( getVisibleRect().x + " " + getVisibleRect().y );
4495 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
4496 .getWidth() ) ) ) );
4497 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
4498 //final PhylogenyNodeIterator it;
4499 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
4500 // paintNodeLite( g, it.next() );
4502 for( final PhylogenyNode element : _nodes_in_preorder ) {
4503 paintNodeLite( g, element );
4505 paintOvRectangle( g );
4509 * Paint the root branch. (Differs from others because it will always be a
4510 * single horizontal line).
4511 * @param to_graphics_file
4513 * @return new x1 value
4515 final private void paintRootBranch( final Graphics2D g,
4518 final PhylogenyNode root,
4519 final boolean to_pdf,
4520 final boolean to_graphics_file ) {
4521 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
4522 float d = getXdistance();
4523 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
4524 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
4526 if ( d < MIN_ROOT_LENGTH ) {
4527 d = MIN_ROOT_LENGTH;
4529 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
4530 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
4533 final double w = PhylogenyMethods.getBranchWidthValue( root );
4534 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
4536 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file, isInFoundNodes( root ) );
4539 final private void paintScale( final Graphics2D g,
4542 final boolean to_pdf,
4543 final boolean to_graphics_file ) {
4545 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
4547 final int y2 = y1 - 8;
4548 final int y3 = y1 - 4;
4549 g.setFont( getTreeFontSet().getSmallFont() );
4550 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4551 g.setColor( Color.BLACK );
4554 g.setColor( getTreeColorSet().getBranchLengthColor() );
4556 drawLine( x1, y1, x1, y2, g );
4557 drawLine( x2, y1, x2, y2, g );
4558 drawLine( x1, y3, x2, y3, g );
4559 if ( getScaleLabel() != null ) {
4560 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
4564 final private int paintTaxonomy( final Graphics2D g,
4565 final PhylogenyNode node,
4566 final boolean is_in_found_nodes,
4567 final boolean to_pdf,
4568 final boolean to_graphics_file,
4569 final double x_shift ) {
4570 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4571 g.setFont( getTreeFontSet().getLargeItalicFont() );
4572 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4573 g.setColor( Color.BLACK );
4575 else if ( is_in_found_nodes ) {
4576 g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
4577 g.setColor( getTreeColorSet().getFoundColor() );
4579 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4580 g.setColor( getTaxonomyBasedColor( node ) );
4582 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
4583 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
4584 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
4586 else if ( to_pdf ) {
4587 g.setColor( Color.BLACK );
4590 g.setColor( getTreeColorSet().getTaxonomyColor() );
4592 final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
4593 final double start_y = node.getYcoord()
4594 + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
4596 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4597 _sb.append( taxonomy.getTaxonomyCode() );
4600 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4601 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4602 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4603 if ( getOptions().isAbbreviateScientificTaxonNames()
4604 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4605 abbreviateScientificName( taxonomy.getScientificName() );
4608 _sb.append( taxonomy.getScientificName() );
4611 _sb.append( taxonomy.getCommonName() );
4614 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4615 if ( getOptions().isAbbreviateScientificTaxonNames()
4616 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4617 abbreviateScientificName( taxonomy.getScientificName() );
4620 _sb.append( taxonomy.getScientificName() );
4624 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4625 _sb.append( taxonomy.getCommonName() );
4629 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4630 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4631 if ( getOptions().isAbbreviateScientificTaxonNames()
4632 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4633 abbreviateScientificName( taxonomy.getScientificName() );
4636 _sb.append( taxonomy.getScientificName() );
4641 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4642 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4643 _sb.append( taxonomy.getCommonName() );
4647 final String label = _sb.toString();
4649 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
4650 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
4651 // invert font color and background color to show that this is the query sequence
4652 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
4656 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
4657 g.setColor( getTreeColorSet().getBackgroundColor() );
4660 TreePanel.drawString( label, start_x, start_y, g );
4661 if ( is_in_found_nodes ) {
4662 return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
4665 return getTreeFontSet()._fm_large_italic.stringWidth( label );
4669 final private void paintUnrooted( final PhylogenyNode n,
4670 final double low_angle,
4671 final double high_angle,
4672 final boolean radial_labels,
4674 final boolean to_pdf,
4675 final boolean to_graphics_file ) {
4677 n.setXcoord( getWidth() / 2 );
4678 n.setYcoord( getHeight() / 2 );
4680 if ( n.isExternal() ) {
4681 paintNodeDataUnrootedCirc( g,
4686 ( high_angle + low_angle ) / 2,
4687 isInFoundNodes( n ) );
4690 final float num_enclosed = n.getNumberOfExternalNodes();
4691 final float x = n.getXcoord();
4692 final float y = n.getYcoord();
4693 double current_angle = low_angle;
4694 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
4695 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
4696 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
4697 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
4698 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4699 final PhylogenyNode desc = n.getChildNode( i );
4700 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
4701 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
4702 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
4703 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
4706 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
4709 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
4712 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4713 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4715 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4716 if ( desc.getDistanceToParent() < 0 ) {
4720 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
4724 length = getUrtFactor();
4726 final double mid_angle = current_angle + ( arc_size / 2 );
4727 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
4728 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
4729 desc.setXcoord( new_x );
4730 desc.setYcoord( new_y );
4731 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
4732 current_angle += arc_size;
4733 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
4734 drawLine( x, y, new_x, new_y, g );
4735 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc ) );
4738 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file, isInFoundNodes( n ) );
4742 final private void paintUnrootedLite( final PhylogenyNode n,
4743 final double low_angle,
4744 final double high_angle,
4746 final float urt_ov_factor ) {
4748 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) );
4749 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) );
4750 n.setXSecondary( x_pos );
4751 n.setYSecondary( y_pos );
4753 if ( n.isExternal() ) {
4756 final float num_enclosed = n.getNumberOfExternalNodes();
4757 final float x = n.getXSecondary();
4758 final float y = n.getYSecondary();
4759 double current_angle = low_angle;
4760 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4761 final PhylogenyNode desc = n.getChildNode( i );
4762 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4763 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4765 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4766 if ( desc.getDistanceToParent() < 0 ) {
4770 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
4774 length = urt_ov_factor;
4776 final double mid_angle = current_angle + ( arc_size / 2 );
4777 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
4778 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
4779 desc.setXSecondary( new_x );
4780 desc.setYSecondary( new_y );
4781 if ( isInFoundNodes( desc ) ) {
4782 g.setColor( getTreeColorSet().getFoundColor() );
4783 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
4784 g.setColor( getTreeColorSet().getOvColor() );
4786 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
4787 current_angle += arc_size;
4788 drawLine( x, y, new_x, new_y, g );
4792 final private void pasteSubtree( final PhylogenyNode node ) {
4793 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4794 errorMessageNoCutCopyPasteInUnrootedDisplay();
4797 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
4798 JOptionPane.showMessageDialog( this,
4799 "No tree in buffer (need to copy or cut a subtree first)",
4800 "Attempt to paste with empty buffer",
4801 JOptionPane.ERROR_MESSAGE );
4804 final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
4805 final Object[] options = { "As sibling", "As descendant", "Cancel" };
4806 final int r = JOptionPane.showOptionDialog( this,
4807 "How to paste subtree" + label + "?",
4809 JOptionPane.CLOSED_OPTION,
4810 JOptionPane.QUESTION_MESSAGE,
4814 boolean paste_as_sibling = true;
4816 paste_as_sibling = false;
4818 else if ( r != 0 ) {
4821 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
4822 buffer_phy.setAllNodesToNotCollapse();
4823 PhylogenyMethods.preOrderReId( buffer_phy );
4824 buffer_phy.setRooted( true );
4825 boolean need_to_show_whole = false;
4826 if ( paste_as_sibling ) {
4827 if ( node.isRoot() ) {
4828 JOptionPane.showMessageDialog( this,
4829 "Cannot paste sibling to root",
4830 "Attempt to paste sibling to root",
4831 JOptionPane.ERROR_MESSAGE );
4834 buffer_phy.addAsSibling( node );
4837 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
4838 need_to_show_whole = true;
4839 _phylogeny = buffer_phy;
4842 buffer_phy.addAsChild( node );
4845 if ( getCopiedAndPastedNodes() == null ) {
4846 setCopiedAndPastedNodes( new HashSet<Integer>() );
4848 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
4849 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
4850 for( final PhylogenyNode n : nodes ) {
4851 node_ids.add( n.getId() );
4853 node_ids.add( node.getId() );
4854 getCopiedAndPastedNodes().addAll( node_ids );
4855 setNodeInPreorderToNull();
4856 _phylogeny.externalNodesHaveChanged();
4857 _phylogeny.clearHashIdToNodeMap();
4858 _phylogeny.recalculateNumberOfExternalDescendants( true );
4859 resetNodeIdToDistToLeafMap();
4861 if ( need_to_show_whole ) {
4862 getControlPanel().showWhole();
4867 private final StringBuffer propertiesToString( final PhylogenyNode node ) {
4868 final PropertiesMap properties = node.getNodeData().getProperties();
4869 final StringBuffer sb = new StringBuffer();
4870 boolean first = true;
4871 for( final String ref : properties.getPropertyRefs() ) {
4878 final Property p = properties.getProperty( ref );
4879 sb.append( getPartAfterColon( p.getRef() ) );
4881 sb.append( p.getValue() );
4882 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
4883 sb.append( getPartAfterColon( p.getUnit() ) );
4889 final private void setCopiedAndPastedNodes( final Set<Integer> nodeIds ) {
4890 getMainPanel().setCopiedAndPastedNodes( nodeIds );
4893 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
4894 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
4897 final private void setInOv( final boolean in_ov ) {
4901 final private void setOvMaxHeight( final float ov_max_height ) {
4902 _ov_max_height = ov_max_height;
4905 final private void setOvMaxWidth( final float ov_max_width ) {
4906 _ov_max_width = ov_max_width;
4909 final private void setOvXcorrectionFactor( final float f ) {
4910 _ov_x_correction_factor = f;
4913 final private void setOvXDistance( final float ov_x_distance ) {
4914 _ov_x_distance = ov_x_distance;
4917 final private void setOvXPosition( final int ov_x_position ) {
4918 _ov_x_position = ov_x_position;
4921 final private void setOvYDistance( final float ov_y_distance ) {
4922 _ov_y_distance = ov_y_distance;
4925 final private void setOvYPosition( final int ov_y_position ) {
4926 _ov_y_position = ov_y_position;
4929 final private void setOvYStart( final int ov_y_start ) {
4930 _ov_y_start = ov_y_start;
4933 final private void setScaleDistance( final double scale_distance ) {
4934 _scale_distance = scale_distance;
4937 final private void setScaleLabel( final String scale_label ) {
4938 _scale_label = scale_label;
4941 final private void setUpUrtFactor() {
4942 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
4943 : getVisibleRect().height;
4944 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4945 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
4948 final int max_depth = _circ_max_depth;
4949 if ( max_depth > 0 ) {
4950 setUrtFactor( d / ( 2 * max_depth ) );
4953 setUrtFactor( d / 2 );
4956 setUrtFactorOv( getUrtFactor() );
4959 final private void setUrtFactor( final float urt_factor ) {
4960 _urt_factor = urt_factor;
4963 final private void setUrtFactorOv( final float urt_factor_ov ) {
4964 _urt_factor_ov = urt_factor_ov;
4967 private void showExtDescNodeData( final PhylogenyNode node ) {
4968 final List<String> data = new ArrayList<String>();
4969 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
4970 switch ( getOptions().getExtDescNodeDataToReturn() ) {
4972 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
4973 data.add( n.getName() );
4977 if ( n.getNodeData().isHasSequence()
4978 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
4979 data.add( n.getNodeData().getSequence().getName() );
4982 case SEQUENCE_SYMBOL:
4983 if ( n.getNodeData().isHasSequence()
4984 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
4985 data.add( n.getNodeData().getSequence().getSymbol() );
4988 case SEQUENCE_MOL_SEQ:
4989 if ( n.getNodeData().isHasSequence()
4990 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
4991 data.add( n.getNodeData().getSequence().getMolecularSequence() );
4995 if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
4996 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
4997 data.add( n.getNodeData().getSequence().getAccession().toString() );
5000 case TAXONOMY_SCIENTIFIC_NAME:
5001 if ( n.getNodeData().isHasTaxonomy()
5002 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
5003 data.add( n.getNodeData().getTaxonomy().getScientificName() );
5007 if ( n.getNodeData().isHasTaxonomy()
5008 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
5009 data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
5013 AptxUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
5016 throw new IllegalArgumentException( "unknown data element: "
5017 + getOptions().getExtDescNodeDataToReturn() );
5020 if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
5021 || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
5022 final StringBuilder sb = new StringBuilder();
5023 for( final String d : data ) {
5024 if ( !ForesterUtil.isEmpty( d ) ) {
5025 if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
5026 System.out.println( d );
5029 sb.append( ForesterUtil.LINE_SEPARATOR );
5032 if ( sb.length() < 1 ) {
5033 clearCurrentExternalNodesDataBuffer();
5036 setCurrentExternalNodesDataBuffer( sb );
5039 else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
5040 final StringBuilder sb = new StringBuilder();
5041 for( final String d : data ) {
5042 if ( !ForesterUtil.isEmpty( d ) ) {
5044 sb.append( ForesterUtil.LINE_SEPARATOR );
5047 if ( sb.length() < 1 ) {
5048 AptxUtil.showInformationMessage( this,
5049 "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")",
5050 "Descendants of selected node do not contain selected data" );
5051 clearCurrentExternalNodesDataBuffer();
5054 setCurrentExternalNodesDataBuffer( sb );
5055 final String title = "External Descendants "
5056 + ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
5057 : obtainTitleForExtDescNodeData() ) + " (" + data.size() + "/"
5058 + node.getNumberOfExternalNodes() + ") For Node " + node;
5059 final String s = sb.toString().trim();
5060 if ( getMainPanel().getMainFrame() == null ) {
5061 // Must be "E" applet version.
5062 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
5063 ae.showTextFrame( s, title );
5066 getMainPanel().getMainFrame().showTextFrame( s, title );
5072 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
5074 if ( ( node.getName().length() > 0 )
5075 || ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
5076 || ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) )
5077 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
5078 || node.getBranchData().isHasConfidences() ) {
5079 _popup_buffer.setLength( 0 );
5081 if ( node.getName().length() > 0 ) {
5083 _popup_buffer.append( node.getName() );
5085 if ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
5087 boolean enc_data = false;
5088 final Taxonomy tax = node.getNodeData().getTaxonomy();
5089 if ( _popup_buffer.length() > 0 ) {
5090 _popup_buffer.append( "\n" );
5092 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
5093 _popup_buffer.append( "[" );
5094 _popup_buffer.append( tax.getTaxonomyCode() );
5095 _popup_buffer.append( "]" );
5098 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
5100 _popup_buffer.append( " " );
5102 _popup_buffer.append( tax.getScientificName() );
5105 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
5107 _popup_buffer.append( " (" );
5110 _popup_buffer.append( "(" );
5112 _popup_buffer.append( tax.getCommonName() );
5113 _popup_buffer.append( ")" );
5116 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
5118 _popup_buffer.append( " (" );
5121 _popup_buffer.append( "(" );
5123 _popup_buffer.append( tax.getAuthority() );
5124 _popup_buffer.append( ")" );
5127 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
5129 _popup_buffer.append( " [" );
5132 _popup_buffer.append( "[" );
5134 _popup_buffer.append( tax.getRank() );
5135 _popup_buffer.append( "]" );
5138 if ( tax.getSynonyms().size() > 0 ) {
5140 _popup_buffer.append( " " );
5142 _popup_buffer.append( "[" );
5144 for( final String syn : tax.getSynonyms() ) {
5145 if ( !ForesterUtil.isEmpty( syn ) ) {
5147 _popup_buffer.append( syn );
5148 if ( counter < tax.getSynonyms().size() ) {
5149 _popup_buffer.append( ", " );
5154 _popup_buffer.append( "]" );
5157 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
5158 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
5159 _popup_buffer.append( "[" );
5160 _popup_buffer.append( tax.getIdentifier().getProvider() );
5161 _popup_buffer.append( "] " );
5163 _popup_buffer.append( tax.getIdentifier().getValue() );
5167 if ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) ) {
5169 boolean enc_data = false;
5170 if ( _popup_buffer.length() > 0 ) {
5171 _popup_buffer.append( "\n" );
5173 final Sequence seq = node.getNodeData().getSequence();
5174 if ( seq.getAccession() != null ) {
5175 _popup_buffer.append( "[" );
5176 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
5177 _popup_buffer.append( seq.getAccession().getSource() );
5178 _popup_buffer.append( ":" );
5180 _popup_buffer.append( seq.getAccession().getValue() );
5181 _popup_buffer.append( "]" );
5184 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
5186 _popup_buffer.append( " [" );
5189 _popup_buffer.append( "[" );
5191 _popup_buffer.append( seq.getSymbol() );
5192 _popup_buffer.append( "]" );
5195 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
5197 _popup_buffer.append( " " );
5199 _popup_buffer.append( seq.getName() );
5202 if ( node.getNodeData().isHasDate() ) {
5204 if ( _popup_buffer.length() > 0 ) {
5205 _popup_buffer.append( "\n" );
5207 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
5209 if ( node.getNodeData().isHasDistribution() ) {
5211 if ( _popup_buffer.length() > 0 ) {
5212 _popup_buffer.append( "\n" );
5214 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
5216 if ( node.getBranchData().isHasConfidences() ) {
5217 final List<Confidence> confs = node.getBranchData().getConfidences();
5218 for( final Confidence confidence : confs ) {
5220 if ( _popup_buffer.length() > 0 ) {
5221 _popup_buffer.append( "\n" );
5223 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
5224 _popup_buffer.append( "[" );
5225 _popup_buffer.append( confidence.getType() );
5226 _popup_buffer.append( "] " );
5229 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
5231 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5232 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5233 _popup_buffer.append( " (sd=" );
5234 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence
5235 .getStandardDeviation(), getOptions()
5236 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5237 _popup_buffer.append( ")" );
5241 if ( node.getNodeData().isHasProperties() ) {
5242 final PropertiesMap properties = node.getNodeData().getProperties();
5243 for( final String ref : properties.getPropertyRefs() ) {
5244 _popup_buffer.append( "\n" );
5245 final Property p = properties.getProperty( ref );
5246 _popup_buffer.append( getPartAfterColon( p.getRef() ) );
5247 _popup_buffer.append( "=" );
5248 _popup_buffer.append( p.getValue() );
5249 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
5250 _popup_buffer.append( getPartAfterColon( p.getUnit() ) );
5254 if ( _popup_buffer.length() > 0 ) {
5255 if ( !getConfiguration().isUseNativeUI() ) {
5257 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
5258 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
5259 if ( isInFoundNodes( node ) ) {
5260 _rollover_popup.setForeground( getTreeColorSet().getFoundColor() );
5262 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
5263 _rollover_popup.setForeground( getTaxonomyBasedColor( node ) );
5266 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
5270 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
5272 _rollover_popup.setText( _popup_buffer.toString() );
5273 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
5275 e.getLocationOnScreen().x + 10,
5276 e.getLocationOnScreen().y
5278 _node_desc_popup.show();
5282 catch ( final Exception ex ) {
5287 final private void showNodeEditFrame( final PhylogenyNode n ) {
5288 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5289 // pop up edit box for single node
5290 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
5291 _node_frame_index++;
5294 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5298 final private void showNodeFrame( final PhylogenyNode n ) {
5299 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5300 // pop up edit box for single node
5301 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
5302 _node_frame_index++;
5305 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5309 final private void switchDisplaygetPhylogenyGraphicsType() {
5310 switch ( getPhylogenyGraphicsType() ) {
5312 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5313 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5316 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5317 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5320 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5321 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5324 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5325 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5328 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5329 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5332 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5333 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5336 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5337 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5340 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5341 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5344 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
5346 if ( getControlPanel().getDynamicallyHideData() != null ) {
5347 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5348 getControlPanel().getDynamicallyHideData().setEnabled( false );
5351 getControlPanel().getDynamicallyHideData().setEnabled( true );
5354 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5355 getControlPanel().setDrawPhylogramEnabled( true );
5358 getControlPanel().setDrawPhylogramEnabled( false );
5360 if ( getMainPanel().getMainFrame() == null ) {
5361 // Must be "E" applet version.
5362 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
5363 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5366 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5370 final private static void drawString( final int i, final double x, final double y, final Graphics2D g ) {
5371 g.drawString( String.valueOf( i ), ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5374 final private static void drawString( final String str, final double x, final double y, final Graphics2D g ) {
5375 g.drawString( str, ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5378 final private static String getPartAfterColon( final String s ) {
5379 final int i = s.indexOf( ':' );
5380 if ( ( i < 1 ) || ( i == ( s.length() - 1 ) ) ) {
5383 return s.substring( i + 1, s.length() );
5386 final private static boolean isSequenceEmpty( final Sequence seq ) {
5387 return ( seq.getAccession() == null ) && ForesterUtil.isEmpty( seq.getName() )
5388 && ForesterUtil.isEmpty( seq.getSymbol() );
5391 final private static boolean isTaxonomyEmpty( final Taxonomy tax ) {
5392 return ( ( tax.getIdentifier() == null ) && ForesterUtil.isEmpty( tax.getTaxonomyCode() )
5393 && ForesterUtil.isEmpty( tax.getCommonName() ) && ForesterUtil.isEmpty( tax.getScientificName() ) && tax
5394 .getSynonyms().isEmpty() );
5397 final private static boolean plusPressed( final int key_code ) {
5398 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
5399 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
5402 final private static Phylogeny subTree( final PhylogenyNode new_root, final Phylogeny source_phy ) {
5403 final Phylogeny new_phy = new Phylogeny();
5404 new_phy.setRooted( true );
5405 new_phy.setName( source_phy.getName() );
5406 new_phy.setDescription( source_phy.getDescription() );
5407 new_phy.setType( source_phy.getType() );
5408 new_phy.setDistanceUnit( source_phy.getDistanceUnit() );
5409 new_phy.setConfidence( source_phy.getConfidence() );
5410 new_phy.setIdentifier( source_phy.getIdentifier() );
5411 new_phy.setRoot( new_root.copyNodeDataShallow() );
5413 for( final PhylogenyNode n : new_root.getDescendants() ) {
5414 new_phy.getRoot().setChildNode( i++, n );
5419 final private class SubtreeColorizationActionListener implements ActionListener {
5421 JColorChooser _chooser;
5422 PhylogenyNode _node;
5424 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
5430 public void actionPerformed( final ActionEvent e ) {
5431 final Color c = _chooser.getColor();
5433 colorizeSubtree( c, _node );