tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r566836 - in /tapestry/tapestry4/trunk/tapestry-contrib/src: descriptor/META-INF/hivemodule.xml java/org/apache/tapestry/contrib/services/impl/RoundedCornerGenerator.java java/org/apache/tapestry/contrib/services/impl/RoundedCornerService.java
Date Thu, 16 Aug 2007 20:38:01 GMT
Author: jkuhnert
Date: Thu Aug 16 13:38:00 2007
New Revision: 566836

URL: http://svn.apache.org/viewvc?view=rev&rev=566836
Log:
Fixes TAPESTRY-1706. 

GIF formats aren't supported in the sun jre until version 1.6 so refactored to iterate over
the supported formats of the running jre to fall back to jpeg when gif isn't available.

Modified:
    tapestry/tapestry4/trunk/tapestry-contrib/src/descriptor/META-INF/hivemodule.xml
    tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerGenerator.java
    tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerService.java

Modified: tapestry/tapestry4/trunk/tapestry-contrib/src/descriptor/META-INF/hivemodule.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-contrib/src/descriptor/META-INF/hivemodule.xml?view=diff&rev=566836&r1=566835&r2=566836
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-contrib/src/descriptor/META-INF/hivemodule.xml (original)
+++ tapestry/tapestry4/trunk/tapestry-contrib/src/descriptor/META-INF/hivemodule.xml Thu Aug
16 13:38:00 2007
@@ -62,7 +62,8 @@
 
     <service-point id="RoundedCornerService" interface="org.apache.tapestry.engine.IEngineService">
         <invoke-factory>
-            <construct class="org.apache.tapestry.contrib.services.impl.RoundedCornerService"
>
+            <construct class="org.apache.tapestry.contrib.services.impl.RoundedCornerService"
+                    initialize-method="initialize">
                 <set-object property="exceptionReporter" value="infrastructure:requestExceptionReporter"/>
                 <set-object property="response" value="infrastructure:response"/>
                 <set-object property="linkFactory" value="infrastructure:linkFactory"/>

Modified: tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerGenerator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerGenerator.java?view=diff&rev=566836&r1=566835&r2=566836
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerGenerator.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerGenerator.java
Thu Aug 16 13:38:00 2007
@@ -61,7 +61,7 @@
 
     public BufferedImage buildCorner(String color, String backgroundColor, int width, int
height,
                                      String angle, int shadowWidth, float endOpacity)
-    throws Exception
+      throws Exception
     {
         width = width * 2;
         height = height * 2;
@@ -75,17 +75,17 @@
 
             Arc2D.Float arcArea = new Arc2D.Float(0, 0, width, height, startAngle, 90, Arc2D.PIE);
             if (bgColor != null) {
-                
+
                 ret = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                 Graphics2D g2 = (Graphics2D)ret.createGraphics();
                 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                 g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
-                
+
                 g2.setColor(bgColor);
                 g2.fill(arcArea.getBounds2D());
 
                 g2.drawImage(arc, 0, 0, null);
-                
+
                 g2.dispose();
 
                 ret = convertType(ret, BufferedImage.TYPE_INT_RGB);
@@ -139,7 +139,7 @@
         g2.drawImage(arc, 0, 0, null);
 
         return convertType(ret, BufferedImage.TYPE_INT_RGB).getSubimage((int)arcArea.getBounds2D().getX(),
(int)arcArea.getBounds2D().getY(),
-                    (int)arcArea.getBounds2D().getWidth(), (int)arcArea.getBounds2D().getHeight());
+                                                                        (int)arcArea.getBounds2D().getWidth(),
(int)arcArea.getBounds2D().getHeight());
     }
 
     static BufferedImage convertType(BufferedImage image, int type) {
@@ -183,9 +183,9 @@
 
                 startX -= shadowSize;
                 startY += shadowSize;
-                
+
             } else if (startAngle == ANGLE_BOTTOM_RIGHT) {
-                
+
                 startX -= shadowSize;
                 startY -= shadowSize;
             }
@@ -196,13 +196,13 @@
 
         float extent = 90;
         if (masking) {
-            
+
             extent = 120;
             startAngle -= 20;
         }
-        
+
         Arc2D.Float fillArea = new Arc2D.Float(startX, startY, width, height, startAngle,
extent, Arc2D.PIE);
-        
+
         // draw arc
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
@@ -257,7 +257,7 @@
 
         BufferedImage img = new BufferedImage( (width * 4), (height * 4), BufferedImage.TYPE_INT_ARGB);
         Graphics2D g2 = (Graphics2D) img.createGraphics();
-        
+
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         g2.setComposite(AlphaComposite.Src);
         g2.drawImage(dropShadow, 0, 0, null);
@@ -278,7 +278,7 @@
         Graphics2D g2 = mask.createGraphics();
 
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        
+
         RoundRectangle2D.Float fillArea = new RoundRectangle2D.Float(0, 0, width, height,
arcHeight, arcWidth);
         g2.setColor(fgColor);
         g2.fill(fillArea);
@@ -299,7 +299,7 @@
         g2.setClip(clip);
         g2.drawImage(dropShadow, 0, 0, null);
         g2.dispose();
-        
+
         // draw everything
 
         BufferedImage img = new BufferedImage( width + (shadowWidth * 2), height + (shadowWidth
* 2), BufferedImage.TYPE_INT_ARGB);
@@ -328,10 +328,10 @@
     }
 
     public BufferedImage buildSideShadow(String side, int size, float opacity)
-    throws Exception
+      throws Exception
     {
         Defense.notNull(side, "side");
-        
+
         if (opacity <= 0)
             opacity = DEFAULT_OPACITY;
 
@@ -350,7 +350,7 @@
             sampleWidth = size * 2;
             sampleHeight = 2;
         } else if (RIGHT.equals(side)) {
-            
+
             maskWidth = size * 4;
             maskHeight = size * 4;
             sampleY = maskHeight / 2;
@@ -374,7 +374,7 @@
             sampleWidth = 2;
             sampleHeight = size * 2;
         }
-        
+
         BufferedImage mask = new BufferedImage( maskWidth, maskHeight, BufferedImage.TYPE_INT_ARGB);
         Graphics2D g2 = (Graphics2D) mask.createGraphics();
 
@@ -390,12 +390,12 @@
         g2 = (Graphics2D)render.createGraphics();
 
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        
+
         Rectangle2D.Float clip = new Rectangle2D.Float(sampleX, sampleY, sampleWidth, sampleHeight);
 
         g2.setColor(Color.white);
         g2.fill(clip);
-        
+
         g2.drawImage(dropShadow, 0, 0, null);
 
         g2.dispose();
@@ -427,7 +427,7 @@
     /**
      * Decodes the specified input color string into a compatible awt color object. Valid
inputs
      * are any in the css2 color spec or hex strings.
-     * 
+     *
      * @param color The color to match.
      * @return The decoded color object, may be black if decoding fails.
      */
@@ -438,7 +438,7 @@
             return specColor;
 
         String hexColor = color.startsWith("0x") ? color : "0x" + color;
-        
+
         return Color.decode(hexColor);
     }
 }

Modified: tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerService.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerService.java?view=diff&rev=566836&r1=566835&r2=566836
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerService.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-contrib/src/java/org/apache/tapestry/contrib/services/impl/RoundedCornerService.java
Thu Aug 16 13:38:00 2007
@@ -62,6 +62,30 @@
 
     private Log _log;
 
+    /** The ImageIO format name to encode images in that don't need alpha transparency */
+    private String _nonTransparentFormatName = "gif";
+
+    public void initialize()
+    {
+        String[] names = ImageIO.getWriterFormatNames();
+
+        boolean supportsGif = false;
+        
+        for (int i=0; i < names.length; i++)
+        {
+            if (names[i].toLowerCase().equals("gif"))
+            {
+                supportsGif = true;
+                break;
+            }
+        }
+
+        if (!supportsGif)
+        {
+            _nonTransparentFormatName = "jpeg";
+        }
+    }
+
     public ILink getLink(boolean post, Object parameter)
     {
         Defense.notNull(parameter, "parameter");
@@ -105,7 +129,7 @@
         
         try {
             
-            String type = (bgColor != null) ? "gif" : "png";
+            String type = (bgColor != null) ? _nonTransparentFormatName : "png";
 
             byte[] data = (byte[])_imageCache.get(hashKey);
             if (data != null)
@@ -129,13 +153,13 @@
 
             bo = new ByteArrayOutputStream();
 
-            ImageIO.write(image, type, bo);
+            boolean success = ImageIO.write(image, type, bo);
 
             data = bo.toByteArray();
 
-            if (data == null || data.length < 1)
+            if (!success || data == null || data.length < 1)
             {
-                _log.error("Image generated had zero length byte array from parameters of:\n"
+                _log.error("Image generated had zero length byte array or failed to convert
from parameters of:\n"
                            + "[color:" + color + ", bgColor:" + bgColor
                            + ", width:" + width + ", height:" + height
                            + ", angle:" + angle + ", shadowWidth:" + shadowWidth



Mime
View raw message