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 BOX_SIZE = 4;
140 private final static int HALF_BOX_SIZE = TreePanel.BOX_SIZE / 2;
141 private final static int MAX_SUBTREES = 100;
142 private final static int MAX_NODE_FRAMES = 10;
143 private final static int MOVE = 20;
144 private final static NumberFormat FORMATTER_CONFIDENCE;
145 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
146 private final static int WIGGLE = 2;
147 private final static int HALF_BOX_SIZE_PLUS_WIGGLE = HALF_BOX_SIZE + WIGGLE;
148 private final static int LIMIT_FOR_HQ_RENDERING = 1000;
149 private final static int CONFIDENCE_LEFT_MARGIN = 4;
150 // TODO "rendering_hints" was static before. Need to make sure everything is OK with it not
151 // being static anymore (02/20/2009).
152 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
153 RenderingHints.VALUE_RENDER_DEFAULT );
154 private File _treefile = null;
155 private Configuration _configuration = null;
156 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
157 private int _node_frame_index = 0;
158 private Phylogeny _phylogeny = null;
159 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
160 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
161 private int _subtree_index = 0;
162 private MainPanel _main_panel = null;
163 private Set<Integer> _found_nodes = null;
164 private PhylogenyNode _highlight_node = null;
165 private JPopupMenu _node_popup_menu = null;
166 private JMenuItem _node_popup_menu_items[] = null;
167 private int _longest_ext_node_info = 0;
168 private float _x_correction_factor = 0.0f;
169 private float _ov_x_correction_factor = 0.0f;
170 private float _x_distance = 0.0f;
171 private float _y_distance = 0.0f;
172 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
173 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
174 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
175 private float _last_drag_point_x = 0;
176 private float _last_drag_point_y = 0;
177 private ControlPanel _control_panel = null;
178 private int _external_node_index = 0;
179 private final Polygon _polygon = new Polygon();
180 private final StringBuilder _sb = new StringBuilder();
181 private JColorChooser _color_chooser = null;
182 private double _scale_distance = 0.0;
183 private String _scale_label = null;
184 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
185 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
186 private final Line2D _line = new Line2D.Float();
187 private final Ellipse2D _ellipse = new Ellipse2D.Float();
188 private final Rectangle2D _rectangle = new Rectangle2D.Float();
189 private Options _options = null;
190 private float _ov_max_width = 0;
191 private float _ov_max_height = 0;
192 private int _ov_x_position = 0;
193 private int _ov_y_position = 0;
194 private int _ov_y_start = 0;
195 private float _ov_y_distance = 0;
196 private float _ov_x_distance = 0;
197 private boolean _ov_on = false;
198 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
199 private float _urt_factor = 1;
200 private float _urt_factor_ov = 1;
201 private final boolean _phy_has_branch_lengths;
202 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
203 private boolean _in_ov_rect = false;
204 private boolean _in_ov = false;
205 private final Rectangle _ov_virtual_rectangle = new Rectangle();
206 final private static double _180_OVER_PI = 180.0 / Math.PI;
207 private static final float ROUNDED_D = 8;
208 private int _circ_max_depth;
209 private int _circ_num_ext_nodes;
210 private PhylogenyNode _root;
211 final private Arc2D _arc = new Arc2D.Double();
212 final private HashMap<Integer, Double> _urt_nodeid_angle_map = new HashMap<Integer, Double>();
213 final private HashMap<Integer, Integer> _urt_nodeid_index_map = new HashMap<Integer, Integer>();
214 HashMap<Integer, Short> _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
215 private AffineTransform _at;
216 private double _max_distance_to_root = -1;
217 private int _dynamic_hiding_factor = 0;
218 private boolean _edited = false;
219 private Popup _node_desc_popup;
220 private JTextArea _rollover_popup;
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 );
270 // if ( !_phylogeny.isEmpty() ) {
271 _phylogeny.recalculateNumberOfExternalDescendants( true );
272 checkForVectorProperties( _phylogeny );
274 setBackground( getTreeColorSet().getBackgroundColor() );
275 final MouseListener mouse_listener = new MouseListener( this );
276 addMouseListener( mouse_listener );
277 addMouseMotionListener( mouse_listener );
278 addMouseWheelListener( this );
279 calculateScaleDistance();
280 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
281 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
282 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
285 public void checkForVectorProperties( final Phylogeny phy ) {
286 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
287 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
288 final PhylogenyNode node = iter.next();
289 if ( node.getNodeData().getProperties() != null ) {
290 final PropertiesMap pm = node.getNodeData().getProperties();
291 final double[] vector = new double[ pm.getProperties().size() ];
293 for( final String ref : pm.getProperties().keySet() ) {
294 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
295 final Property p = pm.getProperty( ref );
296 final String value_str = p.getValue();
297 final String index_str = ref
298 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
301 d = Double.parseDouble( value_str );
303 catch ( final NumberFormatException e ) {
304 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
305 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
310 i = Integer.parseInt( index_str );
312 catch ( final NumberFormatException e ) {
313 JOptionPane.showMessageDialog( this,
314 "Could not parse \"" + index_str
315 + "\" into index for vector data",
316 "Problem with Vector Data",
317 JOptionPane.ERROR_MESSAGE );
321 JOptionPane.showMessageDialog( this,
322 "Attempt to use negative index for vector data",
323 "Problem with Vector Data",
324 JOptionPane.ERROR_MESSAGE );
332 final List<Double> vector_l = new ArrayList<Double>( counter );
333 for( int i = 0; i < counter; ++i ) {
334 vector_l.add( vector[ i ] );
336 node.getNodeData().setVector( vector_l );
339 if ( stats.getN() > 0 ) {
340 _statistics_for_vector_data = stats;
344 final public void actionPerformed( final ActionEvent e ) {
346 boolean done = false;
347 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
348 for( index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
349 // NOTE: index corresponds to the indices of click-to options
350 // in the control panel.
351 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
352 // Set this as the new default click-to action
353 _main_panel.getControlPanel().setClickToAction( index );
354 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
355 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
356 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
361 requestFocusInWindow();
364 final private void addEmptyNode( final PhylogenyNode node ) {
365 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
366 errorMessageNoCutCopyPasteInUnrootedDisplay();
369 final String label = getASimpleTextRepresentationOfANode( node );
371 if ( ForesterUtil.isEmpty( label ) ) {
372 msg = "How to add the new, empty node?";
375 msg = "How to add the new, empty node to node" + label + "?";
377 final Object[] options = { "As sibling", "As descendant", "Cancel" };
378 final int r = JOptionPane.showOptionDialog( this,
380 "Addition of Empty New Node",
381 JOptionPane.CLOSED_OPTION,
382 JOptionPane.QUESTION_MESSAGE,
386 boolean add_as_sibling = true;
388 add_as_sibling = false;
393 final Phylogeny phy = new Phylogeny();
394 phy.setRoot( new PhylogenyNode() );
395 phy.setRooted( true );
396 if ( add_as_sibling ) {
397 if ( node.isRoot() ) {
398 JOptionPane.showMessageDialog( this,
399 "Cannot add sibling to root",
400 "Attempt to add sibling to root",
401 JOptionPane.ERROR_MESSAGE );
404 phy.addAsSibling( node );
407 phy.addAsChild( node );
409 _nodes_in_preorder = null;
410 _phylogeny.externalNodesHaveChanged();
411 _phylogeny.hashIDs();
412 _phylogeny.recalculateNumberOfExternalDescendants( true );
413 resetNodeIdToDistToLeafMap();
418 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
419 final boolean is_vertical,
421 final boolean to_pdf,
422 final boolean to_graphics_file ) {
423 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
424 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
425 g.setColor( Color.BLACK );
427 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
428 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
429 && ( getCutOrCopiedTree() != null )
430 && ( getCopiedAndPastedNodes() != null )
432 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
433 g.setColor( getTreeColorSet().getFoundColor() );
435 else if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
436 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
439 g.setColor( getTreeColorSet().getBranchColorForPdf() );
442 g.setColor( getTreeColorSet().getBranchColor() );
446 final void assignGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node, final Graphics g ) {
447 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
448 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
451 g.setColor( getTreeColorSet().getBranchColor() );
455 final private void blast( final PhylogenyNode node ) {
456 if ( !isCanBlast( node ) ) {
457 JOptionPane.showMessageDialog( this,
458 "No sequence information present",
460 JOptionPane.WARNING_MESSAGE );
463 if ( node.getNodeData().isHasSequence() ) {
465 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) {
466 name = node.getNodeData().getSequence().getName();
468 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) {
469 name = node.getNodeData().getSequence().getSymbol();
471 else if ( node.getNodeData().getSequence().getAccession() != null ) {
472 name = node.getNodeData().getSequence().getAccession().getValue();
474 if ( !ForesterUtil.isEmpty( name ) ) {
476 System.out.println( "trying: " + name );
477 final Blast s = new Blast();
480 catch ( final Exception e ) {
487 final void calcMaxDepth() {
488 if ( _phylogeny != null ) {
489 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
494 * Calculate the length of the distance between the given node and its
500 * @return the distance value
502 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
503 if ( getControlPanel().isDrawPhylogram() ) {
504 if ( node.getDistanceToParent() < 0.0 ) {
507 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
510 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
511 return getXdistance();
513 return getXdistance() * factor;
517 final private Color calculateColorForAnnotation( final PhylogenyData ann ) {
518 Color c = getTreeColorSet().getAnnotationColor();
519 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
520 c = getControlPanel().getAnnotationColors().get( ann.asSimpleText().toString() );
522 c = getTreeColorSet().getAnnotationColor();
528 final void calculateLongestExtNodeInfo() {
529 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
533 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
535 if ( node.isCollapse() ) {
538 if ( getControlPanel().isShowNodeNames() ) {
539 sum += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
541 if ( node.getNodeData().isHasSequence() ) {
542 if ( getControlPanel().isShowSequenceAcc()
543 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
544 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
548 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
549 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
551 if ( getControlPanel().isShowGeneSymbols()
552 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
553 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
555 if ( getControlPanel().isShowAnnotation()
556 && ( node.getNodeData().getSequence().getAnnotations() != null )
557 && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
558 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAnnotation( 0 )
563 if ( node.getNodeData().isHasTaxonomy() ) {
564 final Taxonomy tax = node.getNodeData().getTaxonomy();
565 if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
566 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getTaxonomyCode() + " " );
568 if ( getControlPanel().isShowTaxonomyScientificNames()
569 && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
570 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getScientificName() + " " );
572 if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
573 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getCommonName() + " ()" );
576 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
577 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters()
578 .getGainedCharactersAsStringBuffer().toString() );
580 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
581 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
582 sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() )
583 .getRenderingSize().getWidth();
585 if ( sum >= Constants.EXT_NODE_INFO_LENGTH_MAX ) {
586 setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX );
589 if ( sum > longest ) {
593 if ( longest >= Constants.EXT_NODE_INFO_LENGTH_MAX ) {
594 setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX );
597 setLongestExtNodeInfo( longest );
601 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
602 if ( getControlPanel().isDrawPhylogram() ) {
603 if ( node.getDistanceToParent() < 0.0 ) {
606 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
609 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
610 return getOvXDistance();
612 return getOvXDistance() * factor;
616 final void calculateScaleDistance() {
617 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
620 final double height = getMaxDistanceToRoot();
622 if ( ( height <= 0.5 ) ) {
623 setScaleDistance( 0.01 );
625 else if ( height <= 5.0 ) {
626 setScaleDistance( 0.1 );
628 else if ( height <= 50.0 ) {
629 setScaleDistance( 1 );
631 else if ( height <= 500.0 ) {
632 setScaleDistance( 10 );
635 setScaleDistance( 100 );
639 setScaleDistance( 0.0 );
641 String scale_label = String.valueOf( getScaleDistance() );
642 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
643 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
645 setScaleLabel( scale_label );
648 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
649 String species = tax.getTaxonomyCode();
650 if ( ForesterUtil.isEmpty( species ) ) {
651 species = tax.getScientificName();
652 if ( ForesterUtil.isEmpty( species ) ) {
653 species = tax.getCommonName();
656 if ( ForesterUtil.isEmpty( species ) ) {
657 return getTreeColorSet().getTaxonomyColor();
659 // Look in species hash
660 Color c = getControlPanel().getSpeciesColors().get( species );
662 c = Util.calculateColorFromString( species );
663 getControlPanel().getSpeciesColors().put( species, c );
668 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
669 JOptionPane.showMessageDialog( this,
670 "Cannot launch web browser for " + type_type + " data of this node",
671 "Cannot launch web browser",
672 JOptionPane.WARNING_MESSAGE );
676 * Collapse the tree from the given node
681 final void collapse( final PhylogenyNode node ) {
682 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
683 JOptionPane.showMessageDialog( this,
684 "Cannot collapse in unrooted display type",
685 "Attempt to collapse in unrooted display",
686 JOptionPane.WARNING_MESSAGE );
689 if ( !node.isExternal() && !node.isRoot() ) {
690 final boolean collapse = !node.isCollapse();
691 Util.collapseSubtree( node, collapse );
692 _phylogeny.recalculateNumberOfExternalDescendants( true );
693 resetNodeIdToDistToLeafMap();
694 calculateLongestExtNodeInfo();
695 _nodes_in_preorder = null;
696 resetPreferredSize();
698 _main_panel.adjustJScrollPane();
703 final void collapseSpeciesSpecificSubtrees() {
704 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
708 Util.collapseSpeciesSpecificSubtrees( _phylogeny );
709 _phylogeny.recalculateNumberOfExternalDescendants( true );
710 resetNodeIdToDistToLeafMap();
711 calculateLongestExtNodeInfo();
712 _nodes_in_preorder = null;
713 resetPreferredSize();
714 _main_panel.adjustJScrollPane();
719 final private void colorizeSubtree( final Color c, final PhylogenyNode node ) {
720 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
721 JOptionPane.showMessageDialog( this,
722 "Cannot colorize subtree in unrooted display type",
723 "Attempt to colorize subtree in unrooted display",
724 JOptionPane.WARNING_MESSAGE );
727 _control_panel.setColorBranches( true );
728 if ( _control_panel.getColorBranchesCb() != null ) {
729 _control_panel.getColorBranchesCb().setSelected( true );
731 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
732 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
737 final private void colorSubtree( final PhylogenyNode node ) {
738 Color intitial_color = null;
739 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null )
740 && ( ( ( !node.isRoot() && ( node.getParent().getNumberOfDescendants() < 3 ) ) ) || ( node.isRoot() ) ) ) {
741 intitial_color = PhylogenyMethods.getBranchColorValue( node );
744 intitial_color = getTreeColorSet().getBranchColor();
746 _color_chooser.setColor( intitial_color );
747 _color_chooser.setPreviewPanel( new JPanel() );
748 final JDialog dialog = JColorChooser
750 "Subtree colorization",
753 new SubtreeColorizationActionListener( _color_chooser, node ),
755 dialog.setVisible( true );
758 final void confColor() {
759 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
763 Util.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
764 _control_panel.setColorBranches( true );
765 if ( _control_panel.getColorBranchesCb() != null ) {
766 _control_panel.getColorBranchesCb().setSelected( true );
772 final private void copySubtree( final PhylogenyNode node ) {
773 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
774 errorMessageNoCutCopyPasteInUnrootedDisplay();
777 _nodes_in_preorder = null;
778 setCutOrCopiedTree( _phylogeny.copy( node ) );
779 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
780 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
781 for( final PhylogenyNode n : nodes ) {
782 node_ids.add( n.getId() );
784 node_ids.add( node.getId() );
785 setCopiedAndPastedNodes( node_ids );
789 final private void cutSubtree( final PhylogenyNode node ) {
790 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
791 errorMessageNoCutCopyPasteInUnrootedDisplay();
794 if ( node.isRoot() ) {
795 JOptionPane.showMessageDialog( this,
796 "Cannot cut entire tree as subtree",
797 "Attempt to cut entire tree",
798 JOptionPane.ERROR_MESSAGE );
801 final String label = getASimpleTextRepresentationOfANode( node );
802 final int r = JOptionPane.showConfirmDialog( null,
803 "Cut subtree" + label + "?",
804 "Confirm Cutting of Subtree",
805 JOptionPane.YES_NO_OPTION );
806 if ( r != JOptionPane.OK_OPTION ) {
809 _nodes_in_preorder = null;
810 setCopiedAndPastedNodes( null );
811 setCutOrCopiedTree( _phylogeny.copy( node ) );
812 _phylogeny.deleteSubtree( node, true );
813 _phylogeny.hashIDs();
814 _phylogeny.recalculateNumberOfExternalDescendants( true );
815 resetNodeIdToDistToLeafMap();
820 final private void cycleColors() {
821 getMainPanel().getTreeColorSet().cycleColorScheme();
822 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
823 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
827 final void decreaseDomainStructureEvalueThreshold() {
828 if ( _domain_structure_e_value_thr_exp > -20 ) {
829 _domain_structure_e_value_thr_exp -= 1;
833 final private void decreaseOvSize() {
834 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
835 setOvMaxWidth( getOvMaxWidth() - 5 );
836 setOvMaxHeight( getOvMaxHeight() - 5 );
838 getControlPanel().displayedPhylogenyMightHaveChanged( false );
842 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
843 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
844 errorMessageNoCutCopyPasteInUnrootedDisplay();
847 if ( node.isRoot() ) {
848 JOptionPane.showMessageDialog( this,
849 "Cannot delete entire tree",
850 "Attempt to delete entire tree",
851 JOptionPane.ERROR_MESSAGE );
854 final String label = getASimpleTextRepresentationOfANode( node );
855 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
856 final int r = JOptionPane.showOptionDialog( this,
857 "Delete" + label + "?",
858 "Delete Node/Subtree",
859 JOptionPane.CLOSED_OPTION,
860 JOptionPane.QUESTION_MESSAGE,
864 _nodes_in_preorder = null;
865 boolean node_only = true;
873 PhylogenyMethods.removeNode( node, _phylogeny );
876 _phylogeny.deleteSubtree( node, true );
878 _phylogeny.externalNodesHaveChanged();
879 _phylogeny.hashIDs();
880 _phylogeny.recalculateNumberOfExternalDescendants( true );
881 resetNodeIdToDistToLeafMap();
886 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
887 makePopupMenus( node );
888 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
889 _node_popup_menu.show( this, x, y );
892 final private void drawArc( final double x,
896 final double start_angle,
897 final double arc_angle,
898 final Graphics2D g ) {
899 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
903 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
904 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
907 _line.setLine( x1, y1, x2, y2 );
911 final private void drawOval( final double x,
915 final Graphics2D g ) {
916 _ellipse.setFrame( x, y, width, heigth );
920 final private void drawOvalFilled( final double x,
924 final Graphics2D g ) {
925 _ellipse.setFrame( x, y, width, heigth );
929 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
930 _rectangle.setFrame( x, y, width, heigth );
931 g.draw( _rectangle );
934 final private void drawRectFilled( final double x,
938 final Graphics2D g ) {
939 _rectangle.setFrame( x, y, width, heigth );
940 g.fill( _rectangle );
943 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
944 JOptionPane.showMessageDialog( this,
945 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
946 "Attempt to cut/copy/paste/add/delete in unrooted display",
947 JOptionPane.ERROR_MESSAGE );
951 * Find the node, if any, at the given location
955 * @return pointer to the node at x,y, null if not found
957 final PhylogenyNode findNode( final int x, final int y ) {
958 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
961 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
962 final PhylogenyNode node = iter.next();
963 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
964 && ( ( node.getXcoord() - HALF_BOX_SIZE_PLUS_WIGGLE ) <= x )
965 && ( ( node.getXcoord() + HALF_BOX_SIZE_PLUS_WIGGLE ) >= x )
966 && ( ( node.getYcoord() - HALF_BOX_SIZE_PLUS_WIGGLE ) <= y )
967 && ( ( node.getYcoord() + HALF_BOX_SIZE_PLUS_WIGGLE ) >= y ) ) {
974 final private String getASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
975 final String tax = PhylogenyMethods.getSpecies( node );
976 String label = node.getName();
977 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
978 label = label + " " + tax;
980 else if ( !ForesterUtil.isEmpty( tax ) ) {
986 if ( !ForesterUtil.isEmpty( label ) ) {
987 label = " [" + label + "]";
992 final Configuration getConfiguration() {
993 return _configuration;
996 final ControlPanel getControlPanel() {
997 return _control_panel;
1000 final private Set<Integer> getCopiedAndPastedNodes() {
1001 return getMainPanel().getCopiedAndPastedNodes();
1004 final private Phylogeny getCutOrCopiedTree() {
1005 return getMainPanel().getCutOrCopiedTree();
1008 final int getDomainStructureEvalueThreshold() {
1009 return _domain_structure_e_value_thr_exp;
1012 final Set<Integer> getFoundNodes() {
1013 return _found_nodes;
1016 final private float getLastDragPointX() {
1017 return _last_drag_point_x;
1020 final private float getLastDragPointY() {
1021 return _last_drag_point_y;
1024 final int getLongestExtNodeInfo() {
1025 return _longest_ext_node_info;
1028 final public MainPanel getMainPanel() {
1032 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
1033 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
1034 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
1035 _nodeid_dist_to_leaf.put( node.getId(), m );
1039 return _nodeid_dist_to_leaf.get( node.getId() );
1043 final private double getMaxDistanceToRoot() {
1044 if ( _max_distance_to_root < 0 ) {
1045 recalculateMaxDistanceToRoot();
1047 return _max_distance_to_root;
1050 final Options getOptions() {
1051 if ( _options == null ) {
1052 _options = getControlPanel().getOptions();
1057 final private float getOvMaxHeight() {
1058 return _ov_max_height;
1061 final private float getOvMaxWidth() {
1062 return _ov_max_width;
1065 final Rectangle2D getOvRectangle() {
1066 return _ov_rectangle;
1069 final Rectangle getOvVirtualRectangle() {
1070 return _ov_virtual_rectangle;
1073 final private float getOvXcorrectionFactor() {
1074 return _ov_x_correction_factor;
1077 final private float getOvXDistance() {
1078 return _ov_x_distance;
1081 final private int getOvXPosition() {
1082 return _ov_x_position;
1085 final private float getOvYDistance() {
1086 return _ov_y_distance;
1089 final private int getOvYPosition() {
1090 return _ov_y_position;
1093 final private int getOvYStart() {
1098 * Get a pointer to the phylogeny
1100 * @return a pointer to the phylogeny
1102 public final Phylogeny getPhylogeny() {
1106 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
1107 return _graphics_type;
1110 final private double getScaleDistance() {
1111 return _scale_distance;
1114 final private String getScaleLabel() {
1115 return _scale_label;
1118 final double getStartingAngle() {
1119 return _urt_starting_angle;
1123 * Find a color for this species name.
1126 * @return the species color
1128 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
1129 if ( node.getNodeData().isHasTaxonomy() ) {
1130 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
1132 // return non-colorized color
1133 return getTreeColorSet().getTaxonomyColor();
1137 * @return pointer to colorset for tree drawing
1139 final TreeColorSet getTreeColorSet() {
1140 return getMainPanel().getTreeColorSet();
1143 final File getTreeFile() {
1147 final private TreeFontSet getTreeFontSet() {
1148 return getMainPanel().getTreeFontSet();
1151 final private float getUrtFactor() {
1155 final private float getUrtFactorOv() {
1156 return _urt_factor_ov;
1159 final float getXcorrectionFactor() {
1160 return _x_correction_factor;
1163 final float getXdistance() {
1167 final float getYdistance() {
1171 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
1174 showNodeFrame( node );
1189 colorSubtree( node );
1204 copySubtree( node );
1207 pasteSubtree( node );
1209 case DELETE_NODE_OR_SUBTREE:
1210 deleteNodeOrSubtree( node );
1213 addEmptyNode( node );
1215 case EDIT_NODE_DATA:
1216 showNodeEditFrame( node );
1219 throw new IllegalArgumentException( "unknown action: " + action );
1223 final void increaseDomainStructureEvalueThreshold() {
1224 if ( _domain_structure_e_value_thr_exp < 3 ) {
1225 _domain_structure_e_value_thr_exp += 1;
1229 final private void increaseOvSize() {
1230 if ( ( getOvMaxWidth() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 )
1231 && ( getOvMaxHeight() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
1232 .getHeight() / 2 ) ) {
1233 setOvMaxWidth( getOvMaxWidth() + 5 );
1234 setOvMaxHeight( getOvMaxHeight() + 5 );
1236 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1240 final void inferCommonPartOfScientificNames() {
1241 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1245 Util.inferCommonPartOfScientificNames( _phylogeny );
1250 final private void init() {
1251 _color_chooser = new JColorChooser();
1252 _rollover_popup = new JTextArea();
1253 _rollover_popup.setFont( POPUP_FONT );
1254 resetNodeIdToDistToLeafMap();
1256 setTreeFile( null );
1258 initializeOvSettings();
1259 setStartingAngle( TWO_PI * 3 / 4 );
1260 final ImageLoader il = new ImageLoader( this );
1261 new Thread( il ).start();
1264 final private void initializeOvSettings() {
1265 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
1266 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
1269 final void initNodeData() {
1270 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1273 double max_original_domain_structure_width = 0.0;
1274 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1275 if ( node.getNodeData().isHasSequence()
1276 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1277 RenderableDomainArchitecture rds = null;
1278 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
1279 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
1280 getConfiguration() );
1281 node.getNodeData().getSequence().setDomainArchitecture( rds );
1284 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1286 if ( getControlPanel().isShowDomainArchitectures() ) {
1287 final double dsw = rds.getOriginalSize().getWidth();
1288 if ( dsw > max_original_domain_structure_width ) {
1289 max_original_domain_structure_width = dsw;
1294 if ( getControlPanel().isShowDomainArchitectures() ) {
1295 final double ds_factor_width = _domain_structure_width / max_original_domain_structure_width;
1296 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1297 if ( node.getNodeData().isHasSequence()
1298 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1299 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1300 .getSequence().getDomainArchitecture();
1301 rds.setRenderingFactorWidth( ds_factor_width );
1302 rds.setParameter( _domain_structure_e_value_thr_exp );
1308 final boolean inOv( final MouseEvent e ) {
1309 return ( ( e.getX() > getVisibleRect().x + getOvXPosition() + 1 )
1310 && ( e.getX() < getVisibleRect().x + getOvXPosition() + getOvMaxWidth() - 1 )
1311 && ( e.getY() > getVisibleRect().y + getOvYPosition() + 1 ) && ( e.getY() < getVisibleRect().y
1312 + getOvYPosition() + getOvMaxHeight() - 1 ) );
1315 final boolean inOvRectangle( final MouseEvent e ) {
1316 return ( ( e.getX() >= getOvRectangle().getX() - 1 )
1317 && ( e.getX() <= getOvRectangle().getX() + getOvRectangle().getWidth() + 1 )
1318 && ( e.getY() >= getOvRectangle().getY() - 1 ) && ( e.getY() <= getOvRectangle().getY()
1319 + getOvRectangle().getHeight() + 1 ) );
1322 final private boolean inOvVirtualRectangle( final int x, final int y ) {
1323 return ( ( x >= getOvVirtualRectangle().x - 1 )
1324 && ( x <= getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 )
1325 && ( y >= getOvVirtualRectangle().y - 1 ) && ( y <= getOvVirtualRectangle().y
1326 + getOvVirtualRectangle().height + 1 ) );
1329 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
1330 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
1333 final boolean isApplet() {
1334 return getMainPanel() instanceof MainPanelApplets;
1337 final private boolean isCanBlast( final PhylogenyNode node ) {
1338 return ( node.getNodeData().isHasSequence() && ( ( ( node.getNodeData().getSequence().getAccession() != null ) && !ForesterUtil
1339 .isEmpty( node.getNodeData().getSequence().getAccession().getValue() ) )
1340 || !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) || !ForesterUtil.isEmpty( node
1341 .getNodeData().getSequence().getSymbol() ) ) );
1344 final boolean isCanCollapse() {
1345 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1348 final boolean isCanColorSubtree() {
1349 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1352 final boolean isCanCopy() {
1353 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1356 final boolean isCanCut( final PhylogenyNode node ) {
1357 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1361 final boolean isCanDelete() {
1362 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1365 final private boolean isCanOpenSeqWeb( final PhylogenyNode node ) {
1366 if ( node.getNodeData().isHasSequence()
1367 && ( node.getNodeData().getSequence().getAccession() != null )
1368 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
1369 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
1370 && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource()
1371 .toLowerCase() ) ) {
1377 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
1378 if ( node.getNodeData().isHasTaxonomy()
1379 && ( ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
1380 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getProvider() )
1381 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && getConfiguration()
1382 .isHasWebLink( node.getNodeData().getTaxonomy().getIdentifier().getProvider().toLowerCase() ) )
1383 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
1384 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
1385 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
1386 .getNodeData().getTaxonomy().getIdentifier() != null )
1387 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && node
1388 .getNodeData().getTaxonomy().getIdentifier().getValue().startsWith( "http://" ) ) ) ) {
1396 final boolean isCanPaste() {
1397 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1398 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1401 final boolean isCanReroot() {
1402 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1405 final boolean isCanSubtree( final PhylogenyNode node ) {
1406 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1407 .isRoot() || ( _subtree_index > 0 ) ) );
1410 final boolean isEdited() {
1414 final private boolean isInFoundNodes( final PhylogenyNode node ) {
1415 return ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) );
1418 final private boolean isInOv() {
1422 final boolean isInOvRect() {
1426 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
1428 if ( getControlPanel().isShowTaxonomyImages() ) {
1429 y_dist = 40 + ( int ) getYdistance();
1431 return ( ( node.getYcoord() < getVisibleRect().getMinY() - y_dist )
1432 || ( node.getYcoord() > getVisibleRect().getMaxY() + y_dist ) || ( ( node.getParent() != null ) && ( node
1433 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
1436 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
1437 return ( ( node.getYcoord() < getVisibleRect().getMinY() - 20 )
1438 || ( node.getYcoord() > getVisibleRect().getMaxY() + 20 )
1439 || ( node.getXcoord() < getVisibleRect().getMinX() - 20 ) || ( node.getXcoord() > getVisibleRect()
1440 .getMaxX() + 20 ) );
1443 final private boolean isNonLinedUpCladogram() {
1444 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
1447 final boolean isOvOn() {
1451 final boolean isPhyHasBranchLengths() {
1452 return _phy_has_branch_lengths;
1455 final private boolean isUniformBranchLengthsForCladogram() {
1456 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
1459 final private void keyPressedCalls( final KeyEvent e ) {
1460 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
1461 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
1462 if ( !isInOvRect() ) {
1463 setInOvRect( true );
1466 else if ( isInOvRect() ) {
1467 setInOvRect( false );
1470 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
1471 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1472 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
1473 getMainPanel().getTreeFontSet().mediumFonts();
1474 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1476 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1477 getMainPanel().getTreeFontSet().decreaseFontSize();
1478 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1480 else if ( plusPressed( e.getKeyCode() ) ) {
1481 getMainPanel().getTreeFontSet().increaseFontSize();
1482 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1486 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1487 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
1488 getControlPanel().showWhole();
1490 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
1491 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
1492 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
1493 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
1494 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1495 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1497 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1498 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1499 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1501 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1502 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1503 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1504 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1506 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1507 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1508 Constants.WHEEL_ZOOM_IN_FACTOR );
1509 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1516 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1519 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1523 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1527 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1528 scroll_position.x = scroll_position.x + dx;
1529 scroll_position.y = scroll_position.y + dy;
1530 if ( scroll_position.x <= 0 ) {
1531 scroll_position.x = 0;
1534 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1535 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1536 if ( scroll_position.x >= max_x ) {
1537 scroll_position.x = max_x;
1540 if ( scroll_position.y <= 0 ) {
1541 scroll_position.y = 0;
1544 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1545 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1546 if ( scroll_position.y >= max_y ) {
1547 scroll_position.y = max_y;
1551 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1554 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1555 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1556 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1557 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1558 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1560 else if ( plusPressed( e.getKeyCode() ) ) {
1561 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1562 Constants.WHEEL_ZOOM_IN_FACTOR );
1563 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1564 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1566 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
1567 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1568 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1569 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1570 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1573 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
1574 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1575 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1576 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1577 if ( getStartingAngle() < 0 ) {
1578 setStartingAngle( TWO_PI + getStartingAngle() );
1580 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1583 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
1584 boolean selected = false;
1585 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
1586 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1590 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1592 if ( getMainPanel().getMainFrame() == null ) {
1593 // Must be "E" applet version.
1594 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1595 if ( ae.getlabelDirectionCbmi() != null ) {
1596 ae.getlabelDirectionCbmi().setSelected( selected );
1600 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
1604 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
1605 switchDisplaygetPhylogenyGraphicsType();
1608 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
1612 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
1613 MainFrame.cycleOverview( getOptions(), this );
1616 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
1619 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
1626 final private void makePopupMenus( final PhylogenyNode node ) {
1627 _node_popup_menu = new JPopupMenu();
1628 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
1629 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
1630 for( int i = 0; i < clickto_names.size(); i++ ) {
1631 final String title = clickto_names.get( i );
1632 _node_popup_menu_items[ i ] = new JMenuItem( title );
1633 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
1634 _node_popup_menu_items[ i ].setEnabled( isCanOpenSeqWeb( node ) );
1636 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
1637 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
1639 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
1640 if ( Constants.__RELEASE || Constants.__SNAPSHOT_RELEASE ) {
1643 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
1645 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
1646 if ( !getOptions().isEditable() ) {
1649 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
1651 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
1652 if ( !getOptions().isEditable() ) {
1655 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
1657 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
1658 if ( !getOptions().isEditable() ) {
1661 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
1663 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
1664 if ( !getOptions().isEditable() ) {
1667 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
1669 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
1670 if ( !getOptions().isEditable() ) {
1674 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
1675 if ( !getOptions().isEditable() ) {
1679 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
1680 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
1682 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
1683 _node_popup_menu_items[ i ].setEnabled( isCanCollapse() );
1685 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
1686 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
1688 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
1689 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
1691 _node_popup_menu_items[ i ].addActionListener( this );
1692 _node_popup_menu.add( _node_popup_menu_items[ i ] );
1696 final void midpointRoot() {
1697 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1700 if ( !_phylogeny.isRerootable() ) {
1701 JOptionPane.showMessageDialog( this,
1702 "This is not rerootable",
1704 JOptionPane.WARNING_MESSAGE );
1707 _nodes_in_preorder = null;
1709 PhylogenyMethods.midpointRoot( _phylogeny );
1710 resetNodeIdToDistToLeafMap();
1715 final void mouseClicked( final MouseEvent e ) {
1716 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1717 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1718 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1719 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - getOvRectangle().getWidth() / 2.0 )
1721 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - getOvRectangle().getHeight() / 2.0 )
1729 final double max_x = getWidth() - getVisibleRect().width;
1730 final double max_y = getHeight() - getVisibleRect().height;
1737 getMainPanel().getCurrentScrollPane().getViewport()
1738 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1739 setInOvRect( true );
1743 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1744 if ( node != null ) {
1745 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1748 _highlight_node = node;
1749 // Check if shift key is down
1750 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1751 // Yes, so add to _found_nodes
1752 if ( getFoundNodes() == null ) {
1753 setFoundNodes( new HashSet<Integer>() );
1755 getFoundNodes().add( node.getId() );
1756 // Check if control key is down
1758 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1759 // Yes, so pop-up menu
1760 displayNodePopupMenu( node, e.getX(), e.getY() );
1761 // Handle unadorned click
1764 // Check for right mouse button
1765 if ( e.getModifiers() == 4 ) {
1766 displayNodePopupMenu( node, e.getX(), e.getY() );
1769 // if not in _found_nodes, clear _found_nodes
1770 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1775 // no node was clicked
1776 _highlight_node = null;
1782 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1783 setCursor( MOVE_CURSOR );
1784 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1785 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1786 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1787 if ( scroll_position.x < 0 ) {
1788 scroll_position.x = 0;
1791 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1792 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1793 if ( scroll_position.x > max_x ) {
1794 scroll_position.x = max_x;
1797 if ( scroll_position.y < 0 ) {
1798 scroll_position.y = 0;
1801 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1802 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1803 if ( scroll_position.y > max_y ) {
1804 scroll_position.y = max_y;
1807 if ( isOvOn() || getOptions().isShowScale() ) {
1810 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1813 final void mouseDragInOvRectangle( final MouseEvent e ) {
1814 setCursor( HAND_CURSOR );
1815 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1816 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1817 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1818 double dx = ( w_ratio * e.getX() - w_ratio * getLastDragPointX() );
1819 double dy = ( h_ratio * e.getY() - h_ratio * getLastDragPointY() );
1820 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1821 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1822 if ( scroll_position.x <= 0 ) {
1823 scroll_position.x = 0;
1827 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1828 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1829 if ( scroll_position.x >= max_x ) {
1831 scroll_position.x = max_x;
1834 if ( scroll_position.y <= 0 ) {
1836 scroll_position.y = 0;
1839 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1840 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1841 if ( scroll_position.y >= max_y ) {
1843 scroll_position.y = max_y;
1847 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1848 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1849 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1852 final void mouseMoved( final MouseEvent e ) {
1853 requestFocusInWindow();
1854 if ( getControlPanel().isNodeDescPopup() ) {
1855 if ( _node_desc_popup != null ) {
1856 _node_desc_popup.hide();
1857 _node_desc_popup = null;
1860 if ( getOptions().isShowOverview() && isOvOn() ) {
1861 if ( inOvVirtualRectangle( e ) ) {
1862 if ( !isInOvRect() ) {
1863 setInOvRect( true );
1868 if ( isInOvRect() ) {
1869 setInOvRect( false );
1874 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
1883 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1884 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
1885 // cursor is over a tree node
1886 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
1887 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
1888 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
1889 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
1890 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
1891 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
1892 setCursor( CUT_CURSOR );
1895 setCursor( HAND_CURSOR );
1896 if ( getControlPanel().isNodeDescPopup() ) {
1897 showNodeDataPopup( e, node );
1902 setCursor( ARROW_CURSOR );
1907 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
1908 setCursor( ARROW_CURSOR );
1911 final public void mouseWheelMoved( final MouseWheelEvent e ) {
1912 final int notches = e.getWheelRotation();
1913 if ( inOvVirtualRectangle( e ) ) {
1914 if ( !isInOvRect() ) {
1915 setInOvRect( true );
1920 if ( isInOvRect() ) {
1921 setInOvRect( false );
1925 if ( e.isControlDown() ) {
1926 if ( notches < 0 ) {
1927 getTreeFontSet().increaseFontSize();
1928 getControlPanel().displayedPhylogenyMightHaveChanged( true );
1931 getTreeFontSet().decreaseFontSize();
1932 getControlPanel().displayedPhylogenyMightHaveChanged( true );
1935 else if ( e.isShiftDown() ) {
1936 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1937 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1938 if ( notches < 0 ) {
1939 for( int i = 0; i < ( -notches ); ++i ) {
1940 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1941 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1945 for( int i = 0; i < notches; ++i ) {
1946 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1947 if ( getStartingAngle() < 0 ) {
1948 setStartingAngle( TWO_PI + getStartingAngle() );
1950 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1955 if ( notches < 0 ) {
1956 for( int i = 0; i < ( -notches ); ++i ) {
1957 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1958 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1962 for( int i = 0; i < notches; ++i ) {
1963 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1964 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1970 if ( notches < 0 ) {
1971 for( int i = 0; i < ( -notches ); ++i ) {
1972 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1973 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
1974 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1975 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1979 for( int i = 0; i < notches; ++i ) {
1980 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1981 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1982 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1983 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1988 requestFocusInWindow();
1992 final void multiplyUrtFactor( final float f ) {
1996 final JApplet obtainApplet() {
1997 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
2000 final private void openSeqWeb( final PhylogenyNode node ) {
2001 if ( !isCanOpenSeqWeb( node ) ) {
2002 cannotOpenBrowserWarningMessage( "sequence" );
2005 String uri_str = null;
2006 final Sequence seq = node.getNodeData().getSequence();
2007 final String source = seq.getAccession().getSource().toLowerCase();
2009 if ( source.toLowerCase().equals( "ncbi" ) ) {
2010 url = Constants.NCBI_ALL_DATABASE_SEARCH;
2013 final WebLink weblink = getConfiguration().getWebLink( source );
2014 url = weblink.getUrl().toString();
2017 uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 );
2019 catch ( final UnsupportedEncodingException e ) {
2020 Util.showErrorMessage( this, e.toString() );
2021 e.printStackTrace();
2023 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2025 JApplet applet = null;
2027 applet = obtainApplet();
2029 Util.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_seq" );
2031 catch ( final IOException e ) {
2032 Util.showErrorMessage( this, e.toString() );
2033 e.printStackTrace();
2035 catch ( final URISyntaxException e ) {
2036 Util.showErrorMessage( this, e.toString() );
2037 e.printStackTrace();
2041 cannotOpenBrowserWarningMessage( "sequence" );
2045 final private void openTaxWeb( final PhylogenyNode node ) {
2046 if ( !isCanOpenTaxWeb( node ) ) {
2047 cannotOpenBrowserWarningMessage( "taxonomic" );
2050 String uri_str = null;
2051 final Taxonomy tax = node.getNodeData().getTaxonomy();
2052 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
2053 && getConfiguration().isHasWebLink( tax.getIdentifier().getProvider().toLowerCase() ) ) {
2054 final String type = tax.getIdentifier().getProvider().toLowerCase();
2055 final WebLink weblink = getConfiguration().getWebLink( type );
2057 uri_str = weblink.getUrl() + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
2059 catch ( final UnsupportedEncodingException e ) {
2060 Util.showErrorMessage( this, e.toString() );
2061 e.printStackTrace();
2064 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2065 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
2067 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
2069 catch ( final URISyntaxException e ) {
2070 Util.showErrorMessage( this, e.toString() );
2072 e.printStackTrace();
2075 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
2077 uri_str = "http://www.eol.org/search?q="
2078 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
2080 catch ( final UnsupportedEncodingException e ) {
2081 Util.showErrorMessage( this, e.toString() );
2082 e.printStackTrace();
2085 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
2087 uri_str = "http://www.uniprot.org/taxonomy/?query="
2088 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
2090 catch ( final UnsupportedEncodingException e ) {
2091 Util.showErrorMessage( this, e.toString() );
2092 e.printStackTrace();
2095 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
2097 uri_str = "http://www.eol.org/search?q="
2098 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
2100 catch ( final UnsupportedEncodingException e ) {
2101 Util.showErrorMessage( this, e.toString() );
2102 e.printStackTrace();
2105 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2107 JApplet applet = null;
2109 applet = obtainApplet();
2111 Util.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_tax" );
2113 catch ( final IOException e ) {
2114 Util.showErrorMessage( this, e.toString() );
2115 e.printStackTrace();
2117 catch ( final URISyntaxException e ) {
2118 Util.showErrorMessage( this, e.toString() );
2119 e.printStackTrace();
2123 cannotOpenBrowserWarningMessage( "taxonomic" );
2127 final void paintBranchCircular( final PhylogenyNode p,
2128 final PhylogenyNode c,
2130 final boolean radial_labels,
2131 final boolean to_pdf,
2132 final boolean to_graphics_file ) {
2133 final double angle = _urt_nodeid_angle_map.get( c.getId() );
2134 final double root_x = _root.getXcoord();
2135 final double root_y = _root.getYcoord();
2136 final double dx = root_x - p.getXcoord();
2137 final double dy = root_y - p.getYcoord();
2138 final double parent_radius = Math.sqrt( dx * dx + dy * dy );
2139 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
2140 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
2141 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
2142 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
2143 final double r2 = 2.0 * parent_radius;
2144 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
2146 drawLine( c.getXcoord(),
2148 root_x + ( Math.cos( angle ) * parent_radius ),
2149 root_y + ( Math.sin( angle ) * parent_radius ),
2151 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c ) );
2152 if ( c.isExternal() ) {
2153 final boolean is_in_found_nodes = isInFoundNodes( c );
2154 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
2155 && ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor != 1 ) ) {
2158 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
2162 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
2163 final double angle = _urt_nodeid_angle_map.get( c.getId() );
2164 final double root_x = _root.getXSecondary();
2165 final double root_y = _root.getYSecondary();
2166 final double dx = root_x - p.getXSecondary();
2167 final double dy = root_y - p.getYSecondary();
2168 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
2169 final double parent_radius = Math.sqrt( dx * dx + dy * dy );
2170 g.setColor( getTreeColorSet().getOvColor() );
2171 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
2172 final double r2 = 2.0 * parent_radius;
2173 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
2175 drawLine( c.getXSecondary(),
2177 root_x + ( Math.cos( angle ) * parent_radius ),
2178 root_y + ( Math.sin( angle ) * parent_radius ),
2180 if ( isInFoundNodes( c ) ) {
2181 g.setColor( getTreeColorSet().getFoundColor() );
2182 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
2186 final private void paintBranchLength( final Graphics2D g,
2187 final PhylogenyNode node,
2188 final boolean to_pdf,
2189 final boolean to_graphics_file ) {
2190 g.setFont( getTreeFontSet().getSmallFont() );
2191 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2192 g.setColor( Color.BLACK );
2195 g.setColor( getTreeColorSet().getBranchLengthColor() );
2197 if ( !node.isRoot() ) {
2198 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2199 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2200 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2202 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2203 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2204 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2207 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2208 .getXcoord() + 3, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2212 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
2213 - getTreeFontSet()._small_max_descent, g );
2217 final private void paintBranchLite( final Graphics2D g,
2222 final PhylogenyNode node ) {
2223 g.setColor( getTreeColorSet().getOvColor() );
2224 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2225 drawLine( x1, y1, x2, y2, g );
2227 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2228 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2229 ( g ).draw( _quad_curve );
2231 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2232 final float dx = x2 - x1;
2233 final float dy = y2 - y1;
2234 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
2235 + ( dy * 0.8f ), x2, y2 );
2236 ( g ).draw( _cubic_curve );
2239 final float x2a = x2;
2240 final float x1a = x1;
2241 // draw the vertical line
2242 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
2243 drawLine( x1, y1, x1, y2, g );
2245 // draw the horizontal line
2246 drawLine( x1a, y2, x2a, y2, g );
2251 * Paint a branch which consists of a vertical and a horizontal bar
2252 * @param is_ind_found_nodes
2254 final private void paintBranchRectangular( final Graphics2D g,
2259 final PhylogenyNode node,
2260 final boolean to_pdf,
2261 final boolean to_graphics_file ) {
2262 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
2263 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2264 drawLine( x1, y1, x2, y2, g );
2266 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2267 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2268 g.draw( _quad_curve );
2270 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2271 final float dx = x2 - x1;
2272 final float dy = y2 - y1;
2273 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
2274 + ( dy * 0.8f ), x2, y2 );
2275 g.draw( _cubic_curve );
2280 // draw the vertical line
2281 boolean draw_horizontal = true;
2283 if ( node.isFirstChildNode() || node.isLastChildNode()
2284 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2285 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2286 boolean draw_vertical = true;
2287 final PhylogenyNode parent = node.getParent();
2288 if ( ( ( getOptions().isShowNodeBoxes() && !to_pdf && !to_graphics_file ) || ( ( getControlPanel()
2289 .isEvents() ) && ( parent != null ) && parent.isHasAssignedEvent() ) )
2290 && ( _phylogeny.isRooted() || !( ( parent != null ) && parent.isRoot() ) )
2291 && !( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() && !parent
2292 .isDuplication() ) ) {
2293 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2294 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2295 if ( Math.abs( y2 - y1 ) <= TreePanel.HALF_BOX_SIZE ) {
2296 draw_vertical = false;
2300 y1 += TreePanel.HALF_BOX_SIZE;
2304 y1 -= TreePanel.HALF_BOX_SIZE + 1;
2307 y1 -= TreePanel.HALF_BOX_SIZE;
2312 if ( ( x2 - x1 ) <= TreePanel.HALF_BOX_SIZE ) {
2313 draw_horizontal = false;
2315 else if ( !draw_vertical ) {
2316 x1a += TreePanel.HALF_BOX_SIZE;
2318 if ( ( ( x2 - x1a ) > TreePanel.HALF_BOX_SIZE )
2319 && !( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() && !node
2320 .isDuplication() ) ) {
2321 x2a -= TreePanel.HALF_BOX_SIZE;
2324 if ( draw_vertical ) {
2325 if ( !to_graphics_file
2327 && ( ( ( y2 < getVisibleRect().getMinY() - 20 ) && ( y1 < getVisibleRect().getMinY() - 20 ) ) || ( ( y2 > getVisibleRect()
2328 .getMaxY() + 20 ) && ( y1 > getVisibleRect().getMaxY() + 20 ) ) ) ) {
2332 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2333 float x2c = x1 + EURO_D;
2337 drawLine( x1, y1, x2c, y2, g );
2339 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2341 y2_r = y2 - ROUNDED_D;
2345 drawLine( x1, y1, x1, y2_r, g );
2348 y2_r = y2 + ROUNDED_D;
2352 drawLine( x1, y1, x1, y2_r, g );
2356 drawLine( x1, y1, x1, y2, g );
2361 // draw the horizontal line
2362 if ( !to_graphics_file && !to_pdf
2363 && ( ( y2 < getVisibleRect().getMinY() - 20 ) || ( y2 > getVisibleRect().getMaxY() + 20 ) ) ) {
2367 if ( draw_horizontal ) {
2368 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
2369 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2370 x1_r = x1a + ROUNDED_D;
2372 drawLine( x1_r, y2, x2a, y2, g );
2375 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2376 final float x1c = x1a + EURO_D;
2378 drawLine( x1c, y2, x2a, y2, g );
2382 drawLine( x1a, y2, x2a, y2, g );
2386 final double w = PhylogenyMethods.getBranchWidthValue( node );
2387 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2388 x1_r = x1a + ROUNDED_D;
2390 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
2393 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2394 final float x1c = x1a + EURO_D;
2396 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
2400 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
2404 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2409 final double diff = y2 - y2_r;
2410 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
2413 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
2418 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
2421 final void paintCircular( final Phylogeny phy,
2422 final double starting_angle,
2427 final boolean to_pdf,
2428 final boolean to_graphics_file ) {
2429 _circ_num_ext_nodes = phy.getNumberOfExternalNodes();
2430 _root = phy.getRoot();
2431 _root.setXcoord( center_x );
2432 _root.setYcoord( center_y );
2433 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file, isInFoundNodes( _root ) );
2434 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
2435 double current_angle = starting_angle;
2437 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2438 final PhylogenyNode n = it.next();
2439 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
2440 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
2441 _urt_nodeid_angle_map.put( n.getId(), current_angle );
2442 _urt_nodeid_index_map.put( n.getId(), i++ );
2443 current_angle += ( TWO_PI / _circ_num_ext_nodes );
2445 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
2448 final void paintCircularLite( final Phylogeny phy,
2449 final double starting_angle,
2453 final Graphics2D g ) {
2454 _circ_num_ext_nodes = phy.getNumberOfExternalNodes();
2455 _root = phy.getRoot();
2456 _root.setXSecondary( center_x );
2457 _root.setYSecondary( center_y );
2458 double current_angle = starting_angle;
2459 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2460 final PhylogenyNode n = it.next();
2461 n.setXSecondary( ( float ) ( center_x + radius * Math.cos( current_angle ) ) );
2462 n.setYSecondary( ( float ) ( center_y + radius * Math.sin( current_angle ) ) );
2463 _urt_nodeid_angle_map.put( n.getId(), current_angle );
2464 current_angle += ( TWO_PI / _circ_num_ext_nodes );
2466 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
2469 final private double paintCirculars( final PhylogenyNode n,
2470 final Phylogeny phy,
2471 final float center_x,
2472 final float center_y,
2473 final double radius,
2474 final boolean radial_labels,
2476 final boolean to_pdf,
2477 final boolean to_graphics_file ) {
2478 if ( n.isExternal() ) {
2479 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
2480 System.out.println( "no " + n + ", fucker!" );//TODO
2482 return _urt_nodeid_angle_map.get( n.getId() );
2485 final List<PhylogenyNode> descs = n.getDescendants();
2487 for( final PhylogenyNode desc : descs ) {
2488 sum += paintCirculars( desc,
2499 if ( !n.isRoot() ) {
2500 r = 1 - ( ( ( double ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth );
2502 final double theta = sum / descs.size();
2503 n.setXcoord( ( float ) ( center_x + r * radius * Math.cos( theta ) ) );
2504 n.setYcoord( ( float ) ( center_y + r * radius * Math.sin( theta ) ) );
2505 _urt_nodeid_angle_map.put( n.getId(), theta );
2506 for( final PhylogenyNode desc : descs ) {
2507 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
2513 final private void paintCircularsLite( final PhylogenyNode n,
2514 final Phylogeny phy,
2518 final Graphics2D g ) {
2519 if ( n.isExternal() ) {
2523 final List<PhylogenyNode> descs = n.getDescendants();
2524 for( final PhylogenyNode desc : descs ) {
2525 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
2528 if ( !n.isRoot() ) {
2529 r = 1 - ( ( ( float ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth );
2531 final double theta = _urt_nodeid_angle_map.get( n.getId() );
2532 n.setXSecondary( ( float ) ( center_x + radius * r * Math.cos( theta ) ) );
2533 n.setYSecondary( ( float ) ( center_y + radius * r * Math.sin( theta ) ) );
2534 for( final PhylogenyNode desc : descs ) {
2535 paintBranchCircularLite( n, desc, g );
2540 final private void paintCollapsedNode( final Graphics2D g,
2541 final PhylogenyNode node,
2542 final boolean to_graphics_file,
2543 final boolean to_pdf,
2544 final boolean is_in_found_nodes ) {
2545 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2546 g.setColor( Color.BLACK );
2548 else if ( is_in_found_nodes ) {
2549 g.setColor( getTreeColorSet().getFoundColor() );
2551 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2552 g.setColor( getTaxonomyBasedColor( node ) );
2554 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
2555 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2556 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2559 g.setColor( getTreeColorSet().getCollapseFillColor() );
2561 double d = node.getAllExternalDescendants().size();
2563 d = ( 3 * _y_distance ) / 3;
2566 d = ( Math.log10( d ) * _y_distance ) / 2.5;
2568 if ( d < BOX_SIZE ) {
2572 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() - TreePanel.BOX_SIZE ),
2573 ForesterUtil.roundToInt( node.getYcoord() ) );
2574 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + TreePanel.BOX_SIZE ),
2575 ForesterUtil.roundToInt( node.getYcoord() - d ) );
2576 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + TreePanel.BOX_SIZE ),
2577 ForesterUtil.roundToInt( node.getYcoord() + d ) );
2578 g.fillPolygon( _polygon );
2579 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
2583 final public void paintComponent( final Graphics g ) {
2584 // Dimension currentSize = getSize();
2585 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
2586 // call the 'java.awt.Component.createImage(...)' method to get an
2588 // offscreenImage = createImage( currentSize.width, currentSize.height );
2589 // offscreenGraphics = offscreenImage.getGraphics();
2590 // offscreenDimension = currentSize;
2592 // super.paintComponent( g ); //why?
2593 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
2594 final Graphics2D g2d = ( Graphics2D ) g;
2595 g2d.setRenderingHints( _rendering_hints );
2596 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
2597 //g.drawImage( offscreenImage, 0, 0, this );
2601 public void update( final Graphics g ) {
2605 final private void paintConfidenceValues( final Graphics2D g,
2606 final PhylogenyNode node,
2607 final boolean to_pdf,
2608 final boolean to_graphics_file ) {
2609 String conf_str = "";
2610 final List<Confidence> confidences = node.getBranchData().getConfidences();
2611 if ( confidences.size() == 1 ) {
2612 final double value = node.getBranchData().getConfidence( 0 ).getValue();
2613 if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
2616 conf_str = FORMATTER_CONFIDENCE.format( value );
2618 else if ( confidences.size() > 1 ) {
2619 boolean one_ok = false;
2620 boolean not_first = false;
2621 Collections.sort( confidences );
2622 final StringBuilder sb = new StringBuilder();
2623 for( final Confidence confidence : confidences ) {
2624 final double value = confidence.getValue();
2625 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2626 if ( value >= getOptions().getMinConfidenceValue() ) {
2635 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
2636 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2640 conf_str = sb.toString();
2643 if ( conf_str.length() > 0 ) {
2644 final double parent_x = node.getParent().getXcoord();
2645 double x = node.getXcoord();
2646 g.setFont( getTreeFontSet().getSmallFont() );
2647 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2650 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2653 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2654 g.setColor( Color.BLACK );
2657 g.setColor( getTreeColorSet().getConfidenceColor() );
2660 .drawString( conf_str,
2662 + ( ( x - parent_x - getTreeFontSet()._fm_small.stringWidth( conf_str ) ) / 2 ),
2663 ( node.getYcoord() + getTreeFontSet()._small_max_ascent ) - 1,
2668 final private void paintFoundNode( final int x, final int y, final Graphics2D g ) {
2669 g.setColor( getTreeColorSet().getFoundColor() );
2670 g.fillRect( x - TreePanel.HALF_BOX_SIZE, y - TreePanel.HALF_BOX_SIZE, TreePanel.BOX_SIZE, TreePanel.BOX_SIZE );
2673 final private void paintGainedAndLostCharacters( final Graphics2D g,
2674 final PhylogenyNode node,
2675 final String gained,
2676 final String lost ) {
2677 if ( node.getParent() != null ) {
2678 final double parent_x = node.getParent().getXcoord();
2679 final double x = node.getXcoord();
2680 g.setFont( getTreeFontSet().getLargeFont() );
2681 g.setColor( getTreeColorSet().getGainedCharactersColor() );
2682 if ( Constants.SPECIAL_CUSTOM ) {
2683 g.setColor( Color.BLUE );
2686 .drawString( gained,
2687 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( gained ) ) / 2 ),
2688 ( node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent() ),
2690 g.setColor( getTreeColorSet().getLostCharactersColor() );
2691 TreePanel.drawString( lost,
2692 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( lost ) ) / 2 ),
2693 ( node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent() ),
2699 * Draw a box at the indicated node.
2706 final private void paintNodeBox( final double x,
2708 final PhylogenyNode node,
2710 final boolean to_pdf,
2711 final boolean to_graphics_file,
2712 final boolean is_in_found_nodes ) {
2713 if ( node.isCollapse() ) {
2716 // if this node should be highlighted, do so
2717 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
2718 g.setColor( getTreeColorSet().getFoundColor() );
2719 drawOval( x - 8, y - 8, 16, 16, g );
2720 drawOval( x - 9, y - 8, 17, 17, g );
2721 drawOval( x - 9, y - 9, 18, 18, g );
2723 if ( is_in_found_nodes ) {
2724 paintFoundNode( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ), g );
2727 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2728 g.setColor( Color.BLACK );
2730 else if ( getControlPanel().isEvents() && Util.isHasAssignedEvent( node ) ) {
2731 final Event event = node.getNodeData().getEvent();
2732 if ( event.isDuplication() ) {
2733 g.setColor( getTreeColorSet().getDuplicationBoxColor() );
2735 else if ( event.isSpeciation() ) {
2736 g.setColor( getTreeColorSet().getSpecBoxColor() );
2738 else if ( event.isSpeciationOrDuplication() ) {
2739 g.setColor( getTreeColorSet().getDuplicationOrSpeciationColor() );
2743 assignGraphicsForNodeBoxWithColorForParentBranch( node, g );
2745 if ( ( getOptions().isShowNodeBoxes() && !to_pdf && !to_graphics_file )
2746 || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) {
2747 if ( to_pdf || to_graphics_file ) {
2748 if ( node.isDuplication() || !getOptions().isPrintBlackAndWhite() ) {
2749 drawOvalFilled( x - HALF_BOX_SIZE, y - HALF_BOX_SIZE, BOX_SIZE, BOX_SIZE, g );
2753 drawRectFilled( x - HALF_BOX_SIZE, y - HALF_BOX_SIZE, BOX_SIZE, BOX_SIZE, g );
2759 final private void paintNodeData( final Graphics2D g,
2760 final PhylogenyNode node,
2761 final boolean to_graphics_file,
2762 final boolean to_pdf,
2763 final boolean is_in_found_nodes ) {
2764 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
2767 if ( getOptions().isShowBranchLengthValues()
2768 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2769 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
2770 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) ) {
2771 paintBranchLength( g, node, to_pdf, to_graphics_file );
2773 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
2777 if ( getControlPanel().isShowTaxonomyImages()
2778 && ( getImageMap() != null )
2779 && !getImageMap().isEmpty()
2780 && node.getNodeData().isHasTaxonomy()
2781 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
2782 .getUris().isEmpty() ) ) {
2783 x += drawTaxonomyImage( node.getXcoord() + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord(), node, g );
2785 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
2786 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
2787 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
2789 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2790 g.setColor( Color.BLACK );
2792 else if ( is_in_found_nodes ) {
2793 g.setColor( getTreeColorSet().getFoundColor() );
2795 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2796 g.setColor( getTaxonomyBasedColor( node ) );
2798 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
2799 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2800 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2802 else if ( to_pdf ) {
2803 g.setColor( Color.BLACK );
2806 g.setColor( getTreeColorSet().getSequenceColor() );
2809 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
2811 _sb.append( node.getAllExternalDescendants().size() );
2814 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
2815 if ( _sb.length() > 0 ) {
2818 _sb.append( node.getName() );
2820 if ( node.getNodeData().isHasSequence() ) {
2821 if ( getControlPanel().isShowGeneSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
2822 if ( _sb.length() > 0 ) {
2825 _sb.append( node.getNodeData().getSequence().getSymbol() );
2827 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
2828 if ( _sb.length() > 0 ) {
2831 _sb.append( node.getNodeData().getSequence().getName() );
2833 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
2834 if ( _sb.length() > 0 ) {
2837 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
2838 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
2841 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
2844 g.setFont( getTreeFontSet().getLargeFont() );
2845 if ( is_in_found_nodes ) {
2846 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
2848 double down_shift_factor = 3.0;
2849 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
2850 down_shift_factor = 1;
2852 final double pos_x = node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE;
2853 final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
2854 final String sb_str = _sb.toString();
2855 // GUILHEM_BEG ______________
2856 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
2857 && ( _query_sequence != null ) ) {
2858 int nodeTextBoundsWidth = 0;
2859 if ( sb_str.length() > 0 ) {
2860 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
2861 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
2863 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
2864 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
2865 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
2866 g.setColor( getTreeColorSet().getBackgroundColor() );
2870 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
2871 for( final SequenceRelation seqRelation : seqRelations ) {
2872 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
2873 .getRef1().isEqual( _query_sequence ) )
2874 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
2875 .getSelectedItem() );
2876 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
2877 final double linePosX = node.getXcoord() + 2 + TreePanel.HALF_BOX_SIZE;
2878 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
2879 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
2881 if ( sConfidence != null ) {
2882 double confidenceX = pos_x;
2883 if ( sb_str.length() > 0 ) {
2884 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
2885 + CONFIDENCE_LEFT_MARGIN;
2887 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
2888 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
2889 .getBounds().getWidth();
2890 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
2891 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
2894 if ( x + nodeTextBoundsWidth > 0 ) /* we only underline if there is something displayed */
2896 if ( nodeTextBoundsWidth == 0 ) {
2897 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
2900 nodeTextBoundsWidth += 2;
2902 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
2903 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
2910 if ( sb_str.length() > 0 ) {
2911 TreePanel.drawString( sb_str, pos_x, pos_y, g );
2913 // GUILHEM_END _____________
2914 // COMMENTED_OUT_BY_GUILHEM_BEG _______________
2915 // TODO FIXME need to check this one!
2916 //if ( _sb.length() > 0 ) {
2917 // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
2918 // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
2920 // COMMENTED_OUT_BY_GUILHEM_END ________________
2921 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
2922 && ( node.getNodeData().getSequence().getAnnotations() != null )
2923 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
2924 if ( _sb.length() > 0 ) {
2925 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
2927 final Annotation ann = node.getNodeData().getSequence().getAnnotation( 0 );
2928 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2929 g.setColor( Color.BLACK );
2932 g.setColor( calculateColorForAnnotation( ann ) );
2934 final String ann_str = ann.asSimpleText().toString();
2935 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
2936 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
2938 _sb.append( ann_str );
2940 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2941 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2942 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2943 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
2944 && node.getNodeData().isHasBinaryCharacters() ) {
2945 if ( _sb.length() > 0 ) {
2946 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
2948 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2949 g.setColor( Color.BLACK );
2952 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
2954 if ( getControlPanel().isShowBinaryCharacters() ) {
2955 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
2956 .toString(), node.getXcoord() + x + 1 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
2957 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
2958 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
2959 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
2960 .getLostCharactersAsStringBuffer().toString() );
2963 if ( DRAW_MEAN_COUNTS && node.isInternal() ) {
2964 final List<PhylogenyNode> ec = node.getAllExternalDescendants();
2967 for( final PhylogenyNode phylogenyNode : ec ) {
2969 if ( phylogenyNode.getNodeData().getBinaryCharacters() != null ) {
2970 sum += phylogenyNode.getNodeData().getBinaryCharacters().getPresentCount();
2973 final double mean = ForesterUtil.round( sum / count, 1 );
2974 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount() + " ["
2975 + mean + "]", node.getXcoord() + x + 4 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
2976 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
2979 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
2980 node.getXcoord() + x + 4 + TreePanel.HALF_BOX_SIZE,
2982 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ),
2985 paintGainedAndLostCharacters( g, node, "+"
2986 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
2987 + node.getNodeData().getBinaryCharacters().getLostCount() );
2993 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
2994 final List<Uri> us = new ArrayList<Uri>();
2995 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
2996 for( final Uri uri : t.getUris() ) {
3001 for( final Uri uri : us ) {
3002 if ( uri != null ) {
3003 final String uri_str = uri.getValue().toString().toLowerCase();
3004 if ( getImageMap().containsKey( uri_str ) ) {
3005 final BufferedImage bi = getImageMap().get( uri_str );
3006 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
3007 double scaling_factor = 1;
3008 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
3009 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
3010 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
3012 // y = y - ( 0.9 * getYdistance() );
3013 final double hs = bi.getHeight() * scaling_factor;
3014 double ws = bi.getWidth() * scaling_factor + offset;
3015 final double my_y = y - ( 0.5 * hs );
3016 final int x_w = ( int ) ( x + ws + 0.5 );
3017 final int y_h = ( int ) ( my_y + hs + 0.5 );
3018 if ( ( x_w - x > 7 ) && ( y_h - my_y > 7 ) ) {
3020 ( int ) ( x + 0.5 + offset ),
3021 ( int ) ( my_y + 0.5 ),
3042 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
3043 final PhylogenyNode node,
3044 final boolean to_pdf,
3045 final boolean to_graphics_file,
3046 final boolean radial_labels,
3047 final double ur_angle,
3048 final boolean is_in_found_nodes ) {
3049 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
3052 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3053 g.setColor( Color.BLACK );
3055 else if ( is_in_found_nodes ) {
3056 g.setColor( getTreeColorSet().getFoundColor() );
3058 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3059 g.setColor( getTaxonomyBasedColor( node ) );
3062 g.setColor( getTreeColorSet().getSequenceColor() );
3066 if ( node.getNodeData().isHasTaxonomy()
3067 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
3068 .isShowTaxonomyCommonNames() ) ) {
3069 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3070 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3071 _sb.append( taxonomy.getTaxonomyCode() );
3074 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3075 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3076 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3077 _sb.append( taxonomy.getScientificName() );
3079 _sb.append( taxonomy.getCommonName() );
3082 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3083 _sb.append( taxonomy.getScientificName() );
3086 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3087 _sb.append( taxonomy.getCommonName() );
3091 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3092 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3093 _sb.append( taxonomy.getScientificName() );
3097 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3098 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3099 _sb.append( taxonomy.getCommonName() );
3104 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3106 _sb.append( node.getAllExternalDescendants().size() );
3109 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3110 if ( _sb.length() > 0 ) {
3113 _sb.append( node.getName() );
3115 if ( node.getNodeData().isHasSequence() ) {
3116 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3117 if ( _sb.length() > 0 ) {
3120 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3121 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3124 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3126 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3127 if ( _sb.length() > 0 ) {
3130 _sb.append( node.getNodeData().getSequence().getName() );
3133 g.setFont( getTreeFontSet().getLargeFont() );
3134 if ( is_in_found_nodes ) {
3135 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3137 if ( _sb.length() > 1 ) {
3138 final String sb_str = _sb.toString();
3140 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3141 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
3144 m = ( float ) ( ur_angle % TWO_PI );
3146 _at = g.getTransform();
3147 boolean need_to_reset = false;
3148 final float x_coord = node.getXcoord();
3149 final float y_coord = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / 3.0f );
3150 if ( radial_labels ) {
3151 need_to_reset = true;
3152 boolean left = false;
3153 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3157 g.rotate( m, x_coord, node.getYcoord() );
3159 g.translate( -( getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth() ), 0 );
3163 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3164 need_to_reset = true;
3165 g.translate( -getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth(), 0 );
3168 TreePanel.drawString( sb_str, x_coord, y_coord, g );
3169 if ( need_to_reset ) {
3170 g.setTransform( _at );
3175 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
3176 if ( node.isCollapse() ) {
3177 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
3178 paintCollapsedNode( g, node, false, false, false );
3182 if ( isInFoundNodes( node ) ) {
3183 g.setColor( getTreeColorSet().getFoundColor() );
3184 drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
3187 if ( !node.isExternal() && !node.isCollapse() ) {
3188 boolean first_child = true;
3190 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3191 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3192 final PhylogenyNode child_node = node.getChildNode( i );
3194 if ( !isUniformBranchLengthsForCladogram() ) {
3195 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3198 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
3200 if ( first_child ) {
3201 first_child = false;
3202 y2 = node.getYSecondary()
3203 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
3204 .getNumberOfExternalNodes() ) );
3207 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3209 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
3210 new_x = x2 + node.getXSecondary();
3211 final float diff_y = node.getYSecondary() - y2;
3212 final float diff_x = node.getXSecondary() - new_x;
3213 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
3214 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
3216 child_node.setXSecondary( new_x );
3217 child_node.setYSecondary( y2 );
3218 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3223 final private void paintNodeRectangular( final Graphics2D g,
3224 final PhylogenyNode node,
3225 final boolean to_pdf,
3226 final boolean dynamically_hide,
3227 final int dynamic_hiding_factor,
3228 final boolean to_graphics_file ) {
3229 final boolean is_in_found_nodes = isInFoundNodes( node );
3230 if ( node.isCollapse() ) {
3231 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
3232 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3236 if ( node.isExternal() ) {
3237 ++_external_node_index;
3239 // Confidence values
3240 if ( getControlPanel().isShowBootstrapValues()
3241 && !node.isExternal()
3243 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
3244 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3245 && node.getBranchData().isHasConfidences() ) {
3246 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
3248 // Draw a line to root:
3249 if ( node.isRoot() && _phylogeny.isRooted() ) {
3250 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
3253 float new_x_min = Float.MAX_VALUE;
3254 final boolean disallow_shortcutting = dynamic_hiding_factor < 40;
3255 float min_dist = 1.5f;
3256 if ( !disallow_shortcutting ) {
3257 // System.out.println( dynamic_hiding_factor );
3258 if ( dynamic_hiding_factor > 4000 ) {
3261 else if ( dynamic_hiding_factor > 1000 ) {
3264 else if ( dynamic_hiding_factor > 100 ) {
3268 if ( !node.isExternal() && !node.isCollapse() ) {
3269 boolean first_child = true;
3271 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3272 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3273 final PhylogenyNode child_node = node.getChildNode( i );
3275 if ( !isUniformBranchLengthsForCladogram() ) {
3276 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3279 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
3281 if ( first_child ) {
3282 first_child = false;
3283 y2 = node.getYcoord()
3284 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3287 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3289 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
3290 new_x = x2 + node.getXcoord();
3291 if ( dynamically_hide && ( x2 < new_x_min ) ) {
3294 final float diff_y = node.getYcoord() - y2;
3295 final float diff_x = node.getXcoord() - new_x;
3296 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
3297 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
3298 paintBranchRectangular( g,
3307 child_node.setXcoord( new_x );
3308 child_node.setYcoord( y2 );
3309 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3312 if ( dynamically_hide
3313 && !is_in_found_nodes
3314 && ( ( node.isExternal() && ( _external_node_index % dynamic_hiding_factor != 1 ) ) || ( !node
3315 .isExternal() && ( ( new_x_min < 20 ) || ( _y_distance * node.getNumberOfExternalNodes() < getTreeFontSet()._fm_large
3316 .getHeight() ) ) ) ) ) {
3319 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3320 paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
3323 final private void paintNodeWithRenderableData( final Graphics2D g,
3324 final PhylogenyNode node,
3325 final boolean to_graphics_file,
3326 final boolean to_pdf ) {
3327 if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
3330 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
3333 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3334 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
3335 RenderableDomainArchitecture rds = null;
3336 if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
3338 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
3340 catch ( final ClassCastException cce ) {
3341 cce.printStackTrace();
3344 rds.setRenderingHeight( 6 );
3346 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( node ).length() > 0 ) ) {
3347 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( node ) + " " );
3349 if ( getControlPanel().isShowGeneNames() ) {
3350 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
3352 if ( getControlPanel().isShowGeneSymbols() ) {
3353 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
3355 if ( getControlPanel().isShowSequenceAcc() ) {
3356 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
3360 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3361 x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
3363 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
3367 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
3368 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
3369 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
3370 getStatisticsForExpressionValues(),
3371 getConfiguration() );
3373 PhylogenyNode my_node = node;
3374 if ( !getControlPanel().isDrawPhylogram() ) {
3375 my_node = getPhylogeny().getFirstExternalNode();
3377 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
3378 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
3380 if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
3381 x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
3383 rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
3388 final private void paintOvRectangle( final Graphics2D g ) {
3389 final float w_ratio = ( float ) getWidth() / getVisibleRect().width;
3390 final float h_ratio = ( float ) getHeight() / getVisibleRect().height;
3391 final float x_ratio = ( float ) getWidth() / getVisibleRect().x;
3392 final float y_ratio = ( float ) getHeight() / getVisibleRect().y;
3393 final float width = getOvMaxWidth() / w_ratio;
3394 final float height = getOvMaxHeight() / h_ratio;
3395 final float x = getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / x_ratio;
3396 final float y = getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / y_ratio;
3397 g.setColor( getTreeColorSet().getFoundColor() );
3398 getOvRectangle().setRect( x, y, width, height );
3399 if ( ( width < 6 ) && ( height < 6 ) ) {
3400 drawRectFilled( x, y, 6, 6, g );
3401 getOvVirtualRectangle().setRect( x, y, 6, 6 );
3403 else if ( width < 6 ) {
3404 drawRectFilled( x, y, 6, height, g );
3405 getOvVirtualRectangle().setRect( x, y, 6, height );
3407 else if ( height < 6 ) {
3408 drawRectFilled( x, y, width, 6, g );
3409 getOvVirtualRectangle().setRect( x, y, width, 6 );
3412 drawRect( x, y, width, height, g );
3413 if ( isInOvRect() ) {
3414 drawRect( x + 1, y + 1, width - 2, height - 2, g );
3416 getOvVirtualRectangle().setRect( x, y, width, height );
3420 final void paintPhylogeny( final Graphics2D g,
3421 final boolean to_pdf,
3422 final boolean to_graphics_file,
3423 final int graphics_file_width,
3424 final int graphics_file_height,
3425 final int graphics_file_x,
3426 final int graphics_file_y ) {
3427 if ( _control_panel.isShowSequenceRelations() ) {
3428 _query_sequence = _control_panel.getSelectedQuerySequence();
3430 // Color the background
3432 final Rectangle r = getVisibleRect();
3433 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
3434 g.setColor( getTreeColorSet().getBackgroundColor() );
3435 if ( !to_graphics_file ) {
3439 if ( getOptions().isPrintBlackAndWhite() ) {
3440 g.setColor( Color.WHITE );
3442 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
3446 if ( !to_graphics_file ) {
3447 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
3448 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
3452 g.setPaint( new GradientPaint( graphics_file_x,
3454 getTreeColorSet().getBackgroundColor(),
3456 graphics_file_y + graphics_file_height,
3457 getTreeColorSet().getBackgroundColorGradientBottom() ) );
3458 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
3461 g.setStroke( new BasicStroke( 1 ) );
3464 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
3466 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3467 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3468 _external_node_index = 0;
3469 // Position starting X of tree
3470 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
3471 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
3473 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
3474 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
3475 .getDistanceToParent() * getXcorrectionFactor() ) ) );
3478 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
3480 // Position starting Y of tree
3481 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
3482 + ( TreePanel.MOVE / 2.0f ) );
3483 final int dynamic_hiding_factor = ( int ) ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) );
3484 if ( getControlPanel().isDynamicallyHideData() ) {
3485 if ( dynamic_hiding_factor > 1 ) {
3486 getControlPanel().setDynamicHidingIsOn( true );
3489 getControlPanel().setDynamicHidingIsOn( false );
3492 if ( _nodes_in_preorder == null ) {
3493 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
3495 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3496 _nodes_in_preorder[ i++ ] = it.next();
3499 //final PhylogenyNodeIterator it;
3500 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3501 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
3502 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
3504 for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
3505 paintNodeRectangular( g, _nodes_in_preorder[ i ], to_pdf, getControlPanel().isDynamicallyHideData()
3506 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
3508 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
3509 if ( !( to_graphics_file || to_pdf ) ) {
3512 getVisibleRect().y + getVisibleRect().height,
3517 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
3520 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3521 paintPhylogenyLite( g );
3524 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3525 if ( getControlPanel().getDynamicallyHideData() != null ) {
3526 getControlPanel().setDynamicHidingIsOn( false );
3528 final double angle = getStartingAngle();
3529 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
3530 _dynamic_hiding_factor = 0;
3531 if ( getControlPanel().isDynamicallyHideData() ) {
3532 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
3533 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
3535 if ( getControlPanel().getDynamicallyHideData() != null ) {
3536 if ( _dynamic_hiding_factor > 1 ) {
3537 getControlPanel().setDynamicHidingIsOn( true );
3540 getControlPanel().setDynamicHidingIsOn( false );
3543 paintUnrooted( _phylogeny.getRoot(),
3545 ( float ) ( angle + 2 * Math.PI ),
3550 if ( getOptions().isShowScale() ) {
3551 if ( !( to_graphics_file || to_pdf ) ) {
3554 getVisibleRect().y + getVisibleRect().height,
3559 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
3562 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3563 g.setColor( getTreeColorSet().getOvColor() );
3564 paintUnrootedLite( _phylogeny.getRoot(),
3566 angle + 2 * Math.PI,
3568 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
3569 paintOvRectangle( g );
3572 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3573 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
3574 final int d = radius + MOVE + getLongestExtNodeInfo();
3575 _dynamic_hiding_factor = 0;
3576 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
3577 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
3578 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
3580 if ( getControlPanel().getDynamicallyHideData() != null ) {
3581 if ( _dynamic_hiding_factor > 1 ) {
3582 getControlPanel().setDynamicHidingIsOn( true );
3585 getControlPanel().setDynamicHidingIsOn( false );
3588 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
3589 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3590 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
3591 : getOvMaxWidth() / 2 );
3592 double x_scale = 1.0;
3593 double y_scale = 1.0;
3594 int x_pos = getVisibleRect().x + getOvXPosition();
3595 int y_pos = getVisibleRect().y + getOvYPosition();
3596 if ( getWidth() > getHeight() ) {
3597 x_scale = ( double ) getHeight() / getWidth();
3598 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
3601 y_scale = ( double ) getWidth() / getHeight();
3602 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
3604 _at = g.getTransform();
3605 g.scale( x_scale, y_scale );
3606 paintCircularLite( _phylogeny,
3610 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
3613 g.setTransform( _at );
3614 paintOvRectangle( g );
3619 final private void paintPhylogenyLite( final Graphics2D g ) {
3620 //System.out.println( getVisibleRect().x + " " + getVisibleRect().y );
3623 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
3624 .getWidth() ) ) ) );
3625 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
3626 //final PhylogenyNodeIterator it;
3627 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3628 // paintNodeLite( g, it.next() );
3630 for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
3631 paintNodeLite( g, _nodes_in_preorder[ i ] );
3633 paintOvRectangle( g );
3637 * Paint the root branch. (Differs from others because it will always be a
3638 * single horizontal line).
3639 * @param to_graphics_file
3641 * @return new x1 value
3643 final private void paintRootBranch( final Graphics2D g,
3646 final PhylogenyNode root,
3647 final boolean to_pdf,
3648 final boolean to_graphics_file ) {
3649 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
3650 float d = getXdistance();
3651 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
3652 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
3654 if ( d < MIN_ROOT_LENGTH ) {
3655 d = MIN_ROOT_LENGTH;
3657 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
3658 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
3661 final double w = PhylogenyMethods.getBranchWidthValue( root );
3662 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
3664 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file, isInFoundNodes( root ) );
3667 final private void paintScale( final Graphics2D g,
3670 final boolean to_pdf,
3671 final boolean to_graphics_file ) {
3673 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
3675 final int y2 = y1 - 8;
3676 final int y3 = y1 - 4;
3677 g.setFont( getTreeFontSet().getSmallFont() );
3678 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3679 g.setColor( Color.BLACK );
3682 g.setColor( getTreeColorSet().getBranchLengthColor() );
3684 drawLine( x1, y1, x1, y2, g );
3685 drawLine( x2, y1, x2, y2, g );
3686 drawLine( x1, y3, x2, y3, g );
3687 if ( getScaleLabel() != null ) {
3688 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
3692 final private int paintTaxonomy( final Graphics2D g,
3693 final PhylogenyNode node,
3694 final boolean is_in_found_nodes,
3695 final boolean to_pdf,
3696 final boolean to_graphics_file,
3697 final double x_shift ) {
3698 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3699 g.setFont( getTreeFontSet().getLargeItalicFont() );
3700 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3701 g.setColor( Color.BLACK );
3703 else if ( is_in_found_nodes ) {
3704 g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
3705 g.setColor( getTreeColorSet().getFoundColor() );
3707 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3708 g.setColor( getTaxonomyBasedColor( node ) );
3710 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3711 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3712 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3714 else if ( to_pdf ) {
3715 g.setColor( Color.BLACK );
3718 g.setColor( getTreeColorSet().getTaxonomyColor() );
3720 final double start_x = node.getXcoord() + 3 + TreePanel.HALF_BOX_SIZE + x_shift;
3721 final double start_y = node.getYcoord()
3722 + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
3724 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3725 _sb.append( taxonomy.getTaxonomyCode() );
3728 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3729 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3730 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3731 if ( getOptions().isAbbreviateScientificTaxonNames()
3732 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3733 abbreviateScientificName( taxonomy.getScientificName() );
3736 _sb.append( taxonomy.getScientificName() );
3739 _sb.append( taxonomy.getCommonName() );
3742 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3743 if ( getOptions().isAbbreviateScientificTaxonNames()
3744 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3745 abbreviateScientificName( taxonomy.getScientificName() );
3748 _sb.append( taxonomy.getScientificName() );
3752 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3753 _sb.append( taxonomy.getCommonName() );
3757 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3758 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3759 if ( getOptions().isAbbreviateScientificTaxonNames()
3760 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3761 abbreviateScientificName( taxonomy.getScientificName() );
3764 _sb.append( taxonomy.getScientificName() );
3769 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3770 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3771 _sb.append( taxonomy.getCommonName() );
3775 final String label = _sb.toString();
3777 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
3778 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
3779 // invert font color and background color to show that this is the query sequence
3780 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
3784 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
3785 g.setColor( getTreeColorSet().getBackgroundColor() );
3788 TreePanel.drawString( label, start_x, start_y, g );
3789 if ( is_in_found_nodes ) {
3790 return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
3793 return getTreeFontSet()._fm_large_italic.stringWidth( label );
3797 private void abbreviateScientificName( final String sn ) {
3798 final String[] a = sn.split( "\\s+" );
3799 _sb.append( a[ 0 ].substring( 0, 1 ) );
3800 _sb.append( a[ 1 ].substring( 0, 2 ) );
3801 if ( a.length > 2 ) {
3802 for( int i = 2; i < a.length; i++ ) {
3804 _sb.append( a[ i ] );
3809 final private void paintUnrooted( final PhylogenyNode n,
3810 final double low_angle,
3811 final double high_angle,
3812 final boolean radial_labels,
3814 final boolean to_pdf,
3815 final boolean to_graphics_file ) {
3817 n.setXcoord( getWidth() / 2 );
3818 n.setYcoord( getHeight() / 2 );
3819 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file, isInFoundNodes( n ) );
3821 if ( n.isExternal() ) {
3822 paintNodeDataUnrootedCirc( g,
3827 ( high_angle + low_angle ) / 2,
3828 isInFoundNodes( n ) );
3831 final float num_enclosed = n.getNumberOfExternalNodes();
3832 final float x = n.getXcoord();
3833 final float y = n.getYcoord();
3834 double current_angle = low_angle;
3835 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
3836 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
3837 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
3838 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
3839 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3840 final PhylogenyNode desc = n.getChildNode( i );
3841 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
3842 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
3843 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
3844 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
3847 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
3850 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
3853 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3854 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3856 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3857 if ( desc.getDistanceToParent() < 0 ) {
3861 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
3865 length = getUrtFactor();
3867 final double mid_angle = current_angle + arc_size / 2;
3868 final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length );
3869 final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length );
3870 desc.setXcoord( new_x );
3871 desc.setYcoord( new_y );
3872 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc ) );
3873 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
3874 current_angle += arc_size;
3875 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
3876 drawLine( x, y, new_x, new_y, g );
3880 final private void paintUnrootedLite( final PhylogenyNode n,
3881 final double low_angle,
3882 final double high_angle,
3884 final float urt_ov_factor ) {
3886 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / 2 );
3887 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / 2 );
3888 n.setXSecondary( x_pos );
3889 n.setYSecondary( y_pos );
3891 if ( n.isExternal() ) {
3894 final float num_enclosed = n.getNumberOfExternalNodes();
3895 final float x = n.getXSecondary();
3896 final float y = n.getYSecondary();
3897 double current_angle = low_angle;
3898 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
3899 final PhylogenyNode desc = n.getChildNode( i );
3900 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
3901 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
3903 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
3904 if ( desc.getDistanceToParent() < 0 ) {
3908 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
3912 length = urt_ov_factor;
3914 final double mid_angle = current_angle + arc_size / 2;
3915 final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length );
3916 final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length );
3917 desc.setXSecondary( new_x );
3918 desc.setYSecondary( new_y );
3919 if ( isInFoundNodes( desc ) ) {
3920 g.setColor( getTreeColorSet().getFoundColor() );
3921 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
3922 g.setColor( getTreeColorSet().getOvColor() );
3924 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
3925 current_angle += arc_size;
3926 drawLine( x, y, new_x, new_y, g );
3930 final private void pasteSubtree( final PhylogenyNode node ) {
3931 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3932 errorMessageNoCutCopyPasteInUnrootedDisplay();
3935 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
3936 JOptionPane.showMessageDialog( this,
3937 "No tree in buffer (need to copy or cut a subtree first)",
3938 "Attempt to paste with empty buffer",
3939 JOptionPane.ERROR_MESSAGE );
3942 final String label = getASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
3943 final Object[] options = { "As sibling", "As descendant", "Cancel" };
3944 final int r = JOptionPane.showOptionDialog( this,
3945 "How to paste subtree" + label + "?",
3947 JOptionPane.CLOSED_OPTION,
3948 JOptionPane.QUESTION_MESSAGE,
3952 boolean paste_as_sibling = true;
3954 paste_as_sibling = false;
3956 else if ( r != 0 ) {
3959 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
3960 buffer_phy.setAllNodesToNotCollapse();
3961 buffer_phy.preOrderReId();
3962 buffer_phy.setRooted( true );
3963 boolean need_to_show_whole = false;
3964 if ( paste_as_sibling ) {
3965 if ( node.isRoot() ) {
3966 JOptionPane.showMessageDialog( this,
3967 "Cannot paste sibling to root",
3968 "Attempt to paste sibling to root",
3969 JOptionPane.ERROR_MESSAGE );
3972 buffer_phy.addAsSibling( node );
3975 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
3976 need_to_show_whole = true;
3977 _phylogeny = buffer_phy;
3980 buffer_phy.addAsChild( node );
3983 if ( getCopiedAndPastedNodes() == null ) {
3984 setCopiedAndPastedNodes( new HashSet<Integer>() );
3986 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
3987 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
3988 for( final PhylogenyNode n : nodes ) {
3989 node_ids.add( n.getId() );
3991 node_ids.add( node.getId() );
3992 getCopiedAndPastedNodes().addAll( node_ids );
3993 _nodes_in_preorder = null;
3994 _phylogeny.externalNodesHaveChanged();
3995 _phylogeny.hashIDs();
3996 _phylogeny.recalculateNumberOfExternalDescendants( true );
3997 resetNodeIdToDistToLeafMap();
3999 if ( need_to_show_whole ) {
4000 getControlPanel().showWhole();
4005 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
4006 throws PrinterException {
4007 if ( page_index > 0 ) {
4008 return ( NO_SUCH_PAGE );
4011 final Graphics2D g2d = ( Graphics2D ) g;
4012 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
4013 // Turn off double buffering !?
4014 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
4015 // Turn double buffering back on !?
4016 return ( PAGE_EXISTS );
4020 final void recalculateMaxDistanceToRoot() {
4021 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
4025 * Remove all edit-node frames
4027 final void removeAllEditNodeJFrames() {
4028 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
4029 if ( _node_frames[ i ] != null ) {
4030 _node_frames[ i ].dispose();
4031 _node_frames[ i ] = null;
4034 _node_frame_index = 0;
4038 * Remove a node-edit frame.
4040 final void removeEditNodeFrame( final int i ) {
4041 _node_frame_index--;
4042 _node_frames[ i ] = null;
4043 if ( i < _node_frame_index ) {
4044 for( int j = 0; j < _node_frame_index - 1; j++ ) {
4045 _node_frames[ j ] = _node_frames[ j + 1 ];
4047 _node_frames[ _node_frame_index ] = null;
4051 final void reRoot( final PhylogenyNode node ) {
4052 if ( !getPhylogeny().isRerootable() ) {
4053 JOptionPane.showMessageDialog( this,
4054 "This is not rerootable",
4056 JOptionPane.WARNING_MESSAGE );
4059 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4060 JOptionPane.showMessageDialog( this,
4061 "Cannot reroot in unrooted display type",
4062 "Attempt to reroot tree in unrooted display",
4063 JOptionPane.WARNING_MESSAGE );
4066 getPhylogeny().reRoot( node );
4067 getPhylogeny().recalculateNumberOfExternalDescendants( true );
4068 resetNodeIdToDistToLeafMap();
4069 _nodes_in_preorder = null;
4070 resetPreferredSize();
4071 getMainPanel().adjustJScrollPane();
4073 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4074 getControlPanel().showWhole();
4078 final void resetNodeIdToDistToLeafMap() {
4079 _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
4082 final void resetPreferredSize() {
4083 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
4089 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
4090 if ( getControlPanel().isDrawPhylogram() ) {
4092 + getLongestExtNodeInfo()
4094 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
4097 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4099 + getLongestExtNodeInfo()
4100 + ForesterUtil.roundToInt( getXdistance()
4101 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
4105 + getLongestExtNodeInfo()
4106 + ForesterUtil.roundToInt( getXdistance()
4107 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
4110 setPreferredSize( new Dimension( x, y ) );
4113 public final void setArrowCursor() {
4114 setCursor( ARROW_CURSOR );
4118 final void setControlPanel( final ControlPanel atv_control ) {
4119 _control_panel = atv_control;
4122 final private void setCopiedAndPastedNodes( final Set<Integer> nodeIds ) {
4123 getMainPanel().setCopiedAndPastedNodes( nodeIds );
4126 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
4127 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
4130 public final void setEdited( final boolean edited ) {
4134 final void setFoundNodes( final Set<Integer> found_nodes ) {
4135 _found_nodes = found_nodes;
4138 final private void setInOv( final boolean in_ov ) {
4142 final void setInOvRect( final boolean in_ov_rect ) {
4143 _in_ov_rect = in_ov_rect;
4146 final void setLargeFonts() {
4147 getTreeFontSet().largeFonts();
4150 final void setLastMouseDragPointX( final float x ) {
4151 _last_drag_point_x = x;
4154 final void setLastMouseDragPointY( final float y ) {
4155 _last_drag_point_y = y;
4158 final void setLongestExtNodeInfo( final int i ) {
4159 _longest_ext_node_info = i;
4162 final void setMediumFonts() {
4163 getTreeFontSet().mediumFonts();
4166 final private void setOvMaxHeight( final float ov_max_height ) {
4167 _ov_max_height = ov_max_height;
4170 final private void setOvMaxWidth( final float ov_max_width ) {
4171 _ov_max_width = ov_max_width;
4174 final void setOvOn( final boolean ov_on ) {
4178 final private void setOvXcorrectionFactor( final float f ) {
4179 _ov_x_correction_factor = f;
4182 final private void setOvXDistance( final float ov_x_distance ) {
4183 _ov_x_distance = ov_x_distance;
4186 final private void setOvXPosition( final int ov_x_position ) {
4187 _ov_x_position = ov_x_position;
4190 final private void setOvYDistance( final float ov_y_distance ) {
4191 _ov_y_distance = ov_y_distance;
4194 final private void setOvYPosition( final int ov_y_position ) {
4195 _ov_y_position = ov_y_position;
4198 final private void setOvYStart( final int ov_y_start ) {
4199 _ov_y_start = ov_y_start;
4203 * Set parameters for printing the displayed tree
4208 final void setParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
4209 // updateStyle(); not needed?
4210 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4212 if ( recalc_longest_ext_node_info ) {
4213 calculateLongestExtNodeInfo();
4215 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4216 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4217 if ( ext_nodes == 1 ) {
4218 ext_nodes = max_depth;
4219 if ( ext_nodes < 1 ) {
4226 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4227 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
4228 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
4231 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
4232 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
4234 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
4235 if ( xdist < 0.0 ) {
4238 if ( ov_xdist < 0.0 ) {
4241 if ( ydist < 0.0 ) {
4244 setXdistance( xdist );
4245 setYdistance( ydist );
4246 setOvXDistance( ov_xdist );
4247 final double height = _phylogeny.getHeight();
4249 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
4250 setXcorrectionFactor( corr > 0 ? corr : 0 );
4251 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
4252 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4255 setXcorrectionFactor( 0 );
4256 setOvXcorrectionFactor( 0 );
4258 _circ_max_depth = max_depth;
4263 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
4264 _graphics_type = graphics_type;
4268 final private void setScaleDistance( final double scale_distance ) {
4269 _scale_distance = scale_distance;
4272 final private void setScaleLabel( final String scale_label ) {
4273 _scale_label = scale_label;
4276 final void setSmallFonts() {
4277 getTreeFontSet().smallFonts();
4280 final void setStartingAngle( final double starting_angle ) {
4281 _urt_starting_angle = starting_angle;
4284 final void setSuperTinyFonts() {
4285 getTreeFontSet().superTinyFonts();
4288 final void setTextAntialias() {
4289 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4290 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
4291 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
4294 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
4297 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
4298 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) {
4299 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
4302 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
4305 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING,
4306 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
4308 catch ( final Throwable e ) {
4309 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
4313 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
4314 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
4318 final void setTinyFonts() {
4319 getTreeFontSet().tinyFonts();
4323 * Set a phylogeny tree.
4326 * an instance of a Phylogeny
4328 public final void setTree( final Phylogeny t ) {
4329 _nodes_in_preorder = null;
4333 final void setTreeFile( final File treefile ) {
4334 _treefile = treefile;
4337 final private void setUpUrtFactor() {
4338 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
4339 : getVisibleRect().height;
4340 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4341 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
4344 final int max_depth = _circ_max_depth;
4345 if ( max_depth > 0 ) {
4346 setUrtFactor( d / ( 2 * max_depth ) );
4349 setUrtFactor( d / 2 );
4352 setUrtFactorOv( getUrtFactor() );
4355 final private void setUrtFactor( final float urt_factor ) {
4356 _urt_factor = urt_factor;
4359 final private void setUrtFactorOv( final float urt_factor_ov ) {
4360 _urt_factor_ov = urt_factor_ov;
4363 public final void setWaitCursor() {
4364 setCursor( WAIT_CURSOR );
4368 final void setXcorrectionFactor( final float f ) {
4369 _x_correction_factor = f;
4372 final void setXdistance( final float x ) {
4376 final void setYdistance( final float y ) {
4380 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
4382 if ( ( node.getName().length() > 0 )
4383 || ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
4384 || ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) )
4385 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
4386 || node.getBranchData().isHasConfidences() ) {
4387 _popup_buffer.setLength( 0 );
4389 if ( node.getName().length() > 0 ) {
4391 _popup_buffer.append( node.getName() );
4393 if ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
4395 boolean enc_data = false;
4396 final Taxonomy tax = node.getNodeData().getTaxonomy();
4397 if ( _popup_buffer.length() > 0 ) {
4398 _popup_buffer.append( "\n" );
4400 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4401 _popup_buffer.append( "[" );
4402 _popup_buffer.append( tax.getTaxonomyCode() );
4403 _popup_buffer.append( "]" );
4406 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4408 _popup_buffer.append( " " );
4410 _popup_buffer.append( tax.getScientificName() );
4413 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
4415 _popup_buffer.append( " (" );
4418 _popup_buffer.append( "(" );
4420 _popup_buffer.append( tax.getCommonName() );
4421 _popup_buffer.append( ")" );
4424 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
4426 _popup_buffer.append( " (" );
4429 _popup_buffer.append( "(" );
4431 _popup_buffer.append( tax.getAuthority() );
4432 _popup_buffer.append( ")" );
4435 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
4437 _popup_buffer.append( " [" );
4440 _popup_buffer.append( "[" );
4442 _popup_buffer.append( tax.getRank() );
4443 _popup_buffer.append( "]" );
4446 if ( tax.getSynonyms().size() > 0 ) {
4448 _popup_buffer.append( " " );
4450 _popup_buffer.append( "[" );
4452 for( final String syn : tax.getSynonyms() ) {
4453 if ( !ForesterUtil.isEmpty( syn ) ) {
4455 _popup_buffer.append( syn );
4456 if ( counter < tax.getSynonyms().size() ) {
4457 _popup_buffer.append( ", " );
4462 _popup_buffer.append( "]" );
4465 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
4466 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
4467 _popup_buffer.append( "[" );
4468 _popup_buffer.append( tax.getIdentifier().getProvider() );
4469 _popup_buffer.append( "] " );
4471 _popup_buffer.append( tax.getIdentifier().getValue() );
4475 if ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) ) {
4477 boolean enc_data = false;
4478 if ( _popup_buffer.length() > 0 ) {
4479 _popup_buffer.append( "\n" );
4481 final Sequence seq = node.getNodeData().getSequence();
4482 if ( seq.getAccession() != null ) {
4483 _popup_buffer.append( "[" );
4484 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
4485 _popup_buffer.append( seq.getAccession().getSource() );
4486 _popup_buffer.append( ":" );
4488 _popup_buffer.append( seq.getAccession().getValue() );
4489 _popup_buffer.append( "]" );
4492 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
4494 _popup_buffer.append( " [" );
4497 _popup_buffer.append( "[" );
4499 _popup_buffer.append( seq.getSymbol() );
4500 _popup_buffer.append( "]" );
4503 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
4505 _popup_buffer.append( " " );
4507 _popup_buffer.append( seq.getName() );
4510 if ( node.getNodeData().isHasDate() ) {
4512 if ( _popup_buffer.length() > 0 ) {
4513 _popup_buffer.append( "\n" );
4515 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
4517 if ( node.getNodeData().isHasDistribution() ) {
4519 if ( _popup_buffer.length() > 0 ) {
4520 _popup_buffer.append( "\n" );
4522 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
4524 if ( node.getBranchData().isHasConfidences() ) {
4525 final List<Confidence> confs = node.getBranchData().getConfidences();
4526 for( final Confidence confidence : confs ) {
4528 if ( _popup_buffer.length() > 0 ) {
4529 _popup_buffer.append( "\n" );
4531 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
4532 _popup_buffer.append( "[" );
4533 _popup_buffer.append( confidence.getType() );
4534 _popup_buffer.append( "] " );
4537 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
4539 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4542 if ( _popup_buffer.length() > 0 ) {
4543 if ( !getConfiguration().isUseNativeUI() ) {
4545 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
4546 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
4547 if ( isInFoundNodes( node ) ) {
4548 _rollover_popup.setForeground( getTreeColorSet().getFoundColor() );
4550 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4551 _rollover_popup.setForeground( getTaxonomyBasedColor( node ) );
4554 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
4558 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
4560 _rollover_popup.setText( _popup_buffer.toString() );
4561 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
4563 e.getLocationOnScreen().x + 10,
4564 e.getLocationOnScreen().y
4566 _node_desc_popup.show();
4570 catch ( final Exception ex ) {
4575 final private void showNodeEditFrame( final PhylogenyNode n ) {
4576 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4577 // pop up edit box for single node
4578 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
4579 _node_frame_index++;
4582 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4586 final private void showNodeFrame( final PhylogenyNode n ) {
4587 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4588 // pop up edit box for single node
4589 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
4590 _node_frame_index++;
4593 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4597 final void subTree( final PhylogenyNode node ) {
4598 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4599 JOptionPane.showMessageDialog( this,
4600 "Cannot get a sub/super tree in unrooted display",
4601 "Attempt to get sub/super tree in unrooted display",
4602 JOptionPane.WARNING_MESSAGE );
4605 if ( node.isExternal() ) {
4606 JOptionPane.showMessageDialog( this,
4607 "Cannot get a subtree of a external node",
4608 "Attempt to get subtree of external node",
4609 JOptionPane.WARNING_MESSAGE );
4612 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
4613 JOptionPane.showMessageDialog( this,
4614 "Cannot get a subtree of the root node",
4615 "Attempt to get subtree of root node",
4616 JOptionPane.WARNING_MESSAGE );
4619 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
4620 _sub_phylogenies[ _subtree_index ] = _phylogeny;
4621 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
4623 _phylogeny = subTree( node, _phylogeny );
4624 updateSubSuperTreeButton();
4626 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
4629 _main_panel.getControlPanel().showWhole();
4633 final boolean isCurrentTreeIsSubtree() {
4634 return ( _subtree_index > 0 );
4637 final private static Phylogeny subTree( final PhylogenyNode new_root, final Phylogeny source_phy ) {
4638 final Phylogeny new_phy = new Phylogeny();
4639 new_phy.setRooted( true );
4640 new_phy.setName( source_phy.getName() );
4641 new_phy.setDescription( source_phy.getDescription() );
4642 new_phy.setType( source_phy.getType() );
4643 new_phy.setDistanceUnit( source_phy.getDistanceUnit() );
4644 new_phy.setConfidence( source_phy.getConfidence() );
4645 new_phy.setIdentifier( source_phy.getIdentifier() );
4646 new_phy.setRoot( new_root.copyNodeDataShallow() );
4648 for( final PhylogenyNode n : new_root.getDescendants() ) {
4649 new_phy.getRoot().setChildNode( i++, n );
4654 final void superTree() {
4655 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
4656 for( final PhylogenyNode n : temp_root.getDescendants() ) {
4657 n.setParent( temp_root );
4659 _sub_phylogenies[ _subtree_index ] = null;
4660 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
4661 _phylogeny = _sub_phylogenies[ --_subtree_index ];
4662 updateSubSuperTreeButton();
4665 final void swap( final PhylogenyNode node ) {
4666 if ( !node.isExternal() ) {
4667 _phylogeny.swapChildren( node );
4668 _nodes_in_preorder = null;
4673 final private void switchDisplaygetPhylogenyGraphicsType() {
4674 switch ( getPhylogenyGraphicsType() ) {
4676 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4677 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4680 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4681 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4684 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4685 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4688 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4689 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4692 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4693 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4696 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4697 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
4700 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4701 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
4704 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4705 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
4708 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
4710 if ( getControlPanel().getDynamicallyHideData() != null ) {
4711 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4712 getControlPanel().getDynamicallyHideData().setEnabled( false );
4715 getControlPanel().getDynamicallyHideData().setEnabled( true );
4718 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
4719 getControlPanel().setDrawPhylogramEnabled( true );
4722 getControlPanel().setDrawPhylogramEnabled( false );
4724 if ( getMainPanel().getMainFrame() == null ) {
4725 // Must be "E" applet version.
4726 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
4727 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4730 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
4734 final void taxColor() {
4735 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
4739 Util.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
4740 _control_panel.setColorBranches( true );
4741 if ( _control_panel.getColorBranchesCb() != null ) {
4742 _control_panel.getColorBranchesCb().setSelected( true );
4748 final void updateOvSettings() {
4749 switch ( getOptions().getOvPlacement() ) {
4751 setOvXPosition( OV_BORDER );
4752 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
4753 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
4756 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
4757 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
4758 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
4761 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
4762 setOvYPosition( OV_BORDER );
4763 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
4766 setOvXPosition( OV_BORDER );
4767 setOvYPosition( OV_BORDER );
4768 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
4773 final void updateOvSizes() {
4774 if ( ( getWidth() > 1.05 * getVisibleRect().width ) || ( getHeight() > 1.05 * getVisibleRect().height ) ) {
4776 float l = getLongestExtNodeInfo();
4777 final float w_ratio = getOvMaxWidth() / getWidth();
4779 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4780 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
4782 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4783 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
4786 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
4788 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
4789 if ( ov_xdist < 0.0 ) {
4792 if ( ydist < 0.0 ) {
4795 setOvXDistance( ov_xdist );
4796 final double height = _phylogeny.getHeight();
4798 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
4799 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4802 setOvXcorrectionFactor( 0 );
4810 final void updateSubSuperTreeButton() {
4811 if ( _subtree_index < 1 ) {
4812 getControlPanel().deactivateButtonToReturnToSuperTree();
4815 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
4819 final void zoomInDomainStructure() {
4820 if ( _domain_structure_width < 2000 ) {
4821 _domain_structure_width *= 1.2;
4825 final void zoomOutDomainStructure() {
4826 if ( _domain_structure_width > 20 ) {
4827 _domain_structure_width *= 0.8;
4831 final private static void drawString( final int i, final double x, final double y, final Graphics2D g ) {
4832 g.drawString( String.valueOf( i ), ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
4835 final private static void drawString( final String str, final double x, final double y, final Graphics2D g ) {
4836 g.drawString( str, ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
4839 final private static boolean isSequenceEmpty( final Sequence seq ) {
4840 return ( seq.getAccession() == null ) && ForesterUtil.isEmpty( seq.getName() )
4841 && ForesterUtil.isEmpty( seq.getSymbol() );
4844 final private static boolean isTaxonomyEmpty( final Taxonomy tax ) {
4845 return ( ( tax.getIdentifier() == null ) && ForesterUtil.isEmpty( tax.getTaxonomyCode() )
4846 && ForesterUtil.isEmpty( tax.getCommonName() ) && ForesterUtil.isEmpty( tax.getScientificName() ) && tax
4847 .getSynonyms().isEmpty() );
4850 final private static boolean plusPressed( final int key_code ) {
4851 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
4852 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
4855 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
4856 _statistics_for_vector_data = statistics_for_expression_values;
4859 DescriptiveStatistics getStatisticsForExpressionValues() {
4860 return _statistics_for_vector_data;
4863 final private class SubtreeColorizationActionListener implements ActionListener {
4865 JColorChooser _chooser;
4866 PhylogenyNode _node;
4868 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
4874 public void actionPerformed( final ActionEvent e ) {
4875 final Color c = _chooser.getColor();
4877 colorizeSubtree( c, _node );
4882 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
4883 getMainPanel().setImageMap( image_map );
4886 public synchronized Hashtable<String, BufferedImage> getImageMap() {
4887 return getMainPanel().getImageMap();