mirror of https://github.com/apache/poi.git
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:
parent
ad181534cf
commit
56f2ad8eb9
|
@ -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,63 +1448,10 @@ 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.
|
||||
* @return PrintGridlinesRecord for the sheet.
|
||||
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -62,31 +62,31 @@ public final class PageSettingsBlock extends RecordAggregate {
|
|||
private PrintSetupRecord printSetup;
|
||||
private Record _bitmap;
|
||||
|
||||
public PageSettingsBlock(RecordStream rs) {
|
||||
while(true) {
|
||||
if (!readARecord(rs)) {
|
||||
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();
|
||||
public PageSettingsBlock(RecordStream rs) {
|
||||
while(true) {
|
||||
if (!readARecord(rs)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the specified Record sid is one belonging to the
|
||||
* 'Page Settings Block'.
|
||||
*/
|
||||
/**
|
||||
* 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
|
||||
* 'Page Settings Block'.
|
||||
*/
|
||||
public static boolean isComponentRecord(int sid) {
|
||||
switch (sid) {
|
||||
case HorizontalPageBreakRecord.sid:
|
||||
|
@ -105,8 +105,8 @@ public final class PageSettingsBlock extends RecordAggregate {
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean readARecord(RecordStream rs) {
|
||||
switch (rs.peekNextSid()) {
|
||||
case HorizontalPageBreakRecord.sid:
|
||||
|
@ -155,365 +155,365 @@ public final class PageSettingsBlock extends RecordAggregate {
|
|||
return true;
|
||||
}
|
||||
|
||||
private PageBreakRecord getRowBreaksRecord() {
|
||||
if (_rowBreaksRecord == null) {
|
||||
_rowBreaksRecord = new HorizontalPageBreakRecord();
|
||||
}
|
||||
return _rowBreaksRecord;
|
||||
}
|
||||
|
||||
private PageBreakRecord getColumnBreaksRecord() {
|
||||
if (_columnBreaksRecord == null) {
|
||||
_columnBreaksRecord = new VerticalPageBreakRecord();
|
||||
}
|
||||
return _columnBreaksRecord;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a page break at the indicated column
|
||||
*
|
||||
*/
|
||||
public void setColumnBreak(short column, short fromRow, short toRow) {
|
||||
getColumnBreaksRecord().addBreak(column, fromRow, toRow);
|
||||
}
|
||||
private PageBreakRecord getRowBreaksRecord() {
|
||||
if (_rowBreaksRecord == null) {
|
||||
_rowBreaksRecord = new HorizontalPageBreakRecord();
|
||||
}
|
||||
return _rowBreaksRecord;
|
||||
}
|
||||
|
||||
private PageBreakRecord getColumnBreaksRecord() {
|
||||
if (_columnBreaksRecord == null) {
|
||||
_columnBreaksRecord = new VerticalPageBreakRecord();
|
||||
}
|
||||
return _columnBreaksRecord;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a page break at the indicated column
|
||||
*
|
||||
*/
|
||||
public void setColumnBreak(short column, short fromRow, short 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) {
|
||||
visitIfPresent(_rowBreaksRecord, rv);
|
||||
visitIfPresent(_columnBreaksRecord, rv);
|
||||
visitIfPresent(header, rv);
|
||||
visitIfPresent(footer, rv);
|
||||
visitIfPresent(_hCenter, rv);
|
||||
visitIfPresent(_vCenter, rv);
|
||||
visitIfPresent(_leftMargin, rv);
|
||||
visitIfPresent(_rightMargin, rv);
|
||||
visitIfPresent(_topMargin, rv);
|
||||
visitIfPresent(_bottomMargin, rv);
|
||||
visitIfPresent(_pls, rv);
|
||||
visitIfPresent(printSetup, rv);
|
||||
visitIfPresent(_bitmap, rv);
|
||||
visitIfPresent(_rowBreaksRecord, rv);
|
||||
visitIfPresent(_columnBreaksRecord, rv);
|
||||
visitIfPresent(header, rv);
|
||||
visitIfPresent(footer, rv);
|
||||
visitIfPresent(_hCenter, rv);
|
||||
visitIfPresent(_vCenter, rv);
|
||||
visitIfPresent(_leftMargin, rv);
|
||||
visitIfPresent(_rightMargin, rv);
|
||||
visitIfPresent(_topMargin, rv);
|
||||
visitIfPresent(_bottomMargin, rv);
|
||||
visitIfPresent(_pls, rv);
|
||||
visitIfPresent(printSetup, rv);
|
||||
visitIfPresent(_bitmap, rv);
|
||||
}
|
||||
private static void visitIfPresent(Record r, RecordVisitor rv) {
|
||||
if (r != null) {
|
||||
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);
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* creates the Header Record and sets it to nothing/0 length
|
||||
*/
|
||||
private static HeaderRecord createHeader() {
|
||||
HeaderRecord retval = new HeaderRecord();
|
||||
|
||||
/**
|
||||
* creates the Footer Record and sets it to nothing/0 length
|
||||
*/
|
||||
private static FooterRecord createFooter() {
|
||||
FooterRecord retval = new FooterRecord();
|
||||
retval.setHeaderLength(( byte ) 0);
|
||||
retval.setHeader(null);
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval.setFooterLength(( byte ) 0);
|
||||
retval.setFooter(null);
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* creates the Footer Record and sets it to nothing/0 length
|
||||
*/
|
||||
private static FooterRecord createFooter() {
|
||||
FooterRecord retval = new FooterRecord();
|
||||
|
||||
/**
|
||||
* creates the HCenter Record and sets it to false (don't horizontally center)
|
||||
*/
|
||||
private static HCenterRecord createHCenter() {
|
||||
HCenterRecord retval = new HCenterRecord();
|
||||
retval.setFooterLength(( byte ) 0);
|
||||
retval.setFooter(null);
|
||||
return retval;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
/**
|
||||
* creates the VCenter Record and sets it to false (don't horizontally center)
|
||||
*/
|
||||
private static VCenterRecord createVCenter() {
|
||||
VCenterRecord retval = new VCenterRecord();
|
||||
retval.setHCenter(false);
|
||||
return retval;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
/**
|
||||
* 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.Record
|
||||
* @return record containing a PrintSetupRecord
|
||||
*/
|
||||
private static PrintSetupRecord createPrintSetup() {
|
||||
PrintSetupRecord retval = new PrintSetupRecord();
|
||||
retval.setVCenter(false);
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval.setPaperSize(( short ) 1);
|
||||
retval.setScale(( short ) 100);
|
||||
retval.setPageStart(( short ) 1);
|
||||
retval.setFitWidth(( short ) 1);
|
||||
retval.setFitHeight(( short ) 1);
|
||||
retval.setOptions(( short ) 2);
|
||||
retval.setHResolution(( short ) 300);
|
||||
retval.setVResolution(( short ) 300);
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* 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.Record
|
||||
* @return record containing a PrintSetupRecord
|
||||
*/
|
||||
private static PrintSetupRecord createPrintSetup() {
|
||||
PrintSetupRecord retval = new PrintSetupRecord();
|
||||
|
||||
/**
|
||||
* Sets the HeaderRecord.
|
||||
* @param newHeader The new HeaderRecord for the sheet.
|
||||
*/
|
||||
public void setHeader (HeaderRecord newHeader)
|
||||
{
|
||||
header = newHeader;
|
||||
}
|
||||
retval.setPaperSize(( short ) 1);
|
||||
retval.setScale(( short ) 100);
|
||||
retval.setPageStart(( short ) 1);
|
||||
retval.setFitWidth(( short ) 1);
|
||||
retval.setFitHeight(( short ) 1);
|
||||
retval.setOptions(( short ) 2);
|
||||
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.
|
||||
* @param newFooter The new FooterRecord for the sheet.
|
||||
*/
|
||||
public void setFooter (FooterRecord newFooter)
|
||||
{
|
||||
footer = newFooter;
|
||||
}
|
||||
/**
|
||||
* Returns the HeaderRecord.
|
||||
* @return HeaderRecord for the sheet.
|
||||
*/
|
||||
public HeaderRecord getHeader ()
|
||||
{
|
||||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PrintSetupRecord.
|
||||
* @return PrintSetupRecord for the sheet.
|
||||
*/
|
||||
public PrintSetupRecord getPrintSetup ()
|
||||
{
|
||||
return printSetup;
|
||||
}
|
||||
/**
|
||||
* Sets the HeaderRecord.
|
||||
* @param newHeader The new HeaderRecord for the sheet.
|
||||
*/
|
||||
public void setHeader (HeaderRecord newHeader)
|
||||
{
|
||||
header = newHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the PrintSetupRecord.
|
||||
* @param newPrintSetup The new PrintSetupRecord for the sheet.
|
||||
*/
|
||||
public void setPrintSetup (PrintSetupRecord newPrintSetup)
|
||||
{
|
||||
printSetup = newPrintSetup;
|
||||
}
|
||||
/**
|
||||
* Returns the FooterRecord.
|
||||
* @return FooterRecord for the sheet.
|
||||
*/
|
||||
public FooterRecord getFooter ()
|
||||
{
|
||||
return footer;
|
||||
}
|
||||
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the FooterRecord.
|
||||
* @param newFooter The new FooterRecord for the sheet.
|
||||
*/
|
||||
public void setFooter (FooterRecord newFooter)
|
||||
{
|
||||
footer = newFooter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the margin in inches.
|
||||
* @param margin which margin to get
|
||||
* @return the size of the margin
|
||||
*/
|
||||
/**
|
||||
* Returns the PrintSetupRecord.
|
||||
* @return PrintSetupRecord for the sheet.
|
||||
*/
|
||||
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) {
|
||||
Margin m = getMarginRec(margin);
|
||||
if (m != null) {
|
||||
return m.getMargin();
|
||||
} else {
|
||||
switch ( margin )
|
||||
{
|
||||
case Sheet.LeftMargin:
|
||||
return .75;
|
||||
case Sheet.RightMargin:
|
||||
return .75;
|
||||
case Sheet.TopMargin:
|
||||
return 1.0;
|
||||
case Sheet.BottomMargin:
|
||||
return 1.0;
|
||||
}
|
||||
throw new RuntimeException( "Unknown margin constant: " + margin );
|
||||
switch ( margin )
|
||||
{
|
||||
case Sheet.LeftMargin:
|
||||
return .75;
|
||||
case Sheet.RightMargin:
|
||||
return .75;
|
||||
case Sheet.TopMargin:
|
||||
return 1.0;
|
||||
case Sheet.BottomMargin:
|
||||
return 1.0;
|
||||
}
|
||||
throw new RuntimeException( "Unknown margin constant: " + margin );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the margin in inches.
|
||||
* @param margin which margin to get
|
||||
* @param size the size of the 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) {
|
||||
Margin m = getMarginRec(margin);
|
||||
if (m == null) {
|
||||
switch ( margin )
|
||||
{
|
||||
case Sheet.LeftMargin:
|
||||
_leftMargin = new LeftMarginRecord();
|
||||
m = _leftMargin;
|
||||
break;
|
||||
case Sheet.RightMargin:
|
||||
_rightMargin = new RightMarginRecord();
|
||||
m = _rightMargin;
|
||||
break;
|
||||
case Sheet.TopMargin:
|
||||
_topMargin = new TopMarginRecord();
|
||||
m = _topMargin;
|
||||
break;
|
||||
case Sheet.BottomMargin:
|
||||
_bottomMargin = new BottomMarginRecord();
|
||||
m = _bottomMargin;
|
||||
break;
|
||||
default :
|
||||
throw new RuntimeException( "Unknown margin constant: " + margin );
|
||||
}
|
||||
switch ( margin )
|
||||
{
|
||||
case Sheet.LeftMargin:
|
||||
_leftMargin = new LeftMarginRecord();
|
||||
m = _leftMargin;
|
||||
break;
|
||||
case Sheet.RightMargin:
|
||||
_rightMargin = new RightMarginRecord();
|
||||
m = _rightMargin;
|
||||
break;
|
||||
case Sheet.TopMargin:
|
||||
_topMargin = new TopMarginRecord();
|
||||
m = _topMargin;
|
||||
break;
|
||||
case Sheet.BottomMargin:
|
||||
_bottomMargin = new BottomMarginRecord();
|
||||
m = _bottomMargin;
|
||||
break;
|
||||
default :
|
||||
throw new RuntimeException( "Unknown margin constant: " + margin );
|
||||
}
|
||||
}
|
||||
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();
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* 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 = shiftedBreak.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
|
||||
breaks.removeBreak(breakItem.main);
|
||||
breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 iterator = breaks.getBreaksIterator();
|
||||
List shiftedBreak = new ArrayList();
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a page break at the indicated row
|
||||
* @param row
|
||||
*/
|
||||
public void removeRowBreak(int row) {
|
||||
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;
|
||||
}
|
||||
iterator = shiftedBreak.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
|
||||
breaks.removeBreak(breakItem.main);
|
||||
breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 getColumnBreaksRecord().getBreak(column) != null;
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shifts the horizontal page breaks for the indicated count
|
||||
* @param startingRow
|
||||
* @param endingRow
|
||||
* @param count
|
||||
*/
|
||||
public void shiftRowBreaks(int startingRow, int endingRow, int count) {
|
||||
shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count);
|
||||
}
|
||||
/**
|
||||
* Removes a page break at the indicated row
|
||||
* @param row
|
||||
*/
|
||||
public void removeRowBreak(int row) {
|
||||
if (getRowBreaksRecord().getBreaks().length < 1)
|
||||
throw new IllegalArgumentException("Sheet does not define any row breaks");
|
||||
getRowBreaksRecord().removeBreak((short)row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shifts the vertical page breaks for the indicated count
|
||||
* @param startingCol
|
||||
* @param endingCol
|
||||
* @param count
|
||||
*/
|
||||
public void shiftColumnBreaks(short startingCol, short endingCol, short count) {
|
||||
shiftBreaks(getColumnBreaksRecord(), startingCol, endingCol, count);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
/**
|
||||
* Queries if the specified column has a page break
|
||||
*
|
||||
* @return <code>true</code> if the specified column has a page break
|
||||
*/
|
||||
public boolean isColumnBroken(int column) {
|
||||
return getColumnBreaksRecord().getBreak(column) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the column page breaks, never <code>null</code>
|
||||
*/
|
||||
public int[] getColumnBreaks(){
|
||||
return getColumnBreaksRecord().getBreaks();
|
||||
}
|
||||
/**
|
||||
* Shifts the horizontal page breaks for the indicated count
|
||||
* @param startingRow
|
||||
* @param endingRow
|
||||
* @param count
|
||||
*/
|
||||
public void shiftRowBreaks(int startingRow, int endingRow, int count) {
|
||||
shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of column page breaks
|
||||
*/
|
||||
public int getNumColumnBreaks(){
|
||||
return getColumnBreaksRecord().getNumBreaks();
|
||||
}
|
||||
/**
|
||||
* Shifts the vertical page breaks for the indicated count
|
||||
* @param startingCol
|
||||
* @param endingCol
|
||||
* @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() {
|
||||
return _vCenter;
|
||||
|
@ -522,5 +522,4 @@ public final class PageSettingsBlock extends RecordAggregate {
|
|||
public HCenterRecord getHCenter() {
|
||||
return _hCenter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue