Coverage Report - org.dishevelled.iconbundle.tango.TangoProjectIconBundle
 
Classes in this File Line Coverage Branch Coverage Complexity
TangoProjectIconBundle
0%
0/39
0%
0/24
12
 
 1  
 /*
 2  
 
 3  
     dsh-iconbundle-tango  Icon bundles for the Tango Project icon theme.
 4  
     Copyright (c) 2005-2012 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.iconbundle.tango;
 25  
 
 26  
 import java.awt.Image;
 27  
 import java.awt.Color;
 28  
 import java.awt.Component;
 29  
 
 30  
 import java.awt.image.BufferedImage;
 31  
 
 32  
 import java.net.URL;
 33  
 
 34  
 import javax.imageio.ImageIO;
 35  
 
 36  
 import javax.swing.UIManager;
 37  
 
 38  
 import org.dishevelled.iconbundle.IconSize;
 39  
 import org.dishevelled.iconbundle.IconState;
 40  
 import org.dishevelled.iconbundle.IconBundle;
 41  
 import org.dishevelled.iconbundle.IconTextDirection;
 42  
 
 43  
 import org.dishevelled.iconbundle.impl.IconBundleUtils;
 44  
 
 45  
 import org.dishevelled.iconbundle.impl.svg.SVGIconBundleUtils;
 46  
 
 47  
 /**
 48  
  * Tango project icon bundle.
 49  
  *
 50  
  * @author  Michael Heuer
 51  
  * @version $Revision: 1059 $ $Date: 2012-01-03 14:03:02 -0600 (Tue, 03 Jan 2012) $
 52  
  */
 53  
 final class TangoProjectIconBundle
 54  
     implements IconBundle
 55  
 {
 56  
     /** Base url. */
 57  
     private static final String BASE_URL = "/org/freedesktop/tango/";
 58  
 
 59  
     /** Tango project standard icon context. */
 60  
     private final String context;
 61  
 
 62  
     /** Tango project standard icon name. */
 63  
     private final String name;
 64  
 
 65  
 
 66  
     /**
 67  
      * Create a new tango project icon bundle for
 68  
      * the specified standard icon name.
 69  
      *
 70  
      * @param context tango project standard icon context
 71  
      * @param name tango project standard icon name
 72  
      */
 73  
     TangoProjectIconBundle(final String context,
 74  
                            final String name)
 75  0
     {
 76  0
         this.context = context;
 77  0
         this.name = name;
 78  0
     }
 79  
 
 80  
 
 81  
     /** {@inheritDoc} */
 82  
     public Image getImage(final Component component,
 83  
                           final IconTextDirection direction,
 84  
                           final IconState state,
 85  
                           final IconSize size)
 86  
     {
 87  0
         if (direction == null)
 88  
         {
 89  0
             throw new IllegalArgumentException("direction must not be null");
 90  
         }
 91  0
         if (state == null)
 92  
         {
 93  0
             throw new IllegalArgumentException("state must not be null");
 94  
         }
 95  0
         if (size == null)
 96  
         {
 97  0
             throw new IllegalArgumentException("size must not be null");
 98  
         }
 99  
 
 100  0
         URL url = null;
 101  0
         BufferedImage image = null;
 102  
 
 103  0
         if (TangoProject.EXTRA_SMALL.equals(size) || TangoProject.SMALL.equals(size) || TangoProject.MEDIUM.equals(size))
 104  
         {
 105  
             try
 106  
             {
 107  0
                 url = this.getClass().getResource(BASE_URL + size.toString() + "/" + context + "/" + name + ".png");
 108  0
                 image = ImageIO.read(url);
 109  
             }
 110  0
             catch (Exception e)
 111  
             {
 112  0
                 System.err.println("couldn't find image for url=" + url);
 113  0
                 System.err.println("   or=" + BASE_URL + size.toString() + "/" + context + "/" + name + ".png");
 114  0
                 e.printStackTrace();
 115  
                 // ignore
 116  0
             }
 117  
         }
 118  
         else
 119  
         {
 120  0
             int width = size.getWidth();
 121  0
             int height = size.getHeight();
 122  
 
 123  0
             url = this.getClass().getResource(BASE_URL + "scalable/" + context + "/" + name + ".svg");
 124  0
             image = SVGIconBundleUtils.readSVG(url, width, height);
 125  
         }
 126  
 
 127  0
         if (IconState.ACTIVE == state)
 128  
         {
 129  0
             return IconBundleUtils.makeActive(image);
 130  
         }
 131  0
         else if (IconState.MOUSEOVER == state)
 132  
         {
 133  0
             return IconBundleUtils.makeMouseover(image);
 134  
         }
 135  0
         else if (IconState.SELECTED == state)
 136  
         {
 137  0
             Color selectionColor = UIManager.getColor("List.selectionBackground");
 138  0
             return IconBundleUtils.makeSelected(image, selectionColor);
 139  
         }
 140  0
         else if (IconState.SELECTED_MOUSEOVER == state)
 141  
         {
 142  0
             Color selectionColor = UIManager.getColor("List.selectionBackground");
 143  0
             return IconBundleUtils.makeSelectedMouseover(image, selectionColor);
 144  
         }
 145  0
         else if (IconState.DRAGGING == state)
 146  
         {
 147  0
             return IconBundleUtils.makeDragging(image);
 148  
         }
 149  0
         else if (IconState.DISABLED == state)
 150  
         {
 151  0
             return IconBundleUtils.makeDisabled(image);
 152  
         }
 153  
         else
 154  
         {
 155  0
             return image;
 156  
         }
 157  
     }
 158  
 }