+ 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);
+ }
+ }
+ });
+ }
+
+ /**
+ * Process the given action out of the Swing UI thread and link the given
+ * {@link ProgressBar} to the action.
+ * <p>
+ * The code will make sure that the {@link ProgressBar} (if not NULL) is set
+ * to done when the action is done.
+ *
+ * @param pg
+ * the {@link ProgressBar} or NULL
+ * @param run
+ * the action to run
+ */
+ private void outOfUi(Progress progress, final Runnable run) {
+ final Progress pg = new Progress();
+ final Progress reload = new Progress("Reload books");
+ if (progress == null) {
+ progress = new Progress();
+ }
+
+ pg.addProgress(progress, 90);
+ pg.addProgress(reload, 10);
+
+ invalidate();
+ pgBar.setProgress(pg);
+ validate();
+ setEnabled(false);
+