private Date lastClick;
private List<BookActionListener> listeners;
- private String luid;
+ private MetaData meta;
private boolean cached;
/**
- * Create a new {@link LocalReaderBook} item for the givn {@link Story}.
+ * Create a new {@link LocalReaderBook} item for the given {@link Story}.
*
* @param meta
* the story {@code}link MetaData}
* @param cached
* TRUE if it is locally cached
+ * @param seeWordcount
+ * TRUE to see word counts, FALSE to see authors
*/
- public LocalReaderBook(MetaData meta, boolean cached) {
- this.luid = meta.getLuid();
+ public LocalReaderBook(MetaData meta, boolean cached, boolean seeWordCount) {
this.cached = cached;
-
- BufferedImage resizedImage = new BufferedImage(SPINE_WIDTH
- + COVER_WIDTH, SPINE_HEIGHT + COVER_HEIGHT + HOFFSET,
- BufferedImage.TYPE_4BYTE_ABGR);
- Graphics2D g = resizedImage.createGraphics();
- g.setColor(Color.white);
- g.fillRect(0, HOFFSET, COVER_WIDTH, COVER_HEIGHT);
- if (meta.getCover() != null) {
- g.drawImage(meta.getCover(), 0, HOFFSET, COVER_WIDTH, COVER_HEIGHT,
- null);
- } else {
- g.setColor(Color.black);
- g.drawLine(0, HOFFSET, COVER_WIDTH, HOFFSET + COVER_HEIGHT);
- g.drawLine(COVER_WIDTH, HOFFSET, 0, HOFFSET + COVER_HEIGHT);
+ this.meta = meta;
+
+ String optSecondary = meta.getAuthor();
+ if (seeWordCount) {
+ if (meta.getWords() >= 4000) {
+ optSecondary = (meta.getWords() / 1000) + "k words";
+ } else if (meta.getWords() > 0) {
+ optSecondary = meta.getWords() + " words";
+ } else {
+ optSecondary = "";
+ }
}
- g.dispose();
-
- icon = new JLabel(new ImageIcon(resizedImage));
- String optAuthor = meta.getAuthor();
- if (optAuthor != null && !optAuthor.isEmpty()) {
- optAuthor = "(" + optAuthor + ")";
+ if (optSecondary != null && !optSecondary.isEmpty()) {
+ optSecondary = "(" + optSecondary + ")";
}
+ icon = new JLabel(generateCoverIcon(meta.getCover()));
+
title = new JLabel(
String.format(
"<html>"
+ "%s" + "<br>" + "<span style='color: %s;'>"
+ "%s" + "</span>" + "</body>" + "</html>",
TEXT_WIDTH, TEXT_HEIGHT, meta.getTitle(), AUTHOR_COLOR,
- optAuthor));
+ optSecondary));
- this.setLayout(new BorderLayout(10, 10));
- this.add(icon, BorderLayout.CENTER);
- this.add(title, BorderLayout.SOUTH);
+ setLayout(new BorderLayout(10, 10));
+ add(icon, BorderLayout.CENTER);
+ add(title, BorderLayout.SOUTH);
setupListeners();
- setSelected(false);
}
/**
* TRUE if it is selected
*/
public void setSelected(boolean selected) {
- this.selected = selected;
- repaint();
+ if (this.selected != selected) {
+ this.selected = selected;
+ repaint();
+ }
}
/**
* TRUE if it is mouse-hovered
*/
private void setHovered(boolean hovered) {
- this.hovered = hovered;
- repaint();
+ if (this.hovered != hovered) {
+ this.hovered = hovered;
+ repaint();
+ }
}
/**
}
/**
- * The Library UID of the book represented by this item.
+ * The Library {@code}link MetaData} of the book represented by this item.
*
- * @return the LUID
+ * @return the meta
*/
- public String getLuid() {
- return luid;
+ public MetaData getMeta() {
+ return meta;
}
/**
* TRUE if it is present in the {@link LocalReader} cache
*/
public void setCached(boolean cached) {
- this.cached = cached;
+ if (this.cached != cached) {
+ this.cached = cached;
+ repaint();
+ }
}
/**
- * Draw a "cached" icon and a partially transparent overlay if needed
- * depending upon the selection and mouse-hover states on top of the normal
- * component.
+ * Paint the item, then call {@link LocalReaderBook#paintOverlay(Graphics)}.
*/
@Override
public void paint(Graphics g) {
super.paint(g);
+ paintOverlay(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.
+ */
+ public void paintOverlay(Graphics g) {
Rectangle clip = g.getClipBounds();
if (clip.getWidth() <= 0 || clip.getHeight() <= 0) {
return;
+ HOFFSET + 30, 10, 20, 20);
}
}
+
+ /**
+ * Generate a cover icon based upon the given cover image (which may be
+ * NULL).
+ *
+ * @param image
+ * the cover image, or NULL for none
+ *
+ * @return the icon
+ */
+ private ImageIcon generateCoverIcon(BufferedImage image) {
+ BufferedImage resizedImage = new BufferedImage(SPINE_WIDTH
+ + COVER_WIDTH, SPINE_HEIGHT + COVER_HEIGHT + HOFFSET,
+ BufferedImage.TYPE_4BYTE_ABGR);
+ Graphics2D g = resizedImage.createGraphics();
+ g.setColor(Color.white);
+ g.fillRect(0, HOFFSET, COVER_WIDTH, COVER_HEIGHT);
+ if (image != null) {
+ g.drawImage(image, 0, HOFFSET, COVER_WIDTH, COVER_HEIGHT, null);
+ } else {
+ g.setColor(Color.black);
+ g.drawLine(0, HOFFSET, COVER_WIDTH, HOFFSET + COVER_HEIGHT);
+ g.drawLine(COVER_WIDTH, HOFFSET, 0, HOFFSET + COVER_HEIGHT);
+ }
+ g.dispose();
+
+ return new ImageIcon(resizedImage);
+ }
}