Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class PresentationModel
- Object
- 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
Inherited methods
Constructor details
PresentationModel
public PresentationModel()A model of an empty presentation.
PresentationModel
public PresentationModel(Presentation presentation)A model of a presentation.
Parameters
presentationPresentation- 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
valuePresentation- the new presentation
reset
public void reset(Presentation value)Replaces the presentation and forgets the undo history, for opening another file.
Parameters
valuePresentation- 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
limitint- at least 1
addPresentationListener
public void addPresentationListener(PresentationListener l)Adds a listener.
Parameters
lPresentationListener- the listener
removePresentationListener
public void removePresentationListener(PresentationListener l)Removes a listener.
Parameters
lPresentationListener- the listener
newId
public String newId(char prefix)Reserves an id no slide or element has. Reserving is not an edit.
Parameters
prefixchar- 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
indexint- the position
Returns
the slide
addSlide
public String addSlide(int index)Adds an empty white slide.
Parameters
indexint- 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
indexint- the position, or -1 for the end
slideSlide- the slide
setSlide
public void setSlide(int index, Slide slide)Replaces a slide.
Parameters
indexint- the position
slideSlide- the slide
removeSlide
public void removeSlide(int index)Removes a slide.
Parameters
indexint- the position
moveSlide
public void moveSlide(int from, int to)Moves a slide.
Parameters
fromint- its position
toint- 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
indexint- the slide
Returns
the copy’s id
addElement
public void addElement(int slide, SlideElement element)Adds an element in front of the others.
Parameters
slideint- the slide index
elementSlideElement- 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
slideint- the slide index
elementSlideElement- 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
slideint- the slide index
elementIdString- 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
slideint- the slide index
elementIdString- the element
toint- 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
slideint- the slide index
elementIdString- the element
xfloat- left edge in points
yfloat- top edge
widthfloat- width
heightfloat- height
Returns
false when there is no such element
setRotation
public boolean setRotation(int slide, String elementId, float degrees)Rotates an element.
Parameters
slideint- the slide index
elementIdString- the element
degreesfloat- 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
slideint- the slide index
elementIdString- a
ShapeElement blocksList<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
slideint- the slide index
blocksList<Block>- the notes
setTransition
public void setTransition(int slide, Transition transition)Replaces a slide’s transition.
Parameters
slideint- the slide index
transitionTransition- the transition
addBuild
public void addBuild(int slide, Build build)Appends a build to a slide’s animation.
Parameters
slideint- the slide index
buildBuild- the build