From: Niki Roo Date: Tue, 19 Mar 2019 18:09:54 +0000 (+0100) Subject: gui: better app exit X-Git-Tag: fanfix-swing-0.0.1~12^2~234 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=31e28683c108bb5903864c58b0cc06bfa258fbfc;p=fanfix-swing.git gui: better app exit --- diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index f83186c1..522aa4c4 100644 --- a/src/be/nikiroo/fanfix/Main.java +++ b/src/be/nikiroo/fanfix/Main.java @@ -366,9 +366,7 @@ public class Main { syntax(false); } - if (exitCode != 0) { - System.exit(exitCode); - } + System.exit(exitCode); } /** diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReader.java b/src/be/nikiroo/fanfix/reader/ui/GuiReader.java index 7dc373c7..9f2fd3da 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReader.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReader.java @@ -168,14 +168,15 @@ class GuiReader extends BasicReader { try { GuiReaderFrame gui = new GuiReaderFrame(GuiReader.this, typeFinal); - gui.setVisible(true); gui.addWindowListener(new WindowAdapter() { @Override - public void windowClosed(WindowEvent e) { - super.windowClosed(e); + public void windowClosing(WindowEvent e) { + super.windowClosing(e); done[0] = true; } }); + + gui.setVisible(true); } catch (Exception e) { Instance.getTraceHandler().error(e); done[0] = true; diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index f7fb09f2..4a9fa763 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -49,7 +49,7 @@ import be.nikiroo.utils.ui.ConfigEditor; class GuiReaderFrame extends JFrame implements FrameHelper { private static final long serialVersionUID = 1L; private GuiReader reader; - private GuiReaderMainPanel helpee; + private GuiReaderMainPanel mainPanel; private enum MoveAction { SOURCE, TITLE, AUTHOR @@ -69,16 +69,11 @@ class GuiReaderFrame extends JFrame implements FrameHelper { this.reader = reader; - // TODO: should we still have that?? - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - helpee = new GuiReaderMainPanel(this, type); + mainPanel = new GuiReaderMainPanel(this, type); setSize(800, 600); setLayout(new BorderLayout()); - add(helpee); - - setVisible(true); + add(mainPanel); } @Override @@ -119,14 +114,14 @@ class GuiReaderFrame extends JFrame implements FrameHelper { imprt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - helpee.imprt(true); + mainPanel.imprt(true); } }); JMenuItem imprtF = new JMenuItem("Import File...", KeyEvent.VK_F); imprtF.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - helpee.imprt(false); + mainPanel.imprt(false); } }); JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X); @@ -169,8 +164,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { vauthors.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - helpee.setWords(false); - helpee.refreshBooks(); + mainPanel.setWords(false); + mainPanel.refreshBooks(); } }); view.add(vauthors); @@ -179,8 +174,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { vwords.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - helpee.setWords(true); - helpee.refreshBooks(); + mainPanel.setWords(true); + mainPanel.refreshBooks(); } }); view.add(vwords); @@ -280,9 +275,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - helpee.removeBookPanes(); - helpee.addBookPane(source, type); - helpee.refreshBooks(); + mainPanel.removeBookPanes(); + mainPanel.addBookPane(source, type); + mainPanel.refreshBooks(); } }; } @@ -292,9 +287,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - helpee.removeBookPanes(); - helpee.addBookPane(type, listMode); - helpee.refreshBooks(); + mainPanel.removeBookPanes(); + mainPanel.addBookPane(type, listMode); + mainPanel.refreshBooks(); } }; } @@ -389,7 +384,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { export.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final GuiReaderBook selectedBook = helpee.getSelectedBook(); + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { fc.showDialog(GuiReaderFrame.this, "Save"); if (fc.getSelectedFile() != null) { @@ -398,7 +393,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { .getAbsolutePath() + type.getDefaultExtension(false); final Progress pg = new Progress(); - helpee.outOfUi(pg, new Runnable() { + mainPanel.outOfUi(pg, new Runnable() { @Override public void run() { try { @@ -451,9 +446,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper { refresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final GuiReaderBook selectedBook = helpee.getSelectedBook(); + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - helpee.outOfUi(null, new Runnable() { + mainPanel.outOfUi(null, new Runnable() { @Override public void run() { reader.clearLocalReaderCache(selectedBook.getMeta() @@ -594,7 +589,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final GuiReaderBook selectedBook = helpee.getSelectedBook(); + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { String changeTo = type; if (type == null) { @@ -620,7 +615,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { } final String fChangeTo = changeTo; - helpee.outOfUi(null, new Runnable() { + mainPanel.outOfUi(null, new Runnable() { @Override public void run() { if (what.equals("SOURCE")) { @@ -634,7 +629,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { .getLuid(), fChangeTo); } - helpee.unsetSelectedBook(); + mainPanel.unsetSelectedBook(); SwingUtilities.invokeLater(new Runnable() { @Override @@ -659,14 +654,14 @@ class GuiReaderFrame extends JFrame implements FrameHelper { refresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final GuiReaderBook selectedBook = helpee.getSelectedBook(); + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { final MetaData meta = selectedBook.getMeta(); - helpee.imprt(meta.getUrl(), new StoryRunnable() { + mainPanel.imprt(meta.getUrl(), new StoryRunnable() { @Override public void run(Story story) { reader.delete(meta.getLuid()); - helpee.unsetSelectedBook(); + mainPanel.unsetSelectedBook(); MetaData newMeta = story.getMeta(); if (!newMeta.getSource().equals(meta.getSource())) { reader.changeSource(newMeta.getLuid(), @@ -691,13 +686,13 @@ class GuiReaderFrame extends JFrame implements FrameHelper { delete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final GuiReaderBook selectedBook = helpee.getSelectedBook(); + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - helpee.outOfUi(null, new Runnable() { + mainPanel.outOfUi(null, new Runnable() { @Override public void run() { reader.delete(selectedBook.getMeta().getLuid()); - helpee.unsetSelectedBook(); + mainPanel.unsetSelectedBook(); } }); } @@ -717,9 +712,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper { delete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final GuiReaderBook selectedBook = helpee.getSelectedBook(); + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - helpee.outOfUi(null, new Runnable() { + mainPanel.outOfUi(null, new Runnable() { @Override public void run() { new GuiReaderPropertiesFrame(reader, selectedBook @@ -743,15 +738,15 @@ class GuiReaderFrame extends JFrame implements FrameHelper { open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final GuiReaderBook selectedBook = helpee.getSelectedBook(); + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { if (selectedBook.getMeta().getLuid() == null) { - helpee.removeBookPanes(); - helpee.addBookPane(selectedBook.getMeta().getSource(), - true); - helpee.refreshBooks(); + mainPanel.removeBookPanes(); + mainPanel.addBookPane(selectedBook.getMeta() + .getSource(), true); + mainPanel.refreshBooks(); } else { - helpee.openBook(selectedBook); + mainPanel.openBook(selectedBook); } } } @@ -771,7 +766,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final GuiReaderBook selectedBook = helpee.getSelectedBook(); + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { reader.getLibrary().setSourceCover( selectedBook.getMeta().getSource(), diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java index 5a647de5..0ad082ce 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java @@ -15,12 +15,26 @@ import javax.swing.JPanel; import javax.swing.JTextArea; import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.reader.BasicReader; import be.nikiroo.fanfix.reader.Reader; +/** + * A frame displaying properties and other information of a {@link Story}. + * + * @author niki + */ public class GuiReaderPropertiesFrame extends JFrame { private static final long serialVersionUID = 1L; + /** + * Create a new {@link GuiReaderPropertiesFrame}. + * + * @param reader + * the linked reader + * @param meta + * the meta to describe + */ public GuiReaderPropertiesFrame(Reader reader, MetaData meta) { // Borders int top = 20;