X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderGroup.java;h=3e86fba9d0a7a3677a73323ea9d44c4e35a86629;hb=b31a0db030e164bc1d9a8620e71b595dad31adb6;hp=cd98fac58525e7f92b8af0cf8e3a2c09d74b6d8e;hpb=e0fa20fefa6074105e8cb55aa7de4785b90dd20c;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java index cd98fac..3e86fba 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java @@ -33,6 +33,7 @@ public class GuiReaderGroup extends JPanel { private List infos; private List books; private JPanel pane; + private JLabel titleLabel; private boolean words; // words or authors (secondary info on books) private int itemsPerLine; @@ -43,7 +44,8 @@ public class GuiReaderGroup extends JPanel { * the {@link GuiReaderBook} used to probe some information about * the stories * @param title - * the title of this group + * the title of this group (can be NULL for "no title", an empty + * {@link String} will trigger a default title for empty groups) * @param backgroundColor * the background colour to use (or NULL for default) */ @@ -68,18 +70,10 @@ public class GuiReaderGroup extends JPanel { add(pane, BorderLayout.CENTER); - if (title != null) { - if (title.isEmpty()) { - title = GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN); - } - - JLabel label = new JLabel(); - label.setText(String.format("" - + "
" - + "%s" + "" + "", title)); - label.setHorizontalAlignment(JLabel.CENTER); - add(label, BorderLayout.NORTH); - } + titleLabel = new JLabel(); + titleLabel.setHorizontalAlignment(JLabel.CENTER); + add(titleLabel, BorderLayout.NORTH); + setTitle(title); // Compute the number of items per line at each resize addComponentListener(new ComponentAdapter() { @@ -119,6 +113,28 @@ public class GuiReaderGroup extends JPanel { }); } + /** + * The title of this group (can be NULL for "no title", an empty + * {@link String} will trigger a default title for empty groups) + * + * @param title + * the title or NULL + */ + public void setTitle(String title) { + if (title != null) { + if (title.isEmpty()) { + title = GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN); + } + + titleLabel.setText(String.format("" + + "
" + + "%s" + "" + "", title)); + titleLabel.setVisible(true); + } else { + titleLabel.setVisible(false); + } + } + /** * Compute how many items can fit in a line so UP and DOWN can be used to go * up/down one line at a time. @@ -172,7 +188,7 @@ public class GuiReaderGroup extends JPanel { if (infos != null) { for (GuiReaderBookInfo info : infos) { boolean isCached = false; - if (info.getMeta() != null) { + if (info.getMeta() != null && info.getMeta().getLuid() != null) { isCached = reader.isCached(info.getMeta().getLuid()); } @@ -242,12 +258,21 @@ public class GuiReaderGroup extends JPanel { repaint(); } + /** + * The number of books in this group. + * + * @return the count + */ + public int getBooksCount() { + return books.size(); + } + /** * Return the index of the currently selected book if any, -1 if none. * * @return the index or -1 */ - private int getSelectedBookIndex() { + public int getSelectedBookIndex() { int index = -1; for (int i = 0; i < books.size(); i++) { if (books.get(i).isSelected()) { @@ -269,7 +294,7 @@ public class GuiReaderGroup extends JPanel { * TRUE to constraint the index to the first/last element, FALSE * to unselect when outside the range */ - private void setSelectedBook(int index, boolean forceRange) { + public void setSelectedBook(int index, boolean forceRange) { int previousIndex = getSelectedBookIndex(); if (index >= books.size()) {