<classpathentry kind="src" path="java/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="java/resources/itextpdf-5.1.0.jar"/>
+ <classpathentry kind="lib" path="java/resources/commons-codec-1.5.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<property name="classes.dir" value="classes" />
<property name="jars.dir" value="resources" />
<property name="itextjar" value="${jars.dir}/itextpdf-5.1.0.jar" />
+ <property name="commonscodecjar" value="${jars.dir}/commons-codec-1.5.jar" />
<property name="forester_jar" value="forester.jar" />
<property name="archaeopteryx_applets_jar" value="archaeopteryx_applets.jar" />
<target name="compile_applets_only" description="Compiles the Task" depends="clean">
<mkdir dir="${classes.dir}" />
- <javac source="1.5" target="1.5" debug="false" srcdir="${src.dir}" destdir="${classes.dir}" optimize="on" verbose="false" classpath="${itextjar}">
+ <javac source="1.5" target="1.5" debug="false" srcdir="${src.dir}" destdir="${classes.dir}" optimize="on" verbose="false" classpath="${itextjar};${commonscodecjar}">
<compilerarg value="-Xlint:deprecation" />
</javac>
</target>
</target>
<target name="jar_applets_only" description="JARs the classes files" depends="compile_applets_only,copy_resources">
+ <unjar src="${commonscodecjar}" dest="${classes.dir}">
+ <patternset>
+ <include name="**/*.class" />
+ <include name="**/*.afm" />
+ <include name="**/*.txt" />
+ <exclude name="**/*Test*.class" />
+ </patternset>
+ </unjar>
<jar level="9" destfile="${archaeopteryx_applets_jar}" basedir="${classes.dir}" excludes="org/forester/application/**
org/forester/development/**
org/forester/evoinference/**
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
+import org.forester.archaeopteryx.Util.GraphicsExportType;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.data.SequenceRelation;
import org.forester.util.ForesterConstants;
import org.forester.util.ForesterUtil;
+import org.apache.commons.codec.binary.Base64;
// Use like this:
// <applet archive="forester.jar"
return new String();
}
+ /**
+ * 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 ) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try{
+ Util.writePhylogenyToGraphicsByteArrayOutputStream( baos,
+ _main_panel.getWidth(),
+ _main_panel.getHeight(),
+ this.getCurrentTreePanel(),
+ getCurrentTreePanel().getControlPanel(),
+ GraphicsExportType.valueOf(format),
+ getOptions());
+ }catch(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;
+ }
+ byte[] bytes = baos.toByteArray();
+ String dataImg = Base64.encodeBase64String(bytes);
+ return dataImg;
+ }
+
void buildFontSizeMenu() {
_font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
_font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
return msg;
}
+ 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;
+ }
+
final static void writeToTiff( final File file, final BufferedImage image ) throws IOException {
// See: http://log.robmeek.com/2005/08/write-tiff-in-java.html
ImageWriter writer = null;