Author: jheight
Date: Fri Sep  8 14:09:48 2006
New Revision: 441652

URL: http://svn.apache.org/viewvc?view=rev&rev=441652
Log:
BUG 27496: get/setPageBreak and get/getColumnBreak now work correctly if a 
template excel file is loaded which does not contain PaneRecords is loaded.

Modified:
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java?view=diff&rev=441652&r1=441651&r2=441652
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java Fri Sep  8 
14:09:48 2006
@@ -2666,7 +2666,12 @@
      * Sets a page break at the indicated row
      * @param row
      */
-    public void setRowBreak(int row, short fromCol, short toCol) {     
+    public void setRowBreak(int row, short fromCol, short toCol) { 
+       if (rowBreaks == null) {
+            int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
+            rowBreaks = new PageBreakRecord(PageBreakRecord.HORIZONTAL_SID);
+            records.add(loc, rowBreaks);
+       }
        rowBreaks.addBreak((short)row, fromCol, toCol);
     }
 
@@ -2675,6 +2680,8 @@
      * @param row
      */
     public void removeRowBreak(int row) {
+       if (rowBreaks == null)
+               throw new IllegalArgumentException("Sheet does not define any 
row breaks");
        rowBreaks.removeBreak((short)row);
     }
 
@@ -2684,14 +2691,19 @@
      * @return true if the specified row has a page break
      */
     public boolean isRowBroken(int row) {
-       return rowBreaks.getBreak((short)row) != null;
+       return (rowBreaks == null) ? false : rowBreaks.getBreak((short)row) != 
null;
     }
 
     /**
      * Sets a page break at the indicated column
      *
      */
-    public void setColumnBreak(short column, short fromRow, short toRow) {     
+    public void setColumnBreak(short column, short fromRow, short toRow) {
+       if (colBreaks == null) {
+            int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
+            colBreaks = new PageBreakRecord(PageBreakRecord.VERTICAL_SID);
+            records.add(loc, colBreaks);
+       }       
        colBreaks.addBreak(column, fromRow, toRow);
     }
 
@@ -2700,6 +2712,9 @@
      *
      */
     public void removeColumnBreak(short column) {
+       if (colBreaks == null)
+               throw new IllegalArgumentException("Sheet does not define any 
column breaks");
+       
        colBreaks.removeBreak(column);
     }
 
@@ -2709,7 +2724,7 @@
      * @return true if the specified column has a page break
      */
     public boolean isColumnBroken(short column) {
-       return colBreaks.getBreak(column) != null;
+       return (colBreaks == null) ? false : colBreaks.getBreak(column) != null;
     }
     
     /**
@@ -2745,7 +2760,7 @@
      * @return the number of row page breaks
      */
     public int getNumRowBreaks(){
-       return (int)rowBreaks.getNumBreaks();
+       return (rowBreaks == null) ? 0 : (int)rowBreaks.getNumBreaks();
     }
     
     /**
@@ -2761,7 +2776,7 @@
      * @return the number of column page breaks
      */
     public int getNumColumnBreaks(){
-       return (int)colBreaks.getNumBreaks();
+       return (colBreaks == null) ? 0 : (int)colBreaks.getNumBreaks();
     }
 
     public void setColumnGroupCollapsed( short columnNumber, boolean collapsed 
)

Modified: 
jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?view=diff&rev=441652&r1=441651&r2=441652
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java 
(original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Fri 
Sep  8 14:09:48 2006
@@ -1204,34 +1204,42 @@
     
     /**
      * Retrieves all the horizontal page breaks
-     * @return all the horizontal page breaks
+     * @return all the horizontal page breaks, or null if there are no row 
page breaks
      */
     public int[] getRowBreaks(){
-       //we can probably cache this information, but this should be a sparsely 
used function 
-       int[] returnValue = new int[sheet.getNumRowBreaks()];
-       Iterator iterator = sheet.getRowBreaks();
-       int i = 0;
-       while (iterator.hasNext()) {
+       //we can probably cache this information, but this should be a sparsely 
used function
+       int count = sheet.getNumRowBreaks();
+       if (count > 0) {
+         int[] returnValue = new int[count];
+         Iterator iterator = sheet.getRowBreaks();
+         int i = 0;
+         while (iterator.hasNext()) {
                PageBreakRecord.Break breakItem = 
(PageBreakRecord.Break)iterator.next();
                returnValue[i++] = (int)breakItem.main;
+         }
+         return returnValue;
        }
-       return returnValue;
+       return null;
     }
 
     /**
      * Retrieves all the vertical page breaks
-     * @return all the vertical page breaks
+     * @return all the vertical page breaks, or null if there are no column 
page breaks
      */
     public short[] getColumnBreaks(){
        //we can probably cache this information, but this should be a sparsely 
used function 
-       short[] returnValue = new short[sheet.getNumColumnBreaks()];
-       Iterator iterator = sheet.getColumnBreaks();
-       int i = 0;
-       while (iterator.hasNext()) {
+       int count = sheet.getNumColumnBreaks();
+       if (count > 0) {
+         short[] returnValue = new short[count];
+         Iterator iterator = sheet.getColumnBreaks();
+         int i = 0;
+         while (iterator.hasNext()) {
                PageBreakRecord.Break breakItem = 
(PageBreakRecord.Break)iterator.next();
                returnValue[i++] = breakItem.main;
+         }
+         return returnValue;
        }
-       return returnValue;
+       return null;
     }
     
     



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/

Reply via email to