Commit | Line | Data |
---|---|---|
08fe2e33 NR |
1 | package be.nikiroo.fanfix.data; |
2 | ||
16a81ef7 | 3 | import be.nikiroo.utils.Image; |
08fe2e33 NR |
4 | |
5 | /** | |
6 | * A paragraph in a chapter of the story. | |
7 | * | |
8 | * @author niki | |
9 | */ | |
39cd9738 | 10 | public class Paragraph implements Cloneable { |
08fe2e33 NR |
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) */ | |
e5a2f1b3 NR |
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 | } | |
08fe2e33 NR |
39 | } |
40 | ||
41 | private ParagraphType type; | |
42 | private String content; | |
16a81ef7 | 43 | private Image contentImage; |
793f1071 | 44 | private long words; |
08fe2e33 | 45 | |
b0e88ebd NR |
46 | /** |
47 | * Empty constructor, not to use. | |
48 | */ | |
211f7ddb | 49 | @SuppressWarnings("unused") |
b0e88ebd NR |
50 | private Paragraph() { |
51 | // for serialisation purposes | |
52 | } | |
53 | ||
08fe2e33 NR |
54 | /** |
55 | * Create a new {@link Paragraph} with the given image. | |
56 | * | |
2a25f781 NR |
57 | * @param contentImage |
58 | * the image | |
08fe2e33 | 59 | */ |
16a81ef7 | 60 | public Paragraph(Image contentImage) { |
2a25f781 NR |
61 | this(ParagraphType.IMAGE, null, 1); |
62 | this.contentImage = contentImage; | |
793f1071 NR |
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 | |
c8faa52a | 73 | * the number of words (or images) |
793f1071 NR |
74 | */ |
75 | public Paragraph(ParagraphType type, String content, long words) { | |
76 | this.type = type; | |
77 | this.content = content; | |
78 | this.words = words; | |
08fe2e33 NR |
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 | /** | |
2a25f781 | 101 | * The content of this {@link Paragraph} if it is not an image. |
08fe2e33 NR |
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 | ||
2a25f781 NR |
119 | /** |
120 | * The content of this {@link Paragraph} if it is an image. | |
121 | * | |
122 | * @return the content | |
123 | */ | |
16a81ef7 | 124 | public Image getContentImage() { |
2a25f781 NR |
125 | return contentImage; |
126 | } | |
127 | ||
793f1071 | 128 | /** |
c8faa52a | 129 | * The number of words (or images) in this {@link Paragraph}. |
793f1071 NR |
130 | * |
131 | * @return the number of words | |
132 | */ | |
133 | public long getWords() { | |
134 | return words; | |
135 | } | |
136 | ||
137 | /** | |
c8faa52a | 138 | * The number of words (or images) in this {@link Paragraph}. |
793f1071 NR |
139 | * |
140 | * @param words | |
141 | * the number of words to set | |
142 | */ | |
143 | public void setWords(long words) { | |
144 | this.words = words; | |
145 | } | |
146 | ||
08fe2e33 NR |
147 | /** |
148 | * Display a DEBUG {@link String} representation of this object. | |
149 | */ | |
150 | @Override | |
151 | public String toString() { | |
9e2fad36 NR |
152 | return String.format("%s: [%s]", "" + type, content == null ? "N/A" |
153 | : content); | |
08fe2e33 | 154 | } |
39cd9738 NR |
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 | } | |
08fe2e33 | 168 | } |