[jboss-cvs] jboss-seam/src/ui/org/jboss/seam/ui/graphicImage ...

Peter Muir peter at bleepbleep.org.uk
Tue Mar 6 10:21:11 EST 2007


  User: pmuir   
  Date: 07/03/06 10:21:11

  Modified:    src/ui/org/jboss/seam/ui/graphicImage      
                        UIGraphicImage.java
  Added:       src/ui/org/jboss/seam/ui/graphicImage      
                        UITransformImageSize.java UITransformImageType.java
                        UIBlurImage.java ImageTransform.java
  Removed:     src/ui/org/jboss/seam/ui/graphicImage      
                        UIImageTransform.java
  Log:
  Better support for image transforms
  
  Revision  Changes    Path
  1.2       +5 -64     jboss-seam/src/ui/org/jboss/seam/ui/graphicImage/UIGraphicImage.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIGraphicImage.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/graphicImage/UIGraphicImage.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- UIGraphicImage.java	5 Mar 2007 20:59:06 -0000	1.1
  +++ UIGraphicImage.java	6 Mar 2007 15:21:11 -0000	1.2
  @@ -1,12 +1,9 @@
   package org.jboss.seam.ui.graphicImage;
   
   import java.io.IOException;
  -import java.util.HashMap;
   import java.util.List;
  -import java.util.Map;
   
   import javax.faces.component.UIComponent;
  -import javax.faces.component.UIParameter;
   import javax.faces.component.html.HtmlGraphicImage;
   import javax.faces.context.FacesContext;
   import javax.faces.context.ResponseWriter;
  @@ -56,28 +53,20 @@
         String extension = null;
   
         Image image = Image.instance();
  -      image.set(getValue());
  +      image.setInput(getValue());
         
         // Do transforms
         
         for (UIComponent cmp : (List<UIComponent>) this.getChildren()) 
         {
  -         if (cmp instanceof UIImageTransform)
  +         if (cmp instanceof ImageTransform)
            {
  -            UIImageTransform imageTransform = (UIImageTransform) cmp;
  -            Map<String, String> parameters = getParameters(imageTransform);
  -            if (UIImageTransform.SCALE.equals(imageTransform.getType()))
  -            {
  -               scale(imageTransform, image, parameters);
  -            } else if (UIImageTransform.TYPE.equals(imageTransform.getType()))
  -            {
  -               contentType(imageTransform, image, parameters);
  -            }
  -            
  +            ImageTransform imageTransform = (ImageTransform) cmp;
  +            imageTransform.applyTransform(image, this);
            }
         }
   
  -      key = DynamicImageStore.instance().put(new ImageWrapper(image.get(), image.getContentType()),
  +      key = DynamicImageStore.instance().put(new ImageWrapper(image.getImage(), image.getContentType()),
                  key);
         extension = image.getContentType().getExtension();
   
  @@ -89,54 +78,6 @@
         writer.endElement(HTML.IMG_ELEM);
      }
   
  -   private void scale(UIImageTransform imageTransform, Image image, Map<String, String> parameters) throws NumberFormatException, IOException
  -   {
  -//    TODO reduce number of decimal places
  -      if ("true".equals(parameters.get("maintainRatio")))
  -      {
  -         if (parameters.containsKey("width") && parameters.containsKey("height"))
  -         {
  -            throw new UnsupportedOperationException("Cannot maintain ratio and specify height and width");
  -         }
  -         else if (parameters.containsKey("width"))
  -         {
  -            setHeight(((Double) (Double.valueOf(parameters.get("width")) / image.getRatio())).toString());
  -            setWidth(parameters.get("width"));
  -         }
  -         else if (parameters.containsKey("height"))
  -         {
  -            setWidth(((Double) (Double.valueOf(getHeight()) / image.getRatio())).toString());
  -            setHeight(parameters.get("height"));
  -         }
  -      }
  -   }
  -   
  -   private void contentType(UIImageTransform imageTransform, Image image, Map<String, String> parameters) {
  -      if (parameters.containsKey("output")) 
  -      {
  -        Image.Type type = Image.Type.getTypeByMimeType(parameters.get("output"));
  -        if (type != null)
  -        {
  -           image.setContentType(type);
  -        }
  -      }
  -      
  -   }
  -   
  -   private Map<String, String> getParameters(UIImageTransform imageTransform)
  -   {
  -      Map<String, String> parameters = new HashMap<String, String>();
  -      for (UIComponent cmp : (List<UIComponent>) imageTransform.getChildren())
  -      {
  -         if (cmp instanceof UIParameter)
  -         {
  -            UIParameter parameter = (UIParameter) cmp;
  -            parameters.put(parameter.getName(), parameter.getValue() == null ? null : parameter.getValue().toString());
  -         }
  -      }
  -      return parameters;
  -   }
  -
      public String getFileName()
      {
         if (fileName != null)
  
  
  
  1.1      date: 2007/03/06 15:21:11;  author: pmuir;  state: Exp;jboss-seam/src/ui/org/jboss/seam/ui/graphicImage/UITransformImageSize.java
  
  Index: UITransformImageSize.java
  ===================================================================
  package org.jboss.seam.ui.graphicImage;
  
  import java.io.IOException;
  
  import javax.faces.component.UIComponentBase;
  import javax.faces.el.ValueBinding;
  
  import org.jboss.seam.core.Image;
  import org.jboss.seam.ui.JSF;
  
  public class UITransformImageSize extends UIComponentBase implements ImageTransform
  {
     
     private Boolean maintainRatio;
     
     private String width;
     
     private String height;
     
     private String factor;
     
     @Override
     public String getFamily()
     {
        return FAMILY;
     }
     
     public void applyTransform(Image image, UIGraphicImage cmp) throws IOException
     {
  //    TODO reduce number of decimal places
        if (isMaintainRatio())
        {
           if (getWidth() != null && getHeight() != null)
           {
              throw new UnsupportedOperationException("Cannot maintain ratio and specify height and width");
           }
           else if (getWidth() != null)
           {
              image.scaleToWidth(new Integer(getWidth()));
           }
           else if (getHeight() != null)
           {
              image.scaleToHeight(new Integer(getHeight()));
           }
        }
        else if (getFactor() != null)
        {
           if (getWidth() != null || getHeight() != null)
           {
              throw new UnsupportedOperationException("Cannot scale by a factor and specify height and width");
           }
           image.scale(new Double(factor));
        }
        else
        {
           image.resize(new Integer(getWidth()), new Integer(getHeight()));
        }
     }
     
     public boolean isMaintainRatio()
     {
        if (maintainRatio != null)
        {
           return maintainRatio;
        }
        else 
        {
           ValueBinding vb = getValueBinding("maintainRatio");
           Boolean b = vb == null ? null : JSF.getBooleanValue(getFacesContext(), vb);
           return b == null ? false : b;
        }
     }
     
     public void setMaintainRatio(boolean maintainRatio)
     {
        this.maintainRatio = maintainRatio;
     }
     
     public String getWidth()
     {
        if (width != null)
        {
           return width;
        }
        else
        {
           ValueBinding vb = getValueBinding("width");
           return vb == null ? null : JSF.getStringValue(getFacesContext(), vb);
        }
     }
     
     public void setWidth(String width)
     {
        this.width = width;
     }
     
     public String getHeight()
     {
        if (height != null)
        {
           return height;
        }
        else
        {
           ValueBinding vb = getValueBinding("height");
           return vb == null ? null : JSF.getStringValue(getFacesContext(), vb);
        }
     }
     
     public void setHeight(String height)
     {
        this.height = height;
     }
     
     public String getFactor()
     {
        if (factor != null)
        {
           return factor;
        }
        else
        {
           ValueBinding vb = getValueBinding("factor");
           return vb == null ? null : JSF.getStringValue(getFacesContext(), vb);
        }
     }
     
     public void setFactor(String factor)
     {
        this.factor = factor;
     }
     
  }
  
  
  
  1.1      date: 2007/03/06 15:21:11;  author: pmuir;  state: Exp;jboss-seam/src/ui/org/jboss/seam/ui/graphicImage/UITransformImageType.java
  
  Index: UITransformImageType.java
  ===================================================================
  package org.jboss.seam.ui.graphicImage;
  
  import java.io.IOException;
  
  import javax.faces.component.UIComponentBase;
  import javax.faces.el.ValueBinding;
  
  import org.jboss.seam.core.Image;
  import org.jboss.seam.ui.JSF;
  
  public class UITransformImageType extends UIComponentBase implements ImageTransform
  {
     
     private String contentType;
     
   
     @Override
     public String getFamily()
     {
        return FAMILY;
     }
     
     public void applyTransform(Image image, UIGraphicImage cmp) throws IOException
     {
        Image.Type type = Image.Type.getTypeByMimeType(getContentType());
        if (type != null)
        {
           image.setContentType(type);
        }
     }
     
     public String getContentType()
     {
        if (contentType != null)
        {
           return contentType;
        }
        else
        {
           ValueBinding vb = getValueBinding("width");
           return vb == null ? null : JSF.getStringValue(getFacesContext(), vb);
        }
     }
     
     public void setContentType(String width)
     {
        this.contentType = width;
     }
     
  }
  
  
  
  1.1      date: 2007/03/06 15:21:11;  author: pmuir;  state: Exp;jboss-seam/src/ui/org/jboss/seam/ui/graphicImage/UIBlurImage.java
  
  Index: UIBlurImage.java
  ===================================================================
  package org.jboss.seam.ui.graphicImage;
  
  import java.io.IOException;
  
  import javax.faces.component.UIComponentBase;
  import javax.faces.el.ValueBinding;
  
  import org.jboss.seam.core.Image;
  import org.jboss.seam.ui.JSF;
  
  public class UIBlurImage extends UIComponentBase implements ImageTransform
  {
     @Override
     public String getFamily()
     {
        return FAMILY;
     }
     
     private String radius;
     
     public void applyTransform(Image image, UIGraphicImage cmp) throws IOException
     {
        image.blur(new Integer(getRadius()));
     }
     
     public String getRadius()
     {
        if (radius != null)
        {
           return radius;
        }
        else
        {
           ValueBinding vb = getValueBinding("width");
           return vb == null ? null : JSF.getStringValue(getFacesContext(), vb);
        }
     }
     
     public void setRadius(String width)
     {
        this.radius = width;
     }
     
  }
  
  
  
  1.1      date: 2007/03/06 15:21:11;  author: pmuir;  state: Exp;jboss-seam/src/ui/org/jboss/seam/ui/graphicImage/ImageTransform.java
  
  Index: ImageTransform.java
  ===================================================================
  package org.jboss.seam.ui.graphicImage;
  
  import java.io.IOException;
  
  import javax.faces.component.UIComponentBase;
  
  import org.jboss.seam.core.Image;
  
  public interface ImageTransform
  {
     public static final String FAMILY = "org.jboss.seam.ui.UIImageTransform";
     
     public abstract void applyTransform(Image image, UIGraphicImage cmp) throws IOException;
  }
  
  
  



More information about the jboss-cvs-commits mailing list