001package com.hfg.html.attribute; 002 003import java.io.Serializable; 004import java.util.ArrayList; 005import java.util.List; 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 036public final class Align implements Serializable 037{ 038 039 private String mName; 040 private int mIndex; 041 042 private static List<Align> sList = new ArrayList<Align>(3); 043 044 public static final Align LEFT = new Align("left"); 045 public static final Align RIGHT = new Align("right"); 046 public static final Align CENTER = new Align("center"); 047 public static final Align JUSTIFY = new Align("justify"); 048 public static final Align CHAR = new Align("char"); 049 050 //########################################################################### 051 // CONSTRUCTORS 052 //########################################################################### 053 054 //-------------------------------------------------------------------------- 055 private Align(String inName) 056 { 057 mName = inName; 058 mIndex = sList.size(); 059 sList.add(this); 060 } 061 062 //########################################################################### 063 // PUBLIC METHODS 064 //########################################################################### 065 066 //-------------------------------------------------------------------------- 067 @Override 068 public final String toString() 069 { 070 return mName; 071 } 072 073 //-------------------------------------------------------------------------- 074 public static Align valueOf(String inValue) 075 { 076 Align outValue = null; 077 078 for (Align align : sList) 079 { 080 if (align.toString().equalsIgnoreCase(inValue)) 081 { 082 outValue = align; 083 } 084 } 085 086 return outValue; 087 } 088 089 //-------------------------------------------------------------------------- 090 public static Align[] values() 091 { 092 return sList.toArray(new Align[] {}); 093 } 094 095 //-------------------------------------------------------------------------- 096 public final String getHTMLAttributeName() 097 { 098 return HTML.ALIGN; 099 } 100 101 102 //-------------------------------------------------------------------------- 103 @Override 104 public final int hashCode() 105 { 106 return super.hashCode(); 107 } 108 109 //-------------------------------------------------------------------------- 110 @Override 111 public final boolean equals(Object inObj) 112 { 113 Align o2 = (Align) inObj; 114 return (mIndex == o2.mIndex); 115 } 116 117 //-------------------------------------------------------------------------- 118 /** 119 * This method is called after de-serialization, allowing the object 120 * to nominate a replacement object to be used in the output 121 * graph instead of this object. We don't want multiple objects of each type 122 * to exist in a target VM, so instances replace themselves with 123 * local objects. 124 */ 125 private Object readResolve() 126 { 127 return sList.get(mIndex); 128 } 129}