com.hfg.xml.msofficexml.docx.wordprocessingml.WmlPageMargins Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.xml.msofficexml.docx.wordprocessingml;
import com.hfg.graphics.units.GfxSize;
import com.hfg.graphics.units.GfxUnits;
import com.hfg.graphics.units.Twips;
import com.hfg.util.StringUtil;
import com.hfg.xml.XMLName;
import com.hfg.xml.XMLTag;
// Section 17.6.11 (pg. 571) of Ecma Office Open XML Part 1
//
//------------------------------------------------------------------------------
/**
* Page margins tag (<pgMar>) of a OfficeOpenXML Docx document.
*
* @author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
public class WmlPageMargins extends XMLTag
{
//---------------------------------------------------------------------------
public WmlPageMargins()
{
super(WmlXML.PAGE_MARGINS);
}
//---------------------------------------------------------------------------
/**
* Specifies the distance (in twentieths of a point) between the bottom of the text
* margins for the main document and the bottom of the page for all pages in this section.
* @param inValue distance specified in generic GfxSize which will be converted to twisps (twentieths of a point)
* @return this WmlPageMargins object to enable method chaining
*/
public WmlPageMargins setBottom(GfxSize inValue)
{
if (inValue != null)
{
setAttribute(WmlXML.BOTTOM_ATT, inValue.toInt(GfxUnits.dxa));
}
else
{
removeAttribute(WmlXML.BOTTOM_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public GfxSize getBottom()
{
return getTwispAttribute(WmlXML.BOTTOM_ATT);
}
//---------------------------------------------------------------------------
/**
* Specifies the distance (in twips or twentieths of a point) from the bottom edge of the page to the bottom edge of the footer.
* @param inValue distance specified in generic GfxSize which will be converted to twisps (twentieths of a point)
* @return this WmlPageMargins object to enable method chaining
*/
public WmlPageMargins setFooter(GfxSize inValue)
{
if (inValue != null)
{
setAttribute(WmlXML.FOOTER_ATT, inValue.toInt(GfxUnits.dxa));
}
else
{
removeAttribute(WmlXML.FOOTER_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public GfxSize getFooter()
{
return getTwispAttribute(WmlXML.FOOTER_ATT);
}
//---------------------------------------------------------------------------
/**
* Specifies the page gutter (the extra space added to the margin, typically to account for binding).
* @param inValue distance specified in generic GfxSize which will be converted to twisps (twentieths of a point)
* @return this WmlPageMargins object to enable method chaining
*/
public WmlPageMargins setGutter(GfxSize inValue)
{
if (inValue != null)
{
setAttribute(WmlXML.GUTTER_ATT, inValue.toInt(GfxUnits.dxa));
}
else
{
removeAttribute(WmlXML.GUTTER_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public GfxSize getGutter()
{
return getTwispAttribute(WmlXML.GUTTER_ATT);
}
//---------------------------------------------------------------------------
/**
* Specifies the distance (in twips or twentieths of a point) from the top edge of the page to the top edge of the header.
* @param inValue distance specified in generic GfxSize which will be converted to twisps (twentieths of a point)
* @return this WmlPageMargins object to enable method chaining
*/
public WmlPageMargins setHeader(GfxSize inValue)
{
if (inValue != null)
{
setAttribute(WmlXML.HEADER_ATT, inValue.toInt(GfxUnits.dxa));
}
else
{
removeAttribute(WmlXML.HEADER_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public GfxSize getHeader()
{
return getTwispAttribute(WmlXML.HEADER_ATT);
}
//---------------------------------------------------------------------------
/**
* Specifies the distance (in twips or twentieths of a point) from the left edge of the page to the left edge of the text.
* @param inValue distance specified in generic GfxSize which will be converted to twisps (twentieths of a point)
* @return this WmlPageMargins object to enable method chaining
*/
public WmlPageMargins setLeft(GfxSize inValue)
{
if (inValue != null)
{
setAttribute(WmlXML.LEFT_ATT, inValue.toInt(GfxUnits.dxa));
}
else
{
removeAttribute(WmlXML.LEFT_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public GfxSize getLeft()
{
return getTwispAttribute(WmlXML.LEFT_ATT);
}
//---------------------------------------------------------------------------
/**
* Specifies the distance (in twips or twentieths of a point) from the right edge of the page to the right edge of the text.
* @param inValue distance specified in generic GfxSize which will be converted to twisps (twentieths of a point)
* @return this WmlPageMargins object to enable method chaining
*/
public WmlPageMargins setRight(GfxSize inValue)
{
if (inValue != null)
{
setAttribute(WmlXML.RIGHT_ATT, inValue.toInt(GfxUnits.dxa));
}
else
{
removeAttribute(WmlXML.RIGHT_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public GfxSize getRight()
{
return getTwispAttribute(WmlXML.RIGHT_ATT);
}
//---------------------------------------------------------------------------
/**
* Specifies the distance (in twips or twentieths of a point) from the top edge of the page to the top edge of the text.
* @param inValue distance specified in generic GfxSize which will be converted to twisps (twentieths of a point)
* @return this WmlPageMargins object to enable method chaining
*/
public WmlPageMargins setTop(GfxSize inValue)
{
if (inValue != null)
{
setAttribute(WmlXML.TOP_ATT, inValue.toInt(GfxUnits.dxa));
}
else
{
removeAttribute(WmlXML.TOP_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public GfxSize getTop()
{
return getTwispAttribute(WmlXML.TOP_ATT);
}
//---------------------------------------------------------------------------
private GfxSize getTwispAttribute(XMLName inAttribute)
{
GfxSize value = null;
String stringValue = getAttributeValue(inAttribute);
if (StringUtil.isSet(stringValue))
{
value = new Twips(Integer.parseInt(stringValue));
}
return value;
}
}