001package com.hfg.xml.msofficexml.docx.drawingml; 002 003 004import com.hfg.xml.XMLTag; 005import com.hfg.xml.msofficexml.OfficeOpenXMLTag; 006import com.hfg.xml.msofficexml.OfficeOpenXmlDocument; 007import com.hfg.xml.msofficexml.docx.drawingml.fill.DmlFill; 008import com.hfg.xml.msofficexml.docx.drawingml.line.DmlLine; 009 010//------------------------------------------------------------------------------ 011/** 012 Represents an Office Open XML drawingml shape properties (<a:shPr>) tag. 013 <div> 014 @author J. Alex Taylor, hairyfatguy.com 015 </div> 016 */ 017//------------------------------------------------------------------------------ 018// com.hfg XML/HTML Coding Library 019// 020// This library is free software; you can redistribute it and/or 021// modify it under the terms of the GNU Lesser General Public 022// License as published by the Free Software Foundation; either 023// version 2.1 of the License, or (at your option) any later version. 024// 025// This library is distributed in the hope that it will be useful, 026// but WITHOUT ANY WARRANTY; without even the implied warranty of 027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 028// Lesser General Public License for more details. 029// 030// You should have received a copy of the GNU Lesser General Public 031// License along with this library; if not, write to the Free Software 032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 033// 034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 035// jataylor@hairyfatguy.com 036//------------------------------------------------------------------------------ 037 038public class DmlShapeProperties extends OfficeOpenXMLTag 039{ 040 private DmlTransform mTransform; 041 private DmlPresetGeometry mPresetGeometry; 042 private XMLTag mFillTag; 043 private DmlLine mLine; 044 045 //--------------------------------------------------------------------------- 046 public DmlShapeProperties(OfficeOpenXmlDocument inParentDoc) 047 { 048 super(DmlXML.SHAPE_PROPS, inParentDoc); 049 init(); 050 } 051 052 //--------------------------------------------------------------------------- 053 private void init() 054 { 055 setBWMode(DmlBlackWhiteMode.auto); 056 getTransform(); 057 } 058 059 //--------------------------------------------------------------------------- 060 public DmlShapeProperties setBWMode(DmlBlackWhiteMode inValue) 061 { 062 setAttribute(DmlXML.BLACK_WHITE_MODE_ATT, inValue.name()); 063 return this; 064 } 065 066 067 //--------------------------------------------------------------------------- 068 /** 069 * Returns the transform tag if one exists or else instantiates a new one. 070 * @return the transform tag for this shape properties tag 071 */ 072 public DmlTransform getTransform() 073 { 074 if (null == mTransform) 075 { 076 // Check if it has been added via addSubtag()... 077 mTransform = getOptionalSubtagByName(DmlXML.TRANSFORM_2D); 078 if (null == mTransform) 079 { 080 mTransform = new DmlTransform(); 081 addSubtag(mTransform); 082 } 083 } 084 085 return mTransform; 086 } 087 088 //--------------------------------------------------------------------------- 089 /** 090 * Returns the preset geometry tag if one exists or else instantiates a new one. 091 * @return the preset geometry tag for this shape properties tag 092 */ 093 public DmlPresetGeometry getPresetGeometry() 094 { 095 if (null == mPresetGeometry) 096 { 097 // Check if it has been added via addSubtag()... 098 mPresetGeometry = getOptionalSubtagByName(DmlXML.PRESET_GEOMETRY); 099 if (null == mPresetGeometry) 100 { 101 mPresetGeometry = new DmlPresetGeometry(); 102 addSubtag(mPresetGeometry); 103 } 104 } 105 106 return mPresetGeometry; 107 } 108 109 110 //--------------------------------------------------------------------------- 111 /** 112 * Specifies the fill type that should be used for the shape. 113 */ 114 public DmlShapeProperties setFill(DmlFill inValue) 115 { 116 if (mFillTag != null) 117 { 118 removeSubtag(mFillTag); 119 } 120 121 mFillTag = inValue; 122 123 addSubtag(mFillTag); 124 125 return this; 126 } 127 128 //--------------------------------------------------------------------------- 129 /** 130 * Returns the line tag if one exists or else instantiates a new one. 131 * @return the line tag for this shape properties tag 132 */ 133 public DmlLine getLine() 134 { 135 if (null == mLine) 136 { 137 // Check if it has been added via addSubtag()... 138 mLine = getOptionalSubtagByName(DmlXML.LINE); 139 if (null == mLine) 140 { 141 mLine = new DmlLine(getParentDoc()); 142 addSubtag(mLine); 143 } 144 } 145 146 return mLine; 147 } 148 149}