FileDocCategorySizeDatePackage
Sheet.javaAPI DocApache Poi 3.0.110313Thu May 31 18:45:28 BST 2007org.apache.poi.hslf.model

Sheet

public abstract class Sheet extends Object
This class defines the common format of "Sheets" in a powerpoint document. Such sheets could be Slides, Notes, Master etc
author
Nick Burch
author
Yegor Kozlov

Fields Summary
private SlideShow
_slideShow
The SlideShow we belong to
private Background
_background
Sheet background
private SheetContainer
_container
Record container that holds sheet data. For slides it is org.apache.poi.hslf.record.Slide, for notes it is org.apache.poi.hslf.record.Notes, for slide masters it is org.apache.poi.hslf.record.SlideMaster, etc.
private int
_sheetNo
Constructors Summary
public Sheet(SheetContainer container, int sheetNo)

        _container = container;
        _sheetNo = sheetNo;
    
Methods Summary
public int_getSheetNumber()
Returns the (internal, SlideIdentifier based) sheet number, as used to reference this sheet from other records.

        return _sheetNo;
    
public int_getSheetRefId()
Returns the (internal, RefID based) sheet number, as used to in PersistPtr stuff.

        return _container.getSheetId();
    
public voidaddShape(org.apache.poi.hslf.model.Shape shape)
Add a new Shape to this Slide

param
shape - the Shape to add

        PPDrawing ppdrawing = getPPDrawing();

        EscherContainerRecord dgContainer = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
        EscherContainerRecord spgr = (EscherContainerRecord) Shape.getEscherChild(dgContainer, EscherContainerRecord.SPGR_CONTAINER);
        spgr.addChildRecord(shape.getSpContainer());

        EscherDgRecord dg = (EscherDgRecord) Shape.getEscherChild(dgContainer, EscherDgRecord.RECORD_ID);
        dg.setNumShapes(dg.getNumShapes() + 1);

        int shapeId = dg.getLastMSOSPID()+1;
        dg.setLastMSOSPID(shapeId);

        EscherSpRecord sp = shape.getSpContainer().getChildById(EscherSpRecord.RECORD_ID);
        if(sp != null) sp.setShapeId(shapeId);
        shape.setSheet(this);
        shape.afterInsert(this);

        // If it's a TextBox, we need to tell the PPDrawing, as it has to
        //  track TextboxWrappers specially
        if (shape instanceof TextBox) {
            TextBox tbox = (TextBox) shape;
            ppdrawing.addTextboxWrapper(tbox._txtbox);
        }
    
protected static voidfindTextRuns(org.apache.poi.hslf.record.Record[] records, java.util.Vector found)
Scans through the supplied record array, looking for a TextHeaderAtom followed by one of a TextBytesAtom or a TextCharsAtom. Builds up TextRuns from these

param
records the records to build from
param
found vector to add any found to

        // Look for a TextHeaderAtom
        for (int i = 0; i < (records.length - 1); i++) {
            if (records[i] instanceof TextHeaderAtom) {
                TextRun trun = null;
                TextHeaderAtom tha = (TextHeaderAtom) records[i];
                StyleTextPropAtom stpa = null;

                // Look for a subsequent StyleTextPropAtom
                if (i < (records.length - 2)) {
                    if (records[i + 2] instanceof StyleTextPropAtom) {
                        stpa = (StyleTextPropAtom) records[i + 2];
                    }
                }

                // See what follows the TextHeaderAtom
                if (records[i + 1] instanceof TextCharsAtom) {
                    TextCharsAtom tca = (TextCharsAtom) records[i + 1];
                    trun = new TextRun(tha, tca, stpa);
                } else if (records[i + 1] instanceof TextBytesAtom) {
                    TextBytesAtom tba = (TextBytesAtom) records[i + 1];
                    trun = new TextRun(tha, tba, stpa);
                } else if (records[i + 1].getRecordType() == 4001l) {
                    // StyleTextPropAtom - Safe to ignore
                } else if (records[i + 1].getRecordType() == 4010l) {
                    // TextSpecInfoAtom - Safe to ignore
                } else {
                    System.err.println("Found a TextHeaderAtom not followed by a TextBytesAtom or TextCharsAtom: Followed by " + records[i + 1].getRecordType());
                    continue;
                }

                if (trun != null) {
                    ArrayList lst = new ArrayList();
                    for (int j = i; j < records.length; j++) {
                        if(j > i && records[j] instanceof TextHeaderAtom) break;
                        lst.add(records[j]);
                    }
                    Record[] recs = new Record[lst.size()];
                    lst.toArray(recs);
                    trun._records = recs;
                    
                    found.add(trun);
                    i++;
                } else {
                    // Not a valid one, so skip on to next and look again
                }
            }
        }
    
public static org.apache.poi.hslf.model.TextRun[]findTextRuns(org.apache.poi.hslf.record.PPDrawing ppdrawing)
For a given PPDrawing, grab all the TextRuns

        Vector runsV = new Vector();
        EscherTextboxWrapper[] wrappers = ppdrawing.getTextboxWrappers();
        for (int i = 0; i < wrappers.length; i++) {
            int s1 = runsV.size();
            findTextRuns(wrappers[i].getChildRecords(), runsV);
            int s2 = runsV.size();
            if (s2 != s1){
                TextRun t = (TextRun) runsV.get(runsV.size()-1);
                t.setShapeId(wrappers[i].getShapeId());
            }
        }
        TextRun[] runs = new TextRun[runsV.size()];
        for (int i = 0; i < runs.length; i++) {
            runs[i] = (TextRun) runsV.get(i);
        }
        return runs;
    
public org.apache.poi.hslf.model.BackgroundgetBackground()
Returns the background shape for this sheet.

return
the background shape for this sheet.

        if (_background == null) {
            PPDrawing ppdrawing = getPPDrawing();

            EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
            EscherContainerRecord spContainer = null;
            List ch = dg.getChildRecords();

            for (Iterator it = ch.iterator(); it.hasNext();) {
                EscherRecord rec = (EscherRecord) it.next();
                if (rec.getRecordId() == EscherContainerRecord.SP_CONTAINER) {
                    spContainer = (EscherContainerRecord) rec;
                    break;
                }
            }
            _background = new Background(spContainer, null);
            _background.setSheet(this);
        }
        return _background;
    
public org.apache.poi.hslf.record.ColorSchemeAtomgetColorScheme()
Color scheme for this sheet.

        return _container.getColorScheme();
    
public abstract org.apache.poi.hslf.model.MasterSheetgetMasterSheet()
Return the master sheet .

protected org.apache.poi.hslf.record.PPDrawinggetPPDrawing()
Fetch the PPDrawing from the underlying record

        return _container.getPPDrawing();
    
public org.apache.poi.hslf.model.Shape[]getShapes()
Returns all shapes contained in this Sheet

return
all shapes contained in this Sheet (Slide or Notes)

        PPDrawing ppdrawing = getPPDrawing();

        EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
        EscherContainerRecord spgr = null;
        List ch = dg.getChildRecords();

        for (Iterator it = ch.iterator(); it.hasNext();) {
            EscherRecord rec = (EscherRecord) it.next();
            if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
                spgr = (EscherContainerRecord) rec;
                break;
            }
        }
        ch = spgr.getChildRecords();

        ArrayList shapes = new ArrayList();
        for (int i = 1; i < ch.size(); i++) {
            EscherContainerRecord sp = (EscherContainerRecord) ch.get(i);
            Shape sh = ShapeFactory.createShape(sp, null);
            sh.setSheet(this);
            shapes.add(sh);
        }

        return (Shape[]) shapes.toArray(new Shape[shapes.size()]);
    
public org.apache.poi.hslf.record.SheetContainergetSheetContainer()
Return record container for this sheet

        return _container;
    
public org.apache.poi.hslf.usermodel.SlideShowgetSlideShow()
Fetch the SlideShow we're attached to

        return _slideShow;
    
public abstract org.apache.poi.hslf.model.TextRun[]getTextRuns()
Returns an array of all the TextRuns in the sheet.

public voidsetSlideShow(org.apache.poi.hslf.usermodel.SlideShow ss)
Set the SlideShow we're attached to. Also passes it on to our child RichTextRuns

        _slideShow = ss;
        TextRun[] trs = getTextRuns();
        if (trs != null) {
            for (int i = 0; i < trs.length; i++) {
                trs[i].supplySlideShow(_slideShow);
            }
        }