From: Niki Roo Date: Sun, 24 Mar 2019 19:18:24 +0000 (+0100) Subject: gui: better refresh for changeSTA X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=c349fd480d7ab36ad423e965434a6f1f418d60a5;p=fanfix-jexer.git gui: better refresh for changeSTA --- diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java index af2a5a7..15d2ad4 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java @@ -68,6 +68,7 @@ class GuiReaderBook extends JPanel { private List listeners; private GuiReaderBookInfo info; private boolean cached; + private boolean seeWordCount; /** * Create a new {@link GuiReaderBook} item for the given {@link Story}. @@ -83,22 +84,15 @@ class GuiReaderBook extends JPanel { */ public GuiReaderBook(Reader reader, GuiReaderBookInfo info, boolean cached, boolean seeWordCount) { - this.cached = cached; this.info = info; - - String optSecondary = info.getSecondaryInfo(seeWordCount); + this.cached = cached; + this.seeWordCount = seeWordCount; icon = new JLabel(GuiReaderCoverImager.generateCoverIcon( reader.getLibrary(), info)); - title = new JLabel( - String.format( - "" - + "" - + "%s" + "
" + "" - + "%s" + "" + "" + "", - GuiReaderCoverImager.TEXT_WIDTH, - GuiReaderCoverImager.TEXT_HEIGHT, info.getMainInfo(), - AUTHOR_COLOR, optSecondary)); + + title = new JLabel(); + updateTitle(); setLayout(new BorderLayout(10, 10)); add(icon, BorderLayout.CENTER); @@ -258,12 +252,30 @@ class GuiReaderBook extends JPanel { } /** - * Paint the item, then call {@link GuiReaderBook#paintOverlay(Graphics)}. + * Update the title, paint the item, then call + * {@link GuiReaderCoverImager#paintOverlay(Graphics, boolean, boolean, boolean, boolean)} + * . */ @Override public void paint(Graphics g) { + updateTitle(); super.paint(g); GuiReaderCoverImager.paintOverlay(g, isEnabled(), isSelected(), isHovered(), isCached()); } + + /** + * Update the title with the currently registered information. + */ + private void updateTitle() { + String optSecondary = info.getSecondaryInfo(seeWordCount); + title.setText(String + .format("" + + "" + + "%s" + "
" + "" + "%s" + + "" + "" + "", + GuiReaderCoverImager.TEXT_WIDTH, + GuiReaderCoverImager.TEXT_HEIGHT, info.getMainInfo(), + AUTHOR_COLOR, optSecondary)); + } } diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java index fe34844..93763f9 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java @@ -32,6 +32,10 @@ public class GuiReaderBookInfo { } public String getMainInfo() { + if (meta != null) { + return meta.getTitle(); + } + return value; } diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index 9754102..8200754 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -611,6 +611,16 @@ class GuiReaderFrame extends JFrame implements FrameHelper { public void actionPerformed(ActionEvent e) { final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { + boolean refreshRequired = false; + + if (what == ChangeAction.SOURCE) { + refreshRequired = mainPanel.getCurrentType(); + } else if (what == ChangeAction.TITLE) { + refreshRequired = false; + } else if (what == ChangeAction.AUTHOR) { + refreshRequired = !mainPanel.getCurrentType(); + } + String changeTo = type; if (type == null) { MetaData meta = selectedBook.getInfo().getMeta(); @@ -636,7 +646,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { } final String fChangeTo = changeTo; - mainPanel.outOfUi(null, true, new Runnable() { + mainPanel.outOfUi(null, refreshRequired, new Runnable() { @Override public void run() { String luid = selectedBook.getInfo().getMeta() @@ -649,6 +659,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { reader.changeAuthor(luid, fChangeTo); } + mainPanel.getSelectedBook().repaint(); mainPanel.unsetSelectedBook(); SwingUtilities.invokeLater(new Runnable() { @@ -707,15 +718,25 @@ class GuiReaderFrame extends JFrame implements FrameHelper { @Override public void actionPerformed(ActionEvent e) { final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); - if (selectedBook != null) { - mainPanel.outOfUi(null, true, new Runnable() { - @Override - public void run() { - reader.delete(selectedBook.getInfo().getMeta() - .getLuid()); - mainPanel.unsetSelectedBook(); - } - }); + if (selectedBook != null + && selectedBook.getInfo().getMeta() != null) { + + final MetaData meta = selectedBook.getInfo().getMeta(); + int rep = JOptionPane.showConfirmDialog( + GuiReaderFrame.this, + String.format("Delete %s: %s", meta.getLuid(), + meta.getTitle()), "Delete story", + JOptionPane.OK_CANCEL_OPTION); + + if (rep == JOptionPane.OK_OPTION) { + mainPanel.outOfUi(null, true, new Runnable() { + @Override + public void run() { + reader.delete(meta.getLuid()); + mainPanel.unsetSelectedBook(); + } + }); + } } } }); diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java index 160dfb4..45c7a8f 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java @@ -83,8 +83,8 @@ public class GuiReaderGroup extends JPanel { /** * Refresh the list of {@link GuiReaderBook}s displayed in the control. * - * @param stories - * the new list of stories + * @param infos + * the new list of infos * @param seeWordcount * TRUE to see word counts, FALSE to see authors */