From 574d709a282747a775b02fbaef01d26076cfec60 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 28 Mar 2019 09:00:50 +0100 Subject: [PATCH] full selection --- .../fanfix/reader/ui/GuiReaderFrame.java | 1 - .../fanfix/reader/ui/GuiReaderMainPanel.java | 34 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index 131ab05..e207023 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -4,7 +4,6 @@ import java.awt.BorderLayout; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowEvent; import java.io.File; diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java index 5192278..cfd1e94 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java @@ -9,6 +9,8 @@ import java.awt.Toolkit; import java.awt.datatransfer.DataFlavor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -179,6 +181,13 @@ class GuiReaderMainPanel extends JPanel { books = new TreeMap(); + addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + focus(); + } + }); + pane.setVisible(false); final Progress pg = new Progress(); final String typeF = type; @@ -197,12 +206,12 @@ class GuiReaderMainPanel extends JPanel { public void run() { if (status == Status.READY) { helper.createMenu(true); + pane.setVisible(true); if (typeF == null) { addBookPane(true, false); } else { addBookPane(typeF, true); } - pane.setVisible(true); } else { helper.createMenu(false); validate(); @@ -316,6 +325,8 @@ class GuiReaderMainPanel extends JPanel { openBook(book); } }); + + focus(); } /** @@ -649,6 +660,27 @@ class GuiReaderMainPanel extends JPanel { refreshBooks(); } }); + + focus(); + } + + /** + * Focus the first {@link GuiReaderGroup} we find. + */ + private void focus() { + GuiReaderGroup group = null; + Map books = this.books; + if (books.size() > 0) { + group = books.values().iterator().next(); + } + + if (group == null) { + group = bookPane; + } + + if (group != null) { + group.requestFocusInWindow(); + } } /** -- 2.27.0