2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.archaeopteryx;
28 import java.awt.BasicStroke;
29 import java.awt.Color;
30 import java.awt.Cursor;
31 import java.awt.Dimension;
33 import java.awt.GradientPaint;
34 import java.awt.Graphics;
35 import java.awt.Graphics2D;
36 import java.awt.Point;
37 import java.awt.Rectangle;
38 import java.awt.RenderingHints;
39 import java.awt.Stroke;
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.Path2D;
58 import java.awt.geom.QuadCurve2D;
59 import java.awt.geom.Rectangle2D;
60 import java.awt.image.BufferedImage;
61 import java.awt.print.PageFormat;
62 import java.awt.print.Printable;
63 import java.awt.print.PrinterException;
65 import java.io.IOException;
66 import java.io.UnsupportedEncodingException;
68 import java.net.URISyntaxException;
69 import java.net.URLEncoder;
70 import java.text.DecimalFormat;
71 import java.text.DecimalFormatSymbols;
72 import java.text.NumberFormat;
73 import java.util.ArrayList;
74 import java.util.Collections;
75 import java.util.HashMap;
76 import java.util.HashSet;
77 import java.util.Hashtable;
78 import java.util.List;
80 import java.util.SortedSet;
82 import javax.swing.BorderFactory;
83 import javax.swing.JApplet;
84 import javax.swing.JColorChooser;
85 import javax.swing.JDialog;
86 import javax.swing.JMenuItem;
87 import javax.swing.JOptionPane;
88 import javax.swing.JPanel;
89 import javax.swing.JPopupMenu;
90 import javax.swing.JTextArea;
91 import javax.swing.Popup;
92 import javax.swing.PopupFactory;
94 import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON;
95 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
96 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
97 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
98 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
99 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
100 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
101 import org.forester.archaeopteryx.tools.Blast;
102 import org.forester.archaeopteryx.tools.ImageLoader;
103 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
104 import org.forester.io.writers.SequenceWriter;
105 import org.forester.phylogeny.Phylogeny;
106 import org.forester.phylogeny.PhylogenyMethods;
107 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
108 import org.forester.phylogeny.PhylogenyNode;
109 import org.forester.phylogeny.data.Accession;
110 import org.forester.phylogeny.data.Annotation;
111 import org.forester.phylogeny.data.BranchColor;
112 import org.forester.phylogeny.data.Confidence;
113 import org.forester.phylogeny.data.Event;
114 import org.forester.phylogeny.data.NodeData.NODE_DATA;
115 import org.forester.phylogeny.data.NodeVisualization;
116 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
117 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
118 import org.forester.phylogeny.data.PhylogenyDataUtil;
119 import org.forester.phylogeny.data.PropertiesMap;
120 import org.forester.phylogeny.data.Property;
121 import org.forester.phylogeny.data.Sequence;
122 import org.forester.phylogeny.data.SequenceRelation;
123 import org.forester.phylogeny.data.Taxonomy;
124 import org.forester.phylogeny.data.Uri;
125 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
126 import org.forester.phylogeny.iterators.PreorderTreeIterator;
127 import org.forester.util.BasicDescriptiveStatistics;
128 import org.forester.util.DescriptiveStatistics;
129 import org.forester.util.ForesterConstants;
130 import org.forester.util.ForesterUtil;
131 import org.forester.util.SequenceAccessionTools;
132 import org.forester.util.TaxonomyUtil;
134 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
136 private static final BasicStroke STROKE_2 = new BasicStroke( 2f );
137 private static final BasicStroke STROKE_1 = new BasicStroke( 1f );
138 private static final BasicStroke STROKE_075 = new BasicStroke( 0.75f );
139 private static final BasicStroke STROKE_05 = new BasicStroke( 0.5f );
140 private static final BasicStroke STROKE_025 = new BasicStroke( 0.25f );
141 private static final BasicStroke STROKE_01 = new BasicStroke( 0.1f );
142 private static final BasicStroke STROKE_005 = new BasicStroke( 0.05f );
143 private static final float PI = ( float ) ( Math.PI );
144 private static final double TWO_PI = 2 * Math.PI;
145 private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
146 private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
147 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
148 private static final short OV_BORDER = 10;
149 final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
150 final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
151 final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
152 final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
153 final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
154 private final static long serialVersionUID = -978349745916505029L;
155 private final static int EURO_D = 10;
156 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
157 private final static int MIN_ROOT_LENGTH = 3;
158 private final static int MAX_SUBTREES = 100;
159 private final static int MAX_NODE_FRAMES = 10;
160 private final static int MOVE = 20;
161 private final static NumberFormat FORMATTER_CONFIDENCE;
162 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
163 private final static int WIGGLE = 2;
164 private final static int LIMIT_FOR_HQ_RENDERING = 2000;
165 private final static int CONFIDENCE_LEFT_MARGIN = 4;
166 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
167 RenderingHints.VALUE_RENDER_DEFAULT );
168 private File _treefile = null;
169 private Configuration _configuration = null;
170 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
171 private int _node_frame_index = 0;
172 private Phylogeny _phylogeny = null;
173 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
174 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
175 private int _subtree_index = 0;
176 private MainPanel _main_panel = null;
177 private Set<Long> _found_nodes_0 = null;
178 private Set<Long> _found_nodes_1 = null;
180 private PhylogenyNode _highlight_node = null;
181 private JPopupMenu _node_popup_menu = null;
182 private JMenuItem _node_popup_menu_items[] = null;
183 private int _longest_ext_node_info = 0;
184 private float _x_correction_factor = 0.0f;
185 private float _ov_x_correction_factor = 0.0f;
186 private float _x_distance = 0.0f;
187 private float _y_distance = 0.0f;
188 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
189 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
190 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
191 private float _last_drag_point_x = 0;
192 private float _last_drag_point_y = 0;
193 private ControlPanel _control_panel = null;
194 private int _external_node_index = 0;
195 private final Path2D.Float _polygon = new Path2D.Float();
196 private final StringBuilder _sb = new StringBuilder();
197 private JColorChooser _color_chooser = null;
198 private double _scale_distance = 0.0;
199 private String _scale_label = null;
200 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
201 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
202 private final Line2D _line = new Line2D.Float();
203 private final Ellipse2D _ellipse = new Ellipse2D.Float();
204 private final Rectangle2D _rectangle = new Rectangle2D.Float();
205 private Options _options = null;
206 private float _ov_max_width = 0;
207 private float _ov_max_height = 0;
208 private int _ov_x_position = 0;
209 private int _ov_y_position = 0;
210 private int _ov_y_start = 0;
211 private float _ov_y_distance = 0;
212 private float _ov_x_distance = 0;
213 private boolean _ov_on = false;
214 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
215 private float _urt_factor = 1;
216 private float _urt_factor_ov = 1;
217 private final boolean _phy_has_branch_lengths;
218 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
219 private boolean _in_ov_rect = false;
220 private boolean _in_ov = false;
221 private final Rectangle _ov_virtual_rectangle = new Rectangle();
222 final private static double _180_OVER_PI = 180.0 / Math.PI;
223 private static final float ROUNDED_D = 8;
224 private int _circ_max_depth;
225 private PhylogenyNode _root;
226 final private Arc2D _arc = new Arc2D.Double();
227 final private HashMap<Long, Double> _urt_nodeid_angle_map = new HashMap<Long, Double>();
228 final private HashMap<Long, Integer> _urt_nodeid_index_map = new HashMap<Long, Integer>();
229 final private Set<Long> _collapsed_external_nodeid_set = new HashSet<Long>();
230 HashMap<Long, Short> _nodeid_dist_to_leaf = new HashMap<Long, Short>();
231 private AffineTransform _at;
232 private double _max_distance_to_root = -1;
233 private int _dynamic_hiding_factor = 0;
234 private boolean _edited = false;
235 private Popup _node_desc_popup;
236 private JTextArea _rollover_popup;
237 private final StringBuffer _popup_buffer = new StringBuffer();
238 final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(),
241 private Sequence _query_sequence = null;
242 private final FontRenderContext _frc = new FontRenderContext( null,
245 // expression values menu:
246 private DescriptiveStatistics _statistics_for_vector_data;
247 private PhylogenyNode[] _nodes_in_preorder = null;
248 private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
249 private int _current_external_nodes_data_buffer_change_counter = 0;
250 private Set<Long> _current_external_nodes = null;
251 // private Image offscreenImage;
252 // private Graphics offscreenGraphics;
253 // private Dimension offscreenDimension;
255 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
256 dfs.setDecimalSeparator( '.' );
257 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
258 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
261 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
262 requestFocusInWindow();
263 addKeyListener( new KeyAdapter() {
266 public void keyPressed( final KeyEvent key_event ) {
267 keyPressedCalls( key_event );
268 requestFocusInWindow();
271 addFocusListener( new FocusAdapter() {
274 public void focusGained( final FocusEvent e ) {
275 requestFocusInWindow();
278 if ( ( t == null ) || t.isEmpty() ) {
279 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
281 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
283 _configuration = configuration;
285 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
287 // if ( !_phylogeny.isEmpty() ) {
288 _phylogeny.recalculateNumberOfExternalDescendants( true );
289 checkForVectorProperties( _phylogeny );
291 setBackground( getTreeColorSet().getBackgroundColor() );
292 final MouseListener mouse_listener = new MouseListener( this );
293 addMouseListener( mouse_listener );
294 addMouseMotionListener( mouse_listener );
295 addMouseWheelListener( this );
296 calculateScaleDistance();
297 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
298 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
299 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
303 final public void actionPerformed( final ActionEvent e ) {
304 boolean done = false;
305 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
306 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
307 // NOTE: index corresponds to the indices of click-to options
308 // in the control panel.
309 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
310 // Set this as the new default click-to action
311 _main_panel.getControlPanel().setClickToAction( index );
312 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
313 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
314 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
319 requestFocusInWindow();
322 public synchronized Hashtable<String, BufferedImage> getImageMap() {
323 return getMainPanel().getImageMap();
326 final public MainPanel getMainPanel() {
331 * Get a pointer to the phylogeny
333 * @return a pointer to the phylogeny
335 public final Phylogeny getPhylogeny() {
340 final public void mouseWheelMoved( final MouseWheelEvent e ) {
341 final int notches = e.getWheelRotation();
342 if ( inOvVirtualRectangle( e ) ) {
343 if ( !isInOvRect() ) {
349 if ( isInOvRect() ) {
350 setInOvRect( false );
354 if ( e.isControlDown() ) {
356 getTreeFontSet().increaseFontSize();
357 getControlPanel().displayedPhylogenyMightHaveChanged( true );
360 getTreeFontSet().decreaseFontSize( 1, false );
361 getControlPanel().displayedPhylogenyMightHaveChanged( true );
364 else if ( e.isShiftDown() ) {
365 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
366 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
368 for( int i = 0; i < ( -notches ); ++i ) {
369 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
370 getControlPanel().displayedPhylogenyMightHaveChanged( false );
374 for( int i = 0; i < notches; ++i ) {
375 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
376 if ( getStartingAngle() < 0 ) {
377 setStartingAngle( TWO_PI + getStartingAngle() );
379 getControlPanel().displayedPhylogenyMightHaveChanged( false );
385 for( int i = 0; i < ( -notches ); ++i ) {
386 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
387 getControlPanel().displayedPhylogenyMightHaveChanged( false );
391 for( int i = 0; i < notches; ++i ) {
392 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
393 getControlPanel().displayedPhylogenyMightHaveChanged( false );
400 for( int i = 0; i < ( -notches ); ++i ) {
401 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
402 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
403 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
404 getControlPanel().displayedPhylogenyMightHaveChanged( false );
408 for( int i = 0; i < notches; ++i ) {
409 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
410 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
411 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
412 getControlPanel().displayedPhylogenyMightHaveChanged( false );
417 requestFocusInWindow();
422 final public void paintComponent( final Graphics g ) {
423 // Dimension currentSize = getSize();
424 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
425 // call the 'java.awt.Component.createImage(...)' method to get an
427 // offscreenImage = createImage( currentSize.width, currentSize.height );
428 // offscreenGraphics = offscreenImage.getGraphics();
429 // offscreenDimension = currentSize;
431 // super.paintComponent( g ); //why?
432 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
433 final Graphics2D g2d = ( Graphics2D ) g;
434 g2d.setRenderingHints( _rendering_hints );
435 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
436 //g.drawImage( offscreenImage, 0, 0, this );
440 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
441 throws PrinterException {
442 if ( page_index > 0 ) {
443 return ( NO_SUCH_PAGE );
446 final Graphics2D g2d = ( Graphics2D ) g;
447 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
448 // Turn off double buffering !?
449 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
450 // Turn double buffering back on !?
451 return ( PAGE_EXISTS );
455 public final void setEdited( final boolean edited ) {
459 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
460 getMainPanel().setImageMap( image_map );
464 * Set a phylogeny tree.
467 * an instance of a Phylogeny
469 public final void setTree( final Phylogeny t ) {
470 setNodeInPreorderToNull();
474 public final void setWaitCursor() {
475 setCursor( WAIT_CURSOR );
480 public void update( final Graphics g ) {
484 final void calcMaxDepth() {
485 if ( _phylogeny != null ) {
486 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
491 * Set parameters for printing the displayed tree
494 final void calcParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
495 // updateStyle(); not needed?
496 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
498 if ( recalc_longest_ext_node_info ) {
499 calculateLongestExtNodeInfo();
500 if ( getOptions().isAllowFontSizeChange() ) {
501 if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
502 && ( getTreeFontSet().getLargeFont().getSize() > 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) {
503 while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) )
504 && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) {
505 getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(),
507 calculateLongestExtNodeInfo();
511 while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) )
512 && ( getTreeFontSet().getLargeFont().getSize() <= getTreeFontSet().getLargeFontMemory()
513 .getSize() - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) {
514 getMainPanel().getTreeFontSet().increaseFontSize();
515 calculateLongestExtNodeInfo();
520 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
521 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
522 if ( ext_nodes == 1 ) {
523 ext_nodes = max_depth;
524 if ( ext_nodes < 1 ) {
531 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
532 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
533 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
536 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
537 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
539 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
543 if ( ov_xdist < 0.0 ) {
549 setXdistance( xdist );
550 setYdistance( ydist );
551 setOvXDistance( ov_xdist );
552 final double height = _phylogeny.getHeight();
554 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
555 setXcorrectionFactor( corr > 0 ? corr : 0 );
556 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
557 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
560 setXcorrectionFactor( 0 );
561 setOvXcorrectionFactor( 0 );
563 _circ_max_depth = max_depth;
566 if ( getOptions().isAllowFontSizeChange() ) {
567 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
568 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
569 // int dynamic_hiding_factor = calcDynamicHidingFactor();
570 // if ( dynamic_hiding_factor > 1 ) {
571 // while ( dynamic_hiding_factor > 1
572 // && getTreeFontSet()._fm_large.getHeight() > TreeFontSet.SMALL_FONTS_BASE ) {
573 // getTreeFontSet().decreaseFontSize( 1, true );
574 // dynamic_hiding_factor = calcDynamicHidingFactor();
577 // else if ( getTreeFontSet().isDecreasedSizeBySystem() ) {
578 // while ( dynamic_hiding_factor < 1 && getTreeFontSet()._fm_large.getHeight() < 12 ) {
579 // getTreeFontSet().increaseFontSize();
580 // dynamic_hiding_factor = calcDynamicHidingFactor();
589 final void calculateLongestExtNodeInfo() {
590 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
593 int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - MOVE )
594 * Constants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
595 if ( max_length < 40 ) {
599 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
601 if ( node.isCollapse() ) {
604 if ( getControlPanel().isShowNodeNames() ) {
605 sum += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
607 if ( node.getNodeData().isHasSequence() ) {
608 if ( getControlPanel().isShowSequenceAcc()
609 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
610 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
614 if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
615 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
617 if ( getControlPanel().isShowSeqSymbols()
618 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
619 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
621 if ( getControlPanel().isShowGeneNames()
622 && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) {
623 sum += getTreeFontSet()._fm_large
624 .stringWidth( node.getNodeData().getSequence().getGeneName() + " " );
626 if ( getControlPanel().isShowAnnotation()
627 && ( node.getNodeData().getSequence().getAnnotations() != null )
628 && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
629 sum += getTreeFontSet()._fm_large.stringWidth( TreePanelUtil.createAnnotationString( node
630 .getNodeData().getSequence().getAnnotations(), getOptions().isShowAnnotationRefSource() )
633 if ( getControlPanel().isShowDomainArchitectures()
634 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
635 sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() )
636 .getRenderingSize().getWidth();
639 if ( node.getNodeData().isHasTaxonomy() ) {
640 final Taxonomy tax = node.getNodeData().getTaxonomy();
641 if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
642 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getTaxonomyCode() + " " );
644 if ( getControlPanel().isShowTaxonomyScientificNames()
645 && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
646 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getScientificName() + " " );
648 if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
649 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getCommonName() + " ()" );
652 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
653 sum += getTreeFontSet()._fm_large.stringWidth( propertiesToString( node ).toString() );
655 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
656 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters()
657 .getGainedCharactersAsStringBuffer().toString() );
659 if ( sum >= max_length ) {
660 setLongestExtNodeInfo( max_length );
663 if ( sum > longest ) {
667 if ( longest >= max_length ) {
668 setLongestExtNodeInfo( max_length );
671 setLongestExtNodeInfo( longest );
675 final void calculateScaleDistance() {
676 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
679 final double height = getMaxDistanceToRoot();
681 if ( ( height <= 0.5 ) ) {
682 setScaleDistance( 0.01 );
684 else if ( height <= 5.0 ) {
685 setScaleDistance( 0.1 );
687 else if ( height <= 50.0 ) {
688 setScaleDistance( 1 );
690 else if ( height <= 500.0 ) {
691 setScaleDistance( 10 );
694 setScaleDistance( 100 );
698 setScaleDistance( 0.0 );
700 String scale_label = String.valueOf( getScaleDistance() );
701 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
702 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
704 setScaleLabel( scale_label );
707 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
708 if ( getOptions().isColorByTaxonomicGroup() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
712 group = TaxonomyUtil.getTaxGroupByTaxCode( tax.getTaxonomyCode() );
714 catch ( final Exception e ) {
717 if ( !ex && !ForesterUtil.isEmpty( group ) ) {
718 final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group );
723 return getTreeColorSet().getTaxonomyColor();
726 if ( ForesterUtil.isEmpty( tax.getTaxonomyCode() ) && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
727 return getTreeColorSet().getTaxonomyColor();
730 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
731 c = getControlPanel().getSpeciesColors().get( tax.getTaxonomyCode() );
733 if ( ( c == null ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
734 c = getControlPanel().getSpeciesColors().get( tax.getScientificName() );
737 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
738 c = TreePanelUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
739 getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c );
742 c = TreePanelUtil.calculateColorFromString( tax.getScientificName(), true );
743 getControlPanel().getSpeciesColors().put( tax.getScientificName(), c );
750 void checkForVectorProperties( final Phylogeny phy ) {
751 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
752 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
753 final PhylogenyNode node = iter.next();
754 if ( node.getNodeData().getProperties() != null ) {
755 final PropertiesMap pm = node.getNodeData().getProperties();
756 final double[] vector = new double[ pm.getProperties().size() ];
758 for( final String ref : pm.getProperties().keySet() ) {
759 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
760 final Property p = pm.getProperty( ref );
761 final String value_str = p.getValue();
762 final String index_str = ref
763 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
766 d = Double.parseDouble( value_str );
768 catch ( final NumberFormatException e ) {
769 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
770 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
775 i = Integer.parseInt( index_str );
777 catch ( final NumberFormatException e ) {
778 JOptionPane.showMessageDialog( this,
779 "Could not parse \"" + index_str
780 + "\" into index for vector data",
781 "Problem with Vector Data",
782 JOptionPane.ERROR_MESSAGE );
786 JOptionPane.showMessageDialog( this,
787 "Attempt to use negative index for vector data",
788 "Problem with Vector Data",
789 JOptionPane.ERROR_MESSAGE );
797 final List<Double> vector_l = new ArrayList<Double>( counter );
798 for( int i = 0; i < counter; ++i ) {
799 vector_l.add( vector[ i ] );
801 node.getNodeData().setVector( vector_l );
804 if ( stats.getN() > 0 ) {
805 _statistics_for_vector_data = stats;
809 void clearCurrentExternalNodesDataBuffer() {
810 setCurrentExternalNodesDataBuffer( new StringBuilder() );
814 * Collapse the tree from the given node
819 final void collapse( final PhylogenyNode node ) {
820 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
821 JOptionPane.showMessageDialog( this,
822 "Cannot collapse in unrooted display type",
823 "Attempt to collapse in unrooted display",
824 JOptionPane.WARNING_MESSAGE );
827 if ( !node.isExternal() && !node.isRoot() ) {
828 final boolean collapse = !node.isCollapse();
829 TreePanelUtil.collapseSubtree( node, collapse );
830 updateSetOfCollapsedExternalNodes();
831 _phylogeny.recalculateNumberOfExternalDescendants( true );
832 resetNodeIdToDistToLeafMap();
833 calculateLongestExtNodeInfo();
834 setNodeInPreorderToNull();
835 _control_panel.displayedPhylogenyMightHaveChanged( true );
836 resetPreferredSize();
838 _main_panel.adjustJScrollPane();
843 final void collapseSpeciesSpecificSubtrees() {
844 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
848 TreePanelUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
849 updateSetOfCollapsedExternalNodes();
850 _phylogeny.recalculateNumberOfExternalDescendants( true );
851 resetNodeIdToDistToLeafMap();
852 calculateLongestExtNodeInfo();
853 setNodeInPreorderToNull();
854 resetPreferredSize();
855 _main_panel.adjustJScrollPane();
860 final void colorRank( final String rank ) {
861 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
865 AptxUtil.removeBranchColors( _phylogeny );
866 final int colorizations = TreePanelUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
867 if ( colorizations > 0 ) {
868 _control_panel.setColorBranches( true );
869 if ( _control_panel.getColorBranchesCb() != null ) {
870 _control_panel.getColorBranchesCb().setSelected( true );
872 if ( _control_panel.getColorAccSpeciesCb() != null ) {
873 _control_panel.getColorAccSpeciesCb().setSelected( false );
875 _options.setColorLabelsSameAsParentBranch( true );
876 _control_panel.repaint();
880 if ( colorizations > 0 ) {
881 String msg = "Taxonomy colorization via " + rank + " completed:\n";
882 if ( colorizations > 1 ) {
883 msg += "colorized " + colorizations + " subtrees";
886 msg += "colorized one subtree";
889 JOptionPane.showMessageDialog( this,
891 "Taxonomy Colorization Completed (" + rank + ")",
892 JOptionPane.INFORMATION_MESSAGE );
895 String msg = "Could not taxonomy colorize any subtree via " + rank + ".\n";
896 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
897 msg += "select a different rank (e.g. phylum, genus, ...)\n";
900 msg += "1. \"" + MainFrameApplication.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
901 msg += "2. \"" + MainFrameApplication.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
902 JOptionPane.showMessageDialog( this, msg, "Taxonomy Colorization Failed", JOptionPane.WARNING_MESSAGE );
906 final void confColor() {
907 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
911 AptxUtil.removeBranchColors( _phylogeny );
912 TreePanelUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
913 _control_panel.setColorBranches( true );
914 if ( _control_panel.getColorBranchesCb() != null ) {
915 _control_panel.getColorBranchesCb().setSelected( true );
921 final void decreaseDomainStructureEvalueThreshold() {
922 if ( _domain_structure_e_value_thr_exp > -20 ) {
923 _domain_structure_e_value_thr_exp -= 1;
928 * Find the node, if any, at the given location
932 * @return pointer to the node at x,y, null if not found
934 final PhylogenyNode findNode( final int x, final int y ) {
935 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
938 final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE;
939 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
940 final PhylogenyNode node = iter.next();
941 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
942 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
943 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
944 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
945 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
952 final Configuration getConfiguration() {
953 return _configuration;
956 final ControlPanel getControlPanel() {
957 return _control_panel;
960 String getCurrentExternalNodesDataBufferAsString() {
961 return _current_external_nodes_data_buffer.toString();
964 int getCurrentExternalNodesDataBufferChangeCounter() {
965 return _current_external_nodes_data_buffer_change_counter;
968 final int getDomainStructureEvalueThreshold() {
969 return _domain_structure_e_value_thr_exp;
972 final Set<Long> getFoundNodes0() {
973 return _found_nodes_0;
976 final Set<Long> getFoundNodes1() {
977 return _found_nodes_1;
980 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
981 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
982 return ( PhylogenyMethods.getBranchColorValue( node ) );
985 return ( getTreeColorSet().getBranchColor() );
989 final int getLongestExtNodeInfo() {
990 return _longest_ext_node_info;
993 final Options getOptions() {
994 if ( _options == null ) {
995 _options = getControlPanel().getOptions();
1000 final Rectangle2D getOvRectangle() {
1001 return _ov_rectangle;
1004 final Rectangle getOvVirtualRectangle() {
1005 return _ov_virtual_rectangle;
1008 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
1009 return _graphics_type;
1012 final double getStartingAngle() {
1013 return _urt_starting_angle;
1016 DescriptiveStatistics getStatisticsForExpressionValues() {
1017 return _statistics_for_vector_data;
1021 * Find a color for this species name.
1024 * @return the species color
1026 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
1027 if ( node.getNodeData().isHasTaxonomy() ) {
1028 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
1030 // return non-colorized color
1031 return getTreeColorSet().getTaxonomyColor();
1035 * @return pointer to colorset for tree drawing
1037 final TreeColorSet getTreeColorSet() {
1038 return getMainPanel().getTreeColorSet();
1041 final File getTreeFile() {
1045 final float getXcorrectionFactor() {
1046 return _x_correction_factor;
1049 final float getXdistance() {
1053 final float getYdistance() {
1057 final void increaseDomainStructureEvalueThreshold() {
1058 if ( _domain_structure_e_value_thr_exp < 3 ) {
1059 _domain_structure_e_value_thr_exp += 1;
1063 final void initNodeData() {
1064 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1067 double max_original_domain_structure_width = 0.0;
1068 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1069 if ( node.getNodeData().isHasSequence()
1070 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1071 RenderableDomainArchitecture rds = null;
1072 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
1073 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
1074 getConfiguration() );
1075 node.getNodeData().getSequence().setDomainArchitecture( rds );
1078 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1080 if ( getControlPanel().isShowDomainArchitectures() ) {
1081 final double dsw = rds.getOriginalSize().getWidth();
1082 if ( dsw > max_original_domain_structure_width ) {
1083 max_original_domain_structure_width = dsw;
1088 if ( getControlPanel().isShowDomainArchitectures() ) {
1089 final double ds_factor_width = _domain_structure_width / max_original_domain_structure_width;
1090 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1091 if ( node.getNodeData().isHasSequence()
1092 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1093 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1094 .getSequence().getDomainArchitecture();
1095 rds.setRenderingFactorWidth( ds_factor_width );
1096 rds.setParameter( _domain_structure_e_value_thr_exp );
1102 final boolean inOv( final MouseEvent e ) {
1103 return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) )
1104 && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) )
1105 && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) ) && ( e.getY() < ( ( getVisibleRect().y
1106 + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) );
1109 final boolean inOvRectangle( final MouseEvent e ) {
1110 return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) )
1111 && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) )
1112 && ( e.getY() >= ( getOvRectangle().getY() - 1 ) ) && ( e.getY() <= ( getOvRectangle().getY()
1113 + getOvRectangle().getHeight() + 1 ) ) );
1116 final boolean isApplet() {
1117 return getMainPanel() instanceof MainPanelApplets;
1120 final boolean isCanCollapse() {
1121 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1124 final boolean isCanColorSubtree() {
1125 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1128 final boolean isCanCopy() {
1129 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1132 final boolean isCanCut( final PhylogenyNode node ) {
1133 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1137 final boolean isCanDelete() {
1138 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1141 final boolean isCanPaste() {
1142 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1143 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1146 final boolean isCanReroot() {
1147 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1150 final boolean isCanSubtree( final PhylogenyNode node ) {
1151 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1152 .isRoot() || ( _subtree_index > 0 ) ) );
1155 final boolean isCurrentTreeIsSubtree() {
1156 return ( _subtree_index > 0 );
1159 final boolean isEdited() {
1163 final boolean isInOvRect() {
1167 final boolean isOvOn() {
1171 final boolean isPhyHasBranchLengths() {
1172 return _phy_has_branch_lengths;
1175 final void midpointRoot() {
1176 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1179 if ( !_phylogeny.isRerootable() ) {
1180 JOptionPane.showMessageDialog( this,
1181 "This is not rerootable",
1183 JOptionPane.WARNING_MESSAGE );
1186 setNodeInPreorderToNull();
1188 PhylogenyMethods.midpointRoot( _phylogeny );
1189 resetNodeIdToDistToLeafMap();
1195 final void mouseClicked( final MouseEvent e ) {
1196 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1197 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1198 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1199 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) )
1201 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) )
1209 final double max_x = getWidth() - getVisibleRect().width;
1210 final double max_y = getHeight() - getVisibleRect().height;
1217 getMainPanel().getCurrentScrollPane().getViewport()
1218 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1219 setInOvRect( true );
1223 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1224 if ( node != null ) {
1225 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1228 _highlight_node = node;
1229 // Check if shift key is down
1230 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1231 // Yes, so add to _found_nodes
1232 if ( getFoundNodes0() == null ) {
1233 setFoundNodes0( new HashSet<Long>() );
1235 getFoundNodes0().add( node.getId() );
1236 // Check if control key is down
1238 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1239 // Yes, so pop-up menu
1240 displayNodePopupMenu( node, e.getX(), e.getY() );
1241 // Handle unadorned click
1244 // Check for right mouse button
1245 if ( e.getModifiers() == 4 ) {
1246 displayNodePopupMenu( node, e.getX(), e.getY() );
1249 // if not in _found_nodes, clear _found_nodes
1250 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1255 // no node was clicked
1256 _highlight_node = null;
1262 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1263 setCursor( MOVE_CURSOR );
1264 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1265 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1266 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1267 if ( scroll_position.x < 0 ) {
1268 scroll_position.x = 0;
1271 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1272 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1273 if ( scroll_position.x > max_x ) {
1274 scroll_position.x = max_x;
1277 if ( scroll_position.y < 0 ) {
1278 scroll_position.y = 0;
1281 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1282 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1283 if ( scroll_position.y > max_y ) {
1284 scroll_position.y = max_y;
1287 if ( isOvOn() || getOptions().isShowScale() ) {
1290 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1293 final void mouseDragInOvRectangle( final MouseEvent e ) {
1294 setCursor( HAND_CURSOR );
1295 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1296 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1297 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1298 double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) );
1299 double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) );
1300 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1301 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1302 if ( scroll_position.x <= 0 ) {
1303 scroll_position.x = 0;
1307 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1308 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1309 if ( scroll_position.x >= max_x ) {
1311 scroll_position.x = max_x;
1314 if ( scroll_position.y <= 0 ) {
1316 scroll_position.y = 0;
1319 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1320 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1321 if ( scroll_position.y >= max_y ) {
1323 scroll_position.y = max_y;
1327 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1328 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1329 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1332 final void mouseMoved( final MouseEvent e ) {
1333 requestFocusInWindow();
1334 if ( _current_external_nodes != null ) {
1335 _current_external_nodes = null;
1338 if ( getControlPanel().isNodeDescPopup() ) {
1339 if ( _node_desc_popup != null ) {
1340 _node_desc_popup.hide();
1341 _node_desc_popup = null;
1344 if ( getOptions().isShowOverview() && isOvOn() ) {
1345 if ( inOvVirtualRectangle( e ) ) {
1346 if ( !isInOvRect() ) {
1347 setInOvRect( true );
1352 if ( isInOvRect() ) {
1353 setInOvRect( false );
1358 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
1367 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1368 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
1369 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.GET_EXT_DESC_DATA ) ) {
1370 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
1371 addToCurrentExternalNodes( n.getId() );
1373 setCursor( HAND_CURSOR );
1376 else if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
1377 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
1378 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
1379 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
1380 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
1381 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
1382 setCursor( CUT_CURSOR );
1385 setCursor( HAND_CURSOR );
1386 if ( getControlPanel().isNodeDescPopup() ) {
1387 showNodeDataPopup( e, node );
1392 setCursor( ARROW_CURSOR );
1397 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
1398 setCursor( ARROW_CURSOR );
1401 final void multiplyUrtFactor( final float f ) {
1405 final JApplet obtainApplet() {
1406 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1409 final void paintBranchCircular( final PhylogenyNode p,
1410 final PhylogenyNode c,
1412 final boolean radial_labels,
1413 final boolean to_pdf,
1414 final boolean to_graphics_file ) {
1415 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1416 final double root_x = _root.getXcoord();
1417 final double root_y = _root.getYcoord();
1418 final double dx = root_x - p.getXcoord();
1419 final double dy = root_y - p.getYcoord();
1420 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1421 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1422 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
1423 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
1424 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
1425 final double r2 = 2.0 * parent_radius;
1426 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1428 drawLine( c.getXcoord(),
1430 root_x + ( Math.cos( angle ) * parent_radius ),
1431 root_y + ( Math.sin( angle ) * parent_radius ),
1433 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file );
1434 if ( c.isExternal() ) {
1435 final boolean is_in_found_nodes = isInFoundNodes0( c ) || isInFoundNodes1( c ) || isInCurrentExternalNodes( c );
1436 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
1437 && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
1440 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
1444 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
1445 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1446 final double root_x = _root.getXSecondary();
1447 final double root_y = _root.getYSecondary();
1448 final double dx = root_x - p.getXSecondary();
1449 final double dy = root_y - p.getYSecondary();
1450 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1451 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1452 g.setColor( getTreeColorSet().getOvColor() );
1453 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
1454 final double r2 = 2.0 * parent_radius;
1455 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1457 drawLine( c.getXSecondary(),
1459 root_x + ( Math.cos( angle ) * parent_radius ),
1460 root_y + ( Math.sin( angle ) * parent_radius ),
1462 if ( ( isInFoundNodes0( c ) && !isInFoundNodes1( c ) ) || isInCurrentExternalNodes( c ) ) {
1463 g.setColor( getTreeColorSet().getFoundColor0() );
1464 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
1466 else if ( ( isInFoundNodes1( c ) && !isInFoundNodes0( c ) ) ) {
1467 g.setColor( getTreeColorSet().getFoundColor1() );
1468 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
1470 else if ( isInFoundNodes0( c ) && isInFoundNodes1( c ) ) {
1471 g.setColor( getTreeColorSet().getFoundColor0and1() );
1472 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
1476 final void paintCircular( final Phylogeny phy,
1477 final double starting_angle,
1482 final boolean to_pdf,
1483 final boolean to_graphics_file ) {
1484 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
1485 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
1486 _root = phy.getRoot();
1487 _root.setXcoord( center_x );
1488 _root.setYcoord( center_y );
1489 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1490 double current_angle = starting_angle;
1492 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1493 final PhylogenyNode n = it.next();
1494 if ( !n.isCollapse() ) {
1495 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1496 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1497 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1498 _urt_nodeid_index_map.put( n.getId(), i++ );
1499 current_angle += ( TWO_PI / circ_num_ext_nodes );
1503 System.out.println( "is collapse" + n.getName() );
1506 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
1507 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file );
1510 private boolean isInFoundNodes( PhylogenyNode n ) {
1511 return isInFoundNodes0( n ) || isInFoundNodes1( n );
1514 final void paintCircularLite( final Phylogeny phy,
1515 final double starting_angle,
1519 final Graphics2D g ) {
1520 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
1521 _root = phy.getRoot();
1522 _root.setXSecondary( center_x );
1523 _root.setYSecondary( center_y );
1524 double current_angle = starting_angle;
1525 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1526 final PhylogenyNode n = it.next();
1527 n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1528 n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1529 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1530 current_angle += ( TWO_PI / circ_num_ext_nodes );
1532 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
1535 final void paintPhylogeny( final Graphics2D g,
1536 final boolean to_pdf,
1537 final boolean to_graphics_file,
1538 final int graphics_file_width,
1539 final int graphics_file_height,
1540 final int graphics_file_x,
1541 final int graphics_file_y ) {
1542 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1545 if ( _control_panel.isShowSequenceRelations() ) {
1546 _query_sequence = _control_panel.getSelectedQuerySequence();
1548 // Color the background
1550 final Rectangle r = getVisibleRect();
1551 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
1552 g.setColor( getTreeColorSet().getBackgroundColor() );
1553 if ( !to_graphics_file ) {
1557 if ( getOptions().isPrintBlackAndWhite() ) {
1558 g.setColor( Color.WHITE );
1560 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1564 if ( !to_graphics_file ) {
1565 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
1566 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
1570 g.setPaint( new GradientPaint( graphics_file_x,
1572 getTreeColorSet().getBackgroundColor(),
1574 graphics_file_y + graphics_file_height,
1575 getTreeColorSet().getBackgroundColorGradientBottom() ) );
1576 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1582 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
1584 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1585 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1586 _external_node_index = 0;
1587 // Position starting X of tree
1588 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
1589 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
1591 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
1592 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
1593 .getDistanceToParent() * getXcorrectionFactor() ) ) );
1596 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
1598 // Position starting Y of tree
1599 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
1600 + ( TreePanel.MOVE / 2.0f ) );
1601 final int dynamic_hiding_factor = calcDynamicHidingFactor();
1602 if ( getControlPanel().isDynamicallyHideData() ) {
1603 if ( dynamic_hiding_factor > 1 ) {
1604 getControlPanel().setDynamicHidingIsOn( true );
1607 getControlPanel().setDynamicHidingIsOn( false );
1610 if ( _nodes_in_preorder == null ) {
1611 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
1613 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1614 _nodes_in_preorder[ i++ ] = it.next();
1617 //final PhylogenyNodeIterator it;
1618 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1619 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
1620 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1622 for( final PhylogenyNode element : _nodes_in_preorder ) {
1623 paintNodeRectangular( g, element, to_pdf, getControlPanel().isDynamicallyHideData()
1624 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1626 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
1627 if ( !( to_graphics_file || to_pdf ) ) {
1630 getVisibleRect().y + getVisibleRect().height,
1635 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1638 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1639 paintPhylogenyLite( g );
1642 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1643 if ( getControlPanel().getDynamicallyHideData() != null ) {
1644 getControlPanel().setDynamicHidingIsOn( false );
1646 final double angle = getStartingAngle();
1647 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1648 _dynamic_hiding_factor = 0;
1649 if ( getControlPanel().isDynamicallyHideData() ) {
1650 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
1651 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
1653 if ( getControlPanel().getDynamicallyHideData() != null ) {
1654 if ( _dynamic_hiding_factor > 1 ) {
1655 getControlPanel().setDynamicHidingIsOn( true );
1658 getControlPanel().setDynamicHidingIsOn( false );
1661 paintUnrooted( _phylogeny.getRoot(),
1663 ( float ) ( angle + ( 2 * Math.PI ) ),
1668 if ( getOptions().isShowScale() ) {
1669 if ( !( to_graphics_file || to_pdf ) ) {
1672 getVisibleRect().y + getVisibleRect().height,
1677 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1680 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1681 g.setColor( getTreeColorSet().getOvColor() );
1682 paintUnrootedLite( _phylogeny.getRoot(),
1684 angle + ( 2 * Math.PI ),
1686 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
1687 paintOvRectangle( g );
1690 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1691 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
1692 final int d = radius + MOVE + getLongestExtNodeInfo();
1693 _dynamic_hiding_factor = 0;
1694 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
1695 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
1696 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
1698 if ( getControlPanel().getDynamicallyHideData() != null ) {
1699 if ( _dynamic_hiding_factor > 1 ) {
1700 getControlPanel().setDynamicHidingIsOn( true );
1703 getControlPanel().setDynamicHidingIsOn( false );
1706 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
1707 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1708 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
1709 : getOvMaxWidth() / 2 );
1710 double x_scale = 1.0;
1711 double y_scale = 1.0;
1712 int x_pos = getVisibleRect().x + getOvXPosition();
1713 int y_pos = getVisibleRect().y + getOvYPosition();
1714 if ( getWidth() > getHeight() ) {
1715 x_scale = ( double ) getHeight() / getWidth();
1716 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
1719 y_scale = ( double ) getWidth() / getHeight();
1720 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
1722 _at = g.getTransform();
1723 g.scale( x_scale, y_scale );
1724 paintCircularLite( _phylogeny,
1728 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
1731 g.setTransform( _at );
1732 paintOvRectangle( g );
1737 final void recalculateMaxDistanceToRoot() {
1738 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
1742 * Remove all edit-node frames
1744 final void removeAllEditNodeJFrames() {
1745 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
1746 if ( _node_frames[ i ] != null ) {
1747 _node_frames[ i ].dispose();
1748 _node_frames[ i ] = null;
1751 _node_frame_index = 0;
1755 * Remove a node-edit frame.
1757 final void removeEditNodeFrame( final int i ) {
1758 _node_frame_index--;
1759 _node_frames[ i ] = null;
1760 if ( i < _node_frame_index ) {
1761 for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) {
1762 _node_frames[ j ] = _node_frames[ j + 1 ];
1764 _node_frames[ _node_frame_index ] = null;
1768 final void reRoot( final PhylogenyNode node ) {
1769 if ( !getPhylogeny().isRerootable() ) {
1770 JOptionPane.showMessageDialog( this,
1771 "This is not rerootable",
1773 JOptionPane.WARNING_MESSAGE );
1776 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1777 JOptionPane.showMessageDialog( this,
1778 "Cannot reroot in unrooted display type",
1779 "Attempt to reroot tree in unrooted display",
1780 JOptionPane.WARNING_MESSAGE );
1783 getPhylogeny().reRoot( node );
1784 getPhylogeny().recalculateNumberOfExternalDescendants( true );
1785 resetNodeIdToDistToLeafMap();
1786 setNodeInPreorderToNull();
1787 resetPreferredSize();
1788 getMainPanel().adjustJScrollPane();
1791 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1792 getControlPanel().showWhole();
1796 final void resetNodeIdToDistToLeafMap() {
1797 _nodeid_dist_to_leaf = new HashMap<Long, Short>();
1800 final void resetPreferredSize() {
1801 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
1807 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
1808 if ( getControlPanel().isDrawPhylogram() ) {
1810 + getLongestExtNodeInfo()
1812 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
1815 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
1817 + getLongestExtNodeInfo()
1818 + ForesterUtil.roundToInt( getXdistance()
1819 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
1823 + getLongestExtNodeInfo()
1824 + ForesterUtil.roundToInt( getXdistance()
1825 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
1828 setPreferredSize( new Dimension( x, y ) );
1831 final void selectNode( final PhylogenyNode node ) {
1832 if ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) ) {
1833 getFoundNodes0().remove( node.getId() );
1834 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
1835 if ( getFoundNodes0().size() < 1 ) {
1836 getControlPanel().searchReset0();
1840 getControlPanel().getSearchFoundCountsLabel0().setVisible( true );
1841 getControlPanel().getSearchResetButton0().setEnabled( true );
1842 getControlPanel().getSearchResetButton0().setVisible( true );
1843 if ( getFoundNodes0() == null ) {
1844 setFoundNodes0( new HashSet<Long>() );
1846 getFoundNodes0().add( node.getId() );
1847 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
1851 final void setArrowCursor() {
1852 setCursor( ARROW_CURSOR );
1856 final void setControlPanel( final ControlPanel atv_control ) {
1857 _control_panel = atv_control;
1860 void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
1861 increaseCurrentExternalNodesDataBufferChangeCounter();
1862 _current_external_nodes_data_buffer = sb;
1865 final void setFoundNodes0( final Set<Long> found_nodes ) {
1866 _found_nodes_0 = found_nodes;
1869 final void setFoundNodes1( final Set<Long> found_nodes ) {
1870 _found_nodes_1 = found_nodes;
1873 final void setInOvRect( final boolean in_ov_rect ) {
1874 _in_ov_rect = in_ov_rect;
1877 final void setLargeFonts() {
1878 getTreeFontSet().largeFonts();
1881 final void setLastMouseDragPointX( final float x ) {
1882 _last_drag_point_x = x;
1885 final void setLastMouseDragPointY( final float y ) {
1886 _last_drag_point_y = y;
1889 final void setLongestExtNodeInfo( final int i ) {
1890 _longest_ext_node_info = i;
1893 final void setMediumFonts() {
1894 getTreeFontSet().mediumFonts();
1897 final void setNodeInPreorderToNull() {
1898 _nodes_in_preorder = null;
1901 final void setOvOn( final boolean ov_on ) {
1905 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
1906 _graphics_type = graphics_type;
1910 final void setSmallFonts() {
1911 getTreeFontSet().smallFonts();
1914 final void setStartingAngle( final double starting_angle ) {
1915 _urt_starting_angle = starting_angle;
1918 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
1919 _statistics_for_vector_data = statistics_for_expression_values;
1922 final void setSuperTinyFonts() {
1923 getTreeFontSet().superTinyFonts();
1926 final void setTextAntialias() {
1927 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
1928 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
1929 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
1932 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
1935 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
1936 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
1938 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
1940 // catch ( final Throwable e ) {
1941 // _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
1945 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
1946 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1950 final void setTinyFonts() {
1951 getTreeFontSet().tinyFonts();
1954 final void setTreeFile( final File treefile ) {
1955 _treefile = treefile;
1958 final void setXcorrectionFactor( final float f ) {
1959 _x_correction_factor = f;
1962 final void setXdistance( final float x ) {
1966 final void setYdistance( final float y ) {
1970 final void sortDescendants( final PhylogenyNode node ) {
1971 if ( !node.isExternal() ) {
1972 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
1973 if ( ( !getControlPanel().isShowTaxonomyScientificNames() && !getControlPanel().isShowTaxonomyCode() && !getControlPanel()
1974 .isShowTaxonomyCommonNames() ) ) {
1975 if ( ( getControlPanel().isShowSequenceAcc() || getControlPanel().isShowSeqNames() || getControlPanel()
1976 .isShowSeqSymbols() ) ) {
1977 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
1979 else if ( getControlPanel().isShowNodeNames() ) {
1980 pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
1983 PhylogenyMethods.sortNodeDescendents( node, pri );
1984 setNodeInPreorderToNull();
1985 _phylogeny.externalNodesHaveChanged();
1986 _phylogeny.clearHashIdToNodeMap();
1987 _phylogeny.recalculateNumberOfExternalDescendants( true );
1988 resetNodeIdToDistToLeafMap();
1994 final void subTree( final PhylogenyNode node ) {
1995 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1996 JOptionPane.showMessageDialog( this,
1997 "Cannot get a sub/super tree in unrooted display",
1998 "Attempt to get sub/super tree in unrooted display",
1999 JOptionPane.WARNING_MESSAGE );
2002 if ( node.isExternal() ) {
2003 JOptionPane.showMessageDialog( this,
2004 "Cannot get a subtree of a external node",
2005 "Attempt to get subtree of external node",
2006 JOptionPane.WARNING_MESSAGE );
2009 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
2010 JOptionPane.showMessageDialog( this,
2011 "Cannot get a subtree of the root node",
2012 "Attempt to get subtree of root node",
2013 JOptionPane.WARNING_MESSAGE );
2016 setNodeInPreorderToNull();
2017 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
2018 _sub_phylogenies[ _subtree_index ] = _phylogeny;
2019 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
2021 _phylogeny = TreePanelUtil.subTree( node, _phylogeny );
2022 updateSubSuperTreeButton();
2024 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
2027 _main_panel.getControlPanel().showWhole();
2031 final void superTree() {
2032 setNodeInPreorderToNull();
2033 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
2034 for( final PhylogenyNode n : temp_root.getDescendants() ) {
2035 n.setParent( temp_root );
2037 _sub_phylogenies[ _subtree_index ] = null;
2038 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
2039 _phylogeny = _sub_phylogenies[ --_subtree_index ];
2040 updateSubSuperTreeButton();
2043 final void swap( final PhylogenyNode node ) {
2044 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
2047 if ( node.getNumberOfDescendants() > 2 ) {
2048 JOptionPane.showMessageDialog( this,
2049 "Cannot swap descendants of nodes with more than 2 descendants",
2050 "Cannot swap descendants",
2051 JOptionPane.ERROR_MESSAGE );
2054 if ( !node.isExternal() ) {
2055 node.swapChildren();
2056 setNodeInPreorderToNull();
2057 _phylogeny.externalNodesHaveChanged();
2058 _phylogeny.clearHashIdToNodeMap();
2059 _phylogeny.recalculateNumberOfExternalDescendants( true );
2060 resetNodeIdToDistToLeafMap();
2066 final void taxColor() {
2067 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
2071 TreePanelUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
2072 _control_panel.setColorBranches( true );
2073 if ( _control_panel.getColorBranchesCb() != null ) {
2074 _control_panel.getColorBranchesCb().setSelected( true );
2081 final void updateOvSettings() {
2082 switch ( getOptions().getOvPlacement() ) {
2084 setOvXPosition( OV_BORDER );
2085 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
2086 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
2089 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
2090 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
2091 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
2094 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
2095 setOvYPosition( OV_BORDER );
2096 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2099 setOvXPosition( OV_BORDER );
2100 setOvYPosition( OV_BORDER );
2101 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2106 final void updateOvSizes() {
2107 if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) ) || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) {
2109 float l = getLongestExtNodeInfo();
2110 final float w_ratio = getOvMaxWidth() / getWidth();
2112 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
2113 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
2115 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
2116 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
2119 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
2121 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
2122 if ( ov_xdist < 0.0 ) {
2125 if ( ydist < 0.0 ) {
2128 setOvXDistance( ov_xdist );
2129 final double height = _phylogeny.getHeight();
2131 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
2132 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
2135 setOvXcorrectionFactor( 0 );
2143 void updateSetOfCollapsedExternalNodes() {
2144 final Phylogeny phy = getPhylogeny();
2145 _collapsed_external_nodeid_set.clear();
2146 if ( phy != null ) {
2147 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2148 final PhylogenyNode ext_node = it.next();
2149 PhylogenyNode n = ext_node;
2150 while ( !n.isRoot() ) {
2151 if ( n.isCollapse() ) {
2152 _collapsed_external_nodeid_set.add( ext_node.getId() );
2153 ext_node.setCollapse( true );
2162 final void updateSubSuperTreeButton() {
2163 if ( _subtree_index < 1 ) {
2164 getControlPanel().deactivateButtonToReturnToSuperTree();
2167 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
2171 final void zoomInDomainStructure() {
2172 if ( _domain_structure_width < 2000 ) {
2173 _domain_structure_width *= 1.2;
2177 final void zoomOutDomainStructure() {
2178 if ( _domain_structure_width > 20 ) {
2179 _domain_structure_width *= 0.8;
2183 private void abbreviateScientificName( final String sn ) {
2184 final String[] a = sn.split( "\\s+" );
2185 _sb.append( a[ 0 ].substring( 0, 1 ) );
2186 _sb.append( a[ 1 ].substring( 0, 2 ) );
2187 if ( a.length > 2 ) {
2188 for( int i = 2; i < a.length; i++ ) {
2190 _sb.append( a[ i ] );
2195 final private void addEmptyNode( final PhylogenyNode node ) {
2196 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2197 errorMessageNoCutCopyPasteInUnrootedDisplay();
2200 final String label = createASimpleTextRepresentationOfANode( node );
2202 if ( ForesterUtil.isEmpty( label ) ) {
2203 msg = "How to add the new, empty node?";
2206 msg = "How to add the new, empty node to node" + label + "?";
2208 final Object[] options = { "As sibling", "As descendant", "Cancel" };
2209 final int r = JOptionPane.showOptionDialog( this,
2211 "Addition of Empty New Node",
2212 JOptionPane.CLOSED_OPTION,
2213 JOptionPane.QUESTION_MESSAGE,
2217 boolean add_as_sibling = true;
2219 add_as_sibling = false;
2221 else if ( r != 0 ) {
2224 final Phylogeny phy = new Phylogeny();
2225 phy.setRoot( new PhylogenyNode() );
2226 phy.setRooted( true );
2227 if ( add_as_sibling ) {
2228 if ( node.isRoot() ) {
2229 JOptionPane.showMessageDialog( this,
2230 "Cannot add sibling to root",
2231 "Attempt to add sibling to root",
2232 JOptionPane.ERROR_MESSAGE );
2235 phy.addAsSibling( node );
2238 phy.addAsChild( node );
2240 setNodeInPreorderToNull();
2241 _phylogeny.externalNodesHaveChanged();
2242 _phylogeny.clearHashIdToNodeMap();
2243 _phylogeny.recalculateNumberOfExternalDescendants( true );
2244 resetNodeIdToDistToLeafMap();
2249 final private void addToCurrentExternalNodes( final long i ) {
2250 if ( _current_external_nodes == null ) {
2251 _current_external_nodes = new HashSet<Long>();
2253 _current_external_nodes.add( i );
2256 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
2257 final boolean is_vertical,
2259 final boolean to_pdf,
2260 final boolean to_graphics_file ) {
2261 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
2262 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2263 g.setColor( Color.BLACK );
2265 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
2266 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
2267 && ( getCutOrCopiedTree() != null )
2268 && ( getCopiedAndPastedNodes() != null )
2270 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
2271 g.setColor( getTreeColorSet().getFoundColor0() );
2273 else if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2274 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2276 else if ( to_pdf ) {
2277 g.setColor( getTreeColorSet().getBranchColorForPdf() );
2280 g.setColor( getTreeColorSet().getBranchColor() );
2284 final private void blast( final PhylogenyNode node ) {
2285 if ( !isCanBlast( node ) ) {
2286 JOptionPane.showMessageDialog( this,
2287 "Insufficient information present",
2289 JOptionPane.INFORMATION_MESSAGE );
2293 final String query = Blast.obtainQueryForBlast( node );
2294 System.out.println( "query for BLAST is: " + query );
2296 if ( !ForesterUtil.isEmpty( query ) ) {
2297 if ( node.getNodeData().isHasSequence() ) {
2298 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
2299 if ( node.getNodeData().getSequence().getType().toLowerCase()
2300 .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
2307 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2308 if ( ForesterUtil.seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2316 if ( type == '?' ) {
2317 if ( SequenceAccessionTools.isProteinDbQuery( query ) ) {
2324 JApplet applet = null;
2326 applet = obtainApplet();
2329 Blast.openNcbiBlastWeb( query, type == 'n', applet, this );
2331 catch ( final Exception e ) {
2332 e.printStackTrace();
2334 if ( Constants.ALLOW_DDBJ_BLAST ) {
2336 System.out.println( "trying: " + query );
2337 final Blast s = new Blast();
2338 s.ddbjBlast( query );
2340 catch ( final Exception e ) {
2341 e.printStackTrace();
2348 private final int calcDynamicHidingFactor() {
2349 return ( int ) ( 0.5 + ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) ) );
2353 * Calculate the length of the distance between the given node and its
2359 * @return the distance value
2361 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
2362 if ( getControlPanel().isDrawPhylogram() ) {
2363 if ( node.getDistanceToParent() < 0.0 ) {
2366 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
2369 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2370 return getXdistance();
2372 return getXdistance() * factor;
2376 final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
2377 Color c = getTreeColorSet().getAnnotationColor();
2378 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
2379 final StringBuilder sb = new StringBuilder();
2380 for( final Annotation a : ann ) {
2381 sb.append( !ForesterUtil.isEmpty( a.getRefValue() ) ? a.getRefValue() : a.getDesc() );
2383 final String ann_str = sb.toString();
2384 if ( !ForesterUtil.isEmpty( ann_str ) ) {
2385 c = getControlPanel().getAnnotationColors().get( ann_str );
2387 c = TreePanelUtil.calculateColorFromString( ann_str, false );
2388 getControlPanel().getAnnotationColors().put( ann_str, c );
2391 c = getTreeColorSet().getAnnotationColor();
2398 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
2399 if ( getControlPanel().isDrawPhylogram() ) {
2400 if ( node.getDistanceToParent() < 0.0 ) {
2403 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
2406 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2407 return getOvXDistance();
2409 return getOvXDistance() * factor;
2413 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
2414 JOptionPane.showMessageDialog( this,
2415 "Cannot launch web browser for " + type_type + " data of this node",
2416 "Cannot launch web browser",
2417 JOptionPane.WARNING_MESSAGE );
2420 final private void colorizeSubtree( final Color c,
2421 final PhylogenyNode node,
2422 final List<PhylogenyNode> additional_nodes ) {
2423 _control_panel.setColorBranches( true );
2424 if ( _control_panel.getColorBranchesCb() != null ) {
2425 _control_panel.getColorBranchesCb().setSelected( true );
2427 if ( node != null ) {
2428 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
2429 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
2432 if ( additional_nodes != null ) {
2433 for( final PhylogenyNode n : additional_nodes ) {
2434 n.getBranchData().setBranchColor( new BranchColor( c ) );
2440 final private void colorSubtree( final PhylogenyNode node ) {
2441 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2442 JOptionPane.showMessageDialog( this,
2443 "Cannot colorize subtree in unrooted display type",
2444 "Attempt to colorize subtree in unrooted display",
2445 JOptionPane.WARNING_MESSAGE );
2448 _color_chooser.setPreviewPanel( new JPanel() );
2449 SubtreeColorizationActionListener al;
2450 if ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() ) {
2451 final List<PhylogenyNode> additional_nodes = getFoundNodes0AsListOfPhylogenyNodes();
2452 al = new SubtreeColorizationActionListener( _color_chooser, node, additional_nodes );
2455 al = new SubtreeColorizationActionListener( _color_chooser, node );
2457 final JDialog dialog = JColorChooser
2458 .createDialog( this, "Subtree colorization", true, _color_chooser, al, null );
2459 dialog.setVisible( true );
2462 private List<PhylogenyNode> getFoundNodes0AsListOfPhylogenyNodes() {
2463 final List<PhylogenyNode> additional_nodes = new ArrayList<PhylogenyNode>();
2464 for( final Long id : getFoundNodes0() ) {
2465 additional_nodes.add( _phylogeny.getNode( id ) );
2467 return additional_nodes;
2470 private List<PhylogenyNode> getFoundNodes1AsListOfPhylogenyNodes() {
2471 final List<PhylogenyNode> additional_nodes = new ArrayList<PhylogenyNode>();
2472 for( final Long id : getFoundNodes1() ) {
2473 additional_nodes.add( _phylogeny.getNode( id ) );
2475 return additional_nodes;
2478 final private void copySubtree( final PhylogenyNode node ) {
2479 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2480 errorMessageNoCutCopyPasteInUnrootedDisplay();
2483 setNodeInPreorderToNull();
2484 setCutOrCopiedTree( _phylogeny.copy( node ) );
2485 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
2486 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
2487 for( final PhylogenyNode n : nodes ) {
2488 node_ids.add( n.getId() );
2490 node_ids.add( node.getId() );
2491 setCopiedAndPastedNodes( node_ids );
2495 final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
2496 final String tax = PhylogenyMethods.getSpecies( node );
2497 String label = node.getName();
2498 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
2499 label = label + " " + tax;
2501 else if ( !ForesterUtil.isEmpty( tax ) ) {
2507 if ( !ForesterUtil.isEmpty( label ) ) {
2508 label = " [" + label + "]";
2513 final private void cutSubtree( final PhylogenyNode node ) {
2514 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2515 errorMessageNoCutCopyPasteInUnrootedDisplay();
2518 if ( node.isRoot() ) {
2519 JOptionPane.showMessageDialog( this,
2520 "Cannot cut entire tree as subtree",
2521 "Attempt to cut entire tree",
2522 JOptionPane.ERROR_MESSAGE );
2525 final String label = createASimpleTextRepresentationOfANode( node );
2526 final int r = JOptionPane.showConfirmDialog( null,
2527 "Cut subtree" + label + "?",
2528 "Confirm Cutting of Subtree",
2529 JOptionPane.YES_NO_OPTION );
2530 if ( r != JOptionPane.OK_OPTION ) {
2533 setNodeInPreorderToNull();
2534 setCopiedAndPastedNodes( null );
2535 setCutOrCopiedTree( _phylogeny.copy( node ) );
2536 _phylogeny.deleteSubtree( node, true );
2537 _phylogeny.clearHashIdToNodeMap();
2538 _phylogeny.recalculateNumberOfExternalDescendants( true );
2539 resetNodeIdToDistToLeafMap();
2544 final private void cycleColors() {
2545 getMainPanel().getTreeColorSet().cycleColorScheme();
2546 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
2547 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
2551 final private void decreaseOvSize() {
2552 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
2553 setOvMaxWidth( getOvMaxWidth() - 5 );
2554 setOvMaxHeight( getOvMaxHeight() - 5 );
2556 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2560 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
2561 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2562 errorMessageNoCutCopyPasteInUnrootedDisplay();
2565 if ( node.isRoot() && ( node.getNumberOfDescendants() != 1 ) ) {
2566 JOptionPane.showMessageDialog( this,
2567 "Cannot delete entire tree",
2568 "Attempt to delete entire tree",
2569 JOptionPane.ERROR_MESSAGE );
2572 final String label = createASimpleTextRepresentationOfANode( node );
2573 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
2574 final int r = JOptionPane.showOptionDialog( this,
2575 "Delete" + label + "?",
2576 "Delete Node/Subtree",
2577 JOptionPane.CLOSED_OPTION,
2578 JOptionPane.QUESTION_MESSAGE,
2582 setNodeInPreorderToNull();
2583 boolean node_only = true;
2587 else if ( r != 0 ) {
2591 PhylogenyMethods.removeNode( node, _phylogeny );
2594 _phylogeny.deleteSubtree( node, true );
2596 _phylogeny.externalNodesHaveChanged();
2597 _phylogeny.clearHashIdToNodeMap();
2598 _phylogeny.recalculateNumberOfExternalDescendants( true );
2599 resetNodeIdToDistToLeafMap();
2604 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
2605 makePopupMenus( node );
2606 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
2607 _node_popup_menu.show( this, x, y );
2610 final private void drawArc( final double x,
2613 final double heigth,
2614 final double start_angle,
2615 final double arc_angle,
2616 final Graphics2D g ) {
2617 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
2621 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
2622 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
2625 _line.setLine( x1, y1, x2, y2 );
2629 final private void drawOval( final double x,
2632 final double heigth,
2633 final Graphics2D g ) {
2634 _ellipse.setFrame( x, y, width, heigth );
2638 final private void drawOvalFilled( final double x,
2641 final double heigth,
2642 final Graphics2D g ) {
2643 _ellipse.setFrame( x, y, width, heigth );
2647 final private void drawOvalGradient( final double x,
2650 final double heigth,
2652 final Color color_1,
2653 final Color color_2,
2654 final Color color_border ) {
2655 _ellipse.setFrame( x, y, width, heigth );
2656 g.setPaint( new GradientPaint( ( float ) x,
2659 ( float ) ( x + width ),
2660 ( float ) ( y + heigth ),
2664 if ( color_border != null ) {
2665 g.setPaint( color_border );
2670 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
2671 _rectangle.setFrame( x, y, width, heigth );
2672 g.draw( _rectangle );
2675 final private void drawRectFilled( final double x,
2678 final double heigth,
2679 final Graphics2D g ) {
2680 _rectangle.setFrame( x, y, width, heigth );
2681 g.fill( _rectangle );
2684 final private void drawRectGradient( final double x,
2687 final double heigth,
2689 final Color color_1,
2690 final Color color_2,
2691 final Color color_border ) {
2692 _rectangle.setFrame( x, y, width, heigth );
2693 g.setPaint( new GradientPaint( ( float ) x,
2696 ( float ) ( x + width ),
2697 ( float ) ( y + heigth ),
2700 g.fill( _rectangle );
2701 if ( color_border != null ) {
2702 g.setPaint( color_border );
2703 g.draw( _rectangle );
2707 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
2708 final List<Uri> us = new ArrayList<Uri>();
2709 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
2710 for( final Uri uri : t.getUris() ) {
2715 for( final Uri uri : us ) {
2716 if ( uri != null ) {
2717 final String uri_str = uri.getValue().toString().toLowerCase();
2718 if ( getImageMap().containsKey( uri_str ) ) {
2719 final BufferedImage bi = getImageMap().get( uri_str );
2720 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
2721 double scaling_factor = 1;
2722 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
2723 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
2724 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
2726 // y = y - ( 0.9 * getYdistance() );
2727 final double hs = bi.getHeight() * scaling_factor;
2728 double ws = ( bi.getWidth() * scaling_factor ) + offset;
2729 final double my_y = y - ( 0.5 * hs );
2730 final int x_w = ( int ) ( x + ws + 0.5 );
2731 final int y_h = ( int ) ( my_y + hs + 0.5 );
2732 if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) {
2734 ( int ) ( x + 0.5 + offset ),
2735 ( int ) ( my_y + 0.5 ),
2756 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
2757 JOptionPane.showMessageDialog( this,
2758 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
2759 "Attempt to cut/copy/paste/add/delete in unrooted display",
2760 JOptionPane.ERROR_MESSAGE );
2763 final private Set<Long> getCopiedAndPastedNodes() {
2764 return getMainPanel().getCopiedAndPastedNodes();
2767 final private Set<Long> getCurrentExternalNodes() {
2768 return _current_external_nodes;
2771 final private Phylogeny getCutOrCopiedTree() {
2772 return getMainPanel().getCutOrCopiedTree();
2775 final private float getLastDragPointX() {
2776 return _last_drag_point_x;
2779 final private float getLastDragPointY() {
2780 return _last_drag_point_y;
2783 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
2784 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
2785 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
2786 _nodeid_dist_to_leaf.put( node.getId(), m );
2790 return _nodeid_dist_to_leaf.get( node.getId() );
2794 final private double getMaxDistanceToRoot() {
2795 if ( _max_distance_to_root < 0 ) {
2796 recalculateMaxDistanceToRoot();
2798 return _max_distance_to_root;
2801 final private float getOvMaxHeight() {
2802 return _ov_max_height;
2805 final private float getOvMaxWidth() {
2806 return _ov_max_width;
2809 final private float getOvXcorrectionFactor() {
2810 return _ov_x_correction_factor;
2813 final private float getOvXDistance() {
2814 return _ov_x_distance;
2817 final private int getOvXPosition() {
2818 return _ov_x_position;
2821 final private float getOvYDistance() {
2822 return _ov_y_distance;
2825 final private int getOvYPosition() {
2826 return _ov_y_position;
2829 final private int getOvYStart() {
2833 final private double getScaleDistance() {
2834 return _scale_distance;
2837 final private String getScaleLabel() {
2838 return _scale_label;
2841 final private TreeFontSet getTreeFontSet() {
2842 return getMainPanel().getTreeFontSet();
2845 final private float getUrtFactor() {
2849 final private float getUrtFactorOv() {
2850 return _urt_factor_ov;
2853 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
2856 showNodeFrame( node );
2871 colorSubtree( node );
2889 copySubtree( node );
2892 pasteSubtree( node );
2894 case DELETE_NODE_OR_SUBTREE:
2895 deleteNodeOrSubtree( node );
2898 addEmptyNode( node );
2900 case EDIT_NODE_DATA:
2901 showNodeEditFrame( node );
2906 case SORT_DESCENDENTS:
2907 sortDescendants( node );
2909 case GET_EXT_DESC_DATA:
2910 showExtDescNodeData( node );
2913 throw new IllegalArgumentException( "unknown action: " + action );
2917 final private void increaseCurrentExternalNodesDataBufferChangeCounter() {
2918 _current_external_nodes_data_buffer_change_counter++;
2921 final private void increaseOvSize() {
2922 if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) )
2923 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
2924 .getHeight() / 2 ) ) ) {
2925 setOvMaxWidth( getOvMaxWidth() + 5 );
2926 setOvMaxHeight( getOvMaxHeight() + 5 );
2928 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2932 final private void init() {
2933 _color_chooser = new JColorChooser();
2934 _rollover_popup = new JTextArea();
2935 _rollover_popup.setFont( POPUP_FONT );
2936 resetNodeIdToDistToLeafMap();
2938 setTreeFile( null );
2940 initializeOvSettings();
2941 setStartingAngle( ( TWO_PI * 3 ) / 4 );
2942 final ImageLoader il = new ImageLoader( this );
2943 new Thread( il ).start();
2946 final private void initializeOvSettings() {
2947 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
2948 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
2951 final private boolean inOvVirtualRectangle( final int x, final int y ) {
2952 return ( ( x >= ( getOvVirtualRectangle().x - 1 ) )
2953 && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) )
2954 && ( y >= ( getOvVirtualRectangle().y - 1 ) ) && ( y <= ( getOvVirtualRectangle().y
2955 + getOvVirtualRectangle().height + 1 ) ) );
2958 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
2959 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
2962 final private boolean isCanBlast( final PhylogenyNode node ) {
2963 if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) {
2966 return Blast.isContainsQueryForBlast( node );
2969 final private String isCanOpenSeqWeb( final PhylogenyNode node ) {
2970 final Accession a = SequenceAccessionTools.obtainAccessorFromDataFields( node );
2972 return a.getValue();
2977 final private List<Accession> getPdbAccs( final PhylogenyNode node ) {
2978 final List<Accession> pdb_ids = new ArrayList<Accession>();
2979 if ( node.getNodeData().isHasSequence() ) {
2980 final Sequence seq = node.getNodeData().getSequence();
2981 if ( !ForesterUtil.isEmpty( seq.getCrossReferences() ) ) {
2982 final SortedSet<Accession> cross_refs = seq.getCrossReferences();
2983 for( final Accession acc : cross_refs ) {
2984 if ( acc.getSource().equalsIgnoreCase( "pdb" ) ) {
2993 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
2994 if ( node.getNodeData().isHasTaxonomy()
2995 && ( ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
2996 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
2997 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
2998 .getNodeData().getTaxonomy().getIdentifier() != null ) && !ForesterUtil.isEmpty( node
2999 .getNodeData().getTaxonomy().getIdentifier().getValue() ) ) ) ) {
3007 final private boolean isInCurrentExternalNodes( final PhylogenyNode node ) {
3008 return ( ( getCurrentExternalNodes() != null ) && getCurrentExternalNodes().contains( node.getId() ) );
3011 final private boolean isInFoundNodes0( final PhylogenyNode node ) {
3012 return ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) );
3015 final private boolean isInFoundNodes1( final PhylogenyNode node ) {
3016 return ( ( getFoundNodes1() != null ) && getFoundNodes1().contains( node.getId() ) );
3019 final private boolean isInOv() {
3023 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
3025 if ( getControlPanel().isShowTaxonomyImages() ) {
3026 y_dist = 40 + ( int ) getYdistance();
3028 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) )
3029 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) ) || ( ( node.getParent() != null ) && ( node
3030 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
3033 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
3034 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) )
3035 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) )
3036 || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) ) || ( node.getXcoord() > ( getVisibleRect()
3037 .getMaxX() + 20 ) ) );
3040 final private boolean isNonLinedUpCladogram() {
3041 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
3044 final private boolean isUniformBranchLengthsForCladogram() {
3045 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
3048 final private void keyPressedCalls( final KeyEvent e ) {
3049 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
3050 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
3051 if ( !isInOvRect() ) {
3052 setInOvRect( true );
3055 else if ( isInOvRect() ) {
3056 setInOvRect( false );
3059 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
3060 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
3061 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
3062 getMainPanel().getTreeFontSet().mediumFonts();
3063 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3065 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
3066 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
3067 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3069 else if ( plusPressed( e.getKeyCode() ) ) {
3070 getMainPanel().getTreeFontSet().increaseFontSize();
3071 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3075 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
3076 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
3077 getControlPanel().showWhole();
3079 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
3080 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
3081 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
3082 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
3083 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3084 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3086 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
3087 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3088 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3090 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
3091 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3092 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3093 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3095 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
3096 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3097 Constants.WHEEL_ZOOM_IN_FACTOR );
3098 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3105 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
3108 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
3112 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
3116 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
3117 scroll_position.x = scroll_position.x + dx;
3118 scroll_position.y = scroll_position.y + dy;
3119 if ( scroll_position.x <= 0 ) {
3120 scroll_position.x = 0;
3123 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
3124 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
3125 if ( scroll_position.x >= max_x ) {
3126 scroll_position.x = max_x;
3129 if ( scroll_position.y <= 0 ) {
3130 scroll_position.y = 0;
3133 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
3134 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
3135 if ( scroll_position.y >= max_y ) {
3136 scroll_position.y = max_y;
3140 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
3143 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
3144 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3145 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3146 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3147 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3149 else if ( plusPressed( e.getKeyCode() ) ) {
3150 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3151 Constants.WHEEL_ZOOM_IN_FACTOR );
3152 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3153 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3155 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
3156 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3157 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3158 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
3159 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3162 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
3163 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3164 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3165 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
3166 if ( getStartingAngle() < 0 ) {
3167 setStartingAngle( TWO_PI + getStartingAngle() );
3169 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3172 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
3173 boolean selected = false;
3174 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
3175 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
3179 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
3181 if ( getMainPanel().getMainFrame() == null ) {
3182 // Must be "E" applet version.
3183 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
3184 if ( ae.getlabelDirectionCbmi() != null ) {
3185 ae.getlabelDirectionCbmi().setSelected( selected );
3189 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
3193 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
3194 switchDisplaygetPhylogenyGraphicsType();
3197 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
3201 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
3202 MainFrame.cycleOverview( getOptions(), this );
3205 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
3208 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
3215 final private void makePopupMenus( final PhylogenyNode node ) {
3216 _node_popup_menu = new JPopupMenu();
3217 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
3218 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
3219 for( int i = 0; i < clickto_names.size(); i++ ) {
3220 final String title = clickto_names.get( i );
3221 _node_popup_menu_items[ i ] = new JMenuItem( title );
3222 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
3223 final String id = isCanOpenSeqWeb( node );
3224 if ( !ForesterUtil.isEmpty( id ) ) {
3225 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + id + "]" );
3226 _node_popup_menu_items[ i ].setEnabled( true );
3229 _node_popup_menu_items[ i ].setEnabled( false );
3232 else if ( title.equals( Configuration.clickto_options[ Configuration.open_pdb_web ][ 0 ] ) ) {
3233 final List<Accession> accs = getPdbAccs( node );
3234 _node_popup_menu_items[ i ] = new JMenuItem( title );
3235 if ( !ForesterUtil.isEmpty( accs ) ) {
3236 if ( accs.size() == 1 ) {
3237 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
3238 + TreePanelUtil.pdbAccToString( accs, 0 ) + "]" );
3239 _node_popup_menu_items[ i ].setEnabled( true );
3241 else if ( accs.size() == 2 ) {
3242 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
3243 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
3244 + TreePanelUtil.pdbAccToString( accs, 1 ) + "]" );
3245 _node_popup_menu_items[ i ].setEnabled( true );
3247 else if ( accs.size() == 3 ) {
3248 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
3249 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
3250 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
3251 + TreePanelUtil.pdbAccToString( accs, 2 ) + "]" );
3252 _node_popup_menu_items[ i ].setEnabled( true );
3255 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
3256 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
3257 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
3258 + TreePanelUtil.pdbAccToString( accs, 2 ) + ", + " + ( accs.size() - 3 ) + " more]" );
3259 _node_popup_menu_items[ i ].setEnabled( true );
3263 _node_popup_menu_items[ i ].setEnabled( false );
3267 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
3268 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
3270 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
3271 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
3273 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
3274 if ( !getOptions().isEditable() ) {
3277 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
3279 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
3280 if ( !getOptions().isEditable() ) {
3283 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
3285 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
3286 if ( !getOptions().isEditable() ) {
3289 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
3291 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
3292 if ( !getOptions().isEditable() ) {
3295 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
3297 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
3298 if ( !getOptions().isEditable() ) {
3302 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
3303 if ( !getOptions().isEditable() ) {
3307 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
3308 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
3310 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
3311 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
3313 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
3314 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
3316 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
3317 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
3319 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
3320 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
3322 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
3323 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
3325 _node_popup_menu_items[ i ].addActionListener( this );
3326 _node_popup_menu.add( _node_popup_menu_items[ i ] );
3330 private final String obtainTitleForExtDescNodeData() {
3331 switch ( getOptions().getExtDescNodeDataToReturn() ) {
3333 return "Node Names";
3335 return "Gene Names";
3337 return "Sequence Names";
3338 case SEQUENCE_SYMBOL:
3339 return "Sequence Symbols";
3340 case SEQUENCE_MOL_SEQ:
3341 return "Molecular Sequences";
3342 case SEQUENCE_MOL_SEQ_FASTA:
3343 return "Molecular Sequences (Fasta)";
3345 return "Sequence Accessors";
3346 case TAXONOMY_SCIENTIFIC_NAME:
3347 return "Scientific Names";
3349 return "Taxonomy Codes";
3350 case TAXONOMY_COMM0N_NAME:
3351 return "Taxonomy Common Names";
3353 return "User Selected Data";
3355 throw new IllegalArgumentException( "unknown data element: "
3356 + getOptions().getExtDescNodeDataToReturn() );
3360 final private void openSeqWeb( final PhylogenyNode node ) {
3361 if ( ForesterUtil.isEmpty( isCanOpenSeqWeb( node ) ) ) {
3362 cannotOpenBrowserWarningMessage( "sequence" );
3365 final String uri_str = TreePanelUtil.createUriForSeqWeb( node, getConfiguration(), this );
3366 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3368 AptxUtil.launchWebBrowser( new URI( uri_str ),
3370 isApplet() ? obtainApplet() : null,
3373 catch ( final IOException e ) {
3374 AptxUtil.showErrorMessage( this, e.toString() );
3375 e.printStackTrace();
3377 catch ( final URISyntaxException e ) {
3378 AptxUtil.showErrorMessage( this, e.toString() );
3379 e.printStackTrace();
3383 cannotOpenBrowserWarningMessage( "sequence" );
3387 final private void openPdbWeb( final PhylogenyNode node ) {
3388 final List<Accession> pdb_ids = getPdbAccs( node );
3389 if ( ForesterUtil.isEmpty( pdb_ids ) ) {
3390 cannotOpenBrowserWarningMessage( "PDB" );
3393 final List<String> uri_strs = TreePanelUtil.createUrisForPdbWeb( node, pdb_ids, getConfiguration(), this );
3394 if ( !ForesterUtil.isEmpty( uri_strs ) ) {
3395 for( final String uri_str : uri_strs ) {
3397 AptxUtil.launchWebBrowser( new URI( uri_str ),
3399 isApplet() ? obtainApplet() : null,
3402 catch ( final IOException e ) {
3403 AptxUtil.showErrorMessage( this, e.toString() );
3404 e.printStackTrace();
3406 catch ( final URISyntaxException e ) {
3407 AptxUtil.showErrorMessage( this, e.toString() );
3408 e.printStackTrace();
3413 cannotOpenBrowserWarningMessage( "PDB" );
3417 final private void openTaxWeb( final PhylogenyNode node ) {
3418 if ( !isCanOpenTaxWeb( node ) ) {
3419 cannotOpenBrowserWarningMessage( "taxonomic" );
3422 String uri_str = null;
3423 final Taxonomy tax = node.getNodeData().getTaxonomy();
3424 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
3425 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
3427 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
3429 catch ( final URISyntaxException e ) {
3430 AptxUtil.showErrorMessage( this, e.toString() );
3432 e.printStackTrace();
3435 else if ( ( tax.getIdentifier() != null )
3436 && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
3437 && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
3438 && ( tax.getIdentifier().getProvider().equalsIgnoreCase( "ncbi" ) || tax.getIdentifier().getProvider()
3439 .equalsIgnoreCase( "uniprot" ) ) ) {
3441 uri_str = "http://www.uniprot.org/taxonomy/"
3442 + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
3444 catch ( final UnsupportedEncodingException e ) {
3445 AptxUtil.showErrorMessage( this, e.toString() );
3446 e.printStackTrace();
3449 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
3451 uri_str = "http://www.uniprot.org/taxonomy/?query="
3452 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
3454 catch ( final UnsupportedEncodingException e ) {
3455 AptxUtil.showErrorMessage( this, e.toString() );
3456 e.printStackTrace();
3459 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
3461 uri_str = "http://www.uniprot.org/taxonomy/?query="
3462 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
3464 catch ( final UnsupportedEncodingException e ) {
3465 AptxUtil.showErrorMessage( this, e.toString() );
3466 e.printStackTrace();
3469 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
3471 uri_str = "http://www.uniprot.org/taxonomy/?query="
3472 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
3474 catch ( final UnsupportedEncodingException e ) {
3475 AptxUtil.showErrorMessage( this, e.toString() );
3476 e.printStackTrace();
3479 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3481 AptxUtil.launchWebBrowser( new URI( uri_str ),
3483 isApplet() ? obtainApplet() : null,
3486 catch ( final IOException e ) {
3487 AptxUtil.showErrorMessage( this, e.toString() );
3488 e.printStackTrace();
3490 catch ( final URISyntaxException e ) {
3491 AptxUtil.showErrorMessage( this, e.toString() );
3492 e.printStackTrace();
3496 cannotOpenBrowserWarningMessage( "taxonomic" );
3500 final private void paintBranchLength( final Graphics2D g,
3501 final PhylogenyNode node,
3502 final boolean to_pdf,
3503 final boolean to_graphics_file ) {
3504 g.setFont( getTreeFontSet().getSmallFont() );
3505 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3506 g.setColor( Color.BLACK );
3509 g.setColor( getTreeColorSet().getBranchLengthColor() );
3511 if ( !node.isRoot() ) {
3512 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3513 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3514 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3516 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3517 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3518 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3521 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3522 .getXcoord() + 3, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3526 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
3527 - getTreeFontSet()._small_max_descent, g );
3531 final private void paintBranchLite( final Graphics2D g,
3536 final PhylogenyNode node ) {
3537 g.setColor( getTreeColorSet().getOvColor() );
3538 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3539 drawLine( x1, y1, x2, y2, g );
3541 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3542 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3543 ( g ).draw( _quad_curve );
3545 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3546 final float dx = x2 - x1;
3547 final float dy = y2 - y1;
3548 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3549 + ( dy * 0.8f ), x2, y2 );
3550 ( g ).draw( _cubic_curve );
3553 final float x2a = x2;
3554 final float x1a = x1;
3555 // draw the vertical line
3556 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
3557 drawLine( x1, y1, x1, y2, g );
3559 // draw the horizontal line
3560 drawLine( x1a, y2, x2a, y2, g );
3565 * Paint a branch which consists of a vertical and a horizontal bar
3566 * @param is_ind_found_nodes
3568 final private void paintBranchRectangular( final Graphics2D g,
3573 final PhylogenyNode node,
3574 final boolean to_pdf,
3575 final boolean to_graphics_file ) {
3576 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
3577 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3578 drawLine( x1, y1, x2, y2, g );
3580 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3581 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3582 g.draw( _quad_curve );
3584 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3585 final float dx = x2 - x1;
3586 final float dy = y2 - y1;
3587 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3588 + ( dy * 0.8f ), x2, y2 );
3589 g.draw( _cubic_curve );
3592 final float x2a = x2;
3593 final float x1a = x1;
3595 if ( node.isFirstChildNode() || node.isLastChildNode()
3596 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
3597 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3598 if ( !to_graphics_file
3600 && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) ) || ( ( y2 > ( getVisibleRect()
3601 .getMaxY() + 20 ) ) && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) {
3605 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3606 float x2c = x1 + EURO_D;
3610 drawLine( x1, y1, x2c, y2, g );
3612 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3614 y2_r = y2 - ROUNDED_D;
3618 drawLine( x1, y1, x1, y2_r, g );
3621 y2_r = y2 + ROUNDED_D;
3625 drawLine( x1, y1, x1, y2_r, g );
3629 drawLine( x1, y1, x1, y2, g );
3633 // draw the horizontal line
3634 if ( !to_graphics_file && !to_pdf
3635 && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) {
3639 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
3640 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3641 x1_r = x1a + ROUNDED_D;
3643 drawLine( x1_r, y2, x2a, y2, g );
3646 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3647 final float x1c = x1a + EURO_D;
3649 drawLine( x1c, y2, x2a, y2, g );
3653 drawLine( x1a, y2, x2a, y2, g );
3657 final double w = PhylogenyMethods.getBranchWidthValue( node );
3658 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3659 x1_r = x1a + ROUNDED_D;
3661 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
3664 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3665 final float x1c = x1a + EURO_D;
3667 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
3671 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
3674 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3679 final double diff = y2 - y2_r;
3680 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
3683 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
3688 if ( node.isExternal() ) {
3689 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file );
3693 final private double paintCirculars( final PhylogenyNode n,
3694 final Phylogeny phy,
3695 final float center_x,
3696 final float center_y,
3697 final double radius,
3698 final boolean radial_labels,
3700 final boolean to_pdf,
3701 final boolean to_graphics_file ) {
3702 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
3703 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
3704 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
3706 return _urt_nodeid_angle_map.get( n.getId() );
3709 final List<PhylogenyNode> descs = n.getDescendants();
3711 for( final PhylogenyNode desc : descs ) {
3712 sum += paintCirculars( desc,
3723 if ( !n.isRoot() ) {
3724 r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3726 final double theta = sum / descs.size();
3727 n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) );
3728 n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) );
3729 _urt_nodeid_angle_map.put( n.getId(), theta );
3730 for( final PhylogenyNode desc : descs ) {
3731 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
3737 final private void paintCircularsLite( final PhylogenyNode n,
3738 final Phylogeny phy,
3742 final Graphics2D g ) {
3743 if ( n.isExternal() ) {
3747 final List<PhylogenyNode> descs = n.getDescendants();
3748 for( final PhylogenyNode desc : descs ) {
3749 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
3752 if ( !n.isRoot() ) {
3753 r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3755 final double theta = _urt_nodeid_angle_map.get( n.getId() );
3756 n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) );
3757 n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) );
3758 for( final PhylogenyNode desc : descs ) {
3759 paintBranchCircularLite( n, desc, g );
3764 final private void paintCollapsedNode( final Graphics2D g,
3765 final PhylogenyNode node,
3766 final boolean to_graphics_file,
3767 final boolean to_pdf,
3768 final boolean is_in_found_nodes ) {
3770 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3773 else if ( is_in_found_nodes ) {
3774 c = getColorForFoundNode( node );
3776 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3777 c = getTaxonomyBasedColor( node );
3779 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3780 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3781 c = PhylogenyMethods.getBranchColorValue( node );
3784 c = getTreeColorSet().getCollapseFillColor();
3786 double d = node.getAllExternalDescendants().size();
3788 d = ( 3 * _y_distance ) / 3;
3791 d = ( Math.log10( d ) * _y_distance ) / 2.5;
3793 final int box_size = getOptions().getDefaultNodeShapeSize() + 1;
3794 if ( d < box_size ) {
3797 final float xx = node.getXcoord() - ( 2 * box_size );
3798 final float xxx = xx > node.getParent().getXcoord() + 1 ? xx : node.getParent().getXcoord() + 1;
3800 _polygon.moveTo( xxx, node.getYcoord() );
3801 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d );
3802 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d );
3803 _polygon.closePath();
3804 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3808 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
3809 g.setColor( getBackground() );
3814 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
3815 g.setPaint( new GradientPaint( xxx, node.getYcoord(), getBackground(), node.getXcoord(), ( float ) ( node
3816 .getYcoord() - d ), c, false ) );
3821 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3824 final private void paintConfidenceValues( final Graphics2D g,
3825 final PhylogenyNode node,
3826 final boolean to_pdf,
3827 final boolean to_graphics_file ) {
3828 final List<Confidence> confidences = node.getBranchData().getConfidences();
3829 boolean not_first = false;
3830 Collections.sort( confidences );
3831 final StringBuilder sb = new StringBuilder();
3832 for( final Confidence confidence : confidences ) {
3833 final double value = confidence.getValue();
3834 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
3835 if ( value < getOptions().getMinConfidenceValue() ) {
3844 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
3845 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
3846 if ( getOptions().isShowConfidenceStddev() ) {
3847 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
3849 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getStandardDeviation(),
3851 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
3857 if ( sb.length() > 0 ) {
3858 final double parent_x = node.getParent().getXcoord();
3859 double x = node.getXcoord();
3860 g.setFont( getTreeFontSet().getSmallFont() );
3861 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3864 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3867 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3868 g.setColor( Color.BLACK );
3871 g.setColor( getTreeColorSet().getConfidenceColor() );
3873 final String conf_str = sb.toString();
3875 .drawString( conf_str,
3877 + ( ( x - parent_x - getTreeFontSet()._fm_small.stringWidth( conf_str ) ) / 2 ),
3878 ( node.getYcoord() + getTreeFontSet()._small_max_ascent ) - 1,
3883 private final Color getColorForFoundNode( final PhylogenyNode n ) {
3884 if ( isInCurrentExternalNodes( n ) ) {
3885 return getTreeColorSet().getFoundColor0();
3887 else if ( isInFoundNodes0( n ) && !isInFoundNodes1( n ) ) {
3888 return getTreeColorSet().getFoundColor0() ;
3890 else if ( !isInFoundNodes0( n ) && isInFoundNodes1( n ) ) {
3891 return getTreeColorSet().getFoundColor1() ;
3894 return getTreeColorSet().getFoundColor0and1() ;
3899 final private void paintFoundNode( final PhylogenyNode n, final double x, final double y, final Graphics2D g ) {
3900 final int box_size = getOptions().getDefaultNodeShapeSize();
3901 final double half_box_size = getOptions().getDefaultNodeShapeSize() / 2.0;
3906 g.setColor( getColorForFoundNode( n ) );
3907 //g.fillRect( x - half_box_size, y - half_box_size, box_size, box_size );
3910 _rectangle.setRect( x - half_box_size, y - half_box_size, box_size, box_size );
3911 g.fill( _rectangle );
3914 final private void paintGainedAndLostCharacters( final Graphics2D g,
3915 final PhylogenyNode node,
3916 final String gained,
3917 final String lost ) {
3918 if ( node.getParent() != null ) {
3919 final double parent_x = node.getParent().getXcoord();
3920 final double x = node.getXcoord();
3921 g.setFont( getTreeFontSet().getLargeFont() );
3922 g.setColor( getTreeColorSet().getGainedCharactersColor() );
3923 if ( Constants.SPECIAL_CUSTOM ) {
3924 g.setColor( Color.BLUE );
3927 .drawString( gained,
3928 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( gained ) ) / 2 ),
3929 ( node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent() ),
3931 g.setColor( getTreeColorSet().getLostCharactersColor() );
3932 TreePanel.drawString( lost,
3933 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( lost ) ) / 2 ),
3934 ( node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent() ),
3940 * Draw a box at the indicated node.
3947 final private void paintNodeBox( final double x,
3949 final PhylogenyNode node,
3951 final boolean to_pdf,
3952 final boolean to_graphics_file ) {
3953 if ( node.isCollapse() ) {
3956 // if this node should be highlighted, do so
3957 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
3958 g.setColor( getTreeColorSet().getFoundColor0() );
3959 drawOval( x - 8, y - 8, 16, 16, g );
3960 drawOval( x - 9, y - 8, 17, 17, g );
3961 drawOval( x - 9, y - 9, 18, 18, g );
3963 if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
3964 paintFoundNode( node, x , y , g );
3967 Color outline_color = null;
3968 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3969 outline_color = Color.BLACK;
3971 else if ( getControlPanel().isEvents() && TreePanelUtil.isHasAssignedEvent( node ) ) {
3972 final Event event = node.getNodeData().getEvent();
3973 if ( event.isDuplication() ) {
3974 outline_color = getTreeColorSet().getDuplicationBoxColor();
3976 else if ( event.isSpeciation() ) {
3977 outline_color = getTreeColorSet().getSpecBoxColor();
3979 else if ( event.isSpeciationOrDuplication() ) {
3980 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
3983 else if ( getOptions().isTaxonomyColorizeNodeShapes() ) {
3984 outline_color = getTaxonomyBasedColor( node );
3987 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
3988 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
3989 outline_color = getTreeColorSet().getBranchColorForPdf();
3992 final int box_size = getOptions().getDefaultNodeShapeSize();
3993 final int half_box_size = box_size / 2;
3994 if ( ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() )
3995 || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() )
3996 || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) {
3997 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
3998 if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
3999 drawOvalGradient( x - half_box_size,
4004 to_pdf ? Color.WHITE : outline_color,
4005 to_pdf ? outline_color : getBackground(),
4008 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
4009 Color background = getBackground();
4011 background = Color.WHITE;
4013 drawOvalGradient( x - half_box_size,
4022 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
4023 g.setColor( outline_color );
4024 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
4027 else if ( getOptions().getDefaultNodeShape() == NodeVisualization.NodeShape.RECTANGLE ) {
4028 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.GRADIENT ) {
4029 drawRectGradient( x - half_box_size,
4034 to_pdf ? Color.WHITE : outline_color,
4035 to_pdf ? outline_color : getBackground(),
4038 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
4039 Color background = getBackground();
4041 background = Color.WHITE;
4043 drawRectGradient( x - half_box_size,
4052 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
4053 g.setColor( outline_color );
4054 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
4061 final private void paintNodeData( final Graphics2D g,
4062 final PhylogenyNode node,
4063 final boolean to_graphics_file,
4064 final boolean to_pdf,
4065 final boolean is_in_found_nodes ) {
4066 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
4069 if ( getOptions().isShowBranchLengthValues()
4070 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
4071 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
4072 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
4073 paintBranchLength( g, node, to_pdf, to_graphics_file );
4075 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
4080 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
4081 if ( getControlPanel().isShowTaxonomyImages()
4082 && ( getImageMap() != null )
4083 && !getImageMap().isEmpty()
4084 && node.getNodeData().isHasTaxonomy()
4085 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
4086 .getUris().isEmpty() ) ) {
4087 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
4089 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
4090 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
4091 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
4093 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4094 g.setColor( Color.BLACK );
4096 else if ( is_in_found_nodes ) {
4097 g.setColor( getColorForFoundNode( node ) );
4099 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4100 g.setColor( getTaxonomyBasedColor( node ) );
4102 else if ( getControlPanel().isColorAccordingToAnnotation()
4103 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
4104 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
4105 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
4107 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
4108 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
4109 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
4111 else if ( to_pdf ) {
4112 g.setColor( Color.BLACK );
4115 g.setColor( getTreeColorSet().getSequenceColor() );
4117 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
4118 if ( _sb.length() > 0 ) {
4121 _sb.append( node.getAllExternalDescendants().size() );
4128 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
4129 if ( _sb.length() > 0 ) {
4132 _sb.append( node.getName() );
4134 if ( node.getNodeData().isHasSequence() ) {
4135 if ( getControlPanel().isShowSeqSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
4136 if ( _sb.length() > 0 ) {
4139 _sb.append( node.getNodeData().getSequence().getSymbol() );
4141 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) {
4142 if ( _sb.length() > 0 ) {
4145 _sb.append( node.getNodeData().getSequence().getGeneName() );
4147 if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
4148 if ( _sb.length() > 0 ) {
4151 _sb.append( node.getNodeData().getSequence().getName() );
4153 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4154 if ( _sb.length() > 0 ) {
4157 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
4158 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
4161 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
4164 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
4165 if ( _sb.length() > 0 ) {
4168 _sb.append( propertiesToString( node ) );
4170 g.setFont( getTreeFontSet().getLargeFont() );
4171 if ( is_in_found_nodes ) {
4172 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
4174 double down_shift_factor = 3.0;
4175 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
4176 down_shift_factor = 1;
4178 final double pos_x = node.getXcoord() + x + 2 + half_box_size;
4179 final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
4180 final String sb_str = _sb.toString();
4181 // GUILHEM_BEG ______________
4182 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
4183 && ( _query_sequence != null ) ) {
4184 int nodeTextBoundsWidth = 0;
4185 if ( sb_str.length() > 0 ) {
4186 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
4187 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
4189 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
4190 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
4191 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
4192 g.setColor( getTreeColorSet().getBackgroundColor() );
4196 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
4197 for( final SequenceRelation seqRelation : seqRelations ) {
4198 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
4199 .getRef1().isEqual( _query_sequence ) )
4200 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
4201 .getSelectedItem() );
4202 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
4203 final double linePosX = node.getXcoord() + 2 + half_box_size;
4204 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
4205 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
4207 if ( sConfidence != null ) {
4208 double confidenceX = pos_x;
4209 if ( sb_str.length() > 0 ) {
4210 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
4211 + CONFIDENCE_LEFT_MARGIN;
4213 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
4214 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
4215 .getBounds().getWidth();
4216 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
4217 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
4220 if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
4222 if ( nodeTextBoundsWidth == 0 ) {
4223 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
4226 nodeTextBoundsWidth += 2;
4228 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
4229 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
4236 if ( sb_str.length() > 0 ) {
4237 TreePanel.drawString( sb_str, pos_x, pos_y, g );
4239 // GUILHEM_END _____________
4240 // COMMENTED_OUT_BY_GUILHEM_BEG _______________
4241 // TODO FIXME need to check this one!
4242 //if ( _sb.length() > 0 ) {
4243 // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
4244 // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4246 // COMMENTED_OUT_BY_GUILHEM_END ________________
4247 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
4248 && ( node.getNodeData().getSequence().getAnnotations() != null )
4249 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
4250 if ( _sb.length() > 0 ) {
4251 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
4253 final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
4254 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4255 g.setColor( Color.BLACK );
4257 else if ( getControlPanel().isColorAccordingToAnnotation() ) {
4258 g.setColor( calculateColorForAnnotation( ann ) );
4260 final String ann_str = TreePanelUtil.createAnnotationString( ann, getOptions().isShowAnnotationRefSource() );
4261 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
4262 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4264 _sb.append( ann_str );
4266 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
4267 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
4268 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
4269 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
4270 && node.getNodeData().isHasBinaryCharacters() ) {
4271 if ( _sb.length() > 0 ) {
4272 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
4274 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4275 g.setColor( Color.BLACK );
4278 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
4280 if ( getControlPanel().isShowBinaryCharacters() ) {
4281 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
4282 .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord()
4283 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4284 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
4285 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
4286 .getLostCharactersAsStringBuffer().toString() );
4289 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
4290 node.getXcoord() + x + 4 + half_box_size,
4292 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ),
4294 paintGainedAndLostCharacters( g, node, "+"
4295 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
4296 + node.getNodeData().getBinaryCharacters().getLostCount() );
4302 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
4303 final PhylogenyNode node,
4304 final boolean to_pdf,
4305 final boolean to_graphics_file,
4306 final boolean radial_labels,
4307 final double ur_angle,
4308 final boolean is_in_found_nodes ) {
4309 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
4312 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4313 g.setColor( Color.BLACK );
4315 else if ( is_in_found_nodes ) {
4316 g.setColor( getColorForFoundNode( node ) );
4318 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4319 g.setColor( getTaxonomyBasedColor( node ) );
4321 else if ( getControlPanel().isColorAccordingToAnnotation()
4322 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
4323 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
4324 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
4327 g.setColor( getTreeColorSet().getSequenceColor() );
4331 if ( node.getNodeData().isHasTaxonomy()
4332 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
4333 .isShowTaxonomyCommonNames() ) ) {
4334 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4335 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4336 _sb.append( taxonomy.getTaxonomyCode() );
4339 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4340 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4341 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4342 _sb.append( taxonomy.getScientificName() );
4344 _sb.append( taxonomy.getCommonName() );
4347 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4348 _sb.append( taxonomy.getScientificName() );
4351 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4352 _sb.append( taxonomy.getCommonName() );
4356 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4357 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4358 _sb.append( taxonomy.getScientificName() );
4362 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4363 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4364 _sb.append( taxonomy.getCommonName() );
4369 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
4371 _sb.append( node.getAllExternalDescendants().size() );
4374 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
4375 if ( _sb.length() > 0 ) {
4378 _sb.append( node.getName() );
4380 if ( node.getNodeData().isHasSequence() ) {
4381 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4382 if ( _sb.length() > 0 ) {
4385 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
4386 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
4389 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
4391 if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
4392 if ( _sb.length() > 0 ) {
4395 _sb.append( node.getNodeData().getSequence().getName() );
4398 g.setFont( getTreeFontSet().getLargeFont() );
4399 if ( is_in_found_nodes ) {
4400 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
4402 if ( _sb.length() > 1 ) {
4403 final String sb_str = _sb.toString();
4405 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4406 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
4409 m = ( float ) ( ur_angle % TWO_PI );
4411 _at = g.getTransform();
4412 boolean need_to_reset = false;
4413 final float x_coord = node.getXcoord();
4414 final float y_coord = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / 3.0f );
4415 if ( radial_labels ) {
4416 need_to_reset = true;
4417 boolean left = false;
4418 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4422 g.rotate( m, x_coord, node.getYcoord() );
4424 g.translate( -( getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth() ), 0 );
4428 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4429 need_to_reset = true;
4430 g.translate( -getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth(), 0 );
4433 TreePanel.drawString( sb_str, x_coord, y_coord, g );
4434 if ( need_to_reset ) {
4435 g.setTransform( _at );
4440 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
4441 if ( node.isCollapse() ) {
4442 if ( !node.isRoot() && !node.getParent().isCollapse() ) {
4443 paintCollapsedNode( g, node, false, false, false );
4447 if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
4448 g.setColor( getColorForFoundNode( node ) );
4449 drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
4452 if ( !node.isExternal() && !node.isCollapse() ) {
4453 boolean first_child = true;
4455 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4456 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4457 final PhylogenyNode child_node = node.getChildNode( i );
4459 if ( !isUniformBranchLengthsForCladogram() ) {
4460 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4463 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4465 if ( first_child ) {
4466 first_child = false;
4467 y2 = node.getYSecondary()
4468 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
4469 .getNumberOfExternalNodes() ) );
4472 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4474 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
4475 new_x = x2 + node.getXSecondary();
4476 final float diff_y = node.getYSecondary() - y2;
4477 final float diff_x = node.getXSecondary() - new_x;
4478 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
4479 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
4481 child_node.setXSecondary( new_x );
4482 child_node.setYSecondary( y2 );
4483 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4488 final private void paintNodeRectangular( final Graphics2D g,
4489 final PhylogenyNode node,
4490 final boolean to_pdf,
4491 final boolean dynamically_hide,
4492 final int dynamic_hiding_factor,
4493 final boolean to_graphics_file ) {
4494 final boolean is_in_found_nodes = isInFoundNodes( node ) || isInCurrentExternalNodes( node );
4495 if ( node.isCollapse() ) {
4496 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) ) {
4497 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4501 if ( node.isExternal() ) {
4502 ++_external_node_index;
4504 // Confidence values
4505 if ( getControlPanel().isShowConfidenceValues()
4506 && !node.isExternal()
4508 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
4509 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
4510 && node.getBranchData().isHasConfidences() ) {
4511 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
4513 // Draw a line to root:
4514 if ( node.isRoot() && _phylogeny.isRooted() ) {
4515 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
4518 float new_x_min = Float.MAX_VALUE;
4519 final boolean disallow_shortcutting = dynamic_hiding_factor < 40;
4520 float min_dist = 1.5f;
4521 if ( !disallow_shortcutting ) {
4522 // System.out.println( dynamic_hiding_factor );
4523 if ( dynamic_hiding_factor > 4000 ) {
4526 else if ( dynamic_hiding_factor > 1000 ) {
4529 else if ( dynamic_hiding_factor > 100 ) {
4533 if ( !node.isExternal() && !node.isCollapse() ) {
4534 boolean first_child = true;
4536 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4537 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4538 final PhylogenyNode child_node = node.getChildNode( i );
4540 if ( !isUniformBranchLengthsForCladogram() ) {
4541 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4544 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4546 if ( first_child ) {
4547 first_child = false;
4548 y2 = node.getYcoord()
4549 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
4552 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4554 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
4555 new_x = x2 + node.getXcoord();
4556 if ( dynamically_hide && ( x2 < new_x_min ) ) {
4559 final float diff_y = node.getYcoord() - y2;
4560 final float diff_x = node.getXcoord() - new_x;
4561 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
4562 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
4563 paintBranchRectangular( g,
4572 child_node.setXcoord( new_x );
4573 child_node.setYcoord( y2 );
4574 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4576 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file );
4578 if ( dynamically_hide
4579 && !is_in_found_nodes
4580 && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) ) || ( !node
4581 .isExternal() && ( ( new_x_min < 20 ) || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getTreeFontSet()._fm_large
4582 .getHeight() ) ) ) ) ) {
4585 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4586 paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
4589 final private void paintNodeWithRenderableData( final Graphics2D g,
4590 final PhylogenyNode node,
4591 final boolean to_graphics_file,
4592 final boolean to_pdf ) {
4593 if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
4596 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
4599 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4600 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4601 RenderableDomainArchitecture rds = null;
4602 if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
4604 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
4606 catch ( final ClassCastException cce ) {
4607 cce.printStackTrace();
4609 if ( rds != null ) {
4610 rds.setRenderingHeight( 6 );
4612 if ( node.getNodeData().isHasTaxonomy() ) {
4613 if ( getControlPanel().isShowTaxonomyCode()
4614 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
4615 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4619 if ( getControlPanel().isShowTaxonomyScientificNames()
4620 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) ) {
4621 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4622 .getScientificName()
4625 if ( getControlPanel().isShowTaxonomyCommonNames()
4626 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) ) {
4627 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4632 if ( node.getNodeData().isHasSequence() ) {
4633 if ( getControlPanel().isShowSeqNames()
4634 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) ) {
4635 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName()
4638 if ( getControlPanel().isShowSeqSymbols()
4639 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) ) {
4640 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol()
4643 if ( getControlPanel().isShowGeneNames()
4644 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getGeneName() ) ) ) {
4645 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getGeneName()
4648 if ( getControlPanel().isShowSequenceAcc()
4649 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4650 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence()
4651 .getAccession().toString()
4654 if ( getControlPanel().isShowAnnotation()
4655 && ( node.getNodeData().getSequence().getAnnotations() != null )
4656 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
4657 x += getTreeFontSet()._fm_large.stringWidth( TreePanelUtil.createAnnotationString( node
4658 .getNodeData().getSequence().getAnnotations(), getOptions()
4659 .isShowAnnotationRefSource() )
4663 if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( node.getName() ) ) {
4664 x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
4666 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
4671 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
4672 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
4673 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
4674 getStatisticsForExpressionValues(),
4675 getConfiguration() );
4678 PhylogenyNode my_node = node;
4679 if ( !getControlPanel().isDrawPhylogram() ) {
4680 my_node = getPhylogeny().getFirstExternalNode();
4682 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
4683 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
4685 if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
4686 x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
4688 rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
4694 final private void paintOvRectangle( final Graphics2D g ) {
4695 final float w_ratio = ( ( float ) getWidth() ) / getVisibleRect().width;
4696 final float h_ratio = ( ( float ) getHeight() ) / getVisibleRect().height;
4697 final float x_ratio = ( ( float ) getWidth() ) / getVisibleRect().x;
4698 final float y_ratio = ( ( float ) getHeight() ) / getVisibleRect().y;
4699 final float width = getOvMaxWidth() / w_ratio;
4700 final float height = getOvMaxHeight() / h_ratio;
4701 final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio );
4702 final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio );
4703 g.setColor( getTreeColorSet().getFoundColor0() );
4704 getOvRectangle().setRect( x, y, width, height );
4705 final Stroke s = g.getStroke();
4706 g.setStroke( STROKE_1 );
4707 if ( ( width < 6 ) && ( height < 6 ) ) {
4708 drawRectFilled( x, y, 6, 6, g );
4709 getOvVirtualRectangle().setRect( x, y, 6, 6 );
4711 else if ( width < 6 ) {
4712 drawRectFilled( x, y, 6, height, g );
4713 getOvVirtualRectangle().setRect( x, y, 6, height );
4715 else if ( height < 6 ) {
4716 drawRectFilled( x, y, width, 6, g );
4717 getOvVirtualRectangle().setRect( x, y, width, 6 );
4720 drawRect( x, y, width, height, g );
4721 if ( isInOvRect() ) {
4722 drawRect( x + 1, y + 1, width - 2, height - 2, g );
4724 getOvVirtualRectangle().setRect( x, y, width, height );
4729 final private void paintPhylogenyLite( final Graphics2D g ) {
4732 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
4733 .getWidth() ) ) ) );
4734 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
4735 final Stroke s = g.getStroke();
4736 g.setStroke( STROKE_05 );
4737 for( final PhylogenyNode element : _nodes_in_preorder ) {
4738 paintNodeLite( g, element );
4741 paintOvRectangle( g );
4745 * Paint the root branch. (Differs from others because it will always be a
4746 * single horizontal line).
4747 * @param to_graphics_file
4749 * @return new x1 value
4751 final private void paintRootBranch( final Graphics2D g,
4754 final PhylogenyNode root,
4755 final boolean to_pdf,
4756 final boolean to_graphics_file ) {
4757 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
4758 float d = getXdistance();
4759 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
4760 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
4762 if ( d < MIN_ROOT_LENGTH ) {
4763 d = MIN_ROOT_LENGTH;
4765 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
4766 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
4769 final double w = PhylogenyMethods.getBranchWidthValue( root );
4770 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
4772 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file );
4775 final private void paintScale( final Graphics2D g,
4778 final boolean to_pdf,
4779 final boolean to_graphics_file ) {
4781 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
4783 final int y2 = y1 - 8;
4784 final int y3 = y1 - 4;
4785 g.setFont( getTreeFontSet().getSmallFont() );
4786 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4787 g.setColor( Color.BLACK );
4790 g.setColor( getTreeColorSet().getBranchLengthColor() );
4792 final Stroke s = g.getStroke();
4793 g.setStroke( STROKE_1 );
4794 drawLine( x1, y1, x1, y2, g );
4795 drawLine( x2, y1, x2, y2, g );
4796 drawLine( x1, y3, x2, y3, g );
4797 if ( getScaleLabel() != null ) {
4798 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
4803 final private int paintTaxonomy( final Graphics2D g,
4804 final PhylogenyNode node,
4805 final boolean is_in_found_nodes,
4806 final boolean to_pdf,
4807 final boolean to_graphics_file,
4808 final double x_shift ) {
4809 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4810 g.setFont( getTreeFontSet().getLargeItalicFont() );
4811 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4812 g.setColor( Color.BLACK );
4814 else if ( is_in_found_nodes ) {
4815 g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
4816 g.setColor( getColorForFoundNode( node ) );
4818 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4819 g.setColor( getTaxonomyBasedColor( node ) );
4821 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
4822 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
4823 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
4825 else if ( to_pdf ) {
4826 g.setColor( Color.BLACK );
4829 g.setColor( getTreeColorSet().getTaxonomyColor() );
4831 final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
4832 final double start_y = node.getYcoord()
4833 + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
4835 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4836 _sb.append( taxonomy.getTaxonomyCode() );
4839 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4840 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4841 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4842 if ( getOptions().isAbbreviateScientificTaxonNames()
4843 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4844 abbreviateScientificName( taxonomy.getScientificName() );
4847 _sb.append( taxonomy.getScientificName() );
4850 _sb.append( taxonomy.getCommonName() );
4853 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4854 if ( getOptions().isAbbreviateScientificTaxonNames()
4855 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4856 abbreviateScientificName( taxonomy.getScientificName() );
4859 _sb.append( taxonomy.getScientificName() );
4863 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4864 _sb.append( taxonomy.getCommonName() );
4868 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4869 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4870 if ( getOptions().isAbbreviateScientificTaxonNames()
4871 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4872 abbreviateScientificName( taxonomy.getScientificName() );
4875 _sb.append( taxonomy.getScientificName() );
4880 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4881 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4882 _sb.append( taxonomy.getCommonName() );
4886 final String label = _sb.toString();
4888 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
4889 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
4890 // invert font color and background color to show that this is the query sequence
4891 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
4895 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
4896 g.setColor( getTreeColorSet().getBackgroundColor() );
4899 TreePanel.drawString( label, start_x, start_y, g );
4900 if ( is_in_found_nodes ) {
4901 return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
4904 return getTreeFontSet()._fm_large_italic.stringWidth( label );
4908 final private void paintUnrooted( final PhylogenyNode n,
4909 final double low_angle,
4910 final double high_angle,
4911 final boolean radial_labels,
4913 final boolean to_pdf,
4914 final boolean to_graphics_file ) {
4916 n.setXcoord( getWidth() / 2 );
4917 n.setYcoord( getHeight() / 2 );
4919 if ( n.isExternal() ) {
4920 paintNodeDataUnrootedCirc( g,
4925 ( high_angle + low_angle ) / 2,
4926 isInFoundNodes( n ) || isInCurrentExternalNodes( n ) );
4929 final float num_enclosed = n.getNumberOfExternalNodes();
4930 final float x = n.getXcoord();
4931 final float y = n.getYcoord();
4932 double current_angle = low_angle;
4933 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
4934 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
4935 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
4936 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
4937 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4938 final PhylogenyNode desc = n.getChildNode( i );
4939 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
4940 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
4941 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
4942 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
4945 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
4948 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
4951 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4952 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4954 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4955 if ( desc.getDistanceToParent() < 0 ) {
4959 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
4963 length = getUrtFactor();
4965 final double mid_angle = current_angle + ( arc_size / 2 );
4966 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
4967 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
4968 desc.setXcoord( new_x );
4969 desc.setYcoord( new_y );
4970 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
4971 current_angle += arc_size;
4972 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
4973 drawLine( x, y, new_x, new_y, g );
4974 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file );
4977 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file );
4981 final private void paintUnrootedLite( final PhylogenyNode n,
4982 final double low_angle,
4983 final double high_angle,
4985 final float urt_ov_factor ) {
4987 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) );
4988 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) );
4989 n.setXSecondary( x_pos );
4990 n.setYSecondary( y_pos );
4992 if ( n.isExternal() ) {
4995 final float num_enclosed = n.getNumberOfExternalNodes();
4996 final float x = n.getXSecondary();
4997 final float y = n.getYSecondary();
4998 double current_angle = low_angle;
4999 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
5000 final PhylogenyNode desc = n.getChildNode( i );
5001 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
5002 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
5004 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
5005 if ( desc.getDistanceToParent() < 0 ) {
5009 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
5013 length = urt_ov_factor;
5015 final double mid_angle = current_angle + ( arc_size / 2 );
5016 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
5017 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
5018 desc.setXSecondary( new_x );
5019 desc.setYSecondary( new_y );
5020 if ( isInFoundNodes( desc ) || isInCurrentExternalNodes( desc ) ) {
5021 g.setColor( getColorForFoundNode( desc ) );
5022 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
5023 g.setColor( getTreeColorSet().getOvColor() );
5025 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
5026 current_angle += arc_size;
5027 drawLine( x, y, new_x, new_y, g );
5031 final private void pasteSubtree( final PhylogenyNode node ) {
5032 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5033 errorMessageNoCutCopyPasteInUnrootedDisplay();
5036 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
5037 JOptionPane.showMessageDialog( this,
5038 "No tree in buffer (need to copy or cut a subtree first)",
5039 "Attempt to paste with empty buffer",
5040 JOptionPane.ERROR_MESSAGE );
5043 final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
5044 final Object[] options = { "As sibling", "As descendant", "Cancel" };
5045 final int r = JOptionPane.showOptionDialog( this,
5046 "How to paste subtree" + label + "?",
5048 JOptionPane.CLOSED_OPTION,
5049 JOptionPane.QUESTION_MESSAGE,
5053 boolean paste_as_sibling = true;
5055 paste_as_sibling = false;
5057 else if ( r != 0 ) {
5060 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
5061 buffer_phy.setAllNodesToNotCollapse();
5062 PhylogenyMethods.preOrderReId( buffer_phy );
5063 buffer_phy.setRooted( true );
5064 boolean need_to_show_whole = false;
5065 if ( paste_as_sibling ) {
5066 if ( node.isRoot() ) {
5067 JOptionPane.showMessageDialog( this,
5068 "Cannot paste sibling to root",
5069 "Attempt to paste sibling to root",
5070 JOptionPane.ERROR_MESSAGE );
5073 buffer_phy.addAsSibling( node );
5076 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
5077 need_to_show_whole = true;
5078 _phylogeny = buffer_phy;
5081 buffer_phy.addAsChild( node );
5084 if ( getCopiedAndPastedNodes() == null ) {
5085 setCopiedAndPastedNodes( new HashSet<Long>() );
5087 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
5088 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
5089 for( final PhylogenyNode n : nodes ) {
5090 node_ids.add( n.getId() );
5092 node_ids.add( node.getId() );
5093 getCopiedAndPastedNodes().addAll( node_ids );
5094 setNodeInPreorderToNull();
5095 _phylogeny.externalNodesHaveChanged();
5096 _phylogeny.clearHashIdToNodeMap();
5097 _phylogeny.recalculateNumberOfExternalDescendants( true );
5098 resetNodeIdToDistToLeafMap();
5100 if ( need_to_show_whole ) {
5101 getControlPanel().showWhole();
5106 private final StringBuffer propertiesToString( final PhylogenyNode node ) {
5107 final PropertiesMap properties = node.getNodeData().getProperties();
5108 final StringBuffer sb = new StringBuffer();
5109 boolean first = true;
5110 for( final String ref : properties.getPropertyRefs() ) {
5117 final Property p = properties.getProperty( ref );
5118 sb.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
5120 sb.append( p.getValue() );
5121 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
5122 sb.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
5128 final private void setCopiedAndPastedNodes( final Set<Long> nodeIds ) {
5129 getMainPanel().setCopiedAndPastedNodes( nodeIds );
5132 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
5133 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
5136 final private void setInOv( final boolean in_ov ) {
5140 final private void setOvMaxHeight( final float ov_max_height ) {
5141 _ov_max_height = ov_max_height;
5144 final private void setOvMaxWidth( final float ov_max_width ) {
5145 _ov_max_width = ov_max_width;
5148 final private void setOvXcorrectionFactor( final float f ) {
5149 _ov_x_correction_factor = f;
5152 final private void setOvXDistance( final float ov_x_distance ) {
5153 _ov_x_distance = ov_x_distance;
5156 final private void setOvXPosition( final int ov_x_position ) {
5157 _ov_x_position = ov_x_position;
5160 final private void setOvYDistance( final float ov_y_distance ) {
5161 _ov_y_distance = ov_y_distance;
5164 final private void setOvYPosition( final int ov_y_position ) {
5165 _ov_y_position = ov_y_position;
5168 final private void setOvYStart( final int ov_y_start ) {
5169 _ov_y_start = ov_y_start;
5172 final private void setScaleDistance( final double scale_distance ) {
5173 _scale_distance = scale_distance;
5176 final private void setScaleLabel( final String scale_label ) {
5177 _scale_label = scale_label;
5180 private final void setupStroke( final Graphics2D g ) {
5181 if ( getYdistance() < 0.001 ) {
5182 g.setStroke( STROKE_005 );
5184 else if ( getYdistance() < 0.01 ) {
5185 g.setStroke( STROKE_01 );
5187 else if ( getYdistance() < 0.5 ) {
5188 g.setStroke( STROKE_025 );
5190 else if ( getYdistance() < 1 ) {
5191 g.setStroke( STROKE_05 );
5193 else if ( getYdistance() < 2 ) {
5194 g.setStroke( STROKE_075 );
5196 else if ( getYdistance() < 20 ) {
5197 g.setStroke( STROKE_1 );
5200 g.setStroke( STROKE_2 );
5204 final private void setUpUrtFactor() {
5205 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
5206 : getVisibleRect().height;
5207 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
5208 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
5211 final int max_depth = _circ_max_depth;
5212 if ( max_depth > 0 ) {
5213 setUrtFactor( d / ( 2 * max_depth ) );
5216 setUrtFactor( d / 2 );
5219 setUrtFactorOv( getUrtFactor() );
5222 final private void setUrtFactor( final float urt_factor ) {
5223 _urt_factor = urt_factor;
5226 final private void setUrtFactorOv( final float urt_factor_ov ) {
5227 _urt_factor_ov = urt_factor_ov;
5230 private void showExtDescNodeData( final PhylogenyNode node ) {
5231 final List<String> data = new ArrayList<String>();
5232 final List<PhylogenyNode> nodes = node.getAllExternalDescendants();
5233 if ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() ) {
5234 for( final PhylogenyNode n : getFoundNodes0AsListOfPhylogenyNodes() ) {
5235 if ( !nodes.contains( n ) ) {
5240 if ( ( getFoundNodes1() != null ) && !getFoundNodes1().isEmpty() ) {
5241 for( final PhylogenyNode n : getFoundNodes1AsListOfPhylogenyNodes() ) {
5242 if ( !nodes.contains( n ) ) {
5247 for( final PhylogenyNode n : nodes ) {
5248 switch ( getOptions().getExtDescNodeDataToReturn() ) {
5250 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
5251 data.add( n.getName() );
5255 if ( n.getNodeData().isHasSequence()
5256 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
5257 data.add( n.getNodeData().getSequence().getName() );
5261 if ( n.getNodeData().isHasSequence()
5262 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
5263 data.add( n.getNodeData().getSequence().getGeneName() );
5266 case SEQUENCE_SYMBOL:
5267 if ( n.getNodeData().isHasSequence()
5268 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
5269 data.add( n.getNodeData().getSequence().getSymbol() );
5272 case SEQUENCE_MOL_SEQ:
5273 if ( n.getNodeData().isHasSequence()
5274 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
5275 data.add( n.getNodeData().getSequence().getMolecularSequence() );
5278 case SEQUENCE_MOL_SEQ_FASTA:
5279 final StringBuilder sb = new StringBuilder();
5280 if ( n.getNodeData().isHasSequence()
5281 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
5282 final StringBuilder ann = new StringBuilder();
5283 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
5284 ann.append( n.getName() );
5287 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
5288 ann.append( "SYM=" );
5289 ann.append( n.getNodeData().getSequence().getSymbol() );
5292 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
5293 ann.append( "NAME=" );
5294 ann.append( n.getNodeData().getSequence().getName() );
5297 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
5298 ann.append( "GN=" );
5299 ann.append( n.getNodeData().getSequence().getGeneName() );
5302 if ( n.getNodeData().getSequence().getAccession() != null ) {
5303 ann.append( "ACC=" );
5304 ann.append( n.getNodeData().getSequence().getAccession().asText() );
5307 if ( n.getNodeData().isHasTaxonomy() ) {
5308 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
5309 ann.append( "TAXID=" );
5310 ann.append( n.getNodeData().getTaxonomy().getTaxonomyCode() );
5313 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
5314 ann.append( "SN=" );
5315 ann.append( n.getNodeData().getTaxonomy().getScientificName() );
5320 if ( ann.charAt( ann.length() - 1 ) == '|' ) {
5321 ann_str = ann.substring( 0, ann.length() - 1 );
5324 ann_str = ann.toString();
5326 sb.append( SequenceWriter.toFasta( ann_str, n.getNodeData().getSequence()
5327 .getMolecularSequence(), 60 ) );
5328 data.add( sb.toString() );
5332 if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
5333 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
5334 data.add( n.getNodeData().getSequence().getAccession().toString() );
5337 case TAXONOMY_SCIENTIFIC_NAME:
5338 if ( n.getNodeData().isHasTaxonomy()
5339 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
5340 data.add( n.getNodeData().getTaxonomy().getScientificName() );
5343 case TAXONOMY_COMM0N_NAME:
5344 if ( n.getNodeData().isHasTaxonomy()
5345 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getCommonName() ) ) {
5346 data.add( n.getNodeData().getTaxonomy().getCommonName() );
5350 if ( n.getNodeData().isHasTaxonomy()
5351 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
5352 data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
5356 TreePanelUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
5359 throw new IllegalArgumentException( "unknown data element: "
5360 + getOptions().getExtDescNodeDataToReturn() );
5363 final StringBuilder sb = new StringBuilder();
5364 final int size = TreePanelUtil.makeSB( data, getOptions(), sb );
5365 if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
5366 || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
5367 if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
5368 System.out.println( sb );
5370 if ( sb.length() < 1 ) {
5371 clearCurrentExternalNodesDataBuffer();
5374 setCurrentExternalNodesDataBuffer( sb );
5377 else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
5378 if ( sb.length() < 1 ) {
5379 TreePanelUtil.showInformationMessage( this, "No Appropriate Data (" + obtainTitleForExtDescNodeData()
5380 + ")", "Descendants of selected node do not contain selected data" );
5381 clearCurrentExternalNodesDataBuffer();
5384 setCurrentExternalNodesDataBuffer( sb );
5386 if ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() ) {
5387 title = ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
5388 : obtainTitleForExtDescNodeData() )
5391 + " nodes, unique entries: "
5395 title = ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
5396 : obtainTitleForExtDescNodeData() )
5400 + node.getNumberOfExternalNodes()
5401 + " external descendats of node "
5403 + ", unique entries: " + size;
5405 final String s = sb.toString().trim();
5406 if ( getMainPanel().getMainFrame() == null ) {
5407 // Must be "E" applet version.
5408 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
5409 ae.showTextFrame( s, title );
5412 getMainPanel().getMainFrame().showTextFrame( s, title );
5418 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
5420 if ( ( node.getName().length() > 0 )
5421 || ( node.getNodeData().isHasTaxonomy() && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData()
5423 || ( node.getNodeData().isHasSequence() && !TreePanelUtil.isSequenceEmpty( node.getNodeData()
5424 .getSequence() ) ) || ( node.getNodeData().isHasDate() )
5425 || ( node.getNodeData().isHasDistribution() ) || node.getBranchData().isHasConfidences() ) {
5426 _popup_buffer.setLength( 0 );
5428 if ( node.getName().length() > 0 ) {
5430 _popup_buffer.append( node.getName() );
5432 if ( node.getNodeData().isHasTaxonomy()
5433 && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
5435 boolean enc_data = false;
5436 final Taxonomy tax = node.getNodeData().getTaxonomy();
5437 if ( _popup_buffer.length() > 0 ) {
5438 _popup_buffer.append( "\n" );
5440 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
5441 _popup_buffer.append( "[" );
5442 _popup_buffer.append( tax.getTaxonomyCode() );
5443 _popup_buffer.append( "]" );
5446 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
5448 _popup_buffer.append( " " );
5450 _popup_buffer.append( tax.getScientificName() );
5453 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
5455 _popup_buffer.append( " (" );
5458 _popup_buffer.append( "(" );
5460 _popup_buffer.append( tax.getCommonName() );
5461 _popup_buffer.append( ")" );
5464 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
5466 _popup_buffer.append( " (" );
5469 _popup_buffer.append( "(" );
5471 _popup_buffer.append( tax.getAuthority() );
5472 _popup_buffer.append( ")" );
5475 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
5477 _popup_buffer.append( " [" );
5480 _popup_buffer.append( "[" );
5482 _popup_buffer.append( tax.getRank() );
5483 _popup_buffer.append( "]" );
5486 if ( tax.getSynonyms().size() > 0 ) {
5488 _popup_buffer.append( " " );
5490 _popup_buffer.append( "[" );
5492 for( final String syn : tax.getSynonyms() ) {
5493 if ( !ForesterUtil.isEmpty( syn ) ) {
5495 _popup_buffer.append( syn );
5496 if ( counter < tax.getSynonyms().size() ) {
5497 _popup_buffer.append( ", " );
5502 _popup_buffer.append( "]" );
5505 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
5506 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
5507 _popup_buffer.append( "[" );
5508 _popup_buffer.append( tax.getIdentifier().getProvider() );
5509 _popup_buffer.append( "] " );
5511 _popup_buffer.append( tax.getIdentifier().getValue() );
5515 if ( node.getNodeData().isHasSequence()
5516 && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) ) {
5518 boolean enc_data = false;
5519 if ( _popup_buffer.length() > 0 ) {
5520 _popup_buffer.append( "\n" );
5522 final Sequence seq = node.getNodeData().getSequence();
5523 if ( seq.getAccession() != null ) {
5524 _popup_buffer.append( "[" );
5525 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
5526 _popup_buffer.append( seq.getAccession().getSource() );
5527 _popup_buffer.append( ":" );
5529 _popup_buffer.append( seq.getAccession().getValue() );
5530 _popup_buffer.append( "]" );
5533 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
5535 _popup_buffer.append( " [" );
5538 _popup_buffer.append( "[" );
5540 _popup_buffer.append( seq.getSymbol() );
5541 _popup_buffer.append( "]" );
5544 if ( !ForesterUtil.isEmpty( seq.getGeneName() ) ) {
5546 _popup_buffer.append( " [" );
5549 _popup_buffer.append( "[" );
5551 _popup_buffer.append( seq.getGeneName() );
5552 _popup_buffer.append( "]" );
5555 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
5557 _popup_buffer.append( " " );
5559 _popup_buffer.append( seq.getName() );
5562 if ( node.getNodeData().isHasDate() ) {
5564 if ( _popup_buffer.length() > 0 ) {
5565 _popup_buffer.append( "\n" );
5567 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
5569 if ( node.getNodeData().isHasDistribution() ) {
5571 if ( _popup_buffer.length() > 0 ) {
5572 _popup_buffer.append( "\n" );
5574 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
5576 if ( node.getBranchData().isHasConfidences() ) {
5577 final List<Confidence> confs = node.getBranchData().getConfidences();
5578 for( final Confidence confidence : confs ) {
5580 if ( _popup_buffer.length() > 0 ) {
5581 _popup_buffer.append( "\n" );
5583 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
5584 _popup_buffer.append( "[" );
5585 _popup_buffer.append( confidence.getType() );
5586 _popup_buffer.append( "] " );
5589 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
5591 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5592 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5593 _popup_buffer.append( " (sd=" );
5594 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence
5595 .getStandardDeviation(), getOptions()
5596 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5597 _popup_buffer.append( ")" );
5601 if ( node.getNodeData().isHasProperties() ) {
5602 final PropertiesMap properties = node.getNodeData().getProperties();
5603 for( final String ref : properties.getPropertyRefs() ) {
5604 _popup_buffer.append( "\n" );
5605 final Property p = properties.getProperty( ref );
5606 _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
5607 _popup_buffer.append( "=" );
5608 _popup_buffer.append( p.getValue() );
5609 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
5610 _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
5614 if ( _popup_buffer.length() > 0 ) {
5615 if ( !getConfiguration().isUseNativeUI() ) {
5617 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
5618 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
5619 if ( isInFoundNodes0( node ) && !isInFoundNodes1( node ) ) {
5620 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0() );
5622 else if ( !isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
5623 _rollover_popup.setForeground( getTreeColorSet().getFoundColor1() );
5625 else if ( isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
5626 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0and1() );
5628 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
5629 _rollover_popup.setForeground( getTaxonomyBasedColor( node ) );
5632 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
5636 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
5638 _rollover_popup.setText( _popup_buffer.toString() );
5639 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
5641 e.getLocationOnScreen().x + 10,
5642 e.getLocationOnScreen().y
5644 _node_desc_popup.show();
5648 catch ( final Exception ex ) {
5653 final private void showNodeEditFrame( final PhylogenyNode n ) {
5654 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5655 // pop up edit box for single node
5656 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
5657 _node_frame_index++;
5660 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5664 final private void showNodeFrame( final PhylogenyNode n ) {
5665 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5666 // pop up edit box for single node
5667 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
5668 _node_frame_index++;
5671 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5675 final private void switchDisplaygetPhylogenyGraphicsType() {
5676 switch ( getPhylogenyGraphicsType() ) {
5678 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5679 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5682 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5683 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5686 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5687 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5690 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5691 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5694 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5695 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5698 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5699 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5702 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5703 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5706 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5707 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5710 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
5712 if ( getControlPanel().getDynamicallyHideData() != null ) {
5713 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5714 getControlPanel().getDynamicallyHideData().setEnabled( false );
5717 getControlPanel().getDynamicallyHideData().setEnabled( true );
5720 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5721 getControlPanel().setDrawPhylogramEnabled( true );
5724 getControlPanel().setDrawPhylogramEnabled( false );
5726 if ( getMainPanel().getMainFrame() == null ) {
5727 // Must be "E" applet version.
5728 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
5729 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5732 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5736 final private static void drawString( final String str, final double x, final double y, final Graphics2D g ) {
5737 g.drawString( str, ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5740 final private static boolean plusPressed( final int key_code ) {
5741 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
5742 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
5745 final private class SubtreeColorizationActionListener implements ActionListener {
5747 JColorChooser _chooser = null;
5748 PhylogenyNode _node = null;
5749 List<PhylogenyNode> _additional_nodes = null;
5751 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
5756 SubtreeColorizationActionListener( final JColorChooser chooser,
5757 final PhylogenyNode node,
5758 final List<PhylogenyNode> additional_nodes ) {
5761 _additional_nodes = additional_nodes;
5765 public void actionPerformed( final ActionEvent e ) {
5766 final Color c = _chooser.getColor();
5768 colorizeSubtree( c, _node, _additional_nodes );