new itext version, plus minor changes
authorcmzmasek <czmasek@czamseklt-w7.jcvi.ORG>
Thu, 30 Jun 2016 21:05:22 +0000 (14:05 -0700)
committercmzmasek <czmasek@czamseklt-w7.jcvi.ORG>
Thu, 30 Jun 2016 21:05:22 +0000 (14:05 -0700)
forester/aptx/aptx_configuration_files/_aptx_configuration_file
forester/java/build.xml
forester/java/src/org/forester/archaeopteryx/AptxConstants.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java
forester/java/src/org/forester/archaeopteryx/PdfExporter.java
forester/java/src/org/forester/archaeopteryx/TreeFontSet.java
forester/java/src/org/forester/archaeopteryx/TreePanel.java

index 1ffa5d8..2ca3dc7 100644 (file)
@@ -17,11 +17,11 @@ native_ui: ?
 #     value for bootstrap support)
 #
 #  Font family name: 'font_family':
-#     Example: 'font_family: Sans,Helvetica'
+#     Example: 'font_family: Arial_Unicode_MS,Dialog,SansSerif,Sans,Arial,Helvetica'
 #     It is advisable to use more than one value for font_family (in
 #     decreasing order of preference). Font family names have to be
 #     comma separated (no spaces). Spaces in font names have to be
-#     replaced by underscores (e.g. 'Times_New_Roman').
+#     replaced by underscores (e.g. 'Arial_Unicode_MS').
 #
 #  Font size: 'font_size':
 #     Example: 'font_size: 10'
@@ -162,7 +162,7 @@ native_ui: ?
 
 
 min_confidence_value:                      0.0
-font_family:                               SansSerif,Sans-serif,Sans,Dialog,Tahoma,Helvetica,Arial,Verdana
+font_family:                               Arial_Unicode_MS,Dialog,SansSerif,Sans,Arial,Helvetica
 font_size:                                 10
 font_size_min:                             2
 font_size_max:                             20
index 2cbdd38..41380d2 100644 (file)
@@ -4,7 +4,7 @@
        <property name="src.dir" value="src" />
        <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="itextjar" value="${jars.dir}/itextpdf-5.5.9.jar" />
        <property name="commonscodecjar" value="${jars.dir}/commons-codec-1.5.jar" />
        <property name="openchartjar" value="${jars.dir}/openchart.jar" />
        <property name="forester_jar" value="forester.jar" />
index 456dea4..f2e803a 100644 (file)
@@ -39,13 +39,12 @@ public final class AptxConstants {
     final static boolean        __ALLOW_PHYLOGENETIC_INFERENCE                                = true;
     public final static boolean __RELEASE                                                     = false;                                                                             // TODO remove me
     public final static boolean __SNAPSHOT_RELEASE                                            = false;                                                                             // TODO remove me
-    public final static boolean __SYNTH_LF                                                    = false;                                                                             // TODO remove me
     public final static String  PRG_NAME                                                      = "Archaeopteryx";
     final static String         VERSION                                                       = "0.9912 beta";
-    final static String         PRG_DATE                                                      = "160629";
+    final static String         PRG_DATE                                                      = "160631";
     final static String         DEFAULT_CONFIGURATION_FILE_NAME                               = "_aptx_configuration_file";
     final static String[]       DEFAULT_FONT_CHOICES                                          = { 
-            "SansSerif", "Sans-serif", "Sans", "Dialog", "Lucida Sans", "Tahoma", "Helvetica", "Arial", "Verdana" };
+            "Arial Unicode MS", "Dialog", "SansSerif", "Sans", "Arial", "Helvetica" };
     final static boolean        VERBOSE_DEFAULT                                               = false;
     final static int            DOMAIN_STRUCTURE_DEFAULT_WIDTH                                = 100;
     final static String         AUTHOR_EMAIL                                                  = "phyloxml@gmail.com";
index b940f35..d78cf09 100644 (file)
@@ -57,7 +57,6 @@ import javax.swing.UnsupportedLookAndFeelException;
 import javax.swing.WindowConstants;\r
 import javax.swing.event.ChangeEvent;\r
 import javax.swing.event.ChangeListener;\r
-import javax.swing.plaf.synth.SynthLookAndFeel;\r
 \r
 import org.forester.analysis.TaxonomyDataManager;\r
 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;\r
@@ -196,30 +195,12 @@ public final class MainFrameApplication extends MainFrame {
             throw new IllegalArgumentException( "configuration is null" );\r
         }\r
         try {\r
-            boolean synth_exception = false;\r
-            if ( AptxConstants.__SYNTH_LF ) {\r
-                try {\r
-                    final SynthLookAndFeel synth = new SynthLookAndFeel();\r
-                    synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),\r
-                                MainFrameApplication.class );\r
-                    UIManager.setLookAndFeel( synth );\r
-                }\r
-                catch ( final Exception ex ) {\r
-                    synth_exception = true;\r
-                    ForesterUtil.printWarningMessage( AptxConstants.PRG_NAME,\r
-                                                      "could not create synth look and feel: "\r
-                                                              + ex.getLocalizedMessage() );\r
-                }\r
+            if ( _configuration.isUseNativeUI() ) {\r
+                UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );\r
             }\r
-            if ( !AptxConstants.__SYNTH_LF || synth_exception ) {\r
-                if ( _configuration.isUseNativeUI() ) {\r
-                    UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );\r
-                }\r
-                else {\r
-                    UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );\r
-                }\r
+            else {\r
+                UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );\r
             }\r
-            //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );\r
         }\r
         catch ( final UnsupportedLookAndFeelException e ) {\r
             AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );\r
@@ -816,8 +797,16 @@ public final class MainFrameApplication extends MainFrame {
         List<MolecularSequence> seqs = null;\r
         if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
             try {\r
-                if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {\r
-                    seqs = FastaParser.parse( new FileInputStream( file ) );\r
+                final FileInputStream fis1 = new FileInputStream( file );\r
+                if ( FastaParser.isLikelyFasta( fis1 ) ) {\r
+                    final FileInputStream fis2 = new FileInputStream( file );\r
+                    seqs = FastaParser.parse( fis2 );\r
+                    try {\r
+                        fis2.close();\r
+                     }\r
+                     catch ( final Exception e ) {\r
+                         // Ignore.\r
+                     }\r
                 }\r
                 else {\r
                     JOptionPane.showMessageDialog( this,\r
@@ -826,6 +815,12 @@ public final class MainFrameApplication extends MainFrame {
                                                    JOptionPane.ERROR_MESSAGE );\r
                     return;\r
                 }\r
+                try {\r
+                    fis1.close();\r
+                }\r
+                catch ( final Exception e ) {\r
+                     // Ignore.\r
+                }\r
             }\r
             catch ( final MsaFormatException e ) {\r
                 setArrowCursor();\r
index 9a422d3..2d5bcb0 100644 (file)
@@ -32,15 +32,20 @@ import java.awt.Graphics2D;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.forester.phylogeny.Phylogeny;
 import org.forester.util.ForesterUtil;
 
+import com.itextpdf.awt.DefaultFontMapper;
+import com.itextpdf.awt.DefaultFontMapper.BaseFontParameters;
+import com.itextpdf.awt.PdfGraphics2D;
 import com.itextpdf.text.Document;
 import com.itextpdf.text.DocumentException;
 import com.itextpdf.text.FontFactory;
 import com.itextpdf.text.Rectangle;
-import com.itextpdf.text.pdf.DefaultFontMapper;
+import com.itextpdf.text.pdf.BaseFont;
 import com.itextpdf.text.pdf.PdfContentByte;
 import com.itextpdf.text.pdf.PdfWriter;
 
@@ -50,7 +55,7 @@ import com.itextpdf.text.pdf.PdfWriter;
  * 
  * See: http://www.lowagie.com/iText/
  * 
- * Current version: iText-2.1.7
+ * Current version: iText-5.5.9
  */
 final class PdfExporter {
 
@@ -86,6 +91,7 @@ final class PdfExporter {
         PdfWriter writer = null;
         try {
             writer = PdfWriter.getInstance( document, new FileOutputStream( file_name ) );
+           
         }
         catch ( final DocumentException e ) {
             throw new IOException( e );
@@ -94,7 +100,7 @@ final class PdfExporter {
         final DefaultFontMapper mapper = new DefaultFontMapper();
         FontFactory.registerDirectories();
         if ( ForesterUtil.isWindows() ) {
-            mapper.insertDirectory( "C:\\WINDOWS\\Fonts\\" );
+            mapper.insertDirectory( "c:/windows/fonts" );
         }
         else if ( ForesterUtil.isMac() ) {
             mapper.insertDirectory( "/Library/Fonts/" );
@@ -106,8 +112,11 @@ final class PdfExporter {
             mapper.insertDirectory( "/usr/share/fonts/default/TrueType/" );
             mapper.insertDirectory( "/usr/share/fonts/default/Type1/" );
         }
+        enableUnicode( mapper );
         final PdfContentByte cb = writer.getDirectContent();
-        final Graphics2D g2 = cb.createGraphics( width, height, mapper );
+        
+        final Graphics2D g2 = new PdfGraphics2D(cb, width, height, mapper); 
+    
         try {
             tree_panel.paintPhylogeny( g2, true, false, width, height, 0, 0 );
         }
@@ -129,4 +138,47 @@ final class PdfExporter {
         }
         return msg;
     }
+
+    private final static void enableUnicode( final DefaultFontMapper mapper ) {
+        final Map<String, DefaultFontMapper.BaseFontParameters> map = mapper.getMapper();
+        for (final Iterator<String> i = map.keySet().iterator(); i.hasNext();) {
+            final String name = i.next();
+            final String name_lc = name.toLowerCase();
+            if ( name_lc.contains( "unicode" ) || name_lc.equals( "dialog" ) ) {
+                final BaseFontParameters pfps = map.get(name);
+                try {
+                    pfps.encoding = BaseFont.IDENTITY_H;
+                    pfps.embedded = true;
+                }
+                catch ( Exception e )  {
+                    //Ignore.
+                }
+            }
+        }
+    }
+    
+    /* not used currently 
+    static FontMapper arial_uni = new FontMapper() {
+        public BaseFont awtToPdf(Font font) {
+            System.out.println( font.toString() );
+            try {
+                return BaseFont.createFont(
+                        "c:/windows/fonts/arialuni.ttf",
+                        BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
+            }
+            catch (DocumentException e) {
+                e.printStackTrace();
+            }
+            catch (IOException e) {
+                e.printStackTrace();
+            }
+            return null;
+        }
+       
+        @Override
+        public Font pdfToAwt( BaseFont arg0, int arg1 ) {
+            return null;
+        }
+    };
+    */
 }
index 47fd94e..40d945d 100644 (file)
@@ -39,7 +39,7 @@ public final class TreeFontSet {
     static final int            BOLD_AND_ITALIC           = Font.BOLD + Font.ITALIC;
     final static float          FONT_SIZE_CHANGE_STEP     = 1.0f;
     final static float          SMALL_FONTS_BASE          = 8;
-    private final static String DEFAULT_FONT              = "Verdana";
+    private final static String DEFAULT_FONT              = "Arial Unicode MS";
     private Font                _base_font;
     private boolean             _decreased_size_by_system = false;
     private FontMetrics         _fm_large;
index f6f5911..ff41db5 100644 (file)
@@ -313,9 +313,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     private float                        _y_distance                                        = 0.0f;
     private int                          _length_of_longest_text;
     private int                          _longest_domain;
-    //  private Image                           offscreenImage;
-    //  private Graphics                        offscreenGraphics;
-    //  private Dimension                       offscreenDimension;
     static {
         final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
         dfs.setDecimalSeparator( '.' );
@@ -4390,7 +4387,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             setOvXDistance( ov_xdist );
             final double height = _phylogeny.getHeight();
             if ( height > 0 ) {
-                final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
+                final float corr = ( float ) ( ( x - ( 2.0 * TreePanel.MOVE ) - getLongestExtNodeInfo() - getXdistance() ) / height ); 
                 setXcorrectionFactor( corr > 0 ? corr : 0 );
                 final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
                 setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
@@ -4427,7 +4424,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
             return;
         }
-        int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - MOVE )
+        int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - 2 * MOVE )
                                                   * AptxConstants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
         if ( max_length < 40 ) {
             max_length = 40;
@@ -4508,6 +4505,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             _longest_ext_node_info = longest;
         }
         _length_of_longest_text = calcLengthOfLongestText();
+        System.out.println( "_length_of_longest_text=" + _length_of_longest_text );
+        //~~
     }
 
     final void calculateScaleDistance() {
@@ -5687,6 +5686,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                     + getLongestExtNodeInfo()
                     + ForesterUtil
                     .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() );
+            
         }
         else {
             if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {