Class Presentation

java.lang.Object
com.codename1.presentation.Presentation

public final class Presentation extends Object

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.

  • Field Details

    • WIDE_WIDTH

      public static final float WIDE_WIDTH
      16:9 at 960 by 540 points, PowerPoint's and Keynote's default.
      See Also:
    • WIDE_HEIGHT

      public static final float WIDE_HEIGHT
      The height of a 16:9 slide in points.
      See Also:
    • width

      public final float width
      The slide width in points.
    • height

      public final float height
      The slide height in points.
    • slides

      public final List<Slide> slides
      The slides, never null.
    • theme

      public final Theme theme
      The theme.
    • title

      public final String title
      The title, or null.
    • nextId

      public final long nextId
      The 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
      • width: the slide width in points, greater than zero

      • height: the slide height in points, greater than zero

      • slides: the slides, or null

      • theme: the theme, or null for the default

      • title: the title, or null

      • nextId: the next id number

      • warnings: 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
      • prefix: a letter that starts the id
      Returns

      the id

    • indexOf

      public int indexOf(String id)

      A slide by id.

      Parameters
      • id: the id
      Returns

      the index or -1

    • withSlides

      public Presentation withSlides(List<Slide> value)

      This presentation with other slides.

      Parameters
      • value: the slides
      Returns

      the presentation

    • withSlide

      public Presentation withSlide(int index, Slide slide)

      This presentation with one slide replaced.

      Parameters
      • index: the position

      • slide: the slide

      Returns

      the presentation

    • insert

      public Presentation insert(int index, Slide slide)

      This presentation with a slide inserted.

      Parameters
      • index: the position

      • slide: the slide

      Returns

      the presentation

    • remove

      public Presentation remove(int index)

      This presentation without a slide.

      Parameters
      • index: 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
      • w: the width in points

      • h: the height in points

      Returns

      the presentation

    • withTheme

      public Presentation withTheme(Theme value)

      This presentation with another theme.

      Parameters
      • value: the theme
      Returns

      the presentation

    • withTitle

      public Presentation withTitle(String value)

      This presentation with another title.

      Parameters
      • value: the title
      Returns

      the presentation

    • withNextId

      public Presentation withNextId(long value)

      This presentation with another next id number.

      Parameters
      • value: the number
      Returns

      the presentation

    • withWarnings

      public Presentation withWarnings(List<String> value)

      This presentation with warnings.

      Parameters
      • value: 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 IOException

      Reads a presentation.

      Parameters
      • in: the stream; it is read to the end but not closed

      • format: the format, which must be readable

      Returns

      the presentation

      Throws
      • IOException: when the stream fails or the file is not in that format
      Throws:
      IOException
    • read

      public static Presentation read(byte[] data) throws IOException

      Reads 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
      • data: the file
      Returns

      the presentation

      Throws
      • IOException: when the bytes are none of the formats
      Throws:
      IOException
    • detect

      public static Presentation.Format detect(byte[] data) throws IOException

      Tells the format of a file from its content.

      Parameters
      • data: the file
      Returns

      the format

      Throws
      • IOException: when it is none of the readable formats
      Throws:
      IOException
    • write

      public void write(OutputStream out, Presentation.Format format) throws IOException

      Writes the presentation.

      Parameters
      • out: the stream; it is flushed but not closed

      • format: the format, which must be writable

      Throws
      • IOException: when the stream fails or the format cannot be written
      Throws:
      IOException
    • toBytes

      public byte[] toBytes(Presentation.Format format) throws IOException

      The presentation as the bytes of a file.

      Parameters
      • format: a writable format
      Returns

      the bytes

      Throws
      • IOException: when the format cannot be written
      Throws:
      IOException
    • equals

      public boolean equals(Object o)
      Description copied from class: Object
      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).
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Description copied from class: Object
      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.)
      Overrides:
      hashCode in class Object