X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FLocalReaderBook.java;h=263601c471797cba8154540a5135269dca7ccb89;hb=9843a5e5c44825ac404f45ddccd6f63e554567a4;hp=8e353d91472cb3b738490ca3c108a92a7de8bc55;hpb=b4dc6ab518ded2dd92e4cbb02ac615b1d57e8e6d;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/LocalReaderBook.java b/src/be/nikiroo/fanfix/reader/LocalReaderBook.java index 8e353d9..263601c 100644 --- a/src/be/nikiroo/fanfix/reader/LocalReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/LocalReaderBook.java @@ -31,7 +31,7 @@ class LocalReaderBook extends JPanel { * * @author niki */ - interface BookActionListner extends EventListener { + interface BookActionListener extends EventListener { /** * The book was selected (single click). * @@ -47,6 +47,16 @@ class LocalReaderBook extends JPanel { * 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; @@ -59,17 +69,22 @@ class LocalReaderBook extends JPanel { private static final int TEXT_WIDTH = COVER_WIDTH + 40; private static final int TEXT_HEIGHT = 50; private static final String AUTHOR_COLOR = "#888888"; - private static final long serialVersionUID = 1L; + private JLabel icon; - private JLabel tt; + private JLabel title; private boolean selected; private boolean hovered; private Date lastClick; private long doubleClickDelay = 200; // in ms - private List listeners; + private List 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, @@ -91,7 +106,7 @@ class LocalReaderBook extends JPanel { if (optAuthor != null && !optAuthor.isEmpty()) { optAuthor = "(" + optAuthor + ")"; } - tt = new JLabel( + title = new JLabel( String.format( "" + "" @@ -102,7 +117,7 @@ class LocalReaderBook extends JPanel { this.setLayout(new BorderLayout(10, 10)); this.add(icon, BorderLayout.CENTER); - this.add(tt, BorderLayout.SOUTH); + this.add(title, BorderLayout.SOUTH); setupListeners(); setSelected(false); @@ -134,12 +149,18 @@ class LocalReaderBook extends JPanel { } private void setupListeners() { - listeners = new ArrayList(); + listeners = new ArrayList(); 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) { @@ -151,32 +172,65 @@ class LocalReaderBook extends JPanel { } public void mouseClicked(MouseEvent e) { - Date now = new Date(); - if (lastClick != null - && now.getTime() - lastClick.getTime() < doubleClickDelay) { - click(true); - } else { - click(false); + if (isEnabled()) { + Date now = new Date(); + if (lastClick != null + && now.getTime() - lastClick.getTime() < doubleClickDelay) { + click(true); + } else { + click(false); + } + + lastClick = now; } - lastClick = now; } - }); - } - private void click(boolean doubleClick) { - for (BookActionListner 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(BookActionListner listener) { + 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); @@ -199,7 +253,8 @@ class LocalReaderBook extends JPanel { g.fillPolygon(new Polygon(xs, ys, xs.length)); Color color = new Color(255, 255, 255, 0); - if (selected && !hovered) { + if (!isEnabled()) { + } else if (selected && !hovered) { color = new Color(80, 80, 100, 40); } else if (!selected && hovered) { color = new Color(230, 230, 255, 100); @@ -208,6 +263,11 @@ class LocalReaderBook extends JPanel { } 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); }