X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderMainPanel.java;h=8593fe6471c816812220defeedf5775fe1757642;hb=966d62609ff6b19a20f8aa60506cd477c51fe5aa;hp=be523648739f9a4d80cdcf65eea2e2c95478af14;hpb=5bc9573be46f09ac92207e104915bd5babbd6d63;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java
index be52364..8593fe6 100644
--- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java
+++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java
@@ -2,13 +2,15 @@ package be.nikiroo.fanfix.reader.ui;
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@@ -83,10 +85,10 @@ class GuiReaderMainPanel extends JPanel {
*
* Will invalidate the layout.
*
- * @param libOk
- * the library can be queried
+ * @param status
+ * the library status, must not be NULL
*/
- public void createMenu(boolean libOk);
+ public void createMenu(Status status);
/**
* Create a popup menu for a {@link GuiReaderBook} that represents a
@@ -136,6 +138,7 @@ class GuiReaderMainPanel extends JPanel {
pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS));
+ JScrollPane scroll = new JScrollPane(pane);
Integer icolor = Instance.getUiConfig().getColor(
UiConfig.BACKGROUND_COLOR);
@@ -143,9 +146,9 @@ class GuiReaderMainPanel extends JPanel {
color = new Color(icolor);
setBackground(color);
pane.setBackground(color);
+ scroll.setBackground(color);
}
- JScrollPane scroll = new JScrollPane(pane);
scroll.getVerticalScrollBar().setUnitIncrement(16);
add(scroll, BorderLayout.CENTER);
@@ -179,6 +182,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;
@@ -188,23 +198,28 @@ class GuiReaderMainPanel extends JPanel {
final BasicLibrary lib = helper.getReader().getLibrary();
final Status status = lib.getStatus();
- if (status == Status.READY) {
+ if (status == Status.READ_WRITE) {
lib.refresh(pg);
}
inUi(new Runnable() {
@Override
public void run() {
- if (status == Status.READY) {
- helper.createMenu(true);
+ if (status.isReady()) {
+ helper.createMenu(status);
+ pane.setVisible(true);
if (typeF == null) {
- addBookPane(true, false);
+ try {
+ addBookPane(true, false);
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(),
+ "IOException", e);
+ }
} else {
addBookPane(typeF, true);
}
- pane.setVisible(true);
} else {
- helper.createMenu(false);
+ helper.createMenu(status);
validate();
String desc = Instance.getTransGui().getStringX(
@@ -246,8 +261,11 @@ class GuiReaderMainPanel extends JPanel {
* @param listMode
* TRUE to get a listing of all the sources or authors, FALSE to
* get one icon per source or author
+ *
+ * @throws IOException
+ * in case of I/O error
*/
- public void addBookPane(boolean type, boolean listMode) {
+ public void addBookPane(boolean type, boolean listMode) throws IOException {
this.currentType = type;
BasicLibrary lib = helper.getReader().getLibrary();
if (type) {
@@ -305,9 +323,10 @@ class GuiReaderMainPanel extends JPanel {
}
@Override
- public void popupRequested(GuiReaderBook book, MouseEvent e) {
+ public void popupRequested(GuiReaderBook book, Component target,
+ int x, int y) {
JPopupMenu popup = helper.createBookPopup();
- popup.show(e.getComponent(), e.getX(), e.getY());
+ popup.show(target, x, y);
}
@Override
@@ -315,6 +334,8 @@ class GuiReaderMainPanel extends JPanel {
openBook(book);
}
});
+
+ focus();
}
/**
@@ -340,11 +361,17 @@ class GuiReaderMainPanel extends JPanel {
List infos = new ArrayList();
List metas;
- if (currentType) {
- metas = lib.getListBySource(value);
- } else {
- metas = lib.getListByAuthor(value);
+ try {
+ if (currentType) {
+ metas = lib.getListBySource(value);
+ } else {
+ metas = lib.getListByAuthor(value);
+ }
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ metas = new ArrayList();
}
+
for (MetaData meta : metas) {
infos.add(GuiReaderBookInfo.fromMeta(meta));
}
@@ -635,9 +662,10 @@ class GuiReaderMainPanel extends JPanel {
}
@Override
- public void popupRequested(GuiReaderBook book, MouseEvent e) {
+ public void popupRequested(GuiReaderBook book, Component target,
+ int x, int y) {
JPopupMenu popup = helper.createSourceAuthorPopup();
- popup.show(e.getComponent(), e.getX(), e.getY());
+ popup.show(target, x, y);
}
@Override
@@ -647,6 +675,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();
+ }
}
/**