com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlTextRunProperties 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.xlsx.spreadsheetml;
import java.awt.Color;
import java.awt.Font;
import com.hfg.graphics.ColorUtil;
import com.hfg.xml.XMLTag;
import com.hfg.xml.msofficexml.xlsx.ExcelIndexedColor;
import com.hfg.xml.msofficexml.xlsx.Xlsx;
import com.hfg.xml.msofficexml.xlsx.spreadsheetml.style.SsmlTextVerticalAlignRunType;
import com.hfg.xml.msofficexml.xlsx.spreadsheetml.style.SsmlUnderlineType;
//------------------------------------------------------------------------------
/**
Represents an Office Open XML rich text run properties (<ssml:rPr>) tag.
This is the root tag of a table part.
@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 SsmlTextRunProperties extends SsmlXMLTag
{
private XMLTag mBoldTag;
private XMLTag mColorTag;
private XMLTag mFontTag;
private XMLTag mFontSizeTag;
private XMLTag mItalicTag;
private XMLTag mShadowTag;
private XMLTag mStrikeThroughTag;
private XMLTag mCondenseTag;
private XMLTag mExtendTag;
private XMLTag mUnderlineTag;
private XMLTag mVertAlignTag;
//##########################################################################
// CONSTRUCTORS
//##########################################################################
//---------------------------------------------------------------------------
public SsmlTextRunProperties(Xlsx inXlsx)
{
super(SsmlXML.TEXT_RUN_PROPS, inXlsx);
setDefaults();
}
//---------------------------------------------------------------------------
private void setDefaults()
{
}
//##########################################################################
// PUBLIC METHODS
//##########################################################################
//---------------------------------------------------------------------------
public SsmlTextRunProperties setFont(Font inValue)
{
if (null == mFontTag)
{
// Check it it has been added via addSubtag()...
mFontTag = getOptionalSubtagByName(SsmlXML.TEXT_RUN_FONT);
}
if (inValue != null)
{
if (null == mFontTag)
{
mFontTag = new XMLTag(SsmlXML.TEXT_RUN_FONT);
addSubtag(mFontTag);
}
mFontTag.setAttribute(SsmlXML.VALUE_ATT, inValue.getName());
setFontSize(inValue.getSize());
}
else if (mFontTag != null)
{
removeSubtag(mFontTag);
mFontTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setFontSize(Integer inValue)
{
if (null == mFontSizeTag)
{
// Check it it has been added via addSubtag()...
mFontSizeTag = getOptionalSubtagByName(SsmlXML.SIZE);
}
if (inValue != null)
{
if (null == mFontSizeTag)
{
mFontSizeTag = new XMLTag(SsmlXML.SIZE);
addSubtag(mFontSizeTag);
}
mFontSizeTag.setAttribute(SsmlXML.VALUE_ATT, inValue);
}
else if (mFontSizeTag != null)
{
removeSubtag(mFontSizeTag);
mFontSizeTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setBold(boolean inValue)
{
if (null == mBoldTag)
{
// Check it it has been added via addSubtag()...
mBoldTag = getOptionalSubtagByName(SsmlXML.BOLD);
}
if (inValue)
{
if (null == mBoldTag)
{
mBoldTag = new XMLTag(SsmlXML.BOLD);
addSubtag(mBoldTag);
}
}
else if (mBoldTag != null)
{
removeSubtag(mBoldTag);
mBoldTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setItalic(boolean inValue)
{
if (null == mItalicTag)
{
// Check it it has been added via addSubtag()...
mItalicTag = getOptionalSubtagByName(SsmlXML.ITALIC);
}
if (inValue)
{
if (null == mItalicTag)
{
mItalicTag = new XMLTag(SsmlXML.ITALIC);
addSubtag(mItalicTag);
}
}
else if (mItalicTag != null)
{
removeSubtag(mItalicTag);
mItalicTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setShadow(boolean inValue)
{
if (null == mShadowTag)
{
// Check it it has been added via addSubtag()...
mShadowTag = getOptionalSubtagByName(SsmlXML.SHADOW);
}
if (inValue)
{
if (null == mShadowTag)
{
mShadowTag = new XMLTag(SsmlXML.SHADOW);
addSubtag(mShadowTag);
}
}
else if (mShadowTag != null)
{
removeSubtag(mShadowTag);
mShadowTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setStrikeThrough(boolean inValue)
{
if (null == mStrikeThroughTag)
{
// Check it it has been added via addSubtag()...
mStrikeThroughTag = getOptionalSubtagByName(SsmlXML.STRIKE);
}
if (inValue)
{
if (null == mStrikeThroughTag)
{
mStrikeThroughTag = new XMLTag(SsmlXML.STRIKE);
addSubtag(mStrikeThroughTag);
}
}
else if (mStrikeThroughTag != null)
{
removeSubtag(mStrikeThroughTag);
mStrikeThroughTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setCondense(boolean inValue)
{
if (null == mCondenseTag)
{
// Check it it has been added via addSubtag()...
mCondenseTag = getOptionalSubtagByName(SsmlXML.CONDENSE);
}
if (inValue)
{
if (null == mCondenseTag)
{
mCondenseTag = new XMLTag(SsmlXML.CONDENSE);
addSubtag(mCondenseTag);
}
}
else if (mCondenseTag != null)
{
removeSubtag(mCondenseTag);
mCondenseTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setExtend(boolean inValue)
{
if (null == mExtendTag)
{
// Check it it has been added via addSubtag()...
mExtendTag = getOptionalSubtagByName(SsmlXML.EXTEND);
}
if (inValue)
{
if (null == mExtendTag)
{
mExtendTag = new XMLTag(SsmlXML.EXTEND);
addSubtag(mExtendTag);
}
}
else if (mExtendTag != null)
{
removeSubtag(mExtendTag);
mExtendTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setColor(Color inValue)
{
if (null == mColorTag)
{
// Check it it has been added via addSubtag()...
mColorTag = getOptionalSubtagByName(SsmlXML.COLOR);
}
if (inValue != null)
{
if (null == mColorTag)
{
mColorTag = new XMLTag(SsmlXML.COLOR);
addSubtag(mColorTag);
}
if (inValue instanceof ExcelIndexedColor)
{
mColorTag.setAttribute(SsmlXML.INDEXED_ATT, ((ExcelIndexedColor)inValue).getIndex());
}
else
{
mColorTag.setAttribute(SsmlXML.RGB_ATT, ColorUtil.colorToHex(inValue));
}
}
else if (mColorTag != null)
{
removeSubtag(mColorTag);
mColorTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setVertAlign(SsmlTextVerticalAlignRunType inValue)
{
if (null == mVertAlignTag)
{
// Check it it has been added via addSubtag()...
mVertAlignTag = getOptionalSubtagByName(SsmlXML.VERTICAL_ALIGN);
}
if (inValue != null)
{
if (null == mVertAlignTag)
{
mVertAlignTag = new XMLTag(SsmlXML.VERTICAL_ALIGN);
addSubtag(mVertAlignTag);
}
mVertAlignTag.setAttribute(SsmlXML.VALUE_ATT, inValue.name());
}
else if (mVertAlignTag != null)
{
removeSubtag(mVertAlignTag);
mVertAlignTag = null;
}
return this;
}
//---------------------------------------------------------------------------
public SsmlTextRunProperties setUnderline(SsmlUnderlineType inValue)
{
if (null == mUnderlineTag)
{
// Check it it has been added via addSubtag()...
mUnderlineTag = getOptionalSubtagByName(SsmlXML.UNDERLINE);
}
if (inValue != null)
{
if (null == mUnderlineTag)
{
mUnderlineTag = new XMLTag(SsmlXML.UNDERLINE);
addSubtag(mUnderlineTag);
}
mUnderlineTag.setAttribute(SsmlXML.VALUE_ATT, inValue.name());
}
else if (mUnderlineTag != null)
{
removeSubtag(mUnderlineTag);
mUnderlineTag = null;
}
return this;
}
}