Lot of fixes + first (bad, ugly) working GUI
[fanfix.git] / src / be / nikiroo / fanfix / reader / CliReader.java
1 package be.nikiroo.fanfix.reader;
2
3 import java.io.IOException;
4 import java.util.List;
5
6 import be.nikiroo.fanfix.Instance;
7 import be.nikiroo.fanfix.bundles.StringId;
8 import be.nikiroo.fanfix.data.Chapter;
9 import be.nikiroo.fanfix.data.MetaData;
10 import be.nikiroo.fanfix.data.Paragraph;
11 import be.nikiroo.fanfix.data.Story;
12
13 /**
14 * Command line {@link Story} reader.
15 * <p>
16 * Will output stories to the console.
17 *
18 * @author niki
19 */
20 class CliReader extends BasicReader {
21 @Override
22 public void read() throws IOException {
23 if (getStory() == null) {
24 throw new IOException("No story to read");
25 }
26
27 String title = "";
28 String author = "";
29
30 MetaData meta = getStory().getMeta();
31 if (meta != null) {
32 if (meta.getTitle() != null) {
33 title = meta.getTitle();
34 }
35
36 if (meta.getAuthor() != null) {
37 author = "©" + meta.getAuthor();
38 if (meta.getDate() != null && !meta.getDate().isEmpty()) {
39 author = author + " (" + meta.getDate() + ")";
40 }
41 }
42 }
43
44 System.out.println(title);
45 System.out.println(author);
46 System.out.println("");
47
48 for (Chapter chap : getStory()) {
49 if (chap.getName() != null && !chap.getName().isEmpty()) {
50 System.out.println(Instance.getTrans().getString(
51 StringId.CHAPTER_NAMED, chap.getNumber(),
52 chap.getName()));
53 } else {
54 System.out.println(Instance.getTrans().getString(
55 StringId.CHAPTER_UNNAMED, chap.getNumber()));
56 }
57 }
58 }
59
60 @Override
61 public void read(int chapter) {
62 if (chapter > getStory().getChapters().size()) {
63 System.err.println("Chapter " + chapter + ": no such chapter");
64 } else {
65 Chapter chap = getStory().getChapters().get(chapter - 1);
66 System.out.println("Chapter " + chap.getNumber() + ": "
67 + chap.getName());
68
69 for (Paragraph para : chap) {
70 System.out.println(para.getContent());
71 System.out.println("");
72 }
73 }
74 }
75
76 @Override
77 public void start(String type) {
78 List<MetaData> stories;
79 stories = Instance.getLibrary().getList(type);
80
81 for (MetaData story : stories) {
82 String author = "";
83 if (story.getAuthor() != null && !story.getAuthor().isEmpty()) {
84 author = " (" + story.getAuthor() + ")";
85 }
86
87 System.out.println(story.getLuid() + ": " + story.getTitle()
88 + author);
89 }
90 }
91 }