Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  
     Copyright 2001,2003  The Apache Software Foundation 
  
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
         http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 
  */
 package org.apache.batik.svggen;
 
 import java.awt.Image;
 
Implements the GenericImageHandler interface and only uses <image> elements. This class delegates to the ImageHandler interface for handling the xlink:href attribute on the elements it creates.

Author(s):
Vincent Hardy
Version:
$Id: SimpleImageHandler.java,v 1.6 2004/08/18 07:15:09 vhardy Exp $
 
     // duplicate the string here to remove dependencies on
     // org.apache.batik.dom.util.XLinkSupport
     static final String XLINK_NAMESPACE_URI =
         "http://www.w3.org/1999/xlink";

    
ImageHandler which handles xlink:href attribute setting
 
     protected ImageHandler imageHandler;

    

Parameters:
imageHandler ImageHandler handling the xlink:href on the <image> elements this GenericImageHandler implementation creates.
 
     public SimpleImageHandler(ImageHandler imageHandler){
         if (imageHandler == null){
             throw new IllegalArgumentException();
         }
 
         this. = imageHandler;
     }

    
This GenericImageHandler implementation does not need to interact with the DOMTreeManager.
 
     public void setDOMTreeManager(DOMTreeManager domTreeManager){
     }

    
Creates an Element which can refer to an image. Note that no assumptions should be made by the caller about the corresponding SVG tag.
 
     public Element createElement(SVGGeneratorContext generatorContext) {
         // Create a DOM Element in SVG namespace to refer to an image
         Element imageElement =
             generatorContext.getDOMFactory().createElementNS
             ();
 
         return imageElement;
     }

    
The handler sets the xlink:href tag and returns a transform
 
     public AffineTransform handleImage(Image image,
                                        Element imageElement,
                                        int xint y,
                                        int widthint height,
                                        SVGGeneratorContext generatorContext) {
 
         int imageWidth      = image.getWidth(null);
         int imageHeight     = image.getHeight(null);
         if(imageWidth == 0 || imageHeight == 0 ||
            width == 0 || height == 0) {
 
             // Forget about it
             handleEmptyImage(imageElement);
 
         } else {
             .handleImage(imageimageElementgeneratorContext);
            setImageAttributes(imageElementxywidthheight,
                               generatorContext);
        }
        return null;
    }

    
The handler sets the xlink:href tag and returns a transform
                                       Element imageElement,
                                       int xint y,
                                       int widthint height,
                                       SVGGeneratorContext generatorContext) {
        int imageWidth      = image.getWidth();
        int imageHeight     = image.getHeight();
        if(imageWidth == 0 || imageHeight == 0 ||
           width == 0 || height == 0) {
            // Forget about it
            handleEmptyImage(imageElement);
        } else {
            .handleImage(imageimageElementgeneratorContext);
            setImageAttributes(imageElementxywidthheight
                               generatorContext);
        }
        return null;
    }

    
The handler sets the xlink:href tag and returns a transform
                                       Element imageElement,
                                       double xdouble y,
                                       double widthdouble height,
                                       SVGGeneratorContext generatorContext) {
        double imageWidth   = image.getWidth();
        double imageHeight  = image.getHeight();
        if(imageWidth == 0 || imageHeight == 0 ||
           width == 0 || height == 0) {
            // Forget about it
            handleEmptyImage(imageElement);
        } else {
            .handleImage(imageimageElementgeneratorContext);
            setImageAttributes(imageElementxywidthheightgeneratorContext);
        }
        return null;
    }

    
Sets the x/y/width/height attributes on the <image> element.
    protected void setImageAttributes(Element imageElement,
                                      double x
                                      double y,
                                      double width,
                                      double height,
                                      SVGGeneratorContext generatorContext) {
        imageElement.setAttributeNS(null,
                                    ,
                                    generatorContext.doubleString(x));
        imageElement.setAttributeNS(null,
                                    ,
                                    generatorContext.doubleString(y));
        imageElement.setAttributeNS(null,
                                    ,
                                    generatorContext.doubleString(width));
        imageElement.setAttributeNS(null,
                                    ,
                                    generatorContext.doubleString(height));
        imageElement.setAttributeNS(null,
                                    ,
                                    );
    }
              
    protected void handleEmptyImage(Element imageElement) {
        imageElement.setAttributeNS(,
                                    "");
        imageElement.setAttributeNS(null"0");
        imageElement.setAttributeNS(null"0");
    }
New to GrepCode? Check out our FAQ X