com.hfg.xml.msofficexml.docx.wordprocessingml.WmlTableRowProperties 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.xml.XMLTag;
import com.hfg.xml.msofficexml.docx.Docx;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlJustification;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlParagraphStyle;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlShading;
//------------------------------------------------------------------------------
/**
Represents an Office Open XML table row properties (<w:trPr>) tag.
@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 WmlTableRowProperties extends WmlXMLTag
{
private XMLTag mStyle;
private XMLTag mHeightTag;
private XMLTag mJustificationTag;
private XMLTag mCantSplitTag;
private XMLTag mTableHeaderTag;
private WmlShading mShadingTag;
//---------------------------------------------------------------------------
public WmlTableRowProperties(Docx inDocx)
{
super(WmlXML.TABLE_ROW_PROPS, inDocx);
}
//---------------------------------------------------------------------------
public WmlTableRowProperties setStyle(String inStyleId)
{
if (null == mStyle)
{
mStyle = new WmlParagraphStyle(getParentDoc());
addSubtag(mStyle);
}
mStyle.setAttribute(WmlXML.STYLE_ID_ATT, inStyleId);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies that the table row should determine its height based on contents.
@return this properties object to enable method chaining.
*/
public WmlTableRowProperties setAutoHeight()
{
XMLTag heightTag = getHeightTag();
heightTag.setAttribute(WmlXML.HEIGHT_RULE_ATT, "auto");
heightTag.removeAttribute(WmlXML.VALUE_ATT);
return this;
}
//---------------------------------------------------------------------------
public WmlTableRowProperties setAtLeastHeight(GfxSize inValue)
{
XMLTag heightTag = getHeightTag();
heightTag.setAttribute(WmlXML.HEIGHT_RULE_ATT, "atLeast");
heightTag.setAttribute(WmlXML.VALUE_ATT, inValue.toInt(GfxUnits.dxa));
return this;
}
//---------------------------------------------------------------------------
public WmlTableRowProperties setExactHeight(GfxSize inValue)
{
XMLTag heightTag = getHeightTag();
heightTag.setAttribute(WmlXML.HEIGHT_RULE_ATT, "exact");
heightTag.setAttribute(WmlXML.VALUE_ATT, inValue.toInt(GfxUnits.dxa));
return this;
}
//---------------------------------------------------------------------------
public WmlTableRowProperties setJustification(WmlJustification inValue)
{
if (null == mJustificationTag)
{
// Check it it has been added via addSubtag()...
mJustificationTag = getOptionalSubtagByName(WmlXML.JUSTIFICATION);
if (null == mJustificationTag)
{
mJustificationTag = new XMLTag(WmlXML.JUSTIFICATION);
addSubtag(mJustificationTag);
}
}
mJustificationTag.setAttribute(WmlXML.VALUE_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Repeat Table Row on Every New Page.
*/
public WmlTableRowProperties setTableHeader(boolean inValue)
{
if (null == mTableHeaderTag)
{
// Check if it has been added via addSubtag()...
mTableHeaderTag = getOptionalSubtagByName(WmlXML.TABLE_HEADER);
if (null == mTableHeaderTag)
{
mTableHeaderTag = new XMLTag(WmlXML.TABLE_HEADER);
addSubtag(mTableHeaderTag);
}
}
mTableHeaderTag.setAttribute(WmlXML.VALUE_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
* Specifies that this table row should not be separated by a page break from the row that follows it.
*/
public WmlTableRowProperties setCantSplit()
{
if (null == mCantSplitTag)
{
// Check if it has been added via addSubtag()...
mCantSplitTag = getOptionalSubtagByName(WmlXML.CANT_SPLIT);
if (null == mCantSplitTag)
{
mCantSplitTag = new XMLTag(WmlXML.CANT_SPLIT);
addSubtag(mCantSplitTag);
}
}
return this;
}
//---------------------------------------------------------------------------
public WmlShading getShading()
{
if (null == mShadingTag)
{
// Check if it has been added via addSubtag()...
mShadingTag = getOptionalSubtagByName(WmlXML.SHADING);
if (null == mShadingTag)
{
mShadingTag = new WmlShading();
addSubtag(mShadingTag);
}
}
return mShadingTag;
}
//---------------------------------------------------------------------------
private XMLTag getHeightTag()
{
if (null == mHeightTag)
{
// Check if it has been added via addSubtag()...
mHeightTag = getOptionalSubtagByName(WmlXML.TABLE_ROW_HEIGHT);
if (null == mHeightTag)
{
mHeightTag = new XMLTag(WmlXML.TABLE_ROW_HEIGHT);
addSubtag(mHeightTag);
}
}
return mHeightTag;
}
}