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.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
104 import org.forester.phylogeny.PhylogenyNode;
105 import org.forester.phylogeny.data.Annotation;
106 import org.forester.phylogeny.data.BranchColor;
107 import org.forester.phylogeny.data.Confidence;
108 import org.forester.phylogeny.data.Event;
109 import org.forester.phylogeny.data.NodeVisualization;
110 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
111 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
112 import org.forester.phylogeny.data.PhylogenyData;
113 import org.forester.phylogeny.data.PhylogenyDataUtil;
114 import org.forester.phylogeny.data.PropertiesMap;
115 import org.forester.phylogeny.data.Property;
116 import org.forester.phylogeny.data.Sequence;
117 import org.forester.phylogeny.data.SequenceRelation;
118 import org.forester.phylogeny.data.Taxonomy;
119 import org.forester.phylogeny.data.Uri;
120 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
121 import org.forester.phylogeny.iterators.PreorderTreeIterator;
122 import org.forester.util.BasicDescriptiveStatistics;
123 import org.forester.util.DescriptiveStatistics;
124 import org.forester.util.ForesterConstants;
125 import org.forester.util.ForesterUtil;
127 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
129 private static final float PI = ( float ) ( Math.PI );
130 private static final double TWO_PI = 2 * Math.PI;
131 private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI );
132 private static final float HALF_PI = ( float ) ( Math.PI / 2.0 );
133 private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 );
134 private static final short OV_BORDER = 10;
135 final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
136 final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
137 final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
138 final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
139 final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
140 private final static long serialVersionUID = -978349745916505029L;
141 private final static int EURO_D = 10;
142 private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
143 private final static int MIN_ROOT_LENGTH = 3;
144 private final static int MAX_SUBTREES = 100;
145 private final static int MAX_NODE_FRAMES = 10;
146 private final static int MOVE = 20;
147 private final static NumberFormat FORMATTER_CONFIDENCE;
148 private final static NumberFormat FORMATTER_BRANCH_LENGTH;
149 private final static int WIGGLE = 2;
150 private final static int LIMIT_FOR_HQ_RENDERING = 1000;
151 private final static int CONFIDENCE_LEFT_MARGIN = 4;
152 // TODO "rendering_hints" was static before. Need to make sure everything is OK with it not
153 // being static anymore (02/20/2009).
154 private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
155 RenderingHints.VALUE_RENDER_DEFAULT );
156 private File _treefile = null;
157 private Configuration _configuration = null;
158 private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
159 private int _node_frame_index = 0;
160 private Phylogeny _phylogeny = null;
161 private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ];
162 private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
163 private int _subtree_index = 0;
164 private MainPanel _main_panel = null;
165 private Set<Integer> _found_nodes = null;
166 private PhylogenyNode _highlight_node = null;
167 private JPopupMenu _node_popup_menu = null;
168 private JMenuItem _node_popup_menu_items[] = null;
169 private int _longest_ext_node_info = 0;
170 private float _x_correction_factor = 0.0f;
171 private float _ov_x_correction_factor = 0.0f;
172 private float _x_distance = 0.0f;
173 private float _y_distance = 0.0f;
174 private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
175 private double _domain_structure_width = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
176 private int _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
177 private float _last_drag_point_x = 0;
178 private float _last_drag_point_y = 0;
179 private ControlPanel _control_panel = null;
180 private int _external_node_index = 0;
181 private final Polygon _polygon = new Polygon();
182 private final StringBuilder _sb = new StringBuilder();
183 private JColorChooser _color_chooser = null;
184 private double _scale_distance = 0.0;
185 private String _scale_label = null;
186 private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float();
187 private final QuadCurve2D _quad_curve = new QuadCurve2D.Float();
188 private final Line2D _line = new Line2D.Float();
189 private final Ellipse2D _ellipse = new Ellipse2D.Float();
190 private final Rectangle2D _rectangle = new Rectangle2D.Float();
191 private Options _options = null;
192 private float _ov_max_width = 0;
193 private float _ov_max_height = 0;
194 private int _ov_x_position = 0;
195 private int _ov_y_position = 0;
196 private int _ov_y_start = 0;
197 private float _ov_y_distance = 0;
198 private float _ov_x_distance = 0;
199 private boolean _ov_on = false;
200 private double _urt_starting_angle = ( float ) ( Math.PI / 2 );
201 private float _urt_factor = 1;
202 private float _urt_factor_ov = 1;
203 private final boolean _phy_has_branch_lengths;
204 private final Rectangle2D _ov_rectangle = new Rectangle2D.Float();
205 private boolean _in_ov_rect = false;
206 private boolean _in_ov = false;
207 private final Rectangle _ov_virtual_rectangle = new Rectangle();
208 final private static double _180_OVER_PI = 180.0 / Math.PI;
209 private static final float ROUNDED_D = 8;
210 private int _circ_max_depth;
211 private PhylogenyNode _root;
212 final private Arc2D _arc = new Arc2D.Double();
213 final private HashMap<Integer, Double> _urt_nodeid_angle_map = new HashMap<Integer, Double>();
214 final private HashMap<Integer, Integer> _urt_nodeid_index_map = new HashMap<Integer, Integer>();
215 final private Set<Integer> _collapsed_external_nodeid_set = new HashSet<Integer>();
216 HashMap<Integer, Short> _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
217 private AffineTransform _at;
218 private double _max_distance_to_root = -1;
219 private int _dynamic_hiding_factor = 0;
220 private boolean _edited = false;
221 private Popup _node_desc_popup;
222 private JTextArea _rollover_popup;
223 // private final int _box_size;
224 // private final int _half_box_size;
225 //private final short _skip_counter = 0;
226 private final StringBuffer _popup_buffer = new StringBuffer();
227 final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(),
230 private static final boolean DRAW_MEAN_COUNTS = true; //TODO remove me later
231 private Sequence _query_sequence = null;
232 private final FontRenderContext _frc = new FontRenderContext( null,
235 // expression values menu:
236 private DescriptiveStatistics _statistics_for_vector_data;
237 private PhylogenyNode[] _nodes_in_preorder = null;
238 // private Image offscreenImage;
239 // private Graphics offscreenGraphics;
240 // private Dimension offscreenDimension;
242 final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
243 dfs.setDecimalSeparator( '.' );
244 FORMATTER_CONFIDENCE = new DecimalFormat( "#.###", dfs );
245 FORMATTER_BRANCH_LENGTH = new DecimalFormat( "#.###", dfs );
248 TreePanel( final Phylogeny t, final Configuration configuration, final MainPanel tjp ) {
249 requestFocusInWindow();
250 addKeyListener( new KeyAdapter() {
253 public void keyPressed( final KeyEvent key_event ) {
254 keyPressedCalls( key_event );
255 requestFocusInWindow();
258 addFocusListener( new FocusAdapter() {
261 public void focusGained( final FocusEvent e ) {
262 requestFocusInWindow();
265 if ( ( t == null ) || t.isEmpty() ) {
266 throw new IllegalArgumentException( "attempt to draw phylogeny which is null or empty" );
268 _graphics_type = tjp.getOptions().getPhylogenyGraphicsType();
270 _configuration = configuration;
272 _phy_has_branch_lengths = AptxUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny );
274 // if ( !_phylogeny.isEmpty() ) {
275 _phylogeny.recalculateNumberOfExternalDescendants( true );
276 checkForVectorProperties( _phylogeny );
278 setBackground( getTreeColorSet().getBackgroundColor() );
279 final MouseListener mouse_listener = new MouseListener( this );
280 addMouseListener( mouse_listener );
281 addMouseMotionListener( mouse_listener );
282 addMouseWheelListener( this );
283 calculateScaleDistance();
284 FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() );
285 FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration
286 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
289 public void checkForVectorProperties( final Phylogeny phy ) {
290 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
291 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
292 final PhylogenyNode node = iter.next();
293 if ( node.getNodeData().getProperties() != null ) {
294 final PropertiesMap pm = node.getNodeData().getProperties();
295 final double[] vector = new double[ pm.getProperties().size() ];
297 for( final String ref : pm.getProperties().keySet() ) {
298 if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
299 final Property p = pm.getProperty( ref );
300 final String value_str = p.getValue();
301 final String index_str = ref
302 .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() );
305 d = Double.parseDouble( value_str );
307 catch ( final NumberFormatException e ) {
308 JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str
309 + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE );
314 i = Integer.parseInt( index_str );
316 catch ( final NumberFormatException e ) {
317 JOptionPane.showMessageDialog( this,
318 "Could not parse \"" + index_str
319 + "\" into index for vector data",
320 "Problem with Vector Data",
321 JOptionPane.ERROR_MESSAGE );
325 JOptionPane.showMessageDialog( this,
326 "Attempt to use negative index for vector data",
327 "Problem with Vector Data",
328 JOptionPane.ERROR_MESSAGE );
336 final List<Double> vector_l = new ArrayList<Double>( counter );
337 for( int i = 0; i < counter; ++i ) {
338 vector_l.add( vector[ i ] );
340 node.getNodeData().setVector( vector_l );
343 if ( stats.getN() > 0 ) {
344 _statistics_for_vector_data = stats;
348 final public void actionPerformed( final ActionEvent e ) {
349 boolean done = false;
350 final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource();
351 for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) {
352 // NOTE: index corresponds to the indices of click-to options
353 // in the control panel.
354 if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) {
355 // Set this as the new default click-to action
356 _main_panel.getControlPanel().setClickToAction( index );
357 final PhylogenyNode node = ( PhylogenyNode ) _node_popup_menu
358 .getClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY );
359 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
364 requestFocusInWindow();
367 final private void addEmptyNode( final PhylogenyNode node ) {
368 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
369 errorMessageNoCutCopyPasteInUnrootedDisplay();
372 final String label = getASimpleTextRepresentationOfANode( node );
374 if ( ForesterUtil.isEmpty( label ) ) {
375 msg = "How to add the new, empty node?";
378 msg = "How to add the new, empty node to node" + label + "?";
380 final Object[] options = { "As sibling", "As descendant", "Cancel" };
381 final int r = JOptionPane.showOptionDialog( this,
383 "Addition of Empty New Node",
384 JOptionPane.CLOSED_OPTION,
385 JOptionPane.QUESTION_MESSAGE,
389 boolean add_as_sibling = true;
391 add_as_sibling = false;
396 final Phylogeny phy = new Phylogeny();
397 phy.setRoot( new PhylogenyNode() );
398 phy.setRooted( true );
399 if ( add_as_sibling ) {
400 if ( node.isRoot() ) {
401 JOptionPane.showMessageDialog( this,
402 "Cannot add sibling to root",
403 "Attempt to add sibling to root",
404 JOptionPane.ERROR_MESSAGE );
407 phy.addAsSibling( node );
410 phy.addAsChild( node );
412 setNodeInPreorderToNull();
413 _phylogeny.externalNodesHaveChanged();
414 _phylogeny.hashIDs();
415 _phylogeny.recalculateNumberOfExternalDescendants( true );
416 resetNodeIdToDistToLeafMap();
421 final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
422 final boolean is_vertical,
424 final boolean to_pdf,
425 final boolean to_graphics_file ) {
426 final NodeClickAction action = _control_panel.getActionWhenNodeClicked();
427 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
428 g.setColor( Color.BLACK );
430 else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE )
431 || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) )
432 && ( getCutOrCopiedTree() != null )
433 && ( getCopiedAndPastedNodes() != null )
435 && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) {
436 g.setColor( getTreeColorSet().getFoundColor() );
438 else if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
439 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
442 g.setColor( getTreeColorSet().getBranchColorForPdf() );
445 g.setColor( getTreeColorSet().getBranchColor() );
449 final Color getGraphicsForNodeBoxWithColorForParentBranch( final PhylogenyNode node ) {
450 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
451 return ( PhylogenyMethods.getBranchColorValue( node ) );
454 return ( getTreeColorSet().getBranchColor() );
458 final private void blast( final PhylogenyNode node ) {
459 if ( !isCanBlast( node ) ) {
460 JOptionPane.showMessageDialog( this,
461 "No sequence information present",
463 JOptionPane.WARNING_MESSAGE );
466 if ( node.getNodeData().isHasSequence() ) {
467 final String query = Blast.obtainQueryForBlast( node );
468 boolean nucleotide = false;
469 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) {
470 if ( !node.getNodeData().getSequence().getType().toLowerCase().equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) {
474 else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
475 nucleotide = !ForesterUtil.seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() );
477 if ( !ForesterUtil.isEmpty( query ) ) {
478 JApplet applet = null;
480 applet = obtainApplet();
483 Blast.openNcbiBlastWeb( query, nucleotide, applet, this );
485 catch ( final Exception e ) {
488 if ( Constants.ALLOW_DDBJ_BLAST ) {
490 System.out.println( "trying: " + query );
491 final Blast s = new Blast();
492 s.ddbjBlast( query );
494 catch ( final Exception e ) {
502 final void calcMaxDepth() {
503 if ( _phylogeny != null ) {
504 _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
509 * Calculate the length of the distance between the given node and its
515 * @return the distance value
517 final private float calculateBranchLengthToParent( final PhylogenyNode node, final float factor ) {
518 if ( getControlPanel().isDrawPhylogram() ) {
519 if ( node.getDistanceToParent() < 0.0 ) {
522 return ( float ) ( getXcorrectionFactor() * node.getDistanceToParent() );
525 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
526 return getXdistance();
528 return getXdistance() * factor;
532 final private Color calculateColorForAnnotation( final PhylogenyData ann ) {
533 Color c = getTreeColorSet().getAnnotationColor();
534 if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
535 c = getControlPanel().getAnnotationColors().get( ann.asSimpleText().toString() );
537 c = getTreeColorSet().getAnnotationColor();
543 final void calculateLongestExtNodeInfo() {
544 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
548 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
550 if ( node.isCollapse() ) {
553 if ( getControlPanel().isShowNodeNames() ) {
554 sum += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
556 if ( node.getNodeData().isHasSequence() ) {
557 if ( getControlPanel().isShowSequenceAcc()
558 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
559 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
563 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
564 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
566 if ( getControlPanel().isShowGeneSymbols()
567 && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
568 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
570 if ( getControlPanel().isShowAnnotation()
571 && ( node.getNodeData().getSequence().getAnnotations() != null )
572 && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
573 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAnnotation( 0 )
578 if ( node.getNodeData().isHasTaxonomy() ) {
579 final Taxonomy tax = node.getNodeData().getTaxonomy();
580 if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
581 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getTaxonomyCode() + " " );
583 if ( getControlPanel().isShowTaxonomyScientificNames()
584 && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
585 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getScientificName() + " " );
587 if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
588 sum += getTreeFontSet()._fm_large_italic.stringWidth( tax.getCommonName() + " ()" );
591 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
592 sum += getTreeFontSet()._fm_large.stringWidth( propertiesToString( node ).toString() );
594 if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
595 sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters()
596 .getGainedCharactersAsStringBuffer().toString() );
598 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
599 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
600 sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() )
601 .getRenderingSize().getWidth();
603 if ( sum >= Constants.EXT_NODE_INFO_LENGTH_MAX ) {
604 setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX );
607 if ( sum > longest ) {
611 if ( longest >= Constants.EXT_NODE_INFO_LENGTH_MAX ) {
612 setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX );
615 setLongestExtNodeInfo( longest );
619 final private float calculateOvBranchLengthToParent( final PhylogenyNode node, final int factor ) {
620 if ( getControlPanel().isDrawPhylogram() ) {
621 if ( node.getDistanceToParent() < 0.0 ) {
624 return ( float ) ( getOvXcorrectionFactor() * node.getDistanceToParent() );
627 if ( ( factor == 0 ) || isNonLinedUpCladogram() ) {
628 return getOvXDistance();
630 return getOvXDistance() * factor;
634 final void calculateScaleDistance() {
635 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
638 final double height = getMaxDistanceToRoot();
640 if ( ( height <= 0.5 ) ) {
641 setScaleDistance( 0.01 );
643 else if ( height <= 5.0 ) {
644 setScaleDistance( 0.1 );
646 else if ( height <= 50.0 ) {
647 setScaleDistance( 1 );
649 else if ( height <= 500.0 ) {
650 setScaleDistance( 10 );
653 setScaleDistance( 100 );
657 setScaleDistance( 0.0 );
659 String scale_label = String.valueOf( getScaleDistance() );
660 if ( !ForesterUtil.isEmpty( _phylogeny.getDistanceUnit() ) ) {
661 scale_label += " [" + _phylogeny.getDistanceUnit() + "]";
663 setScaleLabel( scale_label );
666 final Color calculateTaxonomyBasedColor( final Taxonomy tax ) {
667 String species = tax.getTaxonomyCode();
668 if ( ForesterUtil.isEmpty( species ) ) {
669 species = tax.getScientificName();
670 if ( ForesterUtil.isEmpty( species ) ) {
671 species = tax.getCommonName();
674 if ( ForesterUtil.isEmpty( species ) ) {
675 return getTreeColorSet().getTaxonomyColor();
677 // Look in species hash
678 Color c = getControlPanel().getSpeciesColors().get( species );
680 c = AptxUtil.calculateColorFromString( species );
681 getControlPanel().getSpeciesColors().put( species, c );
686 final private void cannotOpenBrowserWarningMessage( final String type_type ) {
687 JOptionPane.showMessageDialog( this,
688 "Cannot launch web browser for " + type_type + " data of this node",
689 "Cannot launch web browser",
690 JOptionPane.WARNING_MESSAGE );
694 * Collapse the tree from the given node
699 final void collapse( final PhylogenyNode node ) {
700 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
701 JOptionPane.showMessageDialog( this,
702 "Cannot collapse in unrooted display type",
703 "Attempt to collapse in unrooted display",
704 JOptionPane.WARNING_MESSAGE );
707 if ( !node.isExternal() && !node.isRoot() ) {
708 final boolean collapse = !node.isCollapse();
709 AptxUtil.collapseSubtree( node, collapse );
710 updateSetOfCollapsedExternalNodes( _phylogeny );
711 _phylogeny.recalculateNumberOfExternalDescendants( true );
712 resetNodeIdToDistToLeafMap();
713 calculateLongestExtNodeInfo();
714 setNodeInPreorderToNull();
715 _control_panel.displayedPhylogenyMightHaveChanged( true );
716 resetPreferredSize();
718 _main_panel.adjustJScrollPane();
723 final void collapseSpeciesSpecificSubtrees() {
724 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
728 AptxUtil.collapseSpeciesSpecificSubtrees( _phylogeny );
729 updateSetOfCollapsedExternalNodes( _phylogeny );
730 _phylogeny.recalculateNumberOfExternalDescendants( true );
731 resetNodeIdToDistToLeafMap();
732 calculateLongestExtNodeInfo();
733 setNodeInPreorderToNull();
734 resetPreferredSize();
735 _main_panel.adjustJScrollPane();
740 final private void colorizeSubtree( final Color c, final PhylogenyNode node ) {
741 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
742 JOptionPane.showMessageDialog( this,
743 "Cannot colorize subtree in unrooted display type",
744 "Attempt to colorize subtree in unrooted display",
745 JOptionPane.WARNING_MESSAGE );
748 _control_panel.setColorBranches( true );
749 if ( _control_panel.getColorBranchesCb() != null ) {
750 _control_panel.getColorBranchesCb().setSelected( true );
752 for( final PreorderTreeIterator it = new PreorderTreeIterator( node ); it.hasNext(); ) {
753 it.next().getBranchData().setBranchColor( new BranchColor( c ) );
758 final private void colorSubtree( final PhylogenyNode node ) {
759 Color intitial_color = null;
760 if ( getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null )
761 && ( ( ( !node.isRoot() && ( node.getParent().getNumberOfDescendants() < 3 ) ) ) || ( node.isRoot() ) ) ) {
762 intitial_color = PhylogenyMethods.getBranchColorValue( node );
765 intitial_color = getTreeColorSet().getBranchColor();
767 _color_chooser.setColor( intitial_color );
768 _color_chooser.setPreviewPanel( new JPanel() );
769 final JDialog dialog = JColorChooser
771 "Subtree colorization",
774 new SubtreeColorizationActionListener( _color_chooser, node ),
776 dialog.setVisible( true );
779 final void confColor() {
780 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
784 AptxUtil.removeBranchColors( _phylogeny );
785 AptxUtil.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this );
786 _control_panel.setColorBranches( true );
787 if ( _control_panel.getColorBranchesCb() != null ) {
788 _control_panel.getColorBranchesCb().setSelected( true );
794 final void colorRank( final String rank ) {
795 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
799 AptxUtil.removeBranchColors( _phylogeny );
800 final int colorizations = AptxUtil.colorPhylogenyAccordingToRanks( _phylogeny, rank, this );
801 if ( colorizations > 0 ) {
802 _control_panel.setColorBranches( true );
803 if ( _control_panel.getColorBranchesCb() != null ) {
804 _control_panel.getColorBranchesCb().setSelected( true );
806 if ( _control_panel.getColorAccSpeciesCb() != null ) {
807 _control_panel.getColorAccSpeciesCb().setSelected( false );
809 _options.setColorLabelsSameAsParentBranch( true );
810 _control_panel.repaint();
814 if ( colorizations > 0 ) {
815 String msg = "Taxonomy colorization via " + rank + " completed:\n";
816 if ( colorizations > 1 ) {
817 msg += "colorized " + colorizations + " subtrees";
820 msg += "colorized one subtree";
822 JOptionPane.showMessageDialog( this,
824 "Taxonomy Colorization Completed (" + rank + ")",
825 JOptionPane.INFORMATION_MESSAGE );
828 String msg = "Could not taxonomy colorize any subtree via " + rank + ".\n";
829 msg += "Possible solutions (given that suitable taxonomic information is present):\n";
830 msg += "select a different rank (e.g. phylum, genus, ...)\n";
833 msg += "1. \"" + MainFrameApplication.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n";
834 msg += "2. \"" + MainFrameApplication.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)";
835 JOptionPane.showMessageDialog( this, msg, "Taxonomy Colorization Failed", JOptionPane.WARNING_MESSAGE );
839 final private void copySubtree( final PhylogenyNode node ) {
840 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
841 errorMessageNoCutCopyPasteInUnrootedDisplay();
844 setNodeInPreorderToNull();
845 setCutOrCopiedTree( _phylogeny.copy( node ) );
846 final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
847 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
848 for( final PhylogenyNode n : nodes ) {
849 node_ids.add( n.getId() );
851 node_ids.add( node.getId() );
852 setCopiedAndPastedNodes( node_ids );
856 final private void cutSubtree( final PhylogenyNode node ) {
857 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
858 errorMessageNoCutCopyPasteInUnrootedDisplay();
861 if ( node.isRoot() ) {
862 JOptionPane.showMessageDialog( this,
863 "Cannot cut entire tree as subtree",
864 "Attempt to cut entire tree",
865 JOptionPane.ERROR_MESSAGE );
868 final String label = getASimpleTextRepresentationOfANode( node );
869 final int r = JOptionPane.showConfirmDialog( null,
870 "Cut subtree" + label + "?",
871 "Confirm Cutting of Subtree",
872 JOptionPane.YES_NO_OPTION );
873 if ( r != JOptionPane.OK_OPTION ) {
876 setNodeInPreorderToNull();
877 setCopiedAndPastedNodes( null );
878 setCutOrCopiedTree( _phylogeny.copy( node ) );
879 _phylogeny.deleteSubtree( node, true );
880 _phylogeny.hashIDs();
881 _phylogeny.recalculateNumberOfExternalDescendants( true );
882 resetNodeIdToDistToLeafMap();
887 final private void cycleColors() {
888 getMainPanel().getTreeColorSet().cycleColorScheme();
889 for( final TreePanel tree_panel : getMainPanel().getTreePanels() ) {
890 tree_panel.setBackground( getMainPanel().getTreeColorSet().getBackgroundColor() );
894 final void decreaseDomainStructureEvalueThreshold() {
895 if ( _domain_structure_e_value_thr_exp > -20 ) {
896 _domain_structure_e_value_thr_exp -= 1;
900 final private void decreaseOvSize() {
901 if ( ( getOvMaxWidth() > 20 ) && ( getOvMaxHeight() > 20 ) ) {
902 setOvMaxWidth( getOvMaxWidth() - 5 );
903 setOvMaxHeight( getOvMaxHeight() - 5 );
905 getControlPanel().displayedPhylogenyMightHaveChanged( false );
909 final private void deleteNodeOrSubtree( final PhylogenyNode node ) {
910 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
911 errorMessageNoCutCopyPasteInUnrootedDisplay();
914 if ( node.isRoot() ) {
915 JOptionPane.showMessageDialog( this,
916 "Cannot delete entire tree",
917 "Attempt to delete entire tree",
918 JOptionPane.ERROR_MESSAGE );
921 final String label = getASimpleTextRepresentationOfANode( node );
922 final Object[] options = { "Node only", "Entire subtree", "Cancel" };
923 final int r = JOptionPane.showOptionDialog( this,
924 "Delete" + label + "?",
925 "Delete Node/Subtree",
926 JOptionPane.CLOSED_OPTION,
927 JOptionPane.QUESTION_MESSAGE,
931 setNodeInPreorderToNull();
932 boolean node_only = true;
940 PhylogenyMethods.removeNode( node, _phylogeny );
943 _phylogeny.deleteSubtree( node, true );
945 _phylogeny.externalNodesHaveChanged();
946 _phylogeny.hashIDs();
947 _phylogeny.recalculateNumberOfExternalDescendants( true );
948 resetNodeIdToDistToLeafMap();
953 final private void displayNodePopupMenu( final PhylogenyNode node, final int x, final int y ) {
954 makePopupMenus( node );
955 _node_popup_menu.putClientProperty( NODE_POPMENU_NODE_CLIENT_PROPERTY, node );
956 _node_popup_menu.show( this, x, y );
959 final private void drawArc( final double x,
963 final double start_angle,
964 final double arc_angle,
965 final Graphics2D g ) {
966 _arc.setArc( x, y, width, heigth, _180_OVER_PI * start_angle, _180_OVER_PI * arc_angle, Arc2D.OPEN );
970 final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) {
971 if ( ( x1 == x2 ) && ( y1 == y2 ) ) {
974 _line.setLine( x1, y1, x2, y2 );
978 final private void drawOval( final double x,
982 final Graphics2D g ) {
983 _ellipse.setFrame( x, y, width, heigth );
987 final private void drawOvalFilled( final double x,
991 final Graphics2D g ) {
992 _ellipse.setFrame( x, y, width, heigth );
996 final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) {
997 _rectangle.setFrame( x, y, width, heigth );
998 g.draw( _rectangle );
1001 final private void drawRectFilled( final double x,
1004 final double heigth,
1005 final Graphics2D g ) {
1006 _rectangle.setFrame( x, y, width, heigth );
1007 g.fill( _rectangle );
1010 final private void drawRectGradient( final double x,
1013 final double heigth,
1015 final Color color_1,
1016 final Color color_2,
1017 final Color color_border ) {
1018 _rectangle.setFrame( x, y, width, heigth );
1019 g.setPaint( new GradientPaint( ( float ) x,
1022 ( float ) ( x + width ),
1023 ( float ) ( y + heigth ),
1026 g.fill( _rectangle );
1027 if ( color_border != null ) {
1028 g.setPaint( color_border );
1029 g.draw( _rectangle );
1033 final private void drawOvalGradient( final double x,
1036 final double heigth,
1038 final Color color_1,
1039 final Color color_2,
1040 final Color color_border ) {
1041 _ellipse.setFrame( x, y, width, heigth );
1042 g.setPaint( new GradientPaint( ( float ) x,
1045 ( float ) ( x + width ),
1046 ( float ) ( y + heigth ),
1050 if ( color_border != null ) {
1051 g.setPaint( color_border );
1056 final private void errorMessageNoCutCopyPasteInUnrootedDisplay() {
1057 JOptionPane.showMessageDialog( this,
1058 "Cannot cut, copy, paste, add, or delete subtrees/nodes in unrooted display",
1059 "Attempt to cut/copy/paste/add/delete in unrooted display",
1060 JOptionPane.ERROR_MESSAGE );
1064 * Find the node, if any, at the given location
1068 * @return pointer to the node at x,y, null if not found
1070 final PhylogenyNode findNode( final int x, final int y ) {
1071 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1074 final int half_box_size_plus_wiggle = getOptions().getDefaultNodeShapeSize() / 2 + WIGGLE;
1075 for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) {
1076 final PhylogenyNode node = iter.next();
1077 if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) )
1078 && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x )
1079 && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x )
1080 && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y )
1081 && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) {
1088 final private String getASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
1089 final String tax = PhylogenyMethods.getSpecies( node );
1090 String label = node.getName();
1091 if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) {
1092 label = label + " " + tax;
1094 else if ( !ForesterUtil.isEmpty( tax ) ) {
1100 if ( !ForesterUtil.isEmpty( label ) ) {
1101 label = " [" + label + "]";
1106 final Configuration getConfiguration() {
1107 return _configuration;
1110 final ControlPanel getControlPanel() {
1111 return _control_panel;
1114 final private Set<Integer> getCopiedAndPastedNodes() {
1115 return getMainPanel().getCopiedAndPastedNodes();
1118 final private Phylogeny getCutOrCopiedTree() {
1119 return getMainPanel().getCutOrCopiedTree();
1122 final int getDomainStructureEvalueThreshold() {
1123 return _domain_structure_e_value_thr_exp;
1126 final Set<Integer> getFoundNodes() {
1127 return _found_nodes;
1130 final private float getLastDragPointX() {
1131 return _last_drag_point_x;
1134 final private float getLastDragPointY() {
1135 return _last_drag_point_y;
1138 final int getLongestExtNodeInfo() {
1139 return _longest_ext_node_info;
1142 final public MainPanel getMainPanel() {
1146 final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
1147 if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
1148 final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
1149 _nodeid_dist_to_leaf.put( node.getId(), m );
1153 return _nodeid_dist_to_leaf.get( node.getId() );
1157 final private double getMaxDistanceToRoot() {
1158 if ( _max_distance_to_root < 0 ) {
1159 recalculateMaxDistanceToRoot();
1161 return _max_distance_to_root;
1164 final Options getOptions() {
1165 if ( _options == null ) {
1166 _options = getControlPanel().getOptions();
1171 final private float getOvMaxHeight() {
1172 return _ov_max_height;
1175 final private float getOvMaxWidth() {
1176 return _ov_max_width;
1179 final Rectangle2D getOvRectangle() {
1180 return _ov_rectangle;
1183 final Rectangle getOvVirtualRectangle() {
1184 return _ov_virtual_rectangle;
1187 final private float getOvXcorrectionFactor() {
1188 return _ov_x_correction_factor;
1191 final private float getOvXDistance() {
1192 return _ov_x_distance;
1195 final private int getOvXPosition() {
1196 return _ov_x_position;
1199 final private float getOvYDistance() {
1200 return _ov_y_distance;
1203 final private int getOvYPosition() {
1204 return _ov_y_position;
1207 final private int getOvYStart() {
1212 * Get a pointer to the phylogeny
1214 * @return a pointer to the phylogeny
1216 public final Phylogeny getPhylogeny() {
1220 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
1221 return _graphics_type;
1224 final private double getScaleDistance() {
1225 return _scale_distance;
1228 final private String getScaleLabel() {
1229 return _scale_label;
1232 final double getStartingAngle() {
1233 return _urt_starting_angle;
1237 * Find a color for this species name.
1240 * @return the species color
1242 final Color getTaxonomyBasedColor( final PhylogenyNode node ) {
1243 if ( node.getNodeData().isHasTaxonomy() ) {
1244 return calculateTaxonomyBasedColor( node.getNodeData().getTaxonomy() );
1246 // return non-colorized color
1247 return getTreeColorSet().getTaxonomyColor();
1251 * @return pointer to colorset for tree drawing
1253 final TreeColorSet getTreeColorSet() {
1254 return getMainPanel().getTreeColorSet();
1257 final File getTreeFile() {
1261 final private TreeFontSet getTreeFontSet() {
1262 return getMainPanel().getTreeFontSet();
1265 final private float getUrtFactor() {
1269 final private float getUrtFactorOv() {
1270 return _urt_factor_ov;
1273 final float getXcorrectionFactor() {
1274 return _x_correction_factor;
1277 final float getXdistance() {
1281 final float getYdistance() {
1285 final private void handleClickToAction( final NodeClickAction action, final PhylogenyNode node ) {
1288 showNodeFrame( node );
1303 colorSubtree( node );
1318 copySubtree( node );
1321 pasteSubtree( node );
1323 case DELETE_NODE_OR_SUBTREE:
1324 deleteNodeOrSubtree( node );
1327 addEmptyNode( node );
1329 case EDIT_NODE_DATA:
1330 showNodeEditFrame( node );
1332 case SORT_DESCENDENTS:
1333 sortDescendants( node );
1336 throw new IllegalArgumentException( "unknown action: " + action );
1340 final void increaseDomainStructureEvalueThreshold() {
1341 if ( _domain_structure_e_value_thr_exp < 3 ) {
1342 _domain_structure_e_value_thr_exp += 1;
1346 final private void increaseOvSize() {
1347 if ( ( getOvMaxWidth() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 )
1348 && ( getOvMaxHeight() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
1349 .getHeight() / 2 ) ) {
1350 setOvMaxWidth( getOvMaxWidth() + 5 );
1351 setOvMaxHeight( getOvMaxHeight() + 5 );
1353 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1357 final void inferCommonPartOfScientificNames() {
1358 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1362 AptxUtil.inferCommonPartOfScientificNames( _phylogeny );
1367 final private void init() {
1368 _color_chooser = new JColorChooser();
1369 _rollover_popup = new JTextArea();
1370 _rollover_popup.setFont( POPUP_FONT );
1371 resetNodeIdToDistToLeafMap();
1373 setTreeFile( null );
1375 initializeOvSettings();
1376 setStartingAngle( TWO_PI * 3 / 4 );
1377 final ImageLoader il = new ImageLoader( this );
1378 new Thread( il ).start();
1381 final private void initializeOvSettings() {
1382 setOvMaxHeight( getConfiguration().getOvMaxHeight() );
1383 setOvMaxWidth( getConfiguration().getOvMaxWidth() );
1386 final void initNodeData() {
1387 if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
1390 double max_original_domain_structure_width = 0.0;
1391 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1392 if ( node.getNodeData().isHasSequence()
1393 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1394 RenderableDomainArchitecture rds = null;
1395 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
1396 rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
1397 getConfiguration() );
1398 node.getNodeData().getSequence().setDomainArchitecture( rds );
1401 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
1403 if ( getControlPanel().isShowDomainArchitectures() ) {
1404 final double dsw = rds.getOriginalSize().getWidth();
1405 if ( dsw > max_original_domain_structure_width ) {
1406 max_original_domain_structure_width = dsw;
1411 if ( getControlPanel().isShowDomainArchitectures() ) {
1412 final double ds_factor_width = _domain_structure_width / max_original_domain_structure_width;
1413 for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
1414 if ( node.getNodeData().isHasSequence()
1415 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
1416 final RenderableDomainArchitecture rds = ( RenderableDomainArchitecture ) node.getNodeData()
1417 .getSequence().getDomainArchitecture();
1418 rds.setRenderingFactorWidth( ds_factor_width );
1419 rds.setParameter( _domain_structure_e_value_thr_exp );
1425 final boolean inOv( final MouseEvent e ) {
1426 return ( ( e.getX() > getVisibleRect().x + getOvXPosition() + 1 )
1427 && ( e.getX() < getVisibleRect().x + getOvXPosition() + getOvMaxWidth() - 1 )
1428 && ( e.getY() > getVisibleRect().y + getOvYPosition() + 1 ) && ( e.getY() < getVisibleRect().y
1429 + getOvYPosition() + getOvMaxHeight() - 1 ) );
1432 final boolean inOvRectangle( final MouseEvent e ) {
1433 return ( ( e.getX() >= getOvRectangle().getX() - 1 )
1434 && ( e.getX() <= getOvRectangle().getX() + getOvRectangle().getWidth() + 1 )
1435 && ( e.getY() >= getOvRectangle().getY() - 1 ) && ( e.getY() <= getOvRectangle().getY()
1436 + getOvRectangle().getHeight() + 1 ) );
1439 final private boolean inOvVirtualRectangle( final int x, final int y ) {
1440 return ( ( x >= getOvVirtualRectangle().x - 1 )
1441 && ( x <= getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 )
1442 && ( y >= getOvVirtualRectangle().y - 1 ) && ( y <= getOvVirtualRectangle().y
1443 + getOvVirtualRectangle().height + 1 ) );
1446 final private boolean inOvVirtualRectangle( final MouseEvent e ) {
1447 return ( inOvVirtualRectangle( e.getX(), e.getY() ) );
1450 final boolean isApplet() {
1451 return getMainPanel() instanceof MainPanelApplets;
1454 final private boolean isCanBlast( final PhylogenyNode node ) {
1455 return ( node.getNodeData().isHasSequence()
1456 && ( ( ( node.getNodeData().getSequence().getAccession() != null ) && !ForesterUtil.isEmpty( node
1457 .getNodeData().getSequence().getAccession().getValue() ) )
1458 || !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) || !ForesterUtil
1459 .isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) && Blast
1460 .isContainsQueryForBlast( node ) );
1463 final boolean isCanCollapse() {
1464 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1467 final boolean isCanColorSubtree() {
1468 return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1471 final boolean isCanCopy() {
1472 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1475 final boolean isCanCut( final PhylogenyNode node ) {
1476 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node
1480 final boolean isCanDelete() {
1481 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() );
1484 final private boolean isCanOpenSeqWeb( final PhylogenyNode node ) {
1485 if ( node.getNodeData().isHasSequence()
1486 && ( node.getNodeData().getSequence().getAccession() != null )
1487 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
1488 && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
1489 && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource()
1490 .toLowerCase() ) ) {
1496 final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) {
1497 if ( node.getNodeData().isHasTaxonomy()
1498 && ( ( ( node.getNodeData().getTaxonomy().getIdentifier() != null )
1499 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getProvider() )
1500 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && getConfiguration()
1501 .isHasWebLink( node.getNodeData().getTaxonomy().getIdentifier().getProvider().toLowerCase() ) )
1502 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) )
1503 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) )
1504 || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node
1505 .getNodeData().getTaxonomy().getIdentifier() != null )
1506 && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) && node
1507 .getNodeData().getTaxonomy().getIdentifier().getValue().startsWith( "http://" ) ) ) ) {
1515 final boolean isCanPaste() {
1516 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable()
1517 && ( getCutOrCopiedTree() != null ) && !getCutOrCopiedTree().isEmpty() );
1520 final boolean isCanReroot() {
1521 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( _subtree_index < 1 ) );
1524 final boolean isCanSubtree( final PhylogenyNode node ) {
1525 return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node
1526 .isRoot() || ( _subtree_index > 0 ) ) );
1529 final boolean isEdited() {
1533 final private boolean isInFoundNodes( final PhylogenyNode node ) {
1534 return ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) );
1537 final private boolean isInOv() {
1541 final boolean isInOvRect() {
1545 final private boolean isNodeDataInvisible( final PhylogenyNode node ) {
1547 if ( getControlPanel().isShowTaxonomyImages() ) {
1548 y_dist = 40 + ( int ) getYdistance();
1550 return ( ( node.getYcoord() < getVisibleRect().getMinY() - y_dist )
1551 || ( node.getYcoord() > getVisibleRect().getMaxY() + y_dist ) || ( ( node.getParent() != null ) && ( node
1552 .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) );
1555 final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) {
1556 return ( ( node.getYcoord() < getVisibleRect().getMinY() - 20 )
1557 || ( node.getYcoord() > getVisibleRect().getMaxY() + 20 )
1558 || ( node.getXcoord() < getVisibleRect().getMinX() - 20 ) || ( node.getXcoord() > getVisibleRect()
1559 .getMaxX() + 20 ) );
1562 final private boolean isNonLinedUpCladogram() {
1563 return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP;
1566 final boolean isOvOn() {
1570 final boolean isPhyHasBranchLengths() {
1571 return _phy_has_branch_lengths;
1574 final private boolean isUniformBranchLengthsForCladogram() {
1575 return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP;
1578 final private void keyPressedCalls( final KeyEvent e ) {
1579 if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) {
1580 if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) {
1581 if ( !isInOvRect() ) {
1582 setInOvRect( true );
1585 else if ( isInOvRect() ) {
1586 setInOvRect( false );
1589 if ( e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK ) {
1590 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1591 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
1592 getMainPanel().getTreeFontSet().mediumFonts();
1593 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1595 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1596 getMainPanel().getTreeFontSet().decreaseFontSize();
1597 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1599 else if ( plusPressed( e.getKeyCode() ) ) {
1600 getMainPanel().getTreeFontSet().increaseFontSize();
1601 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( true );
1605 if ( ( e.getKeyCode() == KeyEvent.VK_DELETE ) || ( e.getKeyCode() == KeyEvent.VK_HOME )
1606 || ( e.getKeyCode() == KeyEvent.VK_F ) ) {
1607 getControlPanel().showWhole();
1609 else if ( ( e.getKeyCode() == KeyEvent.VK_UP ) || ( e.getKeyCode() == KeyEvent.VK_DOWN )
1610 || ( e.getKeyCode() == KeyEvent.VK_LEFT ) || ( e.getKeyCode() == KeyEvent.VK_RIGHT ) ) {
1611 if ( e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK ) {
1612 if ( e.getKeyCode() == KeyEvent.VK_UP ) {
1613 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1614 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1616 else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1617 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1618 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1620 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1621 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1622 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1623 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1625 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1626 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1627 Constants.WHEEL_ZOOM_IN_FACTOR );
1628 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1635 if ( e.getKeyCode() == KeyEvent.VK_DOWN ) {
1638 else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) {
1642 else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) {
1646 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1647 scroll_position.x = scroll_position.x + dx;
1648 scroll_position.y = scroll_position.y + dy;
1649 if ( scroll_position.x <= 0 ) {
1650 scroll_position.x = 0;
1653 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1654 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1655 if ( scroll_position.x >= max_x ) {
1656 scroll_position.x = max_x;
1659 if ( scroll_position.y <= 0 ) {
1660 scroll_position.y = 0;
1663 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1664 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1665 if ( scroll_position.y >= max_y ) {
1666 scroll_position.y = max_y;
1670 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1673 else if ( ( e.getKeyCode() == KeyEvent.VK_SUBTRACT ) || ( e.getKeyCode() == KeyEvent.VK_MINUS ) ) {
1674 getMainPanel().getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
1675 getMainPanel().getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
1676 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
1677 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1679 else if ( plusPressed( e.getKeyCode() ) ) {
1680 getMainPanel().getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
1681 Constants.WHEEL_ZOOM_IN_FACTOR );
1682 getMainPanel().getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
1683 getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged( false );
1685 else if ( e.getKeyCode() == KeyEvent.VK_S ) {
1686 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1687 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1688 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
1689 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1692 else if ( e.getKeyCode() == KeyEvent.VK_A ) {
1693 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1694 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1695 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
1696 if ( getStartingAngle() < 0 ) {
1697 setStartingAngle( TWO_PI + getStartingAngle() );
1699 getControlPanel().displayedPhylogenyMightHaveChanged( false );
1702 else if ( e.getKeyCode() == KeyEvent.VK_D ) {
1703 boolean selected = false;
1704 if ( getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL ) {
1705 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1709 getOptions().setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1711 if ( getMainPanel().getMainFrame() == null ) {
1712 // Must be "E" applet version.
1713 final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1714 if ( ae.getlabelDirectionCbmi() != null ) {
1715 ae.getlabelDirectionCbmi().setSelected( selected );
1719 getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected( selected );
1723 else if ( e.getKeyCode() == KeyEvent.VK_X ) {
1724 switchDisplaygetPhylogenyGraphicsType();
1727 else if ( e.getKeyCode() == KeyEvent.VK_C ) {
1731 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_O ) ) {
1732 MainFrame.cycleOverview( getOptions(), this );
1735 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_I ) ) {
1738 else if ( getOptions().isShowOverview() && isOvOn() && ( e.getKeyCode() == KeyEvent.VK_U ) ) {
1745 final private void makePopupMenus( final PhylogenyNode node ) {
1746 _node_popup_menu = new JPopupMenu();
1747 final List<String> clickto_names = _main_panel.getControlPanel().getSingleClickToNames();
1748 _node_popup_menu_items = new JMenuItem[ clickto_names.size() ];
1749 for( int i = 0; i < clickto_names.size(); i++ ) {
1750 final String title = clickto_names.get( i );
1751 _node_popup_menu_items[ i ] = new JMenuItem( title );
1752 if ( title.equals( Configuration.clickto_options[ Configuration.open_seq_web ][ 0 ] ) ) {
1753 _node_popup_menu_items[ i ].setEnabled( isCanOpenSeqWeb( node ) );
1755 else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) {
1756 _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) );
1758 else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) {
1759 _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) );
1761 else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) {
1762 if ( !getOptions().isEditable() ) {
1765 _node_popup_menu_items[ i ].setEnabled( isCanDelete() );
1767 else if ( title.equals( Configuration.clickto_options[ Configuration.cut_subtree ][ 0 ] ) ) {
1768 if ( !getOptions().isEditable() ) {
1771 _node_popup_menu_items[ i ].setEnabled( isCanCut( node ) );
1773 else if ( title.equals( Configuration.clickto_options[ Configuration.copy_subtree ][ 0 ] ) ) {
1774 if ( !getOptions().isEditable() ) {
1777 _node_popup_menu_items[ i ].setEnabled( isCanCopy() );
1779 else if ( title.equals( Configuration.clickto_options[ Configuration.paste_subtree ][ 0 ] ) ) {
1780 if ( !getOptions().isEditable() ) {
1783 _node_popup_menu_items[ i ].setEnabled( isCanPaste() );
1785 else if ( title.equals( Configuration.clickto_options[ Configuration.edit_node_data ][ 0 ] ) ) {
1786 if ( !getOptions().isEditable() ) {
1790 else if ( title.equals( Configuration.clickto_options[ Configuration.add_new_node ][ 0 ] ) ) {
1791 if ( !getOptions().isEditable() ) {
1795 else if ( title.equals( Configuration.clickto_options[ Configuration.reroot ][ 0 ] ) ) {
1796 _node_popup_menu_items[ i ].setEnabled( isCanReroot() );
1798 else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) {
1799 _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) );
1801 else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) {
1802 _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() );
1804 else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) {
1805 _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) );
1807 else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) {
1808 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 );
1810 else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) {
1811 _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 );
1813 _node_popup_menu_items[ i ].addActionListener( this );
1814 _node_popup_menu.add( _node_popup_menu_items[ i ] );
1818 final void midpointRoot() {
1819 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
1822 if ( !_phylogeny.isRerootable() ) {
1823 JOptionPane.showMessageDialog( this,
1824 "This is not rerootable",
1826 JOptionPane.WARNING_MESSAGE );
1829 setNodeInPreorderToNull();
1831 PhylogenyMethods.midpointRoot( _phylogeny );
1832 resetNodeIdToDistToLeafMap();
1837 final void mouseClicked( final MouseEvent e ) {
1838 if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) {
1839 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1840 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1841 double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - getOvRectangle().getWidth() / 2.0 )
1843 double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - getOvRectangle().getHeight() / 2.0 )
1851 final double max_x = getWidth() - getVisibleRect().width;
1852 final double max_y = getHeight() - getVisibleRect().height;
1859 getMainPanel().getCurrentScrollPane().getViewport()
1860 .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) );
1861 setInOvRect( true );
1865 final PhylogenyNode node = findNode( e.getX(), e.getY() );
1866 if ( node != null ) {
1867 if ( !node.isRoot() && node.getParent().isCollapse() ) {
1870 _highlight_node = node;
1871 // Check if shift key is down
1872 if ( ( e.getModifiers() & InputEvent.SHIFT_MASK ) != 0 ) {
1873 // Yes, so add to _found_nodes
1874 if ( getFoundNodes() == null ) {
1875 setFoundNodes( new HashSet<Integer>() );
1877 getFoundNodes().add( node.getId() );
1878 // Check if control key is down
1880 else if ( ( e.getModifiers() & InputEvent.CTRL_MASK ) != 0 ) {
1881 // Yes, so pop-up menu
1882 displayNodePopupMenu( node, e.getX(), e.getY() );
1883 // Handle unadorned click
1886 // Check for right mouse button
1887 if ( e.getModifiers() == 4 ) {
1888 displayNodePopupMenu( node, e.getX(), e.getY() );
1891 // if not in _found_nodes, clear _found_nodes
1892 handleClickToAction( _control_panel.getActionWhenNodeClicked(), node );
1897 // no node was clicked
1898 _highlight_node = null;
1904 final void mouseDragInBrowserPanel( final MouseEvent e ) {
1905 setCursor( MOVE_CURSOR );
1906 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1907 scroll_position.x -= ( e.getX() - getLastDragPointX() );
1908 scroll_position.y -= ( e.getY() - getLastDragPointY() );
1909 if ( scroll_position.x < 0 ) {
1910 scroll_position.x = 0;
1913 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1914 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1915 if ( scroll_position.x > max_x ) {
1916 scroll_position.x = max_x;
1919 if ( scroll_position.y < 0 ) {
1920 scroll_position.y = 0;
1923 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1924 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1925 if ( scroll_position.y > max_y ) {
1926 scroll_position.y = max_y;
1929 if ( isOvOn() || getOptions().isShowScale() ) {
1932 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1935 final void mouseDragInOvRectangle( final MouseEvent e ) {
1936 setCursor( HAND_CURSOR );
1937 final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
1938 final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
1939 final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition();
1940 double dx = ( w_ratio * e.getX() - w_ratio * getLastDragPointX() );
1941 double dy = ( h_ratio * e.getY() - h_ratio * getLastDragPointY() );
1942 scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx );
1943 scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy );
1944 if ( scroll_position.x <= 0 ) {
1945 scroll_position.x = 0;
1949 final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getMaximum()
1950 - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
1951 if ( scroll_position.x >= max_x ) {
1953 scroll_position.x = max_x;
1956 if ( scroll_position.y <= 0 ) {
1958 scroll_position.y = 0;
1961 final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
1962 - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
1963 if ( scroll_position.y >= max_y ) {
1965 scroll_position.y = max_y;
1969 getMainPanel().getCurrentScrollPane().getViewport().setViewPosition( scroll_position );
1970 setLastMouseDragPointX( ( float ) ( e.getX() + dx ) );
1971 setLastMouseDragPointY( ( float ) ( e.getY() + dy ) );
1974 final void mouseMoved( final MouseEvent e ) {
1975 requestFocusInWindow();
1976 if ( getControlPanel().isNodeDescPopup() ) {
1977 if ( _node_desc_popup != null ) {
1978 _node_desc_popup.hide();
1979 _node_desc_popup = null;
1982 if ( getOptions().isShowOverview() && isOvOn() ) {
1983 if ( inOvVirtualRectangle( e ) ) {
1984 if ( !isInOvRect() ) {
1985 setInOvRect( true );
1990 if ( isInOvRect() ) {
1991 setInOvRect( false );
1996 if ( inOv( e ) && getOptions().isShowOverview() && isOvOn() ) {
2005 final PhylogenyNode node = findNode( e.getX(), e.getY() );
2006 if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
2007 // cursor is over a tree node
2008 if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
2009 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
2010 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
2011 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
2012 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.REROOT )
2013 || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.ADD_NEW_NODE ) ) {
2014 setCursor( CUT_CURSOR );
2017 setCursor( HAND_CURSOR );
2018 if ( getControlPanel().isNodeDescPopup() ) {
2019 showNodeDataPopup( e, node );
2024 setCursor( ARROW_CURSOR );
2029 final void mouseReleasedInBrowserPanel( final MouseEvent e ) {
2030 setCursor( ARROW_CURSOR );
2033 final public void mouseWheelMoved( final MouseWheelEvent e ) {
2034 final int notches = e.getWheelRotation();
2035 if ( inOvVirtualRectangle( e ) ) {
2036 if ( !isInOvRect() ) {
2037 setInOvRect( true );
2042 if ( isInOvRect() ) {
2043 setInOvRect( false );
2047 if ( e.isControlDown() ) {
2048 if ( notches < 0 ) {
2049 getTreeFontSet().increaseFontSize();
2050 getControlPanel().displayedPhylogenyMightHaveChanged( true );
2053 getTreeFontSet().decreaseFontSize();
2054 getControlPanel().displayedPhylogenyMightHaveChanged( true );
2057 else if ( e.isShiftDown() ) {
2058 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
2059 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
2060 if ( notches < 0 ) {
2061 for( int i = 0; i < ( -notches ); ++i ) {
2062 setStartingAngle( ( getStartingAngle() % TWO_PI ) + ANGLE_ROTATION_UNIT );
2063 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2067 for( int i = 0; i < notches; ++i ) {
2068 setStartingAngle( ( getStartingAngle() % TWO_PI ) - ANGLE_ROTATION_UNIT );
2069 if ( getStartingAngle() < 0 ) {
2070 setStartingAngle( TWO_PI + getStartingAngle() );
2072 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2077 if ( notches < 0 ) {
2078 for( int i = 0; i < ( -notches ); ++i ) {
2079 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
2080 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2084 for( int i = 0; i < notches; ++i ) {
2085 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
2086 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2092 if ( notches < 0 ) {
2093 for( int i = 0; i < ( -notches ); ++i ) {
2094 getControlPanel().zoomInX( Constants.WHEEL_ZOOM_IN_FACTOR,
2095 Constants.WHEEL_ZOOM_IN_X_CORRECTION_FACTOR );
2096 getControlPanel().zoomInY( Constants.WHEEL_ZOOM_IN_FACTOR );
2097 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2101 for( int i = 0; i < notches; ++i ) {
2102 getControlPanel().zoomOutY( Constants.WHEEL_ZOOM_OUT_FACTOR );
2103 getControlPanel().zoomOutX( Constants.WHEEL_ZOOM_OUT_FACTOR,
2104 Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR );
2105 getControlPanel().displayedPhylogenyMightHaveChanged( false );
2110 requestFocusInWindow();
2114 final void multiplyUrtFactor( final float f ) {
2118 final JApplet obtainApplet() {
2119 return ( ( MainPanelApplets ) getMainPanel() ).getApplet();
2122 final private void openSeqWeb( final PhylogenyNode node ) {
2123 if ( !isCanOpenSeqWeb( node ) ) {
2124 cannotOpenBrowserWarningMessage( "sequence" );
2127 String uri_str = null;
2128 final Sequence seq = node.getNodeData().getSequence();
2129 final String source = seq.getAccession().getSource().toLowerCase();
2131 if ( source.toLowerCase().equals( "ncbi" ) ) {
2132 url = Constants.NCBI_ALL_DATABASE_SEARCH;
2135 final WebLink weblink = getConfiguration().getWebLink( source );
2136 url = weblink.getUrl().toString();
2139 uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 );
2141 catch ( final UnsupportedEncodingException e ) {
2142 AptxUtil.showErrorMessage( this, e.toString() );
2143 e.printStackTrace();
2145 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2147 JApplet applet = null;
2149 applet = obtainApplet();
2151 AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_seq" );
2153 catch ( final IOException e ) {
2154 AptxUtil.showErrorMessage( this, e.toString() );
2155 e.printStackTrace();
2157 catch ( final URISyntaxException e ) {
2158 AptxUtil.showErrorMessage( this, e.toString() );
2159 e.printStackTrace();
2163 cannotOpenBrowserWarningMessage( "sequence" );
2167 final private void openTaxWeb( final PhylogenyNode node ) {
2168 if ( !isCanOpenTaxWeb( node ) ) {
2169 cannotOpenBrowserWarningMessage( "taxonomic" );
2172 String uri_str = null;
2173 final Taxonomy tax = node.getNodeData().getTaxonomy();
2174 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() )
2175 && getConfiguration().isHasWebLink( tax.getIdentifier().getProvider().toLowerCase() ) ) {
2176 final String type = tax.getIdentifier().getProvider().toLowerCase();
2177 final WebLink weblink = getConfiguration().getWebLink( type );
2179 uri_str = weblink.getUrl() + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF8 );
2181 catch ( final UnsupportedEncodingException e ) {
2182 AptxUtil.showErrorMessage( this, e.toString() );
2183 e.printStackTrace();
2186 else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() )
2187 && tax.getIdentifier().getValue().startsWith( "http://" ) ) {
2189 uri_str = new URI( tax.getIdentifier().getValue() ).toString();
2191 catch ( final URISyntaxException e ) {
2192 AptxUtil.showErrorMessage( this, e.toString() );
2194 e.printStackTrace();
2197 else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
2199 uri_str = "http://www.eol.org/search?q="
2200 + URLEncoder.encode( tax.getScientificName(), ForesterConstants.UTF8 );
2202 catch ( final UnsupportedEncodingException e ) {
2203 AptxUtil.showErrorMessage( this, e.toString() );
2204 e.printStackTrace();
2207 else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
2209 uri_str = "http://www.uniprot.org/taxonomy/?query="
2210 + URLEncoder.encode( tax.getTaxonomyCode(), ForesterConstants.UTF8 );
2212 catch ( final UnsupportedEncodingException e ) {
2213 AptxUtil.showErrorMessage( this, e.toString() );
2214 e.printStackTrace();
2217 else if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
2219 uri_str = "http://www.eol.org/search?q="
2220 + URLEncoder.encode( tax.getCommonName(), ForesterConstants.UTF8 );
2222 catch ( final UnsupportedEncodingException e ) {
2223 AptxUtil.showErrorMessage( this, e.toString() );
2224 e.printStackTrace();
2227 if ( !ForesterUtil.isEmpty( uri_str ) ) {
2229 JApplet applet = null;
2231 applet = obtainApplet();
2233 AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_tax" );
2235 catch ( final IOException e ) {
2236 AptxUtil.showErrorMessage( this, e.toString() );
2237 e.printStackTrace();
2239 catch ( final URISyntaxException e ) {
2240 AptxUtil.showErrorMessage( this, e.toString() );
2241 e.printStackTrace();
2245 cannotOpenBrowserWarningMessage( "taxonomic" );
2249 final void paintBranchCircular( final PhylogenyNode p,
2250 final PhylogenyNode c,
2252 final boolean radial_labels,
2253 final boolean to_pdf,
2254 final boolean to_graphics_file ) {
2255 final double angle = _urt_nodeid_angle_map.get( c.getId() );
2256 final double root_x = _root.getXcoord();
2257 final double root_y = _root.getYcoord();
2258 final double dx = root_x - p.getXcoord();
2259 final double dy = root_y - p.getYcoord();
2260 final double parent_radius = Math.sqrt( dx * dx + dy * dy );
2261 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
2262 assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file );
2263 if ( ( c.isFirstChildNode() || c.isLastChildNode() )
2264 && ( ( Math.abs( parent_radius * arc ) > 1.5 ) || to_pdf || to_graphics_file ) ) {
2265 final double r2 = 2.0 * parent_radius;
2266 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
2268 drawLine( c.getXcoord(),
2270 root_x + ( Math.cos( angle ) * parent_radius ),
2271 root_y + ( Math.sin( angle ) * parent_radius ),
2273 paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c ) );
2274 if ( c.isExternal() ) {
2275 final boolean is_in_found_nodes = isInFoundNodes( c );
2276 if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
2277 && ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor != 1 ) ) {
2280 paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes );
2284 final void paintBranchCircularLite( final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g ) {
2285 final double angle = _urt_nodeid_angle_map.get( c.getId() );
2286 final double root_x = _root.getXSecondary();
2287 final double root_y = _root.getYSecondary();
2288 final double dx = root_x - p.getXSecondary();
2289 final double dy = root_y - p.getYSecondary();
2290 final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle;
2291 final double parent_radius = Math.sqrt( dx * dx + dy * dy );
2292 g.setColor( getTreeColorSet().getOvColor() );
2293 if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) {
2294 final double r2 = 2.0 * parent_radius;
2295 drawArc( root_x - parent_radius, root_y - parent_radius, r2, r2, ( -angle - arc ), arc, g );
2297 drawLine( c.getXSecondary(),
2299 root_x + ( Math.cos( angle ) * parent_radius ),
2300 root_y + ( Math.sin( angle ) * parent_radius ),
2302 if ( isInFoundNodes( c ) ) {
2303 g.setColor( getTreeColorSet().getFoundColor() );
2304 drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
2308 final private void paintBranchLength( final Graphics2D g,
2309 final PhylogenyNode node,
2310 final boolean to_pdf,
2311 final boolean to_graphics_file ) {
2312 g.setFont( getTreeFontSet().getSmallFont() );
2313 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2314 g.setColor( Color.BLACK );
2317 g.setColor( getTreeColorSet().getBranchLengthColor() );
2319 if ( !node.isRoot() ) {
2320 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2321 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2322 .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2324 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2325 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2326 .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2329 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent()
2330 .getXcoord() + 3, node.getYcoord() - getTreeFontSet()._small_max_descent, g );
2334 TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord()
2335 - getTreeFontSet()._small_max_descent, g );
2339 final private void paintBranchLite( final Graphics2D g,
2344 final PhylogenyNode node ) {
2345 g.setColor( getTreeColorSet().getOvColor() );
2346 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2347 drawLine( x1, y1, x2, y2, g );
2349 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2350 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2351 ( g ).draw( _quad_curve );
2353 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2354 final float dx = x2 - x1;
2355 final float dy = y2 - y1;
2356 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
2357 + ( dy * 0.8f ), x2, y2 );
2358 ( g ).draw( _cubic_curve );
2361 final float x2a = x2;
2362 final float x1a = x1;
2363 // draw the vertical line
2364 if ( node.isFirstChildNode() || node.isLastChildNode() ) {
2365 drawLine( x1, y1, x1, y2, g );
2367 // draw the horizontal line
2368 drawLine( x1a, y2, x2a, y2, g );
2373 * Paint a branch which consists of a vertical and a horizontal bar
2374 * @param is_ind_found_nodes
2376 final private void paintBranchRectangular( final Graphics2D g,
2381 final PhylogenyNode node,
2382 final boolean to_pdf,
2383 final boolean to_graphics_file ) {
2384 assignGraphicsForBranchWithColorForParentBranch( node, false, g, to_pdf, to_graphics_file );
2385 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR ) {
2386 drawLine( x1, y1, x2, y2, g );
2388 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CONVEX ) {
2389 _quad_curve.setCurve( x1, y1, x1, y2, x2, y2 );
2390 g.draw( _quad_curve );
2392 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) {
2393 final float dx = x2 - x1;
2394 final float dy = y2 - y1;
2395 _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1
2396 + ( dy * 0.8f ), x2, y2 );
2397 g.draw( _cubic_curve );
2400 final float x2a = x2;
2401 final float x1a = x1;
2403 if ( node.isFirstChildNode() || node.isLastChildNode()
2404 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
2405 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2406 if ( !to_graphics_file
2408 && ( ( ( y2 < getVisibleRect().getMinY() - 20 ) && ( y1 < getVisibleRect().getMinY() - 20 ) ) || ( ( y2 > getVisibleRect()
2409 .getMaxY() + 20 ) && ( y1 > getVisibleRect().getMaxY() + 20 ) ) ) ) {
2413 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2414 float x2c = x1 + EURO_D;
2418 drawLine( x1, y1, x2c, y2, g );
2420 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2422 y2_r = y2 - ROUNDED_D;
2426 drawLine( x1, y1, x1, y2_r, g );
2429 y2_r = y2 + ROUNDED_D;
2433 drawLine( x1, y1, x1, y2_r, g );
2437 drawLine( x1, y1, x1, y2, g );
2441 // draw the horizontal line
2442 if ( !to_graphics_file && !to_pdf
2443 && ( ( y2 < getVisibleRect().getMinY() - 20 ) || ( y2 > getVisibleRect().getMaxY() + 20 ) ) ) {
2447 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( node ) == 1 ) ) {
2448 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2449 x1_r = x1a + ROUNDED_D;
2451 drawLine( x1_r, y2, x2a, y2, g );
2454 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2455 final float x1c = x1a + EURO_D;
2457 drawLine( x1c, y2, x2a, y2, g );
2461 drawLine( x1a, y2, x2a, y2, g );
2465 final double w = PhylogenyMethods.getBranchWidthValue( node );
2466 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2467 x1_r = x1a + ROUNDED_D;
2469 drawRectFilled( x1_r, y2 - ( w / 2 ), x2a - x1_r, w, g );
2472 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2473 final float x1c = x1a + EURO_D;
2475 drawRectFilled( x1c, y2 - ( w / 2 ), x2a - x1c, w, g );
2479 drawRectFilled( x1a, y2 - ( w / 2 ), x2a - x1a, w, g );
2482 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
2487 final double diff = y2 - y2_r;
2488 _arc.setArc( x1, y2_r - diff, 2 * ( x1_r - x1 ), 2 * diff, 180, 90, Arc2D.OPEN );
2491 _arc.setArc( x1, y2, 2 * ( x1_r - x1 ), 2 * ( y2_r - y2 ), 90, 90, Arc2D.OPEN );
2496 if ( node.isExternal() ) {
2497 paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
2501 final void paintCircular( final Phylogeny phy,
2502 final double starting_angle,
2507 final boolean to_pdf,
2508 final boolean to_graphics_file ) {
2509 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes() - _collapsed_external_nodeid_set.size();
2510 System.out.println( "# collapsed external = " + _collapsed_external_nodeid_set.size() );
2511 _root = phy.getRoot();
2512 _root.setXcoord( center_x );
2513 _root.setYcoord( center_y );
2514 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
2515 double current_angle = starting_angle;
2517 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2518 final PhylogenyNode n = it.next();
2519 if ( !n.isCollapse() ) {
2520 n.setXcoord( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) );
2521 n.setYcoord( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) );
2522 _urt_nodeid_angle_map.put( n.getId(), current_angle );
2523 _urt_nodeid_index_map.put( n.getId(), i++ );
2524 current_angle += ( TWO_PI / circ_num_ext_nodes );
2528 System.out.println( "is collapse" + n.getName() );
2531 paintCirculars( phy.getRoot(), phy, center_x, center_y, radius, radial_labels, g, to_pdf, to_graphics_file );
2532 paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file, isInFoundNodes( _root ) );
2535 void updateSetOfCollapsedExternalNodes( final Phylogeny phy ) {
2536 _collapsed_external_nodeid_set.clear();
2537 E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2538 final PhylogenyNode ext_node = it.next();
2539 PhylogenyNode n = ext_node;
2540 while ( !n.isRoot() ) {
2541 if ( n.isCollapse() ) {
2542 _collapsed_external_nodeid_set.add( ext_node.getId() );
2550 final void paintCircularLite( final Phylogeny phy,
2551 final double starting_angle,
2555 final Graphics2D g ) {
2556 final int circ_num_ext_nodes = phy.getNumberOfExternalNodes();
2557 _root = phy.getRoot();
2558 _root.setXSecondary( center_x );
2559 _root.setYSecondary( center_y );
2560 double current_angle = starting_angle;
2561 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
2562 final PhylogenyNode n = it.next();
2563 n.setXSecondary( ( float ) ( center_x + radius * Math.cos( current_angle ) ) );
2564 n.setYSecondary( ( float ) ( center_y + radius * Math.sin( current_angle ) ) );
2565 _urt_nodeid_angle_map.put( n.getId(), current_angle );
2566 current_angle += ( TWO_PI / circ_num_ext_nodes );
2568 paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
2571 final private double paintCirculars( final PhylogenyNode n,
2572 final Phylogeny phy,
2573 final float center_x,
2574 final float center_y,
2575 final double radius,
2576 final boolean radial_labels,
2578 final boolean to_pdf,
2579 final boolean to_graphics_file ) {
2580 if ( n.isExternal() || n.isCollapse() ) { //~~circ collapse
2581 if ( !_urt_nodeid_angle_map.containsKey( n.getId() ) ) {
2582 System.out.println( "no " + n + " =====>>>>>>> ERROR!" );//TODO
2584 return _urt_nodeid_angle_map.get( n.getId() );
2587 final List<PhylogenyNode> descs = n.getDescendants();
2589 for( final PhylogenyNode desc : descs ) {
2590 sum += paintCirculars( desc,
2601 if ( !n.isRoot() ) {
2602 r = 1 - ( ( ( double ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth );
2604 final double theta = sum / descs.size();
2605 n.setXcoord( ( float ) ( center_x + r * radius * Math.cos( theta ) ) );
2606 n.setYcoord( ( float ) ( center_y + r * radius * Math.sin( theta ) ) );
2607 _urt_nodeid_angle_map.put( n.getId(), theta );
2608 for( final PhylogenyNode desc : descs ) {
2609 paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file );
2615 final private void paintCircularsLite( final PhylogenyNode n,
2616 final Phylogeny phy,
2620 final Graphics2D g ) {
2621 if ( n.isExternal() ) {
2625 final List<PhylogenyNode> descs = n.getDescendants();
2626 for( final PhylogenyNode desc : descs ) {
2627 paintCircularsLite( desc, phy, center_x, center_y, radius, g );
2630 if ( !n.isRoot() ) {
2631 r = 1 - ( ( ( float ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth );
2633 final double theta = _urt_nodeid_angle_map.get( n.getId() );
2634 n.setXSecondary( ( float ) ( center_x + radius * r * Math.cos( theta ) ) );
2635 n.setYSecondary( ( float ) ( center_y + radius * r * Math.sin( theta ) ) );
2636 for( final PhylogenyNode desc : descs ) {
2637 paintBranchCircularLite( n, desc, g );
2642 final private void paintCollapsedNode( final Graphics2D g,
2643 final PhylogenyNode node,
2644 final boolean to_graphics_file,
2645 final boolean to_pdf,
2646 final boolean is_in_found_nodes ) {
2648 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2651 else if ( is_in_found_nodes ) {
2652 c = getTreeColorSet().getFoundColor();
2654 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2655 c = getTaxonomyBasedColor( node );
2657 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
2658 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2659 c = PhylogenyMethods.getBranchColorValue( node );
2662 c = getTreeColorSet().getCollapseFillColor();
2664 double d = node.getAllExternalDescendants().size();
2666 d = ( 3 * _y_distance ) / 3;
2669 d = ( Math.log10( d ) * _y_distance ) / 2.5;
2671 final int box_size = getOptions().getDefaultNodeShapeSize();
2672 if ( d < box_size ) {
2676 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() - box_size ),
2677 ForesterUtil.roundToInt( node.getYcoord() ) );
2678 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ),
2679 ForesterUtil.roundToInt( node.getYcoord() - d ) );
2680 _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ),
2681 ForesterUtil.roundToInt( node.getYcoord() + d ) );
2682 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
2684 g.fillPolygon( _polygon );
2686 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
2687 g.setColor( getBackground() );
2688 g.fillPolygon( _polygon );
2690 g.drawPolygon( _polygon );
2692 else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2693 g.setPaint( new GradientPaint( node.getXcoord() - box_size, node.getYcoord(), getBackground(), ( node
2694 .getXcoord() + box_size ), ( float ) ( node.getYcoord() - d ), c, false ) );
2699 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
2703 final public void paintComponent( final Graphics g ) {
2704 // Dimension currentSize = getSize();
2705 // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
2706 // call the 'java.awt.Component.createImage(...)' method to get an
2708 // offscreenImage = createImage( currentSize.width, currentSize.height );
2709 // offscreenGraphics = offscreenImage.getGraphics();
2710 // offscreenDimension = currentSize;
2712 // super.paintComponent( g ); //why?
2713 //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
2714 final Graphics2D g2d = ( Graphics2D ) g;
2715 g2d.setRenderingHints( _rendering_hints );
2716 paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
2717 //g.drawImage( offscreenImage, 0, 0, this );
2721 public void update( final Graphics g ) {
2725 final private void paintConfidenceValues( final Graphics2D g,
2726 final PhylogenyNode node,
2727 final boolean to_pdf,
2728 final boolean to_graphics_file ) {
2729 final List<Confidence> confidences = node.getBranchData().getConfidences();
2730 // if ( confidences.size() == 1 ) {
2731 // final double value = node.getBranchData().getConfidence( 0 ).getValue();
2732 // if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
2735 // conf_str = FORMATTER_CONFIDENCE.format( value );
2737 // else if ( confidences.size() > 1 ) {
2738 boolean one_ok = false;
2739 boolean not_first = false;
2740 Collections.sort( confidences );
2741 final StringBuilder sb = new StringBuilder();
2742 String conf_str = "";
2743 for( final Confidence confidence : confidences ) {
2744 final double value = confidence.getValue();
2745 if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2746 if ( value >= getOptions().getMinConfidenceValue() ) {
2755 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
2756 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2757 if ( getOptions().isShowConfidenceStddev() ) {
2758 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
2760 sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getStandardDeviation(),
2762 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
2769 conf_str = sb.toString();
2772 if ( conf_str.length() > 0 ) {
2773 final double parent_x = node.getParent().getXcoord();
2774 double x = node.getXcoord();
2775 g.setFont( getTreeFontSet().getSmallFont() );
2776 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) {
2779 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
2782 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2783 g.setColor( Color.BLACK );
2786 g.setColor( getTreeColorSet().getConfidenceColor() );
2789 .drawString( conf_str,
2791 + ( ( x - parent_x - getTreeFontSet()._fm_small.stringWidth( conf_str ) ) / 2 ),
2792 ( node.getYcoord() + getTreeFontSet()._small_max_ascent ) - 1,
2797 final private void paintFoundNode( final int x, final int y, final Graphics2D g ) {
2798 final int box_size = getOptions().getDefaultNodeShapeSize();
2799 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
2800 g.setColor( getTreeColorSet().getFoundColor() );
2801 g.fillRect( x - half_box_size, y - half_box_size, box_size, box_size );
2804 final private void paintGainedAndLostCharacters( final Graphics2D g,
2805 final PhylogenyNode node,
2806 final String gained,
2807 final String lost ) {
2808 if ( node.getParent() != null ) {
2809 final double parent_x = node.getParent().getXcoord();
2810 final double x = node.getXcoord();
2811 g.setFont( getTreeFontSet().getLargeFont() );
2812 g.setColor( getTreeColorSet().getGainedCharactersColor() );
2813 if ( Constants.SPECIAL_CUSTOM ) {
2814 g.setColor( Color.BLUE );
2817 .drawString( gained,
2818 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( gained ) ) / 2 ),
2819 ( node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent() ),
2821 g.setColor( getTreeColorSet().getLostCharactersColor() );
2822 TreePanel.drawString( lost,
2823 parent_x + ( ( x - parent_x - getTreeFontSet()._fm_large.stringWidth( lost ) ) / 2 ),
2824 ( node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent() ),
2830 * Draw a box at the indicated node.
2837 final private void paintNodeBox( final double x,
2839 final PhylogenyNode node,
2841 final boolean to_pdf,
2842 final boolean to_graphics_file,
2843 final boolean is_in_found_nodes ) {
2844 if ( node.isCollapse() ) {
2847 // if this node should be highlighted, do so
2848 if ( ( _highlight_node == node ) && !to_pdf && !to_graphics_file ) {
2849 g.setColor( getTreeColorSet().getFoundColor() );
2850 drawOval( x - 8, y - 8, 16, 16, g );
2851 drawOval( x - 9, y - 8, 17, 17, g );
2852 drawOval( x - 9, y - 9, 18, 18, g );
2854 if ( is_in_found_nodes ) {
2855 paintFoundNode( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ), g );
2858 Color outline_color = null;
2859 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2860 outline_color = Color.BLACK;
2862 else if ( getControlPanel().isEvents() && AptxUtil.isHasAssignedEvent( node ) ) {
2863 final Event event = node.getNodeData().getEvent();
2864 if ( event.isDuplication() ) {
2865 outline_color = getTreeColorSet().getDuplicationBoxColor();
2867 else if ( event.isSpeciation() ) {
2868 outline_color = getTreeColorSet().getSpecBoxColor();
2870 else if ( event.isSpeciationOrDuplication() ) {
2871 outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
2874 else if ( getOptions().isTaxonomyColorizeNodeShapes() ) {
2875 outline_color = getTaxonomyBasedColor( node );
2878 outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
2879 if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
2880 outline_color = getTreeColorSet().getBranchColorForPdf();
2883 final int box_size = getOptions().getDefaultNodeShapeSize();
2884 final int half_box_size = box_size / 2;
2885 if ( getOptions().isShowDefaultNodeShapes() || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) {
2886 if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
2887 if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
2888 drawOvalGradient( x - half_box_size,
2893 to_pdf ? Color.WHITE : outline_color,
2894 to_pdf ? outline_color : getBackground(),
2897 else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
2898 Color background = getBackground();
2900 background = Color.WHITE;
2902 drawOvalGradient( x - half_box_size,
2911 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
2912 g.setColor( outline_color );
2913 drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2916 else if ( getOptions().getDefaultNodeShape() == NodeVisualization.NodeShape.RECTANGLE ) {
2917 if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.GRADIENT ) {
2918 drawRectGradient( x - half_box_size,
2923 to_pdf ? Color.WHITE : outline_color,
2924 to_pdf ? outline_color : getBackground(),
2927 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) {
2928 Color background = getBackground();
2930 background = Color.WHITE;
2932 drawRectGradient( x - half_box_size,
2941 else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) {
2942 g.setColor( outline_color );
2943 drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
2950 final private void paintNodeData( final Graphics2D g,
2951 final PhylogenyNode node,
2952 final boolean to_graphics_file,
2953 final boolean to_pdf,
2954 final boolean is_in_found_nodes ) {
2955 if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
2958 if ( getOptions().isShowBranchLengthValues()
2959 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
2960 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
2961 && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
2962 paintBranchLength( g, node, to_pdf, to_graphics_file );
2964 if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
2968 final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
2969 if ( getControlPanel().isShowTaxonomyImages()
2970 && ( getImageMap() != null )
2971 && !getImageMap().isEmpty()
2972 && node.getNodeData().isHasTaxonomy()
2973 && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy()
2974 .getUris().isEmpty() ) ) {
2975 x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
2977 if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
2978 .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
2979 x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
2981 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
2982 g.setColor( Color.BLACK );
2984 else if ( is_in_found_nodes ) {
2985 g.setColor( getTreeColorSet().getFoundColor() );
2987 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
2988 g.setColor( getTaxonomyBasedColor( node ) );
2990 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
2991 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
2992 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
2994 else if ( to_pdf ) {
2995 g.setColor( Color.BLACK );
2998 g.setColor( getTreeColorSet().getSequenceColor() );
3001 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3003 _sb.append( node.getAllExternalDescendants().size() );
3006 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3007 if ( _sb.length() > 0 ) {
3010 _sb.append( node.getName() );
3012 if ( node.getNodeData().isHasSequence() ) {
3013 if ( getControlPanel().isShowGeneSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) {
3014 if ( _sb.length() > 0 ) {
3017 _sb.append( node.getNodeData().getSequence().getSymbol() );
3019 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3020 if ( _sb.length() > 0 ) {
3023 _sb.append( node.getNodeData().getSequence().getName() );
3025 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3026 if ( _sb.length() > 0 ) {
3029 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3030 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3033 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3036 if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) {
3037 if ( _sb.length() > 0 ) {
3040 _sb.append( propertiesToString( node ) );
3042 g.setFont( getTreeFontSet().getLargeFont() );
3043 if ( is_in_found_nodes ) {
3044 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3046 double down_shift_factor = 3.0;
3047 if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
3048 down_shift_factor = 1;
3050 final double pos_x = node.getXcoord() + x + 2 + half_box_size;
3051 final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
3052 final String sb_str = _sb.toString();
3053 // GUILHEM_BEG ______________
3054 if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
3055 && ( _query_sequence != null ) ) {
3056 int nodeTextBoundsWidth = 0;
3057 if ( sb_str.length() > 0 ) {
3058 final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
3059 nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
3061 if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
3062 if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
3063 g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
3064 g.setColor( getTreeColorSet().getBackgroundColor() );
3068 final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
3069 for( final SequenceRelation seqRelation : seqRelations ) {
3070 final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation
3071 .getRef1().isEqual( _query_sequence ) )
3072 && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox()
3073 .getSelectedItem() );
3074 if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
3075 final double linePosX = node.getXcoord() + 2 + half_box_size;
3076 final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation
3077 .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue()
3079 if ( sConfidence != null ) {
3080 double confidenceX = pos_x;
3081 if ( sb_str.length() > 0 ) {
3082 confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
3083 + CONFIDENCE_LEFT_MARGIN;
3085 if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
3086 final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
3087 .getBounds().getWidth();
3088 TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
3089 x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
3092 if ( x + nodeTextBoundsWidth > 0 ) /* we only underline if there is something displayed */
3094 if ( nodeTextBoundsWidth == 0 ) {
3095 nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
3098 nodeTextBoundsWidth += 2;
3100 g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x
3101 + nodeTextBoundsWidth, 3 + ( int ) pos_y );
3108 if ( sb_str.length() > 0 ) {
3109 TreePanel.drawString( sb_str, pos_x, pos_y, g );
3111 // GUILHEM_END _____________
3112 // COMMENTED_OUT_BY_GUILHEM_BEG _______________
3113 // TODO FIXME need to check this one!
3114 //if ( _sb.length() > 0 ) {
3115 // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord()
3116 // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3118 // COMMENTED_OUT_BY_GUILHEM_END ________________
3119 if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
3120 && ( node.getNodeData().getSequence().getAnnotations() != null )
3121 && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
3122 if ( _sb.length() > 0 ) {
3123 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
3125 final Annotation ann = node.getNodeData().getSequence().getAnnotation( 0 );
3126 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3127 g.setColor( Color.BLACK );
3130 g.setColor( calculateColorForAnnotation( ann ) );
3132 final String ann_str = ann.asSimpleText().toString();
3133 TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
3134 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3136 _sb.append( ann_str );
3138 if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
3139 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
3140 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
3141 if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
3142 && node.getNodeData().isHasBinaryCharacters() ) {
3143 if ( _sb.length() > 0 ) {
3144 x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
3146 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3147 g.setColor( Color.BLACK );
3150 g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
3152 if ( getControlPanel().isShowBinaryCharacters() ) {
3153 TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
3154 .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord()
3155 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3156 paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters()
3157 .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters()
3158 .getLostCharactersAsStringBuffer().toString() );
3161 if ( DRAW_MEAN_COUNTS && node.isInternal() ) {
3162 final List<PhylogenyNode> ec = node.getAllExternalDescendants();
3165 for( final PhylogenyNode phylogenyNode : ec ) {
3167 if ( phylogenyNode.getNodeData().getBinaryCharacters() != null ) {
3168 sum += phylogenyNode.getNodeData().getBinaryCharacters().getPresentCount();
3171 final double mean = ForesterUtil.round( sum / count, 1 );
3172 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount() + " ["
3173 + mean + "]", node.getXcoord() + x + 4 + half_box_size, node.getYcoord()
3174 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
3177 TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
3178 node.getXcoord() + x + 4 + half_box_size,
3180 + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ),
3183 paintGainedAndLostCharacters( g, node, "+"
3184 + node.getNodeData().getBinaryCharacters().getGainedCount(), "-"
3185 + node.getNodeData().getBinaryCharacters().getLostCount() );
3191 private StringBuffer propertiesToString( final PhylogenyNode node ) {
3192 final PropertiesMap properties = node.getNodeData().getProperties();
3193 final StringBuffer sb = new StringBuffer();
3194 boolean first = true;
3195 for( final String ref : properties.getPropertyRefs() ) {
3202 final Property p = properties.getProperty( ref );
3203 sb.append( getPartAfterColon( p.getRef() ) );
3205 sb.append( p.getValue() );
3206 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
3207 sb.append( getPartAfterColon( p.getUnit() ) );
3213 final private static String getPartAfterColon( final String s ) {
3214 final int i = s.indexOf( ':' );
3215 if ( ( i < 1 ) || ( i == ( s.length() - 1 ) ) ) {
3218 return s.substring( i + 1, s.length() );
3221 private double drawTaxonomyImage( final double x, final double y, final PhylogenyNode node, final Graphics2D g ) {
3222 final List<Uri> us = new ArrayList<Uri>();
3223 for( final Taxonomy t : node.getNodeData().getTaxonomies() ) {
3224 for( final Uri uri : t.getUris() ) {
3229 for( final Uri uri : us ) {
3230 if ( uri != null ) {
3231 final String uri_str = uri.getValue().toString().toLowerCase();
3232 if ( getImageMap().containsKey( uri_str ) ) {
3233 final BufferedImage bi = getImageMap().get( uri_str );
3234 if ( ( bi != null ) && ( bi.getHeight() > 5 ) && ( bi.getWidth() > 5 ) ) {
3235 double scaling_factor = 1;
3236 if ( getOptions().isAllowMagnificationOfTaxonomyImages()
3237 || ( bi.getHeight() > ( 1.8 * getYdistance() ) ) ) {
3238 scaling_factor = ( 1.8 * getYdistance() ) / bi.getHeight();
3240 // y = y - ( 0.9 * getYdistance() );
3241 final double hs = bi.getHeight() * scaling_factor;
3242 double ws = bi.getWidth() * scaling_factor + offset;
3243 final double my_y = y - ( 0.5 * hs );
3244 final int x_w = ( int ) ( x + ws + 0.5 );
3245 final int y_h = ( int ) ( my_y + hs + 0.5 );
3246 if ( ( x_w - x > 7 ) && ( y_h - my_y > 7 ) ) {
3248 ( int ) ( x + 0.5 + offset ),
3249 ( int ) ( my_y + 0.5 ),
3270 final private void paintNodeDataUnrootedCirc( final Graphics2D g,
3271 final PhylogenyNode node,
3272 final boolean to_pdf,
3273 final boolean to_graphics_file,
3274 final boolean radial_labels,
3275 final double ur_angle,
3276 final boolean is_in_found_nodes ) {
3277 if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
3280 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3281 g.setColor( Color.BLACK );
3283 else if ( is_in_found_nodes ) {
3284 g.setColor( getTreeColorSet().getFoundColor() );
3286 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3287 g.setColor( getTaxonomyBasedColor( node ) );
3290 g.setColor( getTreeColorSet().getSequenceColor() );
3294 if ( node.getNodeData().isHasTaxonomy()
3295 && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
3296 .isShowTaxonomyCommonNames() ) ) {
3297 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3298 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3299 _sb.append( taxonomy.getTaxonomyCode() );
3302 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3303 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3304 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3305 _sb.append( taxonomy.getScientificName() );
3307 _sb.append( taxonomy.getCommonName() );
3310 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3311 _sb.append( taxonomy.getScientificName() );
3314 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3315 _sb.append( taxonomy.getCommonName() );
3319 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3320 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3321 _sb.append( taxonomy.getScientificName() );
3325 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
3326 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3327 _sb.append( taxonomy.getCommonName() );
3332 if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
3334 _sb.append( node.getAllExternalDescendants().size() );
3337 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3338 if ( _sb.length() > 0 ) {
3341 _sb.append( node.getName() );
3343 if ( node.getNodeData().isHasSequence() ) {
3344 if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3345 if ( _sb.length() > 0 ) {
3348 if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) {
3349 _sb.append( node.getNodeData().getSequence().getAccession().getSource() );
3352 _sb.append( node.getNodeData().getSequence().getAccession().getValue() );
3354 if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) {
3355 if ( _sb.length() > 0 ) {
3358 _sb.append( node.getNodeData().getSequence().getName() );
3361 g.setFont( getTreeFontSet().getLargeFont() );
3362 if ( is_in_found_nodes ) {
3363 g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
3365 if ( _sb.length() > 1 ) {
3366 final String sb_str = _sb.toString();
3368 if ( _graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3369 m = _urt_nodeid_angle_map.get( node.getId() ) % TWO_PI;
3372 m = ( float ) ( ur_angle % TWO_PI );
3374 _at = g.getTransform();
3375 boolean need_to_reset = false;
3376 final float x_coord = node.getXcoord();
3377 final float y_coord = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / 3.0f );
3378 if ( radial_labels ) {
3379 need_to_reset = true;
3380 boolean left = false;
3381 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3385 g.rotate( m, x_coord, node.getYcoord() );
3387 g.translate( -( getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth() ), 0 );
3391 if ( ( m > HALF_PI ) && ( m < ONEHALF_PI ) ) {
3392 need_to_reset = true;
3393 g.translate( -getTreeFontSet()._fm_large.getStringBounds( sb_str, g ).getWidth(), 0 );
3396 TreePanel.drawString( sb_str, x_coord, y_coord, g );
3397 if ( need_to_reset ) {
3398 g.setTransform( _at );
3403 final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) {
3404 if ( node.isCollapse() ) {
3405 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
3406 paintCollapsedNode( g, node, false, false, false );
3410 if ( isInFoundNodes( node ) ) {
3411 g.setColor( getTreeColorSet().getFoundColor() );
3412 drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
3415 if ( !node.isExternal() && !node.isCollapse() ) {
3416 boolean first_child = true;
3418 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3419 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3420 final PhylogenyNode child_node = node.getChildNode( i );
3422 if ( !isUniformBranchLengthsForCladogram() ) {
3423 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3426 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
3428 if ( first_child ) {
3429 first_child = false;
3430 y2 = node.getYSecondary()
3431 - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node
3432 .getNumberOfExternalNodes() ) );
3435 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3437 final float x2 = calculateOvBranchLengthToParent( child_node, factor_x );
3438 new_x = x2 + node.getXSecondary();
3439 final float diff_y = node.getYSecondary() - y2;
3440 final float diff_x = node.getXSecondary() - new_x;
3441 if ( ( diff_y > 2 ) || ( diff_y < -2 ) || ( diff_x > 2 ) || ( diff_x < -2 ) ) {
3442 paintBranchLite( g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node );
3444 child_node.setXSecondary( new_x );
3445 child_node.setYSecondary( y2 );
3446 y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
3451 final private void paintNodeRectangular( final Graphics2D g,
3452 final PhylogenyNode node,
3453 final boolean to_pdf,
3454 final boolean dynamically_hide,
3455 final int dynamic_hiding_factor,
3456 final boolean to_graphics_file ) {
3457 final boolean is_in_found_nodes = isInFoundNodes( node );
3458 if ( node.isCollapse() ) {
3459 if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
3460 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3464 if ( node.isExternal() ) {
3465 ++_external_node_index;
3467 // Confidence values
3468 if ( getControlPanel().isShowConfidenceValues()
3469 && !node.isExternal()
3471 && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
3472 || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
3473 && node.getBranchData().isHasConfidences() ) {
3474 paintConfidenceValues( g, node, to_pdf, to_graphics_file );
3476 // Draw a line to root:
3477 if ( node.isRoot() && _phylogeny.isRooted() ) {
3478 paintRootBranch( g, node.getXcoord(), node.getYcoord(), node, to_pdf, to_graphics_file );
3481 float new_x_min = Float.MAX_VALUE;
3482 final boolean disallow_shortcutting = dynamic_hiding_factor < 40;
3483 float min_dist = 1.5f;
3484 if ( !disallow_shortcutting ) {
3485 // System.out.println( dynamic_hiding_factor );
3486 if ( dynamic_hiding_factor > 4000 ) {
3489 else if ( dynamic_hiding_factor > 1000 ) {
3492 else if ( dynamic_hiding_factor > 100 ) {
3496 if ( !node.isExternal() && !node.isCollapse() ) {
3497 boolean first_child = true;
3499 final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
3500 for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
3501 final PhylogenyNode child_node = node.getChildNode( i );
3503 if ( !isUniformBranchLengthsForCladogram() ) {
3504 factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
3507 factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node );
3509 if ( first_child ) {
3510 first_child = false;
3511 y2 = node.getYcoord()
3512 - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) );
3515 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3517 final float x2 = calculateBranchLengthToParent( child_node, factor_x );
3518 new_x = x2 + node.getXcoord();
3519 if ( dynamically_hide && ( x2 < new_x_min ) ) {
3522 final float diff_y = node.getYcoord() - y2;
3523 final float diff_x = node.getXcoord() - new_x;
3524 if ( disallow_shortcutting || ( diff_y > min_dist ) || ( diff_y < -min_dist ) || ( diff_x > min_dist )
3525 || ( diff_x < -min_dist ) || to_graphics_file || to_pdf ) {
3526 paintBranchRectangular( g,
3535 child_node.setXcoord( new_x );
3536 child_node.setYcoord( y2 );
3537 y2 += _y_distance * child_node.getNumberOfExternalNodes();
3539 paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
3541 if ( dynamically_hide
3542 && !is_in_found_nodes
3543 && ( ( node.isExternal() && ( _external_node_index % dynamic_hiding_factor != 1 ) ) || ( !node
3544 .isExternal() && ( ( new_x_min < 20 ) || ( _y_distance * node.getNumberOfExternalNodes() < getTreeFontSet()._fm_large
3545 .getHeight() ) ) ) ) ) {
3548 paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
3549 paintNodeWithRenderableData( g, node, to_graphics_file, to_pdf );
3552 final private void paintNodeWithRenderableData( final Graphics2D g,
3553 final PhylogenyNode node,
3554 final boolean to_graphics_file,
3555 final boolean to_pdf ) {
3556 if ( isNodeDataInvisible( node ) && !to_graphics_file ) {
3559 if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
3562 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
3563 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
3564 RenderableDomainArchitecture rds = null;
3565 if ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) {
3567 rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture();
3569 catch ( final ClassCastException cce ) {
3570 cce.printStackTrace();
3572 if ( rds != null ) {
3573 rds.setRenderingHeight( 6 );
3575 if ( getControlPanel().isShowTaxonomyCode()
3576 && ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( node ) ) ) ) {
3577 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( node ) + " " );
3579 if ( getControlPanel().isShowGeneNames()
3580 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) ) {
3581 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
3583 if ( getControlPanel().isShowGeneSymbols()
3584 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) ) {
3585 x += getTreeFontSet()._fm_large
3586 .stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
3588 if ( getControlPanel().isShowSequenceAcc()
3589 && ( node.getNodeData().getSequence().getAccession() != null ) ) {
3590 x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
3594 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
3595 x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
3597 rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
3602 if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
3603 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
3604 final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
3605 getStatisticsForExpressionValues(),
3606 getConfiguration() );
3609 PhylogenyNode my_node = node;
3610 if ( !getControlPanel().isDrawPhylogram() ) {
3611 my_node = getPhylogeny().getFirstExternalNode();
3613 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) {
3614 x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " );
3616 if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) {
3617 x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " );
3619 rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf );
3625 final private void paintOvRectangle( final Graphics2D g ) {
3626 final float w_ratio = ( float ) getWidth() / getVisibleRect().width;
3627 final float h_ratio = ( float ) getHeight() / getVisibleRect().height;
3628 final float x_ratio = ( float ) getWidth() / getVisibleRect().x;
3629 final float y_ratio = ( float ) getHeight() / getVisibleRect().y;
3630 final float width = getOvMaxWidth() / w_ratio;
3631 final float height = getOvMaxHeight() / h_ratio;
3632 final float x = getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / x_ratio;
3633 final float y = getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / y_ratio;
3634 g.setColor( getTreeColorSet().getFoundColor() );
3635 getOvRectangle().setRect( x, y, width, height );
3636 if ( ( width < 6 ) && ( height < 6 ) ) {
3637 drawRectFilled( x, y, 6, 6, g );
3638 getOvVirtualRectangle().setRect( x, y, 6, 6 );
3640 else if ( width < 6 ) {
3641 drawRectFilled( x, y, 6, height, g );
3642 getOvVirtualRectangle().setRect( x, y, 6, height );
3644 else if ( height < 6 ) {
3645 drawRectFilled( x, y, width, 6, g );
3646 getOvVirtualRectangle().setRect( x, y, width, 6 );
3649 drawRect( x, y, width, height, g );
3650 if ( isInOvRect() ) {
3651 drawRect( x + 1, y + 1, width - 2, height - 2, g );
3653 getOvVirtualRectangle().setRect( x, y, width, height );
3657 final void paintPhylogeny( final Graphics2D g,
3658 final boolean to_pdf,
3659 final boolean to_graphics_file,
3660 final int graphics_file_width,
3661 final int graphics_file_height,
3662 final int graphics_file_x,
3663 final int graphics_file_y ) {
3664 if ( _control_panel.isShowSequenceRelations() ) {
3665 _query_sequence = _control_panel.getSelectedQuerySequence();
3667 // Color the background
3669 final Rectangle r = getVisibleRect();
3670 if ( !getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite() ) {
3671 g.setColor( getTreeColorSet().getBackgroundColor() );
3672 if ( !to_graphics_file ) {
3676 if ( getOptions().isPrintBlackAndWhite() ) {
3677 g.setColor( Color.WHITE );
3679 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
3683 if ( !to_graphics_file ) {
3684 g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y
3685 + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) );
3689 g.setPaint( new GradientPaint( graphics_file_x,
3691 getTreeColorSet().getBackgroundColor(),
3693 graphics_file_y + graphics_file_height,
3694 getTreeColorSet().getBackgroundColorGradientBottom() ) );
3695 g.fillRect( graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height );
3698 g.setStroke( new BasicStroke( 1 ) );
3701 g.setStroke( new BasicStroke( getOptions().getPrintLineWidth() ) );
3703 if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
3704 && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
3705 _external_node_index = 0;
3706 // Position starting X of tree
3707 if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) {
3708 _phylogeny.getRoot().setXcoord( TreePanel.MOVE );
3710 else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) {
3711 _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot()
3712 .getDistanceToParent() * getXcorrectionFactor() ) ) );
3715 _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() );
3717 // Position starting Y of tree
3718 _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() )
3719 + ( TreePanel.MOVE / 2.0f ) );
3720 final int dynamic_hiding_factor = ( int ) ( getTreeFontSet()._fm_large.getHeight() / ( 1.5 * getYdistance() ) );
3721 if ( getControlPanel().isDynamicallyHideData() ) {
3722 if ( dynamic_hiding_factor > 1 ) {
3723 getControlPanel().setDynamicHidingIsOn( true );
3726 getControlPanel().setDynamicHidingIsOn( false );
3729 if ( _nodes_in_preorder == null ) {
3730 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
3732 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3733 _nodes_in_preorder[ i++ ] = it.next();
3736 //final PhylogenyNodeIterator it;
3737 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3738 // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
3739 // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
3741 for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
3742 paintNodeRectangular( g, _nodes_in_preorder[ i ], to_pdf, getControlPanel().isDynamicallyHideData()
3743 && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
3745 if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
3746 if ( !( to_graphics_file || to_pdf ) ) {
3749 getVisibleRect().y + getVisibleRect().height,
3754 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
3757 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3758 paintPhylogenyLite( g );
3761 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
3762 if ( getControlPanel().getDynamicallyHideData() != null ) {
3763 getControlPanel().setDynamicHidingIsOn( false );
3765 final double angle = getStartingAngle();
3766 final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
3767 _dynamic_hiding_factor = 0;
3768 if ( getControlPanel().isDynamicallyHideData() ) {
3769 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
3770 .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) );
3772 if ( getControlPanel().getDynamicallyHideData() != null ) {
3773 if ( _dynamic_hiding_factor > 1 ) {
3774 getControlPanel().setDynamicHidingIsOn( true );
3777 getControlPanel().setDynamicHidingIsOn( false );
3780 paintUnrooted( _phylogeny.getRoot(),
3782 ( float ) ( angle + 2 * Math.PI ),
3787 if ( getOptions().isShowScale() ) {
3788 if ( !( to_graphics_file || to_pdf ) ) {
3791 getVisibleRect().y + getVisibleRect().height,
3796 paintScale( g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file );
3799 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3800 g.setColor( getTreeColorSet().getOvColor() );
3801 paintUnrootedLite( _phylogeny.getRoot(),
3803 angle + 2 * Math.PI,
3805 ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) );
3806 paintOvRectangle( g );
3809 else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
3810 final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) );
3811 final int d = radius + MOVE + getLongestExtNodeInfo();
3812 _dynamic_hiding_factor = 0;
3813 if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) {
3814 _dynamic_hiding_factor = ( int ) ( ( getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny()
3815 .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) );
3817 if ( getControlPanel().getDynamicallyHideData() != null ) {
3818 if ( _dynamic_hiding_factor > 1 ) {
3819 getControlPanel().setDynamicHidingIsOn( true );
3822 getControlPanel().setDynamicHidingIsOn( false );
3825 paintCircular( _phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file );
3826 if ( getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf ) {
3827 final int radius_ov = ( int ) ( getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
3828 : getOvMaxWidth() / 2 );
3829 double x_scale = 1.0;
3830 double y_scale = 1.0;
3831 int x_pos = getVisibleRect().x + getOvXPosition();
3832 int y_pos = getVisibleRect().y + getOvYPosition();
3833 if ( getWidth() > getHeight() ) {
3834 x_scale = ( double ) getHeight() / getWidth();
3835 x_pos = ForesterUtil.roundToInt( x_pos / x_scale );
3838 y_scale = ( double ) getWidth() / getHeight();
3839 y_pos = ForesterUtil.roundToInt( y_pos / y_scale );
3841 _at = g.getTransform();
3842 g.scale( x_scale, y_scale );
3843 paintCircularLite( _phylogeny,
3847 ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle()
3850 g.setTransform( _at );
3851 paintOvRectangle( g );
3856 final private void paintPhylogenyLite( final Graphics2D g ) {
3857 //System.out.println( getVisibleRect().x + " " + getVisibleRect().y );
3860 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
3861 .getWidth() ) ) ) );
3862 _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
3863 //final PhylogenyNodeIterator it;
3864 //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
3865 // paintNodeLite( g, it.next() );
3867 for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
3868 paintNodeLite( g, _nodes_in_preorder[ i ] );
3870 paintOvRectangle( g );
3874 * Paint the root branch. (Differs from others because it will always be a
3875 * single horizontal line).
3876 * @param to_graphics_file
3878 * @return new x1 value
3880 final private void paintRootBranch( final Graphics2D g,
3883 final PhylogenyNode root,
3884 final boolean to_pdf,
3885 final boolean to_graphics_file ) {
3886 assignGraphicsForBranchWithColorForParentBranch( root, false, g, to_pdf, to_graphics_file );
3887 float d = getXdistance();
3888 if ( getControlPanel().isDrawPhylogram() && ( root.getDistanceToParent() > 0.0 ) ) {
3889 d = ( float ) ( getXcorrectionFactor() * root.getDistanceToParent() );
3891 if ( d < MIN_ROOT_LENGTH ) {
3892 d = MIN_ROOT_LENGTH;
3894 if ( !getControlPanel().isWidthBranches() || ( PhylogenyMethods.getBranchWidthValue( root ) == 1 ) ) {
3895 drawLine( x1 - d, root.getYcoord(), x1, root.getYcoord(), g );
3898 final double w = PhylogenyMethods.getBranchWidthValue( root );
3899 drawRectFilled( x1 - d, root.getYcoord() - ( w / 2 ), d, w, g );
3901 paintNodeBox( x1, root.getYcoord(), root, g, to_pdf, to_graphics_file, isInFoundNodes( root ) );
3904 final private void paintScale( final Graphics2D g,
3907 final boolean to_pdf,
3908 final boolean to_graphics_file ) {
3910 final double x2 = x1 + ( getScaleDistance() * getXcorrectionFactor() );
3912 final int y2 = y1 - 8;
3913 final int y3 = y1 - 4;
3914 g.setFont( getTreeFontSet().getSmallFont() );
3915 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3916 g.setColor( Color.BLACK );
3919 g.setColor( getTreeColorSet().getBranchLengthColor() );
3921 drawLine( x1, y1, x1, y2, g );
3922 drawLine( x2, y1, x2, y2, g );
3923 drawLine( x1, y3, x2, y3, g );
3924 if ( getScaleLabel() != null ) {
3925 g.drawString( getScaleLabel(), ( x1 + 2 ), y3 - 2 );
3929 final private int paintTaxonomy( final Graphics2D g,
3930 final PhylogenyNode node,
3931 final boolean is_in_found_nodes,
3932 final boolean to_pdf,
3933 final boolean to_graphics_file,
3934 final double x_shift ) {
3935 final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
3936 g.setFont( getTreeFontSet().getLargeItalicFont() );
3937 if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
3938 g.setColor( Color.BLACK );
3940 else if ( is_in_found_nodes ) {
3941 g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
3942 g.setColor( getTreeColorSet().getFoundColor() );
3944 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
3945 g.setColor( getTaxonomyBasedColor( node ) );
3947 else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
3948 && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
3949 g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
3951 else if ( to_pdf ) {
3952 g.setColor( Color.BLACK );
3955 g.setColor( getTreeColorSet().getTaxonomyColor() );
3957 final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
3958 final double start_y = node.getYcoord()
3959 + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
3961 if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
3962 _sb.append( taxonomy.getTaxonomyCode() );
3965 if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
3966 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
3967 && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3968 if ( getOptions().isAbbreviateScientificTaxonNames()
3969 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3970 abbreviateScientificName( taxonomy.getScientificName() );
3973 _sb.append( taxonomy.getScientificName() );
3976 _sb.append( taxonomy.getCommonName() );
3979 else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3980 if ( getOptions().isAbbreviateScientificTaxonNames()
3981 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3982 abbreviateScientificName( taxonomy.getScientificName() );
3985 _sb.append( taxonomy.getScientificName() );
3989 else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
3990 _sb.append( taxonomy.getCommonName() );
3994 else if ( _control_panel.isShowTaxonomyScientificNames() ) {
3995 if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
3996 if ( getOptions().isAbbreviateScientificTaxonNames()
3997 && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
3998 abbreviateScientificName( taxonomy.getScientificName() );
4001 _sb.append( taxonomy.getScientificName() );
4006 else if ( _control_panel.isShowTaxonomyCommonNames() ) {
4007 if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
4008 _sb.append( taxonomy.getCommonName() );
4012 final String label = _sb.toString();
4014 if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 )
4015 && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) {
4016 // invert font color and background color to show that this is the query sequence
4017 final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null,
4021 g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 );
4022 g.setColor( getTreeColorSet().getBackgroundColor() );
4025 TreePanel.drawString( label, start_x, start_y, g );
4026 if ( is_in_found_nodes ) {
4027 return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
4030 return getTreeFontSet()._fm_large_italic.stringWidth( label );
4034 private void abbreviateScientificName( final String sn ) {
4035 final String[] a = sn.split( "\\s+" );
4036 _sb.append( a[ 0 ].substring( 0, 1 ) );
4037 _sb.append( a[ 1 ].substring( 0, 2 ) );
4038 if ( a.length > 2 ) {
4039 for( int i = 2; i < a.length; i++ ) {
4041 _sb.append( a[ i ] );
4046 final private void paintUnrooted( final PhylogenyNode n,
4047 final double low_angle,
4048 final double high_angle,
4049 final boolean radial_labels,
4051 final boolean to_pdf,
4052 final boolean to_graphics_file ) {
4054 n.setXcoord( getWidth() / 2 );
4055 n.setYcoord( getHeight() / 2 );
4057 if ( n.isExternal() ) {
4058 paintNodeDataUnrootedCirc( g,
4063 ( high_angle + low_angle ) / 2,
4064 isInFoundNodes( n ) );
4067 final float num_enclosed = n.getNumberOfExternalNodes();
4068 final float x = n.getXcoord();
4069 final float y = n.getYcoord();
4070 double current_angle = low_angle;
4071 // final boolean n_below = n.getYcoord() < getVisibleRect().getMinY() - 20;
4072 // final boolean n_above = n.getYcoord() > getVisibleRect().getMaxY() + 20;
4073 // final boolean n_left = n.getXcoord() < getVisibleRect().getMinX() - 20;
4074 // final boolean n_right = n.getXcoord() > getVisibleRect().getMaxX() + 20;
4075 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4076 final PhylogenyNode desc = n.getChildNode( i );
4077 /// if ( ( ( n_below ) & ( desc.getYcoord() < getVisibleRect().getMinY() - 20 ) )
4078 // || ( ( n_above ) & ( desc.getYcoord() > getVisibleRect().getMaxY() + 20 ) )
4079 // || ( ( n_left ) & ( desc.getXcoord() < getVisibleRect().getMinX() - 20 ) )
4080 // || ( ( n_right ) & ( desc.getXcoord() > getVisibleRect().getMaxX() + 20 ) ) ) {
4083 //if ( ( desc.getYcoord() > n.getYcoord() ) && ( n.getYcoord() > getVisibleRect().getMaxY() - 20 ) ) {
4086 //if ( ( desc.getYcoord() < n.getYcoord() ) && ( n.getYcoord() < getVisibleRect().getMinY() + 20 ) ) {
4089 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4090 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4092 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4093 if ( desc.getDistanceToParent() < 0 ) {
4097 length = ( float ) ( desc.getDistanceToParent() * getUrtFactor() );
4101 length = getUrtFactor();
4103 final double mid_angle = current_angle + arc_size / 2;
4104 final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length );
4105 final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length );
4106 desc.setXcoord( new_x );
4107 desc.setYcoord( new_y );
4108 paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file );
4109 current_angle += arc_size;
4110 assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
4111 drawLine( x, y, new_x, new_y, g );
4112 paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc ) );
4115 paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file, isInFoundNodes( n ) );
4119 final private void paintUnrootedLite( final PhylogenyNode n,
4120 final double low_angle,
4121 final double high_angle,
4123 final float urt_ov_factor ) {
4125 final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / 2 );
4126 final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / 2 );
4127 n.setXSecondary( x_pos );
4128 n.setYSecondary( y_pos );
4130 if ( n.isExternal() ) {
4133 final float num_enclosed = n.getNumberOfExternalNodes();
4134 final float x = n.getXSecondary();
4135 final float y = n.getYSecondary();
4136 double current_angle = low_angle;
4137 for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
4138 final PhylogenyNode desc = n.getChildNode( i );
4139 final int desc_num_enclosed = desc.getNumberOfExternalNodes();
4140 final double arc_size = ( desc_num_enclosed / num_enclosed ) * ( high_angle - low_angle );
4142 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4143 if ( desc.getDistanceToParent() < 0 ) {
4147 length = ( float ) ( desc.getDistanceToParent() * urt_ov_factor );
4151 length = urt_ov_factor;
4153 final double mid_angle = current_angle + arc_size / 2;
4154 final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length );
4155 final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length );
4156 desc.setXSecondary( new_x );
4157 desc.setYSecondary( new_y );
4158 if ( isInFoundNodes( desc ) ) {
4159 g.setColor( getTreeColorSet().getFoundColor() );
4160 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
4161 g.setColor( getTreeColorSet().getOvColor() );
4163 paintUnrootedLite( desc, current_angle, current_angle + arc_size, g, urt_ov_factor );
4164 current_angle += arc_size;
4165 drawLine( x, y, new_x, new_y, g );
4169 final private void pasteSubtree( final PhylogenyNode node ) {
4170 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4171 errorMessageNoCutCopyPasteInUnrootedDisplay();
4174 if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
4175 JOptionPane.showMessageDialog( this,
4176 "No tree in buffer (need to copy or cut a subtree first)",
4177 "Attempt to paste with empty buffer",
4178 JOptionPane.ERROR_MESSAGE );
4181 final String label = getASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
4182 final Object[] options = { "As sibling", "As descendant", "Cancel" };
4183 final int r = JOptionPane.showOptionDialog( this,
4184 "How to paste subtree" + label + "?",
4186 JOptionPane.CLOSED_OPTION,
4187 JOptionPane.QUESTION_MESSAGE,
4191 boolean paste_as_sibling = true;
4193 paste_as_sibling = false;
4195 else if ( r != 0 ) {
4198 final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
4199 buffer_phy.setAllNodesToNotCollapse();
4200 buffer_phy.preOrderReId();
4201 buffer_phy.setRooted( true );
4202 boolean need_to_show_whole = false;
4203 if ( paste_as_sibling ) {
4204 if ( node.isRoot() ) {
4205 JOptionPane.showMessageDialog( this,
4206 "Cannot paste sibling to root",
4207 "Attempt to paste sibling to root",
4208 JOptionPane.ERROR_MESSAGE );
4211 buffer_phy.addAsSibling( node );
4214 if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
4215 need_to_show_whole = true;
4216 _phylogeny = buffer_phy;
4219 buffer_phy.addAsChild( node );
4222 if ( getCopiedAndPastedNodes() == null ) {
4223 setCopiedAndPastedNodes( new HashSet<Integer>() );
4225 final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
4226 final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
4227 for( final PhylogenyNode n : nodes ) {
4228 node_ids.add( n.getId() );
4230 node_ids.add( node.getId() );
4231 getCopiedAndPastedNodes().addAll( node_ids );
4232 setNodeInPreorderToNull();
4233 _phylogeny.externalNodesHaveChanged();
4234 _phylogeny.hashIDs();
4235 _phylogeny.recalculateNumberOfExternalDescendants( true );
4236 resetNodeIdToDistToLeafMap();
4238 if ( need_to_show_whole ) {
4239 getControlPanel().showWhole();
4244 final public int print( final Graphics g, final PageFormat page_format, final int page_index )
4245 throws PrinterException {
4246 if ( page_index > 0 ) {
4247 return ( NO_SUCH_PAGE );
4250 final Graphics2D g2d = ( Graphics2D ) g;
4251 g2d.translate( page_format.getImageableX(), page_format.getImageableY() );
4252 // Turn off double buffering !?
4253 paintPhylogeny( g2d, true, false, 0, 0, 0, 0 );
4254 // Turn double buffering back on !?
4255 return ( PAGE_EXISTS );
4259 final void recalculateMaxDistanceToRoot() {
4260 _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
4264 * Remove all edit-node frames
4266 final void removeAllEditNodeJFrames() {
4267 for( int i = 0; i <= ( TreePanel.MAX_NODE_FRAMES - 1 ); i++ ) {
4268 if ( _node_frames[ i ] != null ) {
4269 _node_frames[ i ].dispose();
4270 _node_frames[ i ] = null;
4273 _node_frame_index = 0;
4277 * Remove a node-edit frame.
4279 final void removeEditNodeFrame( final int i ) {
4280 _node_frame_index--;
4281 _node_frames[ i ] = null;
4282 if ( i < _node_frame_index ) {
4283 for( int j = 0; j < _node_frame_index - 1; j++ ) {
4284 _node_frames[ j ] = _node_frames[ j + 1 ];
4286 _node_frames[ _node_frame_index ] = null;
4290 final void reRoot( final PhylogenyNode node ) {
4291 if ( !getPhylogeny().isRerootable() ) {
4292 JOptionPane.showMessageDialog( this,
4293 "This is not rerootable",
4295 JOptionPane.WARNING_MESSAGE );
4298 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4299 JOptionPane.showMessageDialog( this,
4300 "Cannot reroot in unrooted display type",
4301 "Attempt to reroot tree in unrooted display",
4302 JOptionPane.WARNING_MESSAGE );
4305 getPhylogeny().reRoot( node );
4306 getPhylogeny().recalculateNumberOfExternalDescendants( true );
4307 resetNodeIdToDistToLeafMap();
4308 setNodeInPreorderToNull();
4309 resetPreferredSize();
4310 getMainPanel().adjustJScrollPane();
4312 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
4313 getControlPanel().showWhole();
4317 final void resetNodeIdToDistToLeafMap() {
4318 _nodeid_dist_to_leaf = new HashMap<Integer, Short>();
4321 final void resetPreferredSize() {
4322 if ( ( getPhylogeny() == null ) || getPhylogeny().isEmpty() ) {
4328 + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 );
4329 if ( getControlPanel().isDrawPhylogram() ) {
4331 + getLongestExtNodeInfo()
4333 .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
4336 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4338 + getLongestExtNodeInfo()
4339 + ForesterUtil.roundToInt( getXdistance()
4340 * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) );
4344 + getLongestExtNodeInfo()
4345 + ForesterUtil.roundToInt( getXdistance()
4346 * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) );
4349 setPreferredSize( new Dimension( x, y ) );
4352 public final void setArrowCursor() {
4353 setCursor( ARROW_CURSOR );
4357 final void setControlPanel( final ControlPanel atv_control ) {
4358 _control_panel = atv_control;
4361 final private void setCopiedAndPastedNodes( final Set<Integer> nodeIds ) {
4362 getMainPanel().setCopiedAndPastedNodes( nodeIds );
4365 final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
4366 getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
4369 public final void setEdited( final boolean edited ) {
4373 final void setFoundNodes( final Set<Integer> found_nodes ) {
4374 _found_nodes = found_nodes;
4377 final private void setInOv( final boolean in_ov ) {
4381 final void setInOvRect( final boolean in_ov_rect ) {
4382 _in_ov_rect = in_ov_rect;
4385 final void setLargeFonts() {
4386 getTreeFontSet().largeFonts();
4389 final void setLastMouseDragPointX( final float x ) {
4390 _last_drag_point_x = x;
4393 final void setLastMouseDragPointY( final float y ) {
4394 _last_drag_point_y = y;
4397 final void setLongestExtNodeInfo( final int i ) {
4398 _longest_ext_node_info = i;
4401 final void setMediumFonts() {
4402 getTreeFontSet().mediumFonts();
4405 final private void setOvMaxHeight( final float ov_max_height ) {
4406 _ov_max_height = ov_max_height;
4409 final private void setOvMaxWidth( final float ov_max_width ) {
4410 _ov_max_width = ov_max_width;
4413 final void setOvOn( final boolean ov_on ) {
4417 final private void setOvXcorrectionFactor( final float f ) {
4418 _ov_x_correction_factor = f;
4421 final private void setOvXDistance( final float ov_x_distance ) {
4422 _ov_x_distance = ov_x_distance;
4425 final private void setOvXPosition( final int ov_x_position ) {
4426 _ov_x_position = ov_x_position;
4429 final private void setOvYDistance( final float ov_y_distance ) {
4430 _ov_y_distance = ov_y_distance;
4433 final private void setOvYPosition( final int ov_y_position ) {
4434 _ov_y_position = ov_y_position;
4437 final private void setOvYStart( final int ov_y_start ) {
4438 _ov_y_start = ov_y_start;
4442 * Set parameters for printing the displayed tree
4447 public final void setParametersForPainting( final int x, final int y, final boolean recalc_longest_ext_node_info ) {
4448 // updateStyle(); not needed?
4449 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4451 if ( recalc_longest_ext_node_info ) {
4452 calculateLongestExtNodeInfo();
4454 int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
4455 final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
4456 if ( ext_nodes == 1 ) {
4457 ext_nodes = max_depth;
4458 if ( ext_nodes < 1 ) {
4465 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
4466 xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
4467 ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
4470 xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
4471 ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
4473 float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
4474 if ( xdist < 0.0 ) {
4477 if ( ov_xdist < 0.0 ) {
4480 if ( ydist < 0.0 ) {
4483 setXdistance( xdist );
4484 setYdistance( ydist );
4485 setOvXDistance( ov_xdist );
4486 final double height = _phylogeny.getHeight();
4488 final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
4489 setXcorrectionFactor( corr > 0 ? corr : 0 );
4490 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
4491 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
4494 setXcorrectionFactor( 0 );
4495 setOvXcorrectionFactor( 0 );
4497 _circ_max_depth = max_depth;
4502 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE graphics_type ) {
4503 _graphics_type = graphics_type;
4507 final private void setScaleDistance( final double scale_distance ) {
4508 _scale_distance = scale_distance;
4511 final private void setScaleLabel( final String scale_label ) {
4512 _scale_label = scale_label;
4515 final void setSmallFonts() {
4516 getTreeFontSet().smallFonts();
4519 final void setStartingAngle( final double starting_angle ) {
4520 _urt_starting_angle = starting_angle;
4523 final void setSuperTinyFonts() {
4524 getTreeFontSet().superTinyFonts();
4527 final void setTextAntialias() {
4528 if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
4529 if ( _phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING ) {
4530 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
4533 _rendering_hints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
4536 if ( getMainPanel().getOptions().isAntialiasScreen() ) {
4537 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) {
4538 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
4541 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
4544 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING,
4545 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB );
4547 catch ( final Throwable e ) {
4548 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
4552 _rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
4553 _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
4557 final void setTinyFonts() {
4558 getTreeFontSet().tinyFonts();
4562 * Set a phylogeny tree.
4565 * an instance of a Phylogeny
4567 public final void setTree( final Phylogeny t ) {
4568 setNodeInPreorderToNull();
4572 final void setNodeInPreorderToNull() {
4573 _nodes_in_preorder = null;
4576 final void setTreeFile( final File treefile ) {
4577 _treefile = treefile;
4580 final private void setUpUrtFactor() {
4581 final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
4582 : getVisibleRect().height;
4583 if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
4584 setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
4587 final int max_depth = _circ_max_depth;
4588 if ( max_depth > 0 ) {
4589 setUrtFactor( d / ( 2 * max_depth ) );
4592 setUrtFactor( d / 2 );
4595 setUrtFactorOv( getUrtFactor() );
4598 final private void setUrtFactor( final float urt_factor ) {
4599 _urt_factor = urt_factor;
4602 final private void setUrtFactorOv( final float urt_factor_ov ) {
4603 _urt_factor_ov = urt_factor_ov;
4606 public final void setWaitCursor() {
4607 setCursor( WAIT_CURSOR );
4611 final void setXcorrectionFactor( final float f ) {
4612 _x_correction_factor = f;
4615 final void setXdistance( final float x ) {
4619 final void setYdistance( final float y ) {
4623 final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
4625 if ( ( node.getName().length() > 0 )
4626 || ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) )
4627 || ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) )
4628 || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() )
4629 || node.getBranchData().isHasConfidences() ) {
4630 _popup_buffer.setLength( 0 );
4632 if ( node.getName().length() > 0 ) {
4634 _popup_buffer.append( node.getName() );
4636 if ( node.getNodeData().isHasTaxonomy() && !isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
4638 boolean enc_data = false;
4639 final Taxonomy tax = node.getNodeData().getTaxonomy();
4640 if ( _popup_buffer.length() > 0 ) {
4641 _popup_buffer.append( "\n" );
4643 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
4644 _popup_buffer.append( "[" );
4645 _popup_buffer.append( tax.getTaxonomyCode() );
4646 _popup_buffer.append( "]" );
4649 if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
4651 _popup_buffer.append( " " );
4653 _popup_buffer.append( tax.getScientificName() );
4656 if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
4658 _popup_buffer.append( " (" );
4661 _popup_buffer.append( "(" );
4663 _popup_buffer.append( tax.getCommonName() );
4664 _popup_buffer.append( ")" );
4667 if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
4669 _popup_buffer.append( " (" );
4672 _popup_buffer.append( "(" );
4674 _popup_buffer.append( tax.getAuthority() );
4675 _popup_buffer.append( ")" );
4678 if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
4680 _popup_buffer.append( " [" );
4683 _popup_buffer.append( "[" );
4685 _popup_buffer.append( tax.getRank() );
4686 _popup_buffer.append( "]" );
4689 if ( tax.getSynonyms().size() > 0 ) {
4691 _popup_buffer.append( " " );
4693 _popup_buffer.append( "[" );
4695 for( final String syn : tax.getSynonyms() ) {
4696 if ( !ForesterUtil.isEmpty( syn ) ) {
4698 _popup_buffer.append( syn );
4699 if ( counter < tax.getSynonyms().size() ) {
4700 _popup_buffer.append( ", " );
4705 _popup_buffer.append( "]" );
4708 if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
4709 if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
4710 _popup_buffer.append( "[" );
4711 _popup_buffer.append( tax.getIdentifier().getProvider() );
4712 _popup_buffer.append( "] " );
4714 _popup_buffer.append( tax.getIdentifier().getValue() );
4718 if ( node.getNodeData().isHasSequence() && !isSequenceEmpty( node.getNodeData().getSequence() ) ) {
4720 boolean enc_data = false;
4721 if ( _popup_buffer.length() > 0 ) {
4722 _popup_buffer.append( "\n" );
4724 final Sequence seq = node.getNodeData().getSequence();
4725 if ( seq.getAccession() != null ) {
4726 _popup_buffer.append( "[" );
4727 if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
4728 _popup_buffer.append( seq.getAccession().getSource() );
4729 _popup_buffer.append( ":" );
4731 _popup_buffer.append( seq.getAccession().getValue() );
4732 _popup_buffer.append( "]" );
4735 if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
4737 _popup_buffer.append( " [" );
4740 _popup_buffer.append( "[" );
4742 _popup_buffer.append( seq.getSymbol() );
4743 _popup_buffer.append( "]" );
4746 if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
4748 _popup_buffer.append( " " );
4750 _popup_buffer.append( seq.getName() );
4753 if ( node.getNodeData().isHasDate() ) {
4755 if ( _popup_buffer.length() > 0 ) {
4756 _popup_buffer.append( "\n" );
4758 _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
4760 if ( node.getNodeData().isHasDistribution() ) {
4762 if ( _popup_buffer.length() > 0 ) {
4763 _popup_buffer.append( "\n" );
4765 _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
4767 if ( node.getBranchData().isHasConfidences() ) {
4768 final List<Confidence> confs = node.getBranchData().getConfidences();
4769 for( final Confidence confidence : confs ) {
4771 if ( _popup_buffer.length() > 0 ) {
4772 _popup_buffer.append( "\n" );
4774 if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
4775 _popup_buffer.append( "[" );
4776 _popup_buffer.append( confidence.getType() );
4777 _popup_buffer.append( "] " );
4780 .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
4782 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4783 if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
4784 _popup_buffer.append( " (sd=" );
4785 _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence
4786 .getStandardDeviation(), getOptions()
4787 .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
4788 _popup_buffer.append( ")" );
4792 if ( node.getNodeData().isHasProperties() ) {
4793 final PropertiesMap properties = node.getNodeData().getProperties();
4794 for( final String ref : properties.getPropertyRefs() ) {
4795 _popup_buffer.append( "\n" );
4796 final Property p = properties.getProperty( ref );
4797 _popup_buffer.append( getPartAfterColon( p.getRef() ) );
4798 _popup_buffer.append( "=" );
4799 _popup_buffer.append( p.getValue() );
4800 if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
4801 _popup_buffer.append( getPartAfterColon( p.getUnit() ) );
4805 if ( _popup_buffer.length() > 0 ) {
4806 if ( !getConfiguration().isUseNativeUI() ) {
4808 .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
4809 _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
4810 if ( isInFoundNodes( node ) ) {
4811 _rollover_popup.setForeground( getTreeColorSet().getFoundColor() );
4813 else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
4814 _rollover_popup.setForeground( getTaxonomyBasedColor( node ) );
4817 _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
4821 _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
4823 _rollover_popup.setText( _popup_buffer.toString() );
4824 _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
4826 e.getLocationOnScreen().x + 10,
4827 e.getLocationOnScreen().y
4829 _node_desc_popup.show();
4833 catch ( final Exception ex ) {
4838 final private void showNodeEditFrame( final PhylogenyNode n ) {
4839 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4840 // pop up edit box for single node
4841 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
4842 _node_frame_index++;
4845 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4849 final private void showNodeFrame( final PhylogenyNode n ) {
4850 if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
4851 // pop up edit box for single node
4852 _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
4853 _node_frame_index++;
4856 JOptionPane.showMessageDialog( this, "too many node windows are open" );
4860 final void subTree( final PhylogenyNode node ) {
4861 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
4862 JOptionPane.showMessageDialog( this,
4863 "Cannot get a sub/super tree in unrooted display",
4864 "Attempt to get sub/super tree in unrooted display",
4865 JOptionPane.WARNING_MESSAGE );
4868 if ( node.isExternal() ) {
4869 JOptionPane.showMessageDialog( this,
4870 "Cannot get a subtree of a external node",
4871 "Attempt to get subtree of external node",
4872 JOptionPane.WARNING_MESSAGE );
4875 if ( node.isRoot() && !isCurrentTreeIsSubtree() ) {
4876 JOptionPane.showMessageDialog( this,
4877 "Cannot get a subtree of the root node",
4878 "Attempt to get subtree of root node",
4879 JOptionPane.WARNING_MESSAGE );
4882 setNodeInPreorderToNull();
4883 if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) {
4884 _sub_phylogenies[ _subtree_index ] = _phylogeny;
4885 _sub_phylogenies_temp_roots[ _subtree_index ] = node;
4887 _phylogeny = subTree( node, _phylogeny );
4888 updateSubSuperTreeButton();
4890 else if ( node.isRoot() && isCurrentTreeIsSubtree() ) {
4893 _main_panel.getControlPanel().showWhole();
4897 final boolean isCurrentTreeIsSubtree() {
4898 return ( _subtree_index > 0 );
4901 final private static Phylogeny subTree( final PhylogenyNode new_root, final Phylogeny source_phy ) {
4902 final Phylogeny new_phy = new Phylogeny();
4903 new_phy.setRooted( true );
4904 new_phy.setName( source_phy.getName() );
4905 new_phy.setDescription( source_phy.getDescription() );
4906 new_phy.setType( source_phy.getType() );
4907 new_phy.setDistanceUnit( source_phy.getDistanceUnit() );
4908 new_phy.setConfidence( source_phy.getConfidence() );
4909 new_phy.setIdentifier( source_phy.getIdentifier() );
4910 new_phy.setRoot( new_root.copyNodeDataShallow() );
4912 for( final PhylogenyNode n : new_root.getDescendants() ) {
4913 new_phy.getRoot().setChildNode( i++, n );
4918 final void superTree() {
4919 setNodeInPreorderToNull();
4920 final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ];
4921 for( final PhylogenyNode n : temp_root.getDescendants() ) {
4922 n.setParent( temp_root );
4924 _sub_phylogenies[ _subtree_index ] = null;
4925 _sub_phylogenies_temp_roots[ _subtree_index ] = null;
4926 _phylogeny = _sub_phylogenies[ --_subtree_index ];
4927 updateSubSuperTreeButton();
4930 final void swap( final PhylogenyNode node ) {
4931 if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) {
4934 if ( node.getNumberOfDescendants() > 2 ) {
4935 JOptionPane.showMessageDialog( this,
4936 "Cannot swap descendants of nodes with more than 2 descendants",
4937 "Cannot swap descendants",
4938 JOptionPane.ERROR_MESSAGE );
4941 if ( !node.isExternal() ) {
4942 node.swapChildren();
4943 setNodeInPreorderToNull();
4944 _phylogeny.externalNodesHaveChanged();
4945 _phylogeny.hashIDs();
4946 _phylogeny.recalculateNumberOfExternalDescendants( true );
4947 resetNodeIdToDistToLeafMap();
4953 final void sortDescendants( final PhylogenyNode node ) {
4954 if ( !node.isExternal() ) {
4955 DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
4956 if ( ( !getControlPanel().isShowTaxonomyScientificNames() && !getControlPanel().isShowTaxonomyCode() && !getControlPanel()
4957 .isShowTaxonomyCommonNames() ) ) {
4958 if ( ( getControlPanel().isShowSequenceAcc() || getControlPanel().isShowGeneNames() || getControlPanel()
4959 .isShowGeneSymbols() ) ) {
4960 pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
4962 else if ( getControlPanel().isShowNodeNames() ) {
4963 pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
4966 PhylogenyMethods.sortNodeDescendents( node, pri );
4967 setNodeInPreorderToNull();
4968 _phylogeny.externalNodesHaveChanged();
4969 _phylogeny.hashIDs();
4970 _phylogeny.recalculateNumberOfExternalDescendants( true );
4971 resetNodeIdToDistToLeafMap();
4977 final private void switchDisplaygetPhylogenyGraphicsType() {
4978 switch ( getPhylogenyGraphicsType() ) {
4980 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4981 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
4984 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4985 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
4988 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4989 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
4992 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4993 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
4996 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
4997 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
5000 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5001 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
5004 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5005 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
5008 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5009 getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
5012 throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
5014 if ( getControlPanel().getDynamicallyHideData() != null ) {
5015 if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
5016 getControlPanel().getDynamicallyHideData().setEnabled( false );
5019 getControlPanel().getDynamicallyHideData().setEnabled( true );
5022 if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
5023 getControlPanel().setDrawPhylogramEnabled( true );
5026 getControlPanel().setDrawPhylogramEnabled( false );
5028 if ( getMainPanel().getMainFrame() == null ) {
5029 // Must be "E" applet version.
5030 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
5031 .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5034 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
5038 final void taxColor() {
5039 if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
5043 AptxUtil.colorPhylogenyAccordingToExternalTaxonomy( _phylogeny, this );
5044 _control_panel.setColorBranches( true );
5045 if ( _control_panel.getColorBranchesCb() != null ) {
5046 _control_panel.getColorBranchesCb().setSelected( true );
5052 final void updateOvSettings() {
5053 switch ( getOptions().getOvPlacement() ) {
5055 setOvXPosition( OV_BORDER );
5056 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
5057 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
5060 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
5061 setOvYPosition( ForesterUtil.roundToInt( getVisibleRect().height - OV_BORDER - getOvMaxHeight() ) );
5062 setOvYStart( ForesterUtil.roundToInt( getOvYPosition() + ( getOvMaxHeight() / 2 ) ) );
5065 setOvXPosition( ForesterUtil.roundToInt( getVisibleRect().width - OV_BORDER - getOvMaxWidth() ) );
5066 setOvYPosition( OV_BORDER );
5067 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
5070 setOvXPosition( OV_BORDER );
5071 setOvYPosition( OV_BORDER );
5072 setOvYStart( ForesterUtil.roundToInt( OV_BORDER + ( getOvMaxHeight() / 2 ) ) );
5077 final void updateOvSizes() {
5078 if ( ( getWidth() > 1.05 * getVisibleRect().width ) || ( getHeight() > 1.05 * getVisibleRect().height ) ) {
5080 float l = getLongestExtNodeInfo();
5081 final float w_ratio = getOvMaxWidth() / getWidth();
5083 final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
5084 setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) );
5086 if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
5087 ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) );
5090 ov_xdist = ( ( getOvMaxWidth() - l ) / ( PhylogenyMethods.calculateMaxDepth( _phylogeny ) ) );
5092 float ydist = ( float ) ( ( getOvMaxWidth() / ( ext_nodes * 2.0 ) ) );
5093 if ( ov_xdist < 0.0 ) {
5096 if ( ydist < 0.0 ) {
5099 setOvXDistance( ov_xdist );
5100 final double height = _phylogeny.getHeight();
5102 final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height );
5103 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
5106 setOvXcorrectionFactor( 0 );
5114 final void updateSubSuperTreeButton() {
5115 if ( _subtree_index < 1 ) {
5116 getControlPanel().deactivateButtonToReturnToSuperTree();
5119 getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
5123 final void zoomInDomainStructure() {
5124 if ( _domain_structure_width < 2000 ) {
5125 _domain_structure_width *= 1.2;
5129 final void zoomOutDomainStructure() {
5130 if ( _domain_structure_width > 20 ) {
5131 _domain_structure_width *= 0.8;
5135 final private static void drawString( final int i, final double x, final double y, final Graphics2D g ) {
5136 g.drawString( String.valueOf( i ), ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5139 final private static void drawString( final String str, final double x, final double y, final Graphics2D g ) {
5140 g.drawString( str, ( int ) ( x + 0.5 ), ( int ) ( y + 0.5 ) );
5143 final private static boolean isSequenceEmpty( final Sequence seq ) {
5144 return ( seq.getAccession() == null ) && ForesterUtil.isEmpty( seq.getName() )
5145 && ForesterUtil.isEmpty( seq.getSymbol() );
5148 final private static boolean isTaxonomyEmpty( final Taxonomy tax ) {
5149 return ( ( tax.getIdentifier() == null ) && ForesterUtil.isEmpty( tax.getTaxonomyCode() )
5150 && ForesterUtil.isEmpty( tax.getCommonName() ) && ForesterUtil.isEmpty( tax.getScientificName() ) && tax
5151 .getSynonyms().isEmpty() );
5154 final private static boolean plusPressed( final int key_code ) {
5155 return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS )
5156 || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) );
5159 void setStatisticsForExpressionValues( final DescriptiveStatistics statistics_for_expression_values ) {
5160 _statistics_for_vector_data = statistics_for_expression_values;
5163 DescriptiveStatistics getStatisticsForExpressionValues() {
5164 return _statistics_for_vector_data;
5167 final private class SubtreeColorizationActionListener implements ActionListener {
5169 JColorChooser _chooser;
5170 PhylogenyNode _node;
5172 SubtreeColorizationActionListener( final JColorChooser chooser, final PhylogenyNode node ) {
5178 public void actionPerformed( final ActionEvent e ) {
5179 final Color c = _chooser.getColor();
5181 colorizeSubtree( c, _node );
5186 public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
5187 getMainPanel().setImageMap( image_map );
5190 public synchronized Hashtable<String, BufferedImage> getImageMap() {
5191 return getMainPanel().getImageMap();