001package com.hfg.xml.msofficexml.docx.wordprocessingml; 002 003// Section 17.4 (pg. 364) of Ecma Office Open XML Part 1 004 005import com.hfg.graphics.units.GfxSize; 006import com.hfg.graphics.units.GfxUnits; 007import com.hfg.xml.XMLTag; 008import com.hfg.xml.msofficexml.docx.Docx; 009 010import java.util.ArrayList; 011import java.util.List; 012 013public class WmlTable extends WmlXMLTag 014{ 015 private WmlTableProperties mTableProps; 016 private XMLTag mTableGrid; 017 018 //--------------------------------------------------------------------------- 019 public WmlTable(Docx inDocx) 020 { 021 super(WmlXML.TABLE, inDocx); 022 } 023 024 //--------------------------------------------------------------------------- 025 /** 026 * Returns the table properties tag if one exists or else instantiates a new one. 027 * @return the table properties for this table 028 */ 029 public WmlTableProperties getTableProperties() 030 { 031 if (null == mTableProps) 032 { 033 // Check it it has been added via addSubtag()... 034 mTableProps = (WmlTableProperties) getOptionalSubtagByName(WmlXML.TABLE_PROPS); 035 if (null == mTableProps) 036 { 037 mTableProps = new WmlTableProperties(); 038 addSubtag(mTableProps); 039 } 040 } 041 042 return mTableProps; 043 } 044 045 //--------------------------------------------------------------------------- 046 public WmlTable defineColumn(GfxSize inSize) 047 { 048 if (null == mTableGrid) 049 { 050 mTableGrid = new XMLTag(WmlXML.TABLE_GRID); 051 addSubtag(mTableGrid); 052 } 053 054 XMLTag colTag = new XMLTag(WmlXML.GRID_COL); 055 colTag.setAttribute(WmlXML.WIDTH_ATT, inSize.toInt(GfxUnits.dxa)); 056 mTableGrid.addSubtag(colTag); 057 058 return this; 059 } 060 061 //--------------------------------------------------------------------------- 062 /** 063 * Generates a new table row. 064 */ 065 public WmlTableRow addRow() 066 { 067 WmlTableRow row = new WmlTableRow(getParentDoc()); 068 addSubtag(row); 069 070 return row; 071 } 072 073 //--------------------------------------------------------------------------- 074 /** 075 * Returns the table rows. 076 */ 077 public List<WmlTableRow> getRows() 078 { 079 return getSubtagsByName(WmlXML.TABLE_ROW); 080 } 081}