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-2013 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  
  */
 45  
 public abstract class IconSize
 46  
     implements Serializable
 47  
 {
 48  
     /** Icon width. */
 49  
     private final int width;
 50  
 
 51  
     /** Icon height. */
 52  
     private final int height;
 53  
 
 54  
     /** The string value of <code>width + "x" + height</code>. */
 55  
     private final String toStringValue;
 56  
 
 57  
 
 58  
     /**
 59  
      * Create a new icon size with the specified width
 60  
      * and height.
 61  
      *
 62  
      * @param width icon width
 63  
      * @param height icon height
 64  
      */
 65  
     protected IconSize(final int width, final int height)
 66  8
     {
 67  8
         this.width = width;
 68  8
         this.height = height;
 69  8
         toStringValue = width + "x" + height;
 70  8
     }
 71  
 
 72  
 
 73  
     /**
 74  
      * Return the string value of <code>width + "x" + height</code>.
 75  
      *
 76  
      * @return the string value of the icon width and height
 77  
      */
 78  
     public final String toString()
 79  
     {
 80  57
         return toStringValue;
 81  
     }
 82  
 
 83  
     /**
 84  
      * Return the icon width.
 85  
      *
 86  
      * @return the icon width
 87  
      */
 88  
     public final int getWidth()
 89  
     {
 90  6378
         return width;
 91  
     }
 92  
 
 93  
     /**
 94  
      * Return the icon height.
 95  
      *
 96  
      * @return the icon height
 97  
      */
 98  
     public final int getHeight()
 99  
     {
 100  6378
         return height;
 101  
     }
 102  
 
 103  
     /**
 104  
      * Override equals and make it final to prevent
 105  
      * subclasses from changing the implementation.
 106  
      *
 107  
      * @param o object
 108  
      * @return <code>super.equals(o)</code>
 109  
      */
 110  
     public final boolean equals(final Object o)
 111  
     {
 112  2721
         return super.equals(o);
 113  
     }
 114  
 
 115  
     /**
 116  
      * Override hashCode and make it final to prevent
 117  
      * subclasses from changing the implementation.
 118  
      *
 119  
      * @return <code>super.hashCode()</code>
 120  
      */
 121  
     public final int hashCode()
 122  
     {
 123  5165
         return super.hashCode();
 124  
     }
 125  
 
 126  
 
 127  
     /** Default 16x16 icon size. */
 128  1
     public static final IconSize DEFAULT_16X16 = new IconSize(16, 16)
 129  1
         {
 130  
             // empty
 131  
         };
 132  
 
 133  
     /** Default 24x24 icon size. */
 134  1
     public static final IconSize DEFAULT_24X24 = new IconSize(24, 24)
 135  1
         {
 136  
             // empty
 137  
         };
 138  
 
 139  
     /** Default 32x32 icon size. */
 140  1
     public static final IconSize DEFAULT_32X32 = new IconSize(32, 32)
 141  1
         {
 142  
             // empty
 143  
         };
 144  
 
 145  
     /** Default 48x48 icon size. */
 146  1
     public static final IconSize DEFAULT_48X48 = new IconSize(48, 48)
 147  1
         {
 148  
             // empty
 149  
         };
 150  
 
 151  
     /** Default 64x64 icon size. */
 152  1
     public static final IconSize DEFAULT_64X64 = new IconSize(64, 64)
 153  1
         {
 154  
             // empty
 155  
         };
 156  
 
 157  
     /** Default 96x96 icon size. */
 158  1
     public static final IconSize DEFAULT_96X96 = new IconSize(96, 96)
 159  1
         {
 160  
             // empty
 161  
         };
 162  
 
 163  
     /** Default 128x128 icon size. */
 164  1
     public static final IconSize DEFAULT_128X128 = new IconSize(128, 128)
 165  1
         {
 166  
             // empty
 167  
         };
 168  
 
 169  
     /**
 170  
      * Private array of default enumeration values.
 171  
      */
 172  1
     private static final IconSize[] VALUES_ARRAY = {
 173  
                                                      DEFAULT_16X16,
 174  
                                                      DEFAULT_24X24,
 175  
                                                      DEFAULT_32X32,
 176  
                                                      DEFAULT_48X48,
 177  
                                                      DEFAULT_64X64,
 178  
                                                      DEFAULT_96X96,
 179  
                                                      DEFAULT_128X128
 180  
                                                     };
 181  
 
 182  
     /**
 183  
      * Public list of default enumeration values.
 184  
      */
 185  1
     public static final List VALUES = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
 186  
 
 187  
 
 188  
     /** Next ordinal -- necessary for serialization. */
 189  1
     private static int nextOrdinal = 0;
 190  
 
 191  
     /** Ordinal -- necessary for serialization. */
 192  8
     private final int ordinal = nextOrdinal++;
 193  
 
 194  
     /**
 195  
      * Override readResolve to return the proper static
 196  
      * final enumeration values.
 197  
      *
 198  
      * @return the proper static final enumeration value
 199  
      *
 200  
      * @throws ObjectStreamException if an error occurs
 201  
      */
 202  
     Object readResolve()
 203  
         throws ObjectStreamException
 204  
     {
 205  0
         return VALUES_ARRAY[ordinal];
 206  
     }
 207  
 }