Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved. Copyright 2009, 2010 IBM. All rights reserved. Use is subject to license terms. Licensed 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. You can also obtain a copy of the License at http://odftoolkit.org/docs/license.txt 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.odftoolkit.simple.presentation;
 
 
Slide represents the presentation slide feature of the ODF document. Slide provides methods to get the slide index,get the content of the current slide, etc.
 
 public class Slide implements ListContainerTableContainer {
 
This is a tool class which supplies all of the slide creation detail.

The end user isn't allowed to create it directly, otherwise an IllegalStateException will be thrown.

Since:
0.3.5
 
 	public static class SlideBuilder {
 
SlideBuilder constructor. This constructor should only be use in owner PresentationDocument constructor. The end user isn't allowed to call it directly, otherwise an IllegalStateException will be thrown.

Parameters:
doc the owner PresentationDocument.
Throws:
java.lang.IllegalStateException if new SlideBuilder out of owner PresentationDocument constructor, this exception will be thrown.
 
 			if (doc.getSlideBuilder() != null) {
 				throw new IllegalStateException(
 						"SlideBuilder only can be created in owner PresentationDocument constructor.");
 			}
 		}

Get a presentation slide instance by an instance of DrawPageElement.

Parameters:
pageElement an instance of DrawPageElement
Returns:
an instance of Slide that can represent pageElement
 
 		public synchronized Slide getSlideInstance(DrawPageElement pageElement) {
 			if (.containsKey(pageElement)) {
				return .get(pageElement);
else {
				Slide newSlide = new Slide(pageElement);
				.put(pageElementnewSlide);
				return newSlide;
			}
		}
	}
	private Slide(DrawPageElement pageElement) {
		 = pageElement;
	}

Get a presentation slide instance by an instance of DrawPageElement.

Parameters:
pageElement an instance of DrawPageElement
Returns:
an instance of Slide that can represent pageElement
	public static Slide getInstance(DrawPageElement pageElement) {
		PresentationDocument ownerDocument = (PresentationDocument) ((OdfFileDom) (pageElement.getOwnerDocument()))
		return ownerDocument.getSlideBuilder().getSlideInstance(pageElement);
	}

Return an instance of DrawPageElement which represents presentation slide feature.

Returns:
an instance of DrawPageElement
	}

Get the current slide index in the owner document.

Returns:
the slide index in the owner document

-1, if the odf element which can represent this slide is not in the document DOM tree

	public int getSlideIndex() {
		NodeList slideNodes = contentDom.getElementsByTagNameNS(..getUri(), "page");
		for (int i = 0; i < slideNodes.getLength(); i++) {
			DrawPageElement slideEle = (DrawPageElementslideNodes.item(i);
			if (slideEle == )// should not equals here, see
			// OdfElement.equals(Object obj)
			{
				return i;
			}
		}
		return -1;
	}

Get the current slide name.

If the "draw:name" attribute is not present there, create an unique name for this slide

Returns:
the name of the current slide
	public String getSlideName() {
		if (slideName == null) {
			slideName = makeUniqueSlideName();
		}
		return slideName;
	}

Set the current slide name.

It must be unique slide name in the current presentation. If not, an IllegalArgumentException will be thrown. If the given name is null, an IllegalArgumentException will also be thrown.

Parameters:
name the new name of the current slide
Throws:
java.lang.IllegalArgumentException if the given name is null or it is not unique in the current presentation.
	public void setSlideName(String name) {
		if (name == null) {
			throw new IllegalArgumentException("slide name is null is not accepted in the presentation document");
		}
		// check if name is unique in this presentation
		NodeList slideNodes = contentDom.getElementsByTagNameNS(..getUri(), "page");
		for (int i = 0; i < slideNodes.getLength(); i++) {
			DrawPageElement slideEle = (DrawPageElementslideNodes.item(i);
			Slide slide = Slide.getInstance(slideEle);
			String slideName = slide.getSlideName();
			if (slideName.equals(name)) {
						"the given slide name is already exist in the current presentation document");
			}
		}
	}

Get the Notes page of this slide

Returns:
the instance of Notes which represent the notes page of the current slide
	public Notes getNotesPage() {
		if (notesList.getLength() > 0) {
			return Notes.getInstance(noteEle);
		}
		return null;
	}
		int index = getSlideIndex();
		String slideName = "page" + (index + 1) + "-" + String.format("a%06x", (int) (Math.random() * 0xffffff));
		return slideName;
	}

A slide layout is a slide with some predefine placeholder. we define some template layout as below: "blank" template is a slide without any filled element, "title_only" template is a slide with a title, "title_outline" template is a slide with a title and an outline block, "title_text" template is a slide with a title and a text block, "title_two_text_block" template is a slide with a title two text blocks.
	public enum SlideLayout {

Blank, a blank presentation
		BLANK("blank"),
Title_only, the presentation with title only
		TITLE_ONLY("title_only"),
Title_outline, the presentation with outline
		TITLE_OUTLINE("title_outline"),
Title_text, the presentation with title and one text block
		TITLE_PLUS_TEXT("title_text"),
title_two_text_block, the presentation with title and two text blocks
		TITLE_PLUS_2_TEXT_BLOCK("title_two_text_block");
		private String mValue;
		SlideLayout(String aValue) {
			 = aValue;
		}

Return the slide template type value.

Returns:
the template type value
		public String toString() {
			return ;
		}

Return the name of the template slide type.

Parameters:
aEnum a SlideLayout
Returns:
the name of slide template type
		public static String toString(SlideLayout aEnum) {
			return aEnum.toString();
		}

Return a template slide type.

Parameters:
aString the name of the slide template type
Returns:
a SlideLayout
		public static SlideLayout enumValueOf(String aString) {
			for (SlideLayout aIter : values()) {
				if (aString.equals(aIter.toString())) {
					return aIter;
				}
			}
			return null;
		}
	}
	}
	public List addList() {
	}
	public List addList(ListDecorator decorator) {
		return getListContainerImpl().addList(decorator);
	}
	public void clearList() {
	}
	}
	public boolean removeList(List list) {
	}
		if ( == null) {
		}
	}
	private class ListContainerImpl extends AbstractListContainer {
			DrawFrameElement frame = null;
			DrawTextBoxElement textBox = null;
			if (frameList.getLength() > 0) {
				int index = frameList.getLength() - 1;
				while (index >= 0) {
					frame = (DrawFrameElementframeList.item(index);
					String presentationClass = frame.getPresentationClassAttribute();
					if (presentationClass == null || "outline".equals(presentationClass)
							|| "text".equals(presentationClass) || "subtitle".equals(presentationClass)) {
						break;
else {
						index--;
					}
					frame = null;
				}
			}
			if (frame == null) {
						"There is no list container in this slide, please chose a proper slide layout.");
			}
			NodeList textBoxList = frame.getElementsByTagNameNS(..getUri(), "text-box");
			if (textBoxList.getLength() <= 0) {
				textBox = frame.newDrawTextBoxElement();
else {
				textBox = (DrawTextBoxElementtextBoxList.item(textBoxList.getLength() - 1);
			}
			return textBox;
		}
	}
	public Table addTable() {
	}
	public Table addTable(int numRowsint numCols) {
		return getTableContainerImpl().addTable(numRowsnumCols);
	}
	public Table getTableByName(String name) {
	}
	}
	}
	}
		if ( == null) {
		}
	}
	private class TableContainerImpl extends AbstractTableContainer {
			DrawFrameElement frame = null;
			if (frameList.getLength() > 0) {
				int index = frameList.getLength() - 1;
				while (index >= 0) {
					frame = (DrawFrameElementframeList.item(index);
					String presentationClass = frame.getPresentationClassAttribute();
					if (presentationClass == null || "table".equals(presentationClass)) {
						break;
else {
						index--;
					}
					frame = null;
				}
			}
			if (frame == null) {
				frame.setDrawLayerAttribute("layout");
				frame.setStyleName("standard");
				frame.setSvgHeightAttribute("1.945cm");
				frame.setSvgWidthAttribute("14.098cm");
				frame.setSvgXAttribute("6.922cm");
				frame.setSvgYAttribute("10.386cm");
			}
			return frame;
		}
	}
New to GrepCode? Check out our FAQ X