From 4e02024dd76199f19e01eb698a1afc1f175b8644 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 5 May 2020 21:33:58 +0200 Subject: [PATCH] move to fanfix new Main class --- README-fr.md | 2 +- README.md | 2 +- changelog-fr.md | 3 +- changelog.md | 3 +- src/be/nikiroo/fanfix_swing/Main.java | 172 +++++++++++++++++- .../nikiroo/fanfix_swing/gui/MainFrame.java | 16 -- .../fanfix_swing/gui/PropertiesDialog.java | 3 +- .../fanfix_swing/gui/book/BookPopup.java | 35 ++-- .../fanfix_swing/gui/search/GRGroup.java | 4 +- .../fanfix_swing/gui/viewer/ViewerImages.java | 4 +- 10 files changed, 191 insertions(+), 53 deletions(-) diff --git a/README-fr.md b/README-fr.md index 32095cea..8b5d7e41 100644 --- a/README-fr.md +++ b/README-fr.md @@ -11,7 +11,7 @@ Fanfix-swing est un programme qui offre une interface graphique (en java Swing) ## Description -(Si vous voulez juste voir les derniers changements, vous pouvez regarder le [Changelog](changelog-fr.md) -- remarquez que le programme affiche le changelog si une version plus récente est détectée depuis la version x.x.x.) +(Si vous voulez juste voir les derniers changements, vous pouvez regarder le [Changelog](changelog-fr.md) -- remarquez que le programme affiche le changelog si une version plus récente est détectée depuis la version 1.2.0.) ![Main GUI](screenshots/fanfix-swing.png?raw=true "Fenêtre principale") diff --git a/README.md b/README.md index 7624e0da..f8217511 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Fanfix-swing is a program that offer you a graphical interface (in java Swing) a ## Description -(If you are interested in the recent changes, please check the [Changelog](changelog.md) -- note that starting from version x.x.x, the changelog is checked at startup.) +(If you are interested in the recent changes, please check the [Changelog](changelog.md) -- note that starting from version 1.2.0, the changelog is checked at startup.) ![Main GUI](screenshots/fanfix-swing.png?raw=true "Main window") diff --git a/changelog-fr.md b/changelog-fr.md index 9c2a4e27..f3d47851 100644 --- a/changelog-fr.md +++ b/changelog-fr.md @@ -2,14 +2,15 @@ ## Version WIP +- new: le programme vérifie si une version plus récente est disponible (comme Fanfix) - new: l'afficheur d'images peut zoomer avec la molette de la souris et control - fix: l'afficheur d'images affiche maintenant l'image retournée quand on fait une rotation, au lieu de retourner les pixels mais dans la même hauteur / lageur - fix: l'afficheur d'images scroll correctement quand on zoom ## Version 1.1.1 -- fix: récupère maintenant correctement les hitsoires sans chaptitres - new: l'afficheur de livres interne est maintenant correctement refait +- fix: récupère maintenant correctement les hitsoires sans chaptitres ## Version 1.1.0 diff --git a/changelog.md b/changelog.md index c1eb5b52..f8927742 100644 --- a/changelog.md +++ b/changelog.md @@ -2,14 +2,15 @@ ## Version WIP +- new: the program checks if a new version is available (like Fanfix does) - new: the image viewer now zooms on mousewheel + control - fix: the image viewer now displayes turned images on rotation, instead of rotating the pixels but in the same height/width - fix: the image viewer scrolls correctly when we zoom ## Version 1.1.1 -- fix: now correctly retrieve stories without chapters - new: the internal viewer is now up to par +- fix: now correctly retrieve stories without chapters ## Version 1.1.0 diff --git a/src/be/nikiroo/fanfix_swing/Main.java b/src/be/nikiroo/fanfix_swing/Main.java index 1423f762..3164196a 100644 --- a/src/be/nikiroo/fanfix_swing/Main.java +++ b/src/be/nikiroo/fanfix_swing/Main.java @@ -1,9 +1,24 @@ package be.nikiroo.fanfix_swing; +import java.awt.Desktop; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.concurrent.ExecutionException; + +import javax.swing.JEditorPane; import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.SwingWorker; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.VersionCheck; +import be.nikiroo.fanfix.bundles.StringIdGui; +import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix_swing.gui.MainFrame; +import be.nikiroo.utils.Version; import be.nikiroo.utils.ui.UIUtils; /** @@ -11,26 +26,68 @@ import be.nikiroo.utils.ui.UIUtils; * * @author niki */ -public class Main { +public class Main extends be.nikiroo.fanfix.Main { + private boolean busy; + /** * The main entry point of the application. *

- * If arguments are passed, everything will be passed to Fanfix CLI; if no - * argument are present, Fanfix-Swing proper will be launched. + * It overrides some function of Fanfix's Main. * * @param args * the arguments (none, or will be passed to Fanfix) */ public static void main(String[] args) { - // Defer to main application if parameters (we are only a UI) - // (though we could handle some of the parameters in the future, - // maybe importing via ImporterFrame? but that would require a - // unique instance of the UI to be usable...) - if (args != null && args.length > 0) { - be.nikiroo.fanfix.Main.main(args); - return; + new Main().start(args); + } + + @Override + protected VersionCheck checkUpdates() { + new SwingWorker() { + @Override + protected VersionCheck doInBackground() throws Exception { + return VersionCheck.check("nikiroo/fanfix-swing"); + } + + @Override + protected void done() { + try { + VersionCheck v = get(); + if (v != null && v.isNewVersionAvailable()) { + notifyUpdates(v); + } + } catch (InterruptedException e) { + } catch (ExecutionException e) { + } + } + }.execute(); + + return null; + } + + @Override + protected void exit(final int status) { + if (busy) { + new Thread(new Runnable() { + @Override + public void run() { + while (busy) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + + Main.super.exit(status); + } + } + }).start(); + } else { + super.exit(status); } + } + @Override + protected void start() throws IOException { UIUtils.setLookAndFeel(); Instance.init(); @@ -38,4 +95,99 @@ public class Main { main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); main.setVisible(true); } + + @Override + protected int read(Story story, Integer chap) { + if (chap == null) { + Actions.openBook(Instance.getInstance().getLibrary(), + story.getMeta(), null, null); + return 0; + } + + return super.read(story, chap); + } + + @Override + protected void notifyUpdates(VersionCheck updates) { + StringBuilder builder = new StringBuilder(); + final JEditorPane updateMessage = new JEditorPane("text/html", ""); + builder.append(trans(StringIdGui.NEW_VERSION_AVAILABLE, + "" + + "https://github.com/nikiroo/fanfix-swing/releases" + + "")); + builder.append("
"); + builder.append("
"); + for (Version v : updates.getNewer()) { + builder.append("\t" + + trans(StringIdGui.NEW_VERSION_VERSION, v.toString()) + + ""); + builder.append("
"); + builder.append("

"); + } + + // html content + updateMessage.setText("" // + + builder// + + ""); + + // handle link events + updateMessage.addHyperlinkListener(new HyperlinkListener() { + @Override + public void hyperlinkUpdate(HyperlinkEvent e) { + if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) + try { + Desktop.getDesktop().browse(e.getURL().toURI()); + } catch (IOException ee) { + Instance.getInstance().getTraceHandler().error(ee); + } catch (URISyntaxException ee) { + Instance.getInstance().getTraceHandler().error(ee); + } + } + }); + updateMessage.setEditable(false); + updateMessage.setBackground(new JLabel().getBackground()); + updateMessage.addHyperlinkListener(new HyperlinkListener() { + @Override + public void hyperlinkUpdate(HyperlinkEvent evn) { + if (evn.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + if (Desktop.isDesktopSupported()) { + try { + Desktop.getDesktop().browse(evn.getURL().toURI()); + } catch (IOException e) { + } catch (URISyntaxException e) { + } + } + } + } + }); + + int rep = JOptionPane.showConfirmDialog(null, updateMessage, + trans(StringIdGui.NEW_VERSION_TITLE), + JOptionPane.OK_CANCEL_OPTION); + if (rep == JOptionPane.OK_OPTION) { + updates.ok(); + } else { + updates.ignore(); + } + } + + /** + * Translate the given id into user text. + * + * @param id + * the ID to translate + * @param values + * the values to insert instead of the place holders in the + * translation + * + * @return the translated text with the given value where required or NULL + * if not found (not present in the resource file) + */ + static public String trans(StringIdGui id, Object... values) { + return Instance.getInstance().getTransGui().getString(id, values); + } } diff --git a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java index c4e7370b..c560e9a8 100644 --- a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java @@ -484,20 +484,4 @@ public class MainFrame extends JFrame { static public ImporterFrame getImporter() { return importer; } - - /** - * Translate the given id into user text. - * - * @param id - * the ID to translate - * @param values - * the values to insert instead of the place holders in the - * translation - * - * @return the translated text with the given value where required or NULL - * if not found (not present in the resource file) - */ - static public String trans(StringIdGui id, Object... values) { - return Instance.getInstance().getTransGui().getString(id, values); - } } diff --git a/src/be/nikiroo/fanfix_swing/gui/PropertiesDialog.java b/src/be/nikiroo/fanfix_swing/gui/PropertiesDialog.java index 16023be9..6ceae930 100644 --- a/src/be/nikiroo/fanfix_swing/gui/PropertiesDialog.java +++ b/src/be/nikiroo/fanfix_swing/gui/PropertiesDialog.java @@ -10,6 +10,7 @@ import be.nikiroo.fanfix.bundles.StringIdGui; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix_swing.Main; import be.nikiroo.fanfix_swing.gui.utils.UiHelper; /** @@ -37,7 +38,7 @@ public class PropertiesDialog extends JDialog { this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setUndecorated(undecorated); this.setLayout(new BorderLayout()); - this.setTitle(MainFrame.trans(StringIdGui.TITLE_STORY, meta.getLuid(), + this.setTitle(Main.trans(StringIdGui.TITLE_STORY, meta.getLuid(), meta.getTitle())); desc = new PropertiesPanel(lib, meta, undecorated); diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java b/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java index 195c908b..ac60c961 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java @@ -12,14 +12,13 @@ import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.SwingWorker; -import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.StringIdGui; import be.nikiroo.fanfix.library.BasicLibrary; import be.nikiroo.fanfix.library.BasicLibrary.Status; import be.nikiroo.fanfix.library.MetaResultList; +import be.nikiroo.fanfix_swing.Main; import be.nikiroo.fanfix_swing.gui.BooksPanelActions; import be.nikiroo.fanfix_swing.gui.BooksPanelActions.ChangeAction; -import be.nikiroo.fanfix_swing.gui.MainFrame; import be.nikiroo.fanfix_swing.gui.utils.UiHelper; public class BookPopup extends JPopupMenu { @@ -112,7 +111,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemExport() { JMenuItem export = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_FILE_EXPORT), KeyEvent.VK_S); + Main.trans(StringIdGui.MENU_FILE_EXPORT), KeyEvent.VK_S); export.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -130,7 +129,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemClearCache() { JMenuItem refresh = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_EDIT_CLEAR_CACHE), + Main.trans(StringIdGui.MENU_EDIT_CLEAR_CACHE), KeyEvent.VK_C); refresh.addActionListener(new ActionListener() { @Override @@ -154,11 +153,11 @@ public class BookPopup extends JPopupMenu { } JMenu changeTo = new JMenu( - MainFrame.trans(StringIdGui.MENU_FILE_MOVE_TO)); + Main.trans(StringIdGui.MENU_FILE_MOVE_TO)); changeTo.setMnemonic(KeyEvent.VK_M); JMenuItem item = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_TYPE)); + Main.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_TYPE)); item.addActionListener(createMoveAction(ChangeAction.SOURCE, null)); changeTo.add(item); changeTo.addSeparator(); @@ -204,12 +203,12 @@ public class BookPopup extends JPopupMenu { } JMenu changeTo = new JMenu( - MainFrame.trans(StringIdGui.MENU_FILE_SET_AUTHOR)); + Main.trans(StringIdGui.MENU_FILE_SET_AUTHOR)); changeTo.setMnemonic(KeyEvent.VK_A); // New author JMenuItem newItem = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR)); + Main.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR)); changeTo.add(newItem); changeTo.addSeparator(); newItem.addActionListener(createMoveAction(ChangeAction.AUTHOR, null)); @@ -220,7 +219,7 @@ public class BookPopup extends JPopupMenu { JMenu group = new JMenu(key); for (String value : groupedAuthors.get(key)) { JMenuItem item = new JMenuItem(value.isEmpty() - ? MainFrame.trans(StringIdGui.MENU_AUTHORS_UNKNOWN) + ? Main.trans(StringIdGui.MENU_AUTHORS_UNKNOWN) : value); item.addActionListener( createMoveAction(ChangeAction.AUTHOR, value)); @@ -231,7 +230,7 @@ public class BookPopup extends JPopupMenu { } else if (groupedAuthors.size() == 1) { for (String value : groupedAuthors.values().iterator().next()) { JMenuItem item = new JMenuItem(value.isEmpty() - ? MainFrame.trans(StringIdGui.MENU_AUTHORS_UNKNOWN) + ? Main.trans(StringIdGui.MENU_AUTHORS_UNKNOWN) : value); item.addActionListener( createMoveAction(ChangeAction.AUTHOR, value)); @@ -249,7 +248,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemRename() { JMenuItem changeTo = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_FILE_RENAME)); + Main.trans(StringIdGui.MENU_FILE_RENAME)); changeTo.setMnemonic(KeyEvent.VK_R); changeTo.addActionListener(createMoveAction(ChangeAction.TITLE, null)); return changeTo; @@ -272,7 +271,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemRedownload() { JMenuItem refresh = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_EDIT_REDOWNLOAD), + Main.trans(StringIdGui.MENU_EDIT_REDOWNLOAD), KeyEvent.VK_R); refresh.addActionListener(new ActionListener() { @Override @@ -291,7 +290,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemDownloadToCache() { JMenuItem refresh = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_EDIT_DOWNLOAD_TO_CACHE), + Main.trans(StringIdGui.MENU_EDIT_DOWNLOAD_TO_CACHE), KeyEvent.VK_T); refresh.addActionListener(new ActionListener() { @Override @@ -310,7 +309,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemDelete() { JMenuItem delete = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_EDIT_DELETE), KeyEvent.VK_D); + Main.trans(StringIdGui.MENU_EDIT_DELETE), KeyEvent.VK_D); delete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -328,7 +327,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemProperties() { JMenuItem delete = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_FILE_PROPERTIES), + Main.trans(StringIdGui.MENU_FILE_PROPERTIES), KeyEvent.VK_P); delete.addActionListener(new ActionListener() { @Override @@ -347,7 +346,7 @@ public class BookPopup extends JPopupMenu { */ public JMenuItem createMenuItemOpenBook() { JMenuItem open = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_FILE_OPEN), KeyEvent.VK_O); + Main.trans(StringIdGui.MENU_FILE_OPEN), KeyEvent.VK_O); open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -366,7 +365,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemSetCoverForSource() { JMenuItem open = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_SOURCE), + Main.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_SOURCE), KeyEvent.VK_C); open.addActionListener(new ActionListener() { @Override @@ -386,7 +385,7 @@ public class BookPopup extends JPopupMenu { */ private JMenuItem createMenuItemSetCoverForAuthor() { JMenuItem open = new JMenuItem( - MainFrame.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_AUTHOR), + Main.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_AUTHOR), KeyEvent.VK_A); open.addActionListener(new ActionListener() { @Override diff --git a/src/be/nikiroo/fanfix_swing/gui/search/GRGroup.java b/src/be/nikiroo/fanfix_swing/gui/search/GRGroup.java index e6880f7a..822821c4 100644 --- a/src/be/nikiroo/fanfix_swing/gui/search/GRGroup.java +++ b/src/be/nikiroo/fanfix_swing/gui/search/GRGroup.java @@ -20,7 +20,7 @@ import javax.swing.JPanel; import be.nikiroo.fanfix.bundles.StringIdGui; import be.nikiroo.fanfix.library.BasicLibrary; -import be.nikiroo.fanfix_swing.gui.MainFrame; +import be.nikiroo.fanfix_swing.Main; import be.nikiroo.fanfix_swing.gui.book.BookInfo; import be.nikiroo.fanfix_swing.gui.search.GRBook.BookActionListener; import be.nikiroo.utils.ui.WrapLayout; @@ -168,7 +168,7 @@ public class GRGroup extends JPanel { public void setTitle(String title) { if (title != null) { if (title.isEmpty()) { - title = MainFrame.trans(StringIdGui.MENU_AUTHORS_UNKNOWN); + title = Main.trans(StringIdGui.MENU_AUTHORS_UNKNOWN); } titleLabel.setText(String.format("" diff --git a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java index 5834c86a..0be44f49 100644 --- a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java +++ b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java @@ -38,7 +38,7 @@ import be.nikiroo.fanfix.bundles.StringIdGui; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix_swing.gui.MainFrame; +import be.nikiroo.fanfix_swing.Main; import be.nikiroo.fanfix_swing.gui.utils.UiHelper; import be.nikiroo.fanfix_swing.images.IconGenerator; import be.nikiroo.fanfix_swing.images.IconGenerator.Icon; @@ -133,7 +133,7 @@ public class ViewerImages extends JFrame { * the {@link Story} to display */ public ViewerImages(Story story) { - setTitle(MainFrame.trans(StringIdGui.TITLE_STORY, + setTitle(Main.trans(StringIdGui.TITLE_STORY, story.getMeta().getLuid(), story.getMeta().getTitle())); setSize(800, 600); -- 2.27.0