Commit | Line | Data |
---|---|---|
08fe2e33 NR |
1 | package be.nikiroo.fanfix.data; |
2 | ||
8b152e7b NR |
3 | import java.io.Serializable; |
4 | ||
16a81ef7 | 5 | import be.nikiroo.utils.Image; |
08fe2e33 NR |
6 | |
7 | /** | |
8 | * A paragraph in a chapter of the story. | |
9 | * | |
10 | * @author niki | |
11 | */ | |
8b152e7b NR |
12 | public 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 | ||
4b3d19dc NR |
132 | /** |
133 | * The content of this {@link Paragraph} if it is an image. | |
134 | * | |
135 | * @param contentImage | |
136 | * the content | |
137 | */ | |
138 | public void setContentImage(Image contentImage) { | |
139 | this.contentImage = contentImage; | |
140 | } | |
141 | ||
793f1071 | 142 | /** |
c8faa52a | 143 | * The number of words (or images) in this {@link Paragraph}. |
793f1071 NR |
144 | * |
145 | * @return the number of words | |
146 | */ | |
147 | public long getWords() { | |
148 | return words; | |
149 | } | |
150 | ||
151 | /** | |
c8faa52a | 152 | * The number of words (or images) in this {@link Paragraph}. |
793f1071 NR |
153 | * |
154 | * @param words | |
155 | * the number of words to set | |
156 | */ | |
157 | public void setWords(long words) { | |
158 | this.words = words; | |
159 | } | |
160 | ||
08fe2e33 NR |
161 | /** |
162 | * Display a DEBUG {@link String} representation of this object. | |
163 | */ | |
164 | @Override | |
165 | public String toString() { | |
9e2fad36 NR |
166 | return String.format("%s: [%s]", "" + type, content == null ? "N/A" |
167 | : content); | |
08fe2e33 | 168 | } |
39cd9738 NR |
169 | |
170 | @Override | |
171 | public Paragraph clone() { | |
172 | Paragraph para = null; | |
173 | try { | |
174 | para = (Paragraph) super.clone(); | |
175 | } catch (CloneNotSupportedException e) { | |
176 | // Did the clones rebel? | |
177 | System.err.println(e); | |
178 | } | |
179 | ||
180 | return para; | |
181 | } | |
08fe2e33 | 182 | } |