doc
[nikiroo-utils.git] / data / Paragraph.java
1 package be.nikiroo.fanfix.data;
2
3 import java.net.URL;
4
5 /**
6 * A paragraph in a chapter of the story.
7 *
8 * @author niki
9 */
10 public class Paragraph {
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 long words;
32
33 /**
34 * Empty constructor, not to use.
35 */
36 @SuppressWarnings("unused")
37 private Paragraph() {
38 // for serialisation purposes
39 }
40
41 /**
42 * Create a new {@link Paragraph} with the given image.
43 *
44 * @param imageUrl
45 * the image as an URL
46 */
47 public Paragraph(URL imageUrl) {
48 this(ParagraphType.IMAGE, imageUrl.toString(), 1);
49 }
50
51 /**
52 * Create a new {@link Paragraph} with the given values.
53 *
54 * @param type
55 * the {@link ParagraphType}
56 * @param content
57 * the content of this paragraph
58 * @param words
59 * the number of words (or images)
60 */
61 public Paragraph(ParagraphType type, String content, long words) {
62 this.type = type;
63 this.content = content;
64 this.words = words;
65 }
66
67 /**
68 * The {@link ParagraphType}.
69 *
70 * @return the type
71 */
72 public ParagraphType getType() {
73 return type;
74 }
75
76 /**
77 * The {@link ParagraphType}.
78 *
79 * @param type
80 * the type to set
81 */
82 public void setType(ParagraphType type) {
83 this.type = type;
84 }
85
86 /**
87 * The content of this {@link Paragraph}.
88 *
89 * @return the content
90 */
91 public String getContent() {
92 return content;
93 }
94
95 /**
96 * The content of this {@link Paragraph}.
97 *
98 * @param content
99 * the content to set
100 */
101 public void setContent(String content) {
102 this.content = content;
103 }
104
105 /**
106 * The number of words (or images) in this {@link Paragraph}.
107 *
108 * @return the number of words
109 */
110 public long getWords() {
111 return words;
112 }
113
114 /**
115 * The number of words (or images) in this {@link Paragraph}.
116 *
117 * @param words
118 * the number of words to set
119 */
120 public void setWords(long words) {
121 this.words = words;
122 }
123
124 /**
125 * Display a DEBUG {@link String} representation of this object.
126 */
127 @Override
128 public String toString() {
129 return String.format("%s: [%s]", "" + type, "" + content);
130 }
131 }