X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fdata%2FParagraph.java;h=d5a0f1c618ca6327c5602c1a7a1212c22dbfd6f8;hb=83001824bb702296a45cdf400312e34f69951e91;hp=feb949caf91c87d79e2471f6eed2dc6aceef8fa3;hpb=08fe2e33007063e30fe22dc1d290f8afaa18eb1d;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/data/Paragraph.java b/src/be/nikiroo/fanfix/data/Paragraph.java index feb949c..d5a0f1c 100644 --- a/src/be/nikiroo/fanfix/data/Paragraph.java +++ b/src/be/nikiroo/fanfix/data/Paragraph.java @@ -1,13 +1,17 @@ package be.nikiroo.fanfix.data; -import java.net.URL; +import java.io.Serializable; + +import be.nikiroo.utils.Image; /** * A paragraph in a chapter of the story. * * @author niki */ -public class Paragraph { +public class Paragraph implements Cloneable, Serializable { + private static final long serialVersionUID = 1L; + /** * A paragraph type, that will dictate how the paragraph will be handled. * @@ -23,11 +27,44 @@ public class Paragraph { /** Quotation (dialogue) */ QUOTE, /** An image (no text) */ - IMAGE, + IMAGE, ; + + /** + * This paragraph type is of a text kind (quote or not). + * + * @param allowEmpty + * allow empty text as text, too (blanks, breaks...) + * @return TRUE if it is + */ + public boolean isText(boolean allowEmpty) { + return (this == NORMAL || this == QUOTE) + || (allowEmpty && (this == BLANK || this == BREAK)); + } } private ParagraphType type; private String content; + private Image contentImage; + private long words; + + /** + * Empty constructor, not to use. + */ + @SuppressWarnings("unused") + private Paragraph() { + // for serialisation purposes + } + + /** + * Create a new {@link Paragraph} with the given image. + * + * @param contentImage + * the image + */ + public Paragraph(Image contentImage) { + this(ParagraphType.IMAGE, null, 1); + this.contentImage = contentImage; + } /** * Create a new {@link Paragraph} with the given values. @@ -36,24 +73,13 @@ public class Paragraph { * the {@link ParagraphType} * @param content * the content of this paragraph + * @param words + * the number of words (or images) */ - public Paragraph(ParagraphType type, String content) { + public Paragraph(ParagraphType type, String content, long words) { this.type = type; this.content = content; - } - - /** - * Create a new {@link Paragraph} with the given image. - * - * @param support - * the support that will be used to fetch the image via - * {@link Paragraph#getContentImage()}. - * @param content - * the content image of this paragraph - */ - public Paragraph(URL imageUrl) { - this.type = ParagraphType.IMAGE; - this.content = imageUrl.toString(); + this.words = words; } /** @@ -76,7 +102,7 @@ public class Paragraph { } /** - * The content of this {@link Paragraph}. + * The content of this {@link Paragraph} if it is not an image. * * @return the content */ @@ -94,11 +120,63 @@ public class Paragraph { this.content = content; } + /** + * The content of this {@link Paragraph} if it is an image. + * + * @return the content + */ + public Image getContentImage() { + return contentImage; + } + + /** + * The content of this {@link Paragraph} if it is an image. + * + * @param contentImage + * the content + */ + public void setContentImage(Image contentImage) { + this.contentImage = contentImage; + } + + /** + * The number of words (or images) in this {@link Paragraph}. + * + * @return the number of words + */ + public long getWords() { + return words; + } + + /** + * The number of words (or images) in this {@link Paragraph}. + * + * @param words + * the number of words to set + */ + public void setWords(long words) { + this.words = words; + } + /** * Display a DEBUG {@link String} representation of this object. */ @Override public String toString() { - return String.format("%s: [%s]", "" + type, "" + content); + return String.format("%s: [%s]", "" + type, content == null ? "N/A" + : content); + } + + @Override + public Paragraph clone() { + Paragraph para = null; + try { + para = (Paragraph) super.clone(); + } catch (CloneNotSupportedException e) { + // Did the clones rebel? + System.err.println(e); + } + + return para; } }