* 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;
private Date lastClick;
private long doubleClickDelay = 200; // in ms
private List<BookActionListener> listeners;
+ private String luid;
+ private boolean cached;
+
+ public LocalReaderBook(MetaData meta, boolean cached) {
+ this.luid = meta.getLuid();
+ this.cached = cached;
- public LocalReaderBook(MetaData meta) {
if (meta.getCover() != null) {
BufferedImage resizedImage = new BufferedImage(SPINE_WIDTH
+ COVER_WIDTH, SPINE_HEIGHT + COVER_HEIGHT + HOFFSET,
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) {
listeners.add(listener);
}
+ public String getLuid() {
+ return luid;
+ }
+
+ /**
+ * This boos is cached into the {@link LocalReader} library.
+ *
+ * @return the cached
+ */
+ public boolean isCached() {
+ return cached;
+ }
+
+ /**
+ * This boos is cached into the {@link LocalReader} library.
+ *
+ * @param cached
+ * the cached to set
+ */
+ public void setCached(boolean cached) {
+ this.cached = cached;
+ }
+
@Override
public void paint(Graphics g) {
super.paint(g);
}
Rectangle clip = g.getClipBounds();
+ if (cached) {
+ 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);
}