001package com.hfg.xml.msofficexml.docx.wordprocessingml;
002
003
004import com.hfg.graphics.units.GfxSize;
005import com.hfg.graphics.units.GfxUnits;
006import com.hfg.graphics.units.Twips;
007import com.hfg.util.StringUtil;
008import com.hfg.xml.msofficexml.docx.Docx;
009
010//------------------------------------------------------------------------------
011/**
012 Represents an Office Open XML tab (<w:tab>) tag.
013 <div>
014 Reference: ECMA-376, 3rd Edition (June, 2011), Fundamentals and Markup Language Reference § 17.3.1.37 and § 17.3.1.38
015 </div>
016 <div>
017 @author J. Alex Taylor, hairyfatguy.com
018 </div>
019 */
020//------------------------------------------------------------------------------
021// com.hfg XML/HTML Coding Library
022//
023// This library is free software; you can redistribute it and/or
024// modify it under the terms of the GNU Lesser General Public
025// License as published by the Free Software Foundation; either
026// version 2.1 of the License, or (at your option) any later version.
027//
028// This library is distributed in the hope that it will be useful,
029// but WITHOUT ANY WARRANTY; without even the implied warranty of
030// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
031// Lesser General Public License for more details.
032//
033// You should have received a copy of the GNU Lesser General Public
034// License along with this library; if not, write to the Free Software
035// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
036//
037// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
038// jataylor@hairyfatguy.com
039//------------------------------------------------------------------------------
040
041public class WmlTab extends WmlXMLTag
042{
043   //##########################################################################
044   // CONSTRUCTORS
045   //##########################################################################
046
047   //---------------------------------------------------------------------------
048   public WmlTab(Docx inDocx)
049   {
050      super(WmlXML.TAB, inDocx);
051   }
052
053   //##########################################################################
054   // PUBLIC METHODS
055   //##########################################################################
056
057   //---------------------------------------------------------------------------
058   /**
059    Specifies the position of the tab.
060    * @param inValue position specified in arbitrary units
061    * @return this tab object to enable method chaining.
062    */
063   public WmlTab setPosition(GfxSize inValue)
064   {
065      setAttribute(WmlXML.POSITION_ATT, inValue.toInt(GfxUnits.dxa));
066      return this;
067   }
068
069   //---------------------------------------------------------------------------
070   public GfxSize getPosition()
071   {
072      String stringValue = getAttributeValue(WmlXML.POSITION_ATT);
073      GfxSize width =  null;
074      if (StringUtil.isSet(stringValue))
075      {
076         width = new Twips(Integer.parseInt(stringValue));
077      }
078
079      return width;
080   }
081
082   //---------------------------------------------------------------------------
083   /**
084    Specifies the character used to fill in the space created by the tab. Optional.
085    Defaults to 'none'.
086    * @param inValue a WmlTabLeader value
087    * @return this tab object to enable method chaining.
088    */
089   public WmlTab setTabLeader(WmlTabLeader inValue)
090   {
091      if (inValue != null)
092      {
093         setAttribute(WmlXML.LEADER_ATT, inValue.name());
094      }
095      else
096      {
097         removeAttribute(WmlXML.LEADER_ATT);
098      }
099
100      return this;
101   }
102
103   //---------------------------------------------------------------------------
104   public WmlTabLeader getTabLeader()
105   {
106      String stringValue = getAttributeValue(WmlXML.LEADER_ATT);
107      WmlTabLeader tabLeader =  null;
108      if (StringUtil.isSet(stringValue))
109      {
110         tabLeader = WmlTabLeader.valueOf(stringValue);
111      }
112
113      return tabLeader;
114   }
115
116   //---------------------------------------------------------------------------
117   /**
118    Specifies the style for the tab.
119    * @param inValue a WmlTabStyle value
120    * @return this tab object to enable method chaining.
121    */
122   public WmlTab setTabStyle(WmlTabStyle inValue)
123   {
124      if (inValue != null)
125      {
126         setAttribute(WmlXML.VALUE_ATT, inValue.name());
127      }
128      else
129      {
130         removeAttribute(WmlXML.VALUE_ATT);
131      }
132
133      return this;
134   }
135
136   //---------------------------------------------------------------------------
137   public WmlTabStyle getTabStyle()
138   {
139      String stringValue = getAttributeValue(WmlXML.VALUE_ATT);
140      WmlTabStyle tabStyle =  null;
141      if (StringUtil.isSet(stringValue))
142      {
143         tabStyle = WmlTabStyle.valueOf(stringValue);
144      }
145
146      return tabStyle;
147   }
148
149}