changelog
[nikiroo-utils.git] / src / be / nikiroo / fanfix / data / Paragraph.java
CommitLineData
08fe2e33
NR
1package be.nikiroo.fanfix.data;
2
16a81ef7 3import be.nikiroo.utils.Image;
08fe2e33
NR
4
5/**
6 * A paragraph in a chapter of the story.
7 *
8 * @author niki
9 */
39cd9738 10public 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) */
26 IMAGE,
27 }
28
29 private ParagraphType type;
30 private String content;
16a81ef7 31 private Image contentImage;
793f1071 32 private long words;
08fe2e33 33
b0e88ebd
NR
34 /**
35 * Empty constructor, not to use.
36 */
211f7ddb 37 @SuppressWarnings("unused")
b0e88ebd
NR
38 private Paragraph() {
39 // for serialisation purposes
40 }
41
08fe2e33
NR
42 /**
43 * Create a new {@link Paragraph} with the given image.
44 *
2a25f781
NR
45 * @param contentImage
46 * the image
08fe2e33 47 */
16a81ef7 48 public Paragraph(Image contentImage) {
2a25f781
NR
49 this(ParagraphType.IMAGE, null, 1);
50 this.contentImage = contentImage;
793f1071
NR
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
c8faa52a 61 * the number of words (or images)
793f1071
NR
62 */
63 public Paragraph(ParagraphType type, String content, long words) {
64 this.type = type;
65 this.content = content;
66 this.words = words;
08fe2e33
NR
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 /**
2a25f781 89 * The content of this {@link Paragraph} if it is not an image.
08fe2e33
NR
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
2a25f781
NR
107 /**
108 * The content of this {@link Paragraph} if it is an image.
109 *
110 * @return the content
111 */
16a81ef7 112 public Image getContentImage() {
2a25f781
NR
113 return contentImage;
114 }
115
793f1071 116 /**
c8faa52a 117 * The number of words (or images) in this {@link Paragraph}.
793f1071
NR
118 *
119 * @return the number of words
120 */
121 public long getWords() {
122 return words;
123 }
124
125 /**
c8faa52a 126 * The number of words (or images) in this {@link Paragraph}.
793f1071
NR
127 *
128 * @param words
129 * the number of words to set
130 */
131 public void setWords(long words) {
132 this.words = words;
133 }
134
08fe2e33
NR
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 }
39cd9738
NR
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 }
08fe2e33 155}