Class 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();
-
Constructor Summary
ConstructorsConstructorDescriptionA model of an empty presentation.PresentationModel(Presentation presentation) A model of a presentation. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends a build to a slide's animation.voidaddElement(int slide, SlideElement element) Adds an element in front of the others.voidAdds a listener.addSlide(int index) Adds an empty white slide.voidStarts a group of edits that undo as one.booleancanRedo()True when there is an undone edit to redo.booleancanUndo()True when there is an edit to undo.duplicateSlide(int index) Copies a slide after itself, giving the copy and its elements new ids.voidendGroup()Ends a group started bybeginGroup.The current presentation.getSlide(int index) A slide.intThe number of slides.voidinsertSlide(int index, Slide slide) Inserts a slide.booleanmoveElement(int slide, String elementId, int to) Moves an element in the painting order.voidmoveSlide(int from, int to) Moves a slide.newId(char prefix) Reserves an id no slide or element has.booleanredo()Redoes the last undone edit.booleanremoveElement(int slide, String elementId) Removes an element and its builds.voidRemoves a listener.voidremoveSlide(int index) Removes a slide.booleanreplaceElement(int slide, SlideElement element) Replaces an element, found by its id among a slide's top level elements.voidreset(Presentation value) Replaces the presentation and forgets the undo history, for opening another file.booleanMoves and resizes an element.voidReplaces a slide's speaker notes.voidsetPresentation(Presentation value) Replaces the presentation as one undoable edit.booleansetRotation(int slide, String elementId, float degrees) Rotates an element.voidReplaces a slide.booleanReplaces a shape's text.voidsetTransition(int slide, Transition transition) Replaces a slide's transition.voidsetUndoLimit(int limit) Sets how many edits are kept for undo; the default is 100.booleanundo()Undoes the last edit or group.
-
Constructor Details
-
PresentationModel
public PresentationModel()A model of an empty presentation. -
PresentationModel
A model of a presentation.
Parameters
presentation: the presentation, not null
-
-
Method Details
-
getPresentation
The current presentation.
Returns
the presentation
-
setPresentation
Replaces the presentation as one undoable edit.
Parameters
value: the new presentation
-
reset
Replaces the presentation and forgets the undo history, for opening another file.
Parameters
value: 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 bybeginGroup. -
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: at least 1
-
addPresentationListener
Adds a listener.
Parameters
l: the listener
-
removePresentationListener
Removes a listener.
Parameters
l: the listener
-
newId
Reserves an id no slide or element has. Reserving is not an edit.
Parameters
prefix: the letter the id starts with
Returns
the id
-
getSlideCount
public int getSlideCount()The number of slides.
Returns
the count
-
getSlide
A slide.
Parameters
index: the position
Returns
the slide
-
addSlide
Adds an empty white slide.
Parameters
index: the position, or -1 for the end
Returns
the new slide's id
-
insertSlide
Inserts a slide.
Parameters
-
index: the position, or -1 for the end -
slide: the slide
-
-
setSlide
Replaces a slide.
Parameters
-
index: the position -
slide: the slide
-
-
removeSlide
public void removeSlide(int index) Removes a slide.
Parameters
index: the position
-
moveSlide
public void moveSlide(int from, int to) Moves a slide.
Parameters
-
from: its position -
to: the position it ends up at
-
-
duplicateSlide
Copies a slide after itself, giving the copy and its elements new ids.
Parameters
index: the slide
Returns
the copy's id
-
addElement
Adds an element in front of the others.
Parameters
-
slide: the slide index -
element: the element
-
-
replaceElement
Replaces an element, found by its id among a slide's top level elements.
Parameters
-
slide: the slide index -
element: the new element, with the id of the one it replaces
Returns
false when the slide has no element with that id
-
-
removeElement
Removes an element and its builds.
Parameters
-
slide: the slide index -
elementId: the element
Returns
false when there is no such element
-
-
moveElement
Moves an element in the painting order.
Parameters
-
slide: the slide index -
elementId: the element -
to: its new position, 0 at the back
Returns
false when there is no such element
-
-
setBounds
Moves and resizes an element.
Parameters
-
slide: the slide index -
elementId: the element -
x: left edge in points -
y: top edge -
width: width -
height: height
Returns
false when there is no such element
-
-
setRotation
Rotates an element.
Parameters
-
slide: the slide index -
elementId: the element -
degrees: clockwise
Returns
false when there is no such element
-
-
setText
-
setNotes
-
setTransition
Replaces a slide's transition.
Parameters
-
slide: the slide index -
transition: the transition
-
-
addBuild
Appends a build to a slide's animation.
Parameters
-
slide: the slide index -
build: the build
-
-