001package com.hfg.graphics.units;
002
003
004import com.hfg.util.StringUtil;
005
006import java.util.HashMap;
007import java.util.Map;
008
009//------------------------------------------------------------------------------
010/**
011 * Enumeration of absolute graphic length measurement units.
012 *
013 * @author J. Alex Taylor, hairyfatguy.com
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 GfxUnits
037{
038   private static Map<String, GfxUnits> sInstanceMap = new HashMap<>();
039
040   /** Twentieth of a point. Used by Microsoft in the Office Open XML standard. */
041   public static final GfxUnits dxa     = new GfxUnits("dxa",    "dxa");
042   /** English metric units. Used by Microsoft in the Office Open XML standard. */
043   public static final GfxUnits emus         = new GfxUnits("emus",   "emu");
044   public static final GfxUnits inches       = new GfxUnits("inches", "in");
045   public static final GfxUnits centimeters  = new GfxUnits("centimeters", "cm");
046   public static final GfxUnits millimeters  = new GfxUnits("millimeters", "mm");
047   public static final GfxUnits micrometers  = new GfxUnits("micrometers", "μm");
048   public static final GfxUnits pixels       = new GfxUnits("pixels", "px");
049   public static final GfxUnits points       = new GfxUnits("points", "pt");
050   public static final GfxUnits picas        = new GfxUnits("picas",  "pc");
051   public static final GfxUnits half_points  = new GfxUnits("half-points", "hpt");
052
053
054   private String mName;
055   private String mAbbrev;
056
057
058   //---------------------------------------------------------------------------
059   private GfxUnits(String inName, String inAbbrev)
060   {
061      mName = inName;
062      mAbbrev = inAbbrev;
063
064      sInstanceMap.put(mName.toLowerCase(), this);
065      sInstanceMap.put(mAbbrev.toLowerCase(), this);
066   }
067
068   //---------------------------------------------------------------------------
069   public String name()
070   {
071      return mName;
072   }
073
074   //---------------------------------------------------------------------------
075   public String abbrev()
076   {
077      return mAbbrev;
078   }
079
080   //---------------------------------------------------------------------------
081   @Override
082   public String toString()
083   {
084      return abbrev();
085   }
086
087
088   //---------------------------------------------------------------------------
089   public static GfxUnits valueOf(String inString)
090   {
091      return StringUtil.isSet(inString) ? sInstanceMap.get(inString.toLowerCase()) : null;
092   }
093
094}