| 1 | package be.nikiroo.fanfix.data; |
| 2 | |
| 3 | import be.nikiroo.utils.Image; |
| 4 | |
| 5 | /** |
| 6 | * A paragraph in a chapter of the story. |
| 7 | * |
| 8 | * @author niki |
| 9 | */ |
| 10 | public class Paragraph implements Cloneable { |
| 11 | /** |
| 12 | * A paragraph type, that will dictate how the paragraph will be handled. |
| 13 | * |
| 14 | * @author niki |
| 15 | */ |
| 16 | public enum ParagraphType { |
| 17 | /** Normal paragraph (text) */ |
| 18 | NORMAL, |
| 19 | /** Blank line */ |
| 20 | BLANK, |
| 21 | /** A Break paragraph, i.e.: HR (Horizontal Line) or '* * *' or whatever */ |
| 22 | BREAK, |
| 23 | /** Quotation (dialogue) */ |
| 24 | QUOTE, |
| 25 | /** An image (no text) */ |
| 26 | IMAGE, ; |
| 27 | |
| 28 | /** |
| 29 | * This paragraph type is of a text kind (quote or not). |
| 30 | * |
| 31 | * @param allowEmpty |
| 32 | * allow empty text as text, too (blanks, breaks...) |
| 33 | * @return TRUE if it is |
| 34 | */ |
| 35 | public boolean isText(boolean allowEmpty) { |
| 36 | return (this == NORMAL || this == QUOTE) |
| 37 | || (allowEmpty && (this == BLANK || this == BREAK)); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | private ParagraphType type; |
| 42 | private String content; |
| 43 | private Image contentImage; |
| 44 | private long words; |
| 45 | |
| 46 | /** |
| 47 | * Empty constructor, not to use. |
| 48 | */ |
| 49 | @SuppressWarnings("unused") |
| 50 | private Paragraph() { |
| 51 | // for serialisation purposes |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Create a new {@link Paragraph} with the given image. |
| 56 | * |
| 57 | * @param contentImage |
| 58 | * the image |
| 59 | */ |
| 60 | public Paragraph(Image contentImage) { |
| 61 | this(ParagraphType.IMAGE, null, 1); |
| 62 | this.contentImage = contentImage; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Create a new {@link Paragraph} with the given values. |
| 67 | * |
| 68 | * @param type |
| 69 | * the {@link ParagraphType} |
| 70 | * @param content |
| 71 | * the content of this paragraph |
| 72 | * @param words |
| 73 | * the number of words (or images) |
| 74 | */ |
| 75 | public Paragraph(ParagraphType type, String content, long words) { |
| 76 | this.type = type; |
| 77 | this.content = content; |
| 78 | this.words = words; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * The {@link ParagraphType}. |
| 83 | * |
| 84 | * @return the type |
| 85 | */ |
| 86 | public ParagraphType getType() { |
| 87 | return type; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * The {@link ParagraphType}. |
| 92 | * |
| 93 | * @param type |
| 94 | * the type to set |
| 95 | */ |
| 96 | public void setType(ParagraphType type) { |
| 97 | this.type = type; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * The content of this {@link Paragraph} if it is not an image. |
| 102 | * |
| 103 | * @return the content |
| 104 | */ |
| 105 | public String getContent() { |
| 106 | return content; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * The content of this {@link Paragraph}. |
| 111 | * |
| 112 | * @param content |
| 113 | * the content to set |
| 114 | */ |
| 115 | public void setContent(String content) { |
| 116 | this.content = content; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * The content of this {@link Paragraph} if it is an image. |
| 121 | * |
| 122 | * @return the content |
| 123 | */ |
| 124 | public Image getContentImage() { |
| 125 | return contentImage; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * The number of words (or images) in this {@link Paragraph}. |
| 130 | * |
| 131 | * @return the number of words |
| 132 | */ |
| 133 | public long getWords() { |
| 134 | return words; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * The number of words (or images) in this {@link Paragraph}. |
| 139 | * |
| 140 | * @param words |
| 141 | * the number of words to set |
| 142 | */ |
| 143 | public void setWords(long words) { |
| 144 | this.words = words; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Display a DEBUG {@link String} representation of this object. |
| 149 | */ |
| 150 | @Override |
| 151 | public String toString() { |
| 152 | return String.format("%s: [%s]", "" + type, content == null ? "N/A" |
| 153 | : content); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public Paragraph clone() { |
| 158 | Paragraph para = null; |
| 159 | try { |
| 160 | para = (Paragraph) super.clone(); |
| 161 | } catch (CloneNotSupportedException e) { |
| 162 | // Did the clones rebel? |
| 163 | System.err.println(e); |
| 164 | } |
| 165 | |
| 166 | return para; |
| 167 | } |
| 168 | } |