]> source.dussan.org Git - poi.git/commitdiff
make Table elements constructors accepts char positions (as other constructors);...
authorSergey Vladimirov <sergey@apache.org>
Mon, 11 Jul 2011 21:59:33 +0000 (21:59 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 11 Jul 2011 21:59:33 +0000 (21:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1145377 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableIterator.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java

index 83ea717c953984406062b0702bd1952bfb55825d..5c9ab60886ecd085cf0cd51e954aeb96f6cacf98 100644 (file)
@@ -41,7 +41,7 @@ public final class PAPX extends BytePropertyNode<PAPX> {
 
   public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, byte[] papx, ParagraphHeight phe, byte[] dataStream)
   {
-    super(fcStart, fcEnd, translator, new SprmBuffer(papx, 0));
+    super(fcStart, fcEnd, translator, new SprmBuffer(papx, 2));
     _phe = phe;
     SprmBuffer buf = findHuge(new SprmBuffer(papx, 2), dataStream);
     if(buf != null)
index ac3ce8986bdc30c1a0a91d23fad00229b044243b..9640bc5c00e41fd915ec917969336bbb0f964266 100644 (file)
@@ -84,14 +84,17 @@ public class Paragraph extends Range implements Cloneable {
   protected ParagraphProperties _props;
   protected SprmBuffer _papx;
 
-  protected Paragraph(int startIdxInclusive, int endIdxExclusive, Table parent)
-  {
-    super(startIdxInclusive, endIdxExclusive, Range.TYPE_PARAGRAPH, parent);
-    PAPX papx = _paragraphs.get(_parEnd - 1);
-    _props = papx.getParagraphProperties(_doc.getStyleSheet());
-    _papx = papx.getSprmBuf();
-    _istd = papx.getIstd();
-  }
+    protected Paragraph( int startIdxInclusive, int endIdxExclusive,
+            Table parent )
+    {
+        super( startIdxInclusive, endIdxExclusive, parent );
+
+        initAll();
+        PAPX papx = _paragraphs.get( _parEnd - 1 );
+        _props = papx.getParagraphProperties( _doc.getStyleSheet() );
+        _papx = papx.getSprmBuf();
+        _istd = papx.getIstd();
+    }
 
   protected Paragraph(PAPX papx, Range parent)
   {
index 92e00874f785abbc9a5105069eda0d6e5b208fb4..03a0deb03275b2e5e4ff31d0cb21a9537afaefa6 100644 (file)
@@ -186,6 +186,7 @@ public class Range { // TODO -instantiable superclass
         * @param parent
         *            The parent Range this range belongs to.
         */
+       @Deprecated
        protected Range(int startIdx, int endIdx, int idxType, Range parent) {
                _doc = parent._doc;
                _sections = parent._sections;
@@ -194,37 +195,6 @@ public class Range { // TODO -instantiable superclass
                _text = parent._text;
                _parent = new WeakReference<Range>(parent);
 
-               switch (idxType) {
-                       case TYPE_PARAGRAPH:
-                               _parStart = parent._parStart + startIdx;
-                               _parEnd = parent._parStart + endIdx;
-                               _start = _paragraphs.get(_parStart).getStart();
-                               _end = _paragraphs.get(_parEnd - 1).getEnd();
-                               _parRangeFound = true;
-                               break;
-                       case TYPE_CHARACTER:
-                               _charStart = parent._charStart + startIdx;
-                               _charEnd = parent._charStart + endIdx;
-                               _start = _characters.get(_charStart - 1).getStart();
-                               _end = _characters.get(_charEnd).getEnd();
-                               _charRangeFound = true;
-                               break;
-                       case TYPE_SECTION:
-                               _sectionStart = parent._sectionStart + startIdx;
-                               _sectionEnd = parent._sectionStart + endIdx;
-                               _start = _sections.get(_sectionStart - 1).getStart();
-                               _end = _sections.get(_sectionEnd).getEnd();
-                               _sectionRangeFound = true;
-                               break;
-                       case TYPE_TEXT:
-                               _textStart = parent._textStart + startIdx;
-                               _textEnd = parent._textStart + endIdx;
-                               _start = _text.get(_textStart - 1).getStart();
-                               _end = _text.get(_textEnd).getEnd();
-                               _textRangeFound = true;
-                               break;
-               }
-
                sanityCheckStartEnd();
        }
 
@@ -534,7 +504,7 @@ public class Range { // TODO -instantiable superclass
                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, 0);
+               SprmBuffer buf = new SprmBuffer(withIndex, 2);
 
                _doc.getParagraphTable().insert(_parStart, _start, buf);
                insertBefore(text, baseChp);
@@ -584,7 +554,7 @@ public class Range { // TODO -instantiable superclass
                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, 0);
+               SprmBuffer buf = new SprmBuffer(withIndex, 2);
 
                _doc.getParagraphTable().insert(_parEnd, _end, buf);
                _parEnd++;
@@ -902,12 +872,12 @@ public class Range { // TODO -instantiable superclass
             }
         }
 
-        final Range overallrange = getDocument().getOverallRange();
+        Range overallRange = _doc.getOverallRange();
         int limit = _paragraphs.size();
         for ( ; tableEndInclusive < limit - 1; tableEndInclusive++ )
         {
-            Paragraph next = new Paragraph( _paragraphs.get( tableEndInclusive + 1 ),
-                    overallrange );
+            Paragraph next = new Paragraph(
+                    _paragraphs.get( tableEndInclusive + 1 ), overallRange );
             if ( !next.isInTable() || next.getTableLevel() < tableLevel )
                 break;
         }
@@ -923,8 +893,11 @@ public class Range { // TODO -instantiable superclass
             throw new ArrayIndexOutOfBoundsException(
                     "The table's end is negative, which isn't allowed!" );
         }
-        return new Table( r._parStart, tableEndInclusive + 1, r._doc.getRange(),
-                paragraph.getTableLevel() );
+
+        int endOffsetExclusive = _paragraphs.get( tableEndInclusive ).getEnd();
+
+        return new Table( paragraph.getStartOffset(), endOffsetExclusive,
+                this, paragraph.getTableLevel() );
     }
 
        /**
index 246f01a5e16e73201ea6c8d3c4777acac87eb497..fb99df52f94889185ed241d2b4d3e4b02b373064 100644 (file)
@@ -30,7 +30,7 @@ public final class Table extends Range
     Table( int startIdxInclusive, int endIdxExclusive, Range parent,
             int levelNum )
     {
-        super( startIdxInclusive, endIdxExclusive, Range.TYPE_PARAGRAPH, parent );
+        super( startIdxInclusive, endIdxExclusive, parent );
         _tableLevel = levelNum;
         initRows();
     }
@@ -58,11 +58,14 @@ public final class Table extends Range
         int numParagraphs = numParagraphs();
         while ( rowEnd < numParagraphs )
         {
-            Paragraph p = getParagraph( rowEnd );
+            Paragraph startRowP = getParagraph( rowStart );
+            Paragraph endRowP = getParagraph( rowEnd );
             rowEnd++;
-            if ( p.isTableRowEnd() && p.getTableLevel() == _tableLevel )
+            if ( endRowP.isTableRowEnd()
+                    && endRowP.getTableLevel() == _tableLevel )
             {
-                _rows.add( new TableRow( rowStart, rowEnd, this, _tableLevel ) );
+                _rows.add( new TableRow( startRowP.getStartOffset(), endRowP
+                        .getEndOffset(), this, _tableLevel ) );
                 rowStart = rowEnd;
             }
         }
index e319307bf724f3c7408e3360e592e50b059d0d53..83a7b0bcee94f9004290fb9c5ff452a03bfe0c29 100644 (file)
@@ -29,7 +29,7 @@ public final class TableCell
             TableRow parent, int levelNum, TableCellDescriptor tcd,
             int leftEdge, int width )
     {
-        super( startIdxInclusive, endIdxExclusive, Range.TYPE_PARAGRAPH, parent );
+        super( startIdxInclusive, endIdxExclusive, parent );
         _tcd = tcd;
         _leftEdge = leftEdge;
         _width = width;
index 9f2e208e766f265611ec617402413958d44548d1..b2b11d288e61fb95e7f8b1bcf84ffb3c69180ec7 100644 (file)
@@ -66,7 +66,9 @@ public final class TableIterator
         break;
       }
     }
-    return new Table(startIndex, endIndex, _range, _levelNum);
+        return new Table( _range.getParagraph( startIndex ).getStartOffset(),
+                _range.getParagraph( endIndex - 1 ).getEndOffset(), _range,
+                _levelNum );
   }
 
 }
index bd41a339df2f36ba6b1e142ded625cf3d32fd397..16a2967bbbca749c694598509e67727d56a46d5f 100644 (file)
@@ -51,7 +51,8 @@ public final class TableRow extends Range
         super( startIdxInclusive, endIdxExclusive, parent );
 
         Paragraph last = getParagraph( numParagraphs() - 1 );
-        _tprops = TableSprmUncompressor.uncompressTAP( last._papx );
+        _papx = last._papx;
+        _tprops = TableSprmUncompressor.uncompressTAP( _papx );
         _levelNum = levelNum;
         initCells();
     }
@@ -146,9 +147,10 @@ public final class TableRow extends Range
                         && _tprops.getRgdxaCenter().length > cells.size() + 1 ? _tprops
                         .getRgdxaCenter()[cells.size() + 1] : 0;
 
-                TableCell tableCell = new TableCell( lastCellStart, p + 1,
-                        this, _levelNum, tableCellDescriptor, leftEdge,
-                        rightEdge - leftEdge );
+                TableCell tableCell = new TableCell( getParagraph(
+                        lastCellStart ).getStartOffset(), getParagraph( p )
+                        .getEndOffset(), this, _levelNum, tableCellDescriptor,
+                        leftEdge, rightEdge - leftEdge );
                 cells.add( tableCell );
                 lastCellStart = p + 1;
             }