001package com.hfg.graphics.font;
002
003import java.awt.Font;
004import java.util.Map;
005
006import com.hfg.util.collection.OrderedMap;
007
008//------------------------------------------------------------------------------
009/**
010 * A more convenient way of dealing with font styles than is provided by java's Font.
011 * <div>
012 *   @author J. Alex Taylor, hairyfatguy.com
013 * </div>
014 */
015//------------------------------------------------------------------------------
016// com.hfg XML/HTML Coding Library
017//
018// This library is free software; you can redistribute it and/or
019// modify it under the terms of the GNU Lesser General Public
020// License as published by the Free Software Foundation; either
021// version 2.1 of the License, or (at your option) any later version.
022//
023// This library is distributed in the hope that it will be useful,
024// but WITHOUT ANY WARRANTY; without even the implied warranty of
025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
026// Lesser General Public License for more details.
027//
028// You should have received a copy of the GNU Lesser General Public
029// License along with this library; if not, write to the Free Software
030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031//
032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
033// jataylor@hairyfatguy.com
034//------------------------------------------------------------------------------
035
036public class FontStyle
037{
038   private String mName;
039   private int    mIntValue;
040
041   private static Map<Integer, FontStyle> sValueMap = new OrderedMap<>(3);
042
043
044   private static FontStyle PLAIN  = new FontStyle(Font.PLAIN,  "plain");
045   private static FontStyle BOLD   = new FontStyle(Font.BOLD,   "bold");
046   private static FontStyle ITALIC = new FontStyle(Font.ITALIC, "italic");
047   private static FontStyle BOLD_ITALIC = new FontStyle(Font.ITALIC + Font.BOLD, "bolditalic");
048
049   //##########################################################################
050   // CONSTRUCTORS
051   //##########################################################################
052
053   //---------------------------------------------------------------------------
054   private FontStyle(int inIntValue, String inName)
055   {
056      mIntValue = inIntValue;
057      mName = inName;
058
059      sValueMap.put(inIntValue, this);
060   }
061
062   //##########################################################################
063   // PUBLIC METHODS
064   //##########################################################################
065
066   //---------------------------------------------------------------------------
067   public static FontStyle[] values()
068   {
069      return sValueMap.values().toArray(new FontStyle[] {});
070   }
071
072   //---------------------------------------------------------------------------
073   public static FontStyle valueOf(int inValue)
074   {
075      return sValueMap.get(inValue);
076   }
077
078   //---------------------------------------------------------------------------
079   public static FontStyle valueOf(String inValue)
080   {
081      FontStyle requestedValue = null;
082      for (FontStyle value : sValueMap.values())
083      {
084         if (value.name().equalsIgnoreCase(inValue))
085         {
086            requestedValue = value;
087            break;
088         }
089      }
090
091      return requestedValue;
092   }
093
094   //---------------------------------------------------------------------------
095   @Override
096   public String toString()
097   {
098      return name();
099   }
100
101   //---------------------------------------------------------------------------
102   public String name()
103   {
104      return mName;
105   }
106
107   //---------------------------------------------------------------------------
108   public int intValue()
109   {
110      return mIntValue;
111   }
112}