+ final static String writePhylogenyToGraphicsByteArrayOutputStream( final ByteArrayOutputStream baos,
+ int width,
+ int height,
+ final TreePanel tree_panel,
+ final ControlPanel ac,
+ final GraphicsExportType type,
+ final Options options ) throws IOException {
+ if ( !options.isGraphicsExportUsingActualSize() ) {
+ if ( options.isGraphicsExportVisibleOnly() ) {
+ throw new IllegalArgumentException( "cannot export visible rectangle only without exporting in actual size" );
+ }
+ tree_panel.setParametersForPainting( options.getPrintSizeX(), options.getPrintSizeY(), true );
+ 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 "";
+ }
+ Rectangle visible = null;
+ if ( !options.isGraphicsExportUsingActualSize() ) {
+ width = options.getPrintSizeX();
+ height = options.getPrintSizeY();
+ }
+ else if ( options.isGraphicsExportVisibleOnly() ) {
+ visible = tree_panel.getVisibleRect();
+ width = visible.width;
+ height = visible.height;
+ }
+ final BufferedImage buffered_img = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
+ Graphics2D g2d = buffered_img.createGraphics();
+ g2d.setRenderingHints( rendering_hints );
+ int x = 0;
+ int y = 0;
+ if ( options.isGraphicsExportVisibleOnly() ) {
+ g2d = ( Graphics2D ) g2d.create( -visible.x, -visible.y, visible.width, visible.height );
+ g2d.setClip( null );
+ x = visible.x;
+ y = visible.y;
+ }
+ tree_panel.paintPhylogeny( g2d, false, true, width, height, x, y );
+ ImageIO.write( buffered_img, type.toString(), baos );
+ g2d.dispose();
+ System.gc();
+ if ( !options.isGraphicsExportUsingActualSize() ) {
+ tree_panel.getMainPanel().getControlPanel().showWhole();
+ }
+ String msg = baos.toString();
+ if ( ( width > 0 ) && ( height > 0 ) ) {
+ msg += " [size: " + width + ", " + height + "]";
+ }
+ return msg;
+ }
+
+ 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();
+ }
+