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