001package com.hfg.xml.msofficexml.xlsx.spreadsheetDrawing;
002
003
004import java.awt.*;
005
006import com.hfg.xml.XMLTag;
007import com.hfg.xml.msofficexml.OfficeOpenXMLTag;
008import com.hfg.xml.msofficexml.OfficeOpenXmlDocument;
009import com.hfg.xml.msofficexml.docx.drawingml.DmlBlackWhiteMode;
010import com.hfg.xml.msofficexml.docx.drawingml.DmlPresetGeometry;
011import com.hfg.xml.msofficexml.docx.drawingml.DmlTransform;
012import com.hfg.xml.msofficexml.docx.drawingml.DmlXML;
013import com.hfg.xml.msofficexml.docx.drawingml.fill.DmlFill;
014import com.hfg.xml.msofficexml.docx.drawingml.fill.DmlSolidFill;
015import com.hfg.xml.msofficexml.docx.drawingml.line.DmlLine;
016
017public class SsDrawShapeProperties extends OfficeOpenXMLTag
018{
019   private DmlTransform      mTransform;
020   private DmlPresetGeometry mPresetGeometry;
021   private XMLTag            mFillTag;
022   private DmlLine mLine;
023
024   //---------------------------------------------------------------------------
025   public SsDrawShapeProperties(OfficeOpenXmlDocument inParentDoc)
026   {
027      super(SsDrawXML.SHAPE_PROPS, inParentDoc);
028      init();
029   }
030
031   //---------------------------------------------------------------------------
032   private void init()
033   {
034      setBWMode(DmlBlackWhiteMode.auto);
035      getOrCreateTransform();
036   }
037
038   //---------------------------------------------------------------------------
039   public SsDrawShapeProperties setBWMode(DmlBlackWhiteMode inValue)
040   {
041      setAttribute(DmlXML.BLACK_WHITE_MODE_ATT, inValue.name());
042      return this;
043   }
044
045
046   //---------------------------------------------------------------------------
047   /**
048    * Returns the transform tag if one exists or else instantiates a new one.
049    * @return the transform tag for this shape properties tag
050    */
051   public DmlTransform getOrCreateTransform()
052   {
053      if (null == mTransform)
054      {
055         // Check if it has been added via addSubtag()...
056         mTransform = getOptionalSubtagByName(DmlXML.TRANSFORM_2D);
057         if (null == mTransform)
058         {
059            mTransform = new DmlTransform();
060            addSubtag(mTransform);
061         }
062      }
063
064      return mTransform;
065   }
066
067   //---------------------------------------------------------------------------
068   /**
069    * Returns the preset geometry tag if one exists or else instantiates a new one.
070    * @return the preset geometry tag for this shape properties tag
071    */
072   public DmlPresetGeometry getOrCreatePresetGeometry()
073   {
074      if (null == mPresetGeometry)
075      {
076         // Check if it has been added via addSubtag()...
077         mPresetGeometry = getOptionalSubtagByName(DmlXML.PRESET_GEOMETRY);
078         if (null == mPresetGeometry)
079         {
080            mPresetGeometry = new DmlPresetGeometry();
081            addSubtag(mPresetGeometry);
082         }
083      }
084
085      return mPresetGeometry;
086   }
087
088
089   //---------------------------------------------------------------------------
090   /**
091    * Specifies the fill type that should be used for the shape.
092    */
093   public SsDrawShapeProperties setFill(DmlFill inValue)
094   {
095      if (mFillTag != null)
096      {
097         removeSubtag(mFillTag);
098      }
099
100      mFillTag = inValue;
101
102      addSubtag(mFillTag);
103
104      return this;
105   }
106
107   //---------------------------------------------------------------------------
108   /**
109    * Specifies the color for a solid fill to be used for the shape.
110    */
111   public SsDrawShapeProperties setFill(Color inColor)
112   {
113      if (mFillTag != null)
114      {
115         removeSubtag(mFillTag);
116      }
117
118      mFillTag = new DmlSolidFill(inColor);
119
120      addSubtag(mFillTag);
121
122      return this;
123   }
124
125   //---------------------------------------------------------------------------
126   /**
127    * Returns the line tag if one exists or else instantiates a new one.
128    * @return the line tag for this shape properties tag
129    */
130   public DmlLine getOrCreateLine()
131   {
132      if (null == mLine)
133      {
134         // Check if it has been added via addSubtag()...
135         mLine = getOptionalSubtagByName(DmlXML.LINE);
136         if (null == mLine)
137         {
138            mLine = new DmlLine(getParentDoc());
139            addSubtag(mLine);
140         }
141      }
142
143      return mLine;
144   }
145
146}