001package com.hfg.xml.msofficexml.xlsx.spreadsheetml.style;
002
003
004import com.hfg.xml.msofficexml.xlsx.Xlsx;
005import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXML;
006import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXMLTag;
007
008
009//------------------------------------------------------------------------------
010/**
011 Represents an Office Open XML spreadsheetml (<ssml:cellStyle>) tag.
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 SsmlCellStyle extends SsmlXMLTag implements Cloneable
037{
038   private SsmlStyleFormat mStyleFormat;
039
040
041   //---------------------------------------------------------------------------
042   public SsmlCellStyle(Xlsx inXlsx)
043   {
044      this(inXlsx.getStylesPart());
045   }
046
047   //---------------------------------------------------------------------------
048   public SsmlCellStyle(Xlsx inXlsx, String inName)
049   {
050      this(inXlsx.getStylesPart());
051      setName(inName);
052   }
053
054   //---------------------------------------------------------------------------
055   public SsmlCellStyle(StylesPart inStylesPart)
056   {
057      super(SsmlXML.CELL_STYLE, inStylesPart.getParentDoc());
058      // Register with the styles part
059      inStylesPart.defineCellStyle(this);
060//      setBuiltinId(inStylesPart.defineCellStyle(this));
061
062      setDefaults(inStylesPart);
063   }
064
065   //---------------------------------------------------------------------------
066   private void setDefaults(StylesPart inStylesPart)
067   {
068      setStyleFormat(inStylesPart.getDefaultStyleFormat());
069//      setStyleFormat(new SsmlStyleFormat(inStylesPart));
070
071//      setAttribute(SsmlXML.CUSTOM_BUILTIN_ATT, "1");
072   }
073
074   //##########################################################################
075   // PUBLIC METHODS
076   //##########################################################################
077
078   //---------------------------------------------------------------------------
079   @Override
080   public SsmlCellStyle clone()
081   {
082      SsmlCellStyle clone = (SsmlCellStyle) super.clone();
083
084      // Register with the styles part
085      getParentDoc().getStylesPart().defineCellStyle(clone);
086
087      return clone;
088   }
089
090   //---------------------------------------------------------------------------
091   public SsmlCellStyle setStyleFormat(SsmlStyleFormat inValue)
092   {
093      mStyleFormat = inValue;
094      setAttribute(SsmlXML.STYLE_FORMAT_ID_ATT, inValue.getIndex());
095      return this;
096   }
097
098   //---------------------------------------------------------------------------
099   public SsmlStyleFormat getStyleFormat()
100   {
101      return mStyleFormat;
102   }
103
104   //---------------------------------------------------------------------------
105   public SsmlCellStyle setName(String inValue)
106   {
107      setAttribute(SsmlXML.NAME_ATT, inValue);
108      return this;
109   }
110
111   //---------------------------------------------------------------------------
112   public SsmlCellStyle setBuiltinId(int inValue)
113   {
114      setAttribute(SsmlXML.BUILTIN_ID_ATT, inValue);
115      return this;
116   }
117}