com.hfg.xml.msofficexml.xlsx.spreadsheetDrawing.SsDrawShape 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.spreadsheetDrawing;
import java.awt.*;
import com.hfg.xml.msofficexml.docx.drawingml.DmlShapeType;
import com.hfg.xml.msofficexml.docx.drawingml.DmlTransform;
import com.hfg.xml.msofficexml.docx.drawingml.DmlXML;
import com.hfg.xml.msofficexml.docx.drawingml.color.DmlSRGBColor;
import com.hfg.xml.msofficexml.docx.drawingml.text.DmlTextAnchoringType;
import com.hfg.xml.msofficexml.xlsx.Xlsx;
import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXMLTag;
//------------------------------------------------------------------------------
/**
Represents an Office Open XML worksheet shape (<xdr:sp>) 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 SsDrawShape extends SsmlXMLTag
{
private SsDrawNonVisualShapeDrawingProperties mNonVisualShapeDrawingProperties;
private SsDrawShapeProperties mShapeProperties;
private SsDrawShapeStyle mStyle;
private SsDrawTextBody mTextBody;
private DmlTransform mTransform;
//---------------------------------------------------------------------------
public SsDrawShape(Xlsx inXlsx)
{
super(SsDrawXML.SHAPE, inXlsx);
init();
}
//---------------------------------------------------------------------------
public SsDrawShape(Xlsx inXlsx, DmlShapeType inShapeType)
{
this(inXlsx);
getShapeProperties().getOrCreatePresetGeometry().setShape(inShapeType);
}
//---------------------------------------------------------------------------
private void init()
{
// Initialize required subtags
getNonVisualShapeDrawingProperties();
getShapeProperties();
}
//---------------------------------------------------------------------------
/**
A shortcut for setting the name of a shape.
@param inValue the name to be applied to the shape
@return this shape object to facilitate method chaining
*/
public SsDrawShape setName(String inValue)
{
getNonVisualShapeDrawingProperties().getNonVisualDrawingProperties().setName(inValue);
return this;
}
//---------------------------------------------------------------------------
/**
* Returns the non-visual shape drawing properties (<xdr:nvSpPr>) tag if one exists or else instantiates a new one.
* @return the non-visual shape drawing properties (<xdr:nvSpPr>) for this shape tag
*/
public SsDrawNonVisualShapeDrawingProperties getNonVisualShapeDrawingProperties()
{
if (null == mNonVisualShapeDrawingProperties)
{
// Check if it has been added via addSubtag()...
mNonVisualShapeDrawingProperties = getOptionalSubtagByName(SsDrawXML.NON_VISUAL_SHAPE_DRAWING_PROPS);
if (null == mNonVisualShapeDrawingProperties)
{
mNonVisualShapeDrawingProperties = new SsDrawNonVisualShapeDrawingProperties(getParentDoc());
addSubtag(mNonVisualShapeDrawingProperties);
}
}
return mNonVisualShapeDrawingProperties;
}
//---------------------------------------------------------------------------
/**
* Returns the shape properties (<xdr:spPr>) tag if one exists or else instantiates a new one.
* @return the shape properties (<xdr:spPr>) for this shape tag
*/
public SsDrawShapeProperties getShapeProperties()
{
if (null == mShapeProperties)
{
// Check if it has been added via addSubtag()...
mShapeProperties = getOptionalSubtagByName(SsDrawXML.SHAPE_PROPS);
if (null == mShapeProperties)
{
mShapeProperties = new SsDrawShapeProperties(getParentDoc());
addSubtag(mShapeProperties);
}
}
return mShapeProperties;
}
//---------------------------------------------------------------------------
/**
* Returns the style (<xdr:style>) tag if one exists or else instantiates a new one.
* @return the style properties (<xdr:style>) for this shape tag
*/
public SsDrawShapeStyle getOrCreateStyle()
{
if (null == mStyle)
{
// Check if it has been added via addSubtag()...
mStyle = getOptionalSubtagByName(SsDrawXML.STYLE);
if (null == mStyle)
{
mStyle = new SsDrawShapeStyle(getParentDoc());
addSubtag(mStyle);
}
}
return mStyle;
}
//---------------------------------------------------------------------------
/**
* Returns the transform (<a:xfrm>) tag if one exists or else instantiates a new one.
* @return the transform (<a:xfrm>) for this shape tag
*/
public DmlTransform getOrCreateTransform()
{
if (null == mTransform)
{
// Check if it has been added via addSubtag()...
mTransform = getOptionalSubtagByName(DmlXML.TRANSFORM_2D);
if (null == mTransform)
{
mTransform = new DmlTransform();
addSubtag(mTransform);
}
}
return mTransform;
}
//---------------------------------------------------------------------------
/**
* Returns the text body (<xdr:txBody>) tag if one exists or else instantiates a new one.
* @return the text body (<xdr:txBody>) for this shape tag
*/
public SsDrawTextBody getOrCreateTextBody()
{
if (null == mTextBody)
{
// Check if it has been added via addSubtag()...
mTextBody = getOptionalSubtagByName(SsDrawXML.TEXT_BODY);
if (null == mTextBody)
{
mTextBody = new SsDrawTextBody(getParentDoc());
addSubtag(mTextBody);
}
}
return mTextBody;
}
//---------------------------------------------------------------------------
public void setText(String inText)
{
SsDrawTextBody textBody = getOrCreateTextBody();
textBody.getProperties().setAnchor(DmlTextAnchoringType.ctr); // Default to centered text
textBody.addParagraph(inText);
}
}