+ public static MaskFormatter createMaskFormatter( final String s ) {
+ MaskFormatter formatter = null;
+ try {
+ formatter = new MaskFormatter( s );
+ }
+ catch ( final ParseException e ) {
+ throw new IllegalArgumentException( e );
+ }
+ return formatter;
+ }
+
+ final static public boolean isHasAtLeastNodeWithEvent( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ if ( it.next().getNodeData().isHasEvent() ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if at least one branch has a length larger than zero.
+ *
+ *
+ * @param phy
+ */
+ final static public boolean isHasAtLeastOneBranchLengthLargerThanZero( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ if ( it.next().getDistanceToParent() > 0.0 ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ final static public boolean isHasAtLeastOneBranchWithSupportValues( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ if ( it.next().getBranchData().isHasConfidences() ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ final static public boolean isHasAtLeastOneBranchWithSupportSD( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( n.getBranchData().isHasConfidences() ) {
+ final List<Confidence> c = n.getBranchData().getConfidences();
+ for( final Confidence confidence : c ) {
+ if ( confidence.getStandardDeviation() > 0 ) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ final static public boolean isHasAtLeastOneNodeWithScientificName( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( n.getNodeData().isHasTaxonomy()
+ && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ final static public boolean isHasAtLeastOneNodeWithSequenceAnnotation( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( n.getNodeData().isHasSequence()
+ && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAnnotations() ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ final public static void launchWebBrowser( final URI uri,
+ final boolean is_applet,
+ final JApplet applet,
+ final String frame_name ) throws IOException {
+ if ( is_applet ) {
+ applet.getAppletContext().showDocument( uri.toURL(), frame_name );
+ }
+ else {
+ // This requires Java 1.6:
+ // =======================
+ // boolean no_desktop = false;
+ // try {
+ // if ( Desktop.isDesktopSupported() ) {
+ // System.out.println( "desktop supported" );
+ // final Desktop dt = Desktop.getDesktop();
+ // dt.browse( uri );
+ // }
+ // else {
+ // no_desktop = true;
+ // }
+ // }
+ // catch ( final Exception ex ) {
+ // ex.printStackTrace();
+ // no_desktop = true;
+ // }
+ // catch ( final Error er ) {
+ // er.printStackTrace();
+ // no_desktop = true;
+ // }
+ // if ( no_desktop ) {
+ // System.out.println( "desktop not supported" );
+ try {
+ openUrlInWebBrowser( uri.toString() );
+ }
+ catch ( final Exception e ) {
+ throw new IOException( e );
+ }
+ // }
+ }
+ }
+
+ public static Set<Taxonomy> obtainAllDistinctTaxonomies( final PhylogenyNode node ) {
+ final List<PhylogenyNode> descs = node.getAllExternalDescendants();
+ final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
+ for( final PhylogenyNode n : descs ) {
+ if ( n.getNodeData().isHasTaxonomy() && !n.getNodeData().getTaxonomy().isEmpty() ) {
+ tax_set.add( n.getNodeData().getTaxonomy() );
+ }
+ }
+ return tax_set;
+ }
+
+ public final static void printWarningMessage( final String name, final String message ) {
+ System.out.println( "[" + name + "] > " + message );
+ }
+
+ final public static void showErrorMessage( final Component parent, final String error_msg ) {
+ printAppletMessage( Constants.PRG_NAME, error_msg );
+ JOptionPane.showMessageDialog( parent, error_msg, "[" + Constants.PRG_NAME + " " + Constants.VERSION
+ + "] Error", JOptionPane.ERROR_MESSAGE );
+ }
+
+ public static void writePhylogenyToGraphicsFile( final File intree,
+ final File outfile,
+ final int width,
+ final int height,
+ final GraphicsExportType type,
+ final Configuration config ) throws IOException {
+ final PhylogenyParser parser = ParserUtils.createParserDependingOnFileType( intree, true );
+ Phylogeny[] phys = null;
+ phys = PhylogenyMethods.readPhylogenies( parser, intree );
+ writePhylogenyToGraphicsFile( phys[ 0 ], outfile, width, height, type, config );
+ }
+
+ public static void writePhylogenyToGraphicsFile( final Phylogeny phy,
+ final File outfile,
+ final int width,
+ final int height,
+ final GraphicsExportType type,
+ final Configuration config ) throws IOException {
+ final Phylogeny[] phys = new Phylogeny[ 1 ];
+ phys[ 0 ] = phy;
+ final MainFrameApplication mf = MainFrameApplication.createInstance( phys, config );
+ AptxUtil.writePhylogenyToGraphicsFileNonInteractive( outfile, width, height, mf.getMainPanel()
+ .getCurrentTreePanel(), mf.getMainPanel().getControlPanel(), type, mf.getOptions() );
+ mf.end();
+ }
+
+ public final static void writePhylogenyToGraphicsFileNonInteractive( final File outfile,
+ final int width,
+ final int height,
+ final TreePanel tree_panel,
+ final ControlPanel ac,
+ final GraphicsExportType type,
+ final Options options ) throws IOException {
+ tree_panel.calcParametersForPainting( width, height );
+ tree_panel.resetPreferredSize();
+ tree_panel.repaint();
+ final RenderingHints rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY );
+ rendering_hints.put( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY );
+ if ( options.isAntialiasPrint() ) {
+ rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
+ rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
+ }
+ else {
+ rendering_hints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF );
+ rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
+ }
+ final Phylogeny phylogeny = tree_panel.getPhylogeny();
+ if ( ( phylogeny == null ) || phylogeny.isEmpty() ) {
+ return;
+ }
+ if ( outfile.isDirectory() ) {
+ throw new IOException( "\"" + outfile + "\" is a directory" );
+ }
+ final BufferedImage buffered_img = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
+ final Graphics2D g2d = buffered_img.createGraphics();
+ g2d.setRenderingHints( rendering_hints );
+ tree_panel.paintPhylogeny( g2d, false, true, width, height, 0, 0 );
+ if ( type == GraphicsExportType.TIFF ) {
+ writeToTiff( outfile, buffered_img );
+ }
+ else {
+ ImageIO.write( buffered_img, type.toString(), outfile );
+ }
+ g2d.dispose();
+ }
+