com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlDataBar 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 com.hfg.exception.ProgrammingException;
import com.hfg.html.attribute.HTMLColor;
import com.hfg.xml.XMLNamespace;
import com.hfg.xml.XMLTag;
//------------------------------------------------------------------------------
/**
Represents an Office Open XML conditional formatting data bar (<ssml:dataBar>) 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 SsmlDataBar extends SsmlXMLTag
{
private SsmlWorksheet mParentWorksheet;
private SsmlDataBar mDataBarExtension;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public SsmlDataBar(SsmlWorksheet inParentWorksheet)
{
this(inParentWorksheet, SsmlXML.SPREADSHEETML_NAMESPACE);
}
//---------------------------------------------------------------------------
public SsmlDataBar(SsmlWorksheet inParentWorksheet, XMLNamespace inNamespace)
{
super(inNamespace.equals(SsmlXML.SPREADSHEETML_2009_NAMESPACE) ? SsmlXML.X14_DATA_BAR : SsmlXML.DATA_BAR, inParentWorksheet.getParentDoc());
mParentWorksheet = inParentWorksheet;
// Set some defaults
setMinLength(0);
setMaxLength(90);
if (inNamespace.equals(SsmlXML.SPREADSHEETML_NAMESPACE))
{
addSubtag(new XMLTag(SsmlXML.CONDITIONAL_FORMATTING_VALUE_OBJ).setAttribute(SsmlXML.TYPE_ATT, "min"));
addSubtag(new XMLTag(SsmlXML.CONDITIONAL_FORMATTING_VALUE_OBJ).setAttribute(SsmlXML.TYPE_ATT, "max"));
}
else if (inNamespace.equals(SsmlXML.SPREADSHEETML_2009_NAMESPACE))
{
// Extension properties
addSubtag(new XMLTag(SsmlXML.X14_CONDITIONAL_FORMATTING_VALUE_OBJ).setAttribute(SsmlXML.TYPE_ATT, "autoMin"));
addSubtag(new XMLTag(SsmlXML.X14_CONDITIONAL_FORMATTING_VALUE_OBJ).setAttribute(SsmlXML.TYPE_ATT, "autoMax"));
addSubtag(new XMLTag(SsmlXML.X14_NEGATIVE_FILL_COLOR).setAttribute(SsmlXML.RGB_ATT, colorToCT_Color(HTMLColor.RED)));
addSubtag(new XMLTag(SsmlXML.X14_AXIS_COLOR).setAttribute(SsmlXML.RGB_ATT, colorToCT_Color(HTMLColor.BLACK)));
}
else
{
throw new ProgrammingException("Unrecognized namespace option for conditionalFormatting tag: " + inNamespace);
}
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
public void setExtension(SsmlDataBar inValue)
{
mDataBarExtension = inValue;
}
//---------------------------------------------------------------------------
/**
Specifies the minimum length of the data bar, as a percentage of the cell's width.
Default is 0.
* @param inValue the minimum percent of the cell width for data bar values
* @return this SsmlDataBar object to enable method chaining.
*/
public SsmlDataBar setMinLength(Integer inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.MIN_LENGTH_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.MIN_LENGTH_ATT);
}
if (getNamespace().equals(SsmlXML.SPREADSHEETML_NAMESPACE)
&& mDataBarExtension != null)
{
mDataBarExtension.setMinLength(inValue);
}
return this;
}
//---------------------------------------------------------------------------
/**
Specifies the maximum length of the data bar, as a percentage of the cell's width.
Default is 90.
* @param inValue the maximum percent of the cell width for data bar values
* @return this SsmlDataBar object to enable method chaining.
*/
public SsmlDataBar setMaxLength(Integer inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.MAX_LENGTH_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.MAX_LENGTH_ATT);
}
if (getNamespace().equals(SsmlXML.SPREADSHEETML_NAMESPACE)
&& mDataBarExtension != null)
{
mDataBarExtension.setMaxLength(inValue);
}
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not to display the numeric value to the right of the data bar.
Default is "true".
* @param inValue whether or not to display the numeric value
* @return this SsmlDataBar object to enable method chaining.
*/
public SsmlDataBar setShowValue(Boolean inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.SHOW_VALUE_ATT, inValue ? "true" : "false");
}
else
{
removeAttribute(SsmlXML.SHOW_VALUE_ATT);
}
if (getNamespace().equals(SsmlXML.SPREADSHEETML_NAMESPACE)
&& mDataBarExtension != null)
{
mDataBarExtension.setShowValue(inValue);
}
return this;
}
//---------------------------------------------------------------------------
public SsmlDataBar setColor(Color inValue)
{
if (getNamespace().equals(SsmlXML.SPREADSHEETML_NAMESPACE))
{
// Check if it has been added via addSubtag()...
XMLTag colorTag = getOptionalSubtagByName(SsmlXML.COLOR);
if (null == colorTag)
{
colorTag = new XMLTag(SsmlXML.COLOR);
addSubtag(colorTag);
}
colorTag.setAttribute(SsmlXML.RGB_ATT, colorToCT_Color(inValue));
if (mDataBarExtension != null)
{
mDataBarExtension.setColor(inValue);
}
}
else if (getNamespace().equals(SsmlXML.SPREADSHEETML_2009_NAMESPACE))
{
/* // Check if it has been added via addSubtag()...
XMLTag colorTag = getOptionalSubtagByName(SsmlXML.X14_FILL_COLOR);
if (null == colorTag)
{
colorTag = new XMLTag(SsmlXML.X14_FILL_COLOR);
addSubtag(colorTag);
}
colorTag.setAttribute(SsmlXML.RGB_ATT, ColorUtil.colorToHex(inValue));
*/
}
else
{
throw new ProgrammingException("Unrecognized namespace option for dataBar tag: " + getNamespace());
}
return this;
}
//---------------------------------------------------------------------------
public SsmlDataBar setBorderColor(Color inValue)
{
if (getNamespace().equals(SsmlXML.SPREADSHEETML_NAMESPACE))
{
if (mDataBarExtension != null)
{
mDataBarExtension.setBorderColor(inValue);
}
}
else if (getNamespace().equals(SsmlXML.SPREADSHEETML_2009_NAMESPACE))
{
// Check if it has been added via addSubtag()...
XMLTag borderColorTag = getOptionalSubtagByName(SsmlXML.X14_BORDER_COLOR);
if (null == borderColorTag)
{
borderColorTag = new XMLTag(SsmlXML.X14_BORDER_COLOR);
addSubtag(borderColorTag);
}
if (inValue != null)
{
borderColorTag.setAttribute(SsmlXML.RGB_ATT, colorToCT_Color(inValue));
setBorder(true);
}
else
{
removeSubtag(borderColorTag);
}
}
else
{
throw new ProgrammingException("Unrecognized namespace option for dataBar tag: " + getNamespace());
}
return this;
}
//---------------------------------------------------------------------------
public SsmlDataBar setGradient(Boolean inValue)
{
if (getNamespace().equals(SsmlXML.SPREADSHEETML_NAMESPACE))
{
if (mDataBarExtension != null)
{
mDataBarExtension.setGradient(inValue);
}
}
else if (getNamespace().equals(SsmlXML.SPREADSHEETML_2009_NAMESPACE))
{
if (inValue != null)
{
setAttribute(SsmlXML.X14_GRADIENT_ATT, inValue ? "1" : "0");
}
else
{
removeAttribute(SsmlXML.X14_GRADIENT_ATT);
}
}
else
{
throw new ProgrammingException("Unrecognized namespace option for dataBar tag: " + getNamespace());
}
return this;
}
//---------------------------------------------------------------------------
public SsmlDataBar setBorder(Boolean inValue)
{
if (getNamespace().equals(SsmlXML.SPREADSHEETML_NAMESPACE))
{
if (mDataBarExtension != null)
{
mDataBarExtension.setBorder(inValue);
}
}
else if (getNamespace().equals(SsmlXML.SPREADSHEETML_2009_NAMESPACE))
{
if (inValue != null)
{
setAttribute(SsmlXML.X14_BORDER_ATT, inValue ? "1" : "0");
}
else
{
removeAttribute(SsmlXML.X14_BORDER_ATT);
}
}
else
{
throw new ProgrammingException("Unrecognized namespace option for dataBar tag: " + getNamespace());
}
return this;
}
}