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,63 +1448,10 @@ 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.
* @return PrintGridlinesRecord for the sheet. * @return PrintGridlinesRecord for the sheet.
@ -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,8 +105,8 @@ 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()) {
case HorizontalPageBreakRecord.sid: case HorizontalPageBreakRecord.sid:
@ -155,365 +155,365 @@ 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
*
*/
public void removeColumnBreak(int column) {
getColumnBreaksRecord().removeBreak(column);
}
/**
* Removes a page break at the indicated column
*
*/
public void removeColumnBreak(short 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) {
rv.visitRecord(r); rv.visitRecord(r);
} }
} }
/**
* creates the Header Record and sets it to nothing/0 length
*/
private static HeaderRecord createHeader() {
HeaderRecord retval = new HeaderRecord();
retval.setHeaderLength(( byte ) 0); /**
retval.setHeader(null); * creates the Header Record and sets it to nothing/0 length
return retval; */
} private static HeaderRecord createHeader() {
HeaderRecord retval = new HeaderRecord();
/** retval.setHeaderLength(( byte ) 0);
* creates the Footer Record and sets it to nothing/0 length retval.setHeader(null);
*/ return retval;
private static FooterRecord createFooter() { }
FooterRecord retval = new FooterRecord();
retval.setFooterLength(( byte ) 0); /**
retval.setFooter(null); * creates the Footer Record and sets it to nothing/0 length
return retval; */
} private static FooterRecord createFooter() {
FooterRecord retval = new FooterRecord();
/** retval.setFooterLength(( byte ) 0);
* creates the HCenter Record and sets it to false (don't horizontally center) retval.setFooter(null);
*/ return retval;
private static HCenterRecord createHCenter() { }
HCenterRecord retval = new HCenterRecord();
retval.setHCenter(false); /**
return retval; * creates the HCenter Record and sets it to false (don't horizontally center)
} */
private static HCenterRecord createHCenter() {
HCenterRecord retval = new HCenterRecord();
/** retval.setHCenter(false);
* creates the VCenter Record and sets it to false (don't horizontally center) return retval;
*/ }
private static VCenterRecord createVCenter() {
VCenterRecord retval = new VCenterRecord();
retval.setVCenter(false); /**
return retval; * creates the VCenter Record and sets it to false (don't horizontally center)
} */
private static VCenterRecord createVCenter() {
VCenterRecord retval = new VCenterRecord();
/** retval.setVCenter(false);
* creates the PrintSetup Record and sets it to defaults and marks it invalid return retval;
* @see org.apache.poi.hssf.record.PrintSetupRecord }
* @see org.apache.poi.hssf.record.Record
* @return record containing a PrintSetupRecord
*/
private static PrintSetupRecord createPrintSetup() {
PrintSetupRecord retval = new PrintSetupRecord();
retval.setPaperSize(( short ) 1); /**
retval.setScale(( short ) 100); * creates the PrintSetup Record and sets it to defaults and marks it invalid
retval.setPageStart(( short ) 1); * @see org.apache.poi.hssf.record.PrintSetupRecord
retval.setFitWidth(( short ) 1); * @see org.apache.poi.hssf.record.Record
retval.setFitHeight(( short ) 1); * @return record containing a PrintSetupRecord
retval.setOptions(( short ) 2); */
retval.setHResolution(( short ) 300); private static PrintSetupRecord createPrintSetup() {
retval.setVResolution(( short ) 300); PrintSetupRecord retval = new PrintSetupRecord();
retval.setHeaderMargin( 0.5);
retval.setFooterMargin( 0.5);
retval.setCopies(( short ) 0);
return retval;
}
/**
* Returns the HeaderRecord.
* @return HeaderRecord for the sheet.
*/
public HeaderRecord getHeader ()
{
return header;
}
/** retval.setPaperSize(( short ) 1);
* Sets the HeaderRecord. retval.setScale(( short ) 100);
* @param newHeader The new HeaderRecord for the sheet. retval.setPageStart(( short ) 1);
*/ retval.setFitWidth(( short ) 1);
public void setHeader (HeaderRecord newHeader) retval.setFitHeight(( short ) 1);
{ retval.setOptions(( short ) 2);
header = newHeader; retval.setHResolution(( short ) 300);
} retval.setVResolution(( short ) 300);
retval.setHeaderMargin( 0.5);
retval.setFooterMargin( 0.5);
retval.setCopies(( short ) 0);
return retval;
}
/**
* Returns the FooterRecord.
* @return FooterRecord for the sheet.
*/
public FooterRecord getFooter ()
{
return footer;
}
/** /**
* Sets the FooterRecord. * Returns the HeaderRecord.
* @param newFooter The new FooterRecord for the sheet. * @return HeaderRecord for the sheet.
*/ */
public void setFooter (FooterRecord newFooter) public HeaderRecord getHeader ()
{ {
footer = newFooter; return header;
} }
/** /**
* Returns the PrintSetupRecord. * Sets the HeaderRecord.
* @return PrintSetupRecord for the sheet. * @param newHeader The new HeaderRecord for the sheet.
*/ */
public PrintSetupRecord getPrintSetup () public void setHeader (HeaderRecord newHeader)
{ {
return printSetup; header = newHeader;
} }
/** /**
* Sets the PrintSetupRecord. * Returns the FooterRecord.
* @param newPrintSetup The new PrintSetupRecord for the sheet. * @return FooterRecord for the sheet.
*/ */
public void setPrintSetup (PrintSetupRecord newPrintSetup) public FooterRecord getFooter ()
{ {
printSetup = newPrintSetup; return footer;
} }
/**
private Margin getMarginRec(int marginIndex) { * Sets the FooterRecord.
switch (marginIndex) { * @param newFooter The new FooterRecord for the sheet.
case Sheet.LeftMargin: return _leftMargin; */
case Sheet.RightMargin: return _rightMargin; public void setFooter (FooterRecord newFooter)
case Sheet.TopMargin: return _topMargin; {
case Sheet.BottomMargin: return _bottomMargin; footer = newFooter;
} }
throw new RuntimeException( "Unknown margin constant: " + marginIndex );
}
/** /**
* Gets the size of the margin in inches. * Returns the PrintSetupRecord.
* @param margin which margin to get * @return PrintSetupRecord for the sheet.
* @return the size of the margin */
*/ public PrintSetupRecord getPrintSetup ()
{
return printSetup;
}
/**
* Sets the PrintSetupRecord.
* @param newPrintSetup The new PrintSetupRecord for the sheet.
*/
public void setPrintSetup (PrintSetupRecord newPrintSetup)
{
printSetup = newPrintSetup;
}
private Margin getMarginRec(int marginIndex) {
switch (marginIndex) {
case Sheet.LeftMargin: return _leftMargin;
case Sheet.RightMargin: return _rightMargin;
case Sheet.TopMargin: return _topMargin;
case Sheet.BottomMargin: return _bottomMargin;
}
throw new RuntimeException( "Unknown margin constant: " + marginIndex );
}
/**
* 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) { 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
* @param breaks The page record to be shifted
* @param start Starting "main" value to shift breaks
* @param stop Ending "main" value to shift breaks
* @param count number of units (rows/columns) to shift by
*/
private static void shiftBreaks(PageBreakRecord breaks, int start, int stop, int count) {
Iterator iterator = breaks.getBreaksIterator(); /**
List shiftedBreak = new ArrayList(); * Shifts all the page breaks in the range "count" number of rows/columns
while(iterator.hasNext()) * @param breaks The page record to be shifted
{ * @param start Starting "main" value to shift breaks
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); * @param stop Ending "main" value to shift breaks
int breakLocation = breakItem.main; * @param count number of units (rows/columns) to shift by
boolean inStart = (breakLocation >= start); */
boolean inEnd = (breakLocation <= stop); private static void shiftBreaks(PageBreakRecord breaks, int start, int stop, int count) {
if(inStart && inEnd)
shiftedBreak.add(breakItem);
}
iterator = shiftedBreak.iterator(); Iterator iterator = breaks.getBreaksIterator();
while (iterator.hasNext()) { List shiftedBreak = new ArrayList();
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); while(iterator.hasNext())
breaks.removeBreak(breakItem.main); {
breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo); PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
} int breakLocation = breakItem.main;
} boolean inStart = (breakLocation >= start);
boolean inEnd = (breakLocation <= stop);
if(inStart && inEnd)
/** shiftedBreak.add(breakItem);
* Sets a page break at the indicated row }
* @param row
*/
public void setRowBreak(int row, short fromCol, short toCol) {
getRowBreaksRecord().addBreak((short)row, fromCol, toCol);
}
/** iterator = shiftedBreak.iterator();
* Removes a page break at the indicated row while (iterator.hasNext()) {
* @param row PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
*/ breaks.removeBreak(breakItem.main);
public void removeRowBreak(int row) { breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo);
if (getRowBreaksRecord().getBreaks().length < 1) }
throw new IllegalArgumentException("Sheet does not define any row breaks"); }
getRowBreaksRecord().removeBreak((short)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 getRowBreaksRecord().getBreak(row) != null;
}
/** /**
* Queries if the specified column has a page break * Sets a page break at the indicated row
* * @param row
* @return <code>true</code> if the specified column has a page break */
*/ public void setRowBreak(int row, short fromCol, short toCol) {
public boolean isColumnBroken(short column) { getRowBreaksRecord().addBreak((short)row, fromCol, toCol);
return getColumnBreaksRecord().getBreak(column) != null; }
}
/** /**
* Shifts the horizontal page breaks for the indicated count * Removes a page break at the indicated row
* @param startingRow * @param row
* @param endingRow */
* @param count public void removeRowBreak(int row) {
*/ if (getRowBreaksRecord().getBreaks().length < 1)
public void shiftRowBreaks(int startingRow, int endingRow, int count) { throw new IllegalArgumentException("Sheet does not define any row breaks");
shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count); getRowBreaksRecord().removeBreak((short)row);
} }
/** /**
* Shifts the vertical page breaks for the indicated count * Queries if the specified row has a page break
* @param startingCol * @param row
* @param endingCol * @return true if the specified row has a page break
* @param count */
*/ public boolean isRowBroken(int row) {
public void shiftColumnBreaks(short startingCol, short endingCol, short count) { return getRowBreaksRecord().getBreak(row) != null;
shiftBreaks(getColumnBreaksRecord(), startingCol, endingCol, count); }
}
/**
* @return all the horizontal page breaks, never <code>null</code>
*/
public int[] getRowBreaks() {
return getRowBreaksRecord().getBreaks();
}
/** /**
* @return the number of row page breaks * Queries if the specified column has a page break
*/ *
public int getNumRowBreaks(){ * @return <code>true</code> if the specified column has a page break
return getRowBreaksRecord().getNumBreaks(); */
} public boolean isColumnBroken(int column) {
return getColumnBreaksRecord().getBreak(column) != null;
}
/** /**
* @return all the column page breaks, never <code>null</code> * Shifts the horizontal page breaks for the indicated count
*/ * @param startingRow
public int[] getColumnBreaks(){ * @param endingRow
return getColumnBreaksRecord().getBreaks(); * @param count
} */
public void shiftRowBreaks(int startingRow, int endingRow, int count) {
shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count);
}
/** /**
* @return the number of column page breaks * Shifts the vertical page breaks for the indicated count
*/ * @param startingCol
public int getNumColumnBreaks(){ * @param endingCol
return getColumnBreaksRecord().getNumBreaks(); * @param count
} */
public void shiftColumnBreaks(short startingCol, short endingCol, short count) {
shiftBreaks(getColumnBreaksRecord(), startingCol, endingCol, count);
}
/**
* @return all the horizontal page breaks, never <code>null</code>
*/
public int[] getRowBreaks() {
return getRowBreaksRecord().getBreaks();
}
/**
* @return the number of row page breaks
*/
public int getNumRowBreaks(){
return getRowBreaksRecord().getNumBreaks();
}
/**
* @return all the column page breaks, never <code>null</code>
*/
public int[] getColumnBreaks(){
return getColumnBreaksRecord().getBreaks();
}
/**
* @return the number of column page breaks
*/
public int getNumColumnBreaks(){
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());
} }