X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix_swing%2Fgui%2Fbook%2FBookLine.java;h=d601dd6c728cd47e540ced17eaeb4d0cfe53298c;hb=89c5b3e28f9f73777541157adf4e4b4fe25ad50d;hp=b4c6be41c7123786a9d33bfbd9bb1bfa150a8a19;hpb=89f2c4799d6a9d16d2c909da175621e0f2eda301;p=fanfix.git diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java index b4c6be4..d601dd6 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java @@ -2,11 +2,11 @@ package be.nikiroo.fanfix_swing.gui.book; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.SwingConstants; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix_swing.gui.BooksPanel; @@ -21,6 +21,8 @@ import be.nikiroo.fanfix_swing.gui.BooksPanel; public class BookLine extends JPanel { private static final long serialVersionUID = 1L; + private static final int MAX_DISPLAY_SIZE = 40; + /** Colour used for the seconday item (author/word count). */ protected static final Color AUTHOR_COLOR = new Color(128, 128, 128); @@ -38,8 +40,10 @@ public class BookLine extends JPanel { /** * Create a new {@link BookLine} item for the given {@link Story}. * - * @param info the information about the story to represent - * @param seeWordCount TRUE to see word counts, FALSE to see authors + * @param info + * the information about the story to represent + * @param seeWordCount + * TRUE to see word counts, FALSE to see authors */ public BookLine(BookInfo info, boolean seeWordCount) { this.info = info; @@ -52,19 +56,33 @@ public class BookLine extends JPanel { * Initialise this {@link BookLine}. */ protected void init() { - // TODO: image? - iconCached = new JLabel(" "); - iconNotCached = new JLabel(" * "); + iconCached = new JLabel(" ◉ "); + iconNotCached = new JLabel(" ○ "); iconNotCached.setForeground(BookCoverImager.UNCACHED_ICON_COLOR); + iconCached.setForeground(BookCoverImager.UNCACHED_ICON_COLOR); iconCached.setPreferredSize(iconNotCached.getPreferredSize()); title = new JLabel(); secondary = new JLabel(); secondary.setForeground(AUTHOR_COLOR); + String luid = null; + if (info.getMeta() != null) { + luid = info.getMeta().getLuid(); + } + JLabel id = new JLabel(luid); + id.setPreferredSize(new JLabel(" 999 ").getPreferredSize()); + id.setForeground(Color.gray); + id.setHorizontalAlignment(SwingConstants.CENTER); + + JPanel idTitle = new JPanel(new BorderLayout()); + idTitle.setOpaque(false); + idTitle.add(id, BorderLayout.WEST); + idTitle.add(title, BorderLayout.CENTER); + setLayout(new BorderLayout()); - add(title, BorderLayout.CENTER); + add(idTitle, BorderLayout.CENTER); add(secondary, BorderLayout.EAST); updateMeta(); @@ -82,7 +100,8 @@ public class BookLine extends JPanel { /** * The book current selection state, * - * @param selected TRUE if it is selected + * @param selected + * TRUE if it is selected */ public void setSelected(boolean selected) { if (this.selected != selected) { @@ -103,7 +122,8 @@ public class BookLine extends JPanel { /** * The item mouse-hover state. * - * @param hovered TRUE if it is mouse-hovered + * @param hovered + * TRUE if it is mouse-hovered */ public void setHovered(boolean hovered) { if (this.hovered != hovered) { @@ -124,7 +144,8 @@ public class BookLine extends JPanel { /** * The secondary value content: word count or author. * - * @param seeWordCount TRUE to see word counts, FALSE to see authors + * @param seeWordCount + * TRUE to see word counts, FALSE to see authors */ public void setSeeWordCount(boolean seeWordCount) { if (this.seeWordCount != seeWordCount) { @@ -151,22 +172,65 @@ public class BookLine extends JPanel { super.paint(g); } + /** + * Return a display-ready version of {@link BookInfo#getMainInfo()}. + * + * @return the main info in a ready-to-display version + */ + protected String getMainInfoDisplay() { + return toDisplay(getInfo().getMainInfo()); + } + + /** + * Return a display-ready version of + * {@link BookInfo#getSecondaryInfo(boolean)}. + * + * @param seeCount + * TRUE for word/image/story count, FALSE for author name + * + * @return the main info in a ready-to-display version + */ + protected String getSecondaryInfoDisplay(boolean seeCount) { + return toDisplay(getInfo().getSecondaryInfo(seeCount)); + } + /** * Update the title with the currently registered information. */ protected void updateMeta() { - String main = info.getMainInfo(); - String optSecondary = info.getSecondaryInfo(seeWordCount); + String main = getMainInfoDisplay(); + String optSecondary = getSecondaryInfoDisplay(isSeeWordCount()); - // TODO: max size limit? title.setText(main); secondary.setText(optSecondary + " "); - setBackground(BookCoverImager.getBackground(isEnabled(), isSelected(), isHovered())); + setBackground(BookCoverImager.getBackground(isEnabled(), isSelected(), + isHovered())); remove(iconCached); remove(iconNotCached); - add(getInfo().isCached() ? iconCached : iconNotCached, BorderLayout.WEST); + add(getInfo().isCached() ? iconCached : iconNotCached, + BorderLayout.WEST); validate(); } + + /** + * Make the given {@link String} display-ready (i.e., shorten it if it is + * too long). + * + * @param value + * the full value + * + * @return the display-ready value + */ + private String toDisplay(String value) { + if (value == null) + value = ""; + + if (value.length() > MAX_DISPLAY_SIZE) { + value = value.substring(0, MAX_DISPLAY_SIZE - 3) + "..."; + } + + return value; + } }