2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.archaeopteryx;
28 import java.awt.BasicStroke;
29 import java.awt.Color;
30 import java.awt.Cursor;
31 import java.awt.Dimension;
33 import java.awt.FontMetrics;
34 import java.awt.GradientPaint;
35 import java.awt.Graphics;
36 import java.awt.Graphics2D;
37 import java.awt.Point;
38 import java.awt.Rectangle;
39 import java.awt.RenderingHints;
40 import java.awt.Stroke;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.ActionListener;
43 import java.awt.event.FocusAdapter;
44 import java.awt.event.FocusEvent;
45 import java.awt.event.InputEvent;
46 import java.awt.event.KeyAdapter;
47 import java.awt.event.KeyEvent;
48 import java.awt.event.MouseEvent;
49 import java.awt.event.MouseWheelEvent;
50 import java.awt.event.MouseWheelListener;
51 import java.awt.font.FontRenderContext;
52 import java.awt.font.TextLayout;
53 import java.awt.geom.AffineTransform;
54 import java.awt.geom.Arc2D;
55 import java.awt.geom.CubicCurve2D;
56 import java.awt.geom.Ellipse2D;
57 import java.awt.geom.Line2D;
58 import java.awt.geom.Path2D;
59 import java.awt.geom.QuadCurve2D;
60 import java.awt.geom.Rectangle2D;
61 import java.awt.image.BufferedImage;
62 import java.awt.print.PageFormat;
63 import java.awt.print.Printable;
64 import java.awt.print.PrinterException;
66 import java.io.IOException;
67 import java.io.UnsupportedEncodingException;
69 import java.net.URISyntaxException;
70 import java.net.URLEncoder;
71 import java.text.DecimalFormat;
72 import java.text.DecimalFormatSymbols;
73 import java.text.NumberFormat;
74 import java.util.ArrayList;
75 import java.util.Collections;
76 import java.util.HashMap;
77 import java.util.HashSet;
78 import java.util.Hashtable;
79 import java.util.List;
81 import java.util.SortedSet;
83 import javax.swing.BorderFactory;
84 import javax.swing.JApplet;
85 import javax.swing.JColorChooser;
86 import javax.swing.JDialog;
87 import javax.swing.JMenuItem;
88 import javax.swing.JOptionPane;
89 import javax.swing.JPanel;
90 import javax.swing.JPopupMenu;
91 import javax.swing.JTextArea;
92 import javax.swing.Popup;
93 import javax.swing.PopupFactory;
95 import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON;
96 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
97 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
98 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
99 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
100 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
101 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
102 import org.forester.archaeopteryx.tools.Blast;
103 import org.forester.archaeopteryx.tools.ImageLoader;
104 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
105 import org.forester.io.writers.SequenceWriter;
106 import org.forester.phylogeny.Phylogeny;
107 import org.forester.phylogeny.PhylogenyMethods;
108 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
109 import org.forester.phylogeny.PhylogenyNode;
110 import org.forester.phylogeny.data.Accession;
111 import org.forester.phylogeny.data.Annotation;
112 import org.forester.phylogeny.data.BranchColor;
113 import org.forester.phylogeny.data.Confidence;
114 import org.forester.phylogeny.data.DomainArchitecture;
115 import org.forester.phylogeny.data.Event;
116 import org.forester.phylogeny.data.NodeData.NODE_DATA;
117 import org.forester.phylogeny.data.NodeVisualData;
118 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
119 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
120 import org.forester.phylogeny.data.PhylogenyDataUtil;
121 import org.forester.phylogeny.data.PropertiesMap;
122 import org.forester.phylogeny.data.Property;
123 import org.forester.phylogeny.data.Sequence;
124 import org.forester.phylogeny.data.SequenceRelation;
125 import org.forester.phylogeny.data.Taxonomy;
126 import org.forester.phylogeny.data.Uri;
127 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
128 import org.forester.phylogeny.iterators.PreorderTreeIterator;
129 import org.forester.util.BasicDescriptiveStatistics;
130 import org.forester.util.DescriptiveStatistics;
131 import org.forester.util.ForesterConstants;
132 import org.forester.util.ForesterUtil;
133 import org.forester.util.SequenceAccessionTools;
134 import org.forester.util.TaxonomyUtil;
136 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
138 final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
139 final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
140 final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
141 final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
142 final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
143 final private static double _180_OVER_PI = 180.0 / Math.PI;
144 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
145 private final static int CONFIDENCE_LEFT_MARGIN = 4;
146 private final static int EURO_D = 10;
147 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
148 private final static NumberFormat FORMATTER_CONFIDENCE;
149 private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
150 private final static int LIMIT_FOR_HQ_RENDERING = 2000;
151 private final static int MAX_NODE_FRAMES = 10;
152 private final static int MAX_SUBTREES = 100;
153 private final static int MIN_ROOT_LENGTH = 3;
154 private final static int MOVE = 20;
155 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
156 private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
157 private static final short OV_BORDER = 10;
158 private final static double OVERVIEW_FOUND_NODE_BOX_SIZE = 2;
159 private final static double OVERVIEW_FOUND_NODE_BOX_SIZE_HALF = 1;
160 private static final float PI = ( float ) ( Math.PI );
161 final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(),
164 private static final float ROUNDED_D = 8;
165 private final static long serialVersionUID = -978349745916505029L;
166 private static final BasicStroke STROKE_005 = new BasicStroke( 0.05f );
167 private static final BasicStroke STROKE_01 = new BasicStroke( 0.1f );
168 private static final BasicStroke STROKE_025 = new BasicStroke( 0.25f );
169 private static final BasicStroke STROKE_05 = new BasicStroke( 0.5f );
170 private static final BasicStroke STROKE_075 = new BasicStroke( 0.75f );
171 private static final BasicStroke STROKE_1 = new BasicStroke( 1f );
172 private static final BasicStroke STROKE_2 = new BasicStroke( 2f );
173 private static final double TWO_PI = 2 * Math.PI;
174 private final static int WIGGLE = 2;
175 HashMap<Long, Short> _nodeid_dist_to_leaf = new HashMap<Long, Short>();
176 final private Arc2D _arc = new Arc2D.Double();
177 private AffineTransform _at;
178 private int _circ_max_depth;
179 final private Set<Long> _collapsed_external_nodeid_set = new HashSet<Long>();
180 private JColorChooser _color_chooser = null;
181 private Configuration _configuration = null;
182 private ControlPanel _control_panel = null;
183 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
184 private Set<Long> _current_external_nodes = null;
185 private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
186 private int _current_external_nodes_data_buffer_change_counter = 0;
187 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
188 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
189 private int _dynamic_hiding_factor = 0;
190 private boolean _edited = false;
191 private final Ellipse2D _ellipse = new Ellipse2D.Float();
192 private int _external_node_index = 0;
193 private Set<Long> _found_nodes_0 = null;
194 private Set<Long> _found_nodes_1 = null;
195 private final FontRenderContext _frc = new FontRenderContext( null,
198 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
199 private PhylogenyNode _highlight_node = null;
200 private boolean _in_ov = false;
201 private boolean _in_ov_rect = false;
202 private float _last_drag_point_x = 0;
203 private float _last_drag_point_y = 0;
204 private final Line2D _line = new Line2D.Float();
205 private int _longest_ext_node_info = 0;
206 private PhylogenyNode _ext_node_with_longest_txt_info = null;
207 private MainPanel _main_panel = null;
208 private double _max_distance_to_root = -1;
209 private Popup _node_desc_popup;
210 private int _node_frame_index = 0;
211 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
212 private JPopupMenu _node_popup_menu = null;
213 private JMenuItem _node_popup_menu_items[] = null;
214 private PhylogenyNode[] _nodes_in_preorder = null;
215 private Options _options = null;
216 private float _ov_max_height = 0;
217 private float _ov_max_width = 0;
218 private boolean _ov_on = false;
219 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
220 private final Rectangle _ov_virtual_rectangle = new Rectangle();
221 private float _ov_x_correction_factor = 0.0f;
222 private float _ov_x_distance = 0;
223 private int _ov_x_position = 0;
224 private float _ov_y_distance = 0;
225 private int _ov_y_position = 0;
226 private int _ov_y_start = 0;
227 private final boolean _phy_has_branch_lengths;
228 private Phylogeny _phylogeny = null;
229 private final Path2D.Float _polygon = new Path2D.Float();
230 private final StringBuffer _popup_buffer = new StringBuffer();
231 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
232 private Sequence _query_sequence = null;
233 private final Rectangle2D _rectangle = new Rectangle2D.Float();
234 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
235 RenderingHints.VALUE_RENDER_DEFAULT );
236 private JTextArea _rollover_popup;
237 private PhylogenyNode _root;
238 private final StringBuilder _sb = new StringBuilder();
239 private double _scale_distance = 0.0;
240 private String _scale_label = null;
241 private DescriptiveStatistics _statistics_for_vector_data;
242 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
243 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
244 private int _subtree_index = 0;
245 private File _treefile = null;
246 private float _urt_factor = 1;
247 private float _urt_factor_ov = 1;
248 final private HashMap<Long, Double> _urt_nodeid_angle_map = new HashMap<Long, Double>();
249 final private HashMap<Long, Integer> _urt_nodeid_index_map = new HashMap<Long, Integer>();
250 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
251 private float _x_correction_factor = 0.0f;
252 private float _x_distance = 0.0f;
253 private float _y_distance = 0.0f;
255 // private Image offscreenImage;
256 // private Graphics offscreenGraphics;
257 // private Dimension offscreenDimension;
259 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
260 dfs.setDecimalSeparator( '.' );
261 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
262 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
265 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
266 requestFocusInWindow();
267 addKeyListener( new KeyAdapter() {
270 public void keyPressed( final KeyEvent key_event ) {
271 keyPressedCalls( key_event );
272 requestFocusInWindow();
275 addFocusListener( new FocusAdapter() {
278 public void focusGained( final FocusEvent e ) {
279 requestFocusInWindow();
282 if ( ( t == null ) || t.isEmpty() ) {
283 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
285 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
287 _configuration = configuration;
289 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
291 // if ( !_phylogeny.isEmpty() ) {
292 _phylogeny.recalculateNumberOfExternalDescendants( true );
293 checkForVectorProperties( _phylogeny );
295 setBackground( getTreeColorSet().getBackgroundColor() );
296 final MouseListener mouse_listener = new MouseListener( this );
297 addMouseListener( mouse_listener );
298 addMouseMotionListener( mouse_listener );
299 addMouseWheelListener( this );
300 calculateScaleDistance();
301 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
302 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
303 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
307 final public void actionPerformed( final ActionEvent e ) {
308 boolean done = false;
309 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
310 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
311 // NOTE: index corresponds to the indices of click-to options
312 // in the control panel.
313 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
314 // Set this as the new default click-to action
315 _main_panel.getControlPanel().setClickToAction( index );
316 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
317 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
318 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
323 requestFocusInWindow();
326 public synchronized Hashtable<String, BufferedImage> getImageMap() {
327 return getMainPanel().getImageMap();
330 final public MainPanel getMainPanel() {
335 * Get a pointer to the phylogeny
337 * @return a pointer to the phylogeny
339 public final Phylogeny getPhylogeny() {
344 final public void mouseWheelMoved( final MouseWheelEvent e ) {
345 final int notches = e.getWheelRotation();
346 if ( inOvVirtualRectangle( e ) ) {
347 if ( !isInOvRect() ) {
353 if ( isInOvRect() ) {
354 setInOvRect( false );
358 if ( e.isControlDown() ) {
360 getTreeFontSet().increaseFontSize();
361 getControlPanel().displayedPhylogenyMightHaveChanged( true );
364 getTreeFontSet().decreaseFontSize( 1, false );
365 getControlPanel().displayedPhylogenyMightHaveChanged( true );
368 else if ( e.isShiftDown() ) {
369 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
370 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
372 for( int i = 0; i < ( -notches ); ++i ) {
373 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
374 getControlPanel().displayedPhylogenyMightHaveChanged( false );
378 for( int i = 0; i < notches; ++i ) {
379 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
380 if ( getStartingAngle() < 0 ) {
381 setStartingAngle( TWO_PI + getStartingAngle() );
383 getControlPanel().displayedPhylogenyMightHaveChanged( false );
389 for( int i = 0; i < ( -notches ); ++i ) {
390 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
391 getControlPanel().displayedPhylogenyMightHaveChanged( false );
395 for( int i = 0; i < notches; ++i ) {
396 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
397 getControlPanel().displayedPhylogenyMightHaveChanged( false );
404 for( int i = 0; i < ( -notches ); ++i ) {
405 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
406 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
407 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
408 getControlPanel().displayedPhylogenyMightHaveChanged( false );
412 for( int i = 0; i < notches; ++i ) {
413 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
414 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
415 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
416 getControlPanel().displayedPhylogenyMightHaveChanged( false );
421 requestFocusInWindow();
426 final public void paintComponent( final Graphics g ) {
427 // Dimension currentSize = getSize();
428 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
429 // call the 'java.awt.Component.createImage(...)' method to get an
431 // offscreenImage = createImage( currentSize.width, currentSize.height );
432 // offscreenGraphics = offscreenImage.getGraphics();
433 // offscreenDimension = currentSize;
435 // super.paintComponent( g ); //why?
436 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
437 final Graphics2D g2d = ( Graphics2D ) g;
438 g2d.setRenderingHints( _rendering_hints );
439 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
440 //g.drawImage( offscreenImage, 0, 0, this );
444 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
445 throws PrinterException {
446 if ( page_index > 0 ) {
447 return ( NO_SUCH_PAGE );
450 final Graphics2D g2d = ( Graphics2D ) g;
451 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
452 // Turn off double buffering !?
453 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
454 // Turn double buffering back on !?
455 return ( PAGE_EXISTS );
459 public final void setEdited( final boolean edited ) {
463 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
464 getMainPanel().setImageMap( image_map );
468 * Set a phylogeny tree.
471 * an instance of a Phylogeny
473 public final void setTree( final Phylogeny t ) {
474 setNodeInPreorderToNull();
478 public final void setWaitCursor() {
479 setCursor( WAIT_CURSOR );
484 public void update( final Graphics g ) {
488 final void calcMaxDepth() {
489 if ( _phylogeny != null ) {
490 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
495 * Set parameters for printing the displayed tree
498 final void calcParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
499 // updateStyle(); not needed?
500 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
502 if ( recalc_longest_ext_node_info ) {
503 calculateLongestExtNodeInfo();
504 if ( getOptions().isAllowFontSizeChange() ) {
505 if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
506 && ( getTreeFontSet().getLargeFont().getSize() > ( 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
507 while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) )
508 && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) {
509 getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(),
511 calculateLongestExtNodeInfo();
515 while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) )
516 && ( getTreeFontSet().getLargeFont().getSize() <= ( getTreeFontSet()
517 .getLargeFontMemory().getSize() - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
518 getMainPanel().getTreeFontSet().increaseFontSize();
519 calculateLongestExtNodeInfo();
524 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
525 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
526 if ( ext_nodes == 1 ) {
527 ext_nodes = max_depth;
528 if ( ext_nodes < 1 ) {
535 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
536 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
537 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
540 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
541 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
543 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
547 if ( ov_xdist < 0.0 ) {
553 setXdistance( xdist );
554 setYdistance( ydist );
555 setOvXDistance( ov_xdist );
556 final double height = _phylogeny.getHeight();
558 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
559 setXcorrectionFactor( corr > 0 ? corr : 0 );
560 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
561 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
564 setXcorrectionFactor( 0 );
565 setOvXcorrectionFactor( 0 );
567 _circ_max_depth = max_depth;
570 if ( getOptions().isAllowFontSizeChange() ) {
571 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
572 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
573 // int dynamic_hiding_factor = calcDynamicHidingFactor();
574 // if ( dynamic_hiding_factor > 1 ) {
575 // while ( dynamic_hiding_factor > 1
576 // && getTreeFontSet()._fm_large.getHeight() > TreeFontSet.SMALL_FONTS_BASE ) {
577 // getTreeFontSet().decreaseFontSize( 1, true );
578 // dynamic_hiding_factor = calcDynamicHidingFactor();
581 // else if ( getTreeFontSet().isDecreasedSizeBySystem() ) {
582 // while ( dynamic_hiding_factor < 1 && getTreeFontSet()._fm_large.getHeight() < 12 ) {
583 // getTreeFontSet().increaseFontSize();
584 // dynamic_hiding_factor = calcDynamicHidingFactor();
593 final void calculateLongestExtNodeInfo() {
594 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
597 int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - MOVE )
598 * Constants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
599 if ( max_length < 40 ) {
604 PhylogenyNode longest_txt_node = _phylogeny.getFirstExternalNode();
605 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
607 if ( node.isCollapse() ) {
610 final StringBuilder sb = new StringBuilder();
611 nodeDataAsSB( node, sb );
612 if ( node.getNodeData().isHasTaxonomy() ) {
613 nodeTaxonomyDataAsSB( node.getNodeData().getTaxonomy(), sb );
615 final int txt = sb.length();
616 if ( txt > longest_txt ) {
618 longest_txt_node = node;
620 boolean use_vis = false;
621 final Graphics2D g = ( Graphics2D ) getGraphics();
622 if ( getControlPanel().isUseVisualStyles() ) {
623 use_vis = setFont( g, node, false );
626 sum = getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
629 sum = getFontMetrics( g.getFont() ).stringWidth( sb.toString() );
631 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
632 sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getBinaryCharacters()
633 .getGainedCharactersAsStringBuffer().toString() );
635 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
636 && ( node.getNodeData().getVector().size() > 0 ) ) {
637 if ( getConfiguration() != null ) {
638 sum += getConfiguration().getVectorDataWidth() + 10;
641 sum += RenderableVector.VECTOR_DEFAULT_WIDTH + 10;
644 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
645 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
647 // TODO this might need some clean up
648 final DomainArchitecture d = node.getNodeData().getSequence().getDomainArchitecture();
649 sum += ( ( _domain_structure_width / ( ( RenderableDomainArchitecture ) d ).getOriginalSize()
650 .getWidth() ) * d.getTotalLength() ) + 10;
652 if ( sum >= max_length ) {
653 _longest_ext_node_info = max_length;
656 if ( sum > longest ) {
660 _ext_node_with_longest_txt_info = longest_txt_node;
661 if ( longest >= max_length ) {
662 _longest_ext_node_info = max_length;
665 _longest_ext_node_info = longest;
669 final void calculateScaleDistance() {
670 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
673 final double height = getMaxDistanceToRoot();
675 if ( ( height <= 0.5 ) ) {
676 setScaleDistance( 0.01 );
678 else if ( height <= 5.0 ) {
679 setScaleDistance( 0.1 );
681 else if ( height <= 50.0 ) {
682 setScaleDistance( 1 );
684 else if ( height <= 500.0 ) {
685 setScaleDistance( 10 );
688 setScaleDistance( 100 );
692 setScaleDistance( 0.0 );
694 String scale_label = String.valueOf( getScaleDistance() );
695 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
696 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
698 setScaleLabel( scale_label );
701 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
702 if ( getOptions().isColorByTaxonomicGroup() ) {
703 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
707 group = TaxonomyUtil.getTaxGroupByTaxCode( tax.getTaxonomyCode() );
709 catch ( final Exception e ) {
712 if ( !ex && !ForesterUtil.isEmpty( group ) ) {
713 final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group );
719 return getTreeColorSet().getTaxonomyColor();
722 if ( ForesterUtil.isEmpty( tax.getTaxonomyCode() ) && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
723 return getTreeColorSet().getTaxonomyColor();
726 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
727 c = getControlPanel().getSpeciesColors().get( tax.getTaxonomyCode() );
729 if ( ( c == null ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
730 c = getControlPanel().getSpeciesColors().get( tax.getScientificName() );
733 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
734 c = TreePanelUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
735 getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c );
738 c = TreePanelUtil.calculateColorFromString( tax.getScientificName(), true );
739 getControlPanel().getSpeciesColors().put( tax.getScientificName(), c );
746 final Color calculateSequenceBasedColor( final Sequence seq ) {
747 if ( ForesterUtil.isEmpty( seq.getName() ) ) {
748 return getTreeColorSet().getSequenceColor();
751 final String seq_name = seq.getName();
752 c = getControlPanel().getSequenceColors().get( seq_name );
754 c = TreePanelUtil.calculateColorFromString( seq_name, false );
755 getControlPanel().getSequenceColors().put( seq_name, c );
760 void checkForVectorProperties( final Phylogeny phy ) {
761 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
762 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
763 final PhylogenyNode node = iter.next();
764 if ( node.getNodeData().getProperties() != null ) {
765 final PropertiesMap pm = node.getNodeData().getProperties();
766 final double[] vector = new double[ pm.getProperties().size() ];
768 for( final String ref : pm.getProperties().keySet() ) {
769 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
770 final Property p = pm.getProperty( ref );
771 final String value_str = p.getValue();
772 final String index_str = ref
773 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
776 d = Double.parseDouble( value_str );
778 catch ( final NumberFormatException e ) {
779 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
780 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
785 i = Integer.parseInt( index_str );
787 catch ( final NumberFormatException e ) {
788 JOptionPane.showMessageDialog( this,
789 "Could not parse \"" + index_str
790 + "\" into index for vector data",
791 "Problem with Vector Data",
792 JOptionPane.ERROR_MESSAGE );
796 JOptionPane.showMessageDialog( this,
797 "Attempt to use negative index for vector data",
798 "Problem with Vector Data",
799 JOptionPane.ERROR_MESSAGE );
807 final List<Double> vector_l = new ArrayList<Double>( counter );
808 for( int i = 0; i < counter; ++i ) {
809 vector_l.add( vector[ i ] );
811 node.getNodeData().setVector( vector_l );
814 if ( stats.getN() > 0 ) {
815 _statistics_for_vector_data = stats;
819 void clearCurrentExternalNodesDataBuffer() {
820 setCurrentExternalNodesDataBuffer( new StringBuilder() );
824 * Collapse the tree from the given node
829 final void collapse( final PhylogenyNode node ) {
830 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
831 JOptionPane.showMessageDialog( this,
832 "Cannot collapse in unrooted display type",
833 "Attempt to collapse in unrooted display",
834 JOptionPane.WARNING_MESSAGE );
837 if ( !node.isExternal() && !node.isRoot() ) {
838 final boolean collapse = !node.isCollapse();
839 TreePanelUtil.collapseSubtree( node, collapse );
840 updateSetOfCollapsedExternalNodes();
841 _phylogeny.recalculateNumberOfExternalDescendants( true );
842 resetNodeIdToDistToLeafMap();
843 calculateLongestExtNodeInfo();
844 setNodeInPreorderToNull();
845 _control_panel.displayedPhylogenyMightHaveChanged( true );
846 resetPreferredSize();
848 _main_panel.adjustJScrollPane();
853 final void collapseSpeciesSpecificSubtrees() {
854 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
858 TreePanelUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
859 updateSetOfCollapsedExternalNodes();
860 _phylogeny.recalculateNumberOfExternalDescendants( true );
861 resetNodeIdToDistToLeafMap();
862 calculateLongestExtNodeInfo();
863 setNodeInPreorderToNull();
864 resetPreferredSize();
865 _main_panel.adjustJScrollPane();
870 final void colorRank( final String rank ) {
871 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
875 AptxUtil.removeBranchColors( _phylogeny );
876 final int colorizations = TreePanelUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
877 if ( colorizations > 0 ) {
878 _control_panel.setColorBranches( true );
879 if ( _control_panel.getUseVisualStylesCb() != null ) {
880 _control_panel.getUseVisualStylesCb().setSelected( true );
882 if ( _control_panel.getColorAccSpeciesCb() != null ) {
883 _control_panel.getColorAccSpeciesCb().setSelected( false );
885 _options.setColorLabelsSameAsParentBranch( true );
886 _control_panel.repaint();
890 if ( colorizations > 0 ) {
891 String msg = "Taxonomy colorization via " + rank + " completed:\n";
892 if ( colorizations > 1 ) {
893 msg += "colorized " + colorizations + " subtrees";
896 msg += "colorized one subtree";
899 JOptionPane.showMessageDialog( this,
901 "Taxonomy Colorization Completed (" + rank + ")",
902 JOptionPane.INFORMATION_MESSAGE );
905 String msg = "Could not taxonomy colorize any subtree via " + rank + ".\n";
906 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
907 msg += "select a different rank (e.g. phylum, genus, ...)\n";
910 msg += "1. \"" + MainFrameApplication.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
911 msg += "2. \"" + MainFrameApplication.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
912 JOptionPane.showMessageDialog( this, msg, "Taxonomy Colorization Failed", JOptionPane.WARNING_MESSAGE );
916 final void confColor() {
917 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
921 AptxUtil.removeBranchColors( _phylogeny );
922 TreePanelUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
923 _control_panel.setColorBranches( true );
924 if ( _control_panel.getUseVisualStylesCb() != null ) {
925 _control_panel.getUseVisualStylesCb().setSelected( true );
931 final void decreaseDomainStructureEvalueThreshold() {
932 if ( _domain_structure_e_value_thr_exp > -20 ) {
933 _domain_structure_e_value_thr_exp -= 1;
938 * Find the node, if any, at the given location
942 * @return pointer to the node at x,y, null if not found
944 final PhylogenyNode findNode( final int x, final int y ) {
945 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
948 final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE;
949 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
950 final PhylogenyNode node = iter.next();
951 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
952 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
953 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
954 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
955 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
962 final Configuration getConfiguration() {
963 return _configuration;
966 final ControlPanel getControlPanel() {
967 return _control_panel;
970 String getCurrentExternalNodesDataBufferAsString() {
971 return _current_external_nodes_data_buffer.toString();
974 int getCurrentExternalNodesDataBufferChangeCounter() {
975 return _current_external_nodes_data_buffer_change_counter;
978 final int getDomainStructureEvalueThreshold() {
979 return _domain_structure_e_value_thr_exp;
982 final Set<Long> getFoundNodes0() {
983 return _found_nodes_0;
986 final Set<Long> getFoundNodes1() {
987 return _found_nodes_1;
990 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
991 if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
992 return ( PhylogenyMethods.getBranchColorValue( node ) );
995 return ( getTreeColorSet().getBranchColor() );
999 final int getLongestExtNodeInfo() {
1000 return _longest_ext_node_info;
1003 final Options getOptions() {
1004 if ( _options == null ) {
1005 _options = getControlPanel().getOptions();
1010 final Rectangle2D getOvRectangle() {
1011 return _ov_rectangle;
1014 final Rectangle getOvVirtualRectangle() {
1015 return _ov_virtual_rectangle;
1018 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
1019 return _graphics_type;
1022 final double getStartingAngle() {
1023 return _urt_starting_angle;
1026 DescriptiveStatistics getStatisticsForExpressionValues() {
1027 return _statistics_for_vector_data;
1030 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
1031 if ( node.getNodeData().isHasTaxonomy() ) {
1032 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
1034 // return non-colorized color
1035 return getTreeColorSet().getTaxonomyColor();
1038 final Color getSequenceBasedColor( final PhylogenyNode node ) {
1039 if ( node.getNodeData().isHasSequence() ) {
1040 return calculateSequenceBasedColor( node.getNodeData().getSequence() );
1042 // return non-colorized color
1043 return getTreeColorSet().getSequenceColor();
1047 * @return pointer to colorset for tree drawing
1049 final TreeColorSet getTreeColorSet() {
1050 return getMainPanel().getTreeColorSet();
1053 final File getTreeFile() {
1057 final float getXcorrectionFactor() {
1058 return _x_correction_factor;
1061 final float getXdistance() {
1065 final float getYdistance() {
1069 final void increaseDomainStructureEvalueThreshold() {
1070 if ( _domain_structure_e_value_thr_exp < 3 ) {
1071 _domain_structure_e_value_thr_exp += 1;
1075 final void initNodeData() {
1076 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1079 double _max_original_domain_structure_width = 0.0;
1080 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1081 if ( node.getNodeData().isHasSequence()
1082 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1083 RenderableDomainArchitecture rds = null;
1084 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
1085 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
1086 getConfiguration() );
1087 node.getNodeData().getSequence().setDomainArchitecture( rds );
1090 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1092 if ( getControlPanel().isShowDomainArchitectures() ) {
1093 final double dsw = rds.getOriginalSize().getWidth();
1094 if ( dsw > _max_original_domain_structure_width ) {
1095 _max_original_domain_structure_width = dsw;
1100 if ( getControlPanel().isShowDomainArchitectures() ) {
1101 final double ds_factor_width = _domain_structure_width / _max_original_domain_structure_width;
1102 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1103 if ( node.getNodeData().isHasSequence()
1104 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1105 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1106 .getSequence().getDomainArchitecture();
1107 rds.setRenderingFactorWidth( ds_factor_width );
1108 rds.setParameter( _domain_structure_e_value_thr_exp );
1114 final boolean inOv( final MouseEvent e ) {
1115 return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) )
1116 && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) )
1117 && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) ) && ( e.getY() < ( ( getVisibleRect().y
1118 + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) );
1121 final boolean inOvRectangle( final MouseEvent e ) {
1122 return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) )
1123 && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) )
1124 && ( e.getY() >= ( getOvRectangle().getY() - 1 ) ) && ( e.getY() <= ( getOvRectangle().getY()
1125 + getOvRectangle().getHeight() + 1 ) ) );
1128 final boolean isApplet() {
1129 return getMainPanel() instanceof MainPanelApplets;
1132 final boolean isCanCollapse() {
1133 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1136 final boolean isCanColorSubtree() {
1137 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1140 final boolean isCanCopy() {
1141 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1144 final boolean isCanCut( final PhylogenyNode node ) {
1145 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1149 final boolean isCanDelete() {
1150 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1153 final boolean isCanPaste() {
1154 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1155 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1158 final boolean isCanReroot() {
1159 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1162 final boolean isCanSubtree( final PhylogenyNode node ) {
1163 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1164 .isRoot() || ( _subtree_index > 0 ) ) );
1167 final boolean isCurrentTreeIsSubtree() {
1168 return ( _subtree_index > 0 );
1171 final boolean isEdited() {
1175 final boolean isInOvRect() {
1179 final boolean isOvOn() {
1183 final boolean isPhyHasBranchLengths() {
1184 return _phy_has_branch_lengths;
1187 final void midpointRoot() {
1188 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1191 if ( !_phylogeny.isRerootable() ) {
1192 JOptionPane.showMessageDialog( this,
1193 "This is not rerootable",
1195 JOptionPane.WARNING_MESSAGE );
1198 setNodeInPreorderToNull();
1200 PhylogenyMethods.midpointRoot( _phylogeny );
1201 resetNodeIdToDistToLeafMap();
1207 final void mouseClicked( final MouseEvent e ) {
1208 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1209 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1210 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1211 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) )
1213 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) )
1221 final double max_x = getWidth() - getVisibleRect().width;
1222 final double max_y = getHeight() - getVisibleRect().height;
1229 getMainPanel().getCurrentScrollPane().getViewport()
1230 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1231 setInOvRect( true );
1235 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1236 if ( node != null ) {
1237 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1240 _highlight_node = node;
1241 // Check if shift key is down
1242 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1243 // Yes, so add to _found_nodes
1244 if ( getFoundNodes0() == null ) {
1245 setFoundNodes0( new HashSet<Long>() );
1247 getFoundNodes0().add( node.getId() );
1248 // Check if control key is down
1250 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1251 // Yes, so pop-up menu
1252 displayNodePopupMenu( node, e.getX(), e.getY() );
1253 // Handle unadorned click
1256 // Check for right mouse button
1257 if ( e.getModifiers() == 4 ) {
1258 displayNodePopupMenu( node, e.getX(), e.getY() );
1261 // if not in _found_nodes, clear _found_nodes
1262 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1267 // no node was clicked
1268 _highlight_node = null;
1274 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1275 setCursor( MOVE_CURSOR );
1276 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1277 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1278 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1279 if ( scroll_position.x < 0 ) {
1280 scroll_position.x = 0;
1283 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1284 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1285 if ( scroll_position.x > max_x ) {
1286 scroll_position.x = max_x;
1289 if ( scroll_position.y < 0 ) {
1290 scroll_position.y = 0;
1293 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1294 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1295 if ( scroll_position.y > max_y ) {
1296 scroll_position.y = max_y;
1299 if ( isOvOn() || getOptions().isShowScale() ) {
1302 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1305 final void mouseDragInOvRectangle( final MouseEvent e ) {
1306 setCursor( HAND_CURSOR );
1307 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1308 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1309 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1310 double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) );
1311 double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) );
1312 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1313 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1314 if ( scroll_position.x <= 0 ) {
1315 scroll_position.x = 0;
1319 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1320 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1321 if ( scroll_position.x >= max_x ) {
1323 scroll_position.x = max_x;
1326 if ( scroll_position.y <= 0 ) {
1328 scroll_position.y = 0;
1331 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1332 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1333 if ( scroll_position.y >= max_y ) {
1335 scroll_position.y = max_y;
1339 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1340 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1341 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1344 final void mouseMoved( final MouseEvent e ) {
1345 requestFocusInWindow();
1346 if ( _current_external_nodes != null ) {
1347 _current_external_nodes = null;
1350 if ( getControlPanel().isNodeDescPopup() ) {
1351 if ( _node_desc_popup != null ) {
1352 _node_desc_popup.hide();
1353 _node_desc_popup = null;
1356 if ( getOptions().isShowOverview() && isOvOn() ) {
1357 if ( inOvVirtualRectangle( e ) ) {
1358 if ( !isInOvRect() ) {
1359 setInOvRect( true );
1364 if ( isInOvRect() ) {
1365 setInOvRect( false );
1370 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
1379 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1380 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
1381 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.GET_EXT_DESC_DATA ) ) {
1382 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
1383 addToCurrentExternalNodes( n.getId() );
1385 setCursor( HAND_CURSOR );
1388 else if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
1389 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
1390 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
1391 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
1392 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
1393 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
1394 setCursor( CUT_CURSOR );
1397 setCursor( HAND_CURSOR );
1398 if ( getControlPanel().isNodeDescPopup() ) {
1399 showNodeDataPopup( e, node );
1404 setCursor( ARROW_CURSOR );
1409 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
1410 setCursor( ARROW_CURSOR );
1413 final void multiplyUrtFactor( final float f ) {
1417 final JApplet obtainApplet() {
1418 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1421 final void paintBranchCircular( final PhylogenyNode p,
1422 final PhylogenyNode c,
1424 final boolean radial_labels,
1425 final boolean to_pdf,
1426 final boolean to_graphics_file ) {
1427 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1428 final double root_x = _root.getXcoord();
1429 final double root_y = _root.getYcoord();
1430 final double dx = root_x - p.getXcoord();
1431 final double dy = root_y - p.getYcoord();
1432 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1433 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1434 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
1435 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
1436 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
1437 final double r2 = 2.0 * parent_radius;
1438 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1440 drawLine( c.getXcoord(),
1442 root_x + ( Math.cos( angle ) * parent_radius ),
1443 root_y + ( Math.sin( angle ) * parent_radius ),
1445 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file );
1446 if ( c.isExternal() ) {
1447 final boolean is_in_found_nodes = isInFoundNodes0( c ) || isInFoundNodes1( c )
1448 || isInCurrentExternalNodes( c );
1449 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
1450 && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
1453 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
1457 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
1458 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1459 final double root_x = _root.getXSecondary();
1460 final double root_y = _root.getYSecondary();
1461 final double dx = root_x - p.getXSecondary();
1462 final double dy = root_y - p.getYSecondary();
1463 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1464 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1465 g.setColor( getTreeColorSet().getOvColor() );
1466 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
1467 final double r2 = 2.0 * parent_radius;
1468 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1470 drawLine( c.getXSecondary(),
1472 root_x + ( Math.cos( angle ) * parent_radius ),
1473 root_y + ( Math.sin( angle ) * parent_radius ),
1475 if ( isInFoundNodes( c ) || isInCurrentExternalNodes( c ) ) {
1476 g.setColor( getColorForFoundNode( c ) );
1477 drawRectFilled( c.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, c.getYSecondary()
1478 - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, OVERVIEW_FOUND_NODE_BOX_SIZE, OVERVIEW_FOUND_NODE_BOX_SIZE, g );
1482 final void paintCircular( final Phylogeny phy,
1483 final double starting_angle,
1488 final boolean to_pdf,
1489 final boolean to_graphics_file ) {
1490 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
1491 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
1492 _root = phy.getRoot();
1493 _root.setXcoord( center_x );
1494 _root.setYcoord( center_y );
1495 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1496 double current_angle = starting_angle;
1498 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1499 final PhylogenyNode n = it.next();
1500 if ( !n.isCollapse() ) {
1501 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1502 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1503 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1504 _urt_nodeid_index_map.put( n.getId(), i++ );
1505 current_angle += ( TWO_PI / circ_num_ext_nodes );
1509 System.out.println( "is collapse" + n.getName() );
1512 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
1513 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file );
1516 final void paintCircularLite( final Phylogeny phy,
1517 final double starting_angle,
1521 final Graphics2D g ) {
1522 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
1523 _root = phy.getRoot();
1524 _root.setXSecondary( center_x );
1525 _root.setYSecondary( center_y );
1526 double current_angle = starting_angle;
1527 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1528 final PhylogenyNode n = it.next();
1529 n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1530 n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1531 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1532 current_angle += ( TWO_PI / circ_num_ext_nodes );
1534 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
1537 final void paintPhylogeny( final Graphics2D g,
1538 final boolean to_pdf,
1539 final boolean to_graphics_file,
1540 final int graphics_file_width,
1541 final int graphics_file_height,
1542 final int graphics_file_x,
1543 final int graphics_file_y ) {
1544 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1547 if ( _control_panel.isShowSequenceRelations() ) {
1548 _query_sequence = _control_panel.getSelectedQuerySequence();
1550 // Color the background
1552 final Rectangle r = getVisibleRect();
1553 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
1554 g.setColor( getTreeColorSet().getBackgroundColor() );
1555 if ( !to_graphics_file ) {
1559 if ( getOptions().isPrintBlackAndWhite() ) {
1560 g.setColor( Color.WHITE );
1562 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1566 if ( !to_graphics_file ) {
1567 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
1568 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
1572 g.setPaint( new GradientPaint( graphics_file_x,
1574 getTreeColorSet().getBackgroundColor(),
1576 graphics_file_y + graphics_file_height,
1577 getTreeColorSet().getBackgroundColorGradientBottom() ) );
1578 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1584 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
1586 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1587 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1588 _external_node_index = 0;
1589 // Position starting X of tree
1590 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
1591 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
1593 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
1594 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
1595 .getDistanceToParent() * getXcorrectionFactor() ) ) );
1598 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
1600 // Position starting Y of tree
1601 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
1602 + ( TreePanel.MOVE / 2.0f ) );
1603 final int dynamic_hiding_factor = calcDynamicHidingFactor();
1604 if ( getControlPanel().isDynamicallyHideData() ) {
1605 if ( dynamic_hiding_factor > 1 ) {
1606 getControlPanel().setDynamicHidingIsOn( true );
1609 getControlPanel().setDynamicHidingIsOn( false );
1612 if ( _nodes_in_preorder == null ) {
1613 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
1615 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1616 _nodes_in_preorder[ i++ ] = it.next();
1619 //final PhylogenyNodeIterator it;
1620 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1621 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
1622 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1624 for( final PhylogenyNode element : _nodes_in_preorder ) {
1625 paintNodeRectangular( g, element, to_pdf, getControlPanel().isDynamicallyHideData()
1626 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1628 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
1629 if ( !( to_graphics_file || to_pdf ) ) {
1632 getVisibleRect().y + getVisibleRect().height,
1637 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1640 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1641 paintPhylogenyLite( g );
1644 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1645 if ( getControlPanel().getDynamicallyHideData() != null ) {
1646 getControlPanel().setDynamicHidingIsOn( false );
1648 final double angle = getStartingAngle();
1649 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1650 _dynamic_hiding_factor = 0;
1651 if ( getControlPanel().isDynamicallyHideData() ) {
1652 _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5 * getPhylogeny()
1653 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
1655 if ( getControlPanel().getDynamicallyHideData() != null ) {
1656 if ( _dynamic_hiding_factor > 1 ) {
1657 getControlPanel().setDynamicHidingIsOn( true );
1660 getControlPanel().setDynamicHidingIsOn( false );
1663 paintUnrooted( _phylogeny.getRoot(),
1665 ( float ) ( angle + ( 2 * Math.PI ) ),
1670 if ( getOptions().isShowScale() ) {
1671 if ( !( to_graphics_file || to_pdf ) ) {
1674 getVisibleRect().y + getVisibleRect().height,
1679 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1682 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1683 g.setColor( getTreeColorSet().getOvColor() );
1684 paintUnrootedLite( _phylogeny.getRoot(),
1686 angle + ( 2 * Math.PI ),
1688 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
1689 paintOvRectangle( g );
1692 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1693 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
1694 final int d = radius + MOVE + getLongestExtNodeInfo();
1695 _dynamic_hiding_factor = 0;
1696 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
1697 _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5 * getPhylogeny()
1698 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
1700 if ( getControlPanel().getDynamicallyHideData() != null ) {
1701 if ( _dynamic_hiding_factor > 1 ) {
1702 getControlPanel().setDynamicHidingIsOn( true );
1705 getControlPanel().setDynamicHidingIsOn( false );
1708 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
1709 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1710 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
1711 : getOvMaxWidth() / 2 );
1712 double x_scale = 1.0;
1713 double y_scale = 1.0;
1714 int x_pos = getVisibleRect().x + getOvXPosition();
1715 int y_pos = getVisibleRect().y + getOvYPosition();
1716 if ( getWidth() > getHeight() ) {
1717 x_scale = ( double ) getHeight() / getWidth();
1718 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
1721 y_scale = ( double ) getWidth() / getHeight();
1722 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
1724 _at = g.getTransform();
1725 g.scale( x_scale, y_scale );
1726 paintCircularLite( _phylogeny,
1730 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
1733 g.setTransform( _at );
1734 paintOvRectangle( g );
1739 final void recalculateMaxDistanceToRoot() {
1740 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
1744 * Remove all edit-node frames
1746 final void removeAllEditNodeJFrames() {
1747 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
1748 if ( _node_frames[ i ] != null ) {
1749 _node_frames[ i ].dispose();
1750 _node_frames[ i ] = null;
1753 _node_frame_index = 0;
1757 * Remove a node-edit frame.
1759 final void removeEditNodeFrame( final int i ) {
1760 _node_frame_index--;
1761 _node_frames[ i ] = null;
1762 if ( i < _node_frame_index ) {
1763 for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) {
1764 _node_frames[ j ] = _node_frames[ j + 1 ];
1766 _node_frames[ _node_frame_index ] = null;
1770 final void reRoot( final PhylogenyNode node ) {
1771 if ( !getPhylogeny().isRerootable() ) {
1772 JOptionPane.showMessageDialog( this,
1773 "This is not rerootable",
1775 JOptionPane.WARNING_MESSAGE );
1778 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1779 JOptionPane.showMessageDialog( this,
1780 "Cannot reroot in unrooted display type",
1781 "Attempt to reroot tree in unrooted display",
1782 JOptionPane.WARNING_MESSAGE );
1785 getPhylogeny().reRoot( node );
1786 getPhylogeny().recalculateNumberOfExternalDescendants( true );
1787 resetNodeIdToDistToLeafMap();
1788 setNodeInPreorderToNull();
1789 resetPreferredSize();
1790 getMainPanel().adjustJScrollPane();
1793 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1794 getControlPanel().showWhole();
1798 final void resetNodeIdToDistToLeafMap() {
1799 _nodeid_dist_to_leaf = new HashMap<Long, Short>();
1802 final void resetPreferredSize() {
1803 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
1809 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
1810 if ( getControlPanel().isDrawPhylogram() ) {
1812 + getLongestExtNodeInfo()
1814 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
1817 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
1819 + getLongestExtNodeInfo()
1820 + ForesterUtil.roundToInt( getXdistance()
1821 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
1825 + getLongestExtNodeInfo()
1826 + ForesterUtil.roundToInt( getXdistance()
1827 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
1830 setPreferredSize( new Dimension( x, y ) );
1833 final void selectNode( final PhylogenyNode node ) {
1834 if ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) ) {
1835 getFoundNodes0().remove( node.getId() );
1836 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
1837 if ( getFoundNodes0().size() < 1 ) {
1838 getControlPanel().searchReset0();
1842 getControlPanel().getSearchFoundCountsLabel0().setVisible( true );
1843 getControlPanel().getSearchResetButton0().setEnabled( true );
1844 getControlPanel().getSearchResetButton0().setVisible( true );
1845 if ( getFoundNodes0() == null ) {
1846 setFoundNodes0( new HashSet<Long>() );
1848 getFoundNodes0().add( node.getId() );
1849 getControlPanel().setSearchFoundCountsOnLabel0( getFoundNodes0().size() );
1853 final void setArrowCursor() {
1854 setCursor( ARROW_CURSOR );
1858 final void setControlPanel( final ControlPanel atv_control ) {
1859 _control_panel = atv_control;
1862 void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
1863 increaseCurrentExternalNodesDataBufferChangeCounter();
1864 _current_external_nodes_data_buffer = sb;
1867 final void setFoundNodes0( final Set<Long> found_nodes ) {
1868 _found_nodes_0 = found_nodes;
1871 final void setFoundNodes1( final Set<Long> found_nodes ) {
1872 _found_nodes_1 = found_nodes;
1875 final void setInOvRect( final boolean in_ov_rect ) {
1876 _in_ov_rect = in_ov_rect;
1879 final void setLargeFonts() {
1880 getTreeFontSet().largeFonts();
1883 final void setLastMouseDragPointX( final float x ) {
1884 _last_drag_point_x = x;
1887 final void setLastMouseDragPointY( final float y ) {
1888 _last_drag_point_y = y;
1891 final void setMediumFonts() {
1892 getTreeFontSet().mediumFonts();
1895 final void setNodeInPreorderToNull() {
1896 _nodes_in_preorder = null;
1899 final void setOvOn( final boolean ov_on ) {
1903 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
1904 _graphics_type = graphics_type;
1908 final void setSmallFonts() {
1909 getTreeFontSet().smallFonts();
1912 final void setStartingAngle( final double starting_angle ) {
1913 _urt_starting_angle = starting_angle;
1916 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
1917 _statistics_for_vector_data = statistics_for_expression_values;
1920 final void setSuperTinyFonts() {
1921 getTreeFontSet().superTinyFonts();
1924 final void setTextAntialias() {
1925 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
1926 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
1927 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
1930 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
1933 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
1934 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
1936 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
1938 // catch ( final Throwable e ) {
1939 // _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
1943 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
1944 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1948 final void setTinyFonts() {
1949 getTreeFontSet().tinyFonts();
1952 final void setTreeFile( final File treefile ) {
1953 _treefile = treefile;
1956 final void setXcorrectionFactor( final float f ) {
1957 _x_correction_factor = f;
1960 final void setXdistance( final float x ) {
1964 final void setYdistance( final float y ) {
1968 final void sortDescendants( final PhylogenyNode node ) {
1969 if ( !node.isExternal() ) {
1970 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
1971 if ( ( !getControlPanel().isShowTaxonomyScientificNames() && !getControlPanel().isShowTaxonomyCode() && !getControlPanel()
1972 .isShowTaxonomyCommonNames() ) ) {
1973 if ( ( getControlPanel().isShowSequenceAcc() || getControlPanel().isShowSeqNames() || getControlPanel()
1974 .isShowSeqSymbols() ) ) {
1975 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
1977 else if ( getControlPanel().isShowNodeNames() ) {
1978 pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
1981 PhylogenyMethods.sortNodeDescendents( node, pri );
1982 setNodeInPreorderToNull();
1983 _phylogeny.externalNodesHaveChanged();
1984 _phylogeny.clearHashIdToNodeMap();
1985 _phylogeny.recalculateNumberOfExternalDescendants( true );
1986 resetNodeIdToDistToLeafMap();
1992 final void subTree( final PhylogenyNode node ) {
1993 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1994 JOptionPane.showMessageDialog( this,
1995 "Cannot get a sub/super tree in unrooted display",
1996 "Attempt to get sub/super tree in unrooted display",
1997 JOptionPane.WARNING_MESSAGE );
2000 if ( node.isExternal() ) {
2001 JOptionPane.showMessageDialog( this,
2002 "Cannot get a subtree of a external node",
2003 "Attempt to get subtree of external node",
2004 JOptionPane.WARNING_MESSAGE );
2007 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
2008 JOptionPane.showMessageDialog( this,
2009 "Cannot get a subtree of the root node",
2010 "Attempt to get subtree of root node",
2011 JOptionPane.WARNING_MESSAGE );
2014 setNodeInPreorderToNull();
2015 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
2016 _sub_phylogenies[ _subtree_index ] = _phylogeny;
2017 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
2019 _phylogeny = TreePanelUtil.subTree( node, _phylogeny );
2020 updateSubSuperTreeButton();
2022 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
2025 _main_panel.getControlPanel().showWhole();
2029 final void superTree() {
2030 setNodeInPreorderToNull();
2031 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
2032 for( final PhylogenyNode n : temp_root.getDescendants() ) {
2033 n.setParent( temp_root );
2035 _sub_phylogenies[ _subtree_index ] = null;
2036 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
2037 _phylogeny = _sub_phylogenies[ --_subtree_index ];
2038 updateSubSuperTreeButton();
2041 final void swap( final PhylogenyNode node ) {
2042 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
2045 if ( node.getNumberOfDescendants() > 2 ) {
2046 JOptionPane.showMessageDialog( this,
2047 "Cannot swap descendants of nodes with more than 2 descendants",
2048 "Cannot swap descendants",
2049 JOptionPane.ERROR_MESSAGE );
2052 if ( !node.isExternal() ) {
2053 node.swapChildren();
2054 setNodeInPreorderToNull();
2055 _phylogeny.externalNodesHaveChanged();
2056 _phylogeny.clearHashIdToNodeMap();
2057 _phylogeny.recalculateNumberOfExternalDescendants( true );
2058 resetNodeIdToDistToLeafMap();
2064 final void taxColor() {
2065 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
2069 TreePanelUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
2070 _control_panel.setColorBranches( true );
2071 if ( _control_panel.getUseVisualStylesCb() != null ) {
2072 _control_panel.getUseVisualStylesCb().setSelected( true );
2079 final void updateOvSettings() {
2080 switch ( getOptions().getOvPlacement() ) {
2082 setOvXPosition( OV_BORDER );
2083 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
2084 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
2087 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
2088 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
2089 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
2092 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
2093 setOvYPosition( OV_BORDER );
2094 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2097 setOvXPosition( OV_BORDER );
2098 setOvYPosition( OV_BORDER );
2099 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2104 final void updateOvSizes() {
2105 if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) ) || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) {
2107 float l = getLongestExtNodeInfo();
2108 final float w_ratio = getOvMaxWidth() / getWidth();
2110 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
2111 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
2113 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
2114 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
2117 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
2119 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
2120 if ( ov_xdist < 0.0 ) {
2123 if ( ydist < 0.0 ) {
2126 setOvXDistance( ov_xdist );
2127 final double height = _phylogeny.getHeight();
2129 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
2130 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
2133 setOvXcorrectionFactor( 0 );
2141 void updateSetOfCollapsedExternalNodes() {
2142 final Phylogeny phy = getPhylogeny();
2143 _collapsed_external_nodeid_set.clear();
2144 if ( phy != null ) {
2145 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2146 final PhylogenyNode ext_node = it.next();
2147 PhylogenyNode n = ext_node;
2148 while ( !n.isRoot() ) {
2149 if ( n.isCollapse() ) {
2150 _collapsed_external_nodeid_set.add( ext_node.getId() );
2151 ext_node.setCollapse( true );
2160 final void updateSubSuperTreeButton() {
2161 if ( _subtree_index < 1 ) {
2162 getControlPanel().deactivateButtonToReturnToSuperTree();
2165 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
2169 final void zoomInDomainStructure() {
2170 if ( _domain_structure_width < 2000 ) {
2171 _domain_structure_width *= 1.2;
2175 final void zoomOutDomainStructure() {
2176 if ( _domain_structure_width > 20 ) {
2177 _domain_structure_width *= 0.8;
2181 private void abbreviateScientificName( final String sn, final StringBuilder sb ) {
2182 final String[] a = sn.split( "\\s+" );
2183 sb.append( a[ 0 ].substring( 0, 1 ) );
2184 sb.append( a[ 1 ].substring( 0, 2 ) );
2185 if ( a.length > 2 ) {
2186 for( int i = 2; i < a.length; i++ ) {
2188 sb.append( a[ i ] );
2193 final private void addEmptyNode( final PhylogenyNode node ) {
2194 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2195 errorMessageNoCutCopyPasteInUnrootedDisplay();
2198 final String label = createASimpleTextRepresentationOfANode( node );
2200 if ( ForesterUtil.isEmpty( label ) ) {
2201 msg = "How to add the new, empty node?";
2204 msg = "How to add the new, empty node to node" + label + "?";
2206 final Object[] options = { "As sibling", "As descendant", "Cancel" };
2207 final int r = JOptionPane.showOptionDialog( this,
2209 "Addition of Empty New Node",
2210 JOptionPane.CLOSED_OPTION,
2211 JOptionPane.QUESTION_MESSAGE,
2215 boolean add_as_sibling = true;
2217 add_as_sibling = false;
2219 else if ( r != 0 ) {
2222 final Phylogeny phy = new Phylogeny();
2223 phy.setRoot( new PhylogenyNode() );
2224 phy.setRooted( true );
2225 if ( add_as_sibling ) {
2226 if ( node.isRoot() ) {
2227 JOptionPane.showMessageDialog( this,
2228 "Cannot add sibling to root",
2229 "Attempt to add sibling to root",
2230 JOptionPane.ERROR_MESSAGE );
2233 phy.addAsSibling( node );
2236 phy.addAsChild( node );
2238 setNodeInPreorderToNull();
2239 _phylogeny.externalNodesHaveChanged();
2240 _phylogeny.clearHashIdToNodeMap();
2241 _phylogeny.recalculateNumberOfExternalDescendants( true );
2242 resetNodeIdToDistToLeafMap();
2247 final private void addToCurrentExternalNodes( final long i ) {
2248 if ( _current_external_nodes == null ) {
2249 _current_external_nodes = new HashSet<Long>();
2251 _current_external_nodes.add( i );
2254 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
2255 final boolean is_vertical,
2257 final boolean to_pdf,
2258 final boolean to_graphics_file ) {
2259 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
2260 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2261 g.setColor( Color.BLACK );
2263 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
2264 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
2265 && ( getCutOrCopiedTree() != null )
2266 && ( getCopiedAndPastedNodes() != null )
2268 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
2269 g.setColor( getTreeColorSet().getFoundColor0() );
2271 else if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2272 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2274 else if ( to_pdf ) {
2275 g.setColor( getTreeColorSet().getBranchColorForPdf() );
2278 g.setColor( getTreeColorSet().getBranchColor() );
2282 final private void blast( final PhylogenyNode node ) {
2283 if ( !isCanBlast( node ) ) {
2284 JOptionPane.showMessageDialog( this,
2285 "Insufficient information present",
2287 JOptionPane.INFORMATION_MESSAGE );
2291 final String query = Blast.obtainQueryForBlast( node );
2292 System.out.println( "query for BLAST is: " + query );
2294 if ( !ForesterUtil.isEmpty( query ) ) {
2295 if ( node.getNodeData().isHasSequence() ) {
2296 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
2297 if ( node.getNodeData().getSequence().getType().toLowerCase()
2298 .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
2305 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2306 if ( ForesterUtil.seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2314 if ( type == '?' ) {
2315 if ( SequenceAccessionTools.isProteinDbQuery( query ) ) {
2322 JApplet applet = null;
2324 applet = obtainApplet();
2327 Blast.openNcbiBlastWeb( query, type == 'n', applet, this );
2329 catch ( final Exception e ) {
2330 e.printStackTrace();
2332 if ( Constants.ALLOW_DDBJ_BLAST ) {
2334 System.out.println( "trying: " + query );
2335 final Blast s = new Blast();
2336 s.ddbjBlast( query );
2338 catch ( final Exception e ) {
2339 e.printStackTrace();
2346 private final int calcDynamicHidingFactor() {
2347 return ( int ) ( 0.5 + ( getFontMetricsForLargeDefaultFont().getHeight() / ( 1.5 * getYdistance() ) ) );
2351 * Calculate the length of the distance between the given node and its
2357 * @return the distance value
2359 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
2360 if ( getControlPanel().isDrawPhylogram() ) {
2361 if ( node.getDistanceToParent() < 0.0 ) {
2364 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
2367 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2368 return getXdistance();
2370 return getXdistance() * factor;
2374 final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
2375 Color c = getTreeColorSet().getAnnotationColor();
2376 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
2377 final StringBuilder sb = new StringBuilder();
2378 for( final Annotation a : ann ) {
2379 sb.append( !ForesterUtil.isEmpty( a.getRefValue() ) ? a.getRefValue() : a.getDesc() );
2381 final String ann_str = sb.toString();
2382 if ( !ForesterUtil.isEmpty( ann_str ) ) {
2383 c = getControlPanel().getAnnotationColors().get( ann_str );
2385 c = TreePanelUtil.calculateColorFromString( ann_str, false );
2386 getControlPanel().getAnnotationColors().put( ann_str, c );
2389 c = getTreeColorSet().getAnnotationColor();
2396 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
2397 if ( getControlPanel().isDrawPhylogram() ) {
2398 if ( node.getDistanceToParent() < 0.0 ) {
2401 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
2404 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2405 return getOvXDistance();
2407 return getOvXDistance() * factor;
2411 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
2412 JOptionPane.showMessageDialog( this,
2413 "Cannot launch web browser for " + type_type + " data of this node",
2414 "Cannot launch web browser",
2415 JOptionPane.WARNING_MESSAGE );
2418 private void changeNodeFont( final PhylogenyNode node ) {
2419 final FontChooser fc = new FontChooser();
2421 if ( ( node.getNodeData().getNodeVisualData() != null ) && !node.getNodeData().getNodeVisualData().isEmpty() ) {
2422 f = node.getNodeData().getNodeVisualData().getFont();
2428 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
2430 fc.showDialog( this, "Select Font" );
2431 if ( ( fc.getFont() != null ) && !ForesterUtil.isEmpty( fc.getFont().getFamily().trim() ) ) {
2432 List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
2433 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
2434 nodes = getFoundNodesAsListOfPhylogenyNodes();
2437 for( final PhylogenyNode n : nodes ) {
2438 if ( n.getNodeData().getNodeVisualData() == null ) {
2439 n.getNodeData().setNodeVisualData( new NodeVisualData() );
2441 final NodeVisualData vd = n.getNodeData().getNodeVisualData();
2442 final Font ff = fc.getFont();
2443 vd.setFontName( ff.getFamily().trim() );
2444 int s = ff.getSize();
2448 if ( s > Byte.MAX_VALUE ) {
2451 vd.setFontSize( s );
2452 vd.setFontStyle( ff.getStyle() );
2454 if ( _control_panel.getUseVisualStylesCb() != null ) {
2455 getControlPanel().getUseVisualStylesCb().setSelected( true );
2461 final private void colorizeNodes( final Color c,
2462 final PhylogenyNode node,
2463 final List<PhylogenyNode> additional_nodes ) {
2464 _control_panel.setColorBranches( true );
2465 if ( _control_panel.getUseVisualStylesCb() != null ) {
2466 _control_panel.getUseVisualStylesCb().setSelected( true );
2468 if ( node != null ) {
2469 colorizeNodesHelper( c, node );
2471 if ( additional_nodes != null ) {
2472 for( final PhylogenyNode n : additional_nodes ) {
2473 colorizeNodesHelper( c, n );
2479 final private void colorizeSubtree( final Color c,
2480 final PhylogenyNode node,
2481 final List<PhylogenyNode> additional_nodes ) {
2482 _control_panel.setColorBranches( true );
2483 if ( _control_panel.getUseVisualStylesCb() != null ) {
2484 _control_panel.getUseVisualStylesCb().setSelected( true );
2486 if ( node != null ) {
2487 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
2488 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
2491 if ( additional_nodes != null ) {
2492 for( final PhylogenyNode an : additional_nodes ) {
2493 for( final PreorderTreeIterator it = new PreorderTreeIterator( an ); it.hasNext(); ) {
2494 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
2501 private void colorNodeFont( final PhylogenyNode node ) {
2502 _color_chooser.setPreviewPanel( new JPanel() );
2503 NodeColorizationActionListener al;
2504 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
2505 final List<PhylogenyNode> additional_nodes = getFoundNodesAsListOfPhylogenyNodes();
2506 al = new NodeColorizationActionListener( _color_chooser, node, additional_nodes );
2509 al = new NodeColorizationActionListener( _color_chooser, node );
2511 final JDialog dialog = JColorChooser.createDialog( this, "Node colorization", true, _color_chooser, al, null );
2512 dialog.setVisible( true );
2515 final private void colorSubtree( final PhylogenyNode node ) {
2516 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2517 JOptionPane.showMessageDialog( this,
2518 "Cannot colorize subtree in unrooted display type",
2519 "Attempt to colorize subtree in unrooted display",
2520 JOptionPane.WARNING_MESSAGE );
2523 _color_chooser.setPreviewPanel( new JPanel() );
2524 SubtreeColorizationActionListener al;
2525 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
2526 final List<PhylogenyNode> additional_nodes = getFoundNodesAsListOfPhylogenyNodes();
2527 al = new SubtreeColorizationActionListener( _color_chooser, node, additional_nodes );
2530 al = new SubtreeColorizationActionListener( _color_chooser, node );
2532 final JDialog dialog = JColorChooser
2533 .createDialog( this, "Subtree colorization", true, _color_chooser, al, null );
2534 dialog.setVisible( true );
2537 final private void copySubtree( final PhylogenyNode node ) {
2538 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2539 errorMessageNoCutCopyPasteInUnrootedDisplay();
2542 setNodeInPreorderToNull();
2543 setCutOrCopiedTree( _phylogeny.copy( node ) );
2544 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
2545 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
2546 for( final PhylogenyNode n : nodes ) {
2547 node_ids.add( n.getId() );
2549 node_ids.add( node.getId() );
2550 setCopiedAndPastedNodes( node_ids );
2554 final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
2555 final String tax = PhylogenyMethods.getSpecies( node );
2556 String label = node.getName();
2557 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
2558 label = label + " " + tax;
2560 else if ( !ForesterUtil.isEmpty( tax ) ) {
2566 if ( !ForesterUtil.isEmpty( label ) ) {
2567 label = " [" + label + "]";
2572 final private void cutSubtree( final PhylogenyNode node ) {
2573 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2574 errorMessageNoCutCopyPasteInUnrootedDisplay();
2577 if ( node.isRoot() ) {
2578 JOptionPane.showMessageDialog( this,
2579 "Cannot cut entire tree as subtree",
2580 "Attempt to cut entire tree",
2581 JOptionPane.ERROR_MESSAGE );
2584 final String label = createASimpleTextRepresentationOfANode( node );
2585 final int r = JOptionPane.showConfirmDialog( null,
2586 "Cut subtree" + label + "?",
2587 "Confirm Cutting of Subtree",
2588 JOptionPane.YES_NO_OPTION );
2589 if ( r != JOptionPane.OK_OPTION ) {
2592 setNodeInPreorderToNull();
2593 setCopiedAndPastedNodes( null );
2594 setCutOrCopiedTree( _phylogeny.copy( node ) );
2595 _phylogeny.deleteSubtree( node, true );
2596 _phylogeny.clearHashIdToNodeMap();
2597 _phylogeny.recalculateNumberOfExternalDescendants( true );
2598 resetNodeIdToDistToLeafMap();
2603 final private void cycleColors() {
2604 getMainPanel().getTreeColorSet().cycleColorScheme();
2605 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
2606 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
2610 final private void decreaseOvSize() {
2611 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
2612 setOvMaxWidth( getOvMaxWidth() - 5 );
2613 setOvMaxHeight( getOvMaxHeight() - 5 );
2615 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2619 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
2620 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2621 errorMessageNoCutCopyPasteInUnrootedDisplay();
2624 if ( node.isRoot() && ( node.getNumberOfDescendants() != 1 ) ) {
2625 JOptionPane.showMessageDialog( this,
2626 "Cannot delete entire tree",
2627 "Attempt to delete entire tree",
2628 JOptionPane.ERROR_MESSAGE );
2631 final String label = createASimpleTextRepresentationOfANode( node );
2632 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
2633 final int r = JOptionPane.showOptionDialog( this,
2634 "Delete" + label + "?",
2635 "Delete Node/Subtree",
2636 JOptionPane.CLOSED_OPTION,
2637 JOptionPane.QUESTION_MESSAGE,
2641 setNodeInPreorderToNull();
2642 boolean node_only = true;
2646 else if ( r != 0 ) {
2650 PhylogenyMethods.removeNode( node, _phylogeny );
2653 _phylogeny.deleteSubtree( node, true );
2655 _phylogeny.externalNodesHaveChanged();
2656 _phylogeny.clearHashIdToNodeMap();
2657 _phylogeny.recalculateNumberOfExternalDescendants( true );
2658 resetNodeIdToDistToLeafMap();
2663 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
2664 makePopupMenus( node );
2665 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
2666 _node_popup_menu.show( this, x, y );
2669 final private void drawArc( final double x,
2672 final double heigth,
2673 final double start_angle,
2674 final double arc_angle,
2675 final Graphics2D g ) {
2676 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
2680 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
2681 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
2684 _line.setLine( x1, y1, x2, y2 );
2688 final private void drawOval( final double x,
2691 final double heigth,
2692 final Graphics2D g ) {
2693 _ellipse.setFrame( x, y, width, heigth );
2697 final private void drawOvalFilled( final double x,
2700 final double heigth,
2701 final Graphics2D g ) {
2702 _ellipse.setFrame( x, y, width, heigth );
2706 final private void drawOvalGradient( final float x,
2711 final Color color_1,
2712 final Color color_2,
2713 final Color color_border ) {
2714 _ellipse.setFrame( x, y, width, heigth );
2715 g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) );
2717 if ( color_border != null ) {
2718 g.setPaint( color_border );
2723 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
2724 _rectangle.setFrame( x, y, width, heigth );
2725 g.draw( _rectangle );
2728 final private void drawRectFilled( final double x,
2731 final double heigth,
2732 final Graphics2D g ) {
2733 _rectangle.setFrame( x, y, width, heigth );
2734 g.fill( _rectangle );
2737 final private void drawRectGradient( final float x,
2742 final Color color_1,
2743 final Color color_2,
2744 final Color color_border ) {
2745 _rectangle.setFrame( x, y, width, heigth );
2746 g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) );
2747 g.fill( _rectangle );
2748 if ( color_border != null ) {
2749 g.setPaint( color_border );
2750 g.draw( _rectangle );
2754 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
2755 final List<Uri> us = new ArrayList<Uri>();
2756 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
2757 for( final Uri uri : t.getUris() ) {
2762 for( final Uri uri : us ) {
2763 if ( uri != null ) {
2764 final String uri_str = uri.getValue().toString().toLowerCase();
2765 if ( getImageMap().containsKey( uri_str ) ) {
2766 final BufferedImage bi = getImageMap().get( uri_str );
2767 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
2768 double scaling_factor = 1;
2769 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
2770 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
2771 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
2773 // y = y - ( 0.9 * getYdistance() );
2774 final double hs = bi.getHeight() * scaling_factor;
2775 double ws = ( bi.getWidth() * scaling_factor ) + offset;
2776 final double my_y = y - ( 0.5 * hs );
2777 final int x_w = ( int ) ( x + ws + 0.5 );
2778 final int y_h = ( int ) ( my_y + hs + 0.5 );
2779 if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) {
2781 ( int ) ( x + 0.5 + offset ),
2782 ( int ) ( my_y + 0.5 ),
2803 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
2804 JOptionPane.showMessageDialog( this,
2805 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
2806 "Attempt to cut/copy/paste/add/delete in unrooted display",
2807 JOptionPane.ERROR_MESSAGE );
2810 private final Color getColorForFoundNode( final PhylogenyNode n ) {
2811 if ( isInCurrentExternalNodes( n ) ) {
2812 return getTreeColorSet().getFoundColor0();
2814 else if ( isInFoundNodes0( n ) && !isInFoundNodes1( n ) ) {
2815 return getTreeColorSet().getFoundColor0();
2817 else if ( !isInFoundNodes0( n ) && isInFoundNodes1( n ) ) {
2818 return getTreeColorSet().getFoundColor1();
2821 return getTreeColorSet().getFoundColor0and1();
2825 final private Set<Long> getCopiedAndPastedNodes() {
2826 return getMainPanel().getCopiedAndPastedNodes();
2829 final private Set<Long> getCurrentExternalNodes() {
2830 return _current_external_nodes;
2833 final private Phylogeny getCutOrCopiedTree() {
2834 return getMainPanel().getCutOrCopiedTree();
2837 private FontMetrics getFontMetricsForLargeDefaultFont() {
2838 return getTreeFontSet().getFontMetricsLarge();
2841 List<PhylogenyNode> getFoundNodesAsListOfPhylogenyNodes() {
2842 final List<PhylogenyNode> additional_nodes = new ArrayList<PhylogenyNode>();
2843 if ( getFoundNodes0() != null ) {
2844 for( final Long id : getFoundNodes0() ) {
2845 additional_nodes.add( _phylogeny.getNode( id ) );
2848 if ( getFoundNodes1() != null ) {
2849 for( final Long id : getFoundNodes1() ) {
2850 if ( ( getFoundNodes0() == null ) || !getFoundNodes0().contains( id ) ) {
2851 additional_nodes.add( _phylogeny.getNode( id ) );
2855 return additional_nodes;
2858 final private float getLastDragPointX() {
2859 return _last_drag_point_x;
2862 final private float getLastDragPointY() {
2863 return _last_drag_point_y;
2866 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
2867 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
2868 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
2869 _nodeid_dist_to_leaf.put( node.getId(), m );
2873 return _nodeid_dist_to_leaf.get( node.getId() );
2877 final private double getMaxDistanceToRoot() {
2878 if ( _max_distance_to_root < 0 ) {
2879 recalculateMaxDistanceToRoot();
2881 return _max_distance_to_root;
2884 final private float getOvMaxHeight() {
2885 return _ov_max_height;
2888 final private float getOvMaxWidth() {
2889 return _ov_max_width;
2892 final private float getOvXcorrectionFactor() {
2893 return _ov_x_correction_factor;
2896 final private float getOvXDistance() {
2897 return _ov_x_distance;
2900 final private int getOvXPosition() {
2901 return _ov_x_position;
2904 final private float getOvYDistance() {
2905 return _ov_y_distance;
2908 final private int getOvYPosition() {
2909 return _ov_y_position;
2912 final private int getOvYStart() {
2916 final private List<Accession> getPdbAccs( final PhylogenyNode node ) {
2917 final List<Accession> pdb_ids = new ArrayList<Accession>();
2918 if ( node.getNodeData().isHasSequence() ) {
2919 final Sequence seq = node.getNodeData().getSequence();
2920 if ( !ForesterUtil.isEmpty( seq.getCrossReferences() ) ) {
2921 final SortedSet<Accession> cross_refs = seq.getCrossReferences();
2922 for( final Accession acc : cross_refs ) {
2923 if ( acc.getSource().equalsIgnoreCase( "pdb" ) ) {
2932 final private double getScaleDistance() {
2933 return _scale_distance;
2936 final private String getScaleLabel() {
2937 return _scale_label;
2940 final private TreeFontSet getTreeFontSet() {
2941 return getMainPanel().getTreeFontSet();
2944 final private float getUrtFactor() {
2948 final private float getUrtFactorOv() {
2949 return _urt_factor_ov;
2952 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
2955 showNodeFrame( node );
2970 colorSubtree( node );
2972 case COLOR_NODE_FONT:
2973 colorNodeFont( node );
2975 case CHANGE_NODE_FONT:
2976 changeNodeFont( node );
2994 copySubtree( node );
2997 pasteSubtree( node );
2999 case DELETE_NODE_OR_SUBTREE:
3000 deleteNodeOrSubtree( node );
3003 addEmptyNode( node );
3005 case EDIT_NODE_DATA:
3006 showNodeEditFrame( node );
3011 case SORT_DESCENDENTS:
3012 sortDescendants( node );
3014 case GET_EXT_DESC_DATA:
3015 showExtDescNodeData( node );
3018 throw new IllegalArgumentException( "unknown action: " + action );
3022 final private void increaseCurrentExternalNodesDataBufferChangeCounter() {
3023 _current_external_nodes_data_buffer_change_counter++;
3026 final private void increaseOvSize() {
3027 if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) )
3028 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
3029 .getHeight() / 2 ) ) ) {
3030 setOvMaxWidth( getOvMaxWidth() + 5 );
3031 setOvMaxHeight( getOvMaxHeight() + 5 );
3033 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3037 final private void init() {
3038 _color_chooser = new JColorChooser();
3039 _rollover_popup = new JTextArea();
3040 _rollover_popup.setFont( POPUP_FONT );
3041 resetNodeIdToDistToLeafMap();
3043 setTreeFile( null );
3045 initializeOvSettings();
3046 setStartingAngle( ( TWO_PI * 3 ) / 4 );
3047 final ImageLoader il = new ImageLoader( this );
3048 new Thread( il ).start();
3051 final private void initializeOvSettings() {
3052 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
3053 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
3056 final private boolean inOvVirtualRectangle( final int x, final int y ) {
3057 return ( ( x >= ( getOvVirtualRectangle().x - 1 ) )
3058 && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) )
3059 && ( y >= ( getOvVirtualRectangle().y - 1 ) ) && ( y <= ( getOvVirtualRectangle().y
3060 + getOvVirtualRectangle().height + 1 ) ) );
3063 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
3064 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
3067 final private boolean isCanBlast( final PhylogenyNode node ) {
3068 if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) {
3071 return Blast.isContainsQueryForBlast( node );
3074 final private String isCanOpenSeqWeb( final PhylogenyNode node ) {
3075 final Accession a = SequenceAccessionTools.obtainAccessorFromDataFields( node );
3077 return a.getValue();
3082 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
3083 if ( node.getNodeData().isHasTaxonomy()
3084 && ( ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
3085 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
3086 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
3087 .getNodeData().getTaxonomy().getIdentifier() != null ) && !ForesterUtil.isEmpty( node
3088 .getNodeData().getTaxonomy().getIdentifier().getValue() ) ) ) ) {
3096 final private boolean isInCurrentExternalNodes( final PhylogenyNode node ) {
3097 return ( ( getCurrentExternalNodes() != null ) && getCurrentExternalNodes().contains( node.getId() ) );
3100 private boolean isInFoundNodes( final PhylogenyNode n ) {
3101 return isInFoundNodes0( n ) || isInFoundNodes1( n );
3104 final private boolean isInFoundNodes0( final PhylogenyNode node ) {
3105 return ( ( getFoundNodes0() != null ) && getFoundNodes0().contains( node.getId() ) );
3108 final private boolean isInFoundNodes1( final PhylogenyNode node ) {
3109 return ( ( getFoundNodes1() != null ) && getFoundNodes1().contains( node.getId() ) );
3112 final private boolean isInOv() {
3116 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
3118 if ( getControlPanel().isShowTaxonomyImages() ) {
3119 y_dist = 40 + ( int ) getYdistance();
3121 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) )
3122 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) ) || ( ( node.getParent() != null ) && ( node
3123 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
3126 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
3127 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) )
3128 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) )
3129 || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) ) || ( node.getXcoord() > ( getVisibleRect()
3130 .getMaxX() + 20 ) ) );
3133 final private boolean isNonLinedUpCladogram() {
3134 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
3137 final private boolean isUniformBranchLengthsForCladogram() {
3138 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
3141 final private void keyPressedCalls( final KeyEvent e ) {
3142 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
3143 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
3144 if ( !isInOvRect() ) {
3145 setInOvRect( true );
3148 else if ( isInOvRect() ) {
3149 setInOvRect( false );
3152 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
3153 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
3154 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
3155 getMainPanel().getTreeFontSet().mediumFonts();
3156 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3158 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
3159 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
3160 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3162 else if ( plusPressed( e.getKeyCode() ) ) {
3163 getMainPanel().getTreeFontSet().increaseFontSize();
3164 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
3168 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
3169 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
3170 getControlPanel().showWhole();
3172 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
3173 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
3174 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
3175 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
3176 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3177 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3179 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
3180 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3181 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3183 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
3184 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3185 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3186 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3188 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
3189 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3190 Constants.WHEEL_ZOOM_IN_FACTOR );
3191 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3198 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
3201 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
3205 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
3209 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
3210 scroll_position.x = scroll_position.x + dx;
3211 scroll_position.y = scroll_position.y + dy;
3212 if ( scroll_position.x <= 0 ) {
3213 scroll_position.x = 0;
3216 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
3217 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
3218 if ( scroll_position.x >= max_x ) {
3219 scroll_position.x = max_x;
3222 if ( scroll_position.y <= 0 ) {
3223 scroll_position.y = 0;
3226 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
3227 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
3228 if ( scroll_position.y >= max_y ) {
3229 scroll_position.y = max_y;
3233 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
3236 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
3237 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3238 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3239 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3240 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3242 else if ( plusPressed( e.getKeyCode() ) ) {
3243 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3244 Constants.WHEEL_ZOOM_IN_FACTOR );
3245 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3246 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3248 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
3249 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3250 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3251 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
3252 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3255 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
3256 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3257 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3258 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
3259 if ( getStartingAngle() < 0 ) {
3260 setStartingAngle( TWO_PI + getStartingAngle() );
3262 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3265 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
3266 boolean selected = false;
3267 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
3268 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
3272 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
3274 if ( getMainPanel().getMainFrame() == null ) {
3275 // Must be "E" applet version.
3276 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
3277 if ( ae.getlabelDirectionCbmi() != null ) {
3278 ae.getlabelDirectionCbmi().setSelected( selected );
3282 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
3286 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
3287 switchDisplaygetPhylogenyGraphicsType();
3290 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
3294 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
3295 MainFrame.cycleOverview( getOptions(), this );
3298 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
3301 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
3308 final private void makePopupMenus( final PhylogenyNode node ) {
3309 _node_popup_menu = new JPopupMenu();
3310 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
3311 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
3312 for( int i = 0; i < clickto_names.size(); i++ ) {
3313 final String title = clickto_names.get( i );
3314 _node_popup_menu_items[ i ] = new JMenuItem( title );
3315 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
3316 final String id = isCanOpenSeqWeb( node );
3317 if ( !ForesterUtil.isEmpty( id ) ) {
3318 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + id + "]" );
3319 _node_popup_menu_items[ i ].setEnabled( true );
3322 _node_popup_menu_items[ i ].setEnabled( false );
3325 else if ( title.equals( Configuration.clickto_options[ Configuration.open_pdb_web ][ 0 ] ) ) {
3326 final List<Accession> accs = getPdbAccs( node );
3327 _node_popup_menu_items[ i ] = new JMenuItem( title );
3328 if ( !ForesterUtil.isEmpty( accs ) ) {
3329 if ( accs.size() == 1 ) {
3330 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
3331 + TreePanelUtil.pdbAccToString( accs, 0 ) + "]" );
3332 _node_popup_menu_items[ i ].setEnabled( true );
3334 else if ( accs.size() == 2 ) {
3335 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
3336 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
3337 + TreePanelUtil.pdbAccToString( accs, 1 ) + "]" );
3338 _node_popup_menu_items[ i ].setEnabled( true );
3340 else if ( accs.size() == 3 ) {
3341 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
3342 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
3343 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
3344 + TreePanelUtil.pdbAccToString( accs, 2 ) + "]" );
3345 _node_popup_menu_items[ i ].setEnabled( true );
3348 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " ["
3349 + TreePanelUtil.pdbAccToString( accs, 0 ) + ", "
3350 + TreePanelUtil.pdbAccToString( accs, 1 ) + ", "
3351 + TreePanelUtil.pdbAccToString( accs, 2 ) + ", + " + ( accs.size() - 3 ) + " more]" );
3352 _node_popup_menu_items[ i ].setEnabled( true );
3356 _node_popup_menu_items[ i ].setEnabled( false );
3360 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
3361 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
3363 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
3364 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
3366 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
3367 if ( !getOptions().isEditable() ) {
3370 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
3372 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
3373 if ( !getOptions().isEditable() ) {
3376 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
3378 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
3379 if ( !getOptions().isEditable() ) {
3382 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
3384 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
3385 if ( !getOptions().isEditable() ) {
3388 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
3390 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
3391 if ( !getOptions().isEditable() ) {
3395 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
3396 if ( !getOptions().isEditable() ) {
3400 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
3401 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
3403 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
3404 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
3406 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
3407 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
3409 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
3410 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
3412 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
3413 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
3415 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
3416 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
3418 _node_popup_menu_items[ i ].addActionListener( this );
3419 _node_popup_menu.add( _node_popup_menu_items[ i ] );
3423 private final void nodeDataAsSB( final PhylogenyNode node, final StringBuilder sb ) {
3424 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3425 if ( sb.length() > 0 ) {
3428 sb.append( node.getName() );
3430 if ( node.getNodeData().isHasSequence() ) {
3431 if ( getControlPanel().isShowSeqSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
3432 if ( sb.length() > 0 ) {
3435 sb.append( node.getNodeData().getSequence().getSymbol() );
3437 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) {
3438 if ( sb.length() > 0 ) {
3441 sb.append( node.getNodeData().getSequence().getGeneName() );
3443 if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3444 if ( sb.length() > 0 ) {
3447 sb.append( node.getNodeData().getSequence().getName() );
3449 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3450 if ( sb.length() > 0 ) {
3453 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3454 sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3457 sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3460 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
3461 if ( sb.length() > 0 ) {
3464 sb.append( propertiesToString( node ) );
3468 private final void nodeTaxonomyDataAsSB( final Taxonomy taxonomy, final StringBuilder sb ) {
3469 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3470 sb.append( taxonomy.getTaxonomyCode() );
3473 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3474 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3475 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3476 if ( getOptions().isAbbreviateScientificTaxonNames()
3477 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3478 abbreviateScientificName( taxonomy.getScientificName(), sb );
3481 sb.append( taxonomy.getScientificName() );
3484 sb.append( taxonomy.getCommonName() );
3487 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3488 if ( getOptions().isAbbreviateScientificTaxonNames()
3489 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3490 abbreviateScientificName( taxonomy.getScientificName(), sb );
3493 sb.append( taxonomy.getScientificName() );
3497 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3498 sb.append( taxonomy.getCommonName() );
3502 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3503 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3504 if ( getOptions().isAbbreviateScientificTaxonNames()
3505 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3506 abbreviateScientificName( taxonomy.getScientificName(), sb );
3509 sb.append( taxonomy.getScientificName() );
3514 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3515 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3516 sb.append( taxonomy.getCommonName() );
3522 private final String obtainTitleForExtDescNodeData() {
3523 switch ( getOptions().getExtDescNodeDataToReturn() ) {
3525 return "Node Names";
3527 return "Gene Names";
3529 return "Sequence Names";
3530 case SEQUENCE_SYMBOL:
3531 return "Sequence Symbols";
3532 case SEQUENCE_MOL_SEQ:
3533 return "Molecular Sequences";
3534 case SEQUENCE_MOL_SEQ_FASTA:
3535 return "Molecular Sequences (Fasta)";
3537 return "Sequence Accessors";
3538 case TAXONOMY_SCIENTIFIC_NAME:
3539 return "Scientific Names";
3541 return "Taxonomy Codes";
3542 case TAXONOMY_COMM0N_NAME:
3543 return "Taxonomy Common Names";
3545 return "User Selected Data";
3547 throw new IllegalArgumentException( "unknown data element: "
3548 + getOptions().getExtDescNodeDataToReturn() );
3552 final private void openPdbWeb( final PhylogenyNode node ) {
3553 final List<Accession> pdb_ids = getPdbAccs( node );
3554 if ( ForesterUtil.isEmpty( pdb_ids ) ) {
3555 cannotOpenBrowserWarningMessage( "PDB" );
3558 final List<String> uri_strs = TreePanelUtil.createUrisForPdbWeb( node, pdb_ids, getConfiguration(), this );
3559 if ( !ForesterUtil.isEmpty( uri_strs ) ) {
3560 for( final String uri_str : uri_strs ) {
3562 AptxUtil.launchWebBrowser( new URI( uri_str ),
3564 isApplet() ? obtainApplet() : null,
3567 catch ( final IOException e ) {
3568 AptxUtil.showErrorMessage( this, e.toString() );
3569 e.printStackTrace();
3571 catch ( final URISyntaxException e ) {
3572 AptxUtil.showErrorMessage( this, e.toString() );
3573 e.printStackTrace();
3578 cannotOpenBrowserWarningMessage( "PDB" );
3582 final private void openSeqWeb( final PhylogenyNode node ) {
3583 if ( ForesterUtil.isEmpty( isCanOpenSeqWeb( node ) ) ) {
3584 cannotOpenBrowserWarningMessage( "sequence" );
3587 final String uri_str = TreePanelUtil.createUriForSeqWeb( node, getConfiguration(), this );
3588 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3590 AptxUtil.launchWebBrowser( new URI( uri_str ),
3592 isApplet() ? obtainApplet() : null,
3595 catch ( final IOException e ) {
3596 AptxUtil.showErrorMessage( this, e.toString() );
3597 e.printStackTrace();
3599 catch ( final URISyntaxException e ) {
3600 AptxUtil.showErrorMessage( this, e.toString() );
3601 e.printStackTrace();
3605 cannotOpenBrowserWarningMessage( "sequence" );
3609 final private void openTaxWeb( final PhylogenyNode node ) {
3610 if ( !isCanOpenTaxWeb( node ) ) {
3611 cannotOpenBrowserWarningMessage( "taxonomic" );
3614 String uri_str = null;
3615 final Taxonomy tax = node.getNodeData().getTaxonomy();
3616 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
3617 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
3619 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
3621 catch ( final URISyntaxException e ) {
3622 AptxUtil.showErrorMessage( this, e.toString() );
3624 e.printStackTrace();
3627 else if ( ( tax.getIdentifier() != null )
3628 && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
3629 && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
3630 && ( tax.getIdentifier().getProvider().equalsIgnoreCase( "ncbi" ) || tax.getIdentifier().getProvider()
3631 .equalsIgnoreCase( "uniprot" ) ) ) {
3633 uri_str = "http://www.uniprot.org/taxonomy/"
3634 + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
3636 catch ( final UnsupportedEncodingException e ) {
3637 AptxUtil.showErrorMessage( this, e.toString() );
3638 e.printStackTrace();
3641 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
3643 uri_str = "http://www.uniprot.org/taxonomy/?query="
3644 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
3646 catch ( final UnsupportedEncodingException e ) {
3647 AptxUtil.showErrorMessage( this, e.toString() );
3648 e.printStackTrace();
3651 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
3653 uri_str = "http://www.uniprot.org/taxonomy/?query="
3654 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
3656 catch ( final UnsupportedEncodingException e ) {
3657 AptxUtil.showErrorMessage( this, e.toString() );
3658 e.printStackTrace();
3661 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
3663 uri_str = "http://www.uniprot.org/taxonomy/?query="
3664 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
3666 catch ( final UnsupportedEncodingException e ) {
3667 AptxUtil.showErrorMessage( this, e.toString() );
3668 e.printStackTrace();
3671 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3673 AptxUtil.launchWebBrowser( new URI( uri_str ),
3675 isApplet() ? obtainApplet() : null,
3678 catch ( final IOException e ) {
3679 AptxUtil.showErrorMessage( this, e.toString() );
3680 e.printStackTrace();
3682 catch ( final URISyntaxException e ) {
3683 AptxUtil.showErrorMessage( this, e.toString() );
3684 e.printStackTrace();
3688 cannotOpenBrowserWarningMessage( "taxonomic" );
3692 final private void paintBranchLength( final Graphics2D g,
3693 final PhylogenyNode node,
3694 final boolean to_pdf,
3695 final boolean to_graphics_file ) {
3696 g.setFont( getTreeFontSet().getSmallFont() );
3697 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3698 g.setColor( Color.BLACK );
3701 g.setColor( getTreeColorSet().getBranchLengthColor() );
3703 if ( !node.isRoot() ) {
3704 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3705 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3706 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), g );
3708 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3709 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3710 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), g );
3713 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3714 .getXcoord() + 3, node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), g );
3718 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
3719 - getTreeFontSet().getSmallMaxDescent(), g );
3723 final private void paintBranchLite( final Graphics2D g,
3728 final PhylogenyNode node ) {
3729 g.setColor( getTreeColorSet().getOvColor() );
3730 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3731 drawLine( x1, y1, x2, y2, g );
3733 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3734 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3735 ( g ).draw( _quad_curve );
3737 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3738 final float dx = x2 - x1;
3739 final float dy = y2 - y1;
3740 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3741 + ( dy * 0.8f ), x2, y2 );
3742 ( g ).draw( _cubic_curve );
3745 final float x2a = x2;
3746 final float x1a = x1;
3747 // draw the vertical line
3748 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
3749 drawLine( x1, y1, x1, y2, g );
3751 // draw the horizontal line
3752 drawLine( x1a, y2, x2a, y2, g );
3757 * Paint a branch which consists of a vertical and a horizontal bar
3758 * @param is_ind_found_nodes
3760 final private void paintBranchRectangular( final Graphics2D g,
3765 final PhylogenyNode node,
3766 final boolean to_pdf,
3767 final boolean to_graphics_file ) {
3768 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
3769 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3770 drawLine( x1, y1, x2, y2, g );
3772 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3773 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3774 g.draw( _quad_curve );
3776 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3777 final float dx = x2 - x1;
3778 final float dy = y2 - y1;
3779 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3780 + ( dy * 0.8f ), x2, y2 );
3781 g.draw( _cubic_curve );
3784 final float x2a = x2;
3785 final float x1a = x1;
3787 if ( node.isFirstChildNode() || node.isLastChildNode()
3788 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
3789 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3790 if ( !to_graphics_file
3792 && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) ) || ( ( y2 > ( getVisibleRect()
3793 .getMaxY() + 20 ) ) && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) {
3797 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3798 float x2c = x1 + EURO_D;
3802 drawLine( x1, y1, x2c, y2, g );
3804 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3806 y2_r = y2 - ROUNDED_D;
3810 drawLine( x1, y1, x1, y2_r, g );
3813 y2_r = y2 + ROUNDED_D;
3817 drawLine( x1, y1, x1, y2_r, g );
3821 drawLine( x1, y1, x1, y2, g );
3825 // draw the horizontal line
3826 if ( !to_graphics_file && !to_pdf
3827 && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) {
3831 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
3832 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3833 x1_r = x1a + ROUNDED_D;
3835 drawLine( x1_r, y2, x2a, y2, g );
3838 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3839 final float x1c = x1a + EURO_D;
3841 drawLine( x1c, y2, x2a, y2, g );
3845 drawLine( x1a, y2, x2a, y2, g );
3849 final double w = PhylogenyMethods.getBranchWidthValue( node );
3850 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3851 x1_r = x1a + ROUNDED_D;
3853 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
3856 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3857 final float x1c = x1a + EURO_D;
3859 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
3863 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
3866 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3871 final double diff = y2 - y2_r;
3872 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
3875 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
3880 if ( node.isExternal() ) {
3881 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file );
3885 final private double paintCirculars( final PhylogenyNode n,
3886 final Phylogeny phy,
3887 final float center_x,
3888 final float center_y,
3889 final double radius,
3890 final boolean radial_labels,
3892 final boolean to_pdf,
3893 final boolean to_graphics_file ) {
3894 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
3895 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
3896 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
3898 return _urt_nodeid_angle_map.get( n.getId() );
3901 final List<PhylogenyNode> descs = n.getDescendants();
3903 for( final PhylogenyNode desc : descs ) {
3904 sum += paintCirculars( desc,
3915 if ( !n.isRoot() ) {
3916 r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3918 final double theta = sum / descs.size();
3919 n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) );
3920 n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) );
3921 _urt_nodeid_angle_map.put( n.getId(), theta );
3922 for( final PhylogenyNode desc : descs ) {
3923 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
3929 final private void paintCircularsLite( final PhylogenyNode n,
3930 final Phylogeny phy,
3934 final Graphics2D g ) {
3935 if ( n.isExternal() ) {
3939 final List<PhylogenyNode> descs = n.getDescendants();
3940 for( final PhylogenyNode desc : descs ) {
3941 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
3944 if ( !n.isRoot() ) {
3945 r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3947 final double theta = _urt_nodeid_angle_map.get( n.getId() );
3948 n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) );
3949 n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) );
3950 for( final PhylogenyNode desc : descs ) {
3951 paintBranchCircularLite( n, desc, g );
3956 final private void paintCollapsedNode( final Graphics2D g,
3957 final PhylogenyNode node,
3958 final boolean to_graphics_file,
3959 final boolean to_pdf,
3960 final boolean is_in_found_nodes ) {
3962 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3965 else if ( is_in_found_nodes ) {
3966 c = getColorForFoundNode( node );
3968 else if ( getControlPanel().isColorAccordingToSequence() ) {
3969 c = getSequenceBasedColor( node );
3971 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3972 c = getTaxonomyBasedColor( node );
3974 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
3975 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3976 c = PhylogenyMethods.getBranchColorValue( node );
3979 c = getTreeColorSet().getCollapseFillColor();
3981 double d = node.getAllExternalDescendants().size();
3983 d = ( 3 * _y_distance ) / 3;
3986 d = ( Math.log10( d ) * _y_distance ) / 2.5;
3988 final int box_size = getOptions().getDefaultNodeShapeSize() + 1;
3989 if ( d < box_size ) {
3992 final float xx = node.getXcoord() - ( 2 * box_size );
3993 final float xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1;
3995 _polygon.moveTo( xxx, node.getYcoord() );
3996 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d );
3997 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d );
3998 _polygon.closePath();
3999 if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) {
4003 else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.NONE ) {
4004 g.setColor( getBackground() );
4009 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
4010 g.setPaint( new GradientPaint( xxx, node.getYcoord(), getBackground(), node.getXcoord(), ( float ) ( node
4011 .getYcoord() - d ), c, false ) );
4016 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4019 final private void paintConfidenceValues( final Graphics2D g,
4020 final PhylogenyNode node,
4021 final boolean to_pdf,
4022 final boolean to_graphics_file ) {
4023 final List<Confidence> confidences = node.getBranchData().getConfidences();
4024 boolean not_first = false;
4025 Collections.sort( confidences );
4026 final StringBuilder sb = new StringBuilder();
4027 for( final Confidence confidence : confidences ) {
4028 final double value = confidence.getValue();
4029 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
4030 if ( value < getOptions().getMinConfidenceValue() ) {
4039 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
4040 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4041 if ( getOptions().isShowConfidenceStddev() ) {
4042 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
4044 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getStandardDeviation(),
4046 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4052 if ( sb.length() > 0 ) {
4053 final float parent_x = node.getParent().getXcoord();
4054 float x = node.getXcoord();
4055 g.setFont( getTreeFontSet().getSmallFont() );
4056 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
4059 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
4062 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4063 g.setColor( Color.BLACK );
4066 g.setColor( getTreeColorSet().getConfidenceColor() );
4068 final String conf_str = sb.toString();
4069 TreePanel.drawString( conf_str,
4071 + ( ( x - parent_x - getTreeFontSet().getFontMetricsSmall()
4072 .stringWidth( conf_str ) ) / 2 ),
4073 ( node.getYcoord() + getTreeFontSet().getSmallMaxAscent() ) - 1,
4078 final private void paintGainedAndLostCharacters( final Graphics2D g,
4079 final PhylogenyNode node,
4080 final String gained,
4081 final String lost ) {
4082 if ( node.getParent() != null ) {
4083 final float parent_x = node.getParent().getXcoord();
4084 final float x = node.getXcoord();
4085 g.setFont( getTreeFontSet().getLargeFont() );
4086 g.setColor( getTreeColorSet().getGainedCharactersColor() );
4087 if ( Constants.SPECIAL_CUSTOM ) {
4088 g.setColor( Color.BLUE );
4091 .drawString( gained,
4093 + ( ( x - parent_x - getFontMetricsForLargeDefaultFont().stringWidth( gained ) ) / 2 ),
4094 ( node.getYcoord() - getFontMetricsForLargeDefaultFont().getMaxDescent() ),
4096 g.setColor( getTreeColorSet().getLostCharactersColor() );
4100 + ( ( x - parent_x - getFontMetricsForLargeDefaultFont().stringWidth( lost ) ) / 2 ),
4101 ( node.getYcoord() + getFontMetricsForLargeDefaultFont().getMaxAscent() ),
4107 * Draw a box at the indicated node.
4114 final private void paintNodeBox( final float x,
4116 final PhylogenyNode node,
4118 final boolean to_pdf,
4119 final boolean to_graphics_file ) {
4120 if ( node.isCollapse() ) {
4123 // if this node should be highlighted, do so
4124 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
4125 g.setColor( getTreeColorSet().getFoundColor0() );
4126 drawOval( x - 8, y - 8, 16, 16, g );
4127 drawOval( x - 9, y - 8, 17, 17, g );
4128 drawOval( x - 9, y - 9, 18, 18, g );
4130 if ( ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) )
4131 || ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() )
4132 || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() )
4133 || ( getControlPanel().isUseVisualStyles() && ( ( node.getNodeData().getNodeVisualData() != null ) && ( ( node
4134 .getNodeData().getNodeVisualData().getNodeColor() != null )
4135 || ( node.getNodeData().getNodeVisualData().getSize() != NodeVisualData.DEFAULT_SIZE )
4136 || ( node.getNodeData().getNodeVisualData().getFillType() != NodeFill.DEFAULT ) || ( node
4137 .getNodeData().getNodeVisualData().getShape() != NodeShape.DEFAULT ) ) ) )
4138 || ( getControlPanel().isEvents() && node.isHasAssignedEvent() && ( node.getNodeData().getEvent()
4140 || node.getNodeData().getEvent().isSpeciation() || node.getNodeData().getEvent()
4141 .isSpeciationOrDuplication() ) ) ) {
4142 NodeVisualData vis = null;
4143 if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
4144 && ( !node.getNodeData().getNodeVisualData().isEmpty() ) ) {
4145 vis = node.getNodeData().getNodeVisualData();
4147 float box_size = getOptions().getDefaultNodeShapeSize();
4148 if ( ( vis != null ) && ( vis.getSize() != NodeVisualData.DEFAULT_SIZE ) ) {
4149 box_size = vis.getSize();
4151 final float half_box_size = box_size / 2.0f;
4152 Color outline_color = null;
4153 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4154 outline_color = Color.BLACK;
4156 else if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
4157 outline_color = getColorForFoundNode( node );
4159 else if ( vis != null ) {
4160 if ( vis.getNodeColor() != null ) {
4161 outline_color = vis.getNodeColor();
4163 else if ( vis.getFontColor() != null ) {
4164 outline_color = vis.getFontColor();
4167 else if ( getControlPanel().isEvents() && TreePanelUtil.isHasAssignedEvent( node ) ) {
4168 final Event event = node.getNodeData().getEvent();
4169 if ( event.isDuplication() ) {
4170 outline_color = getTreeColorSet().getDuplicationBoxColor();
4172 else if ( event.isSpeciation() ) {
4173 outline_color = getTreeColorSet().getSpecBoxColor();
4175 else if ( event.isSpeciationOrDuplication() ) {
4176 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
4179 if ( outline_color == null ) {
4180 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
4181 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
4182 outline_color = getTreeColorSet().getBranchColorForPdf();
4185 NodeShape shape = null;
4186 if ( vis != null ) {
4187 if ( vis.getShape() == NodeShape.CIRCLE ) {
4188 shape = NodeShape.CIRCLE;
4190 else if ( vis.getShape() == NodeShape.RECTANGLE ) {
4191 shape = NodeShape.RECTANGLE;
4194 if ( shape == null ) {
4195 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
4196 shape = NodeShape.CIRCLE;
4198 else if ( getOptions().getDefaultNodeShape() == NodeShape.RECTANGLE ) {
4199 shape = NodeShape.RECTANGLE;
4202 NodeFill fill = null;
4203 if ( vis != null ) {
4204 if ( vis.getFillType() == NodeFill.SOLID ) {
4205 fill = NodeFill.SOLID;
4207 else if ( vis.getFillType() == NodeFill.NONE ) {
4208 fill = NodeFill.NONE;
4210 else if ( vis.getFillType() == NodeFill.GRADIENT ) {
4211 fill = NodeFill.GRADIENT;
4214 if ( fill == null ) {
4215 if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) {
4216 fill = NodeFill.SOLID;
4218 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
4219 fill = NodeFill.NONE;
4221 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
4222 fill = NodeFill.GRADIENT;
4225 Color vis_fill_color = null;
4226 if ( ( vis != null ) && ( vis.getNodeColor() != null ) ) {
4227 vis_fill_color = vis.getNodeColor();
4229 if ( shape == NodeShape.CIRCLE ) {
4230 if ( fill == NodeFill.GRADIENT ) {
4231 drawOvalGradient( x - half_box_size, y - half_box_size, box_size, box_size, g, to_pdf ? Color.WHITE
4232 : outline_color, to_pdf ? outline_color : getBackground(), outline_color );
4234 else if ( fill == NodeFill.NONE ) {
4235 Color background = getBackground();
4237 background = Color.WHITE;
4239 drawOvalGradient( x - half_box_size,
4248 else if ( fill == NodeVisualData.NodeFill.SOLID ) {
4249 if ( vis_fill_color != null ) {
4250 g.setColor( vis_fill_color );
4253 g.setColor( outline_color );
4255 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
4258 else if ( shape == NodeVisualData.NodeShape.RECTANGLE ) {
4259 if ( fill == NodeVisualData.NodeFill.GRADIENT ) {
4260 drawRectGradient( x - half_box_size, y - half_box_size, box_size, box_size, g, to_pdf ? Color.WHITE
4261 : outline_color, to_pdf ? outline_color : getBackground(), outline_color );
4263 else if ( fill == NodeVisualData.NodeFill.NONE ) {
4264 Color background = getBackground();
4266 background = Color.WHITE;
4268 drawRectGradient( x - half_box_size,
4277 else if ( fill == NodeVisualData.NodeFill.SOLID ) {
4278 if ( vis_fill_color != null ) {
4279 g.setColor( vis_fill_color );
4282 g.setColor( outline_color );
4284 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
4290 final private int paintNodeData( final Graphics2D g,
4291 final PhylogenyNode node,
4292 final boolean to_graphics_file,
4293 final boolean to_pdf,
4294 final boolean is_in_found_nodes ) {
4295 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
4298 if ( getOptions().isShowBranchLengthValues()
4299 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
4300 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
4301 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
4302 paintBranchLength( g, node, to_pdf, to_graphics_file );
4304 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
4309 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
4310 if ( getControlPanel().isShowTaxonomyImages()
4311 && ( getImageMap() != null )
4312 && !getImageMap().isEmpty()
4313 && node.getNodeData().isHasTaxonomy()
4314 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
4315 .getUris().isEmpty() ) ) {
4316 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
4318 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
4319 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
4320 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
4322 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
4323 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
4324 if ( _sb.length() > 0 ) {
4327 _sb.append( node.getAllExternalDescendants().size() );
4334 nodeDataAsSB( node, _sb );
4335 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
4336 float down_shift_factor = 3.0f;
4337 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
4338 down_shift_factor = 1;
4340 final float pos_x = node.getXcoord() + x + 2 + half_box_size;
4342 if ( !using_visual_font ) {
4343 pos_y = ( node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ) );
4346 pos_y = ( node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / down_shift_factor ) );
4348 final String sb_str = _sb.toString();
4349 // GUILHEM_BEG ______________
4350 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
4351 && ( _query_sequence != null ) ) {
4352 int nodeTextBoundsWidth = 0;
4353 if ( sb_str.length() > 0 ) {
4354 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
4355 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
4357 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
4358 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
4359 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
4360 g.setColor( getTreeColorSet().getBackgroundColor() );
4364 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
4365 for( final SequenceRelation seqRelation : seqRelations ) {
4366 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
4367 .getRef1().isEqual( _query_sequence ) )
4368 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
4369 .getSelectedItem() );
4370 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
4371 final double linePosX = node.getXcoord() + 2 + half_box_size;
4372 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
4373 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
4375 if ( sConfidence != null ) {
4376 float confidenceX = pos_x;
4377 if ( sb_str.length() > 0 ) {
4378 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
4379 + CONFIDENCE_LEFT_MARGIN;
4381 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
4382 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
4383 .getBounds().getWidth();
4384 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
4385 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
4388 if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
4390 if ( nodeTextBoundsWidth == 0 ) {
4391 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
4394 nodeTextBoundsWidth += 2;
4396 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
4397 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
4404 if ( sb_str.length() > 0 ) {
4405 TreePanel.drawString( sb_str, pos_x, pos_y, g );
4407 // GUILHEM_END _____________
4408 if ( _sb.length() > 0 ) {
4409 if ( !using_visual_font && !is_in_found_nodes ) {
4410 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
4413 x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
4416 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
4417 && ( node.getNodeData().getSequence().getAnnotations() != null )
4418 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
4419 final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
4420 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4421 g.setColor( Color.BLACK );
4423 else if ( getControlPanel().isColorAccordingToAnnotation() ) {
4424 g.setColor( calculateColorForAnnotation( ann ) );
4426 final String ann_str = TreePanelUtil.createAnnotationString( ann, getOptions().isShowAnnotationRefSource() );
4427 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
4428 + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ), g );
4430 _sb.append( ann_str );
4431 if ( _sb.length() > 0 ) {
4432 if ( !using_visual_font && !is_in_found_nodes ) {
4433 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
4436 x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
4440 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
4441 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
4442 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
4443 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
4444 && node.getNodeData().isHasBinaryCharacters() ) {
4445 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4446 g.setColor( Color.BLACK );
4449 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
4451 if ( getControlPanel().isShowBinaryCharacters() ) {
4452 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
4453 .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord()
4454 + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ), g );
4455 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
4456 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
4457 .getLostCharactersAsStringBuffer().toString() );
4461 .drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
4462 node.getXcoord() + x + 4 + half_box_size,
4464 + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ),
4466 paintGainedAndLostCharacters( g, node, "+"
4467 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
4468 + node.getNodeData().getBinaryCharacters().getLostCount() );
4475 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
4476 final PhylogenyNode node,
4477 final boolean to_pdf,
4478 final boolean to_graphics_file,
4479 final boolean radial_labels,
4480 final double ur_angle,
4481 final boolean is_in_found_nodes ) {
4482 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
4487 if ( node.getNodeData().isHasTaxonomy()
4488 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
4489 .isShowTaxonomyCommonNames() ) ) {
4490 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4491 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4492 _sb.append( taxonomy.getTaxonomyCode() );
4495 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4496 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4497 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4498 _sb.append( taxonomy.getScientificName() );
4500 _sb.append( taxonomy.getCommonName() );
4503 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4504 _sb.append( taxonomy.getScientificName() );
4507 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4508 _sb.append( taxonomy.getCommonName() );
4512 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4513 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4514 _sb.append( taxonomy.getScientificName() );
4518 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4519 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4520 _sb.append( taxonomy.getCommonName() );
4525 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
4527 _sb.append( node.getAllExternalDescendants().size() );
4530 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
4531 if ( _sb.length() > 0 ) {
4534 _sb.append( node.getName() );
4536 if ( node.getNodeData().isHasSequence() ) {
4537 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4538 if ( _sb.length() > 0 ) {
4541 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
4542 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
4545 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
4547 if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
4548 if ( _sb.length() > 0 ) {
4551 _sb.append( node.getNodeData().getSequence().getName() );
4554 //g.setFont( getTreeFontSet().getLargeFont() );
4555 //if ( is_in_found_nodes ) {
4556 // g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
4558 if ( _sb.length() > 1 ) {
4559 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
4560 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
4561 final String sb_str = _sb.toString();
4563 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4564 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
4567 m = ( float ) ( ur_angle % TWO_PI );
4569 _at = g.getTransform();
4570 boolean need_to_reset = false;
4571 final float x_coord = node.getXcoord();
4573 if ( !using_visual_font ) {
4574 y_coord = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / 3.0f );
4577 y_coord = node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / 3.0f );
4579 if ( radial_labels ) {
4580 need_to_reset = true;
4581 boolean left = false;
4582 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4586 g.rotate( m, x_coord, node.getYcoord() );
4588 if ( !using_visual_font ) {
4589 g.translate( -( getFontMetricsForLargeDefaultFont().getStringBounds( sb_str, g ).getWidth() ),
4593 g.translate( -( getFontMetrics( g.getFont() ).getStringBounds( sb_str, g ).getWidth() ), 0 );
4598 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4599 need_to_reset = true;
4600 if ( !using_visual_font ) {
4601 g.translate( -getFontMetricsForLargeDefaultFont().getStringBounds( sb_str, g ).getWidth(), 0 );
4604 g.translate( -getFontMetrics( g.getFont() ).getStringBounds( sb_str, g ).getWidth(), 0 );
4608 TreePanel.drawString( sb_str, x_coord, y_coord, g );
4609 if ( need_to_reset ) {
4610 g.setTransform( _at );
4615 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
4616 if ( node.isCollapse() ) {
4617 if ( !node.isRoot() && !node.getParent().isCollapse() ) {
4618 paintCollapsedNode( g, node, false, false, false );
4622 if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
4623 g.setColor( getColorForFoundNode( node ) );
4624 drawRectFilled( node.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, node.getYSecondary()
4625 - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, OVERVIEW_FOUND_NODE_BOX_SIZE, OVERVIEW_FOUND_NODE_BOX_SIZE, g );
4628 if ( !node.isExternal() && !node.isCollapse() ) {
4629 boolean first_child = true;
4631 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4632 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4633 final PhylogenyNode child_node = node.getChildNode( i );
4635 if ( !isUniformBranchLengthsForCladogram() ) {
4636 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4639 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4641 if ( first_child ) {
4642 first_child = false;
4643 y2 = node.getYSecondary()
4644 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
4645 .getNumberOfExternalNodes() ) );
4648 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4650 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
4651 new_x = x2 + node.getXSecondary();
4652 final float diff_y = node.getYSecondary() - y2;
4653 final float diff_x = node.getXSecondary() - new_x;
4654 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
4655 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
4657 child_node.setXSecondary( new_x );
4658 child_node.setYSecondary( y2 );
4659 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4664 final private void paintNodeRectangular( final Graphics2D g,
4665 final PhylogenyNode node,
4666 final boolean to_pdf,
4667 final boolean dynamically_hide,
4668 final int dynamic_hiding_factor,
4669 final boolean to_graphics_file ) {
4670 final boolean is_in_found_nodes = isInFoundNodes( node ) || isInCurrentExternalNodes( node );
4671 if ( node.isCollapse() ) {
4672 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) ) {
4673 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4677 if ( node.isExternal() ) {
4678 ++_external_node_index;
4680 // Confidence values
4681 if ( getControlPanel().isShowConfidenceValues()
4682 && !node.isExternal()
4684 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
4685 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
4686 && node.getBranchData().isHasConfidences() ) {
4687 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
4689 // Draw a line to root:
4690 if ( node.isRoot() && _phylogeny.isRooted() ) {
4691 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
4694 float new_x_min = Float.MAX_VALUE;
4695 final boolean disallow_shortcutting = ( dynamic_hiding_factor < 40 );
4696 float min_dist = 1.5f;
4697 if ( !disallow_shortcutting ) {
4698 // System.out.println( dynamic_hiding_factor );
4699 if ( dynamic_hiding_factor > 4000 ) {
4702 else if ( dynamic_hiding_factor > 1000 ) {
4705 else if ( dynamic_hiding_factor > 100 ) {
4709 if ( !node.isExternal() && !node.isCollapse() ) {
4710 boolean first_child = true;
4712 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4713 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4714 final PhylogenyNode child_node = node.getChildNode( i );
4716 if ( !isUniformBranchLengthsForCladogram() ) {
4717 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4720 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4722 if ( first_child ) {
4723 first_child = false;
4724 y2 = node.getYcoord()
4725 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
4728 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4730 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
4731 new_x = x2 + node.getXcoord();
4732 if ( dynamically_hide && ( x2 < new_x_min ) ) {
4735 final float diff_y = node.getYcoord() - y2;
4736 final float diff_x = node.getXcoord() - new_x;
4737 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
4738 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
4739 paintBranchRectangular( g,
4748 child_node.setXcoord( new_x );
4749 child_node.setYcoord( y2 );
4750 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4752 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file );
4754 if ( dynamically_hide
4755 && !is_in_found_nodes
4756 && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) ) || ( !node
4757 .isExternal() && ( ( new_x_min < 20 ) || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getFontMetricsForLargeDefaultFont()
4758 .getHeight() ) ) ) ) ) {
4761 final int x = paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4762 paintNodeWithRenderableData( x, g, node, to_graphics_file, to_pdf );
4765 final private void paintNodeWithRenderableData( final int x,
4767 final PhylogenyNode node,
4768 final boolean to_graphics_file,
4769 final boolean to_pdf ) {
4770 if ( isNodeDataInvisible( node ) && !( to_graphics_file || to_pdf ) ) {
4773 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
4776 int length_of_longest_text = -1;
4777 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4778 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4779 RenderableDomainArchitecture rds = null;
4781 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
4783 catch ( final ClassCastException cce ) {
4784 cce.printStackTrace();
4786 if ( rds != null ) {
4787 rds.setRenderingHeight( 6 );
4788 if ( getControlPanel().isDrawPhylogram() ) {
4789 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
4792 length_of_longest_text = calcLengthOfLongestText();
4793 rds.render( getPhylogeny().getFirstExternalNode().getXcoord() + length_of_longest_text,
4794 node.getYcoord() - 3,
4802 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
4803 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
4804 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
4805 getStatisticsForExpressionValues(),
4806 getConfiguration() );
4809 double domain_add = 0;
4810 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4811 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4812 domain_add = _domain_structure_width + 10;
4814 if ( getControlPanel().isDrawPhylogram() ) {
4815 rv.render( node.getXcoord() + x + domain_add, node.getYcoord() - 3, g, this, to_pdf );
4818 if ( length_of_longest_text < 0 ) {
4819 length_of_longest_text = calcLengthOfLongestText();
4821 rv.render( getPhylogeny().getFirstExternalNode().getXcoord() + length_of_longest_text + domain_add,
4822 node.getYcoord() - 3,
4831 private int calcLengthOfLongestText() {
4832 final StringBuilder sb = new StringBuilder();
4833 nodeDataAsSB( _ext_node_with_longest_txt_info, sb );
4834 if ( _ext_node_with_longest_txt_info.getNodeData().isHasTaxonomy() ) {
4835 nodeTaxonomyDataAsSB( _ext_node_with_longest_txt_info.getNodeData().getTaxonomy(), sb );
4837 return getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() + " " );
4840 final private void paintOvRectangle( final Graphics2D g ) {
4841 final float w_ratio = ( ( float ) getWidth() ) / getVisibleRect().width;
4842 final float h_ratio = ( ( float ) getHeight() ) / getVisibleRect().height;
4843 final float x_ratio = ( ( float ) getWidth() ) / getVisibleRect().x;
4844 final float y_ratio = ( ( float ) getHeight() ) / getVisibleRect().y;
4845 final float width = getOvMaxWidth() / w_ratio;
4846 final float height = getOvMaxHeight() / h_ratio;
4847 final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio );
4848 final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio );
4849 g.setColor( getTreeColorSet().getFoundColor0() );
4850 getOvRectangle().setRect( x, y, width, height );
4851 final Stroke s = g.getStroke();
4852 g.setStroke( STROKE_1 );
4853 if ( ( width < 6 ) && ( height < 6 ) ) {
4854 drawRectFilled( x, y, 6, 6, g );
4855 getOvVirtualRectangle().setRect( x, y, 6, 6 );
4857 else if ( width < 6 ) {
4858 drawRectFilled( x, y, 6, height, g );
4859 getOvVirtualRectangle().setRect( x, y, 6, height );
4861 else if ( height < 6 ) {
4862 drawRectFilled( x, y, width, 6, g );
4863 getOvVirtualRectangle().setRect( x, y, width, 6 );
4866 drawRect( x, y, width, height, g );
4867 if ( isInOvRect() ) {
4868 drawRect( x + 1, y + 1, width - 2, height - 2, g );
4870 getOvVirtualRectangle().setRect( x, y, width, height );
4875 final private void paintPhylogenyLite( final Graphics2D g ) {
4878 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
4879 .getWidth() ) ) ) );
4880 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
4881 final Stroke s = g.getStroke();
4882 g.setStroke( STROKE_05 );
4883 for( final PhylogenyNode element : _nodes_in_preorder ) {
4884 paintNodeLite( g, element );
4887 paintOvRectangle( g );
4891 * Paint the root branch. (Differs from others because it will always be a
4892 * single horizontal line).
4893 * @param to_graphics_file
4895 * @return new x1 value
4897 final private void paintRootBranch( final Graphics2D g,
4900 final PhylogenyNode root,
4901 final boolean to_pdf,
4902 final boolean to_graphics_file ) {
4903 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
4904 float d = getXdistance();
4905 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
4906 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
4908 if ( d < MIN_ROOT_LENGTH ) {
4909 d = MIN_ROOT_LENGTH;
4911 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
4912 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
4915 final double w = PhylogenyMethods.getBranchWidthValue( root );
4916 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
4918 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file );
4921 final private void paintScale( final Graphics2D g,
4924 final boolean to_pdf,
4925 final boolean to_graphics_file ) {
4927 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
4929 final int y2 = y1 - 8;
4930 final int y3 = y1 - 4;
4931 g.setFont( getTreeFontSet().getSmallFont() );
4932 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4933 g.setColor( Color.BLACK );
4936 g.setColor( getTreeColorSet().getBranchLengthColor() );
4938 final Stroke s = g.getStroke();
4939 g.setStroke( STROKE_1 );
4940 drawLine( x1, y1, x1, y2, g );
4941 drawLine( x2, y1, x2, y2, g );
4942 drawLine( x1, y3, x2, y3, g );
4943 if ( getScaleLabel() != null ) {
4944 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
4949 final private int paintTaxonomy( final Graphics2D g,
4950 final PhylogenyNode node,
4951 final boolean is_in_found_nodes,
4952 final boolean to_pdf,
4953 final boolean to_graphics_file,
4954 final float x_shift ) {
4955 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4956 final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
4957 setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getTaxonomyColor() );
4958 final float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
4960 if ( !using_visual_font ) {
4961 start_y = node.getYcoord()
4962 + ( getFontMetricsForLargeDefaultFont().getAscent() / ( node.getNumberOfDescendants() == 1 ? 1
4966 start_y = node.getYcoord()
4967 + ( getFontMetrics( g.getFont() ).getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) );
4970 nodeTaxonomyDataAsSB( taxonomy, _sb );
4971 final String label = _sb.toString();
4973 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
4974 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
4975 // invert font color and background color to show that this is the query sequence
4976 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
4980 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
4981 g.setColor( getTreeColorSet().getBackgroundColor() );
4984 TreePanel.drawString( label, start_x, start_y, g );
4985 if ( !using_visual_font && !is_in_found_nodes ) {
4986 return getFontMetricsForLargeDefaultFont().stringWidth( label );
4988 return getFontMetrics( g.getFont() ).stringWidth( label );
4991 final private void paintUnrooted( final PhylogenyNode n,
4992 final double low_angle,
4993 final double high_angle,
4994 final boolean radial_labels,
4996 final boolean to_pdf,
4997 final boolean to_graphics_file ) {
4999 n.setXcoord( getWidth() / 2 );
5000 n.setYcoord( getHeight() / 2 );
5002 if ( n.isExternal() ) {
5003 paintNodeDataUnrootedCirc( g,
5008 ( high_angle + low_angle ) / 2,
5009 isInFoundNodes( n ) || isInCurrentExternalNodes( n ) );
5012 final float num_enclosed = n.getNumberOfExternalNodes();
5013 final float x = n.getXcoord();
5014 final float y = n.getYcoord();
5015 double current_angle = low_angle;
5016 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
5017 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
5018 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
5019 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
5020 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
5021 final PhylogenyNode desc = n.getChildNode( i );
5022 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
5023 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
5024 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
5025 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
5028 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
5031 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
5034 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
5035 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
5037 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
5038 if ( desc.getDistanceToParent() < 0 ) {
5042 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
5046 length = getUrtFactor();
5048 final double mid_angle = current_angle + ( arc_size / 2 );
5049 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
5050 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
5051 desc.setXcoord( new_x );
5052 desc.setYcoord( new_y );
5053 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
5054 current_angle += arc_size;
5055 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
5056 drawLine( x, y, new_x, new_y, g );
5057 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file );
5060 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file );
5064 final private void paintUnrootedLite( final PhylogenyNode n,
5065 final double low_angle,
5066 final double high_angle,
5068 final float urt_ov_factor ) {
5070 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) );
5071 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) );
5072 n.setXSecondary( x_pos );
5073 n.setYSecondary( y_pos );
5075 if ( n.isExternal() ) {
5078 final float num_enclosed = n.getNumberOfExternalNodes();
5079 final float x = n.getXSecondary();
5080 final float y = n.getYSecondary();
5081 double current_angle = low_angle;
5082 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
5083 final PhylogenyNode desc = n.getChildNode( i );
5084 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
5085 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
5087 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
5088 if ( desc.getDistanceToParent() < 0 ) {
5092 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
5096 length = urt_ov_factor;
5098 final double mid_angle = current_angle + ( arc_size / 2 );
5099 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
5100 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
5101 desc.setXSecondary( new_x );
5102 desc.setYSecondary( new_y );
5103 if ( isInFoundNodes( desc ) || isInCurrentExternalNodes( desc ) ) {
5104 g.setColor( getColorForFoundNode( desc ) );
5105 drawRectFilled( desc.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
5106 desc.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF,
5107 OVERVIEW_FOUND_NODE_BOX_SIZE,
5108 OVERVIEW_FOUND_NODE_BOX_SIZE,
5110 g.setColor( getTreeColorSet().getOvColor() );
5112 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
5113 current_angle += arc_size;
5114 drawLine( x, y, new_x, new_y, g );
5118 final private void pasteSubtree( final PhylogenyNode node ) {
5119 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5120 errorMessageNoCutCopyPasteInUnrootedDisplay();
5123 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
5124 JOptionPane.showMessageDialog( this,
5125 "No tree in buffer (need to copy or cut a subtree first)",
5126 "Attempt to paste with empty buffer",
5127 JOptionPane.ERROR_MESSAGE );
5130 final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
5131 final Object[] options = { "As sibling", "As descendant", "Cancel" };
5132 final int r = JOptionPane.showOptionDialog( this,
5133 "How to paste subtree" + label + "?",
5135 JOptionPane.CLOSED_OPTION,
5136 JOptionPane.QUESTION_MESSAGE,
5140 boolean paste_as_sibling = true;
5142 paste_as_sibling = false;
5144 else if ( r != 0 ) {
5147 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
5148 buffer_phy.setAllNodesToNotCollapse();
5149 PhylogenyMethods.preOrderReId( buffer_phy );
5150 buffer_phy.setRooted( true );
5151 boolean need_to_show_whole = false;
5152 if ( paste_as_sibling ) {
5153 if ( node.isRoot() ) {
5154 JOptionPane.showMessageDialog( this,
5155 "Cannot paste sibling to root",
5156 "Attempt to paste sibling to root",
5157 JOptionPane.ERROR_MESSAGE );
5160 buffer_phy.addAsSibling( node );
5163 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
5164 need_to_show_whole = true;
5165 _phylogeny = buffer_phy;
5168 buffer_phy.addAsChild( node );
5171 if ( getCopiedAndPastedNodes() == null ) {
5172 setCopiedAndPastedNodes( new HashSet<Long>() );
5174 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
5175 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
5176 for( final PhylogenyNode n : nodes ) {
5177 node_ids.add( n.getId() );
5179 node_ids.add( node.getId() );
5180 getCopiedAndPastedNodes().addAll( node_ids );
5181 setNodeInPreorderToNull();
5182 _phylogeny.externalNodesHaveChanged();
5183 _phylogeny.clearHashIdToNodeMap();
5184 _phylogeny.recalculateNumberOfExternalDescendants( true );
5185 resetNodeIdToDistToLeafMap();
5187 if ( need_to_show_whole ) {
5188 getControlPanel().showWhole();
5193 private final StringBuffer propertiesToString( final PhylogenyNode node ) {
5194 final PropertiesMap properties = node.getNodeData().getProperties();
5195 final StringBuffer sb = new StringBuffer();
5196 boolean first = true;
5197 for( final String ref : properties.getPropertyRefs() ) {
5204 final Property p = properties.getProperty( ref );
5205 sb.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
5207 sb.append( p.getValue() );
5208 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
5209 sb.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
5215 private void setColor( final Graphics2D g,
5216 final PhylogenyNode node,
5217 final boolean to_graphics_file,
5218 final boolean to_pdf,
5219 final boolean is_in_found_nodes,
5220 final Color default_color ) {
5221 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
5222 g.setColor( Color.BLACK );
5224 else if ( is_in_found_nodes ) {
5225 g.setColor( getColorForFoundNode( node ) );
5227 else if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
5228 && ( node.getNodeData().getNodeVisualData().getFontColor() != null ) ) {
5229 g.setColor( node.getNodeData().getNodeVisualData().getFontColor() );
5231 else if ( getControlPanel().isColorAccordingToSequence() ) {
5232 g.setColor( getSequenceBasedColor( node ) );
5234 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
5235 g.setColor( getTaxonomyBasedColor( node ) );
5237 else if ( getControlPanel().isColorAccordingToAnnotation()
5238 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
5239 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
5240 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
5242 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
5243 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
5244 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
5246 else if ( to_pdf ) {
5247 g.setColor( Color.BLACK );
5250 g.setColor( default_color );
5254 final private void setCopiedAndPastedNodes( final Set<Long> nodeIds ) {
5255 getMainPanel().setCopiedAndPastedNodes( nodeIds );
5258 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
5259 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
5262 private boolean setFont( final Graphics2D g, final PhylogenyNode node, final boolean is_in_found_nodes ) {
5263 Font visual_font = null;
5264 if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null ) ) {
5265 visual_font = node.getNodeData().getNodeVisualData().getFont();
5266 g.setFont( visual_font != null ? visual_font : getTreeFontSet().getLargeFont() );
5269 g.setFont( getTreeFontSet().getLargeFont() );
5271 if ( is_in_found_nodes ) {
5272 g.setFont( g.getFont().deriveFont( Font.BOLD ) );
5274 return visual_font != null;
5277 final private void setInOv( final boolean in_ov ) {
5281 final private void setOvMaxHeight( final float ov_max_height ) {
5282 _ov_max_height = ov_max_height;
5285 final private void setOvMaxWidth( final float ov_max_width ) {
5286 _ov_max_width = ov_max_width;
5289 final private void setOvXcorrectionFactor( final float f ) {
5290 _ov_x_correction_factor = f;
5293 final private void setOvXDistance( final float ov_x_distance ) {
5294 _ov_x_distance = ov_x_distance;
5297 final private void setOvXPosition( final int ov_x_position ) {
5298 _ov_x_position = ov_x_position;
5301 final private void setOvYDistance( final float ov_y_distance ) {
5302 _ov_y_distance = ov_y_distance;
5305 final private void setOvYPosition( final int ov_y_position ) {
5306 _ov_y_position = ov_y_position;
5309 final private void setOvYStart( final int ov_y_start ) {
5310 _ov_y_start = ov_y_start;
5313 final private void setScaleDistance( final double scale_distance ) {
5314 _scale_distance = scale_distance;
5317 final private void setScaleLabel( final String scale_label ) {
5318 _scale_label = scale_label;
5321 private final void setupStroke( final Graphics2D g ) {
5322 if ( getYdistance() < 0.001 ) {
5323 g.setStroke( STROKE_005 );
5325 else if ( getYdistance() < 0.01 ) {
5326 g.setStroke( STROKE_01 );
5328 else if ( getYdistance() < 0.5 ) {
5329 g.setStroke( STROKE_025 );
5331 else if ( getYdistance() < 1 ) {
5332 g.setStroke( STROKE_05 );
5334 else if ( getYdistance() < 2 ) {
5335 g.setStroke( STROKE_075 );
5337 else if ( getYdistance() < 20 ) {
5338 g.setStroke( STROKE_1 );
5341 g.setStroke( STROKE_2 );
5345 final private void setUpUrtFactor() {
5346 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
5347 : getVisibleRect().height;
5348 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
5349 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
5352 final int max_depth = _circ_max_depth;
5353 if ( max_depth > 0 ) {
5354 setUrtFactor( d / ( 2 * max_depth ) );
5357 setUrtFactor( d / 2 );
5360 setUrtFactorOv( getUrtFactor() );
5363 final private void setUrtFactor( final float urt_factor ) {
5364 _urt_factor = urt_factor;
5367 final private void setUrtFactorOv( final float urt_factor_ov ) {
5368 _urt_factor_ov = urt_factor_ov;
5371 private void showExtDescNodeData( final PhylogenyNode node ) {
5372 final List<String> data = new ArrayList<String>();
5373 final List<PhylogenyNode> nodes = node.getAllExternalDescendants();
5374 if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
5375 for( final PhylogenyNode n : getFoundNodesAsListOfPhylogenyNodes() ) {
5376 if ( !nodes.contains( n ) ) {
5381 for( final PhylogenyNode n : nodes ) {
5382 switch ( getOptions().getExtDescNodeDataToReturn() ) {
5384 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
5385 data.add( n.getName() );
5389 if ( n.getNodeData().isHasSequence()
5390 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
5391 data.add( n.getNodeData().getSequence().getName() );
5395 if ( n.getNodeData().isHasSequence()
5396 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
5397 data.add( n.getNodeData().getSequence().getGeneName() );
5400 case SEQUENCE_SYMBOL:
5401 if ( n.getNodeData().isHasSequence()
5402 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
5403 data.add( n.getNodeData().getSequence().getSymbol() );
5406 case SEQUENCE_MOL_SEQ:
5407 if ( n.getNodeData().isHasSequence()
5408 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
5409 data.add( n.getNodeData().getSequence().getMolecularSequence() );
5412 case SEQUENCE_MOL_SEQ_FASTA:
5413 final StringBuilder sb = new StringBuilder();
5414 if ( n.getNodeData().isHasSequence()
5415 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
5416 final StringBuilder ann = new StringBuilder();
5417 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
5418 ann.append( n.getName() );
5421 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
5422 ann.append( "SYM=" );
5423 ann.append( n.getNodeData().getSequence().getSymbol() );
5426 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
5427 ann.append( "NAME=" );
5428 ann.append( n.getNodeData().getSequence().getName() );
5431 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
5432 ann.append( "GN=" );
5433 ann.append( n.getNodeData().getSequence().getGeneName() );
5436 if ( n.getNodeData().getSequence().getAccession() != null ) {
5437 ann.append( "ACC=" );
5438 ann.append( n.getNodeData().getSequence().getAccession().asText() );
5441 if ( n.getNodeData().isHasTaxonomy() ) {
5442 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
5443 ann.append( "TAXID=" );
5444 ann.append( n.getNodeData().getTaxonomy().getTaxonomyCode() );
5447 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
5448 ann.append( "SN=" );
5449 ann.append( n.getNodeData().getTaxonomy().getScientificName() );
5454 if ( ann.charAt( ann.length() - 1 ) == '|' ) {
5455 ann_str = ann.substring( 0, ann.length() - 1 );
5458 ann_str = ann.toString();
5460 sb.append( SequenceWriter.toFasta( ann_str, n.getNodeData().getSequence()
5461 .getMolecularSequence(), 60 ) );
5462 data.add( sb.toString() );
5466 if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
5467 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
5468 data.add( n.getNodeData().getSequence().getAccession().toString() );
5471 case TAXONOMY_SCIENTIFIC_NAME:
5472 if ( n.getNodeData().isHasTaxonomy()
5473 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
5474 data.add( n.getNodeData().getTaxonomy().getScientificName() );
5477 case TAXONOMY_COMM0N_NAME:
5478 if ( n.getNodeData().isHasTaxonomy()
5479 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getCommonName() ) ) {
5480 data.add( n.getNodeData().getTaxonomy().getCommonName() );
5484 if ( n.getNodeData().isHasTaxonomy()
5485 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
5486 data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
5490 TreePanelUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
5493 throw new IllegalArgumentException( "unknown data element: "
5494 + getOptions().getExtDescNodeDataToReturn() );
5497 final StringBuilder sb = new StringBuilder();
5498 final int size = TreePanelUtil.makeSB( data, getOptions(), sb );
5499 if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
5500 || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
5501 if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
5502 System.out.println( sb );
5504 if ( sb.length() < 1 ) {
5505 clearCurrentExternalNodesDataBuffer();
5508 setCurrentExternalNodesDataBuffer( sb );
5511 else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
5512 if ( sb.length() < 1 ) {
5513 TreePanelUtil.showInformationMessage( this, "No Appropriate Data (" + obtainTitleForExtDescNodeData()
5514 + ")", "Descendants of selected node do not contain selected data" );
5515 clearCurrentExternalNodesDataBuffer();
5518 setCurrentExternalNodesDataBuffer( sb );
5520 if ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() ) {
5521 title = ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
5522 : obtainTitleForExtDescNodeData() )
5525 + " nodes, unique entries: "
5529 title = ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
5530 : obtainTitleForExtDescNodeData() )
5534 + node.getNumberOfExternalNodes()
5535 + " external descendats of node "
5537 + ", unique entries: " + size;
5539 final String s = sb.toString().trim();
5540 if ( getMainPanel().getMainFrame() == null ) {
5541 // Must be "E" applet version.
5542 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
5543 ae.showTextFrame( s, title );
5546 getMainPanel().getMainFrame().showTextFrame( s, title );
5552 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
5554 if ( ( node.getName().length() > 0 )
5555 || ( node.getNodeData().isHasTaxonomy() && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData()
5557 || ( node.getNodeData().isHasSequence() && !TreePanelUtil.isSequenceEmpty( node.getNodeData()
5558 .getSequence() ) ) || ( node.getNodeData().isHasDate() )
5559 || ( node.getNodeData().isHasDistribution() ) || node.getBranchData().isHasConfidences() ) {
5560 _popup_buffer.setLength( 0 );
5562 if ( node.getName().length() > 0 ) {
5564 _popup_buffer.append( node.getName() );
5566 if ( node.getNodeData().isHasTaxonomy()
5567 && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
5569 boolean enc_data = false;
5570 final Taxonomy tax = node.getNodeData().getTaxonomy();
5571 if ( _popup_buffer.length() > 0 ) {
5572 _popup_buffer.append( "\n" );
5574 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
5575 _popup_buffer.append( "[" );
5576 _popup_buffer.append( tax.getTaxonomyCode() );
5577 _popup_buffer.append( "]" );
5580 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
5582 _popup_buffer.append( " " );
5584 _popup_buffer.append( tax.getScientificName() );
5587 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
5589 _popup_buffer.append( " (" );
5592 _popup_buffer.append( "(" );
5594 _popup_buffer.append( tax.getCommonName() );
5595 _popup_buffer.append( ")" );
5598 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
5600 _popup_buffer.append( " (" );
5603 _popup_buffer.append( "(" );
5605 _popup_buffer.append( tax.getAuthority() );
5606 _popup_buffer.append( ")" );
5609 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
5611 _popup_buffer.append( " [" );
5614 _popup_buffer.append( "[" );
5616 _popup_buffer.append( tax.getRank() );
5617 _popup_buffer.append( "]" );
5620 if ( tax.getSynonyms().size() > 0 ) {
5622 _popup_buffer.append( " " );
5624 _popup_buffer.append( "[" );
5626 for( final String syn : tax.getSynonyms() ) {
5627 if ( !ForesterUtil.isEmpty( syn ) ) {
5629 _popup_buffer.append( syn );
5630 if ( counter < tax.getSynonyms().size() ) {
5631 _popup_buffer.append( ", " );
5636 _popup_buffer.append( "]" );
5639 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
5640 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
5641 _popup_buffer.append( "[" );
5642 _popup_buffer.append( tax.getIdentifier().getProvider() );
5643 _popup_buffer.append( "] " );
5645 _popup_buffer.append( tax.getIdentifier().getValue() );
5649 if ( node.getNodeData().isHasSequence()
5650 && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) ) {
5652 boolean enc_data = false;
5653 if ( _popup_buffer.length() > 0 ) {
5654 _popup_buffer.append( "\n" );
5656 final Sequence seq = node.getNodeData().getSequence();
5657 if ( seq.getAccession() != null ) {
5658 _popup_buffer.append( "[" );
5659 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
5660 _popup_buffer.append( seq.getAccession().getSource() );
5661 _popup_buffer.append( ":" );
5663 _popup_buffer.append( seq.getAccession().getValue() );
5664 _popup_buffer.append( "]" );
5667 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
5669 _popup_buffer.append( " [" );
5672 _popup_buffer.append( "[" );
5674 _popup_buffer.append( seq.getSymbol() );
5675 _popup_buffer.append( "]" );
5678 if ( !ForesterUtil.isEmpty( seq.getGeneName() ) ) {
5680 _popup_buffer.append( " [" );
5683 _popup_buffer.append( "[" );
5685 _popup_buffer.append( seq.getGeneName() );
5686 _popup_buffer.append( "]" );
5689 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
5691 _popup_buffer.append( " " );
5693 _popup_buffer.append( seq.getName() );
5696 if ( node.getNodeData().isHasDate() ) {
5698 if ( _popup_buffer.length() > 0 ) {
5699 _popup_buffer.append( "\n" );
5701 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
5703 if ( node.getNodeData().isHasDistribution() ) {
5705 if ( _popup_buffer.length() > 0 ) {
5706 _popup_buffer.append( "\n" );
5708 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
5710 if ( node.getBranchData().isHasConfidences() ) {
5711 final List<Confidence> confs = node.getBranchData().getConfidences();
5712 for( final Confidence confidence : confs ) {
5714 if ( _popup_buffer.length() > 0 ) {
5715 _popup_buffer.append( "\n" );
5717 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
5718 _popup_buffer.append( "[" );
5719 _popup_buffer.append( confidence.getType() );
5720 _popup_buffer.append( "] " );
5723 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
5725 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5726 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5727 _popup_buffer.append( " (sd=" );
5728 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence
5729 .getStandardDeviation(), getOptions()
5730 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5731 _popup_buffer.append( ")" );
5735 if ( node.getNodeData().isHasProperties() ) {
5736 final PropertiesMap properties = node.getNodeData().getProperties();
5737 for( final String ref : properties.getPropertyRefs() ) {
5738 _popup_buffer.append( "\n" );
5739 final Property p = properties.getProperty( ref );
5740 _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
5741 _popup_buffer.append( "=" );
5742 _popup_buffer.append( p.getValue() );
5743 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
5744 _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
5748 if ( _popup_buffer.length() > 0 ) {
5749 if ( !getConfiguration().isUseNativeUI() ) {
5751 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
5752 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
5753 if ( isInFoundNodes0( node ) && !isInFoundNodes1( node ) ) {
5754 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0() );
5756 else if ( !isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
5757 _rollover_popup.setForeground( getTreeColorSet().getFoundColor1() );
5759 else if ( isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
5760 _rollover_popup.setForeground( getTreeColorSet().getFoundColor0and1() );
5763 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
5767 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
5769 _rollover_popup.setText( _popup_buffer.toString() );
5770 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
5772 e.getLocationOnScreen().x + 10,
5773 e.getLocationOnScreen().y
5775 _node_desc_popup.show();
5779 catch ( final Exception ex ) {
5784 final private void showNodeEditFrame( final PhylogenyNode n ) {
5785 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5786 // pop up edit box for single node
5787 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
5788 _node_frame_index++;
5791 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5795 final private void showNodeFrame( final PhylogenyNode n ) {
5796 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5797 // pop up edit box for single node
5798 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
5799 _node_frame_index++;
5802 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5806 final private void switchDisplaygetPhylogenyGraphicsType() {
5807 switch ( getPhylogenyGraphicsType() ) {
5809 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5810 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5813 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5814 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5817 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5818 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5821 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5822 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5825 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5826 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5829 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5830 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5833 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5834 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5837 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5838 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5841 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
5843 if ( getControlPanel().getDynamicallyHideData() != null ) {
5844 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5845 getControlPanel().getDynamicallyHideData().setEnabled( false );
5848 getControlPanel().getDynamicallyHideData().setEnabled( true );
5851 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5852 getControlPanel().setDrawPhylogramEnabled( true );
5855 getControlPanel().setDrawPhylogramEnabled( false );
5857 if ( getMainPanel().getMainFrame() == null ) {
5858 // Must be "E" applet version.
5859 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
5860 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5863 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5867 private final static void colorizeNodesHelper( final Color c, final PhylogenyNode node ) {
5868 if ( node.getNodeData().getNodeVisualData() == null ) {
5869 node.getNodeData().setNodeVisualData( new NodeVisualData() );
5871 node.getNodeData().getNodeVisualData().setFontColor( new Color( c.getRed(), c.getGreen(), c.getBlue() ) );
5874 final private static void drawString( final String str, final float x, final float y, final Graphics2D g ) {
5875 g.drawString( str, x, y );
5878 final private static boolean plusPressed( final int key_code ) {
5879 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
5880 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
5883 final private class NodeColorizationActionListener implements ActionListener {
5885 List<PhylogenyNode> _additional_nodes = null;
5886 JColorChooser _chooser = null;
5887 PhylogenyNode _node = null;
5889 NodeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
5894 NodeColorizationActionListener( final JColorChooser chooser,
5895 final PhylogenyNode node,
5896 final List<PhylogenyNode> additional_nodes ) {
5899 _additional_nodes = additional_nodes;
5903 public void actionPerformed( final ActionEvent e ) {
5904 final Color c = _chooser.getColor();
5906 colorizeNodes( c, _node, _additional_nodes );
5911 final private class SubtreeColorizationActionListener implements ActionListener {
5913 List<PhylogenyNode> _additional_nodes = null;
5914 JColorChooser _chooser = null;
5915 PhylogenyNode _node = null;
5917 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
5922 SubtreeColorizationActionListener( final JColorChooser chooser,
5923 final PhylogenyNode node,
5924 final List<PhylogenyNode> additional_nodes ) {
5927 _additional_nodes = additional_nodes;
5931 public void actionPerformed( final ActionEvent e ) {
5932 final Color c = _chooser.getColor();
5934 colorizeSubtree( c, _node, _additional_nodes );