From abf564fe64ada9b63f0b25397d54da875c39c920 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 8 Apr 2020 17:46:00 +0200 Subject: [PATCH] details: delay and do last one only --- .../fanfix_swing/gui/DetailsPanel.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) 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(); -- 2.27.0