Clover coverage report - AdWT - 1.0.0
Coverage timestamp: sam. déc. 27 2003 15:14:10 CET
file stats: LOC: 120   Methods: 5
NCLOC: 73   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultObjectRenderer.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * EJTools, the Enterprise Java Tools
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at www.gnu.org.
 6   
  */
 7   
 package org.ejtools.adwt.util;
 8   
 
 9   
 import java.awt.Image;
 10   
 import java.awt.Toolkit;
 11   
 import java.awt.image.ImageProducer;
 12   
 import java.io.IOException;
 13   
 import java.net.URL;
 14   
 import java.security.AccessController;
 15   
 import java.security.PrivilegedAction;
 16   
 import java.util.Hashtable;
 17   
 import java.util.Map;
 18   
 
 19   
 import javax.swing.Icon;
 20   
 
 21   
 /**
 22   
  * @author    Laurent Etiemble
 23   
  * @version   $Revision: 1.3 $
 24   
  */
 25   
 public class DefaultObjectRenderer implements ObjectRenderer
 26   
 {
 27   
    /** Description of the Field */
 28   
    protected Map objects = new Hashtable();
 29   
 
 30   
 
 31   
    /**
 32   
     * Gets the icon attribute of the DefaultObjectRenderer object
 33   
     *
 34   
     * @param o  Description of the Parameter
 35   
     * @return   The icon value
 36   
     */
 37  0
    public Icon getIcon(Object o)
 38   
    {
 39  0
       return this.getObjectWrapper(o).getIcon();
 40   
    }
 41   
 
 42   
 
 43   
    /**
 44   
     * Gets the label attribute of the DefaultObjectRenderer object
 45   
     *
 46   
     * @param o  Description of the Parameter
 47   
     * @return   The label value
 48   
     */
 49  0
    public String getLabel(Object o)
 50   
    {
 51  0
       return this.getObjectWrapper(o).toString();
 52   
    }
 53   
 
 54   
 
 55   
    /**
 56   
     * Gets the objectWrapper attribute of the DefaultObjectRenderer object
 57   
     *
 58   
     * @param o  Description of the Parameter
 59   
     * @return   The objectWrapper value
 60   
     */
 61  0
    protected ObjectWrapper getObjectWrapper(Object o)
 62   
    {
 63  0
       ObjectWrapper wrapper = (ObjectWrapper) this.objects.get(o);
 64  0
       if (wrapper == null)
 65   
       {
 66  0
          wrapper = new ObjectWrapper(o);
 67  0
          this.objects.put(o, wrapper);
 68   
       }
 69  0
       return wrapper;
 70   
    }
 71   
 
 72   
 
 73   
    /**
 74   
     * Description of the Method
 75   
     *
 76   
     * @param resourceName  Description of the Parameter
 77   
     * @return              Description of the Return Value
 78   
     */
 79  0
    protected static Image loadImage(final String resourceName)
 80   
    {
 81  0
       try
 82   
       {
 83  0
          final Class c = DefaultObjectRenderer.class;
 84  0
          ImageProducer ip = (ImageProducer) AccessController.doPrivileged(
 85   
             new PrivilegedAction()
 86   
             {
 87  0
                public Object run()
 88   
                {
 89  0
                   URL url;
 90  0
                   if ((url = c.getResource(resourceName)) == null)
 91   
                   {
 92  0
                      return null;
 93   
                   }
 94   
                   else
 95   
                   {
 96  0
                      try
 97   
                      {
 98  0
                         return url.getContent();
 99   
                      }
 100   
                      catch (IOException ioe)
 101   
                      {
 102  0
                         return null;
 103   
                      }
 104   
                   }
 105   
                }
 106   
             });
 107  0
          if (ip == null)
 108   
          {
 109  0
             return null;
 110   
          }
 111  0
          Toolkit tk = Toolkit.getDefaultToolkit();
 112  0
          return tk.createImage(ip);
 113   
       }
 114   
       catch (Exception ex)
 115   
       {
 116  0
          return null;
 117   
       }
 118   
    }
 119   
 }
 120