Finished extracting PageSettingsBlock logic from Sheet

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@683880 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-08-08 06:56:06 +00:00
parent 7b9f5ba600
commit 3262629faa
4 changed files with 369 additions and 541 deletions

View File

@ -36,10 +36,8 @@ import org.apache.poi.hssf.record.DimensionsRecord;
import org.apache.poi.hssf.record.DrawingRecord; import org.apache.poi.hssf.record.DrawingRecord;
import org.apache.poi.hssf.record.EOFRecord; import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.EscherAggregate; import org.apache.poi.hssf.record.EscherAggregate;
import org.apache.poi.hssf.record.FooterRecord;
import org.apache.poi.hssf.record.GridsetRecord; import org.apache.poi.hssf.record.GridsetRecord;
import org.apache.poi.hssf.record.GutsRecord; import org.apache.poi.hssf.record.GutsRecord;
import org.apache.poi.hssf.record.HeaderRecord;
import org.apache.poi.hssf.record.IndexRecord; import org.apache.poi.hssf.record.IndexRecord;
import org.apache.poi.hssf.record.IterationRecord; import org.apache.poi.hssf.record.IterationRecord;
import org.apache.poi.hssf.record.MergeCellsRecord; import org.apache.poi.hssf.record.MergeCellsRecord;
@ -49,7 +47,6 @@ import org.apache.poi.hssf.record.PaneRecord;
import org.apache.poi.hssf.record.PasswordRecord; import org.apache.poi.hssf.record.PasswordRecord;
import org.apache.poi.hssf.record.PrintGridlinesRecord; import org.apache.poi.hssf.record.PrintGridlinesRecord;
import org.apache.poi.hssf.record.PrintHeadersRecord; import org.apache.poi.hssf.record.PrintHeadersRecord;
import org.apache.poi.hssf.record.PrintSetupRecord;
import org.apache.poi.hssf.record.ProtectRecord; import org.apache.poi.hssf.record.ProtectRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase; import org.apache.poi.hssf.record.RecordBase;
@ -1451,62 +1448,9 @@ public final class Sheet implements Model {
return -1; return -1;
} }
/**
* Returns the HeaderRecord.
* @return HeaderRecord for the sheet.
*/
public HeaderRecord getHeader ()
{
return getPageSettings().getHeader();
}
public WindowTwoRecord getWindowTwo() { public WindowTwoRecord getWindowTwo() {
return windowTwo; return windowTwo;
} }
/**
* Sets the HeaderRecord.
* @param newHeader The new HeaderRecord for the sheet.
*/
public void setHeader (HeaderRecord newHeader)
{
getPageSettings().setHeader(newHeader);
}
/**
* Returns the FooterRecord.
* @return FooterRecord for the sheet.
*/
public FooterRecord getFooter ()
{
return getPageSettings().getFooter();
}
/**
* Sets the FooterRecord.
* @param newFooter The new FooterRecord for the sheet.
*/
public void setFooter (FooterRecord newFooter)
{
getPageSettings().setFooter(newFooter);
}
/**
* Returns the PrintSetupRecord.
* @return PrintSetupRecord for the sheet.
*/
public PrintSetupRecord getPrintSetup ()
{
return getPageSettings().getPrintSetup();
}
/**
* Sets the PrintSetupRecord.
* @param newPrintSetup The new PrintSetupRecord for the sheet.
*/
public void setPrintSetup (PrintSetupRecord newPrintSetup)
{
getPageSettings().setPrintSetup(newPrintSetup);
}
/** /**
* Returns the PrintGridlinesRecord. * Returns the PrintGridlinesRecord.
@ -1534,24 +1478,6 @@ public final class Sheet implements Model {
windowTwo.setSelected(sel); windowTwo.setSelected(sel);
} }
/**
* Gets the size of the margin in inches.
* @param margin which margin to get
* @return the size of the margin
*/
public double getMargin(short margin) {
return getPageSettings().getMargin(margin);
}
/**
* Sets the size of the margin in inches.
* @param margin which margin to get
* @param size the size of the margin
*/
public void setMargin(short margin, double size) {
getPageSettings().setMargin(margin, size);
}
public int getEofLoc() public int getEofLoc()
{ {
return eofLoc; return eofLoc;
@ -1878,103 +1804,6 @@ public final class Sheet implements Model {
return _psBlock; return _psBlock;
} }
/**
* Sets a page break at the indicated row
* @param row
*/
public void setRowBreak(int row, short fromCol, short toCol) {
getPageSettings().setRowBreak(row, fromCol, toCol);
}
/**
* Removes a page break at the indicated row
* @param row
*/
public void removeRowBreak(int row) {
getPageSettings().removeRowBreak(row);
}
/**
* Queries if the specified row has a page break
* @param row
* @return true if the specified row has a page break
*/
public boolean isRowBroken(int row) {
return getPageSettings().isRowBroken(row);
}
/**
* Sets a page break at the indicated column
*
*/
public void setColumnBreak(short column, short fromRow, short toRow) {
getPageSettings().setColumnBreak(column, fromRow, toRow);
}
/**
* Removes a page break at the indicated column
*
*/
public void removeColumnBreak(short column) {
getPageSettings().removeColumnBreak(column);
}
/**
* Queries if the specified column has a page break
*
* @return <code>true</code> if the specified column has a page break
*/
public boolean isColumnBroken(short column) {
return getPageSettings().isColumnBroken(column);
}
/**
* Shifts the horizontal page breaks for the indicated count
* @param startingRow
* @param endingRow
* @param count
*/
public void shiftRowBreaks(int startingRow, int endingRow, int count) {
getPageSettings().shiftRowBreaks(startingRow, endingRow, count);
}
/**
* Shifts the vertical page breaks for the indicated count
* @param startingCol
* @param endingCol
* @param count
*/
public void shiftColumnBreaks(short startingCol, short endingCol, short count) {
getPageSettings().shiftColumnBreaks(startingCol, endingCol, count);
}
/**
* @return all the horizontal page breaks, never <code>null</code>
*/
public int[] getRowBreaks() {
return getPageSettings().getRowBreaks();
}
/**
* @return the number of row page breaks
*/
public int getNumRowBreaks(){
return getPageSettings().getNumRowBreaks();
}
/**
* @return all the column page breaks, never <code>null</code>
*/
public int[] getColumnBreaks(){
return getPageSettings().getColumnBreaks();
}
/**
* @return the number of column page breaks
*/
public int getNumColumnBreaks(){
return getPageSettings().getNumColumnBreaks();
}
public void setColumnGroupCollapsed( short columnNumber, boolean collapsed ) public void setColumnGroupCollapsed( short columnNumber, boolean collapsed )
{ {

View File

@ -62,31 +62,31 @@ public final class PageSettingsBlock extends RecordAggregate {
private PrintSetupRecord printSetup; private PrintSetupRecord printSetup;
private Record _bitmap; private Record _bitmap;
public PageSettingsBlock(RecordStream rs) { public PageSettingsBlock(RecordStream rs) {
while(true) { while(true) {
if (!readARecord(rs)) { if (!readARecord(rs)) {
break; break;
} }
} }
}
/**
* Creates a PageSettingsBlock with default settings
*/
public PageSettingsBlock() {
_rowBreaksRecord = new HorizontalPageBreakRecord();
_columnBreaksRecord = new VerticalPageBreakRecord();
header = createHeader();
footer = createFooter();
_hCenter = createHCenter();
_vCenter = createVCenter();
printSetup = createPrintSetup();
} }
/** /**
* @return <code>true</code> if the specified Record sid is one belonging to the * Creates a PageSettingsBlock with default settings
* 'Page Settings Block'. */
*/ public PageSettingsBlock() {
_rowBreaksRecord = new HorizontalPageBreakRecord();
_columnBreaksRecord = new VerticalPageBreakRecord();
header = createHeader();
footer = createFooter();
_hCenter = createHCenter();
_vCenter = createVCenter();
printSetup = createPrintSetup();
}
/**
* @return <code>true</code> if the specified Record sid is one belonging to the
* 'Page Settings Block'.
*/
public static boolean isComponentRecord(int sid) { public static boolean isComponentRecord(int sid) {
switch (sid) { switch (sid) {
case HorizontalPageBreakRecord.sid: case HorizontalPageBreakRecord.sid:
@ -105,7 +105,7 @@ public final class PageSettingsBlock extends RecordAggregate {
return true; return true;
} }
return false; return false;
} }
private boolean readARecord(RecordStream rs) { private boolean readARecord(RecordStream rs) {
switch (rs.peekNextSid()) { switch (rs.peekNextSid()) {
@ -155,54 +155,54 @@ public final class PageSettingsBlock extends RecordAggregate {
return true; return true;
} }
private PageBreakRecord getRowBreaksRecord() { private PageBreakRecord getRowBreaksRecord() {
if (_rowBreaksRecord == null) { if (_rowBreaksRecord == null) {
_rowBreaksRecord = new HorizontalPageBreakRecord(); _rowBreaksRecord = new HorizontalPageBreakRecord();
} }
return _rowBreaksRecord; return _rowBreaksRecord;
} }
private PageBreakRecord getColumnBreaksRecord() { private PageBreakRecord getColumnBreaksRecord() {
if (_columnBreaksRecord == null) { if (_columnBreaksRecord == null) {
_columnBreaksRecord = new VerticalPageBreakRecord(); _columnBreaksRecord = new VerticalPageBreakRecord();
} }
return _columnBreaksRecord; return _columnBreaksRecord;
} }
/** /**
* Sets a page break at the indicated column * 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) {
getColumnBreaksRecord().addBreak(column, fromRow, toRow); getColumnBreaksRecord().addBreak(column, fromRow, toRow);
} }
/** /**
* Removes a page break at the indicated column * Removes a page break at the indicated column
* *
*/ */
public void removeColumnBreak(short column) { public void removeColumnBreak(int column) {
getColumnBreaksRecord().removeBreak(column); getColumnBreaksRecord().removeBreak(column);
} }
public void visitContainedRecords(RecordVisitor rv) { public void visitContainedRecords(RecordVisitor rv) {
visitIfPresent(_rowBreaksRecord, rv); visitIfPresent(_rowBreaksRecord, rv);
visitIfPresent(_columnBreaksRecord, rv); visitIfPresent(_columnBreaksRecord, rv);
visitIfPresent(header, rv); visitIfPresent(header, rv);
visitIfPresent(footer, rv); visitIfPresent(footer, rv);
visitIfPresent(_hCenter, rv); visitIfPresent(_hCenter, rv);
visitIfPresent(_vCenter, rv); visitIfPresent(_vCenter, rv);
visitIfPresent(_leftMargin, rv); visitIfPresent(_leftMargin, rv);
visitIfPresent(_rightMargin, rv); visitIfPresent(_rightMargin, rv);
visitIfPresent(_topMargin, rv); visitIfPresent(_topMargin, rv);
visitIfPresent(_bottomMargin, rv); visitIfPresent(_bottomMargin, rv);
visitIfPresent(_pls, rv); visitIfPresent(_pls, rv);
visitIfPresent(printSetup, rv); visitIfPresent(printSetup, rv);
visitIfPresent(_bitmap, rv); visitIfPresent(_bitmap, rv);
} }
private static void visitIfPresent(Record r, RecordVisitor rv) { private static void visitIfPresent(Record r, RecordVisitor rv) {
if (r != null) { if (r != null) {
@ -210,310 +210,310 @@ public final class PageSettingsBlock extends RecordAggregate {
} }
} }
/** /**
* creates the Header Record and sets it to nothing/0 length * creates the Header Record and sets it to nothing/0 length
*/ */
private static HeaderRecord createHeader() { private static HeaderRecord createHeader() {
HeaderRecord retval = new HeaderRecord(); HeaderRecord retval = new HeaderRecord();
retval.setHeaderLength(( byte ) 0); retval.setHeaderLength(( byte ) 0);
retval.setHeader(null); retval.setHeader(null);
return retval; return retval;
} }
/** /**
* creates the Footer Record and sets it to nothing/0 length * creates the Footer Record and sets it to nothing/0 length
*/ */
private static FooterRecord createFooter() { private static FooterRecord createFooter() {
FooterRecord retval = new FooterRecord(); FooterRecord retval = new FooterRecord();
retval.setFooterLength(( byte ) 0); retval.setFooterLength(( byte ) 0);
retval.setFooter(null); retval.setFooter(null);
return retval; return retval;
} }
/** /**
* creates the HCenter Record and sets it to false (don't horizontally center) * creates the HCenter Record and sets it to false (don't horizontally center)
*/ */
private static HCenterRecord createHCenter() { private static HCenterRecord createHCenter() {
HCenterRecord retval = new HCenterRecord(); HCenterRecord retval = new HCenterRecord();
retval.setHCenter(false); retval.setHCenter(false);
return retval; return retval;
} }
/** /**
* creates the VCenter Record and sets it to false (don't horizontally center) * creates the VCenter Record and sets it to false (don't horizontally center)
*/ */
private static VCenterRecord createVCenter() { private static VCenterRecord createVCenter() {
VCenterRecord retval = new VCenterRecord(); VCenterRecord retval = new VCenterRecord();
retval.setVCenter(false); retval.setVCenter(false);
return retval; return retval;
} }
/** /**
* creates the PrintSetup Record and sets it to defaults and marks it invalid * creates the PrintSetup Record and sets it to defaults and marks it invalid
* @see org.apache.poi.hssf.record.PrintSetupRecord * @see org.apache.poi.hssf.record.PrintSetupRecord
* @see org.apache.poi.hssf.record.Record * @see org.apache.poi.hssf.record.Record
* @return record containing a PrintSetupRecord * @return record containing a PrintSetupRecord
*/ */
private static PrintSetupRecord createPrintSetup() { private static PrintSetupRecord createPrintSetup() {
PrintSetupRecord retval = new PrintSetupRecord(); PrintSetupRecord retval = new PrintSetupRecord();
retval.setPaperSize(( short ) 1); retval.setPaperSize(( short ) 1);
retval.setScale(( short ) 100); retval.setScale(( short ) 100);
retval.setPageStart(( short ) 1); retval.setPageStart(( short ) 1);
retval.setFitWidth(( short ) 1); retval.setFitWidth(( short ) 1);
retval.setFitHeight(( short ) 1); retval.setFitHeight(( short ) 1);
retval.setOptions(( short ) 2); retval.setOptions(( short ) 2);
retval.setHResolution(( short ) 300); retval.setHResolution(( short ) 300);
retval.setVResolution(( short ) 300); retval.setVResolution(( short ) 300);
retval.setHeaderMargin( 0.5); retval.setHeaderMargin( 0.5);
retval.setFooterMargin( 0.5); retval.setFooterMargin( 0.5);
retval.setCopies(( short ) 0); retval.setCopies(( short ) 0);
return retval; return retval;
} }
/** /**
* Returns the HeaderRecord. * Returns the HeaderRecord.
* @return HeaderRecord for the sheet. * @return HeaderRecord for the sheet.
*/ */
public HeaderRecord getHeader () public HeaderRecord getHeader ()
{ {
return header; return header;
} }
/** /**
* Sets the HeaderRecord. * Sets the HeaderRecord.
* @param newHeader The new HeaderRecord for the sheet. * @param newHeader The new HeaderRecord for the sheet.
*/ */
public void setHeader (HeaderRecord newHeader) public void setHeader (HeaderRecord newHeader)
{ {
header = newHeader; header = newHeader;
} }
/** /**
* Returns the FooterRecord. * Returns the FooterRecord.
* @return FooterRecord for the sheet. * @return FooterRecord for the sheet.
*/ */
public FooterRecord getFooter () public FooterRecord getFooter ()
{ {
return footer; return footer;
} }
/** /**
* Sets the FooterRecord. * Sets the FooterRecord.
* @param newFooter The new FooterRecord for the sheet. * @param newFooter The new FooterRecord for the sheet.
*/ */
public void setFooter (FooterRecord newFooter) public void setFooter (FooterRecord newFooter)
{ {
footer = newFooter; footer = newFooter;
} }
/** /**
* Returns the PrintSetupRecord. * Returns the PrintSetupRecord.
* @return PrintSetupRecord for the sheet. * @return PrintSetupRecord for the sheet.
*/ */
public PrintSetupRecord getPrintSetup () public PrintSetupRecord getPrintSetup ()
{ {
return printSetup; return printSetup;
} }
/** /**
* Sets the PrintSetupRecord. * Sets the PrintSetupRecord.
* @param newPrintSetup The new PrintSetupRecord for the sheet. * @param newPrintSetup The new PrintSetupRecord for the sheet.
*/ */
public void setPrintSetup (PrintSetupRecord newPrintSetup) public void setPrintSetup (PrintSetupRecord newPrintSetup)
{ {
printSetup = newPrintSetup; printSetup = newPrintSetup;
} }
private Margin getMarginRec(int marginIndex) { private Margin getMarginRec(int marginIndex) {
switch (marginIndex) { switch (marginIndex) {
case Sheet.LeftMargin: return _leftMargin; case Sheet.LeftMargin: return _leftMargin;
case Sheet.RightMargin: return _rightMargin; case Sheet.RightMargin: return _rightMargin;
case Sheet.TopMargin: return _topMargin; case Sheet.TopMargin: return _topMargin;
case Sheet.BottomMargin: return _bottomMargin; case Sheet.BottomMargin: return _bottomMargin;
} }
throw new RuntimeException( "Unknown margin constant: " + marginIndex ); throw new RuntimeException( "Unknown margin constant: " + marginIndex );
} }
/** /**
* Gets the size of the margin in inches. * Gets the size of the margin in inches.
* @param margin which margin to get * @param margin which margin to get
* @return the size of the margin * @return the size of the margin
*/ */
public double getMargin(short margin) { public double getMargin(short margin) {
Margin m = getMarginRec(margin); Margin m = getMarginRec(margin);
if (m != null) { if (m != null) {
return m.getMargin(); return m.getMargin();
} else { } else {
switch ( margin ) switch ( margin )
{ {
case Sheet.LeftMargin: case Sheet.LeftMargin:
return .75; return .75;
case Sheet.RightMargin: case Sheet.RightMargin:
return .75; return .75;
case Sheet.TopMargin: case Sheet.TopMargin:
return 1.0; return 1.0;
case Sheet.BottomMargin: case Sheet.BottomMargin:
return 1.0; return 1.0;
} }
throw new RuntimeException( "Unknown margin constant: " + margin ); throw new RuntimeException( "Unknown margin constant: " + margin );
} }
} }
/** /**
* Sets the size of the margin in inches. * Sets the size of the margin in inches.
* @param margin which margin to get * @param margin which margin to get
* @param size the size of the margin * @param size the size of the margin
*/ */
public void setMargin(short margin, double size) { public void setMargin(short margin, double size) {
Margin m = getMarginRec(margin); Margin m = getMarginRec(margin);
if (m == null) { if (m == null) {
switch ( margin ) switch ( margin )
{ {
case Sheet.LeftMargin: case Sheet.LeftMargin:
_leftMargin = new LeftMarginRecord(); _leftMargin = new LeftMarginRecord();
m = _leftMargin; m = _leftMargin;
break; break;
case Sheet.RightMargin: case Sheet.RightMargin:
_rightMargin = new RightMarginRecord(); _rightMargin = new RightMarginRecord();
m = _rightMargin; m = _rightMargin;
break; break;
case Sheet.TopMargin: case Sheet.TopMargin:
_topMargin = new TopMarginRecord(); _topMargin = new TopMarginRecord();
m = _topMargin; m = _topMargin;
break; break;
case Sheet.BottomMargin: case Sheet.BottomMargin:
_bottomMargin = new BottomMarginRecord(); _bottomMargin = new BottomMarginRecord();
m = _bottomMargin; m = _bottomMargin;
break; break;
default : default :
throw new RuntimeException( "Unknown margin constant: " + margin ); throw new RuntimeException( "Unknown margin constant: " + margin );
} }
} }
m.setMargin( size ); m.setMargin( size );
} }
/** /**
* Shifts all the page breaks in the range "count" number of rows/columns * Shifts all the page breaks in the range "count" number of rows/columns
* @param breaks The page record to be shifted * @param breaks The page record to be shifted
* @param start Starting "main" value to shift breaks * @param start Starting "main" value to shift breaks
* @param stop Ending "main" value to shift breaks * @param stop Ending "main" value to shift breaks
* @param count number of units (rows/columns) to shift by * @param count number of units (rows/columns) to shift by
*/ */
private static void shiftBreaks(PageBreakRecord breaks, int start, int stop, int count) { private static void shiftBreaks(PageBreakRecord breaks, int start, int stop, int count) {
Iterator iterator = breaks.getBreaksIterator(); Iterator iterator = breaks.getBreaksIterator();
List shiftedBreak = new ArrayList(); List shiftedBreak = new ArrayList();
while(iterator.hasNext()) while(iterator.hasNext())
{ {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
int breakLocation = breakItem.main; int breakLocation = breakItem.main;
boolean inStart = (breakLocation >= start); boolean inStart = (breakLocation >= start);
boolean inEnd = (breakLocation <= stop); boolean inEnd = (breakLocation <= stop);
if(inStart && inEnd) if(inStart && inEnd)
shiftedBreak.add(breakItem); shiftedBreak.add(breakItem);
} }
iterator = shiftedBreak.iterator(); iterator = shiftedBreak.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
breaks.removeBreak(breakItem.main); breaks.removeBreak(breakItem.main);
breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo); breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo);
} }
} }
/** /**
* Sets a page break at the indicated row * Sets a page break at the indicated row
* @param row * @param row
*/ */
public void setRowBreak(int row, short fromCol, short toCol) { public void setRowBreak(int row, short fromCol, short toCol) {
getRowBreaksRecord().addBreak((short)row, fromCol, toCol); getRowBreaksRecord().addBreak((short)row, fromCol, toCol);
} }
/** /**
* Removes a page break at the indicated row * Removes a page break at the indicated row
* @param row * @param row
*/ */
public void removeRowBreak(int row) { public void removeRowBreak(int row) {
if (getRowBreaksRecord().getBreaks().length < 1) if (getRowBreaksRecord().getBreaks().length < 1)
throw new IllegalArgumentException("Sheet does not define any row breaks"); throw new IllegalArgumentException("Sheet does not define any row breaks");
getRowBreaksRecord().removeBreak((short)row); getRowBreaksRecord().removeBreak((short)row);
} }
/** /**
* Queries if the specified row has a page break * Queries if the specified row has a page break
* @param row * @param row
* @return true if the specified row has a page break * @return true if the specified row has a page break
*/ */
public boolean isRowBroken(int row) { public boolean isRowBroken(int row) {
return getRowBreaksRecord().getBreak(row) != null; return getRowBreaksRecord().getBreak(row) != null;
} }
/** /**
* Queries if the specified column has a page break * Queries if the specified column has a page break
* *
* @return <code>true</code> if the specified column has a page break * @return <code>true</code> if the specified column has a page break
*/ */
public boolean isColumnBroken(short column) { public boolean isColumnBroken(int column) {
return getColumnBreaksRecord().getBreak(column) != null; return getColumnBreaksRecord().getBreak(column) != null;
} }
/** /**
* Shifts the horizontal page breaks for the indicated count * Shifts the horizontal page breaks for the indicated count
* @param startingRow * @param startingRow
* @param endingRow * @param endingRow
* @param count * @param count
*/ */
public void shiftRowBreaks(int startingRow, int endingRow, int count) { public void shiftRowBreaks(int startingRow, int endingRow, int count) {
shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count); shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count);
} }
/** /**
* Shifts the vertical page breaks for the indicated count * Shifts the vertical page breaks for the indicated count
* @param startingCol * @param startingCol
* @param endingCol * @param endingCol
* @param count * @param count
*/ */
public void shiftColumnBreaks(short startingCol, short endingCol, short count) { public void shiftColumnBreaks(short startingCol, short endingCol, short count) {
shiftBreaks(getColumnBreaksRecord(), startingCol, endingCol, count); shiftBreaks(getColumnBreaksRecord(), startingCol, endingCol, count);
} }
/** /**
* @return all the horizontal page breaks, never <code>null</code> * @return all the horizontal page breaks, never <code>null</code>
*/ */
public int[] getRowBreaks() { public int[] getRowBreaks() {
return getRowBreaksRecord().getBreaks(); return getRowBreaksRecord().getBreaks();
} }
/** /**
* @return the number of row page breaks * @return the number of row page breaks
*/ */
public int getNumRowBreaks(){ public int getNumRowBreaks(){
return getRowBreaksRecord().getNumBreaks(); return getRowBreaksRecord().getNumBreaks();
} }
/** /**
* @return all the column page breaks, never <code>null</code> * @return all the column page breaks, never <code>null</code>
*/ */
public int[] getColumnBreaks(){ public int[] getColumnBreaks(){
return getColumnBreaksRecord().getBreaks(); return getColumnBreaksRecord().getBreaks();
} }
/** /**
* @return the number of column page breaks * @return the number of column page breaks
*/ */
public int getNumColumnBreaks(){ public int getNumColumnBreaks(){
return getColumnBreaksRecord().getNumBreaks(); return getColumnBreaksRecord().getNumBreaks();
} }
public VCenterRecord getVCenter() { public VCenterRecord getVCenter() {
return _vCenter; return _vCenter;
@ -522,5 +522,4 @@ public final class PageSettingsBlock extends RecordAggregate {
public HCenterRecord getHCenter() { public HCenterRecord getHCenter() {
return _hCenter; return _hCenter;
} }
} }

View File

@ -871,7 +871,7 @@ public final class HSSFSheet {
*/ */
public HSSFPrintSetup getPrintSetup() public HSSFPrintSetup getPrintSetup()
{ {
return new HSSFPrintSetup( getSheet().getPrintSetup() ); return new HSSFPrintSetup( sheet.getPageSettings().getPrintSetup() );
} }
/** /**
@ -880,7 +880,7 @@ public final class HSSFSheet {
*/ */
public HSSFHeader getHeader() public HSSFHeader getHeader()
{ {
return new HSSFHeader( getSheet().getHeader() ); return new HSSFHeader( sheet.getPageSettings().getHeader() );
} }
/** /**
@ -889,7 +889,7 @@ public final class HSSFSheet {
*/ */
public HSSFFooter getFooter() public HSSFFooter getFooter()
{ {
return new HSSFFooter( getSheet().getFooter() ); return new HSSFFooter( sheet.getPageSettings().getFooter() );
} }
/** /**
@ -929,7 +929,7 @@ public final class HSSFSheet {
*/ */
public double getMargin( short margin ) public double getMargin( short margin )
{ {
return getSheet().getMargin( margin ); return sheet.getPageSettings().getMargin( margin );
} }
/** /**
@ -939,7 +939,7 @@ public final class HSSFSheet {
*/ */
public void setMargin( short margin, double size ) public void setMargin( short margin, double size )
{ {
getSheet().setMargin( margin, size ); sheet.getPageSettings().setMargin( margin, size );
} }
/** /**
@ -1166,7 +1166,7 @@ public final class HSSFSheet {
} }
shiftMerged(startRow, endRow, n, true); shiftMerged(startRow, endRow, n, true);
sheet.shiftRowBreaks(startRow, endRow, n); sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n);
for ( int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc ) for ( int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc )
{ {
@ -1393,24 +1393,21 @@ public final class HSSFSheet {
*/ */
public void setRowBreak(int row) { public void setRowBreak(int row) {
validateRow(row); validateRow(row);
sheet.setRowBreak(row, (short)0, (short)255); sheet.getPageSettings().setRowBreak(row, (short)0, (short)255);
} }
/** /**
* Determines if there is a page break at the indicated row * @return <code>true</code> if there is a page break at the indicated row
* @param row FIXME: Document this!
* @return FIXME: Document this!
*/ */
public boolean isRowBroken(int row) { public boolean isRowBroken(int row) {
return sheet.isRowBroken(row); return sheet.getPageSettings().isRowBroken(row);
} }
/** /**
* Removes the page break at the indicated row * Removes the page break at the indicated row
* @param row
*/ */
public void removeRowBreak(int row) { public void removeRowBreak(int row) {
sheet.removeRowBreak(row); sheet.getPageSettings().removeRowBreak(row);
} }
/** /**
@ -1418,7 +1415,7 @@ public final class HSSFSheet {
*/ */
public int[] getRowBreaks(){ public int[] getRowBreaks(){
//we can probably cache this information, but this should be a sparsely used function //we can probably cache this information, but this should be a sparsely used function
return sheet.getRowBreaks(); return sheet.getPageSettings().getRowBreaks();
} }
/** /**
@ -1426,7 +1423,7 @@ public final class HSSFSheet {
*/ */
public int[] getColumnBreaks(){ public int[] getColumnBreaks(){
//we can probably cache this information, but this should be a sparsely used function //we can probably cache this information, but this should be a sparsely used function
return sheet.getColumnBreaks(); return sheet.getPageSettings().getColumnBreaks();
} }
@ -1436,7 +1433,7 @@ public final class HSSFSheet {
*/ */
public void setColumnBreak(short column) { public void setColumnBreak(short column) {
validateColumn(column); validateColumn(column);
sheet.setColumnBreak(column, (short)0, (short)65535); sheet.getPageSettings().setColumnBreak(column, (short)0, (short)65535);
} }
/** /**
@ -1445,7 +1442,7 @@ public final class HSSFSheet {
* @return FIXME: Document this! * @return FIXME: Document this!
*/ */
public boolean isColumnBroken(short column) { public boolean isColumnBroken(short column) {
return sheet.isColumnBroken(column); return sheet.getPageSettings().isColumnBroken(column);
} }
/** /**
@ -1453,7 +1450,7 @@ public final class HSSFSheet {
* @param column * @param column
*/ */
public void removeColumnBreak(short column) { public void removeColumnBreak(short column) {
sheet.removeColumnBreak(column); sheet.getPageSettings().removeColumnBreak(column);
} }
/** /**

View File

@ -39,6 +39,7 @@ import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.hssf.record.StringRecord;
import org.apache.poi.hssf.record.UncalcedRecord; import org.apache.poi.hssf.record.UncalcedRecord;
import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate; import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate; import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
import org.apache.poi.hssf.util.CellRangeAddress; import org.apache.poi.hssf.util.CellRangeAddress;
@ -207,7 +208,8 @@ public final class TestSheet extends TestCase {
short colFrom = 0; short colFrom = 0;
short colTo = 255; short colTo = 255;
Sheet sheet = Sheet.createSheet(); Sheet worksheet = Sheet.createSheet();
PageSettingsBlock sheet = worksheet.getPageSettings();
sheet.setRowBreak(0, colFrom, colTo); sheet.setRowBreak(0, colFrom, colTo);
assertTrue("no row break at 0", sheet.isRowBroken(0)); assertTrue("no row break at 0", sheet.isRowBroken(0));
@ -262,24 +264,25 @@ public final class TestSheet extends TestCase {
short rowFrom = 0; short rowFrom = 0;
short rowTo = (short)65535; short rowTo = (short)65535;
Sheet sheet = Sheet.createSheet(); Sheet worksheet = Sheet.createSheet();
PageSettingsBlock sheet = worksheet.getPageSettings();
sheet.setColumnBreak((short)0, rowFrom, rowTo); sheet.setColumnBreak((short)0, rowFrom, rowTo);
assertTrue("no col break at 0", sheet.isColumnBroken((short)0)); assertTrue("no col break at 0", sheet.isColumnBroken(0));
assertEquals("1 col break available", 1, sheet.getNumColumnBreaks()); assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());
sheet.setColumnBreak((short)0, rowFrom, rowTo); sheet.setColumnBreak((short)0, rowFrom, rowTo);
assertTrue("no col break at 0", sheet.isColumnBroken((short)0)); assertTrue("no col break at 0", sheet.isColumnBroken(0));
assertEquals("1 col break available", 1, sheet.getNumColumnBreaks()); assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());
sheet.setColumnBreak((short)1, rowFrom, rowTo); sheet.setColumnBreak((short)1, rowFrom, rowTo);
sheet.setColumnBreak((short)10, rowFrom, rowTo); sheet.setColumnBreak((short)10, rowFrom, rowTo);
sheet.setColumnBreak((short)15, rowFrom, rowTo); sheet.setColumnBreak((short)15, rowFrom, rowTo);
assertTrue("no col break at 1", sheet.isColumnBroken((short)1)); assertTrue("no col break at 1", sheet.isColumnBroken(1));
assertTrue("no col break at 10", sheet.isColumnBroken((short)10)); assertTrue("no col break at 10", sheet.isColumnBroken(10));
assertTrue("no col break at 15", sheet.isColumnBroken((short)15)); assertTrue("no col break at 15", sheet.isColumnBroken(15));
assertEquals("4 col break available", 4, sheet.getNumColumnBreaks()); assertEquals("4 col break available", 4, sheet.getNumColumnBreaks());
boolean is10 = false; boolean is10 = false;
@ -299,17 +302,17 @@ public final class TestSheet extends TestCase {
assertTrue("one of the breaks didnt make it", is0 && is1 && is10 && is15); assertTrue("one of the breaks didnt make it", is0 && is1 && is10 && is15);
sheet.removeColumnBreak((short)15); sheet.removeColumnBreak(15);
assertFalse("column break should not be there", sheet.isColumnBroken((short)15)); assertFalse("column break should not be there", sheet.isColumnBroken(15));
sheet.removeColumnBreak((short)0); sheet.removeColumnBreak(0);
assertFalse("column break should not be there", sheet.isColumnBroken((short)0)); assertFalse("column break should not be there", sheet.isColumnBroken(0));
sheet.removeColumnBreak((short)1); sheet.removeColumnBreak(1);
assertFalse("column break should not be there", sheet.isColumnBroken((short)1)); assertFalse("column break should not be there", sheet.isColumnBroken(1));
sheet.removeColumnBreak((short)10); sheet.removeColumnBreak(10);
assertFalse("column break should not be there", sheet.isColumnBroken((short)10)); assertFalse("column break should not be there", sheet.isColumnBroken(10));
assertEquals("no more breaks", 0, sheet.getNumColumnBreaks()); assertEquals("no more breaks", 0, sheet.getNumColumnBreaks());
} }