Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Presentation
- Object
- 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.Format | The formats a presentation is read from and written to. |
Fields
public static final float WIDE_WIDTH = 960.0f | 16:9 at 960 by 540 points, PowerPoint’s and Keynote’s default. |
public static final float WIDE_HEIGHT = 540.0f | The height of a 16:9 slide in points. |
public final float width | The slide width in points. |
public final float height | The slide height in points. |
public final List<Slide> slides | The slides, never null. |
public final Theme theme | The theme. |
public final String title | The title, or null. |
public final long nextId | The next number newId hands out. |
Constructors
Methods
Inherited methods
Field details
WIDE_WIDTH
public static final float WIDE_WIDTH = 960.0f16:9 at 960 by 540 points, PowerPoint’s and Keynote’s default.
WIDE_HEIGHT
public static final float WIDE_HEIGHT = 540.0fThe height of a 16:9 slide in points.
width
public final float widthThe slide width in points.
height
public final float heightThe slide height in points.
slides
public final List<Slide> slidesThe slides, never null.
theme
public final Theme themeThe theme.
title
public final String titleThe title, or null.
nextId
public final long nextIdThe 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
widthfloat- the slide width in points, greater than zero
heightfloat- the slide height in points, greater than zero
slidesList<Slide>- the slides, or null
themeTheme- the theme, or null for the default
titleString- the title, or null
nextIdlong- the next id number
warningsList<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
prefixchar- a letter that starts the id
Returns
the id
indexOf
public int indexOf(String id)A slide by id.
Parameters
idString- the id
Returns
the index or -1
withSlides
public Presentation withSlides(List<Slide> value)This presentation with other slides.
Parameters
valueList<Slide>- the slides
Returns
the presentation
withSlide
public Presentation withSlide(int index, Slide slide)This presentation with one slide replaced.
Parameters
indexint- the position
slideSlide- the slide
Returns
the presentation
insert
public Presentation insert(int index, Slide slide)This presentation with a slide inserted.
Parameters
indexint- the position
slideSlide- the slide
Returns
the presentation
remove
public Presentation remove(int index)This presentation without a slide.
Parameters
indexint- 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
wfloat- the width in points
hfloat- the height in points
Returns
the presentation
withTheme
public Presentation withTheme(Theme value)This presentation with another theme.
Parameters
valueTheme- the theme
Returns
the presentation
withTitle
public Presentation withTitle(String value)This presentation with another title.
Parameters
valueString- the title
Returns
the presentation
withNextId
public Presentation withNextId(long value)This presentation with another next id number.
Parameters
valuelong- the number
Returns
the presentation
withWarnings
public Presentation withWarnings(List<String> value)This presentation with warnings.
Parameters
valueList<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 IOExceptionReads a presentation.
Parameters
inInputStream- the stream; it is read to the end but not closed
formatPresentation.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 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.Parameters
databyte[]- the file
Returns
the presentation
Throws
IOException- when the bytes are none of the formats
detect
public static Presentation.Format detect(byte[] data)
throws IOExceptionTells the format of a file from its content.
Parameters
databyte[]- 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 IOExceptionWrites the presentation.
Parameters
outOutputStream- the stream; it is flushed but not closed
formatPresentation.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 IOExceptionThe presentation as the bytes of a file.
Parameters
formatPresentation.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.)