All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.xml.msofficexml.xlsx.spreadsheetDrawing.SsDrawShapeProperties Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.xml.msofficexml.xlsx.spreadsheetDrawing;


import java.awt.*;

import com.hfg.xml.XMLTag;
import com.hfg.xml.msofficexml.OfficeOpenXMLTag;
import com.hfg.xml.msofficexml.OfficeOpenXmlDocument;
import com.hfg.xml.msofficexml.docx.drawingml.DmlBlackWhiteMode;
import com.hfg.xml.msofficexml.docx.drawingml.DmlPresetGeometry;
import com.hfg.xml.msofficexml.docx.drawingml.DmlTransform;
import com.hfg.xml.msofficexml.docx.drawingml.DmlXML;
import com.hfg.xml.msofficexml.docx.drawingml.fill.DmlFill;
import com.hfg.xml.msofficexml.docx.drawingml.fill.DmlSolidFill;
import com.hfg.xml.msofficexml.docx.drawingml.line.DmlLine;

public class SsDrawShapeProperties extends OfficeOpenXMLTag
{
   private DmlTransform      mTransform;
   private DmlPresetGeometry mPresetGeometry;
   private XMLTag            mFillTag;
   private DmlLine mLine;

   //---------------------------------------------------------------------------
   public SsDrawShapeProperties(OfficeOpenXmlDocument inParentDoc)
   {
      super(SsDrawXML.SHAPE_PROPS, inParentDoc);
      init();
   }

   //---------------------------------------------------------------------------
   private void init()
   {
      setBWMode(DmlBlackWhiteMode.auto);
      getOrCreateTransform();
   }

   //---------------------------------------------------------------------------
   public SsDrawShapeProperties setBWMode(DmlBlackWhiteMode inValue)
   {
      setAttribute(DmlXML.BLACK_WHITE_MODE_ATT, inValue.name());
      return this;
   }


   //---------------------------------------------------------------------------
   /**
    * Returns the transform tag if one exists or else instantiates a new one.
    * @return the transform tag for this shape properties 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 preset geometry tag if one exists or else instantiates a new one.
    * @return the preset geometry tag for this shape properties tag
    */
   public DmlPresetGeometry getOrCreatePresetGeometry()
   {
      if (null == mPresetGeometry)
      {
         // Check if it has been added via addSubtag()...
         mPresetGeometry = getOptionalSubtagByName(DmlXML.PRESET_GEOMETRY);
         if (null == mPresetGeometry)
         {
            mPresetGeometry = new DmlPresetGeometry();
            addSubtag(mPresetGeometry);
         }
      }

      return mPresetGeometry;
   }


   //---------------------------------------------------------------------------
   /**
    * Specifies the fill type that should be used for the shape.
    */
   public SsDrawShapeProperties setFill(DmlFill inValue)
   {
      if (mFillTag != null)
      {
         removeSubtag(mFillTag);
      }

      mFillTag = inValue;

      addSubtag(mFillTag);

      return this;
   }

   //---------------------------------------------------------------------------
   /**
    * Specifies the color for a solid fill to be used for the shape.
    */
   public SsDrawShapeProperties setFill(Color inColor)
   {
      if (mFillTag != null)
      {
         removeSubtag(mFillTag);
      }

      mFillTag = new DmlSolidFill(inColor);

      addSubtag(mFillTag);

      return this;
   }

   //---------------------------------------------------------------------------
   /**
    * Returns the line tag if one exists or else instantiates a new one.
    * @return the line tag for this shape properties tag
    */
   public DmlLine getOrCreateLine()
   {
      if (null == mLine)
      {
         // Check if it has been added via addSubtag()...
         mLine = getOptionalSubtagByName(DmlXML.LINE);
         if (null == mLine)
         {
            mLine = new DmlLine(getParentDoc());
            addSubtag(mLine);
         }
      }

      return mLine;
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy