FileDocCategorySizeDatePackage
PageBreakRecord.javaAPI DocApache Poi 3.0.18066Mon Jan 01 12:39:40 GMT 2007org.apache.poi.hssf.record

PageBreakRecord

public class PageBreakRecord extends Record

Record that contains the functionality page breaks (horizontal and vertical)

The other two classes just specifically set the SIDS for record creation.

REFERENCE: Microsoft Excel SDK page 322 and 420

see
HorizontalPageBreakRecord <<<<<<< PageBreakRecord.java
see
VerticalPageBreakREcord REFERENCE: Microsoft Excel SDK page 322 and 420 =======
see
VerticalPageBreakRecord >>>>>>> 1.5
author
Danny Mui (dmui at apache dot org)

Fields Summary
public static final short
HORIZONTAL_SID
public static final short
VERTICAL_SID
public short
sid
private short
numBreaks
private List
breaks
private Map
BreakMap
Constructors Summary
public PageBreakRecord()


    
public PageBreakRecord(short sid)

param
sid

       super();
       this.sid = sid;
    
public PageBreakRecord(RecordInputStream in)

        super(in);
        this.sid = in.getSid();
    
Methods Summary
public voidaddBreak(short main, short subFrom, short subTo)
Adds the page break at the specified parameters

param
main Depending on sid, will determine row or column to put page break (zero-based)
param
subFrom No user-interface to set (defaults to minumum, 0)
param
subTo No user-interface to set

        if(breaks == null)
        {
            breaks = new ArrayList(getNumBreaks() + 10);
            BreakMap = new HashMap();
        }
        Integer key = new Integer(main);
        Break region = (Break)BreakMap.get(key);
        if(region != null)
        {
            region.main = main;
            region.subFrom = subFrom;
            region.subTo = subTo;
        } else
        {
            region = new Break(main, subFrom, subTo);
            breaks.add(region);
        }
        BreakMap.put(key, region);
    
public java.lang.Objectclone()

      PageBreakRecord record = new PageBreakRecord(getSid());      
      Iterator iterator = getBreaksIterator();
      while (iterator.hasNext()) {
         Break original = (Break)iterator.next();
         record.addBreak(original.main, original.subFrom, original.subTo);
      }
      return record;
   
protected voidfillFields(org.apache.poi.hssf.record.RecordInputStream in)

        short loadedBreaks = in.readShort();
        setNumBreaks(loadedBreaks);
        for(int k = 0; k < loadedBreaks; k++)
        {
            addBreak((short)(in.readShort()-1), in.readShort(), in.readShort());
        }

    
public org.apache.poi.hssf.record.PageBreakRecord$BreakgetBreak(short main)
Retrieves the region at the row/column indicated

param
main FIXME: Document this!
return
The Break or null if no break exists at the row/col specified.

    	if (BreakMap == null)
    		return null;
        Integer rowKey = new Integer(main);
        return (Break)BreakMap.get(rowKey);
    
public java.util.IteratorgetBreaksIterator()

        if(breaks == null)
            return Collections.EMPTY_LIST.iterator();
        else
            return breaks.iterator();
    
public shortgetNumBreaks()

        return breaks != null ? (short)breaks.size() : numBreaks;
    
public intgetRecordSize()

        return 6 + getNumBreaks() * 6;
    
public shortgetSid()

        return sid;
    
public voidremoveBreak(short main)
Removes the break indicated by the parameter

param
main (zero-based)

        Integer rowKey = new Integer(main);
        Break region = (Break)BreakMap.get(rowKey);
        breaks.remove(region);
        BreakMap.remove(rowKey);
    
public intserialize(int offset, byte[] data)

        int recordsize = getRecordSize();
        int pos = 6;
        LittleEndian.putShort(data, offset + 0, getSid());
        LittleEndian.putShort(data, offset + 2, (short)(recordsize - 4));
        LittleEndian.putShort(data, offset + 4, getNumBreaks());
        for(Iterator iterator = getBreaksIterator(); iterator.hasNext();)
        {
            Break Break = (Break)iterator.next();
            LittleEndian.putShort(data, offset + pos, (short)(Break.main + 1));
            pos += 2;
            LittleEndian.putShort(data, offset + pos, Break.subFrom);
            pos += 2;
            LittleEndian.putShort(data, offset + pos, Break.subTo);
            pos += 2;
        }

        return recordsize;
    
public voidsetNumBreaks(short numBreaks)

        this.numBreaks = numBreaks;
    
public java.lang.StringtoString()

        StringBuffer retval = new StringBuffer();
        
        if (getSid() != HORIZONTAL_SID && getSid()!= VERTICAL_SID) 
            return "[INVALIDPAGEBREAK]\n     .sid ="+getSid()+"[INVALIDPAGEBREAK]";
        
        String label;
        String mainLabel;
        String subLabel;
        
        if (getSid() == HORIZONTAL_SID) {
           label = "HORIZONTALPAGEBREAK";
           mainLabel = "row";
           subLabel = "col";
        } else {
           label = "VERTICALPAGEBREAK";
           mainLabel = "column";
           subLabel = "row";
        }
        
        retval.append("["+label+"]").append("\n");
        retval.append("     .sid        =").append(getSid()).append("\n");
        retval.append("     .numbreaks =").append(getNumBreaks()).append("\n");
        Iterator iterator = getBreaksIterator();
        for(int k = 0; k < getNumBreaks(); k++)
        {
            Break region = (Break)iterator.next();
            
            retval.append("     .").append(mainLabel).append(" (zero-based) =").append(region.main).append("\n");
            retval.append("     .").append(subLabel).append("From    =").append(region.subFrom).append("\n");
            retval.append("     .").append(subLabel).append("To      =").append(region.subTo).append("\n");
        }

        retval.append("["+label+"]").append("\n");
        return retval.toString();
    
protected voidvalidateSid(short id)

        if(id != HORIZONTAL_SID && id != VERTICAL_SID)
            throw new RecordFormatException("NOT A HorizontalPageBreak or VerticalPageBreak RECORD!! " + id);
        else
            return;