001package com.hfg.xml.msofficexml.xlsx.spreadsheetml;
002
003
004import com.hfg.graphics.units.GfxSize;
005import com.hfg.graphics.units.GfxUnits;
006import com.hfg.graphics.units.Inches;
007import com.hfg.util.StringUtil;
008import com.hfg.xml.msofficexml.xlsx.Xlsx;
009
010//------------------------------------------------------------------------------
011/**
012 Represents an Office Open XML worksheet's page margins (<ssml:pageMargins>) tag.
013
014 @author J. Alex Taylor, hairyfatguy.com
015 */
016//------------------------------------------------------------------------------
017// com.hfg XML/HTML Coding Library
018//
019// This library is free software; you can redistribute it and/or
020// modify it under the terms of the GNU Lesser General Public
021// License as published by the Free Software Foundation; either
022// version 2.1 of the License, or (at your option) any later version.
023//
024// This library is distributed in the hope that it will be useful,
025// but WITHOUT ANY WARRANTY; without even the implied warranty of
026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
027// Lesser General Public License for more details.
028//
029// You should have received a copy of the GNU Lesser General Public
030// License along with this library; if not, write to the Free Software
031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
032//
033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
034// jataylor@hairyfatguy.com
035//------------------------------------------------------------------------------
036// Ex: <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
037public class SsmlPageMargins extends SsmlXMLTag
038{
039
040   //---------------------------------------------------------------------------
041   public SsmlPageMargins(Xlsx inXlsx)
042   {
043      super(SsmlXML.PAGE_MARGINS, inXlsx);
044      init();
045   }
046
047
048   //---------------------------------------------------------------------------
049   private void init()
050   {
051      setLeft(new Inches(0.75f));
052      setRight(new Inches(0.75f));
053      setTop(new Inches(1f));
054      setBottom(new Inches(1f));
055      setHeader(new Inches(0.5f));
056      setFooter(new Inches(0.5f));
057   }
058
059   //---------------------------------------------------------------------------
060   public SsmlPageMargins setLeft(GfxSize inValue)
061   {
062      setAttribute(SsmlXML.LEFT_ATT, inValue.to(GfxUnits.inches));
063      return this;
064   }
065
066   //---------------------------------------------------------------------------
067   public GfxSize getLeft()
068   {
069      String stringValue = getAttributeValue(SsmlXML.LEFT_ATT);
070      GfxSize value =  null;
071      if (StringUtil.isSet(stringValue))
072      {
073         value = new Inches(Float.parseFloat(stringValue));
074      }
075
076      return value;
077   }
078
079   //---------------------------------------------------------------------------
080   public SsmlPageMargins setRight(GfxSize inValue)
081   {
082      setAttribute(SsmlXML.RIGHT_ATT, inValue.to(GfxUnits.inches));
083      return this;
084   }
085
086   //---------------------------------------------------------------------------
087   public GfxSize getRight()
088   {
089      String stringValue = getAttributeValue(SsmlXML.RIGHT_ATT);
090      GfxSize value =  null;
091      if (StringUtil.isSet(stringValue))
092      {
093         value = new Inches(Float.parseFloat(stringValue));
094      }
095
096      return value;
097   }
098
099   //---------------------------------------------------------------------------
100   public SsmlPageMargins setTop(GfxSize inValue)
101   {
102      setAttribute(SsmlXML.TOP_ATT, inValue.to(GfxUnits.inches));
103      return this;
104   }
105
106   //---------------------------------------------------------------------------
107   public GfxSize getTop()
108   {
109      String stringValue = getAttributeValue(SsmlXML.TOP_ATT);
110      GfxSize value =  null;
111      if (StringUtil.isSet(stringValue))
112      {
113         value = new Inches(Float.parseFloat(stringValue));
114      }
115
116      return value;
117   }
118
119   //---------------------------------------------------------------------------
120   public SsmlPageMargins setBottom(GfxSize inValue)
121   {
122      setAttribute(SsmlXML.BOTTOM_ATT, inValue.to(GfxUnits.inches));
123      return this;
124   }
125
126   //---------------------------------------------------------------------------
127   public GfxSize getBottom()
128   {
129      String stringValue = getAttributeValue(SsmlXML.BOTTOM_ATT);
130      GfxSize value =  null;
131      if (StringUtil.isSet(stringValue))
132      {
133         value = new Inches(Float.parseFloat(stringValue));
134      }
135
136      return value;
137   }
138
139   //---------------------------------------------------------------------------
140   public SsmlPageMargins setHeader(GfxSize inValue)
141   {
142      setAttribute(SsmlXML.HEADER_ATT, inValue.to(GfxUnits.inches));
143      return this;
144   }
145
146   //---------------------------------------------------------------------------
147   public GfxSize getHeader()
148   {
149      String stringValue = getAttributeValue(SsmlXML.HEADER_ATT);
150      GfxSize value =  null;
151      if (StringUtil.isSet(stringValue))
152      {
153         value = new Inches(Float.parseFloat(stringValue));
154      }
155
156      return value;
157   }
158
159   //---------------------------------------------------------------------------
160   public SsmlPageMargins setFooter(GfxSize inValue)
161   {
162      setAttribute(SsmlXML.FOOTER_ATT, inValue.to(GfxUnits.inches));
163      return this;
164   }
165
166   //---------------------------------------------------------------------------
167   public GfxSize getFooter()
168   {
169      String stringValue = getAttributeValue(SsmlXML.FOOTER_ATT);
170      GfxSize value =  null;
171      if (StringUtil.isSet(stringValue))
172      {
173         value = new Inches(Float.parseFloat(stringValue));
174      }
175
176      return value;
177   }
178}