Version 1.2.1: fixes for GUI, new buttons
authorNiki Roo <niki@nikiroo.be>
Tue, 21 Feb 2017 14:14:20 +0000 (15:14 +0100)
committerNiki Roo <niki@nikiroo.be>
Tue, 21 Feb 2017 14:14:20 +0000 (15:14 +0100)
- new actions in GUI
- fixes in GUI

VERSION
src/be/nikiroo/fanfix/Library.java
src/be/nikiroo/fanfix/output/Html.java
src/be/nikiroo/fanfix/reader/LocalReader.java
src/be/nikiroo/fanfix/reader/LocalReaderBook.java
src/be/nikiroo/fanfix/reader/LocalReaderFrame.java

diff --git a/VERSION b/VERSION
index 26aaba0e86632e4d537006e45b0ec918d780b3b4..6085e946503a10fb4d58a5c7d9a6e572c21ddd2e 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.2.0
+1.2.1
index cae2d7dc781990aa4bf8be024d2e53099a9b4582..eb9c9a39f3d4ae76298fd636c0e3e6ad43a962cc 100644 (file)
@@ -17,6 +17,7 @@ import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.fanfix.supported.BasicSupport;
 import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
 import be.nikiroo.fanfix.supported.InfoReader;
+import be.nikiroo.utils.IOUtils;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -322,13 +323,23 @@ public class Library {
 
                if (file != null) {
                        if (file.delete()) {
-                               String newExt = getOutputType(meta).getDefaultExtension(false);
+                               String readerExt = getOutputType(meta)
+                                               .getDefaultExtension(true);
+                               String fileExt = getOutputType(meta).getDefaultExtension(false);
 
                                String path = file.getAbsolutePath();
+                               if (readerExt != null && !readerExt.equals(fileExt)) {
+                                       path = path
+                                                       .substring(0, path.length() - readerExt.length())
+                                                       + fileExt;
+                                       file = new File(path);
+                                       IOUtils.deltree(file);
+                               }
+
                                File infoFile = new File(path + ".info");
                                if (!infoFile.exists()) {
                                        infoFile = new File(path.substring(0, path.length()
-                                                       - newExt.length())
+                                                       - fileExt.length())
                                                        + ".info");
                                }
                                infoFile.delete();
@@ -339,7 +350,7 @@ public class Library {
                                File coverFile = new File(path + coverExt);
                                if (!coverFile.exists()) {
                                        coverFile = new File(path.substring(0, path.length()
-                                                       - newExt.length()));
+                                                       - fileExt.length()));
                                }
                                coverFile.delete();
 
index 1ec2a082df5691ddb8fe136baa6e8a626c06ad1f..e11ebcf426c152bfb349b323ab7469b1db8bd6a1 100644 (file)
@@ -35,7 +35,7 @@ class Html extends BasicOutput {
                dir = target;
 
                target = new File(targetDir, targetName + getDefaultExtension(true));
-
+               
                writer = new BufferedWriter(new OutputStreamWriter(
                                new FileOutputStream(target), "UTF-8"));
                try {
index 6a66c199df79c4b6e48a4d189ecb7670e70c5175..b43473707796f819259df4bf320198d09e749dbd 100644 (file)
@@ -104,6 +104,15 @@ class LocalReader extends BasicReader {
                return file;
        }
 
+       /**
+        * Check if the {@link Story} denoted by this Library UID is present in the
+        * {@link LocalReader} cache.
+        * 
+        * @param luid
+        *            the Library UID
+        * 
+        * @return TRUE if it is
+        */
        public boolean isCached(String luid) {
                return lib.getInfo(luid) != null;
        }
index c716bd3aa47d75f3d3171aaf3d07f261c154bbad..263601c471797cba8154540a5135269dca7ccb89 100644 (file)
@@ -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;
@@ -142,9 +152,15 @@ class LocalReaderBook extends JPanel {
                listeners = new ArrayList<LocalReaderBook.BookActionListener>();
                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) {
@@ -164,20 +180,28 @@ class LocalReaderBook extends JPanel {
                                        } else {
                                                click(false);
                                        }
+
                                        lastClick = now;
                                }
                        }
-               });
-       }
 
-       private void click(boolean doubleClick) {
-               for (BookActionListener 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(BookActionListener listener) {
@@ -243,7 +267,7 @@ class LocalReaderBook extends JPanel {
                        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);
        }
index 98530b5adb2b7169acc644bcb989c59949e95aa0..81ebbeff11a8732325e570388181c61402b6f57d 100644 (file)
@@ -6,6 +6,8 @@ import java.awt.Desktop;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
 import java.awt.event.WindowEvent;
 import java.io.File;
 import java.io.IOException;
@@ -19,6 +21,7 @@ import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
 import javax.swing.SwingUtilities;
 
@@ -86,8 +89,37 @@ class LocalReaderFrame extends JFrame {
                                book.setBackground(color);
                        }
 
+                       book.addMouseListener(new MouseListener() {
+                               public void mouseReleased(MouseEvent e) {
+                                       if (e.isPopupTrigger())
+                                               pop(e);
+                               }
+
+                               public void mousePressed(MouseEvent e) {
+                                       if (e.isPopupTrigger())
+                                               pop(e);
+                               }
+
+                               public void mouseExited(MouseEvent e) {
+                               }
+
+                               public void mouseEntered(MouseEvent e) {
+                               }
+
+                               public void mouseClicked(MouseEvent e) {
+                               }
+
+                               private void pop(MouseEvent e) {
+                                       JPopupMenu popup = new JPopupMenu();
+                                       popup.add(createMenuItemExport());
+                                       popup.add(createMenuItemRefresh());
+                                       popup.addSeparator();
+                                       popup.add(createMenuItemDelete());
+                                       // popup.show(e.getComponent(), e.getX(), e.getY());
+                               }
+                       });
+
                        books.add(book);
-                       final String luid = meta.getLuid();
                        book.addActionListener(new BookActionListener() {
                                public void select(LocalReaderBook book) {
                                        selectedBook = book;
@@ -96,47 +128,19 @@ class LocalReaderFrame extends JFrame {
                                        }
                                }
 
+                               public void popupRequested(LocalReaderBook book, MouseEvent e) {
+                                       JPopupMenu popup = new JPopupMenu();
+                                       popup.add(createMenuItemOpenBook());
+                                       popup.addSeparator();
+                                       popup.add(createMenuItemExport());
+                                       popup.add(createMenuItemRefresh());
+                                       popup.addSeparator();
+                                       popup.add(createMenuItemDelete());
+                                       popup.show(e.getComponent(), e.getX(), e.getY());
+                               }
+
                                public void action(final LocalReaderBook book) {
-                                       final Progress pg = new Progress();
-                                       outOfUi(pg, new Runnable() {
-                                               public void run() {
-                                                       try {
-                                                               File target = LocalReaderFrame.this.reader
-                                                                               .getTarget(luid, pg);
-                                                               book.setCached(true);
-                                                               // TODO: allow custom programs, with
-                                                               // Desktop/xdg-open fallback
-                                                               try {
-                                                                       Desktop.getDesktop().browse(target.toURI());
-                                                               } catch (UnsupportedOperationException e) {
-                                                                       String browsers[] = new String[] {
-                                                                                       "xdg-open", "epiphany",
-                                                                                       "konqueror", "firefox", "chrome",
-                                                                                       "google-chrome", "mozilla" };
-
-                                                                       Runtime runtime = Runtime.getRuntime();
-                                                                       for (String browser : browsers) {
-                                                                               try {
-                                                                                       runtime.exec(new String[] {
-                                                                                                       browser,
-                                                                                                       target.getAbsolutePath() });
-                                                                                       runtime = null;
-                                                                                       break;
-                                                                               } catch (IOException ioe) {
-                                                                                       // continue, try next browser
-                                                                               }
-                                                                       }
-
-                                                                       if (runtime != null) {
-                                                                               throw new IOException(
-                                                                                               "Cannot find a working GUI browser...");
-                                                                       }
-                                                               }
-                                                       } catch (IOException e) {
-                                                               Instance.syserr(e);
-                                                       }
-                                               }
-                                       });
+                                       openBook(book);
                                }
                        });
 
@@ -173,6 +177,9 @@ class LocalReaderFrame extends JFrame {
                        }
                });
 
+               file.add(createMenuItemOpenBook());
+               file.add(createMenuItemExport());
+               file.addSeparator();
                file.add(imprt);
                file.add(imprtF);
                file.addSeparator();
@@ -183,15 +190,52 @@ class LocalReaderFrame extends JFrame {
                JMenu edit = new JMenu("Edit");
                edit.setMnemonic(KeyEvent.VK_E);
 
-               final String notYet = "[TODO] Show not ready yet, but you can do it on command line, see: fanfix --help";
+               edit.add(createMenuItemRefresh());
+               edit.addSeparator();
+               edit.add(createMenuItemDelete());
 
-               JMenuItem export = new JMenuItem("Export", KeyEvent.VK_E);
+               bar.add(edit);
+
+               JMenu view = new JMenu("View");
+               view.setMnemonic(KeyEvent.VK_V);
+
+               List<String> tt = Instance.getLibrary().getTypes();
+               tt.add(0, null);
+               for (final String type : tt) {
+
+                       JMenuItem item = new JMenuItem(type == null ? "All books" : type);
+                       item.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       refreshBooks(type);
+                               }
+                       });
+                       view.add(item);
+
+                       if (type == null) {
+                               view.addSeparator();
+                       }
+               }
+
+               bar.add(view);
+
+               return bar;
+       }
+
+       private JMenuItem createMenuItemExport() {
+               // TODO
+               final String notYet = "[TODO] not ready yet, but you can do it on command line, see: fanfix --help";
+
+               JMenuItem export = new JMenuItem("Save as...", KeyEvent.VK_E);
                export.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                JOptionPane.showMessageDialog(LocalReaderFrame.this, notYet);
                        }
                });
 
+               return export;
+       }
+
+       private JMenuItem createMenuItemRefresh() {
                JMenuItem refresh = new JMenuItem("Refresh", KeyEvent.VK_R);
                refresh.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
@@ -211,6 +255,10 @@ class LocalReaderFrame extends JFrame {
                        }
                });
 
+               return refresh;
+       }
+
+       private JMenuItem createMenuItemDelete() {
                JMenuItem delete = new JMenuItem("Delete", KeyEvent.VK_D);
                delete.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
@@ -230,35 +278,61 @@ class LocalReaderFrame extends JFrame {
                        }
                });
 
-               edit.add(export);
-               edit.add(refresh);
-               edit.add(delete);
+               return delete;
+       }
 
-               bar.add(edit);
+       private JMenuItem createMenuItemOpenBook() {
+               JMenuItem open = new JMenuItem("Open", KeyEvent.VK_O);
+               open.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               if (selectedBook != null) {
+                                       openBook(selectedBook);
+                               }
+                       }
+               });
 
-               JMenu view = new JMenu("View");
-               view.setMnemonic(KeyEvent.VK_V);
+               return open;
+       }
 
-               List<String> tt = Instance.getLibrary().getTypes();
-               tt.add(0, null);
-               for (final String type : tt) {
+       private void openBook(final LocalReaderBook book) {
+               final Progress pg = new Progress();
+               outOfUi(pg, new Runnable() {
+                       public void run() {
+                               try {
+                                       File target = LocalReaderFrame.this.reader.getTarget(
+                                                       book.getLuid(), pg);
+                                       book.setCached(true);
+                                       // TODO: allow custom programs, with
+                                       // Desktop/xdg-open fallback
+                                       try {
+                                               Desktop.getDesktop().browse(target.toURI());
+                                       } catch (UnsupportedOperationException e) {
+                                               String browsers[] = new String[] { "xdg-open",
+                                                               "epiphany", "konqueror", "firefox", "chrome",
+                                                               "google-chrome", "mozilla" };
+
+                                               Runtime runtime = Runtime.getRuntime();
+                                               for (String browser : browsers) {
+                                                       try {
+                                                               runtime.exec(new String[] { browser,
+                                                                               target.getAbsolutePath() });
+                                                               runtime = null;
+                                                               break;
+                                                       } catch (IOException ioe) {
+                                                               // continue, try next browser
+                                                       }
+                                               }
 
-                       JMenuItem item = new JMenuItem(type == null ? "All books" : type);
-                       item.addActionListener(new ActionListener() {
-                               public void actionPerformed(ActionEvent e) {
-                                       refreshBooks(type);
+                                               if (runtime != null) {
+                                                       throw new IOException(
+                                                                       "Cannot find a working GUI browser...");
+                                               }
+                                       }
+                               } catch (IOException e) {
+                                       Instance.syserr(e);
                                }
-                       });
-                       view.add(item);
-
-                       if (type == null) {
-                               view.addSeparator();
                        }
-               }
-
-               bar.add(view);
-
-               return bar;
+               });
        }
 
        private void outOfUi(final Progress pg, final Runnable run) {