You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by sa...@apache.org on 2004/03/02 07:22:29 UTC

cvs commit: jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel DropCapSpecifier.java List.java ListEntry.java Range.java Table.java TableCell.java TableIterator.java TableRow.java

sackley     2004/03/01 22:22:29

  Added:       src/scratchpad/src/org/apache/poi/hwpf/usermodel
                        DropCapSpecifier.java List.java ListEntry.java
                        Range.java Table.java TableCell.java
                        TableIterator.java TableRow.java
  Log:
  latest changes
  
  Revision  Changes    Path
  1.1                  jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java
  
  Index: DropCapSpecifier.java
  ===================================================================
  package org.apache.poi.hwpf.usermodel;
  
  import org.apache.poi.util.BitField;
  import org.apache.poi.util.LittleEndian;
  
  public class DropCapSpecifier
  {
    private short _info;
      private static BitField _type = new BitField(0x07);
      private static BitField _lines = new BitField(0xf8);
  
    public DropCapSpecifier(byte[] buf, int offset)
    {
      this(LittleEndian.getShort(buf, offset));
    }
  
    public DropCapSpecifier(short info)
    {
      _info = info;
    }
  
    public short toShort()
    {
      return _info;
    }
  }
  
  
  
  1.1                  jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/List.java
  
  Index: List.java
  ===================================================================
  package org.apache.poi.hwpf.usermodel;
  
  import org.apache.poi.hwpf.HWPFDocument;
  import org.apache.poi.hwpf.model.ListTables;
  import org.apache.poi.hwpf.model.ListLevel;
  import org.apache.poi.hwpf.model.ListData;
  import org.apache.poi.hwpf.model.ListFormatOverride;
  import org.apache.poi.hwpf.model.StyleSheet;
  
  import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
  import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
  
  
  public class List
  {
    private ListData _listData;
    private ListFormatOverride _override;
    private boolean _registered;
    private StyleSheet _styleSheet;
  
    public List(boolean numbered, StyleSheet styleSheet)
    {
      _listData = new ListData((int)(Math.random() * (double)System.currentTimeMillis()), numbered);
      _override = new ListFormatOverride(_listData.getLsid());
      _styleSheet = styleSheet;
    }
  
    public void setLevelNumberProperties(int level, CharacterProperties chp)
    {
      ListLevel listLevel = _listData.getLevel(level);
      int styleIndex = _listData.getLevelStyle(level);
      CharacterProperties base = _styleSheet.getCharacterStyle(styleIndex);
  
      byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(chp, base);
      listLevel.setNumberProperties(grpprl);
    }
  
    public void setLevelParagraphProperties(int level, ParagraphProperties pap)
    {
      ListLevel listLevel = _listData.getLevel(level);
      int styleIndex = _listData.getLevelStyle(level);
      ParagraphProperties base = _styleSheet.getParagraphStyle(styleIndex);
  
      byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(pap, base);
      listLevel.setLevelProperties(grpprl);
    }
  
    public void setLevelStyle(int level, int styleIndex)
    {
      _listData.setLevelStyle(level, styleIndex);
    }
  
    public ListData getListData()
    {
      return _listData;
    }
  
    public ListFormatOverride getOverride()
    {
      return _override;
    }
  
  }
  
  
  
  1.1                  jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java
  
  Index: ListEntry.java
  ===================================================================
  package org.apache.poi.hwpf.usermodel;
  
  import org.apache.poi.hwpf.model.ListFormatOverride;
  import org.apache.poi.hwpf.model.ListFormatOverrideLevel;
  import org.apache.poi.hwpf.model.ListLevel;
  import org.apache.poi.hwpf.model.ListTables;
  
  import org.apache.poi.hwpf.sprm.SprmBuffer;
  
  public class ListEntry
    extends Paragraph
  {
    ListLevel _level;
    ListFormatOverrideLevel _overrideLevel;
  
    ListEntry(int start, int end, ListTables tables,
                     ParagraphProperties pap, SprmBuffer sprmBuf, Range parent)
    {
      super(start, end, pap, sprmBuf, parent);
      ListFormatOverride override = tables.getOverride(pap.getIlfo());
      _overrideLevel = override.getOverrideLevel(pap.getIlvl());
      _level = tables.getLevel(override.getLsid(), pap.getIlvl());
    }
  }
  
  
  
  1.1                  jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
  
  Index: Range.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache POI" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache POI", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.poi.hwpf.usermodel;
  
  
  import org.apache.poi.util.LittleEndian;
  
  import org.apache.poi.hwpf.HWPFDocument;
  
  import org.apache.poi.hwpf.usermodel.CharacterRun;
  import org.apache.poi.hwpf.usermodel.Paragraph;
  import org.apache.poi.hwpf.usermodel.ParagraphProperties;
  import org.apache.poi.hwpf.usermodel.Section;
  
  import org.apache.poi.hwpf.model.PropertyNode;
  import org.apache.poi.hwpf.model.StyleSheet;
  import org.apache.poi.hwpf.model.StyleDescription;
  import org.apache.poi.hwpf.model.CHPBinTable;
  import org.apache.poi.hwpf.model.CHPX;
  import org.apache.poi.hwpf.model.PAPX;
  import org.apache.poi.hwpf.model.SEPX;
  import org.apache.poi.hwpf.model.PAPBinTable;
  import org.apache.poi.hwpf.model.SectionTable;
  import org.apache.poi.hwpf.model.TextPieceTable;
  import org.apache.poi.hwpf.model.TextPiece;
  import org.apache.poi.hwpf.model.ListTables;
  
  import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor;
  import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
  import org.apache.poi.hwpf.sprm.SectionSprmUncompressor;
  import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
  import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
  import org.apache.poi.hwpf.sprm.SprmBuffer;
  
  
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import java.io.UnsupportedEncodingException;
  import java.lang.ref.WeakReference;
  
  public class Range
  {
  
    public static final int PARAGRAPH_INDEX = 0;
    public static final int CHARACTER_INDEX = 1;
    public static final int SECTION_INDEX = 2;
    public static final int TEXT_INDEX = 3;
  
    private WeakReference _parent;
    protected int _start;
    protected int _end;
    protected HWPFDocument _doc;
    boolean _sectionRangeFound;
    protected List _sections;
    int _sectionStart;
    int _sectionEnd;
    boolean _parRangeFound;
    protected List _paragraphs;
    protected int _parStart;
    protected int _parEnd;
    boolean _charRangeFound;
    protected List _characters;
    int _charStart;
    int _charEnd;
    boolean _textRangeFound;
    protected List _text;
    int _textStart;
    int _textEnd;
  
  
  //  protected Range()
  //  {
  //
  //  }
  
    public Range(int start, int end, HWPFDocument doc)
    {
      _start = start;
      _end = end;
      _doc = doc;
      _sections = _doc.getSectionTable().getSections();
      _paragraphs = _doc.getParagraphTable().getParagraphs();
      _characters = _doc.getCharacterTable().getTextRuns();
      _text = _doc.getTextTable().getTextPieces();
      _parent = new WeakReference(null);
    }
  
    protected Range(int start, int end, Range parent)
    {
      _start = start;
      _end = end;
      _doc = parent._doc;
      _sections = parent._sections;
      _paragraphs = parent._paragraphs;
      _characters = parent._characters;
      _text = parent._text;
      _parent = new WeakReference(parent);
    }
  
    protected Range(int startIdx, int endIdx, int idxType, Range parent)
    {
      _doc = parent._doc;
      _sections = parent._sections;
      _paragraphs = parent._paragraphs;
      _characters = parent._characters;
      _text = parent._text;
      _parent = new WeakReference(parent);
  
      switch (idxType)
      {
        case PARAGRAPH_INDEX:
          _parStart = parent._parStart + startIdx;
          _parEnd = parent._parStart + endIdx;
          _start = ((PropertyNode)_paragraphs.get(_parStart)).getStart();
          _end = ((PropertyNode)_paragraphs.get(_parEnd)).getEnd();
          _parRangeFound = true;
          break;
        case CHARACTER_INDEX:
          _charStart = parent._charStart + startIdx;
          _charEnd = parent._charStart + endIdx;
          _start = ((PropertyNode)_characters.get(_charStart)).getStart();
          _end = ((PropertyNode)_characters.get(_charEnd)).getEnd();
          _charRangeFound = true;
          break;
       case SECTION_INDEX:
          _sectionStart = parent._sectionStart + startIdx;
          _sectionEnd = parent._sectionStart + endIdx;
          _start = ((PropertyNode)_sections.get(_sectionStart)).getStart();
          _end = ((PropertyNode)_sections.get(_sectionEnd)).getEnd();
          _sectionRangeFound = true;
          break;
       case TEXT_INDEX:
          _textStart = parent._textStart + startIdx;
          _textEnd = parent._textStart + endIdx;
          _start = ((PropertyNode)_text.get(_textStart)).getStart();
          _end = ((PropertyNode)_text.get(_textEnd)).getEnd();
          _textRangeFound = true;
          break;
      }
    }
  
    public String text()
    {
      initText();
  
      StringBuffer sb = new StringBuffer();
  
      for (int x = _textStart; x < _textEnd; x++)
      {
        TextPiece piece = (TextPiece)_text.get(x);
        int start = _start > piece.getStart() ? _start - piece.getStart() : 0;
        int end = _end <= piece.getEnd() ? _end - piece.getStart() : piece.getEnd() - piece.getStart();
        sb.append(piece.getStringBuffer().substring(start, end));
      }
      return sb.toString();
    }
  
    public int numSections()
    {
      initSections();
      return _sectionEnd - _sectionStart;
    }
  
    public int numParagraphs()
    {
      initParagraphs();
      return _parEnd - _parStart;
    }
  
    public int numCharacterRuns()
    {
      initCharacterRuns();
      return _charEnd - _charStart;
    }
  
    public CharacterRun insertBefore(String text)
      //throws UnsupportedEncodingException
    {
      initAll();
  
      TextPiece tp = (TextPiece)_text.get(_textStart);
      StringBuffer sb = (StringBuffer)tp.getStringBuffer();
  
      // Since this is the first item in our list, it is safe to assume that
      // _start >= tp.getStart()
      int insertIndex = _start - tp.getStart();
      sb.insert(insertIndex, text);
      int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length());
      _doc.getCharacterTable().adjustForInsert(_textStart, adjustedLength);
      _doc.getParagraphTable().adjustForInsert(_textStart, adjustedLength);
      _doc.getSectionTable().adjustForInsert(_textStart, adjustedLength);
      adjustForInsert(text.length());
  
      return getCharacterRun(0);
    }
  
    public CharacterRun insertAfter(String text)
    {
      initAll();
      int listIndex = _textEnd - 1;
      TextPiece tp = (TextPiece)_text.get(listIndex);
      StringBuffer sb = (StringBuffer)tp.getStringBuffer();
  
      int insertIndex = _end - tp.getStart();
      sb.insert(insertIndex, text);
      int adjustedLength = _doc.getTextTable().adjustForInsert(listIndex, text.length());
      _doc.getCharacterTable().adjustForInsert(_charEnd - 1, adjustedLength);
      _doc.getParagraphTable().adjustForInsert(_parEnd - 1, adjustedLength);
      _doc.getSectionTable().adjustForInsert(_sectionEnd - 1, adjustedLength);
      adjustForInsert(text.length());
  
      return getCharacterRun(numCharacterRuns() - 1);
  
    }
  
    public CharacterRun insertBefore(String text, CharacterProperties props)
      //throws UnsupportedEncodingException
    {
      initAll();
      PAPX papx = (PAPX)_paragraphs.get(_parStart);
      short istd = papx.getIstd();
  
      StyleSheet ss = _doc.getStyleSheet();
      CharacterProperties baseStyle = ss.getCharacterStyle(istd);
      byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
      SprmBuffer buf = new SprmBuffer(grpprl);
      _doc.getCharacterTable().insert(_charStart, _start, buf);
  
      return insertBefore(text);
    }
  
    public CharacterRun insertAfter(String text, CharacterProperties props)
      //throws UnsupportedEncodingException
    {
      initAll();
      PAPX papx = (PAPX)_paragraphs.get(_parEnd - 1);
      short istd = papx.getIstd();
  
      StyleSheet ss = _doc.getStyleSheet();
      CharacterProperties baseStyle = ss.getCharacterStyle(istd);
      byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
      SprmBuffer buf = new SprmBuffer(grpprl);
      _doc.getCharacterTable().insert(_charEnd, _end, buf);
      _charEnd++;
      return insertAfter(text);
    }
  
  
    public Paragraph insertBefore(ParagraphProperties props, int styleIndex)
      //throws UnsupportedEncodingException
    {
     return this.insertBefore(props, styleIndex, "\r");
    }
  
    protected Paragraph insertBefore(ParagraphProperties props, int styleIndex, String text)
      //throws UnsupportedEncodingException
    {
      initAll();
      StyleSheet ss = _doc.getStyleSheet();
      ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex);
      CharacterProperties baseChp = ss.getCharacterStyle(styleIndex);
  
      byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
      byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
      LittleEndian.putShort(withIndex, (short)styleIndex);
      System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
      SprmBuffer buf = new SprmBuffer(withIndex);
  
      _doc.getParagraphTable().insert(_parStart, _start, buf);
      insertBefore(text, baseChp);
      return getParagraph(0);
    }
  
  
    public Paragraph insertAfter(ParagraphProperties props, int styleIndex)
      //throws UnsupportedEncodingException
    {
      return this.insertAfter(props, styleIndex, "\r");
    }
  
    protected Paragraph insertAfter(ParagraphProperties props, int styleIndex, String text)
      //throws UnsupportedEncodingException
    {
      initAll();
      StyleSheet ss = _doc.getStyleSheet();
      ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex);
      CharacterProperties baseChp = ss.getCharacterStyle(styleIndex);
  
      byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
      byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
      LittleEndian.putShort(withIndex, (short)styleIndex);
      System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
      SprmBuffer buf = new SprmBuffer(withIndex);
  
      _doc.getParagraphTable().insert(_parEnd, _end, buf);
      _parEnd++;
      insertAfter(text, baseChp);
      return getParagraph(numParagraphs() - 1);
    }
  
  
  
    public Table insertBefore(TableProperties props, int rows)
    {
      ParagraphProperties parProps = new ParagraphProperties();
      parProps.setFInTable((byte)1);
      parProps.setTableLevel((byte)1);
  
      int columns = props.getItcMac();
      for (int x = 0; x < rows; x++)
      {
        Paragraph cell = this.insertBefore(parProps, StyleSheet.NIL_STYLE);
        cell.insertAfter(String.valueOf('\u0007'));
        for(int y = 1; y < columns; y++)
        {
          cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE);
          cell.insertAfter(String.valueOf('\u0007'));
        }
        cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE, String.valueOf('\u0007'));
        cell.setTableRowEnd(props);
      }
      return new Table(_start, _start + (rows * (columns + 1)), this, 0);
    }
  
    public ListEntry insertBefore(ParagraphProperties props, int listID, int level, int styleIndex)
      //throws UnsupportedEncodingException
    {
      ListTables lt = _doc.getListTables();
      if (lt.getLevel(listID, level) == null)
      {
        throw new NoSuchElementException("The specified list and level do not exist");
      }
  
      int ilfo = lt.getOverrideIndexFromListID(listID);
      props.setIlfo(ilfo);
      props.setIlvl((byte)level);
  
      return (ListEntry)insertBefore(props, styleIndex);
    }
  
    public CharacterRun getCharacterRun(int index)
    {
      initCharacterRuns();
      CHPX chpx = (CHPX)_characters.get(index + _charStart);
  
      int[] point = findRange(_paragraphs, _parStart, chpx.getStart(),
                                chpx.getEnd());
      PAPX papx = (PAPX)_paragraphs.get(point[0]);
      short istd = papx.getIstd();
  
      CharacterRun chp = new CharacterRun(chpx, _doc.getStyleSheet(), istd, this);
  
      return chp;
    }
  
    public Section getSection(int index)
    {
      initSections();
      SEPX sepx = (SEPX)_sections.get(index + _sectionStart);
      Section sep = new Section(sepx, this);
      return sep;
    }
  
    public Paragraph getParagraph(int index)
    {
      initParagraphs();
      PAPX papx = (PAPX)_paragraphs.get(index + _parStart);
  
      ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet());
      Paragraph pap = null;
      if (props.getIlfo() > 0)
      {
        pap = new ListEntry(papx.getStart(), papx.getEnd(), _doc.getListTables(),
                            props, papx.getSprmBuf(), this);
      }
      else
      {
        pap = new Paragraph(papx.getStart(), papx.getEnd(), props,
                            papx.getSprmBuf(), this);
      }
  
      return pap;
    }
  
    private void initAll()
    {
      initText();
      initCharacterRuns();
      initParagraphs();
      initSections();
    }
  
  
    private void initParagraphs()
    {
      if (!_parRangeFound)
      {
        int[] point = findRange(_paragraphs, _parStart, _start, _end);
        _parStart = point[0];
        _parEnd = point[1];
        _parRangeFound = true;
      }
    }
  
    private void initCharacterRuns()
    {
      if (!_charRangeFound)
      {
        int[] point = findRange(_characters, _charStart, _start, _end);
        _charStart = point[0];
        _charEnd = point[1];
        _charRangeFound = true;
      }
    }
  
    private void initText()
    {
      if (!_textRangeFound)
      {
        int[] point = findRange(_text, _textStart, _start, _end);
        _textStart = point[0];
        _textEnd = point[1];
        _textRangeFound = true;
      }
    }
  
    private void initSections()
    {
      if (!_sectionRangeFound)
      {
        int[] point = findRange(_sections, _sectionStart, _start, _end);
        _sectionStart = point[0];
        _sectionEnd = point[1];
        _sectionRangeFound = true;
      }
    }
  
    private int[] findRange(List rpl, int min, int start, int end)
    {
      int x = min;
      PropertyNode node = (PropertyNode)rpl.get(x);
      while(node.getEnd() <= start)
      {
        x++;
        node = (PropertyNode)rpl.get(x);
      }
  
      int y = x;
      node = (PropertyNode)rpl.get(y);
      while(node.getEnd() < end)
      {
        y++;
        node = (PropertyNode)rpl.get(y);
      }
      return new int[]{x, y + 1};
    }
  
    private void reset()
    {
      _textRangeFound = false;
      _charRangeFound = false;
      _parRangeFound = false;
      _sectionRangeFound = false;
    }
  
    private void adjustForInsert(int length)
    {
      _end += length;
      reset();
      Range parent = (Range)_parent.get();
      if (parent != null)
      {
        parent.adjustForInsert(length);
      }
    }
  
  }
  
  
  
  1.1                  jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java
  
  Index: Table.java
  ===================================================================
  package org.apache.poi.hwpf.usermodel;
  
  import java.util.ArrayList;
  
  public class Table
    extends Range
  {
    ArrayList _rows;
  
    Table(int startIdx, int endIdx, Range parent, int levelNum)
    {
      super(startIdx, endIdx, Range.PARAGRAPH_INDEX, parent);
      _rows = new ArrayList();
      int numParagraphs = numParagraphs();
  
      int rowStart = 0;
      int rowEnd = 0;
  
      while (rowEnd < numParagraphs)
      {
        Paragraph p = getParagraph(rowEnd);
        rowEnd++;
        if (p.isTableRowEnd() && p.getTableLevel() == levelNum)
        {
          _rows.add(new TableRow(rowStart, rowEnd, this, levelNum));
          rowStart = rowEnd;
        }
      }
    }
  
    public int numRows()
    {
      return _rows.size();
    }
  
    public TableRow getRow(int index)
    {
      return (TableRow)_rows.get(index);
    }
  }
  
  
  
  1.1                  jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java
  
  Index: TableCell.java
  ===================================================================
  package org.apache.poi.hwpf.usermodel;
  
  
  public class TableCell
    extends Range
  {
    int _levelNum;
  
    public TableCell(int startIdx, int endIdx, TableRow parent, int levelNum, TableCellDescriptor tcd)
    {
      super(startIdx, endIdx, Range.PARAGRAPH_INDEX, parent);
      _levelNum = levelNum;
    }
  
  
  }
  
  
  
  1.1                  jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableIterator.java
  
  Index: TableIterator.java
  ===================================================================
  package org.apache.poi.hwpf.usermodel;
  
  
  import java.util.ArrayList;
  
  public class TableIterator
  {
    Range _range;
    int _index;
    int _levelNum;
  
    TableIterator(Range range, int levelNum)
    {
      _range = range;
      _index = 0;
      _levelNum = levelNum;
    }
  
    public TableIterator(Range range)
    {
      this(range, 1);
    }
  
  
    public boolean hasNext()
    {
      int numParagraphs = _range.numParagraphs();
      for (;_index < numParagraphs; _index++)
      {
        Paragraph paragraph = _range.getParagraph(_index);
        if (paragraph.isInTable() && paragraph.getTableLevel() == _levelNum)
        {
          return true;
        }
      }
      return false;
    }
  
    public Table next()
    {
      int numParagraphs = _range.numParagraphs();
      int numRows = 0;
      int startIndex = _index;
      int endIndex = _index;
  
      for (;_index < numParagraphs; _index++)
      {
        Paragraph paragraph = _range.getParagraph(_index);
        if (!paragraph.isInTable() || paragraph.getTableLevel() < _levelNum)
        {
          endIndex = _index;
          break;
        }
      }
      return new Table(startIndex, endIndex, _range, _levelNum);
    }
  
  }
  
  
  
  1.1                  jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java
  
  Index: TableRow.java
  ===================================================================
  package org.apache.poi.hwpf.usermodel;
  
  
  import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
  import org.apache.poi.hwpf.sprm.SprmBuffer;
  
  public class TableRow
    extends Paragraph
  {
    private final static char TABLE_CELL_MARK = '\u0007';
  
    private final static short SPRM_TJC = 0x5400;
    private final static short SPRM_DXAGAPHALF = (short)0x9602;
    private final static short SPRM_FCANTSPLIT = 0x3403;
    private final static short SPRM_FTABLEHEADER = 0x3404;
    private final static short SPRM_DYAROWHEIGHT = (short)0x9407;
  
    int _levelNum;
    TableProperties _tprops;
    TableCell[] _cells;
  
    public TableRow(int startIdx, int endIdx, Table parent, int levelNum)
    {
      super(startIdx, endIdx, parent);
  
      _tprops = TableSprmUncompressor.uncompressTAP(_papx.toByteArray(), 2);
      _levelNum = levelNum;
      _cells = new TableCell[_tprops.getItcMac()];
  
      int start = 0;
      int cellIndex = 0;
      for (int x = 0; x < numParagraphs(); x++)
      {
        Paragraph p = getParagraph(x);
        String s = p.text();
  
        if ((levelNum == 1 && s.charAt(s.length()-1) == TABLE_CELL_MARK) ||
            p.isEmbeddedCellMark() && p.getTableLevel() == levelNum)
        {
          _cells[cellIndex] = new TableCell(start, x+1, this, levelNum, _tprops.getRgtc()[cellIndex]);
        }
      }
    }
  
    public int getRowJustification()
    {
      return _tprops.getJc();
    }
  
    public void setRowJustification(int jc)
    {
      _tprops.setJc(jc);
      _papx.addSprm(SPRM_TJC, (short)jc);
    }
  
    public int getGapHalf()
    {
      return _tprops.getDxaGapHalf();
    }
  
    public void setGapHalf(int dxaGapHalf)
    {
      _tprops.setDxaGapHalf(dxaGapHalf);
      _papx.addSprm(SPRM_DXAGAPHALF, (short)dxaGapHalf);
    }
  
    public int getRowHeight()
    {
      return _tprops.getDyaRowHeight();
    }
  
    public void setRowHeight(int dyaRowHeight)
    {
      _tprops.setDyaRowHeight(dyaRowHeight);
      _papx.addSprm(SPRM_DYAROWHEIGHT, (short)dyaRowHeight);
    }
  
    public boolean cantSplit()
    {
      return _tprops.getFCantSplit();
    }
  
    public void setCantSplit(boolean cantSplit)
    {
      _tprops.setFCantSplit(cantSplit);
      _papx.addSprm(SPRM_FCANTSPLIT, (byte)(cantSplit ? 1 : 0));
    }
  
    public boolean isTableHeader()
    {
      return _tprops.getFTableHeader();
    }
  
    public void setTableHeader(boolean tableHeader)
    {
      _tprops.setFTableHeader(tableHeader);
      _papx.addSprm(SPRM_FTABLEHEADER, (byte)(tableHeader ? 1 : 0));
    }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org