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.EOFRecord;
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.GutsRecord;
import org.apache.poi.hssf.record.HeaderRecord;
import org.apache.poi.hssf.record.IndexRecord;
import org.apache.poi.hssf.record.IterationRecord;
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.PrintGridlinesRecord;
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.Record;
import org.apache.poi.hssf.record.RecordBase;
@ -1451,62 +1448,9 @@ public final class Sheet implements Model {
return -1;
}
/**
* Returns the HeaderRecord.
* @return HeaderRecord for the sheet.
*/
public HeaderRecord getHeader ()
{
return getPageSettings().getHeader();
}
public WindowTwoRecord getWindowTwo() {
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.
@ -1534,24 +1478,6 @@ public final class Sheet implements Model {
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()
{
return eofLoc;
@ -1878,103 +1804,6 @@ public final class Sheet implements Model {
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 )
{

View File

@ -182,7 +182,7 @@ public final class PageSettingsBlock extends RecordAggregate {
* Removes a page break at the indicated column
*
*/
public void removeColumnBreak(short column) {
public void removeColumnBreak(int column) {
getColumnBreaksRecord().removeBreak(column);
}
@ -463,7 +463,7 @@ public final class PageSettingsBlock extends RecordAggregate {
*
* @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;
}
@ -522,5 +522,4 @@ public final class PageSettingsBlock extends RecordAggregate {
public HCenterRecord getHCenter() {
return _hCenter;
}
}

View File

@ -871,7 +871,7 @@ public final class HSSFSheet {
*/
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()
{
return new HSSFHeader( getSheet().getHeader() );
return new HSSFHeader( sheet.getPageSettings().getHeader() );
}
/**
@ -889,7 +889,7 @@ public final class HSSFSheet {
*/
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 )
{
return getSheet().getMargin( margin );
return sheet.getPageSettings().getMargin( margin );
}
/**
@ -939,7 +939,7 @@ public final class HSSFSheet {
*/
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);
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 )
{
@ -1393,24 +1393,21 @@ public final class HSSFSheet {
*/
public void setRowBreak(int 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
* @param row FIXME: Document this!
* @return FIXME: Document this!
* @return <code>true</code> if there is a page break at the indicated row
*/
public boolean isRowBroken(int row) {
return sheet.isRowBroken(row);
return sheet.getPageSettings().isRowBroken(row);
}
/**
* Removes the page break at the indicated row
* @param row
*/
public void removeRowBreak(int row) {
sheet.removeRowBreak(row);
sheet.getPageSettings().removeRowBreak(row);
}
/**
@ -1418,7 +1415,7 @@ public final class HSSFSheet {
*/
public int[] getRowBreaks(){
//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(){
//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) {
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!
*/
public boolean isColumnBroken(short column) {
return sheet.isColumnBroken(column);
return sheet.getPageSettings().isColumnBroken(column);
}
/**
@ -1453,7 +1450,7 @@ public final class HSSFSheet {
* @param 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.UncalcedRecord;
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.util.CellRangeAddress;
@ -207,7 +208,8 @@ public final class TestSheet extends TestCase {
short colFrom = 0;
short colTo = 255;
Sheet sheet = Sheet.createSheet();
Sheet worksheet = Sheet.createSheet();
PageSettingsBlock sheet = worksheet.getPageSettings();
sheet.setRowBreak(0, colFrom, colTo);
assertTrue("no row break at 0", sheet.isRowBroken(0));
@ -262,24 +264,25 @@ public final class TestSheet extends TestCase {
short rowFrom = 0;
short rowTo = (short)65535;
Sheet sheet = Sheet.createSheet();
Sheet worksheet = Sheet.createSheet();
PageSettingsBlock sheet = worksheet.getPageSettings();
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());
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());
sheet.setColumnBreak((short)1, rowFrom, rowTo);
sheet.setColumnBreak((short)10, rowFrom, rowTo);
sheet.setColumnBreak((short)15, rowFrom, rowTo);
assertTrue("no col break at 1", sheet.isColumnBroken((short)1));
assertTrue("no col break at 10", sheet.isColumnBroken((short)10));
assertTrue("no col break at 15", sheet.isColumnBroken((short)15));
assertTrue("no col break at 1", sheet.isColumnBroken(1));
assertTrue("no col break at 10", sheet.isColumnBroken(10));
assertTrue("no col break at 15", sheet.isColumnBroken(15));
assertEquals("4 col break available", 4, sheet.getNumColumnBreaks());
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);
sheet.removeColumnBreak((short)15);
assertFalse("column break should not be there", sheet.isColumnBroken((short)15));
sheet.removeColumnBreak(15);
assertFalse("column break should not be there", sheet.isColumnBroken(15));
sheet.removeColumnBreak((short)0);
assertFalse("column break should not be there", sheet.isColumnBroken((short)0));
sheet.removeColumnBreak(0);
assertFalse("column break should not be there", sheet.isColumnBroken(0));
sheet.removeColumnBreak((short)1);
assertFalse("column break should not be there", sheet.isColumnBroken((short)1));
sheet.removeColumnBreak(1);
assertFalse("column break should not be there", sheet.isColumnBroken(1));
sheet.removeColumnBreak((short)10);
assertFalse("column break should not be there", sheet.isColumnBroken((short)10));
sheet.removeColumnBreak(10);
assertFalse("column break should not be there", sheet.isColumnBroken(10));
assertEquals("no more breaks", 0, sheet.getNumColumnBreaks());
}