Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Presentation

  1. Object
  2. Presentation

A slide presentation: slides of a common size, the theme they were designed with, and the formats it is read from and written to.

A presentation is immutable. PresentationModel is the editable, undoable facade a SlideView edits; SlideShow plays one.

void toPdf(InputStream in, OutputStream out) throws IOException {
    Presentation deck = Presentation.read(in, Presentation.Format.PPTX);
    Log.p(deck.getSlides().size() + " slides, first: " + deck.getSlides().get(0).title());
    deck.write(out, Presentation.Format.PDF);
}

Text inside slides is the word processing model of com.codename1.wordprocessing, so every formatting feature a document has – fonts, colors, lists, links, tables – a slide has too, laid out and drawn by the same code.

Nested types

enum Presentation.FormatThe formats a presentation is read from and written to.

Fields

public static final float WIDE_WIDTH = 960.0f16:9 at 960 by 540 points, PowerPoint’s and Keynote’s default.
public static final float WIDE_HEIGHT = 540.0fThe height of a 16:9 slide in points.
public final float widthThe slide width in points.
public final float heightThe slide height in points.
public final List<Slide> slidesThe slides, never null.
public final Theme themeThe theme.
public final String titleThe title, or null.
public final long nextIdThe next number newId hands out.

Constructors

public Presentation()An empty 16:9 presentation with the default theme.
public Presentation(float width, float height, List<Slide> slides, Theme theme, String title, long nextId, List<String> warnings)A presentation.

Methods

public List<Slide> getSlides()The slides.
public List<String> getWarnings()What the reader could not convert – an unknown element, an undecodable Keynote object – one line each.
public String newId(char prefix)An id that no element or slide in this presentation has, for a new element made from it.
public int indexOf(String id)A slide by id.
public Presentation withSlides(List<Slide> value)This presentation with other slides.
public Presentation withSlide(int index, Slide slide)This presentation with one slide replaced.
public Presentation insert(int index, Slide slide)This presentation with a slide inserted.
public Presentation remove(int index)This presentation without a slide.
public Presentation withSize(float w, float h)This presentation at another slide size.
public Presentation withTheme(Theme value)This presentation with another theme.
public Presentation withTitle(String value)This presentation with another title.
public Presentation withNextId(long value)This presentation with another next id number.
public Presentation withWarnings(List<String> value)This presentation with warnings.
public String plainText()The text of every slide, slide by slide.
public static Presentation read(InputStream in, Presentation.Format format) throws IOExceptionReads a presentation.
public static Presentation read(byte[] data) throws IOExceptionReads a presentation from bytes, telling the format from the content: a ZIP holding ppt/presentation.xml is PPTX, one with an ODF presentation mimetype is ODP, one with Index/ archives is Keynote, one holding presentation.xml alone is .cn1slides, and a compound file is PowerPoint 97-2003.
public static Presentation.Format detect(byte[] data) throws IOExceptionTells the format of a file from its content.
public void write(OutputStream out, Presentation.Format format) throws IOExceptionWrites the presentation.
public byte[] toBytes(Presentation.Format format) throws IOExceptionThe presentation as the bytes of a file.
public boolean equals(Object o)Indicates whether some other object is “equal to” this one.
public int hashCode()Returns a hash code value for the object.

Inherited methods

Field details

WIDE_WIDTH

public static final float WIDE_WIDTH = 960.0f
16:9 at 960 by 540 points, PowerPoint’s and Keynote’s default.

WIDE_HEIGHT

public static final float WIDE_HEIGHT = 540.0f
The height of a 16:9 slide in points.

width

public final float width
The slide width in points.

height

public final float height
The slide height in points.

slides

public final List<Slide> slides
The slides, never null.

theme

public final Theme theme
The theme.

title

public final String title
The title, or null.

nextId

public final long nextId
The next number newId hands out.

Constructor details

Presentation

public Presentation()
An empty 16:9 presentation with the default theme.

Presentation

public Presentation(float width, float height, List<Slide> slides, Theme theme, String title, long nextId, List<String> warnings)
A presentation.

Parameters

width float
the slide width in points, greater than zero
height float
the slide height in points, greater than zero
slides List<Slide>
the slides, or null
theme Theme
the theme, or null for the default
title String
the title, or null
nextId long
the next id number
warnings List<String>
what a reader could not convert, or null

Method details

getSlides

public List<Slide> getSlides()
The slides.

Returns

the slides

getWarnings

public List<String> getWarnings()
What the reader could not convert – an unknown element, an undecodable Keynote object – one line each. Empty for a presentation made in code.

Returns

the warnings

newId

public String newId(char prefix)
An id that no element or slide in this presentation has, for a new element made from it. The presentation is immutable, so callers that make several ids in a row use PresentationModel.newId or withNextId.

Parameters

prefix char
a letter that starts the id

Returns

the id

indexOf

public int indexOf(String id)
A slide by id.

Parameters

id String
the id

Returns

the index or -1

withSlides

public Presentation withSlides(List<Slide> value)
This presentation with other slides.

Parameters

value List<Slide>
the slides

Returns

the presentation

withSlide

public Presentation withSlide(int index, Slide slide)
This presentation with one slide replaced.

Parameters

index int
the position
slide Slide
the slide

Returns

the presentation

insert

public Presentation insert(int index, Slide slide)
This presentation with a slide inserted.

Parameters

index int
the position
slide Slide
the slide

Returns

the presentation

remove

public Presentation remove(int index)
This presentation without a slide.

Parameters

index int
the position

Returns

the presentation

withSize

public Presentation withSize(float w, float h)
This presentation at another slide size. Elements keep their positions in points.

Parameters

w float
the width in points
h float
the height in points

Returns

the presentation

withTheme

public Presentation withTheme(Theme value)
This presentation with another theme.

Parameters

value Theme
the theme

Returns

the presentation

withTitle

public Presentation withTitle(String value)
This presentation with another title.

Parameters

value String
the title

Returns

the presentation

withNextId

public Presentation withNextId(long value)
This presentation with another next id number.

Parameters

value long
the number

Returns

the presentation

withWarnings

public Presentation withWarnings(List<String> value)
This presentation with warnings.

Parameters

value List<String>
the warnings

Returns

the presentation

plainText

public String plainText()
The text of every slide, slide by slide.

Returns

the text

read

public static Presentation read(InputStream in, Presentation.Format format) throws IOException
Reads a presentation.

Parameters

in InputStream
the stream; it is read to the end but not closed
format Presentation.Format
the format, which must be readable

Returns

the presentation

Throws

IOException
when the stream fails or the file is not in that format

read

public static Presentation read(byte[] data) throws IOException
Reads a presentation from bytes, telling the format from the content: a ZIP holding ppt/presentation.xml is PPTX, one with an ODF presentation mimetype is ODP, one with Index/ archives is Keynote, one holding presentation.xml alone is .cn1slides, and a compound file is PowerPoint 97-2003.

Parameters

data byte[]
the file

Returns

the presentation

Throws

IOException
when the bytes are none of the formats

detect

public static Presentation.Format detect(byte[] data) throws IOException
Tells the format of a file from its content.

Parameters

data byte[]
the file

Returns

the format

Throws

IOException
when it is none of the readable formats

write

public void write(OutputStream out, Presentation.Format format) throws IOException
Writes the presentation.

Parameters

out OutputStream
the stream; it is flushed but not closed
format Presentation.Format
the format, which must be writable

Throws

IOException
when the stream fails or the format cannot be written

toBytes

public byte[] toBytes(Presentation.Format format) throws IOException
The presentation as the bytes of a file.

Parameters

format Presentation.Format
a writable format

Returns

the bytes

Throws

IOException
when the format cannot be written

equals

public boolean equals(Object o)
Indicates whether some other object is “equal to” this one. The equals method implements an equivalence relation: It is reflexive: for any reference value x, x.equals(x) should return true. It is symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. It is transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the object is modified. For any non-null reference value x, x.equals(null) should return false. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)