X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Ffanfix_swing%2Fgui%2Fbook%2FBookLine.java;h=d601dd6c728cd47e540ced17eaeb4d0cfe53298c;hb=62c7e07ef88c8f809b46f4e4525aa0d3f8a9cb14;hp=beb4c973674eb2b6483e28aa28bc6647224710e7;hpb=6bf49e68d2e9316c61eae630d00e715fbc4940c8;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java index beb4c97..d601dd6 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java @@ -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; @@ -63,7 +67,11 @@ public class BookLine extends JPanel { secondary = new JLabel(); secondary.setForeground(AUTHOR_COLOR); - JLabel id = new JLabel(info.getMeta().getLuid()); + 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); @@ -92,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) { @@ -113,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) { @@ -134,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) { @@ -161,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; + } }