e621: supports searches
[fanfix.git] / src / be / nikiroo / fanfix / data / Paragraph.java
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 private ParagraphType type;
30 private String content;
31 private Image contentImage;
32 private long words;
33
34 /**
35 * Empty constructor, not to use.
36 */
37 @SuppressWarnings("unused")
38 private Paragraph() {
39 // for serialisation purposes
40 }
41
42 /**
43 * Create a new {@link Paragraph} with the given image.
44 *
45 * @param contentImage
46 * the image
47 */
48 public Paragraph(Image contentImage) {
49 this(ParagraphType.IMAGE, null, 1);
50 this.contentImage = contentImage;
51 }
52
53 /**
54 * Create a new {@link Paragraph} with the given values.
55 *
56 * @param type
57 * the {@link ParagraphType}
58 * @param content
59 * the content of this paragraph
60 * @param words
61 * the number of words (or images)
62 */
63 public Paragraph(ParagraphType type, String content, long words) {
64 this.type = type;
65 this.content = content;
66 this.words = words;
67 }
68
69 /**
70 * The {@link ParagraphType}.
71 *
72 * @return the type
73 */
74 public ParagraphType getType() {
75 return type;
76 }
77
78 /**
79 * The {@link ParagraphType}.
80 *
81 * @param type
82 * the type to set
83 */
84 public void setType(ParagraphType type) {
85 this.type = type;
86 }
87
88 /**
89 * The content of this {@link Paragraph} if it is not an image.
90 *
91 * @return the content
92 */
93 public String getContent() {
94 return content;
95 }
96
97 /**
98 * The content of this {@link Paragraph}.
99 *
100 * @param content
101 * the content to set
102 */
103 public void setContent(String content) {
104 this.content = content;
105 }
106
107 /**
108 * The content of this {@link Paragraph} if it is an image.
109 *
110 * @return the content
111 */
112 public Image getContentImage() {
113 return contentImage;
114 }
115
116 /**
117 * The number of words (or images) in this {@link Paragraph}.
118 *
119 * @return the number of words
120 */
121 public long getWords() {
122 return words;
123 }
124
125 /**
126 * The number of words (or images) in this {@link Paragraph}.
127 *
128 * @param words
129 * the number of words to set
130 */
131 public void setWords(long words) {
132 this.words = words;
133 }
134
135 /**
136 * Display a DEBUG {@link String} representation of this object.
137 */
138 @Override
139 public String toString() {
140 return String.format("%s: [%s]", "" + type, "" + content);
141 }
142
143 @Override
144 public Paragraph clone() {
145 Paragraph para = null;
146 try {
147 para = (Paragraph) super.clone();
148 } catch (CloneNotSupportedException e) {
149 // Did the clones rebel?
150 System.err.println(e);
151 }
152
153 return para;
154 }
155 }