From: Niki Roo Date: Tue, 21 Feb 2017 14:14:20 +0000 (+0100) Subject: Version 1.2.1: fixes for GUI, new buttons X-Git-Tag: fanfix-1.2.1 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=9843a5e5c44825ac404f45ddccd6f63e554567a4;p=fanfix.git Version 1.2.1: fixes for GUI, new buttons - new actions in GUI - fixes in GUI --- diff --git a/VERSION b/VERSION index 26aaba0..6085e94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.0 +1.2.1 diff --git a/src/be/nikiroo/fanfix/Library.java b/src/be/nikiroo/fanfix/Library.java index cae2d7d..eb9c9a3 100644 --- a/src/be/nikiroo/fanfix/Library.java +++ b/src/be/nikiroo/fanfix/Library.java @@ -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(); diff --git a/src/be/nikiroo/fanfix/output/Html.java b/src/be/nikiroo/fanfix/output/Html.java index 1ec2a08..e11ebcf 100644 --- a/src/be/nikiroo/fanfix/output/Html.java +++ b/src/be/nikiroo/fanfix/output/Html.java @@ -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 { diff --git a/src/be/nikiroo/fanfix/reader/LocalReader.java b/src/be/nikiroo/fanfix/reader/LocalReader.java index 6a66c19..b434737 100644 --- a/src/be/nikiroo/fanfix/reader/LocalReader.java +++ b/src/be/nikiroo/fanfix/reader/LocalReader.java @@ -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; } diff --git a/src/be/nikiroo/fanfix/reader/LocalReaderBook.java b/src/be/nikiroo/fanfix/reader/LocalReaderBook.java index c716bd3..263601c 100644 --- a/src/be/nikiroo/fanfix/reader/LocalReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/LocalReaderBook.java @@ -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(); 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); } diff --git a/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java b/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java index 98530b5..81ebbef 100644 --- a/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java @@ -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 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 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) {