X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix_swing%2Fgui%2Fbook%2FBookLine.java;h=d601dd6c728cd47e540ced17eaeb4d0cfe53298c;hp=f7926a0212d3dd36db60bf13c9c61b6e0c6308b3;hb=89c5b3e28f9f73777541157adf4e4b4fe25ad50d;hpb=32ed608959c0dec74660388248831976b97e8c56 diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java index f7926a0..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); @@ -65,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); @@ -166,14 +172,35 @@ 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 + " "); @@ -186,4 +213,24 @@ public class BookLine extends JPanel { 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; + } }