Coverage Report - org.dishevelled.iconbundle.IconSize
 
Classes in this File Line Coverage Branch Coverage Complexity
IconSize
95%
21/22
N/A
1
IconSize$1
100%
1/1
N/A
1
IconSize$2
100%
1/1
N/A
1
IconSize$3
100%
1/1
N/A
1
IconSize$4
100%
1/1
N/A
1
IconSize$5
100%
1/1
N/A
1
IconSize$6
100%
1/1
N/A
1
IconSize$7
100%
1/1
N/A
1
 
 1  
 /*
 2  
 
 3  
     dsh-iconbundle  Bundles of variants for icon images.
 4  
     Copyright (c) 2003-2011 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;
 25  
 
 26  
 import java.util.List;
 27  
 import java.util.Arrays;
 28  
 import java.util.Collections;
 29  
 
 30  
 import java.io.Serializable;
 31  
 import java.io.ObjectStreamException;
 32  
 
 33  
 /**
 34  
  * Extensible typesafe enumeration of icon sizes.
 35  
  *
 36  
  * <p>To create a non-default icon size, subclass IconSize
 37  
  * as follows:
 38  
  * <pre>
 39  
  *  IconSize CUSTOM_48X52 = new IconSize(48, 52) { }
 40  
  * </pre>
 41  
  * and optionally override readResolve to support serialization.</p>
 42  
  *
 43  
  * @author  Michael Heuer
 44  
  * @version $Revision: 974 $ $Date: 2011-01-04 21:40:23 -0600 (Tue, 04 Jan 2011) $
 45  
  */
 46  
 public abstract class IconSize
 47  
     implements Serializable
 48  
 {
 49  
     /** Icon width. */
 50  
     private final int width;
 51  
 
 52  
     /** Icon height. */
 53  
     private final int height;
 54  
 
 55  
     /** The string value of <code>width + "x" + height</code>. */
 56  
     private final String toStringValue;
 57  
 
 58  
 
 59  
     /**
 60  
      * Create a new icon size with the specified width
 61  
      * and height.
 62  
      *
 63  
      * @param width icon width
 64  
      * @param height icon height
 65  
      */
 66  
     protected IconSize(final int width, final int height)
 67  8
     {
 68  8
         this.width = width;
 69  8
         this.height = height;
 70  8
         toStringValue = width + "x" + height;
 71  8
     }
 72  
 
 73  
 
 74  
     /**
 75  
      * Return the string value of <code>width + "x" + height</code>.
 76  
      *
 77  
      * @return the string value of the icon width and height
 78  
      */
 79  
     public final String toString()
 80  
     {
 81  57
         return toStringValue;
 82  
     }
 83  
 
 84  
     /**
 85  
      * Return the icon width.
 86  
      *
 87  
      * @return the icon width
 88  
      */
 89  
     public final int getWidth()
 90  
     {
 91  6378
         return width;
 92  
     }
 93  
 
 94  
     /**
 95  
      * Return the icon height.
 96  
      *
 97  
      * @return the icon height
 98  
      */
 99  
     public final int getHeight()
 100  
     {
 101  6378
         return height;
 102  
     }
 103  
 
 104  
     /**
 105  
      * Override equals and make it final to prevent
 106  
      * subclasses from changing the implementation.
 107  
      *
 108  
      * @param o object
 109  
      * @return <code>super.equals(o)</code>
 110  
      */
 111  
     public final boolean equals(final Object o)
 112  
     {
 113  2721
         return super.equals(o);
 114  
     }
 115  
 
 116  
     /**
 117  
      * Override hashCode and make it final to prevent
 118  
      * subclasses from changing the implementation.
 119  
      *
 120  
      * @return <code>super.hashCode()</code>
 121  
      */
 122  
     public final int hashCode()
 123  
     {
 124  5118
         return super.hashCode();
 125  
     }
 126  
 
 127  
 
 128  
     /** Default 16x16 icon size. */
 129  1
     public static final IconSize DEFAULT_16X16 = new IconSize(16, 16)
 130  1
         {
 131  
             // empty
 132  
         };
 133  
 
 134  
     /** Default 24x24 icon size. */
 135  1
     public static final IconSize DEFAULT_24X24 = new IconSize(24, 24)
 136  1
         {
 137  
             // empty
 138  
         };
 139  
 
 140  
     /** Default 32x32 icon size. */
 141  1
     public static final IconSize DEFAULT_32X32 = new IconSize(32, 32)
 142  1
         {
 143  
             // empty
 144  
         };
 145  
 
 146  
     /** Default 48x48 icon size. */
 147  1
     public static final IconSize DEFAULT_48X48 = new IconSize(48, 48)
 148  1
         {
 149  
             // empty
 150  
         };
 151  
 
 152  
     /** Default 64x64 icon size. */
 153  1
     public static final IconSize DEFAULT_64X64 = new IconSize(64, 64)
 154  1
         {
 155  
             // empty
 156  
         };
 157  
 
 158  
     /** Default 96x96 icon size. */
 159  1
     public static final IconSize DEFAULT_96X96 = new IconSize(96, 96)
 160  1
         {
 161  
             // empty
 162  
         };
 163  
 
 164  
     /** Default 128x128 icon size. */
 165  1
     public static final IconSize DEFAULT_128X128 = new IconSize(128, 128)
 166  1
         {
 167  
             // empty
 168  
         };
 169  
 
 170  
     /**
 171  
      * Private array of default enumeration values.
 172  
      */
 173  1
     private static final IconSize[] VALUES_ARRAY = {
 174  
                                                      DEFAULT_16X16,
 175  
                                                      DEFAULT_24X24,
 176  
                                                      DEFAULT_32X32,
 177  
                                                      DEFAULT_48X48,
 178  
                                                      DEFAULT_64X64,
 179  
                                                      DEFAULT_96X96,
 180  
                                                      DEFAULT_128X128
 181  
                                                     };
 182  
 
 183  
     /**
 184  
      * Public list of default enumeration values.
 185  
      */
 186  1
     public static final List VALUES = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
 187  
 
 188  
 
 189  
     /** Next ordinal -- necessary for serialization. */
 190  1
     private static int nextOrdinal = 0;
 191  
 
 192  
     /** Ordinal -- necessary for serialization. */
 193  8
     private final int ordinal = nextOrdinal++;
 194  
 
 195  
     /**
 196  
      * Override readResolve to return the proper static
 197  
      * final enumeration values.
 198  
      *
 199  
      * @return the proper static final enumeration value
 200  
      *
 201  
      * @throws ObjectStreamException if an error occurs
 202  
      */
 203  
     Object readResolve()
 204  
         throws ObjectStreamException
 205  
     {
 206  0
         return VALUES_ARRAY[ordinal];
 207  
     }
 208  
 }