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.xml.XMLName;
007import com.hfg.xml.XMLTag;
008import com.hfg.xml.msofficexml.docx.wordprocessingml.WmlXML;
009
010import java.util.ArrayList;
011import java.util.List;
012
013public class WmlTableCellMargin
014{
015   private Position     mPosition;
016   private GfxSize      mWidth;
017
018
019   public static enum Position {
020      top,
021      bottom,
022//      start,
023//      end
024      left,
025      right
026   }
027
028
029   //---------------------------------------------------------------------------
030   public WmlTableCellMargin()
031   {
032   }
033
034   //---------------------------------------------------------------------------
035   public WmlTableCellMargin(Position inPosition)
036   {
037      setPosition(inPosition);
038   }
039
040   //---------------------------------------------------------------------------
041   public WmlTableCellMargin(GfxSize inWidth)
042   {
043      setWidth(inWidth);
044   }
045
046   //---------------------------------------------------------------------------
047   public WmlTableCellMargin(Position inPosition, GfxSize inWidth)
048   {
049      setPosition(inPosition);
050      setWidth(inWidth);
051   }
052
053
054   //---------------------------------------------------------------------------
055   /**
056    * If a position is not specified via this method, a complete border set (top, end, bottom, and start) will be generated.
057    * @param inValue the border position
058    */
059   public WmlTableCellMargin setPosition(Position inValue)
060   {
061      mPosition = inValue;
062      return this;
063   }
064
065   //---------------------------------------------------------------------------
066   public WmlTableCellMargin setWidth(GfxSize inValue)
067   {
068      mWidth = inValue;
069      return this;
070   }
071
072   //---------------------------------------------------------------------------
073   public List<XMLTag> toXMLTags()
074   {
075      List<XMLTag> tags = new ArrayList<XMLTag>(4);
076
077      List<Position> positions =  new ArrayList<Position>(4);
078      if (mPosition != null)
079      {
080         positions.add(mPosition);
081      }
082      else
083      {
084         positions.add(Position.top);
085         positions.add(Position.right);
086         positions.add(Position.bottom);
087         positions.add(Position.left);
088      }
089
090      for (Position position : positions)
091      {
092         XMLTag tag = new XMLTag(new XMLName(position.name(), WmlXML.WORDPROCESSINGML_NAMESPACE));
093
094         if (mWidth != null)
095         {
096            tag.setAttribute(WmlXML.WIDTH_ATT, mWidth.toInt(GfxUnits.dxa));
097            tag.setAttribute(WmlXML.TYPE_ATT, GfxUnits.dxa.name());
098         }
099
100         tags.add(tag);
101      }
102
103      return tags;
104   }
105}
106