2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.archaeopteryx;
28 import java.awt.BasicStroke;
29 import java.awt.Color;
30 import java.awt.Cursor;
31 import java.awt.Dimension;
33 import java.awt.GradientPaint;
34 import java.awt.Graphics;
35 import java.awt.Graphics2D;
36 import java.awt.Point;
37 import java.awt.Rectangle;
38 import java.awt.RenderingHints;
39 import java.awt.Stroke;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.FocusAdapter;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.InputEvent;
45 import java.awt.event.KeyAdapter;
46 import java.awt.event.KeyEvent;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseWheelEvent;
49 import java.awt.event.MouseWheelListener;
50 import java.awt.font.FontRenderContext;
51 import java.awt.font.TextLayout;
52 import java.awt.geom.AffineTransform;
53 import java.awt.geom.Arc2D;
54 import java.awt.geom.CubicCurve2D;
55 import java.awt.geom.Ellipse2D;
56 import java.awt.geom.Line2D;
57 import java.awt.geom.Path2D;
58 import java.awt.geom.QuadCurve2D;
59 import java.awt.geom.Rectangle2D;
60 import java.awt.image.BufferedImage;
61 import java.awt.print.PageFormat;
62 import java.awt.print.Printable;
63 import java.awt.print.PrinterException;
65 import java.io.IOException;
66 import java.io.UnsupportedEncodingException;
68 import java.net.URISyntaxException;
69 import java.net.URLEncoder;
70 import java.text.DecimalFormat;
71 import java.text.DecimalFormatSymbols;
72 import java.text.NumberFormat;
73 import java.util.ArrayList;
74 import java.util.Collections;
75 import java.util.HashMap;
76 import java.util.HashSet;
77 import java.util.Hashtable;
78 import java.util.List;
79 import java.util.Map.Entry;
81 import java.util.SortedMap;
82 import java.util.SortedSet;
83 import java.util.TreeMap;
85 import javax.swing.BorderFactory;
86 import javax.swing.JApplet;
87 import javax.swing.JColorChooser;
88 import javax.swing.JDialog;
89 import javax.swing.JMenuItem;
90 import javax.swing.JOptionPane;
91 import javax.swing.JPanel;
92 import javax.swing.JPopupMenu;
93 import javax.swing.JTextArea;
94 import javax.swing.Popup;
95 import javax.swing.PopupFactory;
97 import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON;
98 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
99 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
100 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
101 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
102 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
103 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
104 import org.forester.archaeopteryx.tools.Blast;
105 import org.forester.archaeopteryx.tools.ImageLoader;
106 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
107 import org.forester.io.writers.SequenceWriter;
108 import org.forester.phylogeny.Phylogeny;
109 import org.forester.phylogeny.PhylogenyMethods;
110 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
111 import org.forester.phylogeny.PhylogenyNode;
112 import org.forester.phylogeny.data.Annotation;
113 import org.forester.phylogeny.data.BranchColor;
114 import org.forester.phylogeny.data.Confidence;
115 import org.forester.phylogeny.data.Event;
116 import org.forester.phylogeny.data.NodeData.NODE_DATA;
117 import org.forester.phylogeny.data.NodeVisualization;
118 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
119 import org.forester.phylogeny.data.NodeVisualization.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.SequenceIdParser;
135 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
137 private static final BasicStroke STROKE_2 = new BasicStroke( 2f );
138 private static final BasicStroke STROKE_1 = new BasicStroke( 1f );
139 private static final BasicStroke STROKE_075 = new BasicStroke( 0.75f );
140 private static final BasicStroke STROKE_05 = new BasicStroke( 0.5f );
141 private static final BasicStroke STROKE_025 = new BasicStroke( 0.25f );
142 private static final BasicStroke STROKE_01 = new BasicStroke( 0.1f );
143 private static final BasicStroke STROKE_005 = new BasicStroke( 0.05f );
144 private static final float PI = ( float ) ( Math.PI );
145 private static final double TWO_PI = 2 * Math.PI;
146 private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
147 private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
148 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
149 private static final short OV_BORDER = 10;
150 final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
151 final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
152 final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
153 final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
154 final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
155 private final static long serialVersionUID = -978349745916505029L;
156 private final static int EURO_D = 10;
157 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
158 private final static int MIN_ROOT_LENGTH = 3;
159 private final static int MAX_SUBTREES = 100;
160 private final static int MAX_NODE_FRAMES = 10;
161 private final static int MOVE = 20;
162 private final static NumberFormat FORMATTER_CONFIDENCE;
163 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
164 private final static int WIGGLE = 2;
165 private final static int LIMIT_FOR_HQ_RENDERING = 2000;
166 private final static int CONFIDENCE_LEFT_MARGIN = 4;
167 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
168 RenderingHints.VALUE_RENDER_DEFAULT );
169 private File _treefile = null;
170 private Configuration _configuration = null;
171 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
172 private int _node_frame_index = 0;
173 private Phylogeny _phylogeny = null;
174 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
175 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
176 private int _subtree_index = 0;
177 private MainPanel _main_panel = null;
178 private Set<Long> _found_nodes = null;
179 private PhylogenyNode _highlight_node = null;
180 private JPopupMenu _node_popup_menu = null;
181 private JMenuItem _node_popup_menu_items[] = null;
182 private int _longest_ext_node_info = 0;
183 private float _x_correction_factor = 0.0f;
184 private float _ov_x_correction_factor = 0.0f;
185 private float _x_distance = 0.0f;
186 private float _y_distance = 0.0f;
187 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
188 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
189 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
190 private float _last_drag_point_x = 0;
191 private float _last_drag_point_y = 0;
192 private ControlPanel _control_panel = null;
193 private int _external_node_index = 0;
194 private final Path2D.Float _polygon = new Path2D.Float();
195 private final StringBuilder _sb = new StringBuilder();
196 private JColorChooser _color_chooser = null;
197 private double _scale_distance = 0.0;
198 private String _scale_label = null;
199 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
200 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
201 private final Line2D _line = new Line2D.Float();
202 private final Ellipse2D _ellipse = new Ellipse2D.Float();
203 private final Rectangle2D _rectangle = new Rectangle2D.Float();
204 private Options _options = null;
205 private float _ov_max_width = 0;
206 private float _ov_max_height = 0;
207 private int _ov_x_position = 0;
208 private int _ov_y_position = 0;
209 private int _ov_y_start = 0;
210 private float _ov_y_distance = 0;
211 private float _ov_x_distance = 0;
212 private boolean _ov_on = false;
213 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
214 private float _urt_factor = 1;
215 private float _urt_factor_ov = 1;
216 private final boolean _phy_has_branch_lengths;
217 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
218 private boolean _in_ov_rect = false;
219 private boolean _in_ov = false;
220 private final Rectangle _ov_virtual_rectangle = new Rectangle();
221 final private static double _180_OVER_PI = 180.0 / Math.PI;
222 private static final float ROUNDED_D = 8;
223 private int _circ_max_depth;
224 private PhylogenyNode _root;
225 final private Arc2D _arc = new Arc2D.Double();
226 final private HashMap<Long, Double> _urt_nodeid_angle_map = new HashMap<Long, Double>();
227 final private HashMap<Long, Integer> _urt_nodeid_index_map = new HashMap<Long, Integer>();
228 final private Set<Long> _collapsed_external_nodeid_set = new HashSet<Long>();
229 HashMap<Long, Short> _nodeid_dist_to_leaf = new HashMap<Long, Short>();
230 private AffineTransform _at;
231 private double _max_distance_to_root = -1;
232 private int _dynamic_hiding_factor = 0;
233 private boolean _edited = false;
234 private Popup _node_desc_popup;
235 private JTextArea _rollover_popup;
236 private final StringBuffer _popup_buffer = new StringBuffer();
237 final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(),
240 private Sequence _query_sequence = null;
241 private final FontRenderContext _frc = new FontRenderContext( null,
244 // expression values menu:
245 private DescriptiveStatistics _statistics_for_vector_data;
246 private PhylogenyNode[] _nodes_in_preorder = null;
247 private StringBuilder _current_external_nodes_data_buffer = new StringBuilder();
248 private int _current_external_nodes_data_buffer_change_counter = 0;
249 private Set<Long> _current_external_nodes = null;
250 // private Image offscreenImage;
251 // private Graphics offscreenGraphics;
252 // private Dimension offscreenDimension;
254 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
255 dfs.setDecimalSeparator( '.' );
256 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
257 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
260 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
261 requestFocusInWindow();
262 addKeyListener( new KeyAdapter() {
265 public void keyPressed( final KeyEvent key_event ) {
266 keyPressedCalls( key_event );
267 requestFocusInWindow();
270 addFocusListener( new FocusAdapter() {
273 public void focusGained( final FocusEvent e ) {
274 requestFocusInWindow();
277 if ( ( t == null ) || t.isEmpty() ) {
278 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
280 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
282 _configuration = configuration;
284 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
286 // if ( !_phylogeny.isEmpty() ) {
287 _phylogeny.recalculateNumberOfExternalDescendants( true );
288 checkForVectorProperties( _phylogeny );
290 setBackground( getTreeColorSet().getBackgroundColor() );
291 final MouseListener mouse_listener = new MouseListener( this );
292 addMouseListener( mouse_listener );
293 addMouseMotionListener( mouse_listener );
294 addMouseWheelListener( this );
295 calculateScaleDistance();
296 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
297 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
298 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
302 final public void actionPerformed( final ActionEvent e ) {
303 boolean done = false;
304 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
305 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
306 // NOTE: index corresponds to the indices of click-to options
307 // in the control panel.
308 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
309 // Set this as the new default click-to action
310 _main_panel.getControlPanel().setClickToAction( index );
311 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
312 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
313 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
318 requestFocusInWindow();
321 public synchronized Hashtable<String, BufferedImage> getImageMap() {
322 return getMainPanel().getImageMap();
325 final public MainPanel getMainPanel() {
330 * Get a pointer to the phylogeny
332 * @return a pointer to the phylogeny
334 public final Phylogeny getPhylogeny() {
339 final public void mouseWheelMoved( final MouseWheelEvent e ) {
340 final int notches = e.getWheelRotation();
341 if ( inOvVirtualRectangle( e ) ) {
342 if ( !isInOvRect() ) {
348 if ( isInOvRect() ) {
349 setInOvRect( false );
353 if ( e.isControlDown() ) {
355 getTreeFontSet().increaseFontSize();
356 getControlPanel().displayedPhylogenyMightHaveChanged( true );
359 getTreeFontSet().decreaseFontSize( 1, false );
360 getControlPanel().displayedPhylogenyMightHaveChanged( true );
363 else if ( e.isShiftDown() ) {
364 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
365 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
367 for( int i = 0; i < ( -notches ); ++i ) {
368 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
369 getControlPanel().displayedPhylogenyMightHaveChanged( false );
373 for( int i = 0; i < notches; ++i ) {
374 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
375 if ( getStartingAngle() < 0 ) {
376 setStartingAngle( TWO_PI + getStartingAngle() );
378 getControlPanel().displayedPhylogenyMightHaveChanged( false );
384 for( int i = 0; i < ( -notches ); ++i ) {
385 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
386 getControlPanel().displayedPhylogenyMightHaveChanged( false );
390 for( int i = 0; i < notches; ++i ) {
391 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
392 getControlPanel().displayedPhylogenyMightHaveChanged( false );
399 for( int i = 0; i < ( -notches ); ++i ) {
400 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
401 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
402 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
403 getControlPanel().displayedPhylogenyMightHaveChanged( false );
407 for( int i = 0; i < notches; ++i ) {
408 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
409 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
410 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
411 getControlPanel().displayedPhylogenyMightHaveChanged( false );
416 requestFocusInWindow();
421 final public void paintComponent( final Graphics g ) {
422 // Dimension currentSize = getSize();
423 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
424 // call the 'java.awt.Component.createImage(...)' method to get an
426 // offscreenImage = createImage( currentSize.width, currentSize.height );
427 // offscreenGraphics = offscreenImage.getGraphics();
428 // offscreenDimension = currentSize;
430 // super.paintComponent( g ); //why?
431 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
432 final Graphics2D g2d = ( Graphics2D ) g;
433 g2d.setRenderingHints( _rendering_hints );
434 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
435 //g.drawImage( offscreenImage, 0, 0, this );
439 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
440 throws PrinterException {
441 if ( page_index > 0 ) {
442 return ( NO_SUCH_PAGE );
445 final Graphics2D g2d = ( Graphics2D ) g;
446 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
447 // Turn off double buffering !?
448 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
449 // Turn double buffering back on !?
450 return ( PAGE_EXISTS );
454 public final void setEdited( final boolean edited ) {
458 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
459 getMainPanel().setImageMap( image_map );
463 * Set a phylogeny tree.
466 * an instance of a Phylogeny
468 public final void setTree( final Phylogeny t ) {
469 setNodeInPreorderToNull();
473 public final void setWaitCursor() {
474 setCursor( WAIT_CURSOR );
479 public void update( final Graphics g ) {
483 final void calcMaxDepth() {
484 if ( _phylogeny != null ) {
485 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
490 * Set parameters for printing the displayed tree
493 final void calcParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
494 // updateStyle(); not needed?
495 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
497 if ( recalc_longest_ext_node_info ) {
498 calculateLongestExtNodeInfo();
499 if ( getOptions().isAllowFontSizeChange() ) {
500 if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
501 && ( getTreeFontSet().getLargeFont().getSize() > 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) {
502 while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) )
503 && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) {
504 getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(),
506 calculateLongestExtNodeInfo();
510 while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) )
511 && ( getTreeFontSet().getLargeFont().getSize() <= getTreeFontSet().getLargeFontMemory()
512 .getSize() - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) {
513 getMainPanel().getTreeFontSet().increaseFontSize();
514 calculateLongestExtNodeInfo();
519 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
520 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
521 if ( ext_nodes == 1 ) {
522 ext_nodes = max_depth;
523 if ( ext_nodes < 1 ) {
530 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
531 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
532 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
535 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
536 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
538 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
542 if ( ov_xdist < 0.0 ) {
548 setXdistance( xdist );
549 setYdistance( ydist );
550 setOvXDistance( ov_xdist );
551 final double height = _phylogeny.getHeight();
553 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
554 setXcorrectionFactor( corr > 0 ? corr : 0 );
555 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
556 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
559 setXcorrectionFactor( 0 );
560 setOvXcorrectionFactor( 0 );
562 _circ_max_depth = max_depth;
565 if ( getOptions().isAllowFontSizeChange() ) {
566 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
567 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
568 // int dynamic_hiding_factor = calcDynamicHidingFactor();
569 // if ( dynamic_hiding_factor > 1 ) {
570 // while ( dynamic_hiding_factor > 1
571 // && getTreeFontSet()._fm_large.getHeight() > TreeFontSet.SMALL_FONTS_BASE ) {
572 // getTreeFontSet().decreaseFontSize( 1, true );
573 // dynamic_hiding_factor = calcDynamicHidingFactor();
576 // else if ( getTreeFontSet().isDecreasedSizeBySystem() ) {
577 // while ( dynamic_hiding_factor < 1 && getTreeFontSet()._fm_large.getHeight() < 12 ) {
578 // getTreeFontSet().increaseFontSize();
579 // dynamic_hiding_factor = calcDynamicHidingFactor();
588 final void calculateLongestExtNodeInfo() {
589 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
592 int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - MOVE )
593 * Constants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
594 if ( max_length < 40 ) {
598 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
600 if ( node.isCollapse() ) {
603 if ( getControlPanel().isShowNodeNames() ) {
604 sum += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
606 if ( node.getNodeData().isHasSequence() ) {
607 if ( getControlPanel().isShowSequenceAcc()
608 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
609 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
613 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
614 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
616 if ( getControlPanel().isShowGeneSymbols()
617 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
618 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
620 if ( getControlPanel().isShowAnnotation()
621 && ( node.getNodeData().getSequence().getAnnotations() != null )
622 && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
623 sum += getTreeFontSet()._fm_large.stringWidth( AptxUtil.createAnnotationString( node.getNodeData()
624 .getSequence().getAnnotations(), getOptions().isShowAnnotationRefSource() )
627 if ( getControlPanel().isShowDomainArchitectures()
628 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
629 sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() )
630 .getRenderingSize().getWidth();
633 if ( node.getNodeData().isHasTaxonomy() ) {
634 final Taxonomy tax = node.getNodeData().getTaxonomy();
635 if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
636 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getTaxonomyCode() + " " );
638 if ( getControlPanel().isShowTaxonomyScientificNames()
639 && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
640 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getScientificName() + " " );
642 if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
643 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getCommonName() + " ()" );
646 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
647 sum += getTreeFontSet()._fm_large.stringWidth( propertiesToString( node ).toString() );
649 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
650 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters()
651 .getGainedCharactersAsStringBuffer().toString() );
653 if ( sum >= max_length ) {
654 setLongestExtNodeInfo( max_length );
657 if ( sum > longest ) {
661 if ( longest >= max_length ) {
662 setLongestExtNodeInfo( max_length );
665 setLongestExtNodeInfo( 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 ( ForesterUtil.isEmpty( tax.getTaxonomyCode() ) && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
703 return getTreeColorSet().getTaxonomyColor();
706 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
707 c = getControlPanel().getSpeciesColors().get( tax.getTaxonomyCode() );
709 if ( ( c == null ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
710 c = getControlPanel().getSpeciesColors().get( tax.getScientificName() );
713 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
714 c = AptxUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
715 getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c );
718 c = AptxUtil.calculateColorFromString( tax.getScientificName(), true );
719 getControlPanel().getSpeciesColors().put( tax.getScientificName(), c );
725 void checkForVectorProperties( final Phylogeny phy ) {
726 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
727 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
728 final PhylogenyNode node = iter.next();
729 if ( node.getNodeData().getProperties() != null ) {
730 final PropertiesMap pm = node.getNodeData().getProperties();
731 final double[] vector = new double[ pm.getProperties().size() ];
733 for( final String ref : pm.getProperties().keySet() ) {
734 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
735 final Property p = pm.getProperty( ref );
736 final String value_str = p.getValue();
737 final String index_str = ref
738 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
741 d = Double.parseDouble( value_str );
743 catch ( final NumberFormatException e ) {
744 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
745 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
750 i = Integer.parseInt( index_str );
752 catch ( final NumberFormatException e ) {
753 JOptionPane.showMessageDialog( this,
754 "Could not parse \"" + index_str
755 + "\" into index for vector data",
756 "Problem with Vector Data",
757 JOptionPane.ERROR_MESSAGE );
761 JOptionPane.showMessageDialog( this,
762 "Attempt to use negative index for vector data",
763 "Problem with Vector Data",
764 JOptionPane.ERROR_MESSAGE );
772 final List<Double> vector_l = new ArrayList<Double>( counter );
773 for( int i = 0; i < counter; ++i ) {
774 vector_l.add( vector[ i ] );
776 node.getNodeData().setVector( vector_l );
779 if ( stats.getN() > 0 ) {
780 _statistics_for_vector_data = stats;
784 void clearCurrentExternalNodesDataBuffer() {
785 setCurrentExternalNodesDataBuffer( new StringBuilder() );
789 * Collapse the tree from the given node
794 final void collapse( final PhylogenyNode node ) {
795 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
796 JOptionPane.showMessageDialog( this,
797 "Cannot collapse in unrooted display type",
798 "Attempt to collapse in unrooted display",
799 JOptionPane.WARNING_MESSAGE );
802 if ( !node.isExternal() && !node.isRoot() ) {
803 final boolean collapse = !node.isCollapse();
804 AptxUtil.collapseSubtree( node, collapse );
805 updateSetOfCollapsedExternalNodes();
806 _phylogeny.recalculateNumberOfExternalDescendants( true );
807 resetNodeIdToDistToLeafMap();
808 calculateLongestExtNodeInfo();
809 setNodeInPreorderToNull();
810 _control_panel.displayedPhylogenyMightHaveChanged( true );
811 resetPreferredSize();
813 _main_panel.adjustJScrollPane();
818 final void collapseSpeciesSpecificSubtrees() {
819 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
823 AptxUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
824 updateSetOfCollapsedExternalNodes();
825 _phylogeny.recalculateNumberOfExternalDescendants( true );
826 resetNodeIdToDistToLeafMap();
827 calculateLongestExtNodeInfo();
828 setNodeInPreorderToNull();
829 resetPreferredSize();
830 _main_panel.adjustJScrollPane();
835 final void colorRank( final String rank ) {
836 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
840 AptxUtil.removeBranchColors( _phylogeny );
841 final int colorizations = AptxUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
842 if ( colorizations > 0 ) {
843 _control_panel.setColorBranches( true );
844 if ( _control_panel.getColorBranchesCb() != null ) {
845 _control_panel.getColorBranchesCb().setSelected( true );
847 if ( _control_panel.getColorAccSpeciesCb() != null ) {
848 _control_panel.getColorAccSpeciesCb().setSelected( false );
850 _options.setColorLabelsSameAsParentBranch( true );
851 _control_panel.repaint();
855 if ( colorizations > 0 ) {
856 String msg = "Taxonomy colorization via " + rank + " completed:\n";
857 if ( colorizations > 1 ) {
858 msg += "colorized " + colorizations + " subtrees";
861 msg += "colorized one subtree";
864 JOptionPane.showMessageDialog( this,
866 "Taxonomy Colorization Completed (" + rank + ")",
867 JOptionPane.INFORMATION_MESSAGE );
870 String msg = "Could not taxonomy colorize any subtree via " + rank + ".\n";
871 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
872 msg += "select a different rank (e.g. phylum, genus, ...)\n";
875 msg += "1. \"" + MainFrameApplication.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
876 msg += "2. \"" + MainFrameApplication.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
877 JOptionPane.showMessageDialog( this, msg, "Taxonomy Colorization Failed", JOptionPane.WARNING_MESSAGE );
881 final void confColor() {
882 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
886 AptxUtil.removeBranchColors( _phylogeny );
887 AptxUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
888 _control_panel.setColorBranches( true );
889 if ( _control_panel.getColorBranchesCb() != null ) {
890 _control_panel.getColorBranchesCb().setSelected( true );
896 final void decreaseDomainStructureEvalueThreshold() {
897 if ( _domain_structure_e_value_thr_exp > -20 ) {
898 _domain_structure_e_value_thr_exp -= 1;
903 * Find the node, if any, at the given location
907 * @return pointer to the node at x,y, null if not found
909 final PhylogenyNode findNode( final int x, final int y ) {
910 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
913 final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE;
914 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
915 final PhylogenyNode node = iter.next();
916 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
917 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
918 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
919 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
920 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
927 final Configuration getConfiguration() {
928 return _configuration;
931 final ControlPanel getControlPanel() {
932 return _control_panel;
935 String getCurrentExternalNodesDataBufferAsString() {
936 return _current_external_nodes_data_buffer.toString();
939 int getCurrentExternalNodesDataBufferChangeCounter() {
940 return _current_external_nodes_data_buffer_change_counter;
943 final int getDomainStructureEvalueThreshold() {
944 return _domain_structure_e_value_thr_exp;
947 final Set<Long> getFoundNodes() {
951 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
952 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
953 return ( PhylogenyMethods.getBranchColorValue( node ) );
956 return ( getTreeColorSet().getBranchColor() );
960 final int getLongestExtNodeInfo() {
961 return _longest_ext_node_info;
964 final Options getOptions() {
965 if ( _options == null ) {
966 _options = getControlPanel().getOptions();
971 final Rectangle2D getOvRectangle() {
972 return _ov_rectangle;
975 final Rectangle getOvVirtualRectangle() {
976 return _ov_virtual_rectangle;
979 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
980 return _graphics_type;
983 final double getStartingAngle() {
984 return _urt_starting_angle;
987 DescriptiveStatistics getStatisticsForExpressionValues() {
988 return _statistics_for_vector_data;
992 * Find a color for this species name.
995 * @return the species color
997 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
998 if ( node.getNodeData().isHasTaxonomy() ) {
999 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
1001 // return non-colorized color
1002 return getTreeColorSet().getTaxonomyColor();
1006 * @return pointer to colorset for tree drawing
1008 final TreeColorSet getTreeColorSet() {
1009 return getMainPanel().getTreeColorSet();
1012 final File getTreeFile() {
1016 final float getXcorrectionFactor() {
1017 return _x_correction_factor;
1020 final float getXdistance() {
1024 final float getYdistance() {
1028 final void increaseDomainStructureEvalueThreshold() {
1029 if ( _domain_structure_e_value_thr_exp < 3 ) {
1030 _domain_structure_e_value_thr_exp += 1;
1034 final void initNodeData() {
1035 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1038 double max_original_domain_structure_width = 0.0;
1039 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1040 if ( node.getNodeData().isHasSequence()
1041 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1042 RenderableDomainArchitecture rds = null;
1043 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
1044 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
1045 getConfiguration() );
1046 node.getNodeData().getSequence().setDomainArchitecture( rds );
1049 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1051 if ( getControlPanel().isShowDomainArchitectures() ) {
1052 final double dsw = rds.getOriginalSize().getWidth();
1053 if ( dsw > max_original_domain_structure_width ) {
1054 max_original_domain_structure_width = dsw;
1059 if ( getControlPanel().isShowDomainArchitectures() ) {
1060 final double ds_factor_width = _domain_structure_width / max_original_domain_structure_width;
1061 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1062 if ( node.getNodeData().isHasSequence()
1063 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1064 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1065 .getSequence().getDomainArchitecture();
1066 rds.setRenderingFactorWidth( ds_factor_width );
1067 rds.setParameter( _domain_structure_e_value_thr_exp );
1073 final boolean inOv( final MouseEvent e ) {
1074 return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) )
1075 && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) )
1076 && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) ) && ( e.getY() < ( ( getVisibleRect().y
1077 + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) );
1080 final boolean inOvRectangle( final MouseEvent e ) {
1081 return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) )
1082 && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) )
1083 && ( e.getY() >= ( getOvRectangle().getY() - 1 ) ) && ( e.getY() <= ( getOvRectangle().getY()
1084 + getOvRectangle().getHeight() + 1 ) ) );
1087 final boolean isApplet() {
1088 return getMainPanel() instanceof MainPanelApplets;
1091 final boolean isCanCollapse() {
1092 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1095 final boolean isCanColorSubtree() {
1096 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1099 final boolean isCanCopy() {
1100 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1103 final boolean isCanCut( final PhylogenyNode node ) {
1104 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1108 final boolean isCanDelete() {
1109 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1112 final boolean isCanPaste() {
1113 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1114 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1117 final boolean isCanReroot() {
1118 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1121 final boolean isCanSubtree( final PhylogenyNode node ) {
1122 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1123 .isRoot() || ( _subtree_index > 0 ) ) );
1126 final boolean isCurrentTreeIsSubtree() {
1127 return ( _subtree_index > 0 );
1130 final boolean isEdited() {
1134 final boolean isInOvRect() {
1138 final boolean isOvOn() {
1142 final boolean isPhyHasBranchLengths() {
1143 return _phy_has_branch_lengths;
1146 final void midpointRoot() {
1147 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1150 if ( !_phylogeny.isRerootable() ) {
1151 JOptionPane.showMessageDialog( this,
1152 "This is not rerootable",
1154 JOptionPane.WARNING_MESSAGE );
1157 setNodeInPreorderToNull();
1159 PhylogenyMethods.midpointRoot( _phylogeny );
1160 resetNodeIdToDistToLeafMap();
1166 final void mouseClicked( final MouseEvent e ) {
1167 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1168 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1169 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1170 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) )
1172 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) )
1180 final double max_x = getWidth() - getVisibleRect().width;
1181 final double max_y = getHeight() - getVisibleRect().height;
1188 getMainPanel().getCurrentScrollPane().getViewport()
1189 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1190 setInOvRect( true );
1194 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1195 if ( node != null ) {
1196 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1199 _highlight_node = node;
1200 // Check if shift key is down
1201 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1202 // Yes, so add to _found_nodes
1203 if ( getFoundNodes() == null ) {
1204 setFoundNodes( new HashSet<Long>() );
1206 getFoundNodes().add( node.getId() );
1207 // Check if control key is down
1209 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1210 // Yes, so pop-up menu
1211 displayNodePopupMenu( node, e.getX(), e.getY() );
1212 // Handle unadorned click
1215 // Check for right mouse button
1216 if ( e.getModifiers() == 4 ) {
1217 displayNodePopupMenu( node, e.getX(), e.getY() );
1220 // if not in _found_nodes, clear _found_nodes
1221 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1226 // no node was clicked
1227 _highlight_node = null;
1233 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1234 setCursor( MOVE_CURSOR );
1235 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1236 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1237 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1238 if ( scroll_position.x < 0 ) {
1239 scroll_position.x = 0;
1242 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1243 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1244 if ( scroll_position.x > max_x ) {
1245 scroll_position.x = max_x;
1248 if ( scroll_position.y < 0 ) {
1249 scroll_position.y = 0;
1252 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1253 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1254 if ( scroll_position.y > max_y ) {
1255 scroll_position.y = max_y;
1258 if ( isOvOn() || getOptions().isShowScale() ) {
1261 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1264 final void mouseDragInOvRectangle( final MouseEvent e ) {
1265 setCursor( HAND_CURSOR );
1266 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1267 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1268 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1269 double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) );
1270 double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) );
1271 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1272 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1273 if ( scroll_position.x <= 0 ) {
1274 scroll_position.x = 0;
1278 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1279 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1280 if ( scroll_position.x >= max_x ) {
1282 scroll_position.x = max_x;
1285 if ( scroll_position.y <= 0 ) {
1287 scroll_position.y = 0;
1290 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1291 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1292 if ( scroll_position.y >= max_y ) {
1294 scroll_position.y = max_y;
1298 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1299 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1300 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1303 final void mouseMoved( final MouseEvent e ) {
1304 requestFocusInWindow();
1305 if ( _current_external_nodes != null ) {
1306 _current_external_nodes = null;
1309 if ( getControlPanel().isNodeDescPopup() ) {
1310 if ( _node_desc_popup != null ) {
1311 _node_desc_popup.hide();
1312 _node_desc_popup = null;
1315 if ( getOptions().isShowOverview() && isOvOn() ) {
1316 if ( inOvVirtualRectangle( e ) ) {
1317 if ( !isInOvRect() ) {
1318 setInOvRect( true );
1323 if ( isInOvRect() ) {
1324 setInOvRect( false );
1329 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
1338 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1339 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
1340 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.GET_EXT_DESC_DATA ) ) {
1341 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
1342 addToCurrentExternalNodes( n.getId() );
1344 setCursor( HAND_CURSOR );
1347 else if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
1348 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
1349 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
1350 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
1351 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
1352 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
1353 setCursor( CUT_CURSOR );
1356 setCursor( HAND_CURSOR );
1357 if ( getControlPanel().isNodeDescPopup() ) {
1358 showNodeDataPopup( e, node );
1363 setCursor( ARROW_CURSOR );
1368 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
1369 setCursor( ARROW_CURSOR );
1372 final void multiplyUrtFactor( final float f ) {
1376 final JApplet obtainApplet() {
1377 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1380 final void paintBranchCircular( final PhylogenyNode p,
1381 final PhylogenyNode c,
1383 final boolean radial_labels,
1384 final boolean to_pdf,
1385 final boolean to_graphics_file ) {
1386 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1387 final double root_x = _root.getXcoord();
1388 final double root_y = _root.getYcoord();
1389 final double dx = root_x - p.getXcoord();
1390 final double dy = root_y - p.getYcoord();
1391 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1392 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1393 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
1394 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
1395 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
1396 final double r2 = 2.0 * parent_radius;
1397 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1399 drawLine( c.getXcoord(),
1401 root_x + ( Math.cos( angle ) * parent_radius ),
1402 root_y + ( Math.sin( angle ) * parent_radius ),
1404 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c )
1405 || isInCurrentExternalNodes( c ) );
1406 if ( c.isExternal() ) {
1407 final boolean is_in_found_nodes = isInFoundNodes( c ) || isInCurrentExternalNodes( c );
1408 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
1409 && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
1412 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
1416 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
1417 final double angle = _urt_nodeid_angle_map.get( c.getId() );
1418 final double root_x = _root.getXSecondary();
1419 final double root_y = _root.getYSecondary();
1420 final double dx = root_x - p.getXSecondary();
1421 final double dy = root_y - p.getYSecondary();
1422 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
1423 final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) );
1424 g.setColor( getTreeColorSet().getOvColor() );
1425 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
1426 final double r2 = 2.0 * parent_radius;
1427 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
1429 drawLine( c.getXSecondary(),
1431 root_x + ( Math.cos( angle ) * parent_radius ),
1432 root_y + ( Math.sin( angle ) * parent_radius ),
1434 if ( isInFoundNodes( c ) || isInCurrentExternalNodes( c ) ) {
1435 g.setColor( getTreeColorSet().getFoundColor() );
1436 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
1440 final void paintCircular( final Phylogeny phy,
1441 final double starting_angle,
1446 final boolean to_pdf,
1447 final boolean to_graphics_file ) {
1448 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
1449 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
1450 _root = phy.getRoot();
1451 _root.setXcoord( center_x );
1452 _root.setYcoord( center_y );
1453 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1454 double current_angle = starting_angle;
1456 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1457 final PhylogenyNode n = it.next();
1458 if ( !n.isCollapse() ) {
1459 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1460 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1461 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1462 _urt_nodeid_index_map.put( n.getId(), i++ );
1463 current_angle += ( TWO_PI / circ_num_ext_nodes );
1467 System.out.println( "is collapse" + n.getName() );
1470 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
1471 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file, isInFoundNodes( _root ) );
1474 final void paintCircularLite( final Phylogeny phy,
1475 final double starting_angle,
1479 final Graphics2D g ) {
1480 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
1481 _root = phy.getRoot();
1482 _root.setXSecondary( center_x );
1483 _root.setYSecondary( center_y );
1484 double current_angle = starting_angle;
1485 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1486 final PhylogenyNode n = it.next();
1487 n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
1488 n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
1489 _urt_nodeid_angle_map.put( n.getId(), current_angle );
1490 current_angle += ( TWO_PI / circ_num_ext_nodes );
1492 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
1495 final void paintPhylogeny( final Graphics2D g,
1496 final boolean to_pdf,
1497 final boolean to_graphics_file,
1498 final int graphics_file_width,
1499 final int graphics_file_height,
1500 final int graphics_file_x,
1501 final int graphics_file_y ) {
1502 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1505 if ( _control_panel.isShowSequenceRelations() ) {
1506 _query_sequence = _control_panel.getSelectedQuerySequence();
1508 // Color the background
1510 final Rectangle r = getVisibleRect();
1511 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
1512 g.setColor( getTreeColorSet().getBackgroundColor() );
1513 if ( !to_graphics_file ) {
1517 if ( getOptions().isPrintBlackAndWhite() ) {
1518 g.setColor( Color.WHITE );
1520 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1524 if ( !to_graphics_file ) {
1525 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
1526 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
1530 g.setPaint( new GradientPaint( graphics_file_x,
1532 getTreeColorSet().getBackgroundColor(),
1534 graphics_file_y + graphics_file_height,
1535 getTreeColorSet().getBackgroundColorGradientBottom() ) );
1536 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
1542 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
1544 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1545 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1546 _external_node_index = 0;
1547 // Position starting X of tree
1548 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
1549 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
1551 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
1552 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
1553 .getDistanceToParent() * getXcorrectionFactor() ) ) );
1556 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
1558 // Position starting Y of tree
1559 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
1560 + ( TreePanel.MOVE / 2.0f ) );
1561 final int dynamic_hiding_factor = calcDynamicHidingFactor();
1562 if ( getControlPanel().isDynamicallyHideData() ) {
1563 if ( dynamic_hiding_factor > 1 ) {
1564 getControlPanel().setDynamicHidingIsOn( true );
1567 getControlPanel().setDynamicHidingIsOn( false );
1570 if ( _nodes_in_preorder == null ) {
1571 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
1573 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1574 _nodes_in_preorder[ i++ ] = it.next();
1577 //final PhylogenyNodeIterator it;
1578 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
1579 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
1580 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1582 for( final PhylogenyNode element : _nodes_in_preorder ) {
1583 paintNodeRectangular( g, element, to_pdf, getControlPanel().isDynamicallyHideData()
1584 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
1586 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
1587 if ( !( to_graphics_file || to_pdf ) ) {
1590 getVisibleRect().y + getVisibleRect().height,
1595 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
1598 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1599 paintPhylogenyLite( g );
1602 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1603 if ( getControlPanel().getDynamicallyHideData() != null ) {
1604 getControlPanel().setDynamicHidingIsOn( false );
1606 final double angle = getStartingAngle();
1607 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
1608 _dynamic_hiding_factor = 0;
1609 if ( getControlPanel().isDynamicallyHideData() ) {
1610 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
1611 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
1613 if ( getControlPanel().getDynamicallyHideData() != null ) {
1614 if ( _dynamic_hiding_factor > 1 ) {
1615 getControlPanel().setDynamicHidingIsOn( true );
1618 getControlPanel().setDynamicHidingIsOn( false );
1621 paintUnrooted( _phylogeny.getRoot(),
1623 ( float ) ( angle + ( 2 * Math.PI ) ),
1628 if ( getOptions().isShowScale() ) {
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 g.setColor( getTreeColorSet().getOvColor() );
1642 paintUnrootedLite( _phylogeny.getRoot(),
1644 angle + ( 2 * Math.PI ),
1646 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
1647 paintOvRectangle( g );
1650 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1651 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
1652 final int d = radius + MOVE + getLongestExtNodeInfo();
1653 _dynamic_hiding_factor = 0;
1654 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
1655 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
1656 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
1658 if ( getControlPanel().getDynamicallyHideData() != null ) {
1659 if ( _dynamic_hiding_factor > 1 ) {
1660 getControlPanel().setDynamicHidingIsOn( true );
1663 getControlPanel().setDynamicHidingIsOn( false );
1666 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
1667 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
1668 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
1669 : getOvMaxWidth() / 2 );
1670 double x_scale = 1.0;
1671 double y_scale = 1.0;
1672 int x_pos = getVisibleRect().x + getOvXPosition();
1673 int y_pos = getVisibleRect().y + getOvYPosition();
1674 if ( getWidth() > getHeight() ) {
1675 x_scale = ( double ) getHeight() / getWidth();
1676 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
1679 y_scale = ( double ) getWidth() / getHeight();
1680 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
1682 _at = g.getTransform();
1683 g.scale( x_scale, y_scale );
1684 paintCircularLite( _phylogeny,
1688 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
1691 g.setTransform( _at );
1692 paintOvRectangle( g );
1697 final void recalculateMaxDistanceToRoot() {
1698 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
1702 * Remove all edit-node frames
1704 final void removeAllEditNodeJFrames() {
1705 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
1706 if ( _node_frames[ i ] != null ) {
1707 _node_frames[ i ].dispose();
1708 _node_frames[ i ] = null;
1711 _node_frame_index = 0;
1715 * Remove a node-edit frame.
1717 final void removeEditNodeFrame( final int i ) {
1718 _node_frame_index--;
1719 _node_frames[ i ] = null;
1720 if ( i < _node_frame_index ) {
1721 for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) {
1722 _node_frames[ j ] = _node_frames[ j + 1 ];
1724 _node_frames[ _node_frame_index ] = null;
1728 final void reRoot( final PhylogenyNode node ) {
1729 if ( !getPhylogeny().isRerootable() ) {
1730 JOptionPane.showMessageDialog( this,
1731 "This is not rerootable",
1733 JOptionPane.WARNING_MESSAGE );
1736 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1737 JOptionPane.showMessageDialog( this,
1738 "Cannot reroot in unrooted display type",
1739 "Attempt to reroot tree in unrooted display",
1740 JOptionPane.WARNING_MESSAGE );
1743 getPhylogeny().reRoot( node );
1744 getPhylogeny().recalculateNumberOfExternalDescendants( true );
1745 resetNodeIdToDistToLeafMap();
1746 setNodeInPreorderToNull();
1747 resetPreferredSize();
1748 getMainPanel().adjustJScrollPane();
1751 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1752 getControlPanel().showWhole();
1756 final void resetNodeIdToDistToLeafMap() {
1757 _nodeid_dist_to_leaf = new HashMap<Long, Short>();
1760 final void resetPreferredSize() {
1761 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
1767 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
1768 if ( getControlPanel().isDrawPhylogram() ) {
1770 + getLongestExtNodeInfo()
1772 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
1775 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
1777 + getLongestExtNodeInfo()
1778 + ForesterUtil.roundToInt( getXdistance()
1779 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
1783 + getLongestExtNodeInfo()
1784 + ForesterUtil.roundToInt( getXdistance()
1785 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
1788 setPreferredSize( new Dimension( x, y ) );
1791 final void selectNode( final PhylogenyNode node ) {
1792 if ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) ) {
1793 getFoundNodes().remove( node.getId() );
1794 getControlPanel().setSearchFoundCountsOnLabel( getFoundNodes().size() );
1795 if ( getFoundNodes().size() < 1 ) {
1796 getControlPanel().searchReset();
1800 getControlPanel().getSearchFoundCountsLabel().setVisible( true );
1801 getControlPanel().getSearchResetButton().setEnabled( true );
1802 getControlPanel().getSearchResetButton().setVisible( true );
1803 if ( getFoundNodes() == null ) {
1804 setFoundNodes( new HashSet<Long>() );
1806 getFoundNodes().add( node.getId() );
1807 getControlPanel().setSearchFoundCountsOnLabel( getFoundNodes().size() );
1811 final void setArrowCursor() {
1812 setCursor( ARROW_CURSOR );
1816 final void setControlPanel( final ControlPanel atv_control ) {
1817 _control_panel = atv_control;
1820 void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
1821 increaseCurrentExternalNodesDataBufferChangeCounter();
1822 _current_external_nodes_data_buffer = sb;
1825 final void setFoundNodes( final Set<Long> found_nodes ) {
1826 _found_nodes = found_nodes;
1829 final void setInOvRect( final boolean in_ov_rect ) {
1830 _in_ov_rect = in_ov_rect;
1833 final void setLargeFonts() {
1834 getTreeFontSet().largeFonts();
1837 final void setLastMouseDragPointX( final float x ) {
1838 _last_drag_point_x = x;
1841 final void setLastMouseDragPointY( final float y ) {
1842 _last_drag_point_y = y;
1845 final void setLongestExtNodeInfo( final int i ) {
1846 _longest_ext_node_info = i;
1849 final void setMediumFonts() {
1850 getTreeFontSet().mediumFonts();
1853 final void setNodeInPreorderToNull() {
1854 _nodes_in_preorder = null;
1857 final void setOvOn( final boolean ov_on ) {
1861 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
1862 _graphics_type = graphics_type;
1866 final void setSmallFonts() {
1867 getTreeFontSet().smallFonts();
1870 final void setStartingAngle( final double starting_angle ) {
1871 _urt_starting_angle = starting_angle;
1874 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
1875 _statistics_for_vector_data = statistics_for_expression_values;
1878 final void setSuperTinyFonts() {
1879 getTreeFontSet().superTinyFonts();
1882 final void setTextAntialias() {
1883 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
1884 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
1885 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
1888 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
1891 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
1892 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
1894 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
1896 // catch ( final Throwable e ) {
1897 // _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
1901 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
1902 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
1906 final void setTinyFonts() {
1907 getTreeFontSet().tinyFonts();
1910 final void setTreeFile( final File treefile ) {
1911 _treefile = treefile;
1914 final void setXcorrectionFactor( final float f ) {
1915 _x_correction_factor = f;
1918 final void setXdistance( final float x ) {
1922 final void setYdistance( final float y ) {
1926 final void sortDescendants( final PhylogenyNode node ) {
1927 if ( !node.isExternal() ) {
1928 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
1929 if ( ( !getControlPanel().isShowTaxonomyScientificNames() && !getControlPanel().isShowTaxonomyCode() && !getControlPanel()
1930 .isShowTaxonomyCommonNames() ) ) {
1931 if ( ( getControlPanel().isShowSequenceAcc() || getControlPanel().isShowGeneNames() || getControlPanel()
1932 .isShowGeneSymbols() ) ) {
1933 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
1935 else if ( getControlPanel().isShowNodeNames() ) {
1936 pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
1939 PhylogenyMethods.sortNodeDescendents( node, pri );
1940 setNodeInPreorderToNull();
1941 _phylogeny.externalNodesHaveChanged();
1942 _phylogeny.clearHashIdToNodeMap();
1943 _phylogeny.recalculateNumberOfExternalDescendants( true );
1944 resetNodeIdToDistToLeafMap();
1950 final void subTree( final PhylogenyNode node ) {
1951 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1952 JOptionPane.showMessageDialog( this,
1953 "Cannot get a sub/super tree in unrooted display",
1954 "Attempt to get sub/super tree in unrooted display",
1955 JOptionPane.WARNING_MESSAGE );
1958 if ( node.isExternal() ) {
1959 JOptionPane.showMessageDialog( this,
1960 "Cannot get a subtree of a external node",
1961 "Attempt to get subtree of external node",
1962 JOptionPane.WARNING_MESSAGE );
1965 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
1966 JOptionPane.showMessageDialog( this,
1967 "Cannot get a subtree of the root node",
1968 "Attempt to get subtree of root node",
1969 JOptionPane.WARNING_MESSAGE );
1972 setNodeInPreorderToNull();
1973 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
1974 _sub_phylogenies[ _subtree_index ] = _phylogeny;
1975 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
1977 _phylogeny = subTree( node, _phylogeny );
1978 updateSubSuperTreeButton();
1980 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
1983 _main_panel.getControlPanel().showWhole();
1987 final void superTree() {
1988 setNodeInPreorderToNull();
1989 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
1990 for( final PhylogenyNode n : temp_root.getDescendants() ) {
1991 n.setParent( temp_root );
1993 _sub_phylogenies[ _subtree_index ] = null;
1994 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
1995 _phylogeny = _sub_phylogenies[ --_subtree_index ];
1996 updateSubSuperTreeButton();
1999 final void swap( final PhylogenyNode node ) {
2000 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
2003 if ( node.getNumberOfDescendants() > 2 ) {
2004 JOptionPane.showMessageDialog( this,
2005 "Cannot swap descendants of nodes with more than 2 descendants",
2006 "Cannot swap descendants",
2007 JOptionPane.ERROR_MESSAGE );
2010 if ( !node.isExternal() ) {
2011 node.swapChildren();
2012 setNodeInPreorderToNull();
2013 _phylogeny.externalNodesHaveChanged();
2014 _phylogeny.clearHashIdToNodeMap();
2015 _phylogeny.recalculateNumberOfExternalDescendants( true );
2016 resetNodeIdToDistToLeafMap();
2022 final void taxColor() {
2023 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
2027 AptxUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
2028 _control_panel.setColorBranches( true );
2029 if ( _control_panel.getColorBranchesCb() != null ) {
2030 _control_panel.getColorBranchesCb().setSelected( true );
2037 final void updateOvSettings() {
2038 switch ( getOptions().getOvPlacement() ) {
2040 setOvXPosition( OV_BORDER );
2041 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
2042 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
2045 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
2046 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
2047 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
2050 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
2051 setOvYPosition( OV_BORDER );
2052 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2055 setOvXPosition( OV_BORDER );
2056 setOvYPosition( OV_BORDER );
2057 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
2062 final void updateOvSizes() {
2063 if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) ) || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) {
2065 float l = getLongestExtNodeInfo();
2066 final float w_ratio = getOvMaxWidth() / getWidth();
2068 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
2069 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
2071 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
2072 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
2075 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
2077 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
2078 if ( ov_xdist < 0.0 ) {
2081 if ( ydist < 0.0 ) {
2084 setOvXDistance( ov_xdist );
2085 final double height = _phylogeny.getHeight();
2087 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
2088 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
2091 setOvXcorrectionFactor( 0 );
2099 void updateSetOfCollapsedExternalNodes() {
2100 final Phylogeny phy = getPhylogeny();
2101 _collapsed_external_nodeid_set.clear();
2102 if ( phy != null ) {
2103 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2104 final PhylogenyNode ext_node = it.next();
2105 PhylogenyNode n = ext_node;
2106 while ( !n.isRoot() ) {
2107 if ( n.isCollapse() ) {
2108 _collapsed_external_nodeid_set.add( ext_node.getId() );
2109 ext_node.setCollapse( true );
2118 final void updateSubSuperTreeButton() {
2119 if ( _subtree_index < 1 ) {
2120 getControlPanel().deactivateButtonToReturnToSuperTree();
2123 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
2127 final void zoomInDomainStructure() {
2128 if ( _domain_structure_width < 2000 ) {
2129 _domain_structure_width *= 1.2;
2133 final void zoomOutDomainStructure() {
2134 if ( _domain_structure_width > 20 ) {
2135 _domain_structure_width *= 0.8;
2139 private void abbreviateScientificName( final String sn ) {
2140 final String[] a = sn.split( "\\s+" );
2141 _sb.append( a[ 0 ].substring( 0, 1 ) );
2142 _sb.append( a[ 1 ].substring( 0, 2 ) );
2143 if ( a.length > 2 ) {
2144 for( int i = 2; i < a.length; i++ ) {
2146 _sb.append( a[ i ] );
2151 final private void addEmptyNode( final PhylogenyNode node ) {
2152 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2153 errorMessageNoCutCopyPasteInUnrootedDisplay();
2156 final String label = createASimpleTextRepresentationOfANode( node );
2158 if ( ForesterUtil.isEmpty( label ) ) {
2159 msg = "How to add the new, empty node?";
2162 msg = "How to add the new, empty node to node" + label + "?";
2164 final Object[] options = { "As sibling", "As descendant", "Cancel" };
2165 final int r = JOptionPane.showOptionDialog( this,
2167 "Addition of Empty New Node",
2168 JOptionPane.CLOSED_OPTION,
2169 JOptionPane.QUESTION_MESSAGE,
2173 boolean add_as_sibling = true;
2175 add_as_sibling = false;
2177 else if ( r != 0 ) {
2180 final Phylogeny phy = new Phylogeny();
2181 phy.setRoot( new PhylogenyNode() );
2182 phy.setRooted( true );
2183 if ( add_as_sibling ) {
2184 if ( node.isRoot() ) {
2185 JOptionPane.showMessageDialog( this,
2186 "Cannot add sibling to root",
2187 "Attempt to add sibling to root",
2188 JOptionPane.ERROR_MESSAGE );
2191 phy.addAsSibling( node );
2194 phy.addAsChild( node );
2196 setNodeInPreorderToNull();
2197 _phylogeny.externalNodesHaveChanged();
2198 _phylogeny.clearHashIdToNodeMap();
2199 _phylogeny.recalculateNumberOfExternalDescendants( true );
2200 resetNodeIdToDistToLeafMap();
2205 final private void addToCurrentExternalNodes( final long i ) {
2206 if ( _current_external_nodes == null ) {
2207 _current_external_nodes = new HashSet<Long>();
2209 _current_external_nodes.add( i );
2212 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
2213 final boolean is_vertical,
2215 final boolean to_pdf,
2216 final boolean to_graphics_file ) {
2217 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
2218 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2219 g.setColor( Color.BLACK );
2221 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
2222 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
2223 && ( getCutOrCopiedTree() != null )
2224 && ( getCopiedAndPastedNodes() != null )
2226 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
2227 g.setColor( getTreeColorSet().getFoundColor() );
2229 else if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2230 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2232 else if ( to_pdf ) {
2233 g.setColor( getTreeColorSet().getBranchColorForPdf() );
2236 g.setColor( getTreeColorSet().getBranchColor() );
2240 final private void blast( final PhylogenyNode node ) {
2241 if ( !isCanBlast( node ) ) {
2242 JOptionPane.showMessageDialog( this,
2243 "Insufficient information present",
2245 JOptionPane.INFORMATION_MESSAGE );
2249 final String query = Blast.obtainQueryForBlast( node );
2250 System.out.println( "query for BLAST is: " + query );
2252 if ( !ForesterUtil.isEmpty( query ) ) {
2253 if ( node.getNodeData().isHasSequence() ) {
2254 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
2255 if ( node.getNodeData().getSequence().getType().toLowerCase()
2256 .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
2263 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2264 if ( ForesterUtil.seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) {
2272 if ( type == '?' ) {
2273 if ( SequenceIdParser.isProtein( query ) ) {
2280 JApplet applet = null;
2282 applet = obtainApplet();
2285 Blast.openNcbiBlastWeb( query, type == 'n', applet, this );
2287 catch ( final Exception e ) {
2288 e.printStackTrace();
2290 if ( Constants.ALLOW_DDBJ_BLAST ) {
2292 System.out.println( "trying: " + query );
2293 final Blast s = new Blast();
2294 s.ddbjBlast( query );
2296 catch ( final Exception e ) {
2297 e.printStackTrace();
2304 private final int calcDynamicHidingFactor() {
2305 return ( int ) ( 0.5 + ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) ) );
2309 * Calculate the length of the distance between the given node and its
2315 * @return the distance value
2317 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
2318 if ( getControlPanel().isDrawPhylogram() ) {
2319 if ( node.getDistanceToParent() < 0.0 ) {
2322 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
2325 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2326 return getXdistance();
2328 return getXdistance() * factor;
2332 final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
2333 Color c = getTreeColorSet().getAnnotationColor();
2334 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
2335 final StringBuilder sb = new StringBuilder();
2336 for( final Annotation a : ann ) {
2337 sb.append( !ForesterUtil.isEmpty( a.getRefValue() ) ? a.getRefValue() : a.getDesc() );
2339 final String ann_str = sb.toString();
2340 if ( !ForesterUtil.isEmpty( ann_str ) ) {
2341 c = getControlPanel().getAnnotationColors().get( ann_str );
2343 c = AptxUtil.calculateColorFromString( ann_str, false );
2344 getControlPanel().getAnnotationColors().put( ann_str, c );
2347 c = getTreeColorSet().getAnnotationColor();
2354 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
2355 if ( getControlPanel().isDrawPhylogram() ) {
2356 if ( node.getDistanceToParent() < 0.0 ) {
2359 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
2362 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
2363 return getOvXDistance();
2365 return getOvXDistance() * factor;
2369 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
2370 JOptionPane.showMessageDialog( this,
2371 "Cannot launch web browser for " + type_type + " data of this node",
2372 "Cannot launch web browser",
2373 JOptionPane.WARNING_MESSAGE );
2376 final private void colorizeSubtree( final Color c, final PhylogenyNode node ) {
2377 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2378 JOptionPane.showMessageDialog( this,
2379 "Cannot colorize subtree in unrooted display type",
2380 "Attempt to colorize subtree in unrooted display",
2381 JOptionPane.WARNING_MESSAGE );
2384 _control_panel.setColorBranches( true );
2385 if ( _control_panel.getColorBranchesCb() != null ) {
2386 _control_panel.getColorBranchesCb().setSelected( true );
2388 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
2389 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
2394 final private void colorSubtree( final PhylogenyNode node ) {
2395 Color intitial_color = null;
2396 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null )
2397 && ( ( ( !node.isRoot() && ( node.getParent().getNumberOfDescendants() < 3 ) ) ) || ( node.isRoot() ) ) ) {
2398 intitial_color = PhylogenyMethods.getBranchColorValue( node );
2401 intitial_color = getTreeColorSet().getBranchColor();
2403 _color_chooser.setColor( intitial_color );
2404 _color_chooser.setPreviewPanel( new JPanel() );
2405 final JDialog dialog = JColorChooser
2406 .createDialog( this,
2407 "Subtree colorization",
2410 new SubtreeColorizationActionListener( _color_chooser, node ),
2412 dialog.setVisible( true );
2415 final private void copySubtree( final PhylogenyNode node ) {
2416 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2417 errorMessageNoCutCopyPasteInUnrootedDisplay();
2420 setNodeInPreorderToNull();
2421 setCutOrCopiedTree( _phylogeny.copy( node ) );
2422 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
2423 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
2424 for( final PhylogenyNode n : nodes ) {
2425 node_ids.add( n.getId() );
2427 node_ids.add( node.getId() );
2428 setCopiedAndPastedNodes( node_ids );
2432 final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
2433 final String tax = PhylogenyMethods.getSpecies( node );
2434 String label = node.getName();
2435 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
2436 label = label + " " + tax;
2438 else if ( !ForesterUtil.isEmpty( tax ) ) {
2444 if ( !ForesterUtil.isEmpty( label ) ) {
2445 label = " [" + label + "]";
2450 final private void cutSubtree( final PhylogenyNode node ) {
2451 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2452 errorMessageNoCutCopyPasteInUnrootedDisplay();
2455 if ( node.isRoot() ) {
2456 JOptionPane.showMessageDialog( this,
2457 "Cannot cut entire tree as subtree",
2458 "Attempt to cut entire tree",
2459 JOptionPane.ERROR_MESSAGE );
2462 final String label = createASimpleTextRepresentationOfANode( node );
2463 final int r = JOptionPane.showConfirmDialog( null,
2464 "Cut subtree" + label + "?",
2465 "Confirm Cutting of Subtree",
2466 JOptionPane.YES_NO_OPTION );
2467 if ( r != JOptionPane.OK_OPTION ) {
2470 setNodeInPreorderToNull();
2471 setCopiedAndPastedNodes( null );
2472 setCutOrCopiedTree( _phylogeny.copy( node ) );
2473 _phylogeny.deleteSubtree( node, true );
2474 _phylogeny.clearHashIdToNodeMap();
2475 _phylogeny.recalculateNumberOfExternalDescendants( true );
2476 resetNodeIdToDistToLeafMap();
2481 final private void cycleColors() {
2482 getMainPanel().getTreeColorSet().cycleColorScheme();
2483 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
2484 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
2488 final private void decreaseOvSize() {
2489 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
2490 setOvMaxWidth( getOvMaxWidth() - 5 );
2491 setOvMaxHeight( getOvMaxHeight() - 5 );
2493 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2497 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
2498 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
2499 errorMessageNoCutCopyPasteInUnrootedDisplay();
2502 if ( node.isRoot() && ( node.getNumberOfDescendants() != 1 ) ) {
2503 JOptionPane.showMessageDialog( this,
2504 "Cannot delete entire tree",
2505 "Attempt to delete entire tree",
2506 JOptionPane.ERROR_MESSAGE );
2509 final String label = createASimpleTextRepresentationOfANode( node );
2510 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
2511 final int r = JOptionPane.showOptionDialog( this,
2512 "Delete" + label + "?",
2513 "Delete Node/Subtree",
2514 JOptionPane.CLOSED_OPTION,
2515 JOptionPane.QUESTION_MESSAGE,
2519 setNodeInPreorderToNull();
2520 boolean node_only = true;
2524 else if ( r != 0 ) {
2528 PhylogenyMethods.removeNode( node, _phylogeny );
2531 _phylogeny.deleteSubtree( node, true );
2533 _phylogeny.externalNodesHaveChanged();
2534 _phylogeny.clearHashIdToNodeMap();
2535 _phylogeny.recalculateNumberOfExternalDescendants( true );
2536 resetNodeIdToDistToLeafMap();
2541 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
2542 makePopupMenus( node );
2543 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
2544 _node_popup_menu.show( this, x, y );
2547 final private void drawArc( final double x,
2550 final double heigth,
2551 final double start_angle,
2552 final double arc_angle,
2553 final Graphics2D g ) {
2554 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
2558 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
2559 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
2562 _line.setLine( x1, y1, x2, y2 );
2566 final private void drawOval( final double x,
2569 final double heigth,
2570 final Graphics2D g ) {
2571 _ellipse.setFrame( x, y, width, heigth );
2575 final private void drawOvalFilled( final double x,
2578 final double heigth,
2579 final Graphics2D g ) {
2580 _ellipse.setFrame( x, y, width, heigth );
2584 final private void drawOvalGradient( final double x,
2587 final double heigth,
2589 final Color color_1,
2590 final Color color_2,
2591 final Color color_border ) {
2592 _ellipse.setFrame( x, y, width, heigth );
2593 g.setPaint( new GradientPaint( ( float ) x,
2596 ( float ) ( x + width ),
2597 ( float ) ( y + heigth ),
2601 if ( color_border != null ) {
2602 g.setPaint( color_border );
2607 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
2608 _rectangle.setFrame( x, y, width, heigth );
2609 g.draw( _rectangle );
2612 final private void drawRectFilled( final double x,
2615 final double heigth,
2616 final Graphics2D g ) {
2617 _rectangle.setFrame( x, y, width, heigth );
2618 g.fill( _rectangle );
2621 final private void drawRectGradient( final double x,
2624 final double heigth,
2626 final Color color_1,
2627 final Color color_2,
2628 final Color color_border ) {
2629 _rectangle.setFrame( x, y, width, heigth );
2630 g.setPaint( new GradientPaint( ( float ) x,
2633 ( float ) ( x + width ),
2634 ( float ) ( y + heigth ),
2637 g.fill( _rectangle );
2638 if ( color_border != null ) {
2639 g.setPaint( color_border );
2640 g.draw( _rectangle );
2644 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
2645 final List<Uri> us = new ArrayList<Uri>();
2646 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
2647 for( final Uri uri : t.getUris() ) {
2652 for( final Uri uri : us ) {
2653 if ( uri != null ) {
2654 final String uri_str = uri.getValue().toString().toLowerCase();
2655 if ( getImageMap().containsKey( uri_str ) ) {
2656 final BufferedImage bi = getImageMap().get( uri_str );
2657 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
2658 double scaling_factor = 1;
2659 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
2660 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
2661 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
2663 // y = y - ( 0.9 * getYdistance() );
2664 final double hs = bi.getHeight() * scaling_factor;
2665 double ws = ( bi.getWidth() * scaling_factor ) + offset;
2666 final double my_y = y - ( 0.5 * hs );
2667 final int x_w = ( int ) ( x + ws + 0.5 );
2668 final int y_h = ( int ) ( my_y + hs + 0.5 );
2669 if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) {
2671 ( int ) ( x + 0.5 + offset ),
2672 ( int ) ( my_y + 0.5 ),
2693 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
2694 JOptionPane.showMessageDialog( this,
2695 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
2696 "Attempt to cut/copy/paste/add/delete in unrooted display",
2697 JOptionPane.ERROR_MESSAGE );
2700 final private Set<Long> getCopiedAndPastedNodes() {
2701 return getMainPanel().getCopiedAndPastedNodes();
2704 final private Set<Long> getCurrentExternalNodes() {
2705 return _current_external_nodes;
2708 final private Phylogeny getCutOrCopiedTree() {
2709 return getMainPanel().getCutOrCopiedTree();
2712 final private float getLastDragPointX() {
2713 return _last_drag_point_x;
2716 final private float getLastDragPointY() {
2717 return _last_drag_point_y;
2720 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
2721 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
2722 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
2723 _nodeid_dist_to_leaf.put( node.getId(), m );
2727 return _nodeid_dist_to_leaf.get( node.getId() );
2731 final private double getMaxDistanceToRoot() {
2732 if ( _max_distance_to_root < 0 ) {
2733 recalculateMaxDistanceToRoot();
2735 return _max_distance_to_root;
2738 final private float getOvMaxHeight() {
2739 return _ov_max_height;
2742 final private float getOvMaxWidth() {
2743 return _ov_max_width;
2746 final private float getOvXcorrectionFactor() {
2747 return _ov_x_correction_factor;
2750 final private float getOvXDistance() {
2751 return _ov_x_distance;
2754 final private int getOvXPosition() {
2755 return _ov_x_position;
2758 final private float getOvYDistance() {
2759 return _ov_y_distance;
2762 final private int getOvYPosition() {
2763 return _ov_y_position;
2766 final private int getOvYStart() {
2770 final private double getScaleDistance() {
2771 return _scale_distance;
2774 final private String getScaleLabel() {
2775 return _scale_label;
2778 final private TreeFontSet getTreeFontSet() {
2779 return getMainPanel().getTreeFontSet();
2782 final private float getUrtFactor() {
2786 final private float getUrtFactorOv() {
2787 return _urt_factor_ov;
2790 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
2793 showNodeFrame( node );
2808 colorSubtree( node );
2823 copySubtree( node );
2826 pasteSubtree( node );
2828 case DELETE_NODE_OR_SUBTREE:
2829 deleteNodeOrSubtree( node );
2832 addEmptyNode( node );
2834 case EDIT_NODE_DATA:
2835 showNodeEditFrame( node );
2840 case SORT_DESCENDENTS:
2841 sortDescendants( node );
2843 case GET_EXT_DESC_DATA:
2844 showExtDescNodeData( node );
2847 throw new IllegalArgumentException( "unknown action: " + action );
2851 final private void increaseCurrentExternalNodesDataBufferChangeCounter() {
2852 _current_external_nodes_data_buffer_change_counter++;
2855 final private void increaseOvSize() {
2856 if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) )
2857 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
2858 .getHeight() / 2 ) ) ) {
2859 setOvMaxWidth( getOvMaxWidth() + 5 );
2860 setOvMaxHeight( getOvMaxHeight() + 5 );
2862 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2866 final private void init() {
2867 _color_chooser = new JColorChooser();
2868 _rollover_popup = new JTextArea();
2869 _rollover_popup.setFont( POPUP_FONT );
2870 resetNodeIdToDistToLeafMap();
2872 setTreeFile( null );
2874 initializeOvSettings();
2875 setStartingAngle( ( TWO_PI * 3 ) / 4 );
2876 final ImageLoader il = new ImageLoader( this );
2877 new Thread( il ).start();
2880 final private void initializeOvSettings() {
2881 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
2882 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
2885 final private boolean inOvVirtualRectangle( final int x, final int y ) {
2886 return ( ( x >= ( getOvVirtualRectangle().x - 1 ) )
2887 && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) )
2888 && ( y >= ( getOvVirtualRectangle().y - 1 ) ) && ( y <= ( getOvVirtualRectangle().y
2889 + getOvVirtualRectangle().height + 1 ) ) );
2892 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
2893 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
2896 final private boolean isCanBlast( final PhylogenyNode node ) {
2897 if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) {
2900 return Blast.isContainsQueryForBlast( node );
2903 final private String isCanOpenSeqWeb( final PhylogenyNode node ) {
2904 String v = ForesterUtil.extractUniProtKbProteinSeqIdentifier( node );
2905 if ( ForesterUtil.isEmpty( v ) ) {
2906 v = ForesterUtil.extractGenbankAccessor( node );
2908 if ( ForesterUtil.isEmpty( v ) ) {
2909 v = ForesterUtil.extractRefSeqAccessorAccessor( node );
2911 if ( ForesterUtil.isEmpty( v ) ) {
2912 v = ForesterUtil.extractGInumber( node );
2917 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
2918 if ( node.getNodeData().isHasTaxonomy()
2919 && ( ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
2920 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
2921 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
2922 .getNodeData().getTaxonomy().getIdentifier() != null ) && !ForesterUtil.isEmpty( node
2923 .getNodeData().getTaxonomy().getIdentifier().getValue() ) ) ) ) {
2931 final private boolean isInCurrentExternalNodes( final PhylogenyNode node ) {
2932 return ( ( getCurrentExternalNodes() != null ) && getCurrentExternalNodes().contains( node.getId() ) );
2935 final private boolean isInFoundNodes( final PhylogenyNode node ) {
2936 return ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) );
2939 final private boolean isInOv() {
2943 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
2945 if ( getControlPanel().isShowTaxonomyImages() ) {
2946 y_dist = 40 + ( int ) getYdistance();
2948 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) )
2949 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) ) || ( ( node.getParent() != null ) && ( node
2950 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
2953 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
2954 return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) )
2955 || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) )
2956 || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) ) || ( node.getXcoord() > ( getVisibleRect()
2957 .getMaxX() + 20 ) ) );
2960 final private boolean isNonLinedUpCladogram() {
2961 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
2964 final private boolean isUniformBranchLengthsForCladogram() {
2965 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
2968 final private void keyPressedCalls( final KeyEvent e ) {
2969 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
2970 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
2971 if ( !isInOvRect() ) {
2972 setInOvRect( true );
2975 else if ( isInOvRect() ) {
2976 setInOvRect( false );
2979 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
2980 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
2981 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
2982 getMainPanel().getTreeFontSet().mediumFonts();
2983 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
2985 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
2986 getMainPanel().getTreeFontSet().decreaseFontSize( 1, false );
2987 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
2989 else if ( plusPressed( e.getKeyCode() ) ) {
2990 getMainPanel().getTreeFontSet().increaseFontSize();
2991 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
2995 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
2996 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
2997 getControlPanel().showWhole();
2999 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
3000 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
3001 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
3002 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
3003 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3004 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3006 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
3007 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3008 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3010 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
3011 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3012 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3013 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3015 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
3016 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3017 Constants.WHEEL_ZOOM_IN_FACTOR );
3018 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3025 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
3028 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
3032 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
3036 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
3037 scroll_position.x = scroll_position.x + dx;
3038 scroll_position.y = scroll_position.y + dy;
3039 if ( scroll_position.x <= 0 ) {
3040 scroll_position.x = 0;
3043 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
3044 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
3045 if ( scroll_position.x >= max_x ) {
3046 scroll_position.x = max_x;
3049 if ( scroll_position.y <= 0 ) {
3050 scroll_position.y = 0;
3053 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
3054 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
3055 if ( scroll_position.y >= max_y ) {
3056 scroll_position.y = max_y;
3060 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
3063 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
3064 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
3065 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
3066 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
3067 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3069 else if ( plusPressed( e.getKeyCode() ) ) {
3070 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
3071 Constants.WHEEL_ZOOM_IN_FACTOR );
3072 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
3073 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
3075 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
3076 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3077 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3078 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
3079 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3082 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
3083 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3084 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3085 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
3086 if ( getStartingAngle() < 0 ) {
3087 setStartingAngle( TWO_PI + getStartingAngle() );
3089 getControlPanel().displayedPhylogenyMightHaveChanged( false );
3092 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
3093 boolean selected = false;
3094 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
3095 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
3099 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
3101 if ( getMainPanel().getMainFrame() == null ) {
3102 // Must be "E" applet version.
3103 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
3104 if ( ae.getlabelDirectionCbmi() != null ) {
3105 ae.getlabelDirectionCbmi().setSelected( selected );
3109 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
3113 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
3114 switchDisplaygetPhylogenyGraphicsType();
3117 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
3121 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
3122 MainFrame.cycleOverview( getOptions(), this );
3125 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
3128 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
3135 final private void makePopupMenus( final PhylogenyNode node ) {
3136 _node_popup_menu = new JPopupMenu();
3137 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
3138 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
3139 for( int i = 0; i < clickto_names.size(); i++ ) {
3140 final String title = clickto_names.get( i );
3141 _node_popup_menu_items[ i ] = new JMenuItem( title );
3142 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
3143 final String id = isCanOpenSeqWeb( node );
3144 if ( !ForesterUtil.isEmpty( id ) ) {
3145 _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + id + "]" );
3146 _node_popup_menu_items[ i ].setEnabled( true );
3149 _node_popup_menu_items[ i ].setEnabled( false );
3152 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
3153 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
3155 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
3156 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
3158 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
3159 if ( !getOptions().isEditable() ) {
3162 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
3164 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
3165 if ( !getOptions().isEditable() ) {
3168 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
3170 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
3171 if ( !getOptions().isEditable() ) {
3174 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
3176 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
3177 if ( !getOptions().isEditable() ) {
3180 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
3182 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
3183 if ( !getOptions().isEditable() ) {
3187 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
3188 if ( !getOptions().isEditable() ) {
3192 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
3193 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
3195 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
3196 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
3198 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
3199 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
3201 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
3202 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
3204 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
3205 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
3207 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
3208 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
3210 _node_popup_menu_items[ i ].addActionListener( this );
3211 _node_popup_menu.add( _node_popup_menu_items[ i ] );
3215 private final String obtainTitleForExtDescNodeData() {
3216 switch ( getOptions().getExtDescNodeDataToReturn() ) {
3218 return "Node Names";
3220 return "Sequence Names";
3221 case SEQUENCE_SYMBOL:
3222 return "Sequence Symbols";
3223 case SEQUENCE_MOL_SEQ:
3224 return "Molecular Sequences";
3225 case SEQUENCE_MOL_SEQ_FASTA:
3226 return "Molecular Sequences (Fasta)";
3228 return "Sequence Accessors";
3229 case TAXONOMY_SCIENTIFIC_NAME:
3230 return "Scientific Names";
3232 return "Taxonomy Codes";
3233 case TAXONOMY_COMM0N_NAME:
3234 return "Taxonomy Common Names";
3236 return "User Selected Data";
3238 throw new IllegalArgumentException( "unknown data element: "
3239 + getOptions().getExtDescNodeDataToReturn() );
3243 final private void openSeqWeb( final PhylogenyNode node ) {
3244 if ( ForesterUtil.isEmpty( isCanOpenSeqWeb( node ) ) ) {
3245 cannotOpenBrowserWarningMessage( "sequence" );
3248 final String uri_str = AptxUtil.createUriForSeqWeb( node, getConfiguration(), this );
3249 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3251 AptxUtil.launchWebBrowser( new URI( uri_str ),
3253 isApplet() ? obtainApplet() : null,
3256 catch ( final IOException e ) {
3257 AptxUtil.showErrorMessage( this, e.toString() );
3258 e.printStackTrace();
3260 catch ( final URISyntaxException e ) {
3261 AptxUtil.showErrorMessage( this, e.toString() );
3262 e.printStackTrace();
3266 cannotOpenBrowserWarningMessage( "sequence" );
3270 final private void openTaxWeb( final PhylogenyNode node ) {
3271 if ( !isCanOpenTaxWeb( node ) ) {
3272 cannotOpenBrowserWarningMessage( "taxonomic" );
3275 String uri_str = null;
3276 final Taxonomy tax = node.getNodeData().getTaxonomy();
3277 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
3278 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
3280 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
3282 catch ( final URISyntaxException e ) {
3283 AptxUtil.showErrorMessage( this, e.toString() );
3285 e.printStackTrace();
3288 else if ( ( tax.getIdentifier() != null )
3289 && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
3290 && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
3291 && ( tax.getIdentifier().getProvider().equalsIgnoreCase( "ncbi" ) || tax.getIdentifier().getProvider()
3292 .equalsIgnoreCase( "uniprot" ) ) ) {
3294 uri_str = "http://www.uniprot.org/taxonomy/"
3295 + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
3297 catch ( final UnsupportedEncodingException e ) {
3298 AptxUtil.showErrorMessage( this, e.toString() );
3299 e.printStackTrace();
3302 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
3304 uri_str = "http://www.uniprot.org/taxonomy/?query="
3305 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
3307 catch ( final UnsupportedEncodingException e ) {
3308 AptxUtil.showErrorMessage( this, e.toString() );
3309 e.printStackTrace();
3312 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
3314 uri_str = "http://www.uniprot.org/taxonomy/?query="
3315 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
3317 catch ( final UnsupportedEncodingException e ) {
3318 AptxUtil.showErrorMessage( this, e.toString() );
3319 e.printStackTrace();
3322 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
3324 uri_str = "http://www.uniprot.org/taxonomy/?query="
3325 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
3327 catch ( final UnsupportedEncodingException e ) {
3328 AptxUtil.showErrorMessage( this, e.toString() );
3329 e.printStackTrace();
3332 if ( !ForesterUtil.isEmpty( uri_str ) ) {
3334 AptxUtil.launchWebBrowser( new URI( uri_str ),
3336 isApplet() ? obtainApplet() : null,
3339 catch ( final IOException e ) {
3340 AptxUtil.showErrorMessage( this, e.toString() );
3341 e.printStackTrace();
3343 catch ( final URISyntaxException e ) {
3344 AptxUtil.showErrorMessage( this, e.toString() );
3345 e.printStackTrace();
3349 cannotOpenBrowserWarningMessage( "taxonomic" );
3353 final private void paintBranchLength( final Graphics2D g,
3354 final PhylogenyNode node,
3355 final boolean to_pdf,
3356 final boolean to_graphics_file ) {
3357 g.setFont( getTreeFontSet().getSmallFont() );
3358 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3359 g.setColor( Color.BLACK );
3362 g.setColor( getTreeColorSet().getBranchLengthColor() );
3364 if ( !node.isRoot() ) {
3365 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3366 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3367 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3369 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3370 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3371 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3374 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
3375 .getXcoord() + 3, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
3379 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
3380 - getTreeFontSet()._small_max_descent, g );
3384 final private void paintBranchLite( final Graphics2D g,
3389 final PhylogenyNode node ) {
3390 g.setColor( getTreeColorSet().getOvColor() );
3391 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3392 drawLine( x1, y1, x2, y2, g );
3394 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3395 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3396 ( g ).draw( _quad_curve );
3398 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3399 final float dx = x2 - x1;
3400 final float dy = y2 - y1;
3401 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3402 + ( dy * 0.8f ), x2, y2 );
3403 ( g ).draw( _cubic_curve );
3406 final float x2a = x2;
3407 final float x1a = x1;
3408 // draw the vertical line
3409 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
3410 drawLine( x1, y1, x1, y2, g );
3412 // draw the horizontal line
3413 drawLine( x1a, y2, x2a, y2, g );
3418 * Paint a branch which consists of a vertical and a horizontal bar
3419 * @param is_ind_found_nodes
3421 final private void paintBranchRectangular( final Graphics2D g,
3426 final PhylogenyNode node,
3427 final boolean to_pdf,
3428 final boolean to_graphics_file ) {
3429 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
3430 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
3431 drawLine( x1, y1, x2, y2, g );
3433 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
3434 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
3435 g.draw( _quad_curve );
3437 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
3438 final float dx = x2 - x1;
3439 final float dy = y2 - y1;
3440 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
3441 + ( dy * 0.8f ), x2, y2 );
3442 g.draw( _cubic_curve );
3445 final float x2a = x2;
3446 final float x1a = x1;
3448 if ( node.isFirstChildNode() || node.isLastChildNode()
3449 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
3450 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3451 if ( !to_graphics_file
3453 && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) ) || ( ( y2 > ( getVisibleRect()
3454 .getMaxY() + 20 ) ) && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) {
3458 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3459 float x2c = x1 + EURO_D;
3463 drawLine( x1, y1, x2c, y2, g );
3465 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3467 y2_r = y2 - ROUNDED_D;
3471 drawLine( x1, y1, x1, y2_r, g );
3474 y2_r = y2 + ROUNDED_D;
3478 drawLine( x1, y1, x1, y2_r, g );
3482 drawLine( x1, y1, x1, y2, g );
3486 // draw the horizontal line
3487 if ( !to_graphics_file && !to_pdf
3488 && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) {
3492 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
3493 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3494 x1_r = x1a + ROUNDED_D;
3496 drawLine( x1_r, y2, x2a, y2, g );
3499 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3500 final float x1c = x1a + EURO_D;
3502 drawLine( x1c, y2, x2a, y2, g );
3506 drawLine( x1a, y2, x2a, y2, g );
3510 final double w = PhylogenyMethods.getBranchWidthValue( node );
3511 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3512 x1_r = x1a + ROUNDED_D;
3514 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
3517 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3518 final float x1c = x1a + EURO_D;
3520 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
3524 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
3527 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3532 final double diff = y2 - y2_r;
3533 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
3536 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
3541 if ( node.isExternal() ) {
3542 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node )
3543 || isInCurrentExternalNodes( node ) );
3547 final private double paintCirculars( final PhylogenyNode n,
3548 final Phylogeny phy,
3549 final float center_x,
3550 final float center_y,
3551 final double radius,
3552 final boolean radial_labels,
3554 final boolean to_pdf,
3555 final boolean to_graphics_file ) {
3556 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
3557 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
3558 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
3560 return _urt_nodeid_angle_map.get( n.getId() );
3563 final List<PhylogenyNode> descs = n.getDescendants();
3565 for( final PhylogenyNode desc : descs ) {
3566 sum += paintCirculars( desc,
3577 if ( !n.isRoot() ) {
3578 r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3580 final double theta = sum / descs.size();
3581 n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) );
3582 n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) );
3583 _urt_nodeid_angle_map.put( n.getId(), theta );
3584 for( final PhylogenyNode desc : descs ) {
3585 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
3591 final private void paintCircularsLite( final PhylogenyNode n,
3592 final Phylogeny phy,
3596 final Graphics2D g ) {
3597 if ( n.isExternal() ) {
3601 final List<PhylogenyNode> descs = n.getDescendants();
3602 for( final PhylogenyNode desc : descs ) {
3603 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
3606 if ( !n.isRoot() ) {
3607 r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth );
3609 final double theta = _urt_nodeid_angle_map.get( n.getId() );
3610 n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) );
3611 n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) );
3612 for( final PhylogenyNode desc : descs ) {
3613 paintBranchCircularLite( n, desc, g );
3618 final private void paintCollapsedNode( final Graphics2D g,
3619 final PhylogenyNode node,
3620 final boolean to_graphics_file,
3621 final boolean to_pdf,
3622 final boolean is_in_found_nodes ) {
3624 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3627 else if ( is_in_found_nodes ) {
3628 c = getTreeColorSet().getFoundColor();
3630 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3631 c = getTaxonomyBasedColor( node );
3633 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3634 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3635 c = PhylogenyMethods.getBranchColorValue( node );
3638 c = getTreeColorSet().getCollapseFillColor();
3640 double d = node.getAllExternalDescendants().size();
3642 d = ( 3 * _y_distance ) / 3;
3645 d = ( Math.log10( d ) * _y_distance ) / 2.5;
3647 final int box_size = getOptions().getDefaultNodeShapeSize() + 1;
3648 if ( d < box_size ) {
3651 final float xx = node.getXcoord() - ( 2 * box_size );
3652 final float xxx = xx > node.getParent().getXcoord() + 1 ? xx : node.getParent().getXcoord() + 1;
3654 _polygon.moveTo( xxx, node.getYcoord() );
3655 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d );
3656 _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d );
3657 _polygon.closePath();
3658 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3662 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
3663 g.setColor( getBackground() );
3668 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
3669 g.setPaint( new GradientPaint( xxx, node.getYcoord(), getBackground(), node.getXcoord(), ( float ) ( node
3670 .getYcoord() - d ), c, false ) );
3675 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3678 final private void paintConfidenceValues( final Graphics2D g,
3679 final PhylogenyNode node,
3680 final boolean to_pdf,
3681 final boolean to_graphics_file ) {
3682 final List<Confidence> confidences = node.getBranchData().getConfidences();
3683 // if ( confidences.size() == 1 ) {
3684 // final double value = node.getBranchData().getConfidence( 0 ).getValue();
3685 // if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
3688 // conf_str = FORMATTER_CONFIDENCE.format( value );
3690 // else if ( confidences.size() > 1 ) {
3691 boolean one_ok = false;
3692 boolean not_first = false;
3693 Collections.sort( confidences );
3694 final StringBuilder sb = new StringBuilder();
3695 String conf_str = "";
3696 for( final Confidence confidence : confidences ) {
3697 final double value = confidence.getValue();
3698 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
3699 if ( value >= getOptions().getMinConfidenceValue() ) {
3708 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
3709 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
3710 if ( getOptions().isShowConfidenceStddev() ) {
3711 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
3713 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getStandardDeviation(),
3715 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
3722 conf_str = sb.toString();
3725 if ( conf_str.length() > 0 ) {
3726 final double parent_x = node.getParent().getXcoord();
3727 double x = node.getXcoord();
3728 g.setFont( getTreeFontSet().getSmallFont() );
3729 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
3732 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
3735 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3736 g.setColor( Color.BLACK );
3739 g.setColor( getTreeColorSet().getConfidenceColor() );
3742 .drawString( conf_str,
3744 + ( ( x - parent_x - getTreeFontSet()._fm_small.stringWidth( conf_str ) ) / 2 ),
3745 ( node.getYcoord() + getTreeFontSet()._small_max_ascent ) - 1,
3750 final private void paintFoundNode( final int x, final int y, final Graphics2D g ) {
3751 final int box_size = getOptions().getDefaultNodeShapeSize();
3752 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
3753 g.setColor( getTreeColorSet().getFoundColor() );
3754 g.fillRect( x - half_box_size, y - half_box_size, box_size, box_size );
3757 final private void paintGainedAndLostCharacters( final Graphics2D g,
3758 final PhylogenyNode node,
3759 final String gained,
3760 final String lost ) {
3761 if ( node.getParent() != null ) {
3762 final double parent_x = node.getParent().getXcoord();
3763 final double x = node.getXcoord();
3764 g.setFont( getTreeFontSet().getLargeFont() );
3765 g.setColor( getTreeColorSet().getGainedCharactersColor() );
3766 if ( Constants.SPECIAL_CUSTOM ) {
3767 g.setColor( Color.BLUE );
3770 .drawString( gained,
3771 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( gained ) ) / 2 ),
3772 ( node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent() ),
3774 g.setColor( getTreeColorSet().getLostCharactersColor() );
3775 TreePanel.drawString( lost,
3776 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( lost ) ) / 2 ),
3777 ( node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent() ),
3783 * Draw a box at the indicated node.
3790 final private void paintNodeBox( final double x,
3792 final PhylogenyNode node,
3794 final boolean to_pdf,
3795 final boolean to_graphics_file,
3796 final boolean is_in_found_nodes ) {
3797 if ( node.isCollapse() ) {
3800 // if this node should be highlighted, do so
3801 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
3802 g.setColor( getTreeColorSet().getFoundColor() );
3803 drawOval( x - 8, y - 8, 16, 16, g );
3804 drawOval( x - 9, y - 8, 17, 17, g );
3805 drawOval( x - 9, y - 9, 18, 18, g );
3807 if ( is_in_found_nodes ) {
3808 paintFoundNode( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ), g );
3811 Color outline_color = null;
3812 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3813 outline_color = Color.BLACK;
3815 else if ( getControlPanel().isEvents() && AptxUtil.isHasAssignedEvent( node ) ) {
3816 final Event event = node.getNodeData().getEvent();
3817 if ( event.isDuplication() ) {
3818 outline_color = getTreeColorSet().getDuplicationBoxColor();
3820 else if ( event.isSpeciation() ) {
3821 outline_color = getTreeColorSet().getSpecBoxColor();
3823 else if ( event.isSpeciationOrDuplication() ) {
3824 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
3827 else if ( getOptions().isTaxonomyColorizeNodeShapes() ) {
3828 outline_color = getTaxonomyBasedColor( node );
3831 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
3832 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
3833 outline_color = getTreeColorSet().getBranchColorForPdf();
3836 final int box_size = getOptions().getDefaultNodeShapeSize();
3837 final int half_box_size = box_size / 2;
3838 if ( ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() )
3839 || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() )
3840 || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) {
3841 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
3842 if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
3843 drawOvalGradient( x - half_box_size,
3848 to_pdf ? Color.WHITE : outline_color,
3849 to_pdf ? outline_color : getBackground(),
3852 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
3853 Color background = getBackground();
3855 background = Color.WHITE;
3857 drawOvalGradient( x - half_box_size,
3866 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3867 g.setColor( outline_color );
3868 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
3871 else if ( getOptions().getDefaultNodeShape() == NodeVisualization.NodeShape.RECTANGLE ) {
3872 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.GRADIENT ) {
3873 drawRectGradient( x - half_box_size,
3878 to_pdf ? Color.WHITE : outline_color,
3879 to_pdf ? outline_color : getBackground(),
3882 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
3883 Color background = getBackground();
3885 background = Color.WHITE;
3887 drawRectGradient( x - half_box_size,
3896 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
3897 g.setColor( outline_color );
3898 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
3905 final private void paintNodeData( final Graphics2D g,
3906 final PhylogenyNode node,
3907 final boolean to_graphics_file,
3908 final boolean to_pdf,
3909 final boolean is_in_found_nodes ) {
3910 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
3913 if ( getOptions().isShowBranchLengthValues()
3914 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3915 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3916 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
3917 paintBranchLength( g, node, to_pdf, to_graphics_file );
3919 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
3924 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
3925 if ( getControlPanel().isShowTaxonomyImages()
3926 && ( getImageMap() != null )
3927 && !getImageMap().isEmpty()
3928 && node.getNodeData().isHasTaxonomy()
3929 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
3930 .getUris().isEmpty() ) ) {
3931 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
3933 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
3934 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
3935 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
3937 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3938 g.setColor( Color.BLACK );
3940 else if ( is_in_found_nodes ) {
3941 g.setColor( getTreeColorSet().getFoundColor() );
3943 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3944 g.setColor( getTaxonomyBasedColor( node ) );
3946 else if ( getControlPanel().isColorAccordingToAnnotation()
3947 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
3948 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
3949 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
3951 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3952 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3953 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3955 else if ( to_pdf ) {
3956 g.setColor( Color.BLACK );
3959 g.setColor( getTreeColorSet().getSequenceColor() );
3961 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3962 if ( _sb.length() > 0 ) {
3965 _sb.append( node.getAllExternalDescendants().size() );
3972 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3973 if ( _sb.length() > 0 ) {
3976 _sb.append( node.getName() );
3978 if ( node.getNodeData().isHasSequence() ) {
3979 if ( getControlPanel().isShowGeneSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
3980 if ( _sb.length() > 0 ) {
3983 _sb.append( node.getNodeData().getSequence().getSymbol() );
3985 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3986 if ( _sb.length() > 0 ) {
3989 _sb.append( node.getNodeData().getSequence().getName() );
3991 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3992 if ( _sb.length() > 0 ) {
3995 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3996 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3999 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
4002 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
4003 if ( _sb.length() > 0 ) {
4006 _sb.append( propertiesToString( node ) );
4008 g.setFont( getTreeFontSet().getLargeFont() );
4009 if ( is_in_found_nodes ) {
4010 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
4012 double down_shift_factor = 3.0;
4013 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
4014 down_shift_factor = 1;
4016 final double pos_x = node.getXcoord() + x + 2 + half_box_size;
4017 final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
4018 final String sb_str = _sb.toString();
4019 // GUILHEM_BEG ______________
4020 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
4021 && ( _query_sequence != null ) ) {
4022 int nodeTextBoundsWidth = 0;
4023 if ( sb_str.length() > 0 ) {
4024 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
4025 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
4027 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
4028 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
4029 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
4030 g.setColor( getTreeColorSet().getBackgroundColor() );
4034 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
4035 for( final SequenceRelation seqRelation : seqRelations ) {
4036 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
4037 .getRef1().isEqual( _query_sequence ) )
4038 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
4039 .getSelectedItem() );
4040 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
4041 final double linePosX = node.getXcoord() + 2 + half_box_size;
4042 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
4043 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
4045 if ( sConfidence != null ) {
4046 double confidenceX = pos_x;
4047 if ( sb_str.length() > 0 ) {
4048 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
4049 + CONFIDENCE_LEFT_MARGIN;
4051 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
4052 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
4053 .getBounds().getWidth();
4054 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
4055 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
4058 if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
4060 if ( nodeTextBoundsWidth == 0 ) {
4061 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
4064 nodeTextBoundsWidth += 2;
4066 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
4067 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
4074 if ( sb_str.length() > 0 ) {
4075 TreePanel.drawString( sb_str, pos_x, pos_y, g );
4077 // GUILHEM_END _____________
4078 // COMMENTED_OUT_BY_GUILHEM_BEG _______________
4079 // TODO FIXME need to check this one!
4080 //if ( _sb.length() > 0 ) {
4081 // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
4082 // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4084 // COMMENTED_OUT_BY_GUILHEM_END ________________
4085 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
4086 && ( node.getNodeData().getSequence().getAnnotations() != null )
4087 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
4088 if ( _sb.length() > 0 ) {
4089 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
4091 final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
4092 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4093 g.setColor( Color.BLACK );
4095 else if ( getControlPanel().isColorAccordingToAnnotation() ) {
4096 g.setColor( calculateColorForAnnotation( ann ) );
4098 final String ann_str = AptxUtil.createAnnotationString( ann, getOptions().isShowAnnotationRefSource() );
4099 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
4100 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4102 _sb.append( ann_str );
4104 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
4105 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
4106 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
4107 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
4108 && node.getNodeData().isHasBinaryCharacters() ) {
4109 if ( _sb.length() > 0 ) {
4110 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
4112 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4113 g.setColor( Color.BLACK );
4116 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
4118 if ( getControlPanel().isShowBinaryCharacters() ) {
4119 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
4120 .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord()
4121 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
4122 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
4123 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
4124 .getLostCharactersAsStringBuffer().toString() );
4127 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
4128 node.getXcoord() + x + 4 + half_box_size,
4130 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ),
4132 paintGainedAndLostCharacters( g, node, "+"
4133 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
4134 + node.getNodeData().getBinaryCharacters().getLostCount() );
4140 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
4141 final PhylogenyNode node,
4142 final boolean to_pdf,
4143 final boolean to_graphics_file,
4144 final boolean radial_labels,
4145 final double ur_angle,
4146 final boolean is_in_found_nodes ) {
4147 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
4150 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4151 g.setColor( Color.BLACK );
4153 else if ( is_in_found_nodes ) {
4154 g.setColor( getTreeColorSet().getFoundColor() );
4156 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4157 g.setColor( getTaxonomyBasedColor( node ) );
4159 else if ( getControlPanel().isColorAccordingToAnnotation()
4160 && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
4161 .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
4162 g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
4165 g.setColor( getTreeColorSet().getSequenceColor() );
4169 if ( node.getNodeData().isHasTaxonomy()
4170 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
4171 .isShowTaxonomyCommonNames() ) ) {
4172 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4173 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4174 _sb.append( taxonomy.getTaxonomyCode() );
4177 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4178 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4179 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4180 _sb.append( taxonomy.getScientificName() );
4182 _sb.append( taxonomy.getCommonName() );
4185 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4186 _sb.append( taxonomy.getScientificName() );
4189 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4190 _sb.append( taxonomy.getCommonName() );
4194 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4195 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4196 _sb.append( taxonomy.getScientificName() );
4200 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4201 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4202 _sb.append( taxonomy.getCommonName() );
4207 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
4209 _sb.append( node.getAllExternalDescendants().size() );
4212 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
4213 if ( _sb.length() > 0 ) {
4216 _sb.append( node.getName() );
4218 if ( node.getNodeData().isHasSequence() ) {
4219 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4220 if ( _sb.length() > 0 ) {
4223 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
4224 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
4227 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
4229 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
4230 if ( _sb.length() > 0 ) {
4233 _sb.append( node.getNodeData().getSequence().getName() );
4236 g.setFont( getTreeFontSet().getLargeFont() );
4237 if ( is_in_found_nodes ) {
4238 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
4240 if ( _sb.length() > 1 ) {
4241 final String sb_str = _sb.toString();
4243 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4244 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
4247 m = ( float ) ( ur_angle % TWO_PI );
4249 _at = g.getTransform();
4250 boolean need_to_reset = false;
4251 final float x_coord = node.getXcoord();
4252 final float y_coord = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / 3.0f );
4253 if ( radial_labels ) {
4254 need_to_reset = true;
4255 boolean left = false;
4256 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4260 g.rotate( m, x_coord, node.getYcoord() );
4262 g.translate( -( getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth() ), 0 );
4266 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
4267 need_to_reset = true;
4268 g.translate( -getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth(), 0 );
4271 TreePanel.drawString( sb_str, x_coord, y_coord, g );
4272 if ( need_to_reset ) {
4273 g.setTransform( _at );
4278 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
4279 if ( node.isCollapse() ) {
4280 if ( !node.isRoot() && !node.getParent().isCollapse() ) {
4281 paintCollapsedNode( g, node, false, false, false );
4285 if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
4286 g.setColor( getTreeColorSet().getFoundColor() );
4287 drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
4290 if ( !node.isExternal() && !node.isCollapse() ) {
4291 boolean first_child = true;
4293 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4294 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4295 final PhylogenyNode child_node = node.getChildNode( i );
4297 if ( !isUniformBranchLengthsForCladogram() ) {
4298 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4301 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4303 if ( first_child ) {
4304 first_child = false;
4305 y2 = node.getYSecondary()
4306 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
4307 .getNumberOfExternalNodes() ) );
4310 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4312 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
4313 new_x = x2 + node.getXSecondary();
4314 final float diff_y = node.getYSecondary() - y2;
4315 final float diff_x = node.getXSecondary() - new_x;
4316 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
4317 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
4319 child_node.setXSecondary( new_x );
4320 child_node.setYSecondary( y2 );
4321 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
4326 final private void paintNodeRectangular( final Graphics2D g,
4327 final PhylogenyNode node,
4328 final boolean to_pdf,
4329 final boolean dynamically_hide,
4330 final int dynamic_hiding_factor,
4331 final boolean to_graphics_file ) {
4332 final boolean is_in_found_nodes = isInFoundNodes( node ) || isInCurrentExternalNodes( node );
4333 if ( node.isCollapse() ) {
4334 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) ) {
4335 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4339 if ( node.isExternal() ) {
4340 ++_external_node_index;
4342 // Confidence values
4343 if ( getControlPanel().isShowConfidenceValues()
4344 && !node.isExternal()
4346 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
4347 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
4348 && node.getBranchData().isHasConfidences() ) {
4349 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
4351 // Draw a line to root:
4352 if ( node.isRoot() && _phylogeny.isRooted() ) {
4353 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
4356 float new_x_min = Float.MAX_VALUE;
4357 final boolean disallow_shortcutting = dynamic_hiding_factor < 40;
4358 float min_dist = 1.5f;
4359 if ( !disallow_shortcutting ) {
4360 // System.out.println( dynamic_hiding_factor );
4361 if ( dynamic_hiding_factor > 4000 ) {
4364 else if ( dynamic_hiding_factor > 1000 ) {
4367 else if ( dynamic_hiding_factor > 100 ) {
4371 if ( !node.isExternal() && !node.isCollapse() ) {
4372 boolean first_child = true;
4374 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
4375 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
4376 final PhylogenyNode child_node = node.getChildNode( i );
4378 if ( !isUniformBranchLengthsForCladogram() ) {
4379 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
4382 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
4384 if ( first_child ) {
4385 first_child = false;
4386 y2 = node.getYcoord()
4387 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
4390 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4392 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
4393 new_x = x2 + node.getXcoord();
4394 if ( dynamically_hide && ( x2 < new_x_min ) ) {
4397 final float diff_y = node.getYcoord() - y2;
4398 final float diff_x = node.getXcoord() - new_x;
4399 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
4400 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
4401 paintBranchRectangular( g,
4410 child_node.setXcoord( new_x );
4411 child_node.setYcoord( y2 );
4412 y2 += _y_distance * child_node.getNumberOfExternalNodes();
4414 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node )
4415 || isInCurrentExternalNodes( node ) );
4417 if ( dynamically_hide
4418 && !is_in_found_nodes
4419 && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) ) || ( !node
4420 .isExternal() && ( ( new_x_min < 20 ) || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getTreeFontSet()._fm_large
4421 .getHeight() ) ) ) ) ) {
4424 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
4425 paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
4428 final private void paintNodeWithRenderableData( final Graphics2D g,
4429 final PhylogenyNode node,
4430 final boolean to_graphics_file,
4431 final boolean to_pdf ) {
4432 if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
4435 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
4438 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
4439 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
4440 RenderableDomainArchitecture rds = null;
4441 if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
4443 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
4445 catch ( final ClassCastException cce ) {
4446 cce.printStackTrace();
4448 if ( rds != null ) {
4449 rds.setRenderingHeight( 6 );
4451 if ( node.getNodeData().isHasTaxonomy() ) {
4452 if ( getControlPanel().isShowTaxonomyCode()
4453 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
4454 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4458 if ( getControlPanel().isShowTaxonomyScientificNames()
4459 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) ) {
4460 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4461 .getScientificName()
4464 if ( getControlPanel().isShowTaxonomyCommonNames()
4465 && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) ) {
4466 x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy()
4471 if ( node.getNodeData().isHasSequence() ) {
4472 if ( getControlPanel().isShowGeneNames()
4473 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) ) {
4474 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName()
4477 if ( getControlPanel().isShowGeneSymbols()
4478 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) ) {
4479 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol()
4482 if ( getControlPanel().isShowSequenceAcc()
4483 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
4484 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence()
4485 .getAccession().toString()
4488 if ( getControlPanel().isShowAnnotation()
4489 && ( node.getNodeData().getSequence().getAnnotations() != null )
4490 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
4491 x += getTreeFontSet()._fm_large.stringWidth( AptxUtil.createAnnotationString( node
4492 .getNodeData().getSequence().getAnnotations(), getOptions()
4493 .isShowAnnotationRefSource() )
4497 if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( node.getName() ) ) {
4498 x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
4500 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
4505 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
4506 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
4507 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
4508 getStatisticsForExpressionValues(),
4509 getConfiguration() );
4512 PhylogenyNode my_node = node;
4513 if ( !getControlPanel().isDrawPhylogram() ) {
4514 my_node = getPhylogeny().getFirstExternalNode();
4516 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
4517 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
4519 if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
4520 x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
4522 rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
4528 final private void paintOvRectangle( final Graphics2D g ) {
4529 final float w_ratio = ( ( float ) getWidth() ) / getVisibleRect().width;
4530 final float h_ratio = ( ( float ) getHeight() ) / getVisibleRect().height;
4531 final float x_ratio = ( ( float ) getWidth() ) / getVisibleRect().x;
4532 final float y_ratio = ( ( float ) getHeight() ) / getVisibleRect().y;
4533 final float width = getOvMaxWidth() / w_ratio;
4534 final float height = getOvMaxHeight() / h_ratio;
4535 final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio );
4536 final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio );
4537 g.setColor( getTreeColorSet().getFoundColor() );
4538 getOvRectangle().setRect( x, y, width, height );
4539 final Stroke s = g.getStroke();
4540 g.setStroke( STROKE_1 );
4541 if ( ( width < 6 ) && ( height < 6 ) ) {
4542 drawRectFilled( x, y, 6, 6, g );
4543 getOvVirtualRectangle().setRect( x, y, 6, 6 );
4545 else if ( width < 6 ) {
4546 drawRectFilled( x, y, 6, height, g );
4547 getOvVirtualRectangle().setRect( x, y, 6, height );
4549 else if ( height < 6 ) {
4550 drawRectFilled( x, y, width, 6, g );
4551 getOvVirtualRectangle().setRect( x, y, width, 6 );
4554 drawRect( x, y, width, height, g );
4555 if ( isInOvRect() ) {
4556 drawRect( x + 1, y + 1, width - 2, height - 2, g );
4558 getOvVirtualRectangle().setRect( x, y, width, height );
4563 final private void paintPhylogenyLite( final Graphics2D g ) {
4566 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
4567 .getWidth() ) ) ) );
4568 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
4569 final Stroke s = g.getStroke();
4570 g.setStroke( STROKE_05 );
4571 for( final PhylogenyNode element : _nodes_in_preorder ) {
4572 paintNodeLite( g, element );
4575 paintOvRectangle( g );
4579 * Paint the root branch. (Differs from others because it will always be a
4580 * single horizontal line).
4581 * @param to_graphics_file
4583 * @return new x1 value
4585 final private void paintRootBranch( final Graphics2D g,
4588 final PhylogenyNode root,
4589 final boolean to_pdf,
4590 final boolean to_graphics_file ) {
4591 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
4592 float d = getXdistance();
4593 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
4594 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
4596 if ( d < MIN_ROOT_LENGTH ) {
4597 d = MIN_ROOT_LENGTH;
4599 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
4600 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
4603 final double w = PhylogenyMethods.getBranchWidthValue( root );
4604 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
4606 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file, isInFoundNodes( root ) );
4609 final private void paintScale( final Graphics2D g,
4612 final boolean to_pdf,
4613 final boolean to_graphics_file ) {
4615 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
4617 final int y2 = y1 - 8;
4618 final int y3 = y1 - 4;
4619 g.setFont( getTreeFontSet().getSmallFont() );
4620 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4621 g.setColor( Color.BLACK );
4624 g.setColor( getTreeColorSet().getBranchLengthColor() );
4626 final Stroke s = g.getStroke();
4627 g.setStroke( STROKE_1 );
4628 drawLine( x1, y1, x1, y2, g );
4629 drawLine( x2, y1, x2, y2, g );
4630 drawLine( x1, y3, x2, y3, g );
4631 if ( getScaleLabel() != null ) {
4632 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
4637 final private int paintTaxonomy( final Graphics2D g,
4638 final PhylogenyNode node,
4639 final boolean is_in_found_nodes,
4640 final boolean to_pdf,
4641 final boolean to_graphics_file,
4642 final double x_shift ) {
4643 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
4644 g.setFont( getTreeFontSet().getLargeItalicFont() );
4645 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
4646 g.setColor( Color.BLACK );
4648 else if ( is_in_found_nodes ) {
4649 g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
4650 g.setColor( getTreeColorSet().getFoundColor() );
4652 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4653 g.setColor( getTaxonomyBasedColor( node ) );
4655 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
4656 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
4657 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
4659 else if ( to_pdf ) {
4660 g.setColor( Color.BLACK );
4663 g.setColor( getTreeColorSet().getTaxonomyColor() );
4665 final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
4666 final double start_y = node.getYcoord()
4667 + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
4669 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
4670 _sb.append( taxonomy.getTaxonomyCode() );
4673 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
4674 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
4675 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4676 if ( getOptions().isAbbreviateScientificTaxonNames()
4677 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4678 abbreviateScientificName( taxonomy.getScientificName() );
4681 _sb.append( taxonomy.getScientificName() );
4684 _sb.append( taxonomy.getCommonName() );
4687 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4688 if ( getOptions().isAbbreviateScientificTaxonNames()
4689 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4690 abbreviateScientificName( taxonomy.getScientificName() );
4693 _sb.append( taxonomy.getScientificName() );
4697 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4698 _sb.append( taxonomy.getCommonName() );
4702 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
4703 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
4704 if ( getOptions().isAbbreviateScientificTaxonNames()
4705 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
4706 abbreviateScientificName( taxonomy.getScientificName() );
4709 _sb.append( taxonomy.getScientificName() );
4714 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4715 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4716 _sb.append( taxonomy.getCommonName() );
4720 final String label = _sb.toString();
4722 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
4723 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
4724 // invert font color and background color to show that this is the query sequence
4725 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
4729 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
4730 g.setColor( getTreeColorSet().getBackgroundColor() );
4733 TreePanel.drawString( label, start_x, start_y, g );
4734 if ( is_in_found_nodes ) {
4735 return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
4738 return getTreeFontSet()._fm_large_italic.stringWidth( label );
4742 final private void paintUnrooted( final PhylogenyNode n,
4743 final double low_angle,
4744 final double high_angle,
4745 final boolean radial_labels,
4747 final boolean to_pdf,
4748 final boolean to_graphics_file ) {
4750 n.setXcoord( getWidth() / 2 );
4751 n.setYcoord( getHeight() / 2 );
4753 if ( n.isExternal() ) {
4754 paintNodeDataUnrootedCirc( g,
4759 ( high_angle + low_angle ) / 2,
4760 isInFoundNodes( n ) || isInCurrentExternalNodes( n ) );
4763 final float num_enclosed = n.getNumberOfExternalNodes();
4764 final float x = n.getXcoord();
4765 final float y = n.getYcoord();
4766 double current_angle = low_angle;
4767 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
4768 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
4769 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
4770 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
4771 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4772 final PhylogenyNode desc = n.getChildNode( i );
4773 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
4774 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
4775 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
4776 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
4779 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
4782 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
4785 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4786 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4788 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4789 if ( desc.getDistanceToParent() < 0 ) {
4793 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
4797 length = getUrtFactor();
4799 final double mid_angle = current_angle + ( arc_size / 2 );
4800 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
4801 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
4802 desc.setXcoord( new_x );
4803 desc.setYcoord( new_y );
4804 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
4805 current_angle += arc_size;
4806 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
4807 drawLine( x, y, new_x, new_y, g );
4808 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc )
4809 || isInCurrentExternalNodes( desc ) );
4812 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file, isInFoundNodes( n ) );
4816 final private void paintUnrootedLite( final PhylogenyNode n,
4817 final double low_angle,
4818 final double high_angle,
4820 final float urt_ov_factor ) {
4822 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) );
4823 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) );
4824 n.setXSecondary( x_pos );
4825 n.setYSecondary( y_pos );
4827 if ( n.isExternal() ) {
4830 final float num_enclosed = n.getNumberOfExternalNodes();
4831 final float x = n.getXSecondary();
4832 final float y = n.getYSecondary();
4833 double current_angle = low_angle;
4834 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4835 final PhylogenyNode desc = n.getChildNode( i );
4836 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4837 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4839 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4840 if ( desc.getDistanceToParent() < 0 ) {
4844 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
4848 length = urt_ov_factor;
4850 final double mid_angle = current_angle + ( arc_size / 2 );
4851 final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) );
4852 final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
4853 desc.setXSecondary( new_x );
4854 desc.setYSecondary( new_y );
4855 if ( isInFoundNodes( desc ) || isInCurrentExternalNodes( desc ) ) {
4856 g.setColor( getTreeColorSet().getFoundColor() );
4857 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
4858 g.setColor( getTreeColorSet().getOvColor() );
4860 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
4861 current_angle += arc_size;
4862 drawLine( x, y, new_x, new_y, g );
4866 final private void pasteSubtree( final PhylogenyNode node ) {
4867 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4868 errorMessageNoCutCopyPasteInUnrootedDisplay();
4871 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
4872 JOptionPane.showMessageDialog( this,
4873 "No tree in buffer (need to copy or cut a subtree first)",
4874 "Attempt to paste with empty buffer",
4875 JOptionPane.ERROR_MESSAGE );
4878 final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
4879 final Object[] options = { "As sibling", "As descendant", "Cancel" };
4880 final int r = JOptionPane.showOptionDialog( this,
4881 "How to paste subtree" + label + "?",
4883 JOptionPane.CLOSED_OPTION,
4884 JOptionPane.QUESTION_MESSAGE,
4888 boolean paste_as_sibling = true;
4890 paste_as_sibling = false;
4892 else if ( r != 0 ) {
4895 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
4896 buffer_phy.setAllNodesToNotCollapse();
4897 PhylogenyMethods.preOrderReId( buffer_phy );
4898 buffer_phy.setRooted( true );
4899 boolean need_to_show_whole = false;
4900 if ( paste_as_sibling ) {
4901 if ( node.isRoot() ) {
4902 JOptionPane.showMessageDialog( this,
4903 "Cannot paste sibling to root",
4904 "Attempt to paste sibling to root",
4905 JOptionPane.ERROR_MESSAGE );
4908 buffer_phy.addAsSibling( node );
4911 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
4912 need_to_show_whole = true;
4913 _phylogeny = buffer_phy;
4916 buffer_phy.addAsChild( node );
4919 if ( getCopiedAndPastedNodes() == null ) {
4920 setCopiedAndPastedNodes( new HashSet<Long>() );
4922 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
4923 final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
4924 for( final PhylogenyNode n : nodes ) {
4925 node_ids.add( n.getId() );
4927 node_ids.add( node.getId() );
4928 getCopiedAndPastedNodes().addAll( node_ids );
4929 setNodeInPreorderToNull();
4930 _phylogeny.externalNodesHaveChanged();
4931 _phylogeny.clearHashIdToNodeMap();
4932 _phylogeny.recalculateNumberOfExternalDescendants( true );
4933 resetNodeIdToDistToLeafMap();
4935 if ( need_to_show_whole ) {
4936 getControlPanel().showWhole();
4941 private final StringBuffer propertiesToString( final PhylogenyNode node ) {
4942 final PropertiesMap properties = node.getNodeData().getProperties();
4943 final StringBuffer sb = new StringBuffer();
4944 boolean first = true;
4945 for( final String ref : properties.getPropertyRefs() ) {
4952 final Property p = properties.getProperty( ref );
4953 sb.append( getPartAfterColon( p.getRef() ) );
4955 sb.append( p.getValue() );
4956 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
4957 sb.append( getPartAfterColon( p.getUnit() ) );
4963 final private void setCopiedAndPastedNodes( final Set<Long> nodeIds ) {
4964 getMainPanel().setCopiedAndPastedNodes( nodeIds );
4967 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
4968 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
4971 final private void setInOv( final boolean in_ov ) {
4975 final private void setOvMaxHeight( final float ov_max_height ) {
4976 _ov_max_height = ov_max_height;
4979 final private void setOvMaxWidth( final float ov_max_width ) {
4980 _ov_max_width = ov_max_width;
4983 final private void setOvXcorrectionFactor( final float f ) {
4984 _ov_x_correction_factor = f;
4987 final private void setOvXDistance( final float ov_x_distance ) {
4988 _ov_x_distance = ov_x_distance;
4991 final private void setOvXPosition( final int ov_x_position ) {
4992 _ov_x_position = ov_x_position;
4995 final private void setOvYDistance( final float ov_y_distance ) {
4996 _ov_y_distance = ov_y_distance;
4999 final private void setOvYPosition( final int ov_y_position ) {
5000 _ov_y_position = ov_y_position;
5003 final private void setOvYStart( final int ov_y_start ) {
5004 _ov_y_start = ov_y_start;
5007 final private void setScaleDistance( final double scale_distance ) {
5008 _scale_distance = scale_distance;
5011 final private void setScaleLabel( final String scale_label ) {
5012 _scale_label = scale_label;
5015 private final void setupStroke( final Graphics2D g ) {
5016 if ( getYdistance() < 0.001 ) {
5017 g.setStroke( STROKE_005 );
5019 else if ( getYdistance() < 0.01 ) {
5020 g.setStroke( STROKE_01 );
5022 else if ( getYdistance() < 0.5 ) {
5023 g.setStroke( STROKE_025 );
5025 else if ( getYdistance() < 1 ) {
5026 g.setStroke( STROKE_05 );
5028 else if ( getYdistance() < 2 ) {
5029 g.setStroke( STROKE_075 );
5031 else if ( getYdistance() < 20 ) {
5032 g.setStroke( STROKE_1 );
5035 g.setStroke( STROKE_2 );
5039 final private void setUpUrtFactor() {
5040 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
5041 : getVisibleRect().height;
5042 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
5043 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
5046 final int max_depth = _circ_max_depth;
5047 if ( max_depth > 0 ) {
5048 setUrtFactor( d / ( 2 * max_depth ) );
5051 setUrtFactor( d / 2 );
5054 setUrtFactorOv( getUrtFactor() );
5057 final private void setUrtFactor( final float urt_factor ) {
5058 _urt_factor = urt_factor;
5061 final private void setUrtFactorOv( final float urt_factor_ov ) {
5062 _urt_factor_ov = urt_factor_ov;
5065 private void showExtDescNodeData( final PhylogenyNode node ) {
5066 final List<String> data = new ArrayList<String>();
5067 for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
5068 switch ( getOptions().getExtDescNodeDataToReturn() ) {
5070 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
5071 data.add( n.getName() );
5075 if ( n.getNodeData().isHasSequence()
5076 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
5077 data.add( n.getNodeData().getSequence().getName() );
5080 case SEQUENCE_SYMBOL:
5081 if ( n.getNodeData().isHasSequence()
5082 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
5083 data.add( n.getNodeData().getSequence().getSymbol() );
5086 case SEQUENCE_MOL_SEQ:
5087 if ( n.getNodeData().isHasSequence()
5088 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
5089 data.add( n.getNodeData().getSequence().getMolecularSequence() );
5092 case SEQUENCE_MOL_SEQ_FASTA:
5093 final StringBuilder sb = new StringBuilder();
5094 if ( n.getNodeData().isHasSequence()
5095 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
5096 final StringBuilder ann = new StringBuilder();
5097 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
5098 ann.append( n.getName() );
5101 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
5102 ann.append( "SYM=" );
5103 ann.append( n.getNodeData().getSequence().getSymbol() );
5106 if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
5107 ann.append( "NAME=" );
5108 ann.append( n.getNodeData().getSequence().getName() );
5111 if ( n.getNodeData().getSequence().getAccession() != null ) {
5112 ann.append( "ACC=" );
5113 ann.append( n.getNodeData().getSequence().getAccession().asText() );
5116 if ( n.getNodeData().isHasTaxonomy() ) {
5117 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
5118 ann.append( "TAXID=" );
5119 ann.append( n.getNodeData().getTaxonomy().getTaxonomyCode() );
5122 if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
5123 ann.append( "SN=" );
5124 ann.append( n.getNodeData().getTaxonomy().getScientificName() );
5128 String ann_str = ann.toString().trim();
5129 if ( ann_str.endsWith( "|" ) ) {
5130 ann_str = ann_str.substring( 0, ann_str.length() - 1 );
5132 sb.append( SequenceWriter.toFasta( ann_str, n.getNodeData().getSequence()
5133 .getMolecularSequence(), 60 ) );
5134 data.add( sb.toString() );
5138 if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
5139 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
5140 data.add( n.getNodeData().getSequence().getAccession().toString() );
5143 case TAXONOMY_SCIENTIFIC_NAME:
5144 if ( n.getNodeData().isHasTaxonomy()
5145 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
5146 data.add( n.getNodeData().getTaxonomy().getScientificName() );
5149 case TAXONOMY_COMM0N_NAME:
5150 if ( n.getNodeData().isHasTaxonomy()
5151 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getCommonName() ) ) {
5152 data.add( n.getNodeData().getTaxonomy().getCommonName() );
5156 if ( n.getNodeData().isHasTaxonomy()
5157 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
5158 data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
5162 AptxUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
5165 throw new IllegalArgumentException( "unknown data element: "
5166 + getOptions().getExtDescNodeDataToReturn() );
5169 final StringBuilder sb = new StringBuilder();
5170 final int size = makeSB( data, getOptions(), sb );
5171 if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
5172 || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
5173 if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
5174 System.out.println( sb );
5176 if ( sb.length() < 1 ) {
5177 clearCurrentExternalNodesDataBuffer();
5180 setCurrentExternalNodesDataBuffer( sb );
5183 else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
5184 if ( sb.length() < 1 ) {
5185 AptxUtil.showInformationMessage( this,
5186 "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")",
5187 "Descendants of selected node do not contain selected data" );
5188 clearCurrentExternalNodesDataBuffer();
5191 setCurrentExternalNodesDataBuffer( sb );
5192 final String title = ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
5193 : obtainTitleForExtDescNodeData() )
5197 + node.getNumberOfExternalNodes()
5198 + " external descendats of node "
5200 + ", unique entries: " + size;
5201 final String s = sb.toString().trim();
5202 if ( getMainPanel().getMainFrame() == null ) {
5203 // Must be "E" applet version.
5204 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
5205 ae.showTextFrame( s, title );
5208 getMainPanel().getMainFrame().showTextFrame( s, title );
5214 private int makeSB( final List<String> data, final Options optz, final StringBuilder sb ) {
5215 final SortedMap<String, Integer> map = new TreeMap<String, Integer>();
5216 if ( ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ )
5217 && ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ_FASTA ) ) {
5218 for( final String d : data ) {
5219 if ( !ForesterUtil.isEmpty( d ) ) {
5220 if ( map.containsKey( d ) ) {
5221 map.put( d, map.get( d ) + 1 );
5230 if ( ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ )
5231 && ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ_FASTA ) ) {
5232 for( final Entry<String, Integer> e : map.entrySet() ) {
5233 final String v = e.getKey();
5234 final Object c = e.getValue();
5238 sb.append( ForesterUtil.LINE_SEPARATOR );
5243 for( final String d : data ) {
5244 if ( !ForesterUtil.isEmpty( d ) ) {
5246 sb.append( ForesterUtil.LINE_SEPARATOR );
5254 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
5256 if ( ( node.getName().length() > 0 )
5257 || ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
5258 || ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) )
5259 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
5260 || node.getBranchData().isHasConfidences() ) {
5261 _popup_buffer.setLength( 0 );
5263 if ( node.getName().length() > 0 ) {
5265 _popup_buffer.append( node.getName() );
5267 if ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
5269 boolean enc_data = false;
5270 final Taxonomy tax = node.getNodeData().getTaxonomy();
5271 if ( _popup_buffer.length() > 0 ) {
5272 _popup_buffer.append( "\n" );
5274 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
5275 _popup_buffer.append( "[" );
5276 _popup_buffer.append( tax.getTaxonomyCode() );
5277 _popup_buffer.append( "]" );
5280 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
5282 _popup_buffer.append( " " );
5284 _popup_buffer.append( tax.getScientificName() );
5287 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
5289 _popup_buffer.append( " (" );
5292 _popup_buffer.append( "(" );
5294 _popup_buffer.append( tax.getCommonName() );
5295 _popup_buffer.append( ")" );
5298 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
5300 _popup_buffer.append( " (" );
5303 _popup_buffer.append( "(" );
5305 _popup_buffer.append( tax.getAuthority() );
5306 _popup_buffer.append( ")" );
5309 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
5311 _popup_buffer.append( " [" );
5314 _popup_buffer.append( "[" );
5316 _popup_buffer.append( tax.getRank() );
5317 _popup_buffer.append( "]" );
5320 if ( tax.getSynonyms().size() > 0 ) {
5322 _popup_buffer.append( " " );
5324 _popup_buffer.append( "[" );
5326 for( final String syn : tax.getSynonyms() ) {
5327 if ( !ForesterUtil.isEmpty( syn ) ) {
5329 _popup_buffer.append( syn );
5330 if ( counter < tax.getSynonyms().size() ) {
5331 _popup_buffer.append( ", " );
5336 _popup_buffer.append( "]" );
5339 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
5340 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
5341 _popup_buffer.append( "[" );
5342 _popup_buffer.append( tax.getIdentifier().getProvider() );
5343 _popup_buffer.append( "] " );
5345 _popup_buffer.append( tax.getIdentifier().getValue() );
5349 if ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) ) {
5351 boolean enc_data = false;
5352 if ( _popup_buffer.length() > 0 ) {
5353 _popup_buffer.append( "\n" );
5355 final Sequence seq = node.getNodeData().getSequence();
5356 if ( seq.getAccession() != null ) {
5357 _popup_buffer.append( "[" );
5358 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
5359 _popup_buffer.append( seq.getAccession().getSource() );
5360 _popup_buffer.append( ":" );
5362 _popup_buffer.append( seq.getAccession().getValue() );
5363 _popup_buffer.append( "]" );
5366 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
5368 _popup_buffer.append( " [" );
5371 _popup_buffer.append( "[" );
5373 _popup_buffer.append( seq.getSymbol() );
5374 _popup_buffer.append( "]" );
5377 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
5379 _popup_buffer.append( " " );
5381 _popup_buffer.append( seq.getName() );
5384 if ( node.getNodeData().isHasDate() ) {
5386 if ( _popup_buffer.length() > 0 ) {
5387 _popup_buffer.append( "\n" );
5389 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
5391 if ( node.getNodeData().isHasDistribution() ) {
5393 if ( _popup_buffer.length() > 0 ) {
5394 _popup_buffer.append( "\n" );
5396 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
5398 if ( node.getBranchData().isHasConfidences() ) {
5399 final List<Confidence> confs = node.getBranchData().getConfidences();
5400 for( final Confidence confidence : confs ) {
5402 if ( _popup_buffer.length() > 0 ) {
5403 _popup_buffer.append( "\n" );
5405 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
5406 _popup_buffer.append( "[" );
5407 _popup_buffer.append( confidence.getType() );
5408 _popup_buffer.append( "] " );
5411 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
5413 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5414 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5415 _popup_buffer.append( " (sd=" );
5416 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence
5417 .getStandardDeviation(), getOptions()
5418 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
5419 _popup_buffer.append( ")" );
5423 if ( node.getNodeData().isHasProperties() ) {
5424 final PropertiesMap properties = node.getNodeData().getProperties();
5425 for( final String ref : properties.getPropertyRefs() ) {
5426 _popup_buffer.append( "\n" );
5427 final Property p = properties.getProperty( ref );
5428 _popup_buffer.append( getPartAfterColon( p.getRef() ) );
5429 _popup_buffer.append( "=" );
5430 _popup_buffer.append( p.getValue() );
5431 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
5432 _popup_buffer.append( getPartAfterColon( p.getUnit() ) );
5436 if ( _popup_buffer.length() > 0 ) {
5437 if ( !getConfiguration().isUseNativeUI() ) {
5439 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
5440 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
5441 if ( isInFoundNodes( node ) ) {
5442 _rollover_popup.setForeground( getTreeColorSet().getFoundColor() );
5444 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
5445 _rollover_popup.setForeground( getTaxonomyBasedColor( node ) );
5448 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
5452 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
5454 _rollover_popup.setText( _popup_buffer.toString() );
5455 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
5457 e.getLocationOnScreen().x + 10,
5458 e.getLocationOnScreen().y
5460 _node_desc_popup.show();
5464 catch ( final Exception ex ) {
5469 final private void showNodeEditFrame( final PhylogenyNode n ) {
5470 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5471 // pop up edit box for single node
5472 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
5473 _node_frame_index++;
5476 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5480 final private void showNodeFrame( final PhylogenyNode n ) {
5481 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
5482 // pop up edit box for single node
5483 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
5484 _node_frame_index++;
5487 JOptionPane.showMessageDialog( this, "too many node windows are open" );
5491 final private void switchDisplaygetPhylogenyGraphicsType() {
5492 switch ( getPhylogenyGraphicsType() ) {
5494 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5495 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
5498 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5499 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
5502 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5503 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
5506 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5507 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
5510 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5511 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5514 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5515 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5518 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5519 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5522 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5523 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5526 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
5528 if ( getControlPanel().getDynamicallyHideData() != null ) {
5529 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5530 getControlPanel().getDynamicallyHideData().setEnabled( false );
5533 getControlPanel().getDynamicallyHideData().setEnabled( true );
5536 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5537 getControlPanel().setDrawPhylogramEnabled( true );
5540 getControlPanel().setDrawPhylogramEnabled( false );
5542 if ( getMainPanel().getMainFrame() == null ) {
5543 // Must be "E" applet version.
5544 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
5545 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5548 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5552 final private static void drawString( final int i, final double x, final double y, final Graphics2D g ) {
5553 g.drawString( String.valueOf( i ), ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5556 final private static void drawString( final String str, final double x, final double y, final Graphics2D g ) {
5557 g.drawString( str, ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5560 final private static String getPartAfterColon( final String s ) {
5561 final int i = s.indexOf( ':' );
5562 if ( ( i < 1 ) || ( i == ( s.length() - 1 ) ) ) {
5565 return s.substring( i + 1, s.length() );
5568 final private static boolean isSequenceEmpty( final Sequence seq ) {
5569 return ( seq.getAccession() == null ) && ForesterUtil.isEmpty( seq.getName() )
5570 && ForesterUtil.isEmpty( seq.getSymbol() );
5573 final private static boolean isTaxonomyEmpty( final Taxonomy tax ) {
5574 return ( ( tax.getIdentifier() == null ) && ForesterUtil.isEmpty( tax.getTaxonomyCode() )
5575 && ForesterUtil.isEmpty( tax.getCommonName() ) && ForesterUtil.isEmpty( tax.getScientificName() ) && tax
5576 .getSynonyms().isEmpty() );
5579 final private static boolean plusPressed( final int key_code ) {
5580 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
5581 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
5584 final private static Phylogeny subTree( final PhylogenyNode new_root, final Phylogeny source_phy ) {
5585 final Phylogeny new_phy = new Phylogeny();
5586 new_phy.setRooted( true );
5587 new_phy.setName( source_phy.getName() );
5588 new_phy.setDescription( source_phy.getDescription() );
5589 new_phy.setType( source_phy.getType() );
5590 new_phy.setDistanceUnit( source_phy.getDistanceUnit() );
5591 new_phy.setConfidence( source_phy.getConfidence() );
5592 new_phy.setIdentifier( source_phy.getIdentifier() );
5593 new_phy.setRoot( new_root.copyNodeDataShallow() );
5595 for( final PhylogenyNode n : new_root.getDescendants() ) {
5596 new_phy.getRoot().setChildNode( i++, n );
5601 final private class SubtreeColorizationActionListener implements ActionListener {
5603 JColorChooser _chooser;
5604 PhylogenyNode _node;
5606 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
5612 public void actionPerformed( final ActionEvent e ) {
5613 final Color c = _chooser.getColor();
5615 colorizeSubtree( c, _node );