001package com.hfg.xml.msofficexml.docx.wordprocessingml.style;
002
003
004import com.hfg.graphics.units.GfxSize;
005import com.hfg.graphics.units.GfxUnits;
006import com.hfg.graphics.ColorUtil;
007import com.hfg.xml.msofficexml.docx.Docx;
008import com.hfg.xml.msofficexml.docx.DocxException;
009import com.hfg.xml.msofficexml.docx.wordprocessingml.*;
010
011import java.awt.Color;
012
013//------------------------------------------------------------------------------
014/**
015 Represents an Office Open XML border tag.
016
017 @author J. Alex Taylor, hairyfatguy.com
018 */
019//------------------------------------------------------------------------------
020// com.hfg XML/HTML Coding Library
021//
022// This library is free software; you can redistribute it and/or
023// modify it under the terms of the GNU Lesser General Public
024// License as published by the Free Software Foundation; either
025// version 2.1 of the License, or (at your option) any later version.
026//
027// This library is distributed in the hope that it will be useful,
028// but WITHOUT ANY WARRANTY; without even the implied warranty of
029// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
030// Lesser General Public License for more details.
031//
032// You should have received a copy of the GNU Lesser General Public
033// License along with this library; if not, write to the Free Software
034// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
035//
036// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
037// jataylor@hairyfatguy.com
038//------------------------------------------------------------------------------
039
040public abstract class WmlBorder extends WmlXMLTag
041{
042   private WmlBorderPosition mPosition;
043
044   //---------------------------------------------------------------------------
045   public WmlBorder(WmlBorderPosition inPosition, Docx inDocx)
046   {
047      super(inPosition.getXMLName(), inDocx);
048      mPosition = inPosition;
049   }
050
051   //---------------------------------------------------------------------------
052   public WmlBorderPosition getPosition()
053   {
054      return mPosition;
055   }
056
057   //---------------------------------------------------------------------------
058   public WmlBorder setColor(Color inValue)
059   {
060      setAttribute(WmlXML.COLOR_ATT, ColorUtil.colorToHex(inValue));
061      return this;
062   }
063
064   //---------------------------------------------------------------------------
065   public WmlBorder setAutoColor()
066   {
067      setAttribute(WmlXML.COLOR_ATT, "auto");
068      return this;
069   }
070
071   //---------------------------------------------------------------------------
072   /**
073    * Specifies the width of the border in eighths of a point, with a minimum value
074    * of 1/4 of a point and a maximum value of twelve points.
075    * @param inValue width of the border
076    */
077   public WmlBorder setSize(GfxSize inValue)
078   {
079      int eighthOfAPointValue = (int) (inValue.to(GfxUnits.points) * 8);
080      if (eighthOfAPointValue < 2)
081      {
082         throw new DocxException("The border size must be between 1/4 to 12 points!");
083      }
084
085      setAttribute(WmlXML.SIZE_ATT, eighthOfAPointValue);
086      return this;
087   }
088
089   //---------------------------------------------------------------------------
090   /**
091    * The padding (in points) between the text and the border.
092    * @param inValue padding (in points)
093    */
094   public WmlBorder setSpace(GfxSize inValue)
095   {
096      setAttribute(WmlXML.SPACE_ATT, inValue.to(GfxUnits.points));
097      return this;
098   }
099
100   //---------------------------------------------------------------------------
101   /**
102    * Whether or not to add a shadow to the border.
103    * @param inValue whether or not to add a shadow to the border
104    */
105   public WmlBorder setShadow(boolean inValue)
106   {
107      setAttribute(WmlXML.SHADOW_ATT, inValue);
108      return this;
109   }
110
111   //---------------------------------------------------------------------------
112   /**
113    * Whether or not to create a frame effect for the border.
114    * @param inValue whether or not to create a frame effect for the border
115    */
116   public WmlBorder setFrame(boolean inValue)
117   {
118      setAttribute(WmlXML.FRAME_ATT, inValue);
119      return this;
120   }
121
122}