001package com.hfg.xml.msofficexml.docx.wordprocessingml.style;
002
003
004import java.awt.Color;
005
006import com.hfg.graphics.ColorSpec;
007import com.hfg.graphics.ColorUtil;
008import com.hfg.util.StringUtil;
009import com.hfg.xml.XMLTag;
010import com.hfg.xml.msofficexml.docx.wordprocessingml.WmlXML;
011
012
013public class WmlShading extends XMLTag
014{
015   public enum ShadingValue
016   {
017      clear
018   }
019
020   //---------------------------------------------------------------------------
021   public WmlShading()
022   {
023      super(WmlXML.SHADING);
024   }
025
026   //---------------------------------------------------------------------------
027   public WmlShading setValue(ShadingValue inValue)
028   {
029      setAttribute(WmlXML.VALUE_ATT, inValue);
030      return this;
031   }
032
033   //---------------------------------------------------------------------------
034   public WmlShading setPctValue(int inValue)
035   {
036      if (inValue < 0
037          || inValue > 100)
038      {
039         throw new RuntimeException("The percent value " + StringUtil.singleQuote(inValue + "") + " is not in the allowed range of 0-100!");
040      }
041
042      setAttribute(WmlXML.VALUE_ATT, "pct" + inValue);
043      return this;
044   }
045
046   //---------------------------------------------------------------------------
047   /**
048    Convenience method for setting both the color and the fill.
049    */
050   public WmlShading setColorSpec(ColorSpec inValue)
051   {
052      if (inValue.getForegroundColor() != null)
053      {
054         setColor(inValue.getForegroundColor());
055      }
056
057      if (inValue.getBackgroundColor() != null)
058      {
059         setFill(inValue.getBackgroundColor());
060      }
061
062      return this;
063   }
064
065   //---------------------------------------------------------------------------
066   public WmlShading setColor(Color inValue)
067   {
068      setAttribute(WmlXML.COLOR_ATT, ColorUtil.colorToHex(inValue));
069      return this;
070   }
071
072   //---------------------------------------------------------------------------
073   public WmlShading setAutoColor()
074   {
075      setAttribute(WmlXML.COLOR_ATT, "auto");
076      return this;
077   }
078
079   //---------------------------------------------------------------------------
080   public WmlShading setFill(Color inValue)
081   {
082      setAttribute(WmlXML.FILL_ATT, ColorUtil.colorToHex(inValue));
083      return this;
084   }
085
086   //---------------------------------------------------------------------------
087   public WmlShading setThemeFill(String inValue)
088   {
089      setAttribute(WmlXML.THEME_FILL_ATT, inValue);
090      return this;
091   }
092
093}