001package com.hfg.util.collection;
002
003import com.hfg.graphics.units.GfxSize;
004import com.hfg.html.attribute.Align;
005import com.hfg.util.CompareUtil;
006
007import java.awt.*;
008import java.util.regex.Pattern;
009
010//------------------------------------------------------------------------------
011/**
012 Column info for a DataTable column.
013 <div>
014  @author J. Alex Taylor, hairyfatguy.com
015 </div>
016 */
017//------------------------------------------------------------------------------
018// com.hfg Library
019//
020// This library is free software; you can redistribute it and/or
021// modify it under the terms of the GNU Lesser General Public
022// License as published by the Free Software Foundation; either
023// version 2.1 of the License, or (at your option) any later version.
024//
025// This library is distributed in the hope that it will be useful,
026// but WITHOUT ANY WARRANTY; without even the implied warranty of
027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
028// Lesser General Public License for more details.
029//
030// You should have received a copy of the GNU Lesser General Public
031// License along with this library; if not, write to the Free Software
032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
033//
034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
035// jataylor@hairyfatguy.com
036//------------------------------------------------------------------------------
037
038public class DataColumn implements Comparable
039{
040   private String  mTitle;
041   private String  mDescription;
042   private Align   mTextAlign;
043   private String  mCssStyle;
044   private GfxSize mWidth;
045   private Font    mFont;
046   private String  mFormatString;
047   private boolean mIsRequired;
048   private Pattern mTitlePattern;
049   private Integer mIndex;
050
051   //##########################################################################
052   // CONSTRUCTORS
053   //##########################################################################
054
055   //--------------------------------------------------------------------------
056   public DataColumn(String inTitle)
057   {
058      mTitle = inTitle;
059   }
060
061   //##########################################################################
062   // PUBLIC METHODS
063   //##########################################################################
064
065   //--------------------------------------------------------------------------
066   @Override
067   public String toString()
068   {
069      return getTitle();
070   }
071
072   //--------------------------------------------------------------------------
073   @Override
074   public int hashCode()
075   {
076      return mTitle != null ? mTitle.hashCode() : 0;
077   }
078
079   //--------------------------------------------------------------------------
080   @Override
081   public boolean equals(Object inObj2)
082   {
083      return 0 == compareTo(inObj2);   
084   }
085
086   //--------------------------------------------------------------------------
087   @Override
088   public int compareTo(Object inObj2)
089   {
090      int result = -1;
091      if (inObj2 instanceof DataColumn)
092      {
093         result = CompareUtil.compare(getTitle(), ((DataColumn) inObj2).getTitle());
094      }
095      
096      return result;
097   }
098
099   //--------------------------------------------------------------------------
100   public DataColumn setTitle(String inValue)
101   {
102      mTitle = inValue;
103      return this;
104   }
105
106   //--------------------------------------------------------------------------
107   public String getTitle()
108   {
109      return mTitle;
110   }
111
112   //--------------------------------------------------------------------------
113   public DataColumn setDescription(String inValue)
114   {
115      mDescription = inValue;
116      return this;
117   }
118
119   //--------------------------------------------------------------------------
120   public String getDescription()
121   {
122      return mDescription;
123   }
124
125   //--------------------------------------------------------------------------
126   public DataColumn setTextAlign(Align inValue)
127   {
128      mTextAlign = inValue;
129      return this;
130   }
131
132   //--------------------------------------------------------------------------
133   public Align getTextAlign()
134   {
135      return mTextAlign;
136   }
137
138   //--------------------------------------------------------------------------
139   public DataColumn setCssStyle(String inValue)
140   {
141      mCssStyle = inValue;
142      return this;
143   }
144
145   //--------------------------------------------------------------------------
146   public String getCssStyle()
147   {
148      return mCssStyle;
149   }
150
151   //--------------------------------------------------------------------------
152   public GfxSize getWidth()
153   {
154      return mWidth;
155   }
156
157   //--------------------------------------------------------------------------
158   public DataColumn setWidth(GfxSize inValue)
159   {
160      this.mWidth = inValue;
161      return this;
162   }
163
164
165   //--------------------------------------------------------------------------
166   public Font getFont()
167   {
168      return mFont;
169   }
170
171   //--------------------------------------------------------------------------
172   public DataColumn setFont(Font inValue)
173   {
174      mFont = inValue;
175      return this;
176   }
177
178
179   //--------------------------------------------------------------------------
180   /**
181    Sets a formatting string (like "%.1f%%") to be used by the DataTable's
182    getFormatted().
183    * @param inValue formatting string
184    * @return this DataColumn object
185    */
186   public DataColumn setFormatString(String inValue)
187   {
188      mFormatString = inValue;
189      return this;
190   }
191
192   //--------------------------------------------------------------------------
193   public String getFormatString()
194   {
195      return mFormatString;
196   }
197
198
199   //--------------------------------------------------------------------------
200   public boolean isRequired()
201   {
202      return mIsRequired;
203   }
204
205   //--------------------------------------------------------------------------
206   public DataColumn setIsRequired(boolean inValue)
207   {
208      mIsRequired = inValue;
209      return this;
210   }
211
212
213   //--------------------------------------------------------------------------
214   public Pattern getTitlePattern()
215   {
216      return mTitlePattern;
217   }
218
219   //--------------------------------------------------------------------------
220   /**
221    Sets a pattern which can be used to match this column definition to column header from a spreadsheet.
222    * @param inValue pattern for matching
223    * @return this DataColumn object
224    */
225   public DataColumn setTitlePattern(Pattern inValue)
226   {
227      mTitlePattern = inValue;
228      return this;
229   }
230
231
232   //--------------------------------------------------------------------------
233   public Integer getIndex()
234   {
235      return mIndex;
236   }
237
238   //--------------------------------------------------------------------------
239   public DataColumn setIndex(Integer inValue)
240   {
241      mIndex = inValue;
242      return this;
243   }
244
245}