This class represents a slide in a PowerPoint Document. It allows
access to the text within, and the layout. For now, it only does
the text side of things though
| Constructor: |
public Slide(int sheetNumber,
int sheetRefId,
int slideNumber) {
super(new org.apache.poi.hslf.record.Slide(), sheetNumber);
_slideNo = slideNumber;
getSheetContainer().setSheetId(sheetRefId);
}
Create a new Slide instance Parameters:
sheetNumber - The internal number of the sheet, as used by PersistPtrHolder
slideNumber - The user facing number of the sheet
|
public Slide(Slide slide,
Notes notes,
SlideAtomsSet atomSet,
int slideIdentifier,
int slideNumber) {
super(slide, slideIdentifier);
_notes = notes;
_atomSet = atomSet;
_slideNo = slideNumber;
// Grab the TextRuns from the PPDrawing
TextRun[] _otherRuns = findTextRuns(getPPDrawing());
// For the text coming in from the SlideAtomsSet:
// Build up TextRuns from pairs of TextHeaderAtom and
// one of TextBytesAtom or TextCharsAtom
Vector textRuns = new Vector();
if(_atomSet != null) {
findTextRuns(_atomSet.getSlideRecords(),textRuns);
} else {
// No text on the slide, must just be pictures
}
// Build an array, more useful than a vector
_runs = new TextRun[textRuns.size()+_otherRuns.length];
// Grab text from SlideListWithTexts entries
int i=0;
for(i=0; i< textRuns.size(); i++) {
_runs[i] = (TextRun)textRuns.get(i);
_runs[i].setSheet(this);
}
// Grab text from slide's PPDrawing
for(int k=0; k< _otherRuns.length; i++, k++) {
_runs[i] = _otherRuns[k];
_runs[i].setSheet(this);
}
}
Constructs a Slide from the Slide record, and the SlideAtomsSet
containing the text.
Initialises TextRuns, to provide easier access to the text Parameters:
slide - the Slide record we're based on
notes - the Notes sheet attached to us
atomSet - the SlideAtomsSet to get the text from
|
| Method from org.apache.poi.hslf.model.Slide Detail: |
public TextBox addTitle() {
Placeholder pl = new Placeholder();
pl.setShapeType(ShapeTypes.Rectangle);
pl.getTextRun().setRunType(TextHeaderAtom.TITLE_TYPE);
pl.setText("Click to edit title");
pl.setAnchor(new java.awt.Rectangle(54, 48, 612, 90));
addShape(pl);
return pl;
}
Create a TextBox object that represents the slide's title. |
public void draw(Graphics2D graphics) {
MasterSheet master = getMasterSheet();
if(getFollowMasterBackground()) master.getBackground().draw(graphics);
if(getFollowMasterObjects()){
Shape[] sh = master.getShapes();
for (int i = 0; i < sh.length; i++) {
if(MasterSheet.isPlaceholder(sh[i])) continue;
sh[i].draw(graphics);
}
}
Shape[] sh = getShapes();
for (int i = 0; i < sh.length; i++) {
sh[i].draw(graphics);
}
}
|
public Background getBackground() {
if(getFollowMasterBackground())
return getMasterSheet().getBackground();
else
return super.getBackground();
}
Background for this slide. |
public ColorSchemeAtom getColorScheme() {
if(getFollowMasterScheme()){
return getMasterSheet().getColorScheme();
}
return super.getColorScheme();
}
Color scheme for this slide. |
public boolean getFollowMasterBackground() {
SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterBackground();
}
Whether this slide follows master sheet background |
public boolean getFollowMasterObjects() {
SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterObjects();
}
Whether this slide draws master sheet objects |
public boolean getFollowMasterScheme() {
SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterScheme();
}
Whether this slide follows master color scheme |
public MasterSheet getMasterSheet() {
SlideMaster[] master = getSlideShow().getSlidesMasters();
SlideAtom sa = getSlideRecord().getSlideAtom();
int masterId = sa.getMasterID();
MasterSheet sheet = null;
for (int i = 0; i < master.length; i++) {
if (masterId == master[i]._getSheetNumber()) {
sheet = master[i];
break;
}
}
if (sheet == null){
TitleMaster[] titleMaster = getSlideShow().getTitleMasters();
if(titleMaster != null) for (int i = 0; i < titleMaster.length; i++) {
if (masterId == titleMaster[i]._getSheetNumber()) {
sheet = titleMaster[i];
break;
}
}
}
return sheet;
}
Returns master sheet associated with this slide.
It can be either SlideMaster or TitleMaster objects. |
public Notes getNotesSheet() {
return _notes;
}
Returns the Notes Sheet for this slide, or null if there isn't one |
protected SlideAtomsSet getSlideAtomsSet() {
return _atomSet;
}
|
public int getSlideNumber() {
return _slideNo;
}
Returns the (public facing) page number of this slide |
public Slide getSlideRecord() {
return (org.apache.poi.hslf.record.Slide)getSheetContainer();
}
Returns the underlying slide record |
public TextRun[] getTextRuns() {
return _runs;
}
Returns an array of all the TextRuns found |
public String getTitle() {
TextRun[] txt = getTextRuns();
for (int i = 0; i < txt.length; i++) {
int type = txt[i].getRunType();
if (type == TextHeaderAtom.CENTER_TITLE_TYPE ||
type == TextHeaderAtom.TITLE_TYPE ){
String title = txt[i].getText();
return title;
}
}
return null;
}
|
public void onCreate() {
//initialize drawing group id
EscherDggRecord dgg = getSlideShow().getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
EscherContainerRecord dgContainer = (EscherContainerRecord)getSheetContainer().getPPDrawing().getEscherRecords()[0];
EscherDgRecord dg = (EscherDgRecord) Shape.getEscherChild(dgContainer, EscherDgRecord.RECORD_ID);
int dgId = dgg.getMaxDrawingGroupId() + 1;
dg.setOptions((short)(dgId < < 4));
dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
dgg.setMaxDrawingGroupId(dgId);
for (Iterator it = dgContainer.getChildContainers().iterator(); it.hasNext(); ) {
EscherContainerRecord c = (EscherContainerRecord)it.next();
EscherSpRecord spr = null;
switch(c.getRecordId()){
case EscherContainerRecord.SPGR_CONTAINER:
EscherContainerRecord dc = (EscherContainerRecord)c.getChildRecords().get(0);
spr = dc.getChildById(EscherSpRecord.RECORD_ID);
break;
case EscherContainerRecord.SP_CONTAINER:
spr = c.getChildById(EscherSpRecord.RECORD_ID);
break;
}
if(spr != null) spr.setShapeId(allocateShapeId());
}
//PPT doen't increment the number of saved shapes for group descriptor and background
dg.setNumShapes(1);
}
|
public void setFollowMasterBackground(boolean flag) {
SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterBackground(flag);
}
Sets whether this slide follows master background |
public void setFollowMasterObjects(boolean flag) {
SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterObjects(flag);
}
Sets whether this slide draws master sheet objects |
public void setFollowMasterScheme(boolean flag) {
SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterScheme(flag);
}
Sets whether this slide draws master color scheme |
public void setMasterSheet(MasterSheet master) {
SlideAtom sa = getSlideRecord().getSlideAtom();
int sheetNo = master._getSheetNumber();
sa.setMasterID(sheetNo);
}
Change Master of this slide. |
public void setNotes(Notes notes) {
_notes = notes;
// Update the Slide Atom's ID of where to point to
SlideAtom sa = getSlideRecord().getSlideAtom();
if(notes == null) {
// Set to 0
sa.setNotesID(0);
} else {
// Set to the value from the notes' sheet id
sa.setNotesID(notes._getSheetNumber());
}
}
Sets the Notes that are associated with this. Updates the
references in the records to point to the new ID |
public void setSlideNumber(int newSlideNumber) {
_slideNo = newSlideNumber;
}
Changes the Slide's (external facing) page number. |