Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* ====================================================================
     Licensed to the Apache Software Foundation (ASF) under one or more
     contributor license agreements.  See the NOTICE file distributed with
     this work for additional information regarding copyright ownership.
     The ASF licenses this file to You under the Apache License, Version 2.0
     (the "License"); you may not use this file except in compliance with
     the License.  You may obtain a copy of the License at
  
         http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
 
 package org.apache.poi.hslf.model;
 
 import java.util.List;
 
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

Author(s):
Nick Burch
Yegor Kozlov
 
 
 public final class Slide extends Sheet
 {
 	private int _slideNo;
 	private TextRun[] _runs;
 	private Notes _notes// usermodel needs to set this
 
Constructs a Slide from the Slide record, and the SlideAtomsSet containing the text. Initializes 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
 
 	public Slide(org.apache.poi.hslf.record.Slide slideNotes notesSlideAtomsSet atomSetint slideIdentifierint slideNumber) {
         super(slideslideIdentifier);
 
 		 = notes;
 		 = atomSet;
 		 = 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
 		final List<TextRuntextRuns = new LinkedList<TextRun>();
 		if( != null) {
 		} else {
 			// No text on the slide, must just be pictures
 		}
 
 		// Build an array, more useful than a vector
 		 = new TextRun[textRuns.size()+_otherRuns.length];
 		// Grab text from SlideListWithTexts entries
 		int i=0;
 		for(i=0; i<textRuns.size(); i++) {
 			[i] = (TextRun)textRuns.get(i);
             [i].setSheet(this);
 		}
 		// Grab text from slide's PPDrawing
 		for(int k=0; k<_otherRuns.lengthi++, k++) {
 			[i] = _otherRuns[k];
             [i].setSheet(this);
             [i].setIndex(-1); // runs found in PPDrawing are not linked with SlideListWithTexts
 		}
	}

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(int sheetNumberint sheetRefIdint slideNumber){
		super(new org.apache.poi.hslf.record.Slide(), sheetNumber);
		 = slideNumber;
        getSheetContainer().setSheetId(sheetRefId);
	}

Sets the Notes that are associated with this. Updates the references in the records to point to the new ID
	public void setNotes(Notes notes) {
		 = notes;
		// Update the Slide Atom's ID of where to point to
		if(notes == null) {
			// Set to 0
else {
			// Set to the value from the notes' sheet id
		}
	}

Changes the Slide's (external facing) page number.

	public void setSlideNumber(int newSlideNumber) {
		 = newSlideNumber;
	}

    
Called by SlideShow ater a new slide is created.

For Slide we need to do the following:

  • set id of the drawing group.
  • set shapeId for the container descriptor and background
  •     public void onCreate(){
            //initialize drawing group id
            EscherDgRecord dg = (EscherDgRecord) Shape.getEscherChild(dgContainer.);
            int dgId = dgg.getMaxDrawingGroupId() + 1;
            dg.setOptions((short)(dgId << 4));
            dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
            dgg.setMaxDrawingGroupId(dgId);
            for (EscherContainerRecord c : dgContainer.getChildContainers()) {
                EscherSpRecord spr = null;
                switch(c.getRecordId()){
                    case .:
                        EscherContainerRecord dc = (EscherContainerRecord)c.getChild(0);
                        spr = dc.getChildById(.);
                        break;
                    case .:
                        spr = c.getChildById(.);
                        break;
                }
                if(spr != nullspr.setShapeId(allocateShapeId());
            }
            //PPT doen't increment the number of saved shapes for group descriptor and background
            dg.setNumShapes(1);
        }

    Create a TextBox object that represents the slide's title.

    Returns:
    TextBox object that represents the slide's title.
    	public TextBox addTitle() {
    		Placeholder pl = new Placeholder();
    		pl.setText("Click to edit title");
    		pl.setAnchor(new java.awt.Rectangle(54, 48, 612, 90));
    		return pl;
    	}
    	// Complex Accesser methods follow
    Return title of this slide or null if the slide does not have title.

    The title is a run of text of type TextHeaderAtom.CENTER_TITLE_TYPE or TextHeaderAtom.TITLE_TYPE

    Returns:
    title of this slide
    See also:
    org.apache.poi.hslf.record.TextHeaderAtom
    	public String getTitle(){
    		TextRun[] txt = getTextRuns();
    		for (int i = 0; i < txt.lengthi++) {
    			int type = txt[i].getRunType();
    				String title = txt[i].getText();
    				return title;
    			}
    		}
    		return null;
    	}
    	// Simple Accesser methods follow
    Returns an array of all the TextRuns found
    	public TextRun[] getTextRuns() { return ; }

    Returns the (public facing) page number of this slide
    	public int getSlideNumber() { return ; }

    Returns the underlying slide record
            return (org.apache.poi.hslf.record.Slide)getSheetContainer();
        }

    Returns the Notes Sheet for this slide, or null if there isn't one
    	public Notes getNotesSheet() { return ; }

    Returns:
    set of records inside SlideListWithtext container which hold text data for this slide (typically for placeholders).
    	protected SlideAtomsSet getSlideAtomsSet() { return ;  }

        
    Returns master sheet associated with this slide. It can be either SlideMaster or TitleMaster objects.

    Returns:
    the master sheet associated with this slide.
         public MasterSheet getMasterSheet(){
            SlideMaster[] master = getSlideShow().getSlidesMasters();
            SlideAtom sa = getSlideRecord().getSlideAtom();
            int masterId = sa.getMasterID();
            MasterSheet sheet = null;
            for (int i = 0; i < master.lengthi++) {
                if (masterId == master[i]._getSheetNumber()) {
                    sheet = master[i];
                    break;
                }
            }
            if (sheet == null){
                TitleMaster[] titleMaster = getSlideShow().getTitleMasters();
                if(titleMaster != nullfor (int i = 0; i < titleMaster.lengthi++) {
                    if (masterId == titleMaster[i]._getSheetNumber()) {
                        sheet = titleMaster[i];
                        break;
                    }
                }
            }
            return sheet;
        }

        
    Change Master of this slide.
        public void setMasterSheet(MasterSheet master){
            SlideAtom sa = getSlideRecord().getSlideAtom();
            int sheetNo = master._getSheetNumber();
            sa.setMasterID(sheetNo);
        }

        
    Sets whether this slide follows master background

    Parameters:
    flag true if the slide follows master, false otherwise
        public void setFollowMasterBackground(boolean flag){
            SlideAtom sa = getSlideRecord().getSlideAtom();
            sa.setFollowMasterBackground(flag);
        }

        
    Whether this slide follows master sheet background

    Returns:
    true if the slide follows master background, false otherwise
        public boolean getFollowMasterBackground(){
            SlideAtom sa = getSlideRecord().getSlideAtom();
            return sa.getFollowMasterBackground();
        }

        
    Sets whether this slide draws master sheet objects

    Parameters:
    flag true if the slide draws master sheet objects, false otherwise
        public void setFollowMasterObjects(boolean flag){
            SlideAtom sa = getSlideRecord().getSlideAtom();
            sa.setFollowMasterObjects(flag);
        }

        
    Whether this slide follows master color scheme

    Returns:
    true if the slide follows master color scheme, false otherwise
        public boolean getFollowMasterScheme(){
            SlideAtom sa = getSlideRecord().getSlideAtom();
            return sa.getFollowMasterScheme();
        }

        
    Sets whether this slide draws master color scheme

    Parameters:
    flag true if the slide draws master color scheme, false otherwise
        public void setFollowMasterScheme(boolean flag){
            SlideAtom sa = getSlideRecord().getSlideAtom();
            sa.setFollowMasterScheme(flag);
        }

        
    Whether this slide draws master sheet objects

    Returns:
    true if the slide draws master sheet objects, false otherwise
        public boolean getFollowMasterObjects(){
            SlideAtom sa = getSlideRecord().getSlideAtom();
            return sa.getFollowMasterObjects();
        }

        
    Background for this slide.
         public Background getBackground() {
            if(getFollowMasterBackground()) {
                return getMasterSheet().getBackground();
            }
            return super.getBackground();
        }

        
    Color scheme for this slide.
        public ColorSchemeAtom getColorScheme() {
            if(getFollowMasterScheme()){
                return getMasterSheet().getColorScheme();
            }
            return super.getColorScheme();
        }

        
    Get the comment(s) for this slide. Note - for now, only works on PPT 2000 and PPT 2003 files. Doesn't work for PPT 97 ones, as they do their comments oddly.
        public Comment[] getComments() {
        	// If there are any, they're in
        	//  ProgTags -> ProgBinaryTag -> BinaryTagData
        	RecordContainer progTags = (RecordContainer)
        	);
        	if(progTags != null) {
        		RecordContainer progBinaryTag = (RecordContainer)
        			progTags.findFirstOfType(
        		);
        		if(progBinaryTag != null) {
        			RecordContainer binaryTags = (RecordContainer)
        				progBinaryTag.findFirstOfType(
        			);
        			if(binaryTags != null) {
        				// This is where they'll be
        				int count = 0;
        				for(int i=0; i<binaryTags.getChildRecords().lengthi++) {
        					if(binaryTags.getChildRecords()[iinstanceof Comment2000) {
        						count++;
        					}
        				}
        				// Now build
        				Comment[] comments = new Comment[count];
        				count = 0;
        				for(int i=0; i<binaryTags.getChildRecords().lengthi++) {
        					if(binaryTags.getChildRecords()[iinstanceof Comment2000) {
        						comments[i] = new Comment(
        								(Comment2000)binaryTags.getChildRecords()[i]
        						);
        						count++;
        					}
        				}
        				return comments;
        			}
        		}
        	}
        	// None found
        	return new Comment[0];
        }
        public void draw(Graphics2D graphics){
            MasterSheet master = getMasterSheet();
            Background bg = getBackground();
            if(bg != null)bg.draw(graphics);
            if(getFollowMasterObjects()){
                Shape[] sh = master.getShapes();
                for (int i = 0; i < sh.lengthi++) {
                    if(MasterSheet.isPlaceholder(sh[i])) continue;
                    sh[i].draw(graphics);
                }
            }
            Shape[] sh = getShapes();
            for (int i = 0; i < sh.lengthi++) {
                sh[i].draw(graphics);
            }
        }

        
    Header / Footer settings for this slide.

    Returns:
    Header / Footer settings for this slide
         public HeadersFooters getHeadersFooters(){
            HeadersFootersContainer hdd = null;
            Record[] ch = getSheetContainer().getChildRecords();
            boolean ppt2007 = false;
            for (int i = 0; i < ch.lengthi++) {
                if(ch[iinstanceof HeadersFootersContainer){
                    hdd = (HeadersFootersContainer)ch[i];
                } else if (ch[i].getRecordType() == ..){
                    ppt2007 = true;
                }
            }
            boolean newRecord = false;
            if(hdd == null && !ppt2007) {
                return getSlideShow().getSlideHeadersFooters();
            }
            if(hdd == null) {
                newRecord = true;
            }
            return new HeadersFooters(hddthisnewRecordppt2007);
        }
        protected void onAddTextShape(TextShape shape) {
            TextRun run = shape.getTextRun();
            if( == null = new TextRun[]{run};
            else {
                TextRun[] tmp = new TextRun[. + 1];
                System.arraycopy(, 0, tmp, 0, .);
                tmp[tmp.length-1] = run;
                 = tmp;
            }
        }

        
    This will return an atom per TextBox, so if the page has two text boxes the method should return two atoms.
        	return this.getPPDrawing().getNumberedListInfo();
        }
    	}
    	public void setHidden(boolean hidden) {
    		SSSlideInfoAtom slideInfo = 
    		if (slideInfo == null) {
    			slideInfo = new SSSlideInfoAtom();
    		}
    	}
    	public boolean getHidden() {
    		SSSlideInfoAtom slideInfo = 
    		return (slideInfo == null)
    false
    	}
    New to GrepCode? Check out our FAQ X