2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.archaeopteryx;
28 import java.awt.BasicStroke;
29 import java.awt.Color;
30 import java.awt.Cursor;
31 import java.awt.Dimension;
33 import java.awt.GradientPaint;
34 import java.awt.Graphics;
35 import java.awt.Graphics2D;
36 import java.awt.Point;
37 import java.awt.Polygon;
38 import java.awt.Rectangle;
39 import java.awt.RenderingHints;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.FocusAdapter;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.InputEvent;
45 import java.awt.event.KeyAdapter;
46 import java.awt.event.KeyEvent;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseWheelEvent;
49 import java.awt.event.MouseWheelListener;
50 import java.awt.font.FontRenderContext;
51 import java.awt.font.TextLayout;
52 import java.awt.geom.AffineTransform;
53 import java.awt.geom.Arc2D;
54 import java.awt.geom.CubicCurve2D;
55 import java.awt.geom.Ellipse2D;
56 import java.awt.geom.Line2D;
57 import java.awt.geom.QuadCurve2D;
58 import java.awt.geom.Rectangle2D;
59 import java.awt.image.BufferedImage;
60 import java.awt.print.PageFormat;
61 import java.awt.print.Printable;
62 import java.awt.print.PrinterException;
64 import java.io.IOException;
65 import java.io.UnsupportedEncodingException;
67 import java.net.URISyntaxException;
68 import java.net.URLEncoder;
69 import java.text.DecimalFormat;
70 import java.text.DecimalFormatSymbols;
71 import java.text.NumberFormat;
72 import java.util.ArrayList;
73 import java.util.Collections;
74 import java.util.HashMap;
75 import java.util.HashSet;
76 import java.util.Hashtable;
77 import java.util.List;
80 import javax.swing.BorderFactory;
81 import javax.swing.JApplet;
82 import javax.swing.JColorChooser;
83 import javax.swing.JDialog;
84 import javax.swing.JMenuItem;
85 import javax.swing.JOptionPane;
86 import javax.swing.JPanel;
87 import javax.swing.JPopupMenu;
88 import javax.swing.JTextArea;
89 import javax.swing.Popup;
90 import javax.swing.PopupFactory;
92 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
93 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
94 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
95 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
96 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
97 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
98 import org.forester.archaeopteryx.tools.Blast;
99 import org.forester.archaeopteryx.tools.ImageLoader;
100 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
101 import org.forester.phylogeny.Phylogeny;
102 import org.forester.phylogeny.PhylogenyMethods;
103 import org.forester.phylogeny.PhylogenyNode;
104 import org.forester.phylogeny.data.Annotation;
105 import org.forester.phylogeny.data.BranchColor;
106 import org.forester.phylogeny.data.Confidence;
107 import org.forester.phylogeny.data.Event;
108 import org.forester.phylogeny.data.PhylogenyData;
109 import org.forester.phylogeny.data.PropertiesMap;
110 import org.forester.phylogeny.data.Property;
111 import org.forester.phylogeny.data.Sequence;
112 import org.forester.phylogeny.data.SequenceRelation;
113 import org.forester.phylogeny.data.Taxonomy;
114 import org.forester.phylogeny.data.Uri;
115 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
116 import org.forester.phylogeny.iterators.PreorderTreeIterator;
117 import org.forester.util.BasicDescriptiveStatistics;
118 import org.forester.util.DescriptiveStatistics;
119 import org.forester.util.ForesterConstants;
120 import org.forester.util.ForesterUtil;
122 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
124 private static final float PI = ( float ) ( Math.PI );
125 private static final double TWO_PI = 2 * Math.PI;
126 private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
127 private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
128 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
129 private static final short OV_BORDER = 10;
130 final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
131 final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
132 final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
133 final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
134 final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
135 private final static long serialVersionUID = -978349745916505029L;
136 private final static int EURO_D = 10;
137 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
138 private final static int MIN_ROOT_LENGTH = 3;
139 private final static int MAX_SUBTREES = 100;
140 private final static int MAX_NODE_FRAMES = 10;
141 private final static int MOVE = 20;
142 private final static NumberFormat FORMATTER_CONFIDENCE;
143 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
144 private final static int WIGGLE = 2;
145 private int _half_box_size_plus_wiggle;
146 private final static int LIMIT_FOR_HQ_RENDERING = 1000;
147 private final static int CONFIDENCE_LEFT_MARGIN = 4;
148 // TODO "rendering_hints" was static before. Need to make sure everything is OK with it not
149 // being static anymore (02/20/2009).
150 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
151 RenderingHints.VALUE_RENDER_DEFAULT );
152 private File _treefile = null;
153 private Configuration _configuration = null;
154 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
155 private int _node_frame_index = 0;
156 private Phylogeny _phylogeny = null;
157 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
158 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
159 private int _subtree_index = 0;
160 private MainPanel _main_panel = null;
161 private Set<Integer> _found_nodes = null;
162 private PhylogenyNode _highlight_node = null;
163 private JPopupMenu _node_popup_menu = null;
164 private JMenuItem _node_popup_menu_items[] = null;
165 private int _longest_ext_node_info = 0;
166 private float _x_correction_factor = 0.0f;
167 private float _ov_x_correction_factor = 0.0f;
168 private float _x_distance = 0.0f;
169 private float _y_distance = 0.0f;
170 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
171 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
172 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
173 private float _last_drag_point_x = 0;
174 private float _last_drag_point_y = 0;
175 private ControlPanel _control_panel = null;
176 private int _external_node_index = 0;
177 private final Polygon _polygon = new Polygon();
178 private final StringBuilder _sb = new StringBuilder();
179 private JColorChooser _color_chooser = null;
180 private double _scale_distance = 0.0;
181 private String _scale_label = null;
182 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
183 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
184 private final Line2D _line = new Line2D.Float();
185 private final Ellipse2D _ellipse = new Ellipse2D.Float();
186 private final Rectangle2D _rectangle = new Rectangle2D.Float();
187 private Options _options = null;
188 private float _ov_max_width = 0;
189 private float _ov_max_height = 0;
190 private int _ov_x_position = 0;
191 private int _ov_y_position = 0;
192 private int _ov_y_start = 0;
193 private float _ov_y_distance = 0;
194 private float _ov_x_distance = 0;
195 private boolean _ov_on = false;
196 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
197 private float _urt_factor = 1;
198 private float _urt_factor_ov = 1;
199 private final boolean _phy_has_branch_lengths;
200 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
201 private boolean _in_ov_rect = false;
202 private boolean _in_ov = false;
203 private final Rectangle _ov_virtual_rectangle = new Rectangle();
204 final private static double _180_OVER_PI = 180.0 / Math.PI;
205 private static final float ROUNDED_D = 8;
206 private int _circ_max_depth;
207 private int _circ_num_ext_nodes;
208 private PhylogenyNode _root;
209 final private Arc2D _arc = new Arc2D.Double();
210 final private HashMap<Integer, Double> _urt_nodeid_angle_map = new HashMap<Integer, Double>();
211 final private HashMap<Integer, Integer> _urt_nodeid_index_map = new HashMap<Integer, Integer>();
212 HashMap<Integer, Short> _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
213 private AffineTransform _at;
214 private double _max_distance_to_root = -1;
215 private int _dynamic_hiding_factor = 0;
216 private boolean _edited = false;
217 private Popup _node_desc_popup;
218 private JTextArea _rollover_popup;
219 private int _box_size ;
220 private int _half_box_size;
221 //private final short _skip_counter = 0;
222 private final StringBuffer _popup_buffer = new StringBuffer();
223 final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(),
226 private static final boolean DRAW_MEAN_COUNTS = true; //TODO remove me later
227 private Sequence _query_sequence = null;
228 private final FontRenderContext _frc = new FontRenderContext( null,
231 // expression values menu:
232 private DescriptiveStatistics _statistics_for_vector_data;
233 private PhylogenyNode[] _nodes_in_preorder = null;
234 // private Image offscreenImage;
235 // private Graphics offscreenGraphics;
236 // private Dimension offscreenDimension;
238 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
239 dfs.setDecimalSeparator( '.' );
240 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
241 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
244 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
245 requestFocusInWindow();
246 addKeyListener( new KeyAdapter() {
249 public void keyPressed( final KeyEvent key_event ) {
250 keyPressedCalls( key_event );
251 requestFocusInWindow();
254 addFocusListener( new FocusAdapter() {
257 public void focusGained( final FocusEvent e ) {
258 requestFocusInWindow();
261 if ( ( t == null ) || t.isEmpty() ) {
262 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
264 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
266 _configuration = configuration;
268 _phy_has_branch_lengths = ForesterUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
269 _box_size = tjp.getOptions().getDefaultNodeBoxSize();
270 _half_box_size = tjp.getOptions().getDefaultNodeBoxSize() / 2;
272 _half_box_size_plus_wiggle = _half_box_size + WIGGLE;
274 // if ( !_phylogeny.isEmpty() ) {
275 _phylogeny.recalculateNumberOfExternalDescendants( true );
276 checkForVectorProperties( _phylogeny );
278 setBackground( getTreeColorSet().getBackgroundColor() );
279 final MouseListener mouse_listener = new MouseListener( this );
280 addMouseListener( mouse_listener );
281 addMouseMotionListener( mouse_listener );
282 addMouseWheelListener( this );
283 calculateScaleDistance();
284 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
285 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
286 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
289 public void checkForVectorProperties( final Phylogeny phy ) {
290 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
291 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
292 final PhylogenyNode node = iter.next();
293 if ( node.getNodeData().getProperties() != null ) {
294 final PropertiesMap pm = node.getNodeData().getProperties();
295 final double[] vector = new double[ pm.getProperties().size() ];
297 for( final String ref : pm.getProperties().keySet() ) {
298 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
299 final Property p = pm.getProperty( ref );
300 final String value_str = p.getValue();
301 final String index_str = ref
302 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
305 d = Double.parseDouble( value_str );
307 catch ( final NumberFormatException e ) {
308 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
309 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
314 i = Integer.parseInt( index_str );
316 catch ( final NumberFormatException e ) {
317 JOptionPane.showMessageDialog( this,
318 "Could not parse \"" + index_str
319 + "\" into index for vector data",
320 "Problem with Vector Data",
321 JOptionPane.ERROR_MESSAGE );
325 JOptionPane.showMessageDialog( this,
326 "Attempt to use negative index for vector data",
327 "Problem with Vector Data",
328 JOptionPane.ERROR_MESSAGE );
336 final List<Double> vector_l = new ArrayList<Double>( counter );
337 for( int i = 0; i < counter; ++i ) {
338 vector_l.add( vector[ i ] );
340 node.getNodeData().setVector( vector_l );
343 if ( stats.getN() > 0 ) {
344 _statistics_for_vector_data = stats;
348 final public void actionPerformed( final ActionEvent e ) {
350 boolean done = false;
351 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
352 for( index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
353 // NOTE: index corresponds to the indices of click-to options
354 // in the control panel.
355 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
356 // Set this as the new default click-to action
357 _main_panel.getControlPanel().setClickToAction( index );
358 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
359 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
360 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
365 requestFocusInWindow();
368 final private void addEmptyNode( final PhylogenyNode node ) {
369 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
370 errorMessageNoCutCopyPasteInUnrootedDisplay();
373 final String label = getASimpleTextRepresentationOfANode( node );
375 if ( ForesterUtil.isEmpty( label ) ) {
376 msg = "How to add the new, empty node?";
379 msg = "How to add the new, empty node to node" + label + "?";
381 final Object[] options = { "As sibling", "As descendant", "Cancel" };
382 final int r = JOptionPane.showOptionDialog( this,
384 "Addition of Empty New Node",
385 JOptionPane.CLOSED_OPTION,
386 JOptionPane.QUESTION_MESSAGE,
390 boolean add_as_sibling = true;
392 add_as_sibling = false;
397 final Phylogeny phy = new Phylogeny();
398 phy.setRoot( new PhylogenyNode() );
399 phy.setRooted( true );
400 if ( add_as_sibling ) {
401 if ( node.isRoot() ) {
402 JOptionPane.showMessageDialog( this,
403 "Cannot add sibling to root",
404 "Attempt to add sibling to root",
405 JOptionPane.ERROR_MESSAGE );
408 phy.addAsSibling( node );
411 phy.addAsChild( node );
413 _nodes_in_preorder = null;
414 _phylogeny.externalNodesHaveChanged();
415 _phylogeny.hashIDs();
416 _phylogeny.recalculateNumberOfExternalDescendants( true );
417 resetNodeIdToDistToLeafMap();
422 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
423 final boolean is_vertical,
425 final boolean to_pdf,
426 final boolean to_graphics_file ) {
427 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
428 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
429 g.setColor( Color.BLACK );
431 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
432 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
433 && ( getCutOrCopiedTree() != null )
434 && ( getCopiedAndPastedNodes() != null )
436 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
437 g.setColor( getTreeColorSet().getFoundColor() );
439 else if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
440 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
443 g.setColor( getTreeColorSet().getBranchColorForPdf() );
446 g.setColor( getTreeColorSet().getBranchColor() );
450 final void assignGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node, final Graphics g ) {
451 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
452 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
455 g.setColor( getTreeColorSet().getBranchColor() );
459 final private void blast( final PhylogenyNode node ) {
460 if ( !isCanBlast( node ) ) {
461 JOptionPane.showMessageDialog( this,
462 "No sequence information present",
464 JOptionPane.WARNING_MESSAGE );
467 if ( node.getNodeData().isHasSequence() ) {
469 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) {
470 name = node.getNodeData().getSequence().getName();
472 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) {
473 name = node.getNodeData().getSequence().getSymbol();
475 else if ( node.getNodeData().getSequence().getAccession() != null ) {
476 name = node.getNodeData().getSequence().getAccession().getValue();
478 if ( !ForesterUtil.isEmpty( name ) ) {
480 System.out.println( "trying: " + name );
481 final Blast s = new Blast();
484 catch ( final Exception e ) {
491 final void calcMaxDepth() {
492 if ( _phylogeny != null ) {
493 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
498 * Calculate the length of the distance between the given node and its
504 * @return the distance value
506 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
507 if ( getControlPanel().isDrawPhylogram() ) {
508 if ( node.getDistanceToParent() < 0.0 ) {
511 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
514 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
515 return getXdistance();
517 return getXdistance() * factor;
521 final private Color calculateColorForAnnotation( final PhylogenyData ann ) {
522 Color c = getTreeColorSet().getAnnotationColor();
523 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
524 c = getControlPanel().getAnnotationColors().get( ann.asSimpleText().toString() );
526 c = getTreeColorSet().getAnnotationColor();
532 final void calculateLongestExtNodeInfo() {
533 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
537 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
539 if ( node.isCollapse() ) {
542 if ( getControlPanel().isShowNodeNames() ) {
543 sum += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
545 if ( node.getNodeData().isHasSequence() ) {
546 if ( getControlPanel().isShowSequenceAcc()
547 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
548 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
552 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
553 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
555 if ( getControlPanel().isShowGeneSymbols()
556 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
557 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
559 if ( getControlPanel().isShowAnnotation()
560 && ( node.getNodeData().getSequence().getAnnotations() != null )
561 && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
562 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAnnotation( 0 )
567 if ( node.getNodeData().isHasTaxonomy() ) {
568 final Taxonomy tax = node.getNodeData().getTaxonomy();
569 if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
570 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getTaxonomyCode() + " " );
572 if ( getControlPanel().isShowTaxonomyScientificNames()
573 && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
574 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getScientificName() + " " );
576 if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
577 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getCommonName() + " ()" );
580 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
581 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters()
582 .getGainedCharactersAsStringBuffer().toString() );
584 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
585 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
586 sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() )
587 .getRenderingSize().getWidth();
589 if ( sum >= Constants.EXT_NODE_INFO_LENGTH_MAX ) {
590 setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX );
593 if ( sum > longest ) {
597 if ( longest >= Constants.EXT_NODE_INFO_LENGTH_MAX ) {
598 setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX );
601 setLongestExtNodeInfo( longest );
605 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
606 if ( getControlPanel().isDrawPhylogram() ) {
607 if ( node.getDistanceToParent() < 0.0 ) {
610 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
613 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
614 return getOvXDistance();
616 return getOvXDistance() * factor;
620 final void calculateScaleDistance() {
621 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
624 final double height = getMaxDistanceToRoot();
626 if ( ( height <= 0.5 ) ) {
627 setScaleDistance( 0.01 );
629 else if ( height <= 5.0 ) {
630 setScaleDistance( 0.1 );
632 else if ( height <= 50.0 ) {
633 setScaleDistance( 1 );
635 else if ( height <= 500.0 ) {
636 setScaleDistance( 10 );
639 setScaleDistance( 100 );
643 setScaleDistance( 0.0 );
645 String scale_label = String.valueOf( getScaleDistance() );
646 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
647 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
649 setScaleLabel( scale_label );
652 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
653 String species = tax.getTaxonomyCode();
654 if ( ForesterUtil.isEmpty( species ) ) {
655 species = tax.getScientificName();
656 if ( ForesterUtil.isEmpty( species ) ) {
657 species = tax.getCommonName();
660 if ( ForesterUtil.isEmpty( species ) ) {
661 return getTreeColorSet().getTaxonomyColor();
663 // Look in species hash
664 Color c = getControlPanel().getSpeciesColors().get( species );
666 c = Util.calculateColorFromString( species );
667 getControlPanel().getSpeciesColors().put( species, c );
672 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
673 JOptionPane.showMessageDialog( this,
674 "Cannot launch web browser for " + type_type + " data of this node",
675 "Cannot launch web browser",
676 JOptionPane.WARNING_MESSAGE );
680 * Collapse the tree from the given node
685 final void collapse( final PhylogenyNode node ) {
686 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
687 JOptionPane.showMessageDialog( this,
688 "Cannot collapse in unrooted display type",
689 "Attempt to collapse in unrooted display",
690 JOptionPane.WARNING_MESSAGE );
693 if ( !node.isExternal() && !node.isRoot() ) {
694 final boolean collapse = !node.isCollapse();
695 Util.collapseSubtree( node, collapse );
696 _phylogeny.recalculateNumberOfExternalDescendants( true );
697 resetNodeIdToDistToLeafMap();
698 calculateLongestExtNodeInfo();
699 _nodes_in_preorder = null;
700 resetPreferredSize();
702 _main_panel.adjustJScrollPane();
707 final void collapseSpeciesSpecificSubtrees() {
708 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
712 Util.collapseSpeciesSpecificSubtrees( _phylogeny );
713 _phylogeny.recalculateNumberOfExternalDescendants( true );
714 resetNodeIdToDistToLeafMap();
715 calculateLongestExtNodeInfo();
716 _nodes_in_preorder = null;
717 resetPreferredSize();
718 _main_panel.adjustJScrollPane();
723 final private void colorizeSubtree( final Color c, final PhylogenyNode node ) {
724 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
725 JOptionPane.showMessageDialog( this,
726 "Cannot colorize subtree in unrooted display type",
727 "Attempt to colorize subtree in unrooted display",
728 JOptionPane.WARNING_MESSAGE );
731 _control_panel.setColorBranches( true );
732 if ( _control_panel.getColorBranchesCb() != null ) {
733 _control_panel.getColorBranchesCb().setSelected( true );
735 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
736 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
741 final private void colorSubtree( final PhylogenyNode node ) {
742 Color intitial_color = null;
743 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null )
744 && ( ( ( !node.isRoot() && ( node.getParent().getNumberOfDescendants() < 3 ) ) ) || ( node.isRoot() ) ) ) {
745 intitial_color = PhylogenyMethods.getBranchColorValue( node );
748 intitial_color = getTreeColorSet().getBranchColor();
750 _color_chooser.setColor( intitial_color );
751 _color_chooser.setPreviewPanel( new JPanel() );
752 final JDialog dialog = JColorChooser
754 "Subtree colorization",
757 new SubtreeColorizationActionListener( _color_chooser, node ),
759 dialog.setVisible( true );
762 final void confColor() {
763 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
767 Util.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
768 _control_panel.setColorBranches( true );
769 if ( _control_panel.getColorBranchesCb() != null ) {
770 _control_panel.getColorBranchesCb().setSelected( true );
776 final private void copySubtree( final PhylogenyNode node ) {
777 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
778 errorMessageNoCutCopyPasteInUnrootedDisplay();
781 _nodes_in_preorder = null;
782 setCutOrCopiedTree( _phylogeny.copy( node ) );
783 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
784 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
785 for( final PhylogenyNode n : nodes ) {
786 node_ids.add( n.getId() );
788 node_ids.add( node.getId() );
789 setCopiedAndPastedNodes( node_ids );
793 final private void cutSubtree( final PhylogenyNode node ) {
794 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
795 errorMessageNoCutCopyPasteInUnrootedDisplay();
798 if ( node.isRoot() ) {
799 JOptionPane.showMessageDialog( this,
800 "Cannot cut entire tree as subtree",
801 "Attempt to cut entire tree",
802 JOptionPane.ERROR_MESSAGE );
805 final String label = getASimpleTextRepresentationOfANode( node );
806 final int r = JOptionPane.showConfirmDialog( null,
807 "Cut subtree" + label + "?",
808 "Confirm Cutting of Subtree",
809 JOptionPane.YES_NO_OPTION );
810 if ( r != JOptionPane.OK_OPTION ) {
813 _nodes_in_preorder = null;
814 setCopiedAndPastedNodes( null );
815 setCutOrCopiedTree( _phylogeny.copy( node ) );
816 _phylogeny.deleteSubtree( node, true );
817 _phylogeny.hashIDs();
818 _phylogeny.recalculateNumberOfExternalDescendants( true );
819 resetNodeIdToDistToLeafMap();
824 final private void cycleColors() {
825 getMainPanel().getTreeColorSet().cycleColorScheme();
826 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
827 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
831 final void decreaseDomainStructureEvalueThreshold() {
832 if ( _domain_structure_e_value_thr_exp > -20 ) {
833 _domain_structure_e_value_thr_exp -= 1;
837 final private void decreaseOvSize() {
838 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
839 setOvMaxWidth( getOvMaxWidth() - 5 );
840 setOvMaxHeight( getOvMaxHeight() - 5 );
842 getControlPanel().displayedPhylogenyMightHaveChanged( false );
846 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
847 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
848 errorMessageNoCutCopyPasteInUnrootedDisplay();
851 if ( node.isRoot() ) {
852 JOptionPane.showMessageDialog( this,
853 "Cannot delete entire tree",
854 "Attempt to delete entire tree",
855 JOptionPane.ERROR_MESSAGE );
858 final String label = getASimpleTextRepresentationOfANode( node );
859 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
860 final int r = JOptionPane.showOptionDialog( this,
861 "Delete" + label + "?",
862 "Delete Node/Subtree",
863 JOptionPane.CLOSED_OPTION,
864 JOptionPane.QUESTION_MESSAGE,
868 _nodes_in_preorder = null;
869 boolean node_only = true;
877 PhylogenyMethods.removeNode( node, _phylogeny );
880 _phylogeny.deleteSubtree( node, true );
882 _phylogeny.externalNodesHaveChanged();
883 _phylogeny.hashIDs();
884 _phylogeny.recalculateNumberOfExternalDescendants( true );
885 resetNodeIdToDistToLeafMap();
890 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
891 makePopupMenus( node );
892 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
893 _node_popup_menu.show( this, x, y );
896 final private void drawArc( final double x,
900 final double start_angle,
901 final double arc_angle,
902 final Graphics2D g ) {
903 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
907 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
908 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
911 _line.setLine( x1, y1, x2, y2 );
915 final private void drawOval( final double x,
919 final Graphics2D g ) {
920 _ellipse.setFrame( x, y, width, heigth );
924 final private void drawOvalFilled( final double x,
928 final Graphics2D g ) {
929 _ellipse.setFrame( x, y, width, heigth );
933 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
934 _rectangle.setFrame( x, y, width, heigth );
935 g.draw( _rectangle );
938 final private void drawRectFilled( final double x,
942 final Graphics2D g ) {
943 _rectangle.setFrame( x, y, width, heigth );
944 g.fill( _rectangle );
948 final private void drawRectGradient( final double x,
955 final Color color_border ) {
956 _rectangle.setFrame( x, y, width, heigth );
957 g.setPaint( new GradientPaint(( float )x, ( float )y, color_1, ( float ) (x +width), ( float )( y+heigth), color_2,
959 g.fill( _rectangle );
960 if ( color_border != null ) {
961 g.setPaint( color_border );
962 g.draw( _rectangle );
967 final private void drawOvalGradient( final double x,
974 final Color color_border ) {
975 _ellipse.setFrame( x, y, width, heigth );
976 g.setPaint( new GradientPaint(( float )x, ( float )y, color_1, ( float ) (x +width), ( float )( y+heigth), color_2,
979 if ( color_border != null ) {
980 g.setPaint( color_border );
985 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
986 JOptionPane.showMessageDialog( this,
987 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
988 "Attempt to cut/copy/paste/add/delete in unrooted display",
989 JOptionPane.ERROR_MESSAGE );
993 * Find the node, if any, at the given location
997 * @return pointer to the node at x,y, null if not found
999 final PhylogenyNode findNode( final int x, final int y ) {
1000 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1003 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
1004 final PhylogenyNode node = iter.next();
1005 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
1006 && ( ( node.getXcoord() - _half_box_size_plus_wiggle ) <= x )
1007 && ( ( node.getXcoord() + _half_box_size_plus_wiggle ) >= x )
1008 && ( ( node.getYcoord() - _half_box_size_plus_wiggle ) <= y )
1009 && ( ( node.getYcoord() + _half_box_size_plus_wiggle ) >= y ) ) {
1016 final private String getASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
1017 final String tax = PhylogenyMethods.getSpecies( node );
1018 String label = node.getName();
1019 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
1020 label = label + " " + tax;
1022 else if ( !ForesterUtil.isEmpty( tax ) ) {
1028 if ( !ForesterUtil.isEmpty( label ) ) {
1029 label = " [" + label + "]";
1034 final Configuration getConfiguration() {
1035 return _configuration;
1038 final ControlPanel getControlPanel() {
1039 return _control_panel;
1042 final private Set<Integer> getCopiedAndPastedNodes() {
1043 return getMainPanel().getCopiedAndPastedNodes();
1046 final private Phylogeny getCutOrCopiedTree() {
1047 return getMainPanel().getCutOrCopiedTree();
1050 final int getDomainStructureEvalueThreshold() {
1051 return _domain_structure_e_value_thr_exp;
1054 final Set<Integer> getFoundNodes() {
1055 return _found_nodes;
1058 final private float getLastDragPointX() {
1059 return _last_drag_point_x;
1062 final private float getLastDragPointY() {
1063 return _last_drag_point_y;
1066 final int getLongestExtNodeInfo() {
1067 return _longest_ext_node_info;
1070 final public MainPanel getMainPanel() {
1074 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
1075 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
1076 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
1077 _nodeid_dist_to_leaf.put( node.getId(), m );
1081 return _nodeid_dist_to_leaf.get( node.getId() );
1085 final private double getMaxDistanceToRoot() {
1086 if ( _max_distance_to_root < 0 ) {
1087 recalculateMaxDistanceToRoot();
1089 return _max_distance_to_root;
1092 final Options getOptions() {
1093 if ( _options == null ) {
1094 _options = getControlPanel().getOptions();
1099 final private float getOvMaxHeight() {
1100 return _ov_max_height;
1103 final private float getOvMaxWidth() {
1104 return _ov_max_width;
1107 final Rectangle2D getOvRectangle() {
1108 return _ov_rectangle;
1111 final Rectangle getOvVirtualRectangle() {
1112 return _ov_virtual_rectangle;
1115 final private float getOvXcorrectionFactor() {
1116 return _ov_x_correction_factor;
1119 final private float getOvXDistance() {
1120 return _ov_x_distance;
1123 final private int getOvXPosition() {
1124 return _ov_x_position;
1127 final private float getOvYDistance() {
1128 return _ov_y_distance;
1131 final private int getOvYPosition() {
1132 return _ov_y_position;
1135 final private int getOvYStart() {
1140 * Get a pointer to the phylogeny
1142 * @return a pointer to the phylogeny
1144 public final Phylogeny getPhylogeny() {
1148 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
1149 return _graphics_type;
1152 final private double getScaleDistance() {
1153 return _scale_distance;
1156 final private String getScaleLabel() {
1157 return _scale_label;
1160 final double getStartingAngle() {
1161 return _urt_starting_angle;
1165 * Find a color for this species name.
1168 * @return the species color
1170 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
1171 if ( node.getNodeData().isHasTaxonomy() ) {
1172 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
1174 // return non-colorized color
1175 return getTreeColorSet().getTaxonomyColor();
1179 * @return pointer to colorset for tree drawing
1181 final TreeColorSet getTreeColorSet() {
1182 return getMainPanel().getTreeColorSet();
1185 final File getTreeFile() {
1189 final private TreeFontSet getTreeFontSet() {
1190 return getMainPanel().getTreeFontSet();
1193 final private float getUrtFactor() {
1197 final private float getUrtFactorOv() {
1198 return _urt_factor_ov;
1201 final float getXcorrectionFactor() {
1202 return _x_correction_factor;
1205 final float getXdistance() {
1209 final float getYdistance() {
1213 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
1216 showNodeFrame( node );
1231 colorSubtree( node );
1246 copySubtree( node );
1249 pasteSubtree( node );
1251 case DELETE_NODE_OR_SUBTREE:
1252 deleteNodeOrSubtree( node );
1255 addEmptyNode( node );
1257 case EDIT_NODE_DATA:
1258 showNodeEditFrame( node );
1261 throw new IllegalArgumentException( "unknown action: " + action );
1265 final void increaseDomainStructureEvalueThreshold() {
1266 if ( _domain_structure_e_value_thr_exp < 3 ) {
1267 _domain_structure_e_value_thr_exp += 1;
1271 final private void increaseOvSize() {
1272 if ( ( getOvMaxWidth() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 )
1273 && ( getOvMaxHeight() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
1274 .getHeight() / 2 ) ) {
1275 setOvMaxWidth( getOvMaxWidth() + 5 );
1276 setOvMaxHeight( getOvMaxHeight() + 5 );
1278 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1282 final void inferCommonPartOfScientificNames() {
1283 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1287 Util.inferCommonPartOfScientificNames( _phylogeny );
1292 final private void init() {
1293 _color_chooser = new JColorChooser();
1294 _rollover_popup = new JTextArea();
1295 _rollover_popup.setFont( POPUP_FONT );
1296 resetNodeIdToDistToLeafMap();
1298 setTreeFile( null );
1300 initializeOvSettings();
1301 setStartingAngle( TWO_PI * 3 / 4 );
1302 final ImageLoader il = new ImageLoader( this );
1303 new Thread( il ).start();
1306 final private void initializeOvSettings() {
1307 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
1308 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
1311 final void initNodeData() {
1312 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1315 double max_original_domain_structure_width = 0.0;
1316 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1317 if ( node.getNodeData().isHasSequence()
1318 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1319 RenderableDomainArchitecture rds = null;
1320 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
1321 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
1322 getConfiguration() );
1323 node.getNodeData().getSequence().setDomainArchitecture( rds );
1326 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1328 if ( getControlPanel().isShowDomainArchitectures() ) {
1329 final double dsw = rds.getOriginalSize().getWidth();
1330 if ( dsw > max_original_domain_structure_width ) {
1331 max_original_domain_structure_width = dsw;
1336 if ( getControlPanel().isShowDomainArchitectures() ) {
1337 final double ds_factor_width = _domain_structure_width / max_original_domain_structure_width;
1338 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1339 if ( node.getNodeData().isHasSequence()
1340 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1341 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1342 .getSequence().getDomainArchitecture();
1343 rds.setRenderingFactorWidth( ds_factor_width );
1344 rds.setParameter( _domain_structure_e_value_thr_exp );
1350 final boolean inOv( final MouseEvent e ) {
1351 return ( ( e.getX() > getVisibleRect().x + getOvXPosition() + 1 )
1352 && ( e.getX() < getVisibleRect().x + getOvXPosition() + getOvMaxWidth() - 1 )
1353 && ( e.getY() > getVisibleRect().y + getOvYPosition() + 1 ) && ( e.getY() < getVisibleRect().y
1354 + getOvYPosition() + getOvMaxHeight() - 1 ) );
1357 final boolean inOvRectangle( final MouseEvent e ) {
1358 return ( ( e.getX() >= getOvRectangle().getX() - 1 )
1359 && ( e.getX() <= getOvRectangle().getX() + getOvRectangle().getWidth() + 1 )
1360 && ( e.getY() >= getOvRectangle().getY() - 1 ) && ( e.getY() <= getOvRectangle().getY()
1361 + getOvRectangle().getHeight() + 1 ) );
1364 final private boolean inOvVirtualRectangle( final int x, final int y ) {
1365 return ( ( x >= getOvVirtualRectangle().x - 1 )
1366 && ( x <= getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 )
1367 && ( y >= getOvVirtualRectangle().y - 1 ) && ( y <= getOvVirtualRectangle().y
1368 + getOvVirtualRectangle().height + 1 ) );
1371 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
1372 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
1375 final boolean isApplet() {
1376 return getMainPanel() instanceof MainPanelApplets;
1379 final private boolean isCanBlast( final PhylogenyNode node ) {
1380 return ( node.getNodeData().isHasSequence() && ( ( ( node.getNodeData().getSequence().getAccession() != null ) && !ForesterUtil
1381 .isEmpty( node.getNodeData().getSequence().getAccession().getValue() ) )
1382 || !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) || !ForesterUtil.isEmpty( node
1383 .getNodeData().getSequence().getSymbol() ) ) );
1386 final boolean isCanCollapse() {
1387 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1390 final boolean isCanColorSubtree() {
1391 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1394 final boolean isCanCopy() {
1395 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1398 final boolean isCanCut( final PhylogenyNode node ) {
1399 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1403 final boolean isCanDelete() {
1404 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1407 final private boolean isCanOpenSeqWeb( final PhylogenyNode node ) {
1408 if ( node.getNodeData().isHasSequence()
1409 && ( node.getNodeData().getSequence().getAccession() != null )
1410 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
1411 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
1412 && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource()
1413 .toLowerCase() ) ) {
1419 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
1420 if ( node.getNodeData().isHasTaxonomy()
1421 && ( ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
1422 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getProvider() )
1423 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && getConfiguration()
1424 .isHasWebLink( node.getNodeData().getTaxonomy().getIdentifier().getProvider().toLowerCase() ) )
1425 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
1426 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
1427 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
1428 .getNodeData().getTaxonomy().getIdentifier() != null )
1429 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && node
1430 .getNodeData().getTaxonomy().getIdentifier().getValue().startsWith( "http://" ) ) ) ) {
1438 final boolean isCanPaste() {
1439 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1440 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1443 final boolean isCanReroot() {
1444 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1447 final boolean isCanSubtree( final PhylogenyNode node ) {
1448 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1449 .isRoot() || ( _subtree_index > 0 ) ) );
1452 final boolean isEdited() {
1456 final private boolean isInFoundNodes( final PhylogenyNode node ) {
1457 return ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) );
1460 final private boolean isInOv() {
1464 final boolean isInOvRect() {
1468 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
1470 if ( getControlPanel().isShowTaxonomyImages() ) {
1471 y_dist = 40 + ( int ) getYdistance();
1473 return ( ( node.getYcoord() < getVisibleRect().getMinY() - y_dist )
1474 || ( node.getYcoord() > getVisibleRect().getMaxY() + y_dist ) || ( ( node.getParent() != null ) && ( node
1475 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
1478 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
1479 return ( ( node.getYcoord() < getVisibleRect().getMinY() - 20 )
1480 || ( node.getYcoord() > getVisibleRect().getMaxY() + 20 )
1481 || ( node.getXcoord() < getVisibleRect().getMinX() - 20 ) || ( node.getXcoord() > getVisibleRect()
1482 .getMaxX() + 20 ) );
1485 final private boolean isNonLinedUpCladogram() {
1486 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
1489 final boolean isOvOn() {
1493 final boolean isPhyHasBranchLengths() {
1494 return _phy_has_branch_lengths;
1497 final private boolean isUniformBranchLengthsForCladogram() {
1498 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
1501 final private void keyPressedCalls( final KeyEvent e ) {
1502 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
1503 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
1504 if ( !isInOvRect() ) {
1505 setInOvRect( true );
1508 else if ( isInOvRect() ) {
1509 setInOvRect( false );
1512 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
1513 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1514 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
1515 getMainPanel().getTreeFontSet().mediumFonts();
1516 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1518 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1519 getMainPanel().getTreeFontSet().decreaseFontSize();
1520 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1522 else if ( plusPressed( e.getKeyCode() ) ) {
1523 getMainPanel().getTreeFontSet().increaseFontSize();
1524 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1528 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1529 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
1530 getControlPanel().showWhole();
1532 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
1533 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
1534 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
1535 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
1536 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1537 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1539 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1540 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1541 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1543 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1544 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1545 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1546 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1548 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1549 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1550 Constants.WHEEL_ZOOM_IN_FACTOR );
1551 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1558 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1561 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1565 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1569 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1570 scroll_position.x = scroll_position.x + dx;
1571 scroll_position.y = scroll_position.y + dy;
1572 if ( scroll_position.x <= 0 ) {
1573 scroll_position.x = 0;
1576 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1577 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1578 if ( scroll_position.x >= max_x ) {
1579 scroll_position.x = max_x;
1582 if ( scroll_position.y <= 0 ) {
1583 scroll_position.y = 0;
1586 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1587 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1588 if ( scroll_position.y >= max_y ) {
1589 scroll_position.y = max_y;
1593 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1596 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1597 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1598 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1599 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1600 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1602 else if ( plusPressed( e.getKeyCode() ) ) {
1603 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1604 Constants.WHEEL_ZOOM_IN_FACTOR );
1605 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1606 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1608 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
1609 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1610 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1611 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1612 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1615 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
1616 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1617 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1618 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1619 if ( getStartingAngle() < 0 ) {
1620 setStartingAngle( TWO_PI + getStartingAngle() );
1622 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1625 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
1626 boolean selected = false;
1627 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
1628 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1632 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1634 if ( getMainPanel().getMainFrame() == null ) {
1635 // Must be "E" applet version.
1636 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1637 if ( ae.getlabelDirectionCbmi() != null ) {
1638 ae.getlabelDirectionCbmi().setSelected( selected );
1642 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
1646 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
1647 switchDisplaygetPhylogenyGraphicsType();
1650 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
1654 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
1655 MainFrame.cycleOverview( getOptions(), this );
1658 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
1661 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
1668 final private void makePopupMenus( final PhylogenyNode node ) {
1669 _node_popup_menu = new JPopupMenu();
1670 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
1671 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
1672 for( int i = 0; i < clickto_names.size(); i++ ) {
1673 final String title = clickto_names.get( i );
1674 _node_popup_menu_items[ i ] = new JMenuItem( title );
1675 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
1676 _node_popup_menu_items[ i ].setEnabled( isCanOpenSeqWeb( node ) );
1678 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
1679 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
1681 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
1682 if ( Constants.__RELEASE || Constants.__SNAPSHOT_RELEASE ) {
1685 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
1687 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
1688 if ( !getOptions().isEditable() ) {
1691 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
1693 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
1694 if ( !getOptions().isEditable() ) {
1697 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
1699 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
1700 if ( !getOptions().isEditable() ) {
1703 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
1705 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
1706 if ( !getOptions().isEditable() ) {
1709 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
1711 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
1712 if ( !getOptions().isEditable() ) {
1716 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
1717 if ( !getOptions().isEditable() ) {
1721 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
1722 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
1724 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
1725 _node_popup_menu_items[ i ].setEnabled( isCanCollapse() );
1727 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
1728 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
1730 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
1731 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
1733 _node_popup_menu_items[ i ].addActionListener( this );
1734 _node_popup_menu.add( _node_popup_menu_items[ i ] );
1738 final void midpointRoot() {
1739 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1742 if ( !_phylogeny.isRerootable() ) {
1743 JOptionPane.showMessageDialog( this,
1744 "This is not rerootable",
1746 JOptionPane.WARNING_MESSAGE );
1749 _nodes_in_preorder = null;
1751 PhylogenyMethods.midpointRoot( _phylogeny );
1752 resetNodeIdToDistToLeafMap();
1757 final void mouseClicked( final MouseEvent e ) {
1758 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1759 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1760 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1761 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - getOvRectangle().getWidth() / 2.0 )
1763 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - getOvRectangle().getHeight() / 2.0 )
1771 final double max_x = getWidth() - getVisibleRect().width;
1772 final double max_y = getHeight() - getVisibleRect().height;
1779 getMainPanel().getCurrentScrollPane().getViewport()
1780 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1781 setInOvRect( true );
1785 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1786 if ( node != null ) {
1787 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1790 _highlight_node = node;
1791 // Check if shift key is down
1792 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1793 // Yes, so add to _found_nodes
1794 if ( getFoundNodes() == null ) {
1795 setFoundNodes( new HashSet<Integer>() );
1797 getFoundNodes().add( node.getId() );
1798 // Check if control key is down
1800 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1801 // Yes, so pop-up menu
1802 displayNodePopupMenu( node, e.getX(), e.getY() );
1803 // Handle unadorned click
1806 // Check for right mouse button
1807 if ( e.getModifiers() == 4 ) {
1808 displayNodePopupMenu( node, e.getX(), e.getY() );
1811 // if not in _found_nodes, clear _found_nodes
1812 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1817 // no node was clicked
1818 _highlight_node = null;
1824 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1825 setCursor( MOVE_CURSOR );
1826 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1827 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1828 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1829 if ( scroll_position.x < 0 ) {
1830 scroll_position.x = 0;
1833 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1834 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1835 if ( scroll_position.x > max_x ) {
1836 scroll_position.x = max_x;
1839 if ( scroll_position.y < 0 ) {
1840 scroll_position.y = 0;
1843 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1844 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1845 if ( scroll_position.y > max_y ) {
1846 scroll_position.y = max_y;
1849 if ( isOvOn() || getOptions().isShowScale() ) {
1852 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1855 final void mouseDragInOvRectangle( final MouseEvent e ) {
1856 setCursor( HAND_CURSOR );
1857 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1858 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1859 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1860 double dx = ( w_ratio * e.getX() - w_ratio * getLastDragPointX() );
1861 double dy = ( h_ratio * e.getY() - h_ratio * getLastDragPointY() );
1862 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1863 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1864 if ( scroll_position.x <= 0 ) {
1865 scroll_position.x = 0;
1869 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1870 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1871 if ( scroll_position.x >= max_x ) {
1873 scroll_position.x = max_x;
1876 if ( scroll_position.y <= 0 ) {
1878 scroll_position.y = 0;
1881 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1882 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1883 if ( scroll_position.y >= max_y ) {
1885 scroll_position.y = max_y;
1889 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1890 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1891 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1894 final void mouseMoved( final MouseEvent e ) {
1895 requestFocusInWindow();
1896 if ( getControlPanel().isNodeDescPopup() ) {
1897 if ( _node_desc_popup != null ) {
1898 _node_desc_popup.hide();
1899 _node_desc_popup = null;
1902 if ( getOptions().isShowOverview() && isOvOn() ) {
1903 if ( inOvVirtualRectangle( e ) ) {
1904 if ( !isInOvRect() ) {
1905 setInOvRect( true );
1910 if ( isInOvRect() ) {
1911 setInOvRect( false );
1916 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
1925 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1926 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
1927 // cursor is over a tree node
1928 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
1929 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
1930 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
1931 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
1932 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
1933 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
1934 setCursor( CUT_CURSOR );
1937 setCursor( HAND_CURSOR );
1938 if ( getControlPanel().isNodeDescPopup() ) {
1939 showNodeDataPopup( e, node );
1944 setCursor( ARROW_CURSOR );
1949 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
1950 setCursor( ARROW_CURSOR );
1953 final public void mouseWheelMoved( final MouseWheelEvent e ) {
1954 final int notches = e.getWheelRotation();
1955 if ( inOvVirtualRectangle( e ) ) {
1956 if ( !isInOvRect() ) {
1957 setInOvRect( true );
1962 if ( isInOvRect() ) {
1963 setInOvRect( false );
1967 if ( e.isControlDown() ) {
1968 if ( notches < 0 ) {
1969 getTreeFontSet().increaseFontSize();
1970 getControlPanel().displayedPhylogenyMightHaveChanged( true );
1973 getTreeFontSet().decreaseFontSize();
1974 getControlPanel().displayedPhylogenyMightHaveChanged( true );
1977 else if ( e.isShiftDown() ) {
1978 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1979 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1980 if ( notches < 0 ) {
1981 for( int i = 0; i < ( -notches ); ++i ) {
1982 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1983 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1987 for( int i = 0; i < notches; ++i ) {
1988 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1989 if ( getStartingAngle() < 0 ) {
1990 setStartingAngle( TWO_PI + getStartingAngle() );
1992 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1997 if ( notches < 0 ) {
1998 for( int i = 0; i < ( -notches ); ++i ) {
1999 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
2000 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2004 for( int i = 0; i < notches; ++i ) {
2005 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
2006 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2012 if ( notches < 0 ) {
2013 for( int i = 0; i < ( -notches ); ++i ) {
2014 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
2015 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
2016 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
2017 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2021 for( int i = 0; i < notches; ++i ) {
2022 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
2023 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
2024 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
2025 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2030 requestFocusInWindow();
2034 final void multiplyUrtFactor( final float f ) {
2038 final JApplet obtainApplet() {
2039 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
2042 final private void openSeqWeb( final PhylogenyNode node ) {
2043 if ( !isCanOpenSeqWeb( node ) ) {
2044 cannotOpenBrowserWarningMessage( "sequence" );
2047 String uri_str = null;
2048 final Sequence seq = node.getNodeData().getSequence();
2049 final String source = seq.getAccession().getSource().toLowerCase();
2051 if ( source.toLowerCase().equals( "ncbi" ) ) {
2052 url = Constants.NCBI_ALL_DATABASE_SEARCH;
2055 final WebLink weblink = getConfiguration().getWebLink( source );
2056 url = weblink.getUrl().toString();
2059 uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 );
2061 catch ( final UnsupportedEncodingException e ) {
2062 Util.showErrorMessage( this, e.toString() );
2063 e.printStackTrace();
2065 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2067 JApplet applet = null;
2069 applet = obtainApplet();
2071 Util.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_seq" );
2073 catch ( final IOException e ) {
2074 Util.showErrorMessage( this, e.toString() );
2075 e.printStackTrace();
2077 catch ( final URISyntaxException e ) {
2078 Util.showErrorMessage( this, e.toString() );
2079 e.printStackTrace();
2083 cannotOpenBrowserWarningMessage( "sequence" );
2087 final private void openTaxWeb( final PhylogenyNode node ) {
2088 if ( !isCanOpenTaxWeb( node ) ) {
2089 cannotOpenBrowserWarningMessage( "taxonomic" );
2092 String uri_str = null;
2093 final Taxonomy tax = node.getNodeData().getTaxonomy();
2094 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
2095 && getConfiguration().isHasWebLink( tax.getIdentifier().getProvider().toLowerCase() ) ) {
2096 final String type = tax.getIdentifier().getProvider().toLowerCase();
2097 final WebLink weblink = getConfiguration().getWebLink( type );
2099 uri_str = weblink.getUrl() + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
2101 catch ( final UnsupportedEncodingException e ) {
2102 Util.showErrorMessage( this, e.toString() );
2103 e.printStackTrace();
2106 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2107 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
2109 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
2111 catch ( final URISyntaxException e ) {
2112 Util.showErrorMessage( this, e.toString() );
2114 e.printStackTrace();
2117 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
2119 uri_str = "http://www.eol.org/search?q="
2120 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
2122 catch ( final UnsupportedEncodingException e ) {
2123 Util.showErrorMessage( this, e.toString() );
2124 e.printStackTrace();
2127 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
2129 uri_str = "http://www.uniprot.org/taxonomy/?query="
2130 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
2132 catch ( final UnsupportedEncodingException e ) {
2133 Util.showErrorMessage( this, e.toString() );
2134 e.printStackTrace();
2137 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
2139 uri_str = "http://www.eol.org/search?q="
2140 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
2142 catch ( final UnsupportedEncodingException e ) {
2143 Util.showErrorMessage( this, e.toString() );
2144 e.printStackTrace();
2147 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2149 JApplet applet = null;
2151 applet = obtainApplet();
2153 Util.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_tax" );
2155 catch ( final IOException e ) {
2156 Util.showErrorMessage( this, e.toString() );
2157 e.printStackTrace();
2159 catch ( final URISyntaxException e ) {
2160 Util.showErrorMessage( this, e.toString() );
2161 e.printStackTrace();
2165 cannotOpenBrowserWarningMessage( "taxonomic" );
2169 final void paintBranchCircular( final PhylogenyNode p,
2170 final PhylogenyNode c,
2172 final boolean radial_labels,
2173 final boolean to_pdf,
2174 final boolean to_graphics_file ) {
2175 final double angle = _urt_nodeid_angle_map.get( c.getId() );
2176 final double root_x = _root.getXcoord();
2177 final double root_y = _root.getYcoord();
2178 final double dx = root_x - p.getXcoord();
2179 final double dy = root_y - p.getYcoord();
2180 final double parent_radius = Math.sqrt( dx * dx + dy * dy );
2181 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
2182 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
2183 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
2184 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
2185 final double r2 = 2.0 * parent_radius;
2186 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
2188 drawLine( c.getXcoord(),
2190 root_x + ( Math.cos( angle ) * parent_radius ),
2191 root_y + ( Math.sin( angle ) * parent_radius ),
2193 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c ) );
2194 if ( c.isExternal() ) {
2195 final boolean is_in_found_nodes = isInFoundNodes( c );
2196 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
2197 && ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor != 1 ) ) {
2200 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
2204 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
2205 final double angle = _urt_nodeid_angle_map.get( c.getId() );
2206 final double root_x = _root.getXSecondary();
2207 final double root_y = _root.getYSecondary();
2208 final double dx = root_x - p.getXSecondary();
2209 final double dy = root_y - p.getYSecondary();
2210 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
2211 final double parent_radius = Math.sqrt( dx * dx + dy * dy );
2212 g.setColor( getTreeColorSet().getOvColor() );
2213 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
2214 final double r2 = 2.0 * parent_radius;
2215 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
2217 drawLine( c.getXSecondary(),
2219 root_x + ( Math.cos( angle ) * parent_radius ),
2220 root_y + ( Math.sin( angle ) * parent_radius ),
2222 if ( isInFoundNodes( c ) ) {
2223 g.setColor( getTreeColorSet().getFoundColor() );
2224 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
2228 final private void paintBranchLength( final Graphics2D g,
2229 final PhylogenyNode node,
2230 final boolean to_pdf,
2231 final boolean to_graphics_file ) {
2232 g.setFont( getTreeFontSet().getSmallFont() );
2233 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2234 g.setColor( Color.BLACK );
2237 g.setColor( getTreeColorSet().getBranchLengthColor() );
2239 if ( !node.isRoot() ) {
2240 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2241 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2242 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2244 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2245 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2246 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2249 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2250 .getXcoord() + 3, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2254 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
2255 - getTreeFontSet()._small_max_descent, g );
2259 final private void paintBranchLite( final Graphics2D g,
2264 final PhylogenyNode node ) {
2265 g.setColor( getTreeColorSet().getOvColor() );
2266 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2267 drawLine( x1, y1, x2, y2, g );
2269 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2270 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2271 ( g ).draw( _quad_curve );
2273 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2274 final float dx = x2 - x1;
2275 final float dy = y2 - y1;
2276 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
2277 + ( dy * 0.8f ), x2, y2 );
2278 ( g ).draw( _cubic_curve );
2281 final float x2a = x2;
2282 final float x1a = x1;
2283 // draw the vertical line
2284 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
2285 drawLine( x1, y1, x1, y2, g );
2287 // draw the horizontal line
2288 drawLine( x1a, y2, x2a, y2, g );
2293 * Paint a branch which consists of a vertical and a horizontal bar
2294 * @param is_ind_found_nodes
2296 final private void paintBranchRectangular( final Graphics2D g,
2301 final PhylogenyNode node,
2302 final boolean to_pdf,
2303 final boolean to_graphics_file ) {
2304 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
2305 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2306 drawLine( x1, y1, x2, y2, g );
2308 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2309 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2310 g.draw( _quad_curve );
2312 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2313 final float dx = x2 - x1;
2314 final float dy = y2 - y1;
2315 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
2316 + ( dy * 0.8f ), x2, y2 );
2317 g.draw( _cubic_curve );
2322 // draw the vertical line
2323 boolean draw_horizontal = true;
2325 if ( node.isFirstChildNode() || node.isLastChildNode()
2326 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2327 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2328 boolean draw_vertical = true;
2329 final PhylogenyNode parent = node.getParent();
2330 if ( ( ( getOptions().getDefaultNodeShape() != Options.NodeShape.NONE && !to_pdf && !to_graphics_file ) || ( ( getControlPanel()
2331 .isEvents() ) && ( parent != null ) && parent.isHasAssignedEvent() ) )
2332 && ( _phylogeny.isRooted() || !( ( parent != null ) && parent.isRoot() ) )
2333 && !( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() && !parent
2334 .isDuplication() ) ) {
2335 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2336 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2337 if ( Math.abs( y2 - y1 ) <= _half_box_size ) {
2338 draw_vertical = false;
2342 y1 += _half_box_size;
2346 y1 -= _half_box_size + 1;
2349 y1 -= _half_box_size;
2354 if ( ( x2 - x1 ) <= _half_box_size ) {
2355 draw_horizontal = false;
2357 else if ( !draw_vertical ) {
2358 x1a += _half_box_size;
2360 if ( ( ( x2 - x1a ) > _half_box_size )
2361 && !( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() && !node
2362 .isDuplication() ) ) {
2363 x2a -= _half_box_size;
2366 if ( draw_vertical ) {
2367 if ( !to_graphics_file
2369 && ( ( ( y2 < getVisibleRect().getMinY() - 20 ) && ( y1 < getVisibleRect().getMinY() - 20 ) ) || ( ( y2 > getVisibleRect()
2370 .getMaxY() + 20 ) && ( y1 > getVisibleRect().getMaxY() + 20 ) ) ) ) {
2374 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2375 float x2c = x1 + EURO_D;
2379 drawLine( x1, y1, x2c, y2, g );
2381 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2383 y2_r = y2 - ROUNDED_D;
2387 drawLine( x1, y1, x1, y2_r, g );
2390 y2_r = y2 + ROUNDED_D;
2394 drawLine( x1, y1, x1, y2_r, g );
2398 drawLine( x1, y1, x1, y2, g );
2403 // draw the horizontal line
2404 if ( !to_graphics_file && !to_pdf
2405 && ( ( y2 < getVisibleRect().getMinY() - 20 ) || ( y2 > getVisibleRect().getMaxY() + 20 ) ) ) {
2409 if ( draw_horizontal ) {
2410 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
2411 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2412 x1_r = x1a + ROUNDED_D;
2414 drawLine( x1_r, y2, x2a, y2, g );
2417 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2418 final float x1c = x1a + EURO_D;
2420 drawLine( x1c, y2, x2a, y2, g );
2424 drawLine( x1a, y2, x2a, y2, g );
2428 final double w = PhylogenyMethods.getBranchWidthValue( node );
2429 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2430 x1_r = x1a + ROUNDED_D;
2432 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
2435 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2436 final float x1c = x1a + EURO_D;
2438 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
2442 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
2446 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2451 final double diff = y2 - y2_r;
2452 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
2455 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
2461 if ( node.isExternal() ) {
2463 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
2467 final void paintCircular( final Phylogeny phy,
2468 final double starting_angle,
2473 final boolean to_pdf,
2474 final boolean to_graphics_file ) {
2475 _circ_num_ext_nodes = phy.getNumberOfExternalNodes();
2476 _root = phy.getRoot();
2477 _root.setXcoord( center_x );
2478 _root.setYcoord( center_y );
2479 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
2480 double current_angle = starting_angle;
2482 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2483 final PhylogenyNode n = it.next();
2484 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
2485 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
2486 _urt_nodeid_angle_map.put( n.getId(), current_angle );
2487 _urt_nodeid_index_map.put( n.getId(), i++ );
2488 current_angle += ( TWO_PI / _circ_num_ext_nodes );
2490 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
2491 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file, isInFoundNodes( _root ) );
2495 final void paintCircularLite( final Phylogeny phy,
2496 final double starting_angle,
2500 final Graphics2D g ) {
2501 _circ_num_ext_nodes = phy.getNumberOfExternalNodes();
2502 _root = phy.getRoot();
2503 _root.setXSecondary( center_x );
2504 _root.setYSecondary( center_y );
2505 double current_angle = starting_angle;
2506 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2507 final PhylogenyNode n = it.next();
2508 n.setXSecondary( ( float ) ( center_x + radius * Math.cos( current_angle ) ) );
2509 n.setYSecondary( ( float ) ( center_y + radius * Math.sin( current_angle ) ) );
2510 _urt_nodeid_angle_map.put( n.getId(), current_angle );
2511 current_angle += ( TWO_PI / _circ_num_ext_nodes );
2513 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
2516 final private double paintCirculars( final PhylogenyNode n,
2517 final Phylogeny phy,
2518 final float center_x,
2519 final float center_y,
2520 final double radius,
2521 final boolean radial_labels,
2523 final boolean to_pdf,
2524 final boolean to_graphics_file ) {
2525 if ( n.isExternal() ) {
2526 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
2527 System.out.println( "no " + n + ", ERROR!" );//TODO
2529 return _urt_nodeid_angle_map.get( n.getId() );
2532 final List<PhylogenyNode> descs = n.getDescendants();
2534 for( final PhylogenyNode desc : descs ) {
2535 sum += paintCirculars( desc,
2546 if ( !n.isRoot() ) {
2547 r = 1 - ( ( ( double ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth );
2549 final double theta = sum / descs.size();
2550 n.setXcoord( ( float ) ( center_x + r * radius * Math.cos( theta ) ) );
2551 n.setYcoord( ( float ) ( center_y + r * radius * Math.sin( theta ) ) );
2552 _urt_nodeid_angle_map.put( n.getId(), theta );
2553 for( final PhylogenyNode desc : descs ) {
2554 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
2560 final private void paintCircularsLite( final PhylogenyNode n,
2561 final Phylogeny phy,
2565 final Graphics2D g ) {
2566 if ( n.isExternal() ) {
2570 final List<PhylogenyNode> descs = n.getDescendants();
2571 for( final PhylogenyNode desc : descs ) {
2572 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
2575 if ( !n.isRoot() ) {
2576 r = 1 - ( ( ( float ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth );
2578 final double theta = _urt_nodeid_angle_map.get( n.getId() );
2579 n.setXSecondary( ( float ) ( center_x + radius * r * Math.cos( theta ) ) );
2580 n.setYSecondary( ( float ) ( center_y + radius * r * Math.sin( theta ) ) );
2581 for( final PhylogenyNode desc : descs ) {
2582 paintBranchCircularLite( n, desc, g );
2587 final private void paintCollapsedNode( final Graphics2D g,
2588 final PhylogenyNode node,
2589 final boolean to_graphics_file,
2590 final boolean to_pdf,
2591 final boolean is_in_found_nodes ) {
2592 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2593 g.setColor( Color.BLACK );
2595 else if ( is_in_found_nodes ) {
2596 g.setColor( getTreeColorSet().getFoundColor() );
2598 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2599 g.setColor( getTaxonomyBasedColor( node ) );
2601 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
2602 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2603 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2606 g.setColor( getTreeColorSet().getCollapseFillColor() );
2608 double d = node.getAllExternalDescendants().size();
2610 d = ( 3 * _y_distance ) / 3;
2613 d = ( Math.log10( d ) * _y_distance ) / 2.5;
2615 if ( d < _box_size ) {
2619 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() - _box_size ),
2620 ForesterUtil.roundToInt( node.getYcoord() ) );
2621 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + _box_size ),
2622 ForesterUtil.roundToInt( node.getYcoord() - d ) );
2623 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + _box_size ),
2624 ForesterUtil.roundToInt( node.getYcoord() + d ) );
2625 g.fillPolygon( _polygon );
2626 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
2630 final public void paintComponent( final Graphics g ) {
2631 // Dimension currentSize = getSize();
2632 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
2633 // call the 'java.awt.Component.createImage(...)' method to get an
2635 // offscreenImage = createImage( currentSize.width, currentSize.height );
2636 // offscreenGraphics = offscreenImage.getGraphics();
2637 // offscreenDimension = currentSize;
2639 // super.paintComponent( g ); //why?
2640 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
2641 final Graphics2D g2d = ( Graphics2D ) g;
2642 g2d.setRenderingHints( _rendering_hints );
2643 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
2644 //g.drawImage( offscreenImage, 0, 0, this );
2648 public void update( final Graphics g ) {
2652 final private void paintConfidenceValues( final Graphics2D g,
2653 final PhylogenyNode node,
2654 final boolean to_pdf,
2655 final boolean to_graphics_file ) {
2656 String conf_str = "";
2657 final List<Confidence> confidences = node.getBranchData().getConfidences();
2658 if ( confidences.size() == 1 ) {
2659 final double value = node.getBranchData().getConfidence( 0 ).getValue();
2660 if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
2663 conf_str = FORMATTER_CONFIDENCE.format( value );
2665 else if ( confidences.size() > 1 ) {
2666 boolean one_ok = false;
2667 boolean not_first = false;
2668 Collections.sort( confidences );
2669 final StringBuilder sb = new StringBuilder();
2670 for( final Confidence confidence : confidences ) {
2671 final double value = confidence.getValue();
2672 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2673 if ( value >= getOptions().getMinConfidenceValue() ) {
2682 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
2683 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2687 conf_str = sb.toString();
2690 if ( conf_str.length() > 0 ) {
2691 final double parent_x = node.getParent().getXcoord();
2692 double x = node.getXcoord();
2693 g.setFont( getTreeFontSet().getSmallFont() );
2694 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2697 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2700 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2701 g.setColor( Color.BLACK );
2704 g.setColor( getTreeColorSet().getConfidenceColor() );
2707 .drawString( conf_str,
2709 + ( ( x - parent_x - getTreeFontSet()._fm_small.stringWidth( conf_str ) ) / 2 ),
2710 ( node.getYcoord() + getTreeFontSet()._small_max_ascent ) - 1,
2715 final private void paintFoundNode( final int x, final int y, final Graphics2D g ) {
2716 g.setColor( getTreeColorSet().getFoundColor() );
2717 g.fillRect( x - _half_box_size, y - _half_box_size, _box_size, _box_size );
2720 final private void paintGainedAndLostCharacters( final Graphics2D g,
2721 final PhylogenyNode node,
2722 final String gained,
2723 final String lost ) {
2724 if ( node.getParent() != null ) {
2725 final double parent_x = node.getParent().getXcoord();
2726 final double x = node.getXcoord();
2727 g.setFont( getTreeFontSet().getLargeFont() );
2728 g.setColor( getTreeColorSet().getGainedCharactersColor() );
2729 if ( Constants.SPECIAL_CUSTOM ) {
2730 g.setColor( Color.BLUE );
2733 .drawString( gained,
2734 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( gained ) ) / 2 ),
2735 ( node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent() ),
2737 g.setColor( getTreeColorSet().getLostCharactersColor() );
2738 TreePanel.drawString( lost,
2739 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( lost ) ) / 2 ),
2740 ( node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent() ),
2746 * Draw a box at the indicated node.
2753 final private void paintNodeBox( final double x,
2755 final PhylogenyNode node,
2757 final boolean to_pdf,
2758 final boolean to_graphics_file,
2759 final boolean is_in_found_nodes ) {
2760 if ( node.isCollapse() ) {
2763 // if this node should be highlighted, do so
2764 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
2765 g.setColor( getTreeColorSet().getFoundColor() );
2766 drawOval( x - 8, y - 8, 16, 16, g );
2767 drawOval( x - 9, y - 8, 17, 17, g );
2768 drawOval( x - 9, y - 9, 18, 18, g );
2770 if ( is_in_found_nodes ) {
2771 paintFoundNode( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ), g );
2774 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2775 g.setColor( Color.BLACK );
2777 else if ( getControlPanel().isEvents() && Util.isHasAssignedEvent( node ) ) {
2778 final Event event = node.getNodeData().getEvent();
2779 if ( event.isDuplication() ) {
2780 g.setColor( getTreeColorSet().getDuplicationBoxColor() );
2782 else if ( event.isSpeciation() ) {
2783 g.setColor( getTreeColorSet().getSpecBoxColor() );
2785 else if ( event.isSpeciationOrDuplication() ) {
2786 g.setColor( getTreeColorSet().getDuplicationOrSpeciationColor() );
2790 assignGraphicsForNodeBoxWithColorForParentBranch( node, g );
2792 if ( ( getOptions().getDefaultNodeShape() != Options.NodeShape.NONE && !to_pdf && !to_graphics_file )
2793 || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) {
2794 if ( to_pdf || to_graphics_file ) {
2795 if ( node.isDuplication() || !getOptions().isPrintBlackAndWhite() ) {
2796 drawOvalFilled( x - _half_box_size, y - _half_box_size, _box_size, _box_size, g );
2801 //drawRectFilled( x - HALF_BOX_SIZE, y - HALF_BOX_SIZE, BOX_SIZE, BOX_SIZE, g );
2802 drawOvalGradient( x - _half_box_size, y - _half_box_size, _box_size, _box_size, g
2804 g.getColor(), g.getColor());
2810 final private void paintNodeData( final Graphics2D g,
2811 final PhylogenyNode node,
2812 final boolean to_graphics_file,
2813 final boolean to_pdf,
2814 final boolean is_in_found_nodes ) {
2815 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
2818 if ( getOptions().isShowBranchLengthValues()
2819 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2820 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
2821 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) ) {
2822 paintBranchLength( g, node, to_pdf, to_graphics_file );
2824 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
2828 if ( getControlPanel().isShowTaxonomyImages()
2829 && ( getImageMap() != null )
2830 && !getImageMap().isEmpty()
2831 && node.getNodeData().isHasTaxonomy()
2832 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
2833 .getUris().isEmpty() ) ) {
2834 x += drawTaxonomyImage( node.getXcoord() + 2 + _half_box_size, node.getYcoord(), node, g );
2836 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
2837 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
2838 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
2840 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2841 g.setColor( Color.BLACK );
2843 else if ( is_in_found_nodes ) {
2844 g.setColor( getTreeColorSet().getFoundColor() );
2846 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2847 g.setColor( getTaxonomyBasedColor( node ) );
2849 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
2850 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2851 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2853 else if ( to_pdf ) {
2854 g.setColor( Color.BLACK );
2857 g.setColor( getTreeColorSet().getSequenceColor() );
2860 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
2862 _sb.append( node.getAllExternalDescendants().size() );
2865 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
2866 if ( _sb.length() > 0 ) {
2869 _sb.append( node.getName() );
2871 if ( node.getNodeData().isHasSequence() ) {
2872 if ( getControlPanel().isShowGeneSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
2873 if ( _sb.length() > 0 ) {
2876 _sb.append( node.getNodeData().getSequence().getSymbol() );
2878 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
2879 if ( _sb.length() > 0 ) {
2882 _sb.append( node.getNodeData().getSequence().getName() );
2884 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
2885 if ( _sb.length() > 0 ) {
2888 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
2889 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
2892 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
2895 g.setFont( getTreeFontSet().getLargeFont() );
2896 if ( is_in_found_nodes ) {
2897 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
2899 double down_shift_factor = 3.0;
2900 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
2901 down_shift_factor = 1;
2903 final double pos_x = node.getXcoord() + x + 2 + _half_box_size;
2904 final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
2905 final String sb_str = _sb.toString();
2906 // GUILHEM_BEG ______________
2907 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
2908 && ( _query_sequence != null ) ) {
2909 int nodeTextBoundsWidth = 0;
2910 if ( sb_str.length() > 0 ) {
2911 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
2912 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
2914 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
2915 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
2916 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
2917 g.setColor( getTreeColorSet().getBackgroundColor() );
2921 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
2922 for( final SequenceRelation seqRelation : seqRelations ) {
2923 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
2924 .getRef1().isEqual( _query_sequence ) )
2925 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
2926 .getSelectedItem() );
2927 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
2928 final double linePosX = node.getXcoord() + 2 + _half_box_size;
2929 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
2930 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
2932 if ( sConfidence != null ) {
2933 double confidenceX = pos_x;
2934 if ( sb_str.length() > 0 ) {
2935 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
2936 + CONFIDENCE_LEFT_MARGIN;
2938 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
2939 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
2940 .getBounds().getWidth();
2941 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
2942 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
2945 if ( x + nodeTextBoundsWidth > 0 ) /* we only underline if there is something displayed */
2947 if ( nodeTextBoundsWidth == 0 ) {
2948 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
2951 nodeTextBoundsWidth += 2;
2953 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
2954 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
2961 if ( sb_str.length() > 0 ) {
2962 TreePanel.drawString( sb_str, pos_x, pos_y, g );
2964 // GUILHEM_END _____________
2965 // COMMENTED_OUT_BY_GUILHEM_BEG _______________
2966 // TODO FIXME need to check this one!
2967 //if ( _sb.length() > 0 ) {
2968 // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
2969 // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
2971 // COMMENTED_OUT_BY_GUILHEM_END ________________
2972 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
2973 && ( node.getNodeData().getSequence().getAnnotations() != null )
2974 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
2975 if ( _sb.length() > 0 ) {
2976 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
2978 final Annotation ann = node.getNodeData().getSequence().getAnnotation( 0 );
2979 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2980 g.setColor( Color.BLACK );
2983 g.setColor( calculateColorForAnnotation( ann ) );
2985 final String ann_str = ann.asSimpleText().toString();
2986 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + _half_box_size, node.getYcoord()
2987 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
2989 _sb.append( ann_str );
2991 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2992 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2993 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2994 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
2995 && node.getNodeData().isHasBinaryCharacters() ) {
2996 if ( _sb.length() > 0 ) {
2997 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
2999 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3000 g.setColor( Color.BLACK );
3003 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
3005 if ( getControlPanel().isShowBinaryCharacters() ) {
3006 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
3007 .toString(), node.getXcoord() + x + 1 + _half_box_size, node.getYcoord()
3008 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3009 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
3010 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
3011 .getLostCharactersAsStringBuffer().toString() );
3014 if ( DRAW_MEAN_COUNTS && node.isInternal() ) {
3015 final List<PhylogenyNode> ec = node.getAllExternalDescendants();
3018 for( final PhylogenyNode phylogenyNode : ec ) {
3020 if ( phylogenyNode.getNodeData().getBinaryCharacters() != null ) {
3021 sum += phylogenyNode.getNodeData().getBinaryCharacters().getPresentCount();
3024 final double mean = ForesterUtil.round( sum / count, 1 );
3025 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount() + " ["
3026 + mean + "]", node.getXcoord() + x + 4 + _half_box_size, node.getYcoord()
3027 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3030 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
3031 node.getXcoord() + x + 4 + _half_box_size,
3033 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ),
3036 paintGainedAndLostCharacters( g, node, "+"
3037 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
3038 + node.getNodeData().getBinaryCharacters().getLostCount() );
3044 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
3045 final List<Uri> us = new ArrayList<Uri>();
3046 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
3047 for( final Uri uri : t.getUris() ) {
3052 for( final Uri uri : us ) {
3053 if ( uri != null ) {
3054 final String uri_str = uri.getValue().toString().toLowerCase();
3055 if ( getImageMap().containsKey( uri_str ) ) {
3056 final BufferedImage bi = getImageMap().get( uri_str );
3057 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
3058 double scaling_factor = 1;
3059 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
3060 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
3061 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
3063 // y = y - ( 0.9 * getYdistance() );
3064 final double hs = bi.getHeight() * scaling_factor;
3065 double ws = bi.getWidth() * scaling_factor + offset;
3066 final double my_y = y - ( 0.5 * hs );
3067 final int x_w = ( int ) ( x + ws + 0.5 );
3068 final int y_h = ( int ) ( my_y + hs + 0.5 );
3069 if ( ( x_w - x > 7 ) && ( y_h - my_y > 7 ) ) {
3071 ( int ) ( x + 0.5 + offset ),
3072 ( int ) ( my_y + 0.5 ),
3093 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
3094 final PhylogenyNode node,
3095 final boolean to_pdf,
3096 final boolean to_graphics_file,
3097 final boolean radial_labels,
3098 final double ur_angle,
3099 final boolean is_in_found_nodes ) {
3100 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
3103 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3104 g.setColor( Color.BLACK );
3106 else if ( is_in_found_nodes ) {
3107 g.setColor( getTreeColorSet().getFoundColor() );
3109 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3110 g.setColor( getTaxonomyBasedColor( node ) );
3113 g.setColor( getTreeColorSet().getSequenceColor() );
3117 if ( node.getNodeData().isHasTaxonomy()
3118 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
3119 .isShowTaxonomyCommonNames() ) ) {
3120 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3121 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3122 _sb.append( taxonomy.getTaxonomyCode() );
3125 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3126 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3127 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3128 _sb.append( taxonomy.getScientificName() );
3130 _sb.append( taxonomy.getCommonName() );
3133 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3134 _sb.append( taxonomy.getScientificName() );
3137 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3138 _sb.append( taxonomy.getCommonName() );
3142 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3143 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3144 _sb.append( taxonomy.getScientificName() );
3148 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3149 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3150 _sb.append( taxonomy.getCommonName() );
3155 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3157 _sb.append( node.getAllExternalDescendants().size() );
3160 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3161 if ( _sb.length() > 0 ) {
3164 _sb.append( node.getName() );
3166 if ( node.getNodeData().isHasSequence() ) {
3167 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3168 if ( _sb.length() > 0 ) {
3171 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3172 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3175 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3177 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3178 if ( _sb.length() > 0 ) {
3181 _sb.append( node.getNodeData().getSequence().getName() );
3184 g.setFont( getTreeFontSet().getLargeFont() );
3185 if ( is_in_found_nodes ) {
3186 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3188 if ( _sb.length() > 1 ) {
3189 final String sb_str = _sb.toString();
3191 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3192 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
3195 m = ( float ) ( ur_angle % TWO_PI );
3197 _at = g.getTransform();
3198 boolean need_to_reset = false;
3199 final float x_coord = node.getXcoord();
3200 final float y_coord = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / 3.0f );
3201 if ( radial_labels ) {
3202 need_to_reset = true;
3203 boolean left = false;
3204 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3208 g.rotate( m, x_coord, node.getYcoord() );
3210 g.translate( -( getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth() ), 0 );
3214 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3215 need_to_reset = true;
3216 g.translate( -getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth(), 0 );
3219 TreePanel.drawString( sb_str, x_coord, y_coord, g );
3220 if ( need_to_reset ) {
3221 g.setTransform( _at );
3226 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
3227 if ( node.isCollapse() ) {
3228 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
3229 paintCollapsedNode( g, node, false, false, false );
3233 if ( isInFoundNodes( node ) ) {
3234 g.setColor( getTreeColorSet().getFoundColor() );
3235 drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
3238 if ( !node.isExternal() && !node.isCollapse() ) {
3239 boolean first_child = true;
3241 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3242 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3243 final PhylogenyNode child_node = node.getChildNode( i );
3245 if ( !isUniformBranchLengthsForCladogram() ) {
3246 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3249 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
3251 if ( first_child ) {
3252 first_child = false;
3253 y2 = node.getYSecondary()
3254 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
3255 .getNumberOfExternalNodes() ) );
3258 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3260 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
3261 new_x = x2 + node.getXSecondary();
3262 final float diff_y = node.getYSecondary() - y2;
3263 final float diff_x = node.getXSecondary() - new_x;
3264 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
3265 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
3267 child_node.setXSecondary( new_x );
3268 child_node.setYSecondary( y2 );
3269 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3274 final private void paintNodeRectangular( final Graphics2D g,
3275 final PhylogenyNode node,
3276 final boolean to_pdf,
3277 final boolean dynamically_hide,
3278 final int dynamic_hiding_factor,
3279 final boolean to_graphics_file ) {
3280 final boolean is_in_found_nodes = isInFoundNodes( node );
3281 if ( node.isCollapse() ) {
3282 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
3283 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3287 if ( node.isExternal() ) {
3288 ++_external_node_index;
3290 // Confidence values
3291 if ( getControlPanel().isShowBootstrapValues()
3292 && !node.isExternal()
3294 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
3295 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3296 && node.getBranchData().isHasConfidences() ) {
3297 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
3299 // Draw a line to root:
3300 if ( node.isRoot() && _phylogeny.isRooted() ) {
3301 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
3304 float new_x_min = Float.MAX_VALUE;
3305 final boolean disallow_shortcutting = dynamic_hiding_factor < 40;
3306 float min_dist = 1.5f;
3307 if ( !disallow_shortcutting ) {
3308 // System.out.println( dynamic_hiding_factor );
3309 if ( dynamic_hiding_factor > 4000 ) {
3312 else if ( dynamic_hiding_factor > 1000 ) {
3315 else if ( dynamic_hiding_factor > 100 ) {
3319 if ( !node.isExternal() && !node.isCollapse() ) {
3320 boolean first_child = true;
3322 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3323 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3324 final PhylogenyNode child_node = node.getChildNode( i );
3326 if ( !isUniformBranchLengthsForCladogram() ) {
3327 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3330 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
3332 if ( first_child ) {
3333 first_child = false;
3334 y2 = node.getYcoord()
3335 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3338 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3340 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
3341 new_x = x2 + node.getXcoord();
3342 if ( dynamically_hide && ( x2 < new_x_min ) ) {
3345 final float diff_y = node.getYcoord() - y2;
3346 final float diff_x = node.getXcoord() - new_x;
3347 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
3348 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
3349 paintBranchRectangular( g,
3358 child_node.setXcoord( new_x );
3359 child_node.setYcoord( y2 );
3360 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3363 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
3366 if ( dynamically_hide
3367 && !is_in_found_nodes
3368 && ( ( node.isExternal() && ( _external_node_index % dynamic_hiding_factor != 1 ) ) || ( !node
3369 .isExternal() && ( ( new_x_min < 20 ) || ( _y_distance * node.getNumberOfExternalNodes() < getTreeFontSet()._fm_large
3370 .getHeight() ) ) ) ) ) {
3373 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3374 paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
3377 final private void paintNodeWithRenderableData( final Graphics2D g,
3378 final PhylogenyNode node,
3379 final boolean to_graphics_file,
3380 final boolean to_pdf ) {
3381 if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
3384 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
3387 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3388 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
3389 RenderableDomainArchitecture rds = null;
3390 if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
3392 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
3394 catch ( final ClassCastException cce ) {
3395 cce.printStackTrace();
3398 rds.setRenderingHeight( 6 );
3400 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( node ).length() > 0 ) ) {
3401 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( node ) + " " );
3403 if ( getControlPanel().isShowGeneNames() ) {
3404 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
3406 if ( getControlPanel().isShowGeneSymbols() ) {
3407 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
3409 if ( getControlPanel().isShowSequenceAcc() ) {
3410 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
3414 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3415 x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
3417 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
3421 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
3422 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
3423 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
3424 getStatisticsForExpressionValues(),
3425 getConfiguration() );
3427 PhylogenyNode my_node = node;
3428 if ( !getControlPanel().isDrawPhylogram() ) {
3429 my_node = getPhylogeny().getFirstExternalNode();
3431 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
3432 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
3434 if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
3435 x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
3437 rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
3442 final private void paintOvRectangle( final Graphics2D g ) {
3443 final float w_ratio = ( float ) getWidth() / getVisibleRect().width;
3444 final float h_ratio = ( float ) getHeight() / getVisibleRect().height;
3445 final float x_ratio = ( float ) getWidth() / getVisibleRect().x;
3446 final float y_ratio = ( float ) getHeight() / getVisibleRect().y;
3447 final float width = getOvMaxWidth() / w_ratio;
3448 final float height = getOvMaxHeight() / h_ratio;
3449 final float x = getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / x_ratio;
3450 final float y = getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / y_ratio;
3451 g.setColor( getTreeColorSet().getFoundColor() );
3452 getOvRectangle().setRect( x, y, width, height );
3453 if ( ( width < 6 ) && ( height < 6 ) ) {
3454 drawRectFilled( x, y, 6, 6, g );
3455 getOvVirtualRectangle().setRect( x, y, 6, 6 );
3457 else if ( width < 6 ) {
3458 drawRectFilled( x, y, 6, height, g );
3459 getOvVirtualRectangle().setRect( x, y, 6, height );
3461 else if ( height < 6 ) {
3462 drawRectFilled( x, y, width, 6, g );
3463 getOvVirtualRectangle().setRect( x, y, width, 6 );
3466 drawRect( x, y, width, height, g );
3467 if ( isInOvRect() ) {
3468 drawRect( x + 1, y + 1, width - 2, height - 2, g );
3470 getOvVirtualRectangle().setRect( x, y, width, height );
3474 final void paintPhylogeny( final Graphics2D g,
3475 final boolean to_pdf,
3476 final boolean to_graphics_file,
3477 final int graphics_file_width,
3478 final int graphics_file_height,
3479 final int graphics_file_x,
3480 final int graphics_file_y ) {
3481 if ( _control_panel.isShowSequenceRelations() ) {
3482 _query_sequence = _control_panel.getSelectedQuerySequence();
3484 // Color the background
3486 final Rectangle r = getVisibleRect();
3487 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
3488 g.setColor( getTreeColorSet().getBackgroundColor() );
3489 if ( !to_graphics_file ) {
3493 if ( getOptions().isPrintBlackAndWhite() ) {
3494 g.setColor( Color.WHITE );
3496 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
3500 if ( !to_graphics_file ) {
3501 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
3502 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
3506 g.setPaint( new GradientPaint( graphics_file_x,
3508 getTreeColorSet().getBackgroundColor(),
3510 graphics_file_y + graphics_file_height,
3511 getTreeColorSet().getBackgroundColorGradientBottom() ) );
3512 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
3515 g.setStroke( new BasicStroke( 1 ) );
3518 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
3520 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3521 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3522 _external_node_index = 0;
3523 // Position starting X of tree
3524 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
3525 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
3527 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
3528 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
3529 .getDistanceToParent() * getXcorrectionFactor() ) ) );
3532 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
3534 // Position starting Y of tree
3535 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
3536 + ( TreePanel.MOVE / 2.0f ) );
3537 final int dynamic_hiding_factor = ( int ) ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) );
3538 if ( getControlPanel().isDynamicallyHideData() ) {
3539 if ( dynamic_hiding_factor > 1 ) {
3540 getControlPanel().setDynamicHidingIsOn( true );
3543 getControlPanel().setDynamicHidingIsOn( false );
3546 if ( _nodes_in_preorder == null ) {
3547 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
3549 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3550 _nodes_in_preorder[ i++ ] = it.next();
3553 //final PhylogenyNodeIterator it;
3554 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3555 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
3556 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
3558 for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
3559 paintNodeRectangular( g, _nodes_in_preorder[ i ], to_pdf, getControlPanel().isDynamicallyHideData()
3560 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
3562 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
3563 if ( !( to_graphics_file || to_pdf ) ) {
3566 getVisibleRect().y + getVisibleRect().height,
3571 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
3574 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3575 paintPhylogenyLite( g );
3578 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3579 if ( getControlPanel().getDynamicallyHideData() != null ) {
3580 getControlPanel().setDynamicHidingIsOn( false );
3582 final double angle = getStartingAngle();
3583 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
3584 _dynamic_hiding_factor = 0;
3585 if ( getControlPanel().isDynamicallyHideData() ) {
3586 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
3587 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
3589 if ( getControlPanel().getDynamicallyHideData() != null ) {
3590 if ( _dynamic_hiding_factor > 1 ) {
3591 getControlPanel().setDynamicHidingIsOn( true );
3594 getControlPanel().setDynamicHidingIsOn( false );
3597 paintUnrooted( _phylogeny.getRoot(),
3599 ( float ) ( angle + 2 * Math.PI ),
3604 if ( getOptions().isShowScale() ) {
3605 if ( !( to_graphics_file || to_pdf ) ) {
3608 getVisibleRect().y + getVisibleRect().height,
3613 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
3616 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3617 g.setColor( getTreeColorSet().getOvColor() );
3618 paintUnrootedLite( _phylogeny.getRoot(),
3620 angle + 2 * Math.PI,
3622 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
3623 paintOvRectangle( g );
3626 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3627 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
3628 final int d = radius + MOVE + getLongestExtNodeInfo();
3629 _dynamic_hiding_factor = 0;
3630 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
3631 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
3632 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
3634 if ( getControlPanel().getDynamicallyHideData() != null ) {
3635 if ( _dynamic_hiding_factor > 1 ) {
3636 getControlPanel().setDynamicHidingIsOn( true );
3639 getControlPanel().setDynamicHidingIsOn( false );
3642 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
3643 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3644 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
3645 : getOvMaxWidth() / 2 );
3646 double x_scale = 1.0;
3647 double y_scale = 1.0;
3648 int x_pos = getVisibleRect().x + getOvXPosition();
3649 int y_pos = getVisibleRect().y + getOvYPosition();
3650 if ( getWidth() > getHeight() ) {
3651 x_scale = ( double ) getHeight() / getWidth();
3652 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
3655 y_scale = ( double ) getWidth() / getHeight();
3656 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
3658 _at = g.getTransform();
3659 g.scale( x_scale, y_scale );
3660 paintCircularLite( _phylogeny,
3664 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
3667 g.setTransform( _at );
3668 paintOvRectangle( g );
3673 final private void paintPhylogenyLite( final Graphics2D g ) {
3674 //System.out.println( getVisibleRect().x + " " + getVisibleRect().y );
3677 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
3678 .getWidth() ) ) ) );
3679 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
3680 //final PhylogenyNodeIterator it;
3681 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3682 // paintNodeLite( g, it.next() );
3684 for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
3685 paintNodeLite( g, _nodes_in_preorder[ i ] );
3687 paintOvRectangle( g );
3691 * Paint the root branch. (Differs from others because it will always be a
3692 * single horizontal line).
3693 * @param to_graphics_file
3695 * @return new x1 value
3697 final private void paintRootBranch( final Graphics2D g,
3700 final PhylogenyNode root,
3701 final boolean to_pdf,
3702 final boolean to_graphics_file ) {
3703 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
3704 float d = getXdistance();
3705 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
3706 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
3708 if ( d < MIN_ROOT_LENGTH ) {
3709 d = MIN_ROOT_LENGTH;
3711 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
3712 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
3715 final double w = PhylogenyMethods.getBranchWidthValue( root );
3716 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
3718 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file, isInFoundNodes( root ) );
3721 final private void paintScale( final Graphics2D g,
3724 final boolean to_pdf,
3725 final boolean to_graphics_file ) {
3727 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
3729 final int y2 = y1 - 8;
3730 final int y3 = y1 - 4;
3731 g.setFont( getTreeFontSet().getSmallFont() );
3732 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3733 g.setColor( Color.BLACK );
3736 g.setColor( getTreeColorSet().getBranchLengthColor() );
3738 drawLine( x1, y1, x1, y2, g );
3739 drawLine( x2, y1, x2, y2, g );
3740 drawLine( x1, y3, x2, y3, g );
3741 if ( getScaleLabel() != null ) {
3742 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
3746 final private int paintTaxonomy( final Graphics2D g,
3747 final PhylogenyNode node,
3748 final boolean is_in_found_nodes,
3749 final boolean to_pdf,
3750 final boolean to_graphics_file,
3751 final double x_shift ) {
3752 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3753 g.setFont( getTreeFontSet().getLargeItalicFont() );
3754 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3755 g.setColor( Color.BLACK );
3757 else if ( is_in_found_nodes ) {
3758 g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
3759 g.setColor( getTreeColorSet().getFoundColor() );
3761 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3762 g.setColor( getTaxonomyBasedColor( node ) );
3764 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3765 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3766 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3768 else if ( to_pdf ) {
3769 g.setColor( Color.BLACK );
3772 g.setColor( getTreeColorSet().getTaxonomyColor() );
3774 final double start_x = node.getXcoord() + 3 + _half_box_size + x_shift;
3775 final double start_y = node.getYcoord()
3776 + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
3778 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3779 _sb.append( taxonomy.getTaxonomyCode() );
3782 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3783 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3784 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3785 if ( getOptions().isAbbreviateScientificTaxonNames()
3786 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3787 abbreviateScientificName( taxonomy.getScientificName() );
3790 _sb.append( taxonomy.getScientificName() );
3793 _sb.append( taxonomy.getCommonName() );
3796 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3797 if ( getOptions().isAbbreviateScientificTaxonNames()
3798 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3799 abbreviateScientificName( taxonomy.getScientificName() );
3802 _sb.append( taxonomy.getScientificName() );
3806 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3807 _sb.append( taxonomy.getCommonName() );
3811 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3812 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3813 if ( getOptions().isAbbreviateScientificTaxonNames()
3814 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3815 abbreviateScientificName( taxonomy.getScientificName() );
3818 _sb.append( taxonomy.getScientificName() );
3823 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3824 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3825 _sb.append( taxonomy.getCommonName() );
3829 final String label = _sb.toString();
3831 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
3832 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
3833 // invert font color and background color to show that this is the query sequence
3834 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
3838 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
3839 g.setColor( getTreeColorSet().getBackgroundColor() );
3842 TreePanel.drawString( label, start_x, start_y, g );
3843 if ( is_in_found_nodes ) {
3844 return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
3847 return getTreeFontSet()._fm_large_italic.stringWidth( label );
3851 private void abbreviateScientificName( final String sn ) {
3852 final String[] a = sn.split( "\\s+" );
3853 _sb.append( a[ 0 ].substring( 0, 1 ) );
3854 _sb.append( a[ 1 ].substring( 0, 2 ) );
3855 if ( a.length > 2 ) {
3856 for( int i = 2; i < a.length; i++ ) {
3858 _sb.append( a[ i ] );
3863 final private void paintUnrooted( final PhylogenyNode n,
3864 final double low_angle,
3865 final double high_angle,
3866 final boolean radial_labels,
3868 final boolean to_pdf,
3869 final boolean to_graphics_file ) {
3871 n.setXcoord( getWidth() / 2 );
3872 n.setYcoord( getHeight() / 2 );
3873 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file, isInFoundNodes( n ) );
3875 if ( n.isExternal() ) {
3876 paintNodeDataUnrootedCirc( g,
3881 ( high_angle + low_angle ) / 2,
3882 isInFoundNodes( n ) );
3885 final float num_enclosed = n.getNumberOfExternalNodes();
3886 final float x = n.getXcoord();
3887 final float y = n.getYcoord();
3888 double current_angle = low_angle;
3889 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
3890 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
3891 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
3892 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
3893 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3894 final PhylogenyNode desc = n.getChildNode( i );
3895 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
3896 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
3897 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
3898 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
3901 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
3904 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
3907 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3908 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3910 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3911 if ( desc.getDistanceToParent() < 0 ) {
3915 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
3919 length = getUrtFactor();
3921 final double mid_angle = current_angle + arc_size / 2;
3922 final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length );
3923 final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length );
3924 desc.setXcoord( new_x );
3925 desc.setYcoord( new_y );
3926 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc ) );
3927 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
3928 current_angle += arc_size;
3929 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
3930 drawLine( x, y, new_x, new_y, g );
3934 final private void paintUnrootedLite( final PhylogenyNode n,
3935 final double low_angle,
3936 final double high_angle,
3938 final float urt_ov_factor ) {
3940 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / 2 );
3941 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / 2 );
3942 n.setXSecondary( x_pos );
3943 n.setYSecondary( y_pos );
3945 if ( n.isExternal() ) {
3948 final float num_enclosed = n.getNumberOfExternalNodes();
3949 final float x = n.getXSecondary();
3950 final float y = n.getYSecondary();
3951 double current_angle = low_angle;
3952 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3953 final PhylogenyNode desc = n.getChildNode( i );
3954 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3955 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3957 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3958 if ( desc.getDistanceToParent() < 0 ) {
3962 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
3966 length = urt_ov_factor;
3968 final double mid_angle = current_angle + arc_size / 2;
3969 final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length );
3970 final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length );
3971 desc.setXSecondary( new_x );
3972 desc.setYSecondary( new_y );
3973 if ( isInFoundNodes( desc ) ) {
3974 g.setColor( getTreeColorSet().getFoundColor() );
3975 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
3976 g.setColor( getTreeColorSet().getOvColor() );
3978 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
3979 current_angle += arc_size;
3980 drawLine( x, y, new_x, new_y, g );
3984 final private void pasteSubtree( final PhylogenyNode node ) {
3985 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3986 errorMessageNoCutCopyPasteInUnrootedDisplay();
3989 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
3990 JOptionPane.showMessageDialog( this,
3991 "No tree in buffer (need to copy or cut a subtree first)",
3992 "Attempt to paste with empty buffer",
3993 JOptionPane.ERROR_MESSAGE );
3996 final String label = getASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
3997 final Object[] options = { "As sibling", "As descendant", "Cancel" };
3998 final int r = JOptionPane.showOptionDialog( this,
3999 "How to paste subtree" + label + "?",
4001 JOptionPane.CLOSED_OPTION,
4002 JOptionPane.QUESTION_MESSAGE,
4006 boolean paste_as_sibling = true;
4008 paste_as_sibling = false;
4010 else if ( r != 0 ) {
4013 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
4014 buffer_phy.setAllNodesToNotCollapse();
4015 buffer_phy.preOrderReId();
4016 buffer_phy.setRooted( true );
4017 boolean need_to_show_whole = false;
4018 if ( paste_as_sibling ) {
4019 if ( node.isRoot() ) {
4020 JOptionPane.showMessageDialog( this,
4021 "Cannot paste sibling to root",
4022 "Attempt to paste sibling to root",
4023 JOptionPane.ERROR_MESSAGE );
4026 buffer_phy.addAsSibling( node );
4029 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
4030 need_to_show_whole = true;
4031 _phylogeny = buffer_phy;
4034 buffer_phy.addAsChild( node );
4037 if ( getCopiedAndPastedNodes() == null ) {
4038 setCopiedAndPastedNodes( new HashSet<Integer>() );
4040 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
4041 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
4042 for( final PhylogenyNode n : nodes ) {
4043 node_ids.add( n.getId() );
4045 node_ids.add( node.getId() );
4046 getCopiedAndPastedNodes().addAll( node_ids );
4047 _nodes_in_preorder = null;
4048 _phylogeny.externalNodesHaveChanged();
4049 _phylogeny.hashIDs();
4050 _phylogeny.recalculateNumberOfExternalDescendants( true );
4051 resetNodeIdToDistToLeafMap();
4053 if ( need_to_show_whole ) {
4054 getControlPanel().showWhole();
4059 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
4060 throws PrinterException {
4061 if ( page_index > 0 ) {
4062 return ( NO_SUCH_PAGE );
4065 final Graphics2D g2d = ( Graphics2D ) g;
4066 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
4067 // Turn off double buffering !?
4068 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
4069 // Turn double buffering back on !?
4070 return ( PAGE_EXISTS );
4074 final void recalculateMaxDistanceToRoot() {
4075 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
4079 * Remove all edit-node frames
4081 final void removeAllEditNodeJFrames() {
4082 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
4083 if ( _node_frames[ i ] != null ) {
4084 _node_frames[ i ].dispose();
4085 _node_frames[ i ] = null;
4088 _node_frame_index = 0;
4092 * Remove a node-edit frame.
4094 final void removeEditNodeFrame( final int i ) {
4095 _node_frame_index--;
4096 _node_frames[ i ] = null;
4097 if ( i < _node_frame_index ) {
4098 for( int j = 0; j < _node_frame_index - 1; j++ ) {
4099 _node_frames[ j ] = _node_frames[ j + 1 ];
4101 _node_frames[ _node_frame_index ] = null;
4105 final void reRoot( final PhylogenyNode node ) {
4106 if ( !getPhylogeny().isRerootable() ) {
4107 JOptionPane.showMessageDialog( this,
4108 "This is not rerootable",
4110 JOptionPane.WARNING_MESSAGE );
4113 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4114 JOptionPane.showMessageDialog( this,
4115 "Cannot reroot in unrooted display type",
4116 "Attempt to reroot tree in unrooted display",
4117 JOptionPane.WARNING_MESSAGE );
4120 getPhylogeny().reRoot( node );
4121 getPhylogeny().recalculateNumberOfExternalDescendants( true );
4122 resetNodeIdToDistToLeafMap();
4123 _nodes_in_preorder = null;
4124 resetPreferredSize();
4125 getMainPanel().adjustJScrollPane();
4127 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4128 getControlPanel().showWhole();
4132 final void resetNodeIdToDistToLeafMap() {
4133 _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
4136 final void resetPreferredSize() {
4137 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
4143 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
4144 if ( getControlPanel().isDrawPhylogram() ) {
4146 + getLongestExtNodeInfo()
4148 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
4151 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4153 + getLongestExtNodeInfo()
4154 + ForesterUtil.roundToInt( getXdistance()
4155 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
4159 + getLongestExtNodeInfo()
4160 + ForesterUtil.roundToInt( getXdistance()
4161 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
4164 setPreferredSize( new Dimension( x, y ) );
4167 public final void setArrowCursor() {
4168 setCursor( ARROW_CURSOR );
4172 final void setControlPanel( final ControlPanel atv_control ) {
4173 _control_panel = atv_control;
4176 final private void setCopiedAndPastedNodes( final Set<Integer> nodeIds ) {
4177 getMainPanel().setCopiedAndPastedNodes( nodeIds );
4180 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
4181 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
4184 public final void setEdited( final boolean edited ) {
4188 final void setFoundNodes( final Set<Integer> found_nodes ) {
4189 _found_nodes = found_nodes;
4192 final private void setInOv( final boolean in_ov ) {
4196 final void setInOvRect( final boolean in_ov_rect ) {
4197 _in_ov_rect = in_ov_rect;
4200 final void setLargeFonts() {
4201 getTreeFontSet().largeFonts();
4204 final void setLastMouseDragPointX( final float x ) {
4205 _last_drag_point_x = x;
4208 final void setLastMouseDragPointY( final float y ) {
4209 _last_drag_point_y = y;
4212 final void setLongestExtNodeInfo( final int i ) {
4213 _longest_ext_node_info = i;
4216 final void setMediumFonts() {
4217 getTreeFontSet().mediumFonts();
4220 final private void setOvMaxHeight( final float ov_max_height ) {
4221 _ov_max_height = ov_max_height;
4224 final private void setOvMaxWidth( final float ov_max_width ) {
4225 _ov_max_width = ov_max_width;
4228 final void setOvOn( final boolean ov_on ) {
4232 final private void setOvXcorrectionFactor( final float f ) {
4233 _ov_x_correction_factor = f;
4236 final private void setOvXDistance( final float ov_x_distance ) {
4237 _ov_x_distance = ov_x_distance;
4240 final private void setOvXPosition( final int ov_x_position ) {
4241 _ov_x_position = ov_x_position;
4244 final private void setOvYDistance( final float ov_y_distance ) {
4245 _ov_y_distance = ov_y_distance;
4248 final private void setOvYPosition( final int ov_y_position ) {
4249 _ov_y_position = ov_y_position;
4252 final private void setOvYStart( final int ov_y_start ) {
4253 _ov_y_start = ov_y_start;
4257 * Set parameters for printing the displayed tree
4262 final void setParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
4263 // updateStyle(); not needed?
4264 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4266 if ( recalc_longest_ext_node_info ) {
4267 calculateLongestExtNodeInfo();
4269 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4270 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4271 if ( ext_nodes == 1 ) {
4272 ext_nodes = max_depth;
4273 if ( ext_nodes < 1 ) {
4280 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4281 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
4282 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
4285 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
4286 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
4288 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
4289 if ( xdist < 0.0 ) {
4292 if ( ov_xdist < 0.0 ) {
4295 if ( ydist < 0.0 ) {
4298 setXdistance( xdist );
4299 setYdistance( ydist );
4300 setOvXDistance( ov_xdist );
4301 final double height = _phylogeny.getHeight();
4303 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
4304 setXcorrectionFactor( corr > 0 ? corr : 0 );
4305 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
4306 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4309 setXcorrectionFactor( 0 );
4310 setOvXcorrectionFactor( 0 );
4312 _circ_max_depth = max_depth;
4317 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
4318 _graphics_type = graphics_type;
4322 final private void setScaleDistance( final double scale_distance ) {
4323 _scale_distance = scale_distance;
4326 final private void setScaleLabel( final String scale_label ) {
4327 _scale_label = scale_label;
4330 final void setSmallFonts() {
4331 getTreeFontSet().smallFonts();
4334 final void setStartingAngle( final double starting_angle ) {
4335 _urt_starting_angle = starting_angle;
4338 final void setSuperTinyFonts() {
4339 getTreeFontSet().superTinyFonts();
4342 final void setTextAntialias() {
4343 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4344 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
4345 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
4348 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
4351 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
4352 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) {
4353 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
4356 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
4359 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING,
4360 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
4362 catch ( final Throwable e ) {
4363 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
4367 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
4368 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
4372 final void setTinyFonts() {
4373 getTreeFontSet().tinyFonts();
4377 * Set a phylogeny tree.
4380 * an instance of a Phylogeny
4382 public final void setTree( final Phylogeny t ) {
4383 _nodes_in_preorder = null;
4387 final void setTreeFile( final File treefile ) {
4388 _treefile = treefile;
4391 final private void setUpUrtFactor() {
4392 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
4393 : getVisibleRect().height;
4394 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4395 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
4398 final int max_depth = _circ_max_depth;
4399 if ( max_depth > 0 ) {
4400 setUrtFactor( d / ( 2 * max_depth ) );
4403 setUrtFactor( d / 2 );
4406 setUrtFactorOv( getUrtFactor() );
4409 final private void setUrtFactor( final float urt_factor ) {
4410 _urt_factor = urt_factor;
4413 final private void setUrtFactorOv( final float urt_factor_ov ) {
4414 _urt_factor_ov = urt_factor_ov;
4417 public final void setWaitCursor() {
4418 setCursor( WAIT_CURSOR );
4422 final void setXcorrectionFactor( final float f ) {
4423 _x_correction_factor = f;
4426 final void setXdistance( final float x ) {
4430 final void setYdistance( final float y ) {
4434 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
4436 if ( ( node.getName().length() > 0 )
4437 || ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
4438 || ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) )
4439 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
4440 || node.getBranchData().isHasConfidences() ) {
4441 _popup_buffer.setLength( 0 );
4443 if ( node.getName().length() > 0 ) {
4445 _popup_buffer.append( node.getName() );
4447 if ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
4449 boolean enc_data = false;
4450 final Taxonomy tax = node.getNodeData().getTaxonomy();
4451 if ( _popup_buffer.length() > 0 ) {
4452 _popup_buffer.append( "\n" );
4454 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4455 _popup_buffer.append( "[" );
4456 _popup_buffer.append( tax.getTaxonomyCode() );
4457 _popup_buffer.append( "]" );
4460 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4462 _popup_buffer.append( " " );
4464 _popup_buffer.append( tax.getScientificName() );
4467 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
4469 _popup_buffer.append( " (" );
4472 _popup_buffer.append( "(" );
4474 _popup_buffer.append( tax.getCommonName() );
4475 _popup_buffer.append( ")" );
4478 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
4480 _popup_buffer.append( " (" );
4483 _popup_buffer.append( "(" );
4485 _popup_buffer.append( tax.getAuthority() );
4486 _popup_buffer.append( ")" );
4489 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
4491 _popup_buffer.append( " [" );
4494 _popup_buffer.append( "[" );
4496 _popup_buffer.append( tax.getRank() );
4497 _popup_buffer.append( "]" );
4500 if ( tax.getSynonyms().size() > 0 ) {
4502 _popup_buffer.append( " " );
4504 _popup_buffer.append( "[" );
4506 for( final String syn : tax.getSynonyms() ) {
4507 if ( !ForesterUtil.isEmpty( syn ) ) {
4509 _popup_buffer.append( syn );
4510 if ( counter < tax.getSynonyms().size() ) {
4511 _popup_buffer.append( ", " );
4516 _popup_buffer.append( "]" );
4519 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
4520 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
4521 _popup_buffer.append( "[" );
4522 _popup_buffer.append( tax.getIdentifier().getProvider() );
4523 _popup_buffer.append( "] " );
4525 _popup_buffer.append( tax.getIdentifier().getValue() );
4529 if ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) ) {
4531 boolean enc_data = false;
4532 if ( _popup_buffer.length() > 0 ) {
4533 _popup_buffer.append( "\n" );
4535 final Sequence seq = node.getNodeData().getSequence();
4536 if ( seq.getAccession() != null ) {
4537 _popup_buffer.append( "[" );
4538 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
4539 _popup_buffer.append( seq.getAccession().getSource() );
4540 _popup_buffer.append( ":" );
4542 _popup_buffer.append( seq.getAccession().getValue() );
4543 _popup_buffer.append( "]" );
4546 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
4548 _popup_buffer.append( " [" );
4551 _popup_buffer.append( "[" );
4553 _popup_buffer.append( seq.getSymbol() );
4554 _popup_buffer.append( "]" );
4557 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
4559 _popup_buffer.append( " " );
4561 _popup_buffer.append( seq.getName() );
4564 if ( node.getNodeData().isHasDate() ) {
4566 if ( _popup_buffer.length() > 0 ) {
4567 _popup_buffer.append( "\n" );
4569 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
4571 if ( node.getNodeData().isHasDistribution() ) {
4573 if ( _popup_buffer.length() > 0 ) {
4574 _popup_buffer.append( "\n" );
4576 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
4578 if ( node.getBranchData().isHasConfidences() ) {
4579 final List<Confidence> confs = node.getBranchData().getConfidences();
4580 for( final Confidence confidence : confs ) {
4582 if ( _popup_buffer.length() > 0 ) {
4583 _popup_buffer.append( "\n" );
4585 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
4586 _popup_buffer.append( "[" );
4587 _popup_buffer.append( confidence.getType() );
4588 _popup_buffer.append( "] " );
4591 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
4593 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4596 if ( _popup_buffer.length() > 0 ) {
4597 if ( !getConfiguration().isUseNativeUI() ) {
4599 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
4600 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
4601 if ( isInFoundNodes( node ) ) {
4602 _rollover_popup.setForeground( getTreeColorSet().getFoundColor() );
4604 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4605 _rollover_popup.setForeground( getTaxonomyBasedColor( node ) );
4608 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
4612 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
4614 _rollover_popup.setText( _popup_buffer.toString() );
4615 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
4617 e.getLocationOnScreen().x + 10,
4618 e.getLocationOnScreen().y
4620 _node_desc_popup.show();
4624 catch ( final Exception ex ) {
4629 final private void showNodeEditFrame( final PhylogenyNode n ) {
4630 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4631 // pop up edit box for single node
4632 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
4633 _node_frame_index++;
4636 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4640 final private void showNodeFrame( final PhylogenyNode n ) {
4641 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4642 // pop up edit box for single node
4643 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
4644 _node_frame_index++;
4647 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4651 final void subTree( final PhylogenyNode node ) {
4652 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4653 JOptionPane.showMessageDialog( this,
4654 "Cannot get a sub/super tree in unrooted display",
4655 "Attempt to get sub/super tree in unrooted display",
4656 JOptionPane.WARNING_MESSAGE );
4659 if ( node.isExternal() ) {
4660 JOptionPane.showMessageDialog( this,
4661 "Cannot get a subtree of a external node",
4662 "Attempt to get subtree of external node",
4663 JOptionPane.WARNING_MESSAGE );
4666 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
4667 JOptionPane.showMessageDialog( this,
4668 "Cannot get a subtree of the root node",
4669 "Attempt to get subtree of root node",
4670 JOptionPane.WARNING_MESSAGE );
4673 _nodes_in_preorder = null;
4674 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
4675 _sub_phylogenies[ _subtree_index ] = _phylogeny;
4676 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
4678 _phylogeny = subTree( node, _phylogeny );
4679 updateSubSuperTreeButton();
4681 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
4684 _main_panel.getControlPanel().showWhole();
4688 final boolean isCurrentTreeIsSubtree() {
4689 return ( _subtree_index > 0 );
4692 final private static Phylogeny subTree( final PhylogenyNode new_root, final Phylogeny source_phy ) {
4694 final Phylogeny new_phy = new Phylogeny();
4695 new_phy.setRooted( true );
4696 new_phy.setName( source_phy.getName() );
4697 new_phy.setDescription( source_phy.getDescription() );
4698 new_phy.setType( source_phy.getType() );
4699 new_phy.setDistanceUnit( source_phy.getDistanceUnit() );
4700 new_phy.setConfidence( source_phy.getConfidence() );
4701 new_phy.setIdentifier( source_phy.getIdentifier() );
4702 new_phy.setRoot( new_root.copyNodeDataShallow() );
4704 for( final PhylogenyNode n : new_root.getDescendants() ) {
4705 new_phy.getRoot().setChildNode( i++, n );
4710 final void superTree() {
4711 _nodes_in_preorder = null;
4712 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
4713 for( final PhylogenyNode n : temp_root.getDescendants() ) {
4714 n.setParent( temp_root );
4716 _sub_phylogenies[ _subtree_index ] = null;
4717 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
4718 _phylogeny = _sub_phylogenies[ --_subtree_index ];
4719 updateSubSuperTreeButton();
4722 final void swap( final PhylogenyNode node ) {
4723 if ( !node.isExternal() ) {
4724 _phylogeny.swapChildren( node );
4725 _nodes_in_preorder = null;
4730 final private void switchDisplaygetPhylogenyGraphicsType() {
4731 switch ( getPhylogenyGraphicsType() ) {
4733 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4734 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4737 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4738 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4741 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4742 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4745 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4746 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4749 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4750 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4753 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4754 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4757 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4758 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4761 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4762 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4765 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
4767 if ( getControlPanel().getDynamicallyHideData() != null ) {
4768 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4769 getControlPanel().getDynamicallyHideData().setEnabled( false );
4772 getControlPanel().getDynamicallyHideData().setEnabled( true );
4775 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4776 getControlPanel().setDrawPhylogramEnabled( true );
4779 getControlPanel().setDrawPhylogramEnabled( false );
4781 if ( getMainPanel().getMainFrame() == null ) {
4782 // Must be "E" applet version.
4783 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
4784 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4787 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4791 final void taxColor() {
4792 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4796 Util.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
4797 _control_panel.setColorBranches( true );
4798 if ( _control_panel.getColorBranchesCb() != null ) {
4799 _control_panel.getColorBranchesCb().setSelected( true );
4805 final void updateOvSettings() {
4806 switch ( getOptions().getOvPlacement() ) {
4808 setOvXPosition( OV_BORDER );
4809 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
4810 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
4813 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
4814 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
4815 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
4818 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
4819 setOvYPosition( OV_BORDER );
4820 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
4823 setOvXPosition( OV_BORDER );
4824 setOvYPosition( OV_BORDER );
4825 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
4830 final void updateOvSizes() {
4831 if ( ( getWidth() > 1.05 * getVisibleRect().width ) || ( getHeight() > 1.05 * getVisibleRect().height ) ) {
4833 float l = getLongestExtNodeInfo();
4834 final float w_ratio = getOvMaxWidth() / getWidth();
4836 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4837 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
4839 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4840 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
4843 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
4845 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
4846 if ( ov_xdist < 0.0 ) {
4849 if ( ydist < 0.0 ) {
4852 setOvXDistance( ov_xdist );
4853 final double height = _phylogeny.getHeight();
4855 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
4856 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4859 setOvXcorrectionFactor( 0 );
4867 final void updateSubSuperTreeButton() {
4868 if ( _subtree_index < 1 ) {
4869 getControlPanel().deactivateButtonToReturnToSuperTree();
4872 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
4876 final void zoomInDomainStructure() {
4877 if ( _domain_structure_width < 2000 ) {
4878 _domain_structure_width *= 1.2;
4882 final void zoomOutDomainStructure() {
4883 if ( _domain_structure_width > 20 ) {
4884 _domain_structure_width *= 0.8;
4888 final private static void drawString( final int i, final double x, final double y, final Graphics2D g ) {
4889 g.drawString( String.valueOf( i ), ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
4892 final private static void drawString( final String str, final double x, final double y, final Graphics2D g ) {
4893 g.drawString( str, ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
4896 final private static boolean isSequenceEmpty( final Sequence seq ) {
4897 return ( seq.getAccession() == null ) && ForesterUtil.isEmpty( seq.getName() )
4898 && ForesterUtil.isEmpty( seq.getSymbol() );
4901 final private static boolean isTaxonomyEmpty( final Taxonomy tax ) {
4902 return ( ( tax.getIdentifier() == null ) && ForesterUtil.isEmpty( tax.getTaxonomyCode() )
4903 && ForesterUtil.isEmpty( tax.getCommonName() ) && ForesterUtil.isEmpty( tax.getScientificName() ) && tax
4904 .getSynonyms().isEmpty() );
4907 final private static boolean plusPressed( final int key_code ) {
4908 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
4909 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
4912 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
4913 _statistics_for_vector_data = statistics_for_expression_values;
4916 DescriptiveStatistics getStatisticsForExpressionValues() {
4917 return _statistics_for_vector_data;
4920 final private class SubtreeColorizationActionListener implements ActionListener {
4922 JColorChooser _chooser;
4923 PhylogenyNode _node;
4925 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
4931 public void actionPerformed( final ActionEvent e ) {
4932 final Color c = _chooser.getColor();
4934 colorizeSubtree( c, _node );
4939 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
4940 getMainPanel().setImageMap( image_map );
4943 public synchronized Hashtable<String, BufferedImage> getImageMap() {
4944 return getMainPanel().getImageMap();