com.hfg.xml.msofficexml.docx.wordprocessingml.WmlTableCellProperties 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.WmlParagraphStyle;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlShading;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlTableCellBorders;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlTableCellMargins;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlTextDirection;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlVerticalJustification;
public class WmlTableCellProperties extends WmlXMLTag
{
private XMLTag mStyle;
private XMLTag mWidthTag;
private XMLTag mGridSpanTag;
private XMLTag mHideMarkTag;
private XMLTag mTextDirectionTag;
private XMLTag mVAlignTag;
private XMLTag mVMergeTag;
private WmlShading mShadingTag;
private WmlTableCellBorders mBorders;
private WmlTableCellMargins mTableCellMargins;
private enum Type {
auto,
dxa, // twentieths of a point
pct
}
//---------------------------------------------------------------------------
public WmlTableCellProperties(Docx inDocx)
{
super(WmlXML.TABLE_CELL_PROPS, inDocx);
}
//---------------------------------------------------------------------------
public WmlTableCellProperties add(WmlTableCellProperties inProperties)
{
if (inProperties.mStyle != null)
{
mStyle = inProperties.mStyle;
}
if (inProperties.mWidthTag != null)
{
mWidthTag = inProperties.mWidthTag;
}
if (inProperties.mGridSpanTag != null)
{
mGridSpanTag = inProperties.mGridSpanTag;
}
if (inProperties.mHideMarkTag != null)
{
mHideMarkTag = inProperties.mHideMarkTag;
}
if (inProperties.mTextDirectionTag != null)
{
mTextDirectionTag = inProperties.mTextDirectionTag;
}
if (inProperties.mVAlignTag != null)
{
mVAlignTag = inProperties.mVAlignTag;
}
if (inProperties.mVMergeTag != null)
{
mVMergeTag = inProperties.mVMergeTag;
}
if (inProperties.mShadingTag != null)
{
mShadingTag = inProperties.mShadingTag;
}
if (inProperties.mBorders != null)
{
mBorders = inProperties.mBorders;
}
if (inProperties.mTableCellMargins != null)
{
mTableCellMargins = inProperties.mTableCellMargins;
}
return this;
}
//---------------------------------------------------------------------------
public WmlTableCellProperties setStyle(String inStyleId)
{
if (null == mStyle)
{
mStyle = new WmlParagraphStyle(getParentDoc());
addSubtag(mStyle);
}
mStyle.setAttribute(WmlXML.STYLE_ID_ATT, inStyleId);
return this;
}
//---------------------------------------------------------------------------
public WmlTableCellProperties setWidth(GfxSize inValue)
{
if (null == mWidthTag)
{
// Check if it has been added via addSubtag()...
mWidthTag = getOptionalSubtagByName(WmlXML.TABLE_CELL_WIDTH);
if (null == mWidthTag)
{
mWidthTag = new XMLTag(WmlXML.TABLE_CELL_WIDTH);
addSubtag(mWidthTag);
}
}
mWidthTag.setAttribute(WmlXML.TYPE_ATT, "dxa");
mWidthTag.setAttribute(WmlXML.VALUE_ATT, inValue.toInt(GfxUnits.dxa));
return this;
}
//---------------------------------------------------------------------------
// From http://officeopenxml.com/WPtableCellProperties-Width.php :
// "Note: The 2006 version of the OOXML standard specified that the value was to be a decimal.
// When type="pct", the value was interpreted as fifths of a percent, so 4975=99.5%, and no % symbol
// was included in the attribute. In the 2011 version the value can be either a decimal or a percent,
// so a % symbol should be included when type="pct"."
public WmlTableCellProperties setWidthPct(float inValue)
{
if (null == mWidthTag)
{
// Check it it has been added via addSubtag()...
mWidthTag = getOptionalSubtagByName(WmlXML.TABLE_CELL_WIDTH);
if (null == mWidthTag)
{
mWidthTag = new XMLTag(WmlXML.TABLE_CELL_WIDTH);
addSubtag(mWidthTag);
}
}
// This was causing an error for older versions of Word that prevented the file from opening
// mWidthTag.setAttribute(WmlXML.WIDTH_ATT, inValue + "%");
mWidthTag.setAttribute(WmlXML.WIDTH_ATT, (int) inValue * 50);
mWidthTag.setAttribute(WmlXML.TYPE_ATT, Type.pct.name());
return this;
}
//---------------------------------------------------------------------------
public WmlTableCellProperties setGridSpan(Integer inValue)
{
if (null == mGridSpanTag)
{
// Check if it has been added via addSubtag()...
mGridSpanTag = getOptionalSubtagByName(WmlXML.GRID_SPAN);
if (null == mGridSpanTag)
{
mGridSpanTag = new XMLTag(WmlXML.GRID_SPAN);
addSubtag(mGridSpanTag);
}
}
mGridSpanTag.setAttribute(WmlXML.VALUE_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Ignore End Of Cell Marker In Row Height Calculation.
*/
public WmlTableCellProperties setHideMark(boolean inValue)
{
if (null == mHideMarkTag)
{
// Check if it has been added via addSubtag()...
mHideMarkTag = getOptionalSubtagByName(WmlXML.HIDE_MARK);
if (null == mHideMarkTag)
{
mHideMarkTag = new XMLTag(WmlXML.HIDE_MARK);
addSubtag(mHideMarkTag);
}
}
mHideMarkTag.setAttribute(WmlXML.VALUE_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
public WmlTableCellProperties setTextDirection(WmlTextDirection inValue)
{
if (null == mTextDirectionTag)
{
// Check if it has been added via addSubtag()...
mTextDirectionTag = getOptionalSubtagByName(WmlXML.TEXT_DIRECTION);
if (inValue != null
&& null == mTextDirectionTag)
{
mTextDirectionTag = new XMLTag(WmlXML.TEXT_DIRECTION);
addSubtag(mTextDirectionTag);
}
else if (null == inValue
&& mTextDirectionTag != null)
{
removeSubtag(mTextDirectionTag);
mTextDirectionTag = null;
}
}
if (inValue != null)
{
mTextDirectionTag.setAttribute(WmlXML.VALUE_ATT, inValue.name());
}
return this;
}
//---------------------------------------------------------------------------
public WmlTableCellProperties setVerticalJustification(WmlVerticalJustification inValue)
{
if (null == mVAlignTag)
{
// Check if it has been added via addSubtag()...
mVAlignTag = getOptionalSubtagByName(WmlXML.VALIGN);
if (null == mVAlignTag)
{
mVAlignTag = new XMLTag(WmlXML.VALIGN);
addSubtag(mVAlignTag);
}
}
mVAlignTag.setAttribute(WmlXML.VALUE_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
public WmlTableCellProperties setVerticalMerge(WmlVerticalMerge inValue)
{
if (null == mVMergeTag)
{
// Check if it has been added via addSubtag()...
mVMergeTag = getOptionalSubtagByName(WmlXML.VMERGE);
if (null == mVMergeTag)
{
mVMergeTag = new XMLTag(WmlXML.VMERGE);
addSubtag(mVMergeTag);
}
}
mVMergeTag.setAttribute(WmlXML.VALUE_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
public WmlShading getShading()
{
if (null == mShadingTag)
{
// Check it it has been added via addSubtag()...
mShadingTag = getOptionalSubtagByName(WmlXML.SHADING);
if (null == mShadingTag)
{
mShadingTag = new WmlShading();
addSubtag(mShadingTag);
}
}
return mShadingTag;
}
//---------------------------------------------------------------------------
public WmlTableCellBorders getBorders()
{
if (null == mBorders)
{
mBorders = new WmlTableCellBorders();
addSubtag(mBorders);
}
return mBorders;
}
//---------------------------------------------------------------------------
public WmlTableCellMargins getTableCellMargins()
{
if (null == mTableCellMargins)
{
// Check it it has been added via addSubtag()...
mTableCellMargins = getOptionalSubtagByName(WmlXML.TABLE_CELL_MARGIN);
if (null == mTableCellMargins)
{
mTableCellMargins = new WmlTableCellMargins(this);
addSubtag(mTableCellMargins);
}
}
return mTableCellMargins;
}
}