+ /**
+ * This method returns a view of the current phylogeny in a chosen
+ * graphics format, base64-encoded in a string so that in can be used
+ * from javascript.
+ *
+ * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
+ * @return the phylogeny string
+ * @author Herve Menager
+ */
+ public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
+ _main_panel.getWidth(),
+ _main_panel.getHeight(),
+ getCurrentTreePanel(),
+ getCurrentTreePanel().getControlPanel(),
+ GraphicsExportType.valueOf( format ),
+ getOptions() );
+ }
+ catch ( final IOException ioe ) {
+ ForesterUtil.printErrorMessage( NAME, ioe.toString() );
+ ioe.printStackTrace();
+ JOptionPane.showMessageDialog( this,
+ NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
+ "Failed to generate graphics",
+ JOptionPane.ERROR_MESSAGE );
+ return null;
+ }
+ final byte[] bytes = baos.toByteArray();
+ final String dataImg = Base64.encodeBase64String( bytes );
+ return dataImg;
+ }