+ }
+ }
+ });
+
+ return export;
+ }
+
+ /**
+ * Create a {@link FileFilter} that accepts all files and return the given
+ * description.
+ *
+ * @param desc
+ * the description
+ *
+ * @return the filter
+ */
+ private FileFilter createAllFilter(final String desc) {
+ return new FileFilter() {
+ @Override
+ public String getDescription() {
+ return desc;
+ }
+
+ @Override
+ public boolean accept(File f) {
+ return true;
+ }
+ };
+ }
+
+ /**
+ * Create the refresh (delete cache) menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemClearCache() {
+ JMenuItem refresh = new JMenuItem("Clear cache", KeyEvent.VK_C);
+ refresh.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ outOfUi(null, new Runnable() {
+ public void run() {
+ reader.clearLocalReaderCache(selectedBook.getMeta()
+ .getLuid());
+ selectedBook.setCached(false);
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ selectedBook.repaint();
+ }
+ });
+ }
+ });
+ }
+ }
+ });
+
+ return refresh;
+ }
+
+ /**
+ * Create the redownload (then delete original) menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemRedownload() {
+ JMenuItem refresh = new JMenuItem("Redownload", KeyEvent.VK_R);
+ refresh.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ final MetaData meta = selectedBook.getMeta();
+ imprt(meta.getUrl(), new Runnable() {
+ public void run() {
+ reader.delete(meta.getLuid());
+ LocalReaderFrame.this.selectedBook = null;
+ }
+ }, "Removing old copy");
+ }
+ }
+ });
+
+ return refresh;
+ }
+
+ /**
+ * Create the delete menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemDelete() {
+ JMenuItem delete = new JMenuItem("Delete", KeyEvent.VK_D);
+ delete.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ outOfUi(null, new Runnable() {
+ public void run() {
+ reader.delete(selectedBook.getMeta().getLuid());
+ selectedBook = null;
+ }
+ });
+ }
+ }
+ });
+
+ return delete;
+ }
+
+ /**
+ * Create the open menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemOpenBook() {
+ JMenuItem open = new JMenuItem("Open", KeyEvent.VK_O);
+ open.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ openBook(selectedBook);
+ }
+ }
+ });
+
+ return open;
+ }
+
+ /**
+ * Open a {@link LocalReaderBook} item.
+ *
+ * @param book
+ * the {@link LocalReaderBook} to open
+ */
+ private void openBook(final LocalReaderBook book) {
+ final Progress pg = new Progress();
+ outOfUi(pg, new Runnable() {
+ public void run() {
+ try {
+ reader.open(book.getMeta().getLuid(), pg);
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ book.setCached(true);
+ }
+ });
+ } catch (IOException e) {
+ // TODO: error message?
+ Instance.syserr(e);
+ }