001package com.hfg.xml.msofficexml.docx.wordprocessingml;
002
003import com.hfg.graphics.units.GfxSize;
004import com.hfg.graphics.units.GfxUnits;
005import com.hfg.xml.XMLTag;
006import com.hfg.xml.msofficexml.docx.Docx;
007import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlJustification;
008import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlParagraphStyle;
009import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlShading;
010
011
012//------------------------------------------------------------------------------
013/**
014 Represents an Office Open XML table row properties (<w:trPr>) tag.
015 <div>
016 @author J. Alex Taylor, hairyfatguy.com
017 </div>
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 class WmlTableRowProperties extends WmlXMLTag
041{
042   private XMLTag              mStyle;
043   private XMLTag              mHeightTag;
044   private XMLTag              mJustificationTag;
045   private XMLTag              mCantSplitTag;
046   private XMLTag              mTableHeaderTag;
047   private WmlShading mShadingTag;
048
049   //---------------------------------------------------------------------------
050   public WmlTableRowProperties(Docx inDocx)
051   {
052      super(WmlXML.TABLE_ROW_PROPS, inDocx);
053   }
054
055   //---------------------------------------------------------------------------
056   public WmlTableRowProperties setStyle(String inStyleId)
057   {
058      if (null == mStyle)
059      {
060         mStyle = new WmlParagraphStyle(getParentDoc());
061         addSubtag(mStyle);
062      }
063
064      mStyle.setAttribute(WmlXML.STYLE_ID_ATT, inStyleId);
065
066      return this;
067   }
068
069   //---------------------------------------------------------------------------
070   /**
071    Specifies that the table row should determine its height based on contents.
072    @return this properties object to enable method chaining.
073    */
074   public WmlTableRowProperties setAutoHeight()
075   {
076      XMLTag heightTag = getHeightTag();
077
078      heightTag.setAttribute(WmlXML.HEIGHT_RULE_ATT, "auto");
079      heightTag.removeAttribute(WmlXML.VALUE_ATT);
080
081      return this;
082   }
083
084   //---------------------------------------------------------------------------
085   public WmlTableRowProperties setAtLeastHeight(GfxSize inValue)
086   {
087      XMLTag heightTag = getHeightTag();
088
089      heightTag.setAttribute(WmlXML.HEIGHT_RULE_ATT, "atLeast");
090      heightTag.setAttribute(WmlXML.VALUE_ATT, inValue.toInt(GfxUnits.dxa));
091
092      return this;
093   }
094
095   //---------------------------------------------------------------------------
096   public WmlTableRowProperties setExactHeight(GfxSize inValue)
097   {
098      XMLTag heightTag = getHeightTag();
099
100      heightTag.setAttribute(WmlXML.HEIGHT_RULE_ATT, "exact");
101      heightTag.setAttribute(WmlXML.VALUE_ATT, inValue.toInt(GfxUnits.dxa));
102
103      return this;
104   }
105
106   //---------------------------------------------------------------------------
107   public WmlTableRowProperties setJustification(WmlJustification inValue)
108   {
109      if (null == mJustificationTag)
110      {
111         // Check it it has been added via addSubtag()...
112         mJustificationTag = getOptionalSubtagByName(WmlXML.JUSTIFICATION);
113         if (null == mJustificationTag)
114         {
115            mJustificationTag = new XMLTag(WmlXML.JUSTIFICATION);
116            addSubtag(mJustificationTag);
117         }
118      }
119
120      mJustificationTag.setAttribute(WmlXML.VALUE_ATT, inValue);
121
122      return this;
123   }
124
125   //---------------------------------------------------------------------------
126   /**
127    Repeat Table Row on Every New Page.
128    */
129   public WmlTableRowProperties setTableHeader(boolean inValue)
130   {
131      if (null == mTableHeaderTag)
132      {
133         // Check if it has been added via addSubtag()...
134         mTableHeaderTag = getOptionalSubtagByName(WmlXML.TABLE_HEADER);
135         if (null == mTableHeaderTag)
136         {
137            mTableHeaderTag = new XMLTag(WmlXML.TABLE_HEADER);
138            addSubtag(mTableHeaderTag);
139         }
140      }
141
142      mTableHeaderTag.setAttribute(WmlXML.VALUE_ATT, inValue);
143
144      return this;
145   }
146
147   //---------------------------------------------------------------------------
148   /**
149    * Specifies that this table row should not be separated by a page break from the row that follows it.
150    */
151   public WmlTableRowProperties setCantSplit()
152   {
153      if (null == mCantSplitTag)
154      {
155         // Check if it has been added via addSubtag()...
156         mCantSplitTag = getOptionalSubtagByName(WmlXML.CANT_SPLIT);
157         if (null == mCantSplitTag)
158         {
159            mCantSplitTag = new XMLTag(WmlXML.CANT_SPLIT);
160            addSubtag(mCantSplitTag);
161         }
162      }
163
164      return this;
165   }
166
167   //---------------------------------------------------------------------------
168   public WmlShading getShading()
169   {
170      if (null == mShadingTag)
171      {
172         // Check if it has been added via addSubtag()...
173         mShadingTag = getOptionalSubtagByName(WmlXML.SHADING);
174         if (null == mShadingTag)
175         {
176            mShadingTag = new WmlShading();
177            addSubtag(mShadingTag);
178         }
179      }
180
181      return mShadingTag;
182   }
183
184   //---------------------------------------------------------------------------
185   private XMLTag getHeightTag()
186   {
187      if (null == mHeightTag)
188      {
189         // Check if it has been added via addSubtag()...
190         mHeightTag = getOptionalSubtagByName(WmlXML.TABLE_ROW_HEIGHT);
191         if (null == mHeightTag)
192         {
193            mHeightTag = new XMLTag(WmlXML.TABLE_ROW_HEIGHT);
194            addSubtag(mHeightTag);
195         }
196      }
197
198      return mHeightTag;
199   }
200
201}
202