From: Niki Roo Date: Wed, 8 Apr 2020 15:46:00 +0000 (+0200) Subject: details: delay and do last one only X-Git-Tag: fanfix-3.1.2~20^2~12^2~17 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=abf564fe64ada9b63f0b25397d54da875c39c920;p=fanfix.git details: delay and do last one only --- diff --git a/src/be/nikiroo/fanfix_swing/gui/DetailsPanel.java b/src/be/nikiroo/fanfix_swing/gui/DetailsPanel.java index da1af4c..ced9c3b 100644 --- a/src/be/nikiroo/fanfix_swing/gui/DetailsPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/DetailsPanel.java @@ -31,6 +31,8 @@ public class DetailsPanel extends JPanel { private JLabel name; private JLabel opt; + private BookInfo info; + /** * Create a new {@link DetailsPanel}. */ @@ -77,25 +79,41 @@ public class DetailsPanel extends JPanel { * @param info the {@link BookInfo} to display */ public void setBook(final BookInfo info) { + this.info = info; + icon.setIcon(null); if (info == null) { name.setText(null); opt.setText(null); } else { + final String myId = info.getId(); + name.setText(info.getMainInfo()); opt.setText(info.getSecondaryInfo(true)); new SwingWorker() { @Override protected Image doInBackground() throws Exception { - return BookBlock.generateCoverImage(Instance.getInstance().getLibrary(), info); + Thread.sleep(20); + + BookInfo current = DetailsPanel.this.info; + if (current != null && current.getId().equals(myId)) { + return BookBlock.generateCoverImage(Instance.getInstance().getLibrary(), info); + } + + return null; } @Override protected void done() { - try { - icon.setIcon(new ImageIcon(get())); - } catch (InterruptedException e) { - } catch (ExecutionException e) { + BookInfo current = DetailsPanel.this.info; + if (current != null && current.getId().equals(myId)) { + try { + Image img = get(); + if (img != null) + icon.setIcon(new ImageIcon(img)); + } catch (InterruptedException e) { + } catch (ExecutionException e) { + } } } }.execute();