X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderFrame.java;h=d849a438388f139d2c236d9bc647c03b265c5c1c;hp=8d3142c315679465525ae17efd9ea3b92e46f6f0;hb=5f42f329b6d1dd0d61f49dd9947fe487c39160ee;hpb=63b9c2077a1e4baf3af3b3bb9187b71b6b706145 diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index 8d3142c..d849a43 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -467,27 +468,29 @@ class GuiReaderFrame extends JFrame { JMenu authors = new JMenu("Authors"); authors.setMnemonic(KeyEvent.VK_A); - List aa = new ArrayList(); - if (libOk) { - aa.addAll(reader.getLibrary().getAuthors()); - } - aa.add(0, null); - for (final String author : aa) { - JMenuItem item = new JMenuItem(author == null ? "All" - : author.isEmpty() ? "[unknown]" : author); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - removeBookPanes(); - addBookPane(author, false); - refreshBooks(); - } - }); - authors.add(item); + List>> authorGroups = reader.getLibrary() + .getAuthorsGrouped(); + if (authorGroups.size() > 1) { + // Multiple groups - if (author == null || author.isEmpty()) { - authors.addSeparator(); + // null -> "All" authors special item + populateMenuAuthorList(authors, Arrays.asList((String) null)); + + for (Entry> group : authorGroups) { + JMenu thisGroup = new JMenu(group.getKey()); + populateMenuAuthorList(thisGroup, group.getValue()); + authors.add(thisGroup); + } + } else { + // Only one group + + // null -> "All" authors special item + List authorNames = new ArrayList(); + authorNames.add(null); + if (authorGroups.size() > 0) { + authorNames.addAll(authorGroups.get(0).getValue()); } + populateMenuAuthorList(authors, authorNames); } bar.add(authors); @@ -501,6 +504,37 @@ class GuiReaderFrame extends JFrame { return bar; } + /** + * Populate a list of authors as {@link JMenuItem}s into the given + * {@link JMenu}. + *

+ * Each item will select the author when clicked. + * + * @param authors + * the parent {@link JMenuItem} + * @param names + * the authors' names + */ + private void populateMenuAuthorList(JMenu authors, List names) { + for (final String name : names) { + JMenuItem item = new JMenuItem(name == null ? "All" + : name.isEmpty() ? "[unknown]" : name); + item.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + removeBookPanes(); + addBookPane(name, false); + refreshBooks(); + } + }); + authors.add(item); + + if (name == null || name.isEmpty()) { + authors.addSeparator(); + } + } + } + /** * Create the Fanfix Configuration menu item. *