001package com.hfg.html.attribute; 002 003import java.io.Serializable; 004import java.util.HashMap; 005import java.util.Map; 006 007import com.hfg.html.HTML; 008 009//------------------------------------------------------------------------------ 010/** 011 * Enum-like alignment class 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// 036// 037// <!-- vertical alignment attributes for cell contents --> 038// <!ENTITY % cellvalign 039// "valign (top|middle|bottom|baseline) #IMPLIED" 040// > 041 042public final class VAlign implements Serializable 043{ 044 045 private String mName; 046 private int mIndex; 047 048 private static Map<String, VAlign> sValueMap = new HashMap<>(11); 049 050 public static final VAlign BASELINE = new VAlign("baseline"); 051 public static final VAlign BOTTOM = new VAlign("bottom"); 052 public static final VAlign INHERIT = new VAlign("inherit"); 053 public static final VAlign INITIAL = new VAlign("initial"); 054 public static final VAlign MIDDLE = new VAlign("middle"); 055 public static final VAlign SUB = new VAlign("sub"); 056 public static final VAlign SUPER = new VAlign("super"); 057 public static final VAlign TEXT_BOTTOM = new VAlign("text-bottom"); 058 public static final VAlign TEXT_TOP = new VAlign("text-top"); 059 public static final VAlign TOP = new VAlign("top"); 060 public static final VAlign UNSET = new VAlign("unset"); 061 062 //########################################################################### 063 // CONSTRUCTORS 064 //########################################################################### 065 066 //-------------------------------------------------------------------------- 067 private VAlign(String inName) 068 { 069 mName = inName; 070 mIndex = sValueMap.size(); 071 sValueMap.put(inName, this); 072 } 073 074 //########################################################################### 075 // PUBLIC METHODS 076 //########################################################################### 077 078 //-------------------------------------------------------------------------- 079 public static VAlign[] values() 080 { 081 return sValueMap.values().toArray(new VAlign[] {}); 082 } 083 084 //-------------------------------------------------------------------------- 085 public static VAlign valueOf(String inValue) 086 { 087 return sValueMap.get(inValue); 088 } 089 090 //-------------------------------------------------------------------------- 091 @Override 092 public final String toString() 093 { 094 return mName; 095 } 096 097 //-------------------------------------------------------------------------- 098 public final String getHTMLAttributeName() 099 { 100 return HTML.VALIGN; 101 } 102 103 //-------------------------------------------------------------------------- 104 @Override 105 public final int hashCode() 106 { 107 return super.hashCode(); 108 } 109 110 //-------------------------------------------------------------------------- 111 @Override 112 public final boolean equals(Object inObj) 113 { 114 VAlign o2 = (VAlign) inObj; 115 return (mIndex == o2.mIndex); 116 } 117 118 //-------------------------------------------------------------------------- 119 /** 120 * This method is called after de-serialization, allowing the object 121 * to nominate a replacement object to be used in the output 122 * graph instead of this object. We don't want multiple objects of each type 123 * to exist in a target VM, so instances replace themselves with 124 * local objects. 125 */ 126 private Object readResolve() 127 { 128 Object value = null; 129 for (VAlign vAlign : values()) 130 { 131 if (vAlign.mIndex == mIndex) 132 { 133 value = vAlign; 134 break; 135 } 136 } 137 138 return value; 139 } 140}