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