gui: better refresh for changeSTA
authorNiki Roo <niki@nikiroo.be>
Sun, 24 Mar 2019 19:18:24 +0000 (20:18 +0100)
committerNiki Roo <niki@nikiroo.be>
Sun, 24 Mar 2019 19:18:24 +0000 (20:18 +0100)
src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java

index af2a5a783f370a7b0cd52d0c83f134545a6c5bc5..15d2ad4407ed487554a5586e6c2012986e5b2fb3 100644 (file)
@@ -68,6 +68,7 @@ class GuiReaderBook extends JPanel {
        private List<BookActionListener> 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(
-                                               "<html>"
-                                                               + "<body style='width: %d px; height: %d px; text-align: center'>"
-                                                               + "%s" + "<br>" + "<span style='color: %s;'>"
-                                                               + "%s" + "</span>" + "</body>" + "</html>",
-                                               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("<html>"
+                                               + "<body style='width: %d px; height: %d px; text-align: center'>"
+                                               + "%s" + "<br>" + "<span style='color: %s;'>" + "%s"
+                                               + "</span>" + "</body>" + "</html>",
+                                               GuiReaderCoverImager.TEXT_WIDTH,
+                                               GuiReaderCoverImager.TEXT_HEIGHT, info.getMainInfo(),
+                                               AUTHOR_COLOR, optSecondary));
+       }
 }
index fe34844dd6e6b45500d64043cc9df9fa73ff0620..93763f941092c3fbb8a4e05133f05d3d2ec22163 100644 (file)
@@ -32,6 +32,10 @@ public class GuiReaderBookInfo {
        }
 
        public String getMainInfo() {
+               if (meta != null) {
+                       return meta.getTitle();
+               }
+
                return value;
        }
 
index 97541026188404fd27420d5184f38c41a02e2f54..820075426d812286bb0e9966b7ab7929641cc5dd 100644 (file)
@@ -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();
+                                                       }
+                                               });
+                                       }
                                }
                        }
                });
index 160dfb4d6557859d3195d7a9cf8d031a2ab6a2ed..45c7a8fcf7a4321091c5063341b0a5c66a6b920b 100644 (file)
@@ -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
         */