com.hfg.xml.msofficexml.docx.drawingml.fill.DmlGradientFill 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.drawingml.fill;
import com.hfg.math.Percent;
import com.hfg.math.units.Angle;
import com.hfg.math.units.AngleUnits;
import com.hfg.xml.XMLTag;
import com.hfg.xml.msofficexml.docx.drawingml.DmlXML;
import com.hfg.xml.msofficexml.docx.drawingml.color.DmlColor;
//------------------------------------------------------------------------------
/**
Represents a gradient fill (<a:gradFill>) tag in drawing markup language (DML) from Office Open XML.
@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]
//------------------------------------------------------------------------------
/*
Ex:
*/
public class DmlGradientFill extends DmlFill
{
private XMLTag mGradientStopListTag;
private XMLTag mLinearGradientFillTag;
public enum TileRectFlip
{
none,
x,
xy,
y
}
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public DmlGradientFill()
{
super(DmlXML.SOLID_FILL);
// TODO: Are defaults needed to keep Excel from barfing?
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
/**
Specifies the direction (clockwise) for the gradient.
@param inValue gradient angle in arbitrary units. (The value in the xml will be converted to 60000ths of a degree)
@return this DmlGradientFill object to enable method chaining
*/
public DmlGradientFill setAngle(Angle inValue)
{
getOrCreateLinearGradientFillTag().setAttribute(DmlXML.ANGLE_ATT, inValue.to(AngleUnits.degrees) * 60000);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether the angle scales with the fill region.
@param inValue whether the angle scales with the fill region
@return this DmlGradientFill object to enable method chaining
*/
public DmlGradientFill setScaled(boolean inValue)
{
getOrCreateLinearGradientFillTag().setAttribute(DmlXML.SCALED_ATT, inValue ? "1" : "0");
return this;
}
//---------------------------------------------------------------------------
public DmlGradientFill addGradientStop(Percent inPosition, DmlColor inColorModel)
{
if (null == mGradientStopListTag)
{
mGradientStopListTag = new XMLTag(DmlXML.GRADIENT_STOP_LIST);
addSubtag(mGradientStopListTag);
}
DmlGradientStop gradientStopTag = new DmlGradientStop().setPosition(inPosition).setColorModel(inColorModel);
mGradientStopListTag.addSubtag(gradientStopTag);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies the direction in which to flip the gradient while tiling.
This is only relevant when a tileRect is specified so that the gradient must
be tiles to fill the shape. Possible values are none, x (horizontal), xy
(horizontal and vertical), and y (vertical).
@param inValue the direction to flip the gradient fill
@return this DmlGradientFill object to enable method chaining
*/
public DmlGradientFill setFlip(TileRectFlip inValue)
{
setAttribute(DmlXML.FLIP_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies if the gradient fill rotates with the shape when the shape is rotated.
@param inValue whether to rotate the gradient fill when the shape is rotated
@return this DmlGradientFill object to enable method chaining
*/
public DmlGradientFill setRotateWithShape(boolean inValue)
{
setAttribute(DmlXML.ROTATE_WITH_SHAPE_ATT, inValue);
return this;
}
//###########################################################################
// PRIVATE METHODS
//###########################################################################
//---------------------------------------------------------------------------
private XMLTag getOrCreateLinearGradientFillTag()
{
if (null == mLinearGradientFillTag)
{
mLinearGradientFillTag = new XMLTag(DmlXML.LINEAR_GRAD_FILL);
addSubtag(mLinearGradientFillTag);
}
return mLinearGradientFillTag;
}
}