* the {@link LocalReaderBook} itself
*/
public void action(LocalReaderBook book);
+
+ /**
+ * A popup menu was requested for this {@link LocalReaderBook}.
+ *
+ * @param book
+ * the {@link LocalReaderBook} itself
+ * @param e
+ * the {@link MouseEvent} that generated this call
+ */
+ public void popupRequested(LocalReaderBook book, MouseEvent e);
}
private static final int COVER_WIDTH = 100;
listeners = new ArrayList<LocalReaderBook.BookActionListener>();
addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
+ if (e.isPopupTrigger()) {
+ popup(e);
+ }
}
public void mousePressed(MouseEvent e) {
+ if (e.isPopupTrigger()) {
+ popup(e);
+ }
}
public void mouseExited(MouseEvent e) {
} else {
click(false);
}
+
lastClick = now;
}
}
- });
- }
- private void click(boolean doubleClick) {
- for (BookActionListener listener : listeners) {
- if (doubleClick) {
- listener.action(this);
- } else {
- listener.select(this);
+ private void click(boolean doubleClick) {
+ for (BookActionListener listener : listeners) {
+ if (doubleClick) {
+ listener.action(LocalReaderBook.this);
+ } else {
+ listener.select(LocalReaderBook.this);
+ }
+ }
}
- }
+
+ private void popup(MouseEvent e) {
+ for (BookActionListener listener : listeners) {
+ listener.select((LocalReaderBook.this));
+ listener.popupRequested(LocalReaderBook.this, e);
+ }
+ }
+ });
}
public void addActionListener(BookActionListener listener) {
g.setColor(Color.green);
g.fillOval(clip.x + clip.width - 30, 10, 20, 20);
}
-
+
g.setColor(color);
g.fillRect(clip.x, clip.y, clip.width, clip.height);
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
book.setBackground(color);
}
+ book.addMouseListener(new MouseListener() {
+ public void mouseReleased(MouseEvent e) {
+ if (e.isPopupTrigger())
+ pop(e);
+ }
+
+ public void mousePressed(MouseEvent e) {
+ if (e.isPopupTrigger())
+ pop(e);
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ private void pop(MouseEvent e) {
+ JPopupMenu popup = new JPopupMenu();
+ popup.add(createMenuItemExport());
+ popup.add(createMenuItemRefresh());
+ popup.addSeparator();
+ popup.add(createMenuItemDelete());
+ // popup.show(e.getComponent(), e.getX(), e.getY());
+ }
+ });
+
books.add(book);
- final String luid = meta.getLuid();
book.addActionListener(new BookActionListener() {
public void select(LocalReaderBook book) {
selectedBook = book;
}
}
+ public void popupRequested(LocalReaderBook book, MouseEvent e) {
+ JPopupMenu popup = new JPopupMenu();
+ popup.add(createMenuItemOpenBook());
+ popup.addSeparator();
+ popup.add(createMenuItemExport());
+ popup.add(createMenuItemRefresh());
+ popup.addSeparator();
+ popup.add(createMenuItemDelete());
+ popup.show(e.getComponent(), e.getX(), e.getY());
+ }
+
public void action(final LocalReaderBook book) {
- final Progress pg = new Progress();
- outOfUi(pg, new Runnable() {
- public void run() {
- try {
- File target = LocalReaderFrame.this.reader
- .getTarget(luid, pg);
- book.setCached(true);
- // TODO: allow custom programs, with
- // Desktop/xdg-open fallback
- try {
- Desktop.getDesktop().browse(target.toURI());
- } catch (UnsupportedOperationException e) {
- String browsers[] = new String[] {
- "xdg-open", "epiphany",
- "konqueror", "firefox", "chrome",
- "google-chrome", "mozilla" };
-
- Runtime runtime = Runtime.getRuntime();
- for (String browser : browsers) {
- try {
- runtime.exec(new String[] {
- browser,
- target.getAbsolutePath() });
- runtime = null;
- break;
- } catch (IOException ioe) {
- // continue, try next browser
- }
- }
-
- if (runtime != null) {
- throw new IOException(
- "Cannot find a working GUI browser...");
- }
- }
- } catch (IOException e) {
- Instance.syserr(e);
- }
- }
- });
+ openBook(book);
}
});
}
});
+ file.add(createMenuItemOpenBook());
+ file.add(createMenuItemExport());
+ file.addSeparator();
file.add(imprt);
file.add(imprtF);
file.addSeparator();
JMenu edit = new JMenu("Edit");
edit.setMnemonic(KeyEvent.VK_E);
- final String notYet = "[TODO] Show not ready yet, but you can do it on command line, see: fanfix --help";
+ edit.add(createMenuItemRefresh());
+ edit.addSeparator();
+ edit.add(createMenuItemDelete());
- JMenuItem export = new JMenuItem("Export", KeyEvent.VK_E);
+ bar.add(edit);
+
+ JMenu view = new JMenu("View");
+ view.setMnemonic(KeyEvent.VK_V);
+
+ List<String> tt = Instance.getLibrary().getTypes();
+ tt.add(0, null);
+ for (final String type : tt) {
+
+ JMenuItem item = new JMenuItem(type == null ? "All books" : type);
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ refreshBooks(type);
+ }
+ });
+ view.add(item);
+
+ if (type == null) {
+ view.addSeparator();
+ }
+ }
+
+ bar.add(view);
+
+ return bar;
+ }
+
+ private JMenuItem createMenuItemExport() {
+ // TODO
+ final String notYet = "[TODO] not ready yet, but you can do it on command line, see: fanfix --help";
+
+ JMenuItem export = new JMenuItem("Save as...", KeyEvent.VK_E);
export.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(LocalReaderFrame.this, notYet);
}
});
+ return export;
+ }
+
+ private JMenuItem createMenuItemRefresh() {
JMenuItem refresh = new JMenuItem("Refresh", KeyEvent.VK_R);
refresh.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
+ return refresh;
+ }
+
+ private JMenuItem createMenuItemDelete() {
JMenuItem delete = new JMenuItem("Delete", KeyEvent.VK_D);
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
- edit.add(export);
- edit.add(refresh);
- edit.add(delete);
+ return delete;
+ }
- bar.add(edit);
+ 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);
+ }
+ }
+ });
- JMenu view = new JMenu("View");
- view.setMnemonic(KeyEvent.VK_V);
+ return open;
+ }
- List<String> tt = Instance.getLibrary().getTypes();
- tt.add(0, null);
- for (final String type : tt) {
+ private void openBook(final LocalReaderBook book) {
+ final Progress pg = new Progress();
+ outOfUi(pg, new Runnable() {
+ public void run() {
+ try {
+ File target = LocalReaderFrame.this.reader.getTarget(
+ book.getLuid(), pg);
+ book.setCached(true);
+ // TODO: allow custom programs, with
+ // Desktop/xdg-open fallback
+ try {
+ Desktop.getDesktop().browse(target.toURI());
+ } catch (UnsupportedOperationException e) {
+ String browsers[] = new String[] { "xdg-open",
+ "epiphany", "konqueror", "firefox", "chrome",
+ "google-chrome", "mozilla" };
+
+ Runtime runtime = Runtime.getRuntime();
+ for (String browser : browsers) {
+ try {
+ runtime.exec(new String[] { browser,
+ target.getAbsolutePath() });
+ runtime = null;
+ break;
+ } catch (IOException ioe) {
+ // continue, try next browser
+ }
+ }
- JMenuItem item = new JMenuItem(type == null ? "All books" : type);
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- refreshBooks(type);
+ if (runtime != null) {
+ throw new IOException(
+ "Cannot find a working GUI browser...");
+ }
+ }
+ } catch (IOException e) {
+ Instance.syserr(e);
}
- });
- view.add(item);
-
- if (type == null) {
- view.addSeparator();
}
- }
-
- bar.add(view);
-
- return bar;
+ });
}
private void outOfUi(final Progress pg, final Runnable run) {