Class PresentationModel

java.lang.Object
com.codename1.presentation.PresentationModel

public final class PresentationModel extends Object

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 Details

    • PresentationModel

      public PresentationModel()
      A model of an empty presentation.
    • PresentationModel

      public PresentationModel(Presentation presentation)

      A model of a presentation.

      Parameters
      • 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: the new presentation
    • reset

      public void reset(Presentation value)

      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 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: at least 1
    • addPresentationListener

      public void addPresentationListener(PresentationListener l)

      Adds a listener.

      Parameters
      • l: the listener
    • removePresentationListener

      public void removePresentationListener(PresentationListener l)

      Removes a listener.

      Parameters
      • l: the listener
    • newId

      public String newId(char prefix)

      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

      public Slide getSlide(int index)

      A slide.

      Parameters
      • index: the position
      Returns

      the slide

    • addSlide

      public String addSlide(int index)

      Adds an empty white slide.

      Parameters
      • index: 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: the position, or -1 for the end

      • slide: the slide

    • setSlide

      public void setSlide(int index, Slide slide)

      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

      public String duplicateSlide(int index)

      Copies a slide after itself, giving the copy and its elements new ids.

      Parameters
      • index: 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: the slide index

      • element: 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: 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

      public boolean removeElement(int slide, String elementId)

      Removes an element and its builds.

      Parameters
      • slide: the slide index

      • elementId: 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: the slide index

      • elementId: the element

      • to: 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: 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

      public boolean setRotation(int slide, String elementId, float degrees)

      Rotates an element.

      Parameters
      • slide: the slide index

      • elementId: the element

      • degrees: 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: the slide index

      • elementId: a ShapeElement

      • blocks: 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: the slide index

      • blocks: the notes

    • setTransition

      public void setTransition(int slide, Transition transition)

      Replaces a slide's transition.

      Parameters
      • slide: the slide index

      • transition: the transition

    • addBuild

      public void addBuild(int slide, Build build)

      Appends a build to a slide's animation.

      Parameters
      • slide: the slide index

      • build: the build