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

public final class PresentationModel

  1. Object
  2. PresentationModel

The editable, undoable facade of a Presentation, the way DocumentModel is for a word processing document.

Every edit replaces the immutable presentation and records the one it replaced, so undo and redo are exact. Edits between beginGroup and endGroup undo as one step – a drag that moves a shape through a hundred positions is one undo. Listeners hear every change, which is how a SlideView and its thumbnails follow the model.

import com.codename1.wordprocessing.TextStyle;

PresentationModel model = new PresentationModel(new Presentation());
String slideId = model.addSlide(-1);
model.addElement(0, ShapeElement.textBox(model.newId('e'), 60, 40, 840, 90,
        TextFrame.of("t", "Quarterly review", TextStyle.DEFAULT.withSize(40), "center")));
model.undo();

Constructors

public PresentationModel()A model of an empty presentation.
public PresentationModel(Presentation presentation)A model of a presentation.

Methods

public Presentation getPresentation()The current presentation.
public void setPresentation(Presentation value)Replaces the presentation as one undoable edit.
public void reset(Presentation value)Replaces the presentation and forgets the undo history, for opening another file.
public void beginGroup()Starts a group of edits that undo as one.
public void endGroup()Ends a group started by beginGroup.
public boolean canUndo()True when there is an edit to undo.
public boolean canRedo()True when there is an undone edit to redo.
public boolean undo()Undoes the last edit or group.
public boolean redo()Redoes the last undone edit.
public void setUndoLimit(int limit)Sets how many edits are kept for undo; the default is 100.
public void addPresentationListener(PresentationListener l)Adds a listener.
public void removePresentationListener(PresentationListener l)Removes a listener.
public String newId(char prefix)Reserves an id no slide or element has.
public int getSlideCount()The number of slides.
public Slide getSlide(int index)A slide.
public String addSlide(int index)Adds an empty white slide.
public void insertSlide(int index, Slide slide)Inserts a slide.
public void setSlide(int index, Slide slide)Replaces a slide.
public void removeSlide(int index)Removes a slide.
public void moveSlide(int from, int to)Moves a slide.
public String duplicateSlide(int index)Copies a slide after itself, giving the copy and its elements new ids.
public void addElement(int slide, SlideElement element)Adds an element in front of the others.
public boolean replaceElement(int slide, SlideElement element)Replaces an element, found by its id among a slide’s top level elements.
public boolean removeElement(int slide, String elementId)Removes an element and its builds.
public boolean moveElement(int slide, String elementId, int to)Moves an element in the painting order.
public boolean setBounds(int slide, String elementId, float x, float y, float width, float height)Moves and resizes an element.
public boolean setRotation(int slide, String elementId, float degrees)Rotates an element.
public boolean setText(int slide, String elementId, List<Block> blocks)Replaces a shape’s text.
public void setNotes(int slide, List<Block> blocks)Replaces a slide’s speaker notes.
public void setTransition(int slide, Transition transition)Replaces a slide’s transition.
public void addBuild(int slide, Build build)Appends a build to a slide’s animation.

Inherited methods

Constructor details

PresentationModel

public PresentationModel()
A model of an empty presentation.

PresentationModel

public PresentationModel(Presentation presentation)
A model of a presentation.

Parameters

presentation Presentation
the presentation, not null

Method details

getPresentation

public Presentation getPresentation()
The current presentation.

Returns

the presentation

setPresentation

public void setPresentation(Presentation value)
Replaces the presentation as one undoable edit.

Parameters

value Presentation
the new presentation

reset

public void reset(Presentation value)
Replaces the presentation and forgets the undo history, for opening another file.

Parameters

value Presentation
the presentation

beginGroup

public void beginGroup()
Starts a group of edits that undo as one. Groups nest.

endGroup

public void endGroup()
Ends a group started by beginGroup.

canUndo

public boolean canUndo()
True when there is an edit to undo.

Returns

true when undo is possible

canRedo

public boolean canRedo()
True when there is an undone edit to redo.

Returns

true when redo is possible

undo

public boolean undo()
Undoes the last edit or group.

Returns

false when there was nothing to undo

redo

public boolean redo()
Redoes the last undone edit.

Returns

false when there was nothing to redo

setUndoLimit

public void setUndoLimit(int limit)
Sets how many edits are kept for undo; the default is 100.

Parameters

limit int
at least 1

addPresentationListener

public void addPresentationListener(PresentationListener l)
Adds a listener.

Parameters

l PresentationListener
the listener

removePresentationListener

public void removePresentationListener(PresentationListener l)
Removes a listener.

Parameters

l PresentationListener
the listener

newId

public String newId(char prefix)
Reserves an id no slide or element has. Reserving is not an edit.

Parameters

prefix char
the letter the id starts with

Returns

the id

getSlideCount

public int getSlideCount()
The number of slides.

Returns

the count

getSlide

public Slide getSlide(int index)
A slide.

Parameters

index int
the position

Returns

the slide

addSlide

public String addSlide(int index)
Adds an empty white slide.

Parameters

index int
the position, or -1 for the end

Returns

the new slide’s id

insertSlide

public void insertSlide(int index, Slide slide)
Inserts a slide.

Parameters

index int
the position, or -1 for the end
slide Slide
the slide

setSlide

public void setSlide(int index, Slide slide)
Replaces a slide.

Parameters

index int
the position
slide Slide
the slide

removeSlide

public void removeSlide(int index)
Removes a slide.

Parameters

index int
the position

moveSlide

public void moveSlide(int from, int to)
Moves a slide.

Parameters

from int
its position
to int
the position it ends up at

duplicateSlide

public String duplicateSlide(int index)
Copies a slide after itself, giving the copy and its elements new ids.

Parameters

index int
the slide

Returns

the copy’s id

addElement

public void addElement(int slide, SlideElement element)
Adds an element in front of the others.

Parameters

slide int
the slide index
element SlideElement
the element

replaceElement

public boolean replaceElement(int slide, SlideElement element)
Replaces an element, found by its id among a slide’s top level elements.

Parameters

slide int
the slide index
element SlideElement
the new element, with the id of the one it replaces

Returns

false when the slide has no element with that id

removeElement

public boolean removeElement(int slide, String elementId)
Removes an element and its builds.

Parameters

slide int
the slide index
elementId String
the element

Returns

false when there is no such element

moveElement

public boolean moveElement(int slide, String elementId, int to)
Moves an element in the painting order.

Parameters

slide int
the slide index
elementId String
the element
to int
its new position, 0 at the back

Returns

false when there is no such element

setBounds

public boolean setBounds(int slide, String elementId, float x, float y, float width, float height)
Moves and resizes an element.

Parameters

slide int
the slide index
elementId String
the element
x float
left edge in points
y float
top edge
width float
width
height float
height

Returns

false when there is no such element

setRotation

public boolean setRotation(int slide, String elementId, float degrees)
Rotates an element.

Parameters

slide int
the slide index
elementId String
the element
degrees float
clockwise

Returns

false when there is no such element

setText

public boolean setText(int slide, String elementId, List<Block> blocks)
Replaces a shape’s text.

Parameters

slide int
the slide index
elementId String
a ShapeElement
blocks List<Block>
the new text

Returns

false when there is no such shape

setNotes

public void setNotes(int slide, List<Block> blocks)
Replaces a slide’s speaker notes.

Parameters

slide int
the slide index
blocks List<Block>
the notes

setTransition

public void setTransition(int slide, Transition transition)
Replaces a slide’s transition.

Parameters

slide int
the slide index
transition Transition
the transition

addBuild

public void addBuild(int slide, Build build)
Appends a build to a slide’s animation.

Parameters

slide int
the slide index
build Build
the build