d7285785b6513dc76badadb96ad8ce49a620e9be
[fanfix.git] / src / be / nikiroo / fanfix / reader / Reader.java
1 package be.nikiroo.fanfix.reader;
2
3 import java.io.IOException;
4 import java.net.URL;
5
6 import be.nikiroo.fanfix.data.Story;
7 import be.nikiroo.fanfix.library.BasicLibrary;
8 import be.nikiroo.fanfix.library.LocalLibrary;
9 import be.nikiroo.utils.Progress;
10
11 public interface Reader {
12 /**
13 * A type of {@link BasicReader}.
14 *
15 * @author niki
16 */
17 public enum ReaderType {
18 /** Simple reader that outputs everything on the console */
19 CLI,
20 /** Reader that starts local programs to handle the stories */
21 GUI,
22 /** A text (UTF-8) reader with menu and text windows */
23 TUI,
24
25 ;
26
27 /**
28 * Return the full class name of a type that implements said
29 * {@link ReaderType}.
30 *
31 * @return the class name
32 */
33 public String getTypeName() {
34 String pkg = "be.nikiroo.fanfix.reader.";
35 switch (this) {
36 case CLI:
37 return pkg + "CliReader";
38 case TUI:
39 return pkg + "TuiReader";
40 case GUI:
41 return pkg + "GuiReader";
42 }
43
44 return null;
45 }
46 };
47
48 /**
49 * Return the current {@link Story}.
50 *
51 * @return the {@link Story}
52 */
53 public Story getStory();
54
55 /**
56 * The {@link LocalLibrary} to load the stories from (by default, takes the
57 * default {@link LocalLibrary}).
58 *
59 * @return the {@link LocalLibrary}
60 */
61 public BasicLibrary getLibrary();
62
63 /**
64 * Change the {@link LocalLibrary} that will be managed by this
65 * {@link BasicReader}.
66 *
67 * @param lib
68 * the new {@link LocalLibrary}
69 */
70 public void setLibrary(LocalLibrary lib);
71
72 /**
73 * Create a new {@link BasicReader} for a {@link Story} in the
74 * {@link LocalLibrary}.
75 *
76 * @param luid
77 * the {@link Story} ID
78 * @param pg
79 * the optional progress reporter
80 *
81 * @throws IOException
82 * in case of I/O error
83 */
84 public void setStory(String luid, Progress pg) throws IOException;
85
86 /**
87 * Create a new {@link BasicReader} for an external {@link Story}.
88 *
89 * @param source
90 * the {@link Story} {@link URL}
91 * @param pg
92 * the optional progress reporter
93 *
94 * @throws IOException
95 * in case of I/O error
96 */
97 public void setStory(URL source, Progress pg) throws IOException;
98
99 /**
100 * Start the {@link Story} Reading.
101 *
102 * @throws IOException
103 * in case of I/O error or if the {@link Story} was not
104 * previously set
105 */
106 public void read() throws IOException;
107
108 /**
109 * Read the selected chapter (starting at 1).
110 *
111 * @param chapter
112 * the chapter
113 *
114 * @throws IOException
115 * in case of I/O error or if the {@link Story} was not
116 * previously set
117 */
118 public void read(int chapter) throws IOException;
119
120 /**
121 * Start the reader in browse mode for the given source (or pass NULL for
122 * all sources).
123 *
124 * @param source
125 * the type of {@link Story} to take into account, or NULL for
126 * all
127 */
128 public void browse(String source);
129
130 }