* @author niki
*/
public abstract class BasicReader {
+ /**
+ * A type of {@link BasicReader}.
+ *
+ * @author niki
+ */
public enum ReaderType {
/** Simple reader that outputs everything on the console */
CLI,
;
+ /**
+ * Return the full class name of a type that implements said
+ * {@link ReaderType}.
+ *
+ * @return the class name
+ */
public String getTypeName() {
String pkg = "be.nikiroo.fanfix.reader.";
switch (this) {
case TUI:
return pkg + "TuiReader";
case GUI:
- return pkg + "LocalReader";
+ return pkg + "GuiReader";
}
return null;
*
* @param type
* the new type
+ *
+ * @return the type
*/
protected BasicReader setType(ReaderType type) {
this.type = type;
* Start the reader in browse mode for the given source (or pass NULL for
* all sources).
*
- * @param library
- * the library to browse
- *
* @param source
* the type of {@link Story} to take into account, or NULL for
* all
return source;
}
- // open with external player the related file
+ /**
+ * Open the {@link Story} with an external reader (the program will be
+ * passed the main file associated with this {@link Story}).
+ *
+ * @param lib
+ * the {@link BasicLibrary} to select the {@link Story} from
+ * @param luid
+ * the {@link Story} LUID
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
public static void open(BasicLibrary lib, String luid) throws IOException {
MetaData meta = lib.getInfo(luid);
File target = lib.getFile(luid);
open(meta, target);
}
- // open with external player the related file
+ /**
+ * Open the {@link Story} with an external reader (the program will be
+ * passed the given target file).
+ *
+ * @param meta
+ * the {@link Story} to load
+ * @param target
+ * the target {@link File}
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
protected static void open(MetaData meta, File target) throws IOException {
String program = null;
if (meta.isImageDocument()) {
import be.nikiroo.utils.Version;
import be.nikiroo.utils.ui.UIUtils;
-class LocalReader extends BasicReader {
+class GuiReader extends BasicReader {
static private boolean nativeLookLoaded;
private LocalLibrary localLibrary;
- public LocalReader() throws IOException {
+ public GuiReader() throws IOException {
if (!nativeLookLoaded) {
UIUtils.setLookAndFeel();
nativeLookLoaded = true;
/**
* Check if the {@link Story} denoted by this Library UID is present in the
- * {@link LocalReader} cache.
+ * {@link GuiReader} cache.
*
* @param luid
* the Library UID
}
}
- new LocalReaderFrame(LocalReader.this, typeFinal)
+ new GuiReaderFrame(GuiReader.this, typeFinal)
.setVisible(true);
}
});
import be.nikiroo.utils.ui.UIUtils;
/**
- * A book item presented in a {@link LocalReaderFrame}.
+ * A book item presented in a {@link GuiReaderFrame}.
*
* @author niki
*/
-class LocalReaderBook extends JPanel {
+class GuiReaderBook extends JPanel {
/**
* Action on a book item.
*
* The book was selected (single click).
*
* @param book
- * the {@link LocalReaderBook} itself
+ * the {@link GuiReaderBook} itself
*/
- public void select(LocalReaderBook book);
+ public void select(GuiReaderBook book);
/**
* The book was double-clicked.
*
* @param book
- * the {@link LocalReaderBook} itself
+ * the {@link GuiReaderBook} itself
*/
- public void action(LocalReaderBook book);
+ public void action(GuiReaderBook book);
/**
- * A popup menu was requested for this {@link LocalReaderBook}.
+ * A popup menu was requested for this {@link GuiReaderBook}.
*
* @param book
- * the {@link LocalReaderBook} itself
+ * the {@link GuiReaderBook} itself
* @param e
* the {@link MouseEvent} that generated this call
*/
- public void popupRequested(LocalReaderBook book, MouseEvent e);
+ public void popupRequested(GuiReaderBook book, MouseEvent e);
}
private static final long serialVersionUID = 1L;
private boolean cached;
/**
- * Create a new {@link LocalReaderBook} item for the given {@link Story}.
+ * Create a new {@link GuiReaderBook} item for the given {@link Story}.
*
* @param meta
- * the story {@code}link MetaData}
+ * the story {@link MetaData}
* @param cached
* TRUE if it is locally cached
- * @param seeWordcount
+ * @param seeWordCount
* TRUE to see word counts, FALSE to see authors
*/
- public LocalReaderBook(MetaData meta, boolean cached, boolean seeWordCount) {
+ public GuiReaderBook(MetaData meta, boolean cached, boolean seeWordCount) {
this.cached = cached;
this.meta = meta;
* events.
*/
private void setupListeners() {
- listeners = new ArrayList<LocalReaderBook.BookActionListener>();
+ listeners = new ArrayList<GuiReaderBook.BookActionListener>();
addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
private void click(boolean doubleClick) {
for (BookActionListener listener : listeners) {
if (doubleClick) {
- listener.action(LocalReaderBook.this);
+ listener.action(GuiReaderBook.this);
} else {
- listener.select(LocalReaderBook.this);
+ listener.select(GuiReaderBook.this);
}
}
}
private void popup(MouseEvent e) {
for (BookActionListener listener : listeners) {
- listener.select((LocalReaderBook.this));
- listener.popupRequested(LocalReaderBook.this, e);
+ listener.select((GuiReaderBook.this));
+ listener.popupRequested(GuiReaderBook.this, e);
}
}
});
}
/**
- * The Library {@code}link MetaData} of the book represented by this item.
+ * The Library {@link MetaData} of the book represented by this item.
*
* @return the meta
*/
}
/**
- * This item {@link LocalReader} library cache state.
+ * This item {@link GuiReader} library cache state.
*
- * @return TRUE if it is present in the {@link LocalReader} cache
+ * @return TRUE if it is present in the {@link GuiReader} cache
*/
public boolean isCached() {
return cached;
}
/**
- * This item {@link LocalReader} library cache state.
+ * This item {@link GuiReader} library cache state.
*
* @param cached
- * TRUE if it is present in the {@link LocalReader} cache
+ * TRUE if it is present in the {@link GuiReader} cache
*/
public void setCached(boolean cached) {
if (this.cached != cached) {
}
/**
- * Paint the item, then call {@link LocalReaderBook#paintOverlay(Graphics)}.
+ * Paint the item, then call {@link GuiReaderBook#paintOverlay(Graphics)}.
*/
@Override
public void paint(Graphics g) {
* Draw a partially transparent overlay if needed depending upon the
* selection and mouse-hover states on top of the normal component, as well
* as a possible "cached" icon if the item is cached.
+ *
+ * @param g
+ * the {@link Graphics} to paint onto
*/
public void paintOverlay(Graphics g) {
Rectangle clip = g.getClipBounds();
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.output.BasicOutput.OutputType;
-import be.nikiroo.fanfix.reader.LocalReaderBook.BookActionListener;
+import be.nikiroo.fanfix.reader.GuiReaderBook.BookActionListener;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Version;
import be.nikiroo.utils.ui.ConfigEditor;
import be.nikiroo.utils.ui.ProgressBar;
/**
- * A {@link Frame} that will show a {@link LocalReaderBook} item for each
+ * A {@link Frame} that will show a {@link GuiReaderBook} item for each
* {@link Story} in the main cache ({@link Instance#getCache()}), and offer a
- * way to copy them to the {@link LocalReader} cache ({@link LocalReader#lib}),
- * read them, delete them...
+ * way to copy them to the {@link GuiReader} cache (
+ * {@link BasicReader#getLibrary()}), read them, delete them...
*
* @author niki
*/
-class LocalReaderFrame extends JFrame {
+class GuiReaderFrame extends JFrame {
private static final long serialVersionUID = 1L;
- private LocalReader reader;
- private Map<LocalReaderGroup, String> booksByType;
- private Map<LocalReaderGroup, String> booksByAuthor;
+ private GuiReader reader;
+ private Map<GuiReaderGroup, String> booksByType;
+ private Map<GuiReaderGroup, String> booksByAuthor;
private JPanel pane;
private Color color;
private ProgressBar pgBar;
private JMenuBar bar;
- private LocalReaderBook selectedBook;
+ private GuiReaderBook selectedBook;
private boolean words; // words or authors (secondary info on books)
/**
- * Create a new {@link LocalReaderFrame}.
+ * Create a new {@link GuiReaderFrame}.
*
* @param reader
- * the associated {@link LocalReader} to forward some commands
- * and access its {@link LocalLibrary}
+ * the associated {@link GuiReader} to forward some commands and
+ * access its {@link LocalLibrary}
* @param type
* the type of {@link Story} to load, or NULL for all types
*/
- public LocalReaderFrame(LocalReader reader, String type) {
+ public GuiReaderFrame(GuiReader reader, String type) {
super(String.format("Fanfix %s Library", Version.getCurrentVersion()));
this.reader = reader;
}
});
- booksByType = new HashMap<LocalReaderGroup, String>();
- booksByAuthor = new HashMap<LocalReaderGroup, String>();
+ booksByType = new HashMap<GuiReaderGroup, String>();
+ booksByAuthor = new HashMap<GuiReaderGroup, String>();
pane.setVisible(false);
final Progress pg = new Progress();
}
/**
- * Add a new {@link LocalReaderGroup} on the frame to display the books of
- * the selected type or author.
+ * Add a new {@link GuiReaderGroup} on the frame to display the books of the
+ * selected type or author.
*
* @param value
* the author or the type, or NULL to get all the
return;
}
- LocalReaderGroup bookPane = new LocalReaderGroup(reader, value, color);
+ GuiReaderGroup bookPane = new GuiReaderGroup(reader, value, color);
if (type) {
booksByType.put(bookPane, value);
} else {
this.validate();
bookPane.setActionListener(new BookActionListener() {
- public void select(LocalReaderBook book) {
+ public void select(GuiReaderBook book) {
selectedBook = book;
}
- public void popupRequested(LocalReaderBook book, MouseEvent e) {
+ public void popupRequested(GuiReaderBook book, MouseEvent e) {
JPopupMenu popup = new JPopupMenu();
popup.add(createMenuItemOpenBook());
popup.addSeparator();
popup.show(e.getComponent(), e.getX(), e.getY());
}
- public void action(final LocalReaderBook book) {
+ public void action(final GuiReaderBook book) {
openBook(book);
}
});
}
/**
- * Refresh the list of {@link LocalReaderBook}s from disk.
+ * Refresh the list of {@link GuiReaderBook}s from disk.
*
*/
private void refreshBooks() {
- for (LocalReaderGroup group : booksByType.keySet()) {
+ for (GuiReaderGroup group : booksByType.keySet()) {
List<MetaData> stories = Instance.getLibrary().getListBySource(
booksByType.get(group));
group.refreshBooks(stories, words);
}
- for (LocalReaderGroup group : booksByAuthor.keySet()) {
+ for (GuiReaderGroup group : booksByAuthor.keySet()) {
List<MetaData> stories = Instance.getLibrary().getListByAuthor(
booksByAuthor.get(group));
group.refreshBooks(stories, words);
JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- LocalReaderFrame.this.dispatchEvent(new WindowEvent(
- LocalReaderFrame.this, WindowEvent.WINDOW_CLOSING));
+ GuiReaderFrame.this.dispatchEvent(new WindowEvent(
+ GuiReaderFrame.this, WindowEvent.WINDOW_CLOSING));
}
});
export.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedBook != null) {
- fc.showDialog(LocalReaderFrame.this, "Save");
+ fc.showDialog(GuiReaderFrame.this, "Save");
if (fc.getSelectedFile() != null) {
final OutputType type = filters.get(fc.getFileFilter());
final String path = fc.getSelectedFile()
String type = ftype;
if (type == null) {
Object rep = JOptionPane.showInputDialog(
- LocalReaderFrame.this, "Move to:",
+ GuiReaderFrame.this, "Move to:",
"Moving story",
JOptionPane.QUESTION_MESSAGE, null, null,
selectedBook.getMeta().getSource());
imprt(meta.getUrl(), new Runnable() {
public void run() {
reader.delete(meta.getLuid());
- LocalReaderFrame.this.selectedBook = null;
+ GuiReaderFrame.this.selectedBook = null;
}
}, "Removing old copy");
}
}
/**
- * Open a {@link LocalReaderBook} item.
+ * Open a {@link GuiReaderBook} item.
*
* @param book
- * the {@link LocalReaderBook} to open
+ * the {@link GuiReaderBook} to open
*/
- private void openBook(final LocalReaderBook book) {
+ private void openBook(final GuiReaderBook book) {
final Progress pg = new Progress();
outOfUi(pg, new Runnable() {
public void run() {
* The code will make sure that the {@link ProgressBar} (if not NULL) is set
* to done when the action is done.
*
- * @param pg
+ * @param progress
* the {@link ProgressBar} or NULL
* @param run
* the action to run
clipboard = "";
}
- url = JOptionPane.showInputDialog(LocalReaderFrame.this,
+ url = JOptionPane.showInputDialog(GuiReaderFrame.this,
"url of the story to import?", "Importing from URL",
JOptionPane.QUESTION_MESSAGE, null, null, clipboard);
} else if (fc.showOpenDialog(this) != JFileChooser.CANCEL_OPTION) {
Instance.syserr(e);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
- JOptionPane.showMessageDialog(
- LocalReaderFrame.this, "Cannot import: "
- + url, e.getMessage(),
+ JOptionPane.showMessageDialog(GuiReaderFrame.this,
+ "Cannot import: " + url, e.getMessage(),
JOptionPane.ERROR_MESSAGE);
}
});
bar.setEnabled(b);
}
- for (LocalReaderGroup group : booksByType.keySet()) {
+ for (GuiReaderGroup group : booksByType.keySet()) {
group.setEnabled(b);
}
- for (LocalReaderGroup group : booksByAuthor.keySet()) {
+ for (GuiReaderGroup group : booksByAuthor.keySet()) {
group.setEnabled(b);
}
super.setEnabled(b);
import javax.swing.JPanel;
import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.fanfix.reader.LocalReaderBook.BookActionListener;
+import be.nikiroo.fanfix.reader.GuiReaderBook.BookActionListener;
import be.nikiroo.utils.ui.WrapLayout;
/**
- * A group of {@link LocalReaderBook}s for display.
+ * A group of {@link GuiReaderBook}s for display.
*
* @author niki
*/
-public class LocalReaderGroup extends JPanel {
+public class GuiReaderGroup extends JPanel {
private static final long serialVersionUID = 1L;
private BookActionListener action;
private Color backgroundColor;
- private LocalReader reader;
+ private GuiReader reader;
private List<MetaData> stories;
- private List<LocalReaderBook> books;
+ private List<GuiReaderBook> books;
private JPanel pane;
private boolean words; // words or authors (secondary info on books)
/**
- * Create a new {@link LocalReaderGroup}.
+ * Create a new {@link GuiReaderGroup}.
*
* @param reader
- * the {@link LocalReaderBook} used to probe some information
+ * the {@link GuiReaderBook} used to probe some information
* about the stories
* @param title
* the title of this group
* @param backgroundColor
* the background colour to use (or NULL for default)
*/
- public LocalReaderGroup(LocalReader reader, String title,
+ public GuiReaderGroup(GuiReader reader, String title,
Color backgroundColor) {
this.reader = reader;
this.backgroundColor = backgroundColor;
/**
* Set the {@link ActionListener} that will be fired on each
- * {@link LocalReaderBook} action.
+ * {@link GuiReaderBook} action.
*
* @param action
* the action
}
/**
- * Refresh the list of {@link LocalReaderBook}s displayed in the control.
+ * Refresh the list of {@link GuiReaderBook}s displayed in the control.
*
* @param stories
* the stories
this.stories = stories;
this.words = seeWordcount;
- books = new ArrayList<LocalReaderBook>();
+ books = new ArrayList<GuiReaderBook>();
invalidate();
pane.invalidate();
pane.removeAll();
if (stories != null) {
for (MetaData meta : stories) {
- LocalReaderBook book = new LocalReaderBook(meta,
+ GuiReaderBook book = new GuiReaderBook(meta,
reader.isCached(meta.getLuid()), seeWordcount);
if (backgroundColor != null) {
book.setBackground(backgroundColor);
books.add(book);
book.addActionListener(new BookActionListener() {
- public void select(LocalReaderBook book) {
- for (LocalReaderBook abook : books) {
+ public void select(GuiReaderBook book) {
+ for (GuiReaderBook abook : books) {
abook.setSelected(abook == book);
}
}
- public void popupRequested(LocalReaderBook book,
+ public void popupRequested(GuiReaderBook book,
MouseEvent e) {
}
- public void action(LocalReaderBook book) {
+ public void action(GuiReaderBook book) {
}
});
@Override
public void setEnabled(boolean b) {
if (books != null) {
- for (LocalReaderBook book : books) {
+ for (GuiReaderBook book : books) {
book.setEnabled(b);
book.repaint();
}
package be.nikiroo.fanfix.reader;
import java.io.IOException;
-import java.util.List;
import be.nikiroo.fanfix.Instance;
-import be.nikiroo.fanfix.LocalLibrary;
-import be.nikiroo.fanfix.data.MetaData;
class TuiReader extends BasicReader {
@Override
@Override
public void browse(String source) {
- List<MetaData> stories = getLibrary().getListBySource(source);
try {
- TuiReaderApplication app = new TuiReaderApplication(stories, this);
+ TuiReaderApplication app = new TuiReaderApplication(getLibrary()
+ .getListBySource(source), this);
new Thread(app).start();
} catch (Exception e) {
Instance.syserr(e);
import jexer.TMessageBox;
import be.nikiroo.fanfix.data.MetaData;
-public class TuiReaderApplication extends TApplication {
+class TuiReaderApplication extends TApplication {
private BasicReader reader;
private static BackendType guessBackendType() {
import java.util.ArrayList;
import java.util.List;
-import jexer.*;
+import jexer.TAction;
+import jexer.TCommand;
+import jexer.TKeypress;
+import jexer.TList;
+import jexer.TRadioGroup;
+import jexer.TTreeItem;
+import jexer.TTreeView;
+import jexer.TWindow;
import be.nikiroo.fanfix.data.MetaData;
-public class TuiReaderMainWindow extends TWindow {
+class TuiReaderMainWindow extends TWindow {
private TList list;
private List<MetaData> listKeys;
private List<String> listItems;
/**
* Constructor.
*
- * @param parent
- * the main application
- * @param flags
- * bitmask of MODAL, CENTERED, or RESIZABLE
+ * @param reader
+ * the reader and main application
+ * @param stories
+ * the stories to display
*/
public TuiReaderMainWindow(TuiReaderApplication reader,
List<MetaData> stories) {
}
}
});
-
+
// TODO: add the current "type" or filter
statusBar = newStatusBar("Library");
statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit");
import jexer.TWindow;
import jexer.event.TResizeEvent;
import be.nikiroo.fanfix.BasicLibrary;
-import be.nikiroo.fanfix.Instance;
-import be.nikiroo.fanfix.LocalLibrary;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Story;
-public class TuiReaderStoryWindow extends TWindow {
+class TuiReaderStoryWindow extends TWindow {
private BasicLibrary lib;
private MetaData meta;
private Story story;