import java.awt.BorderLayout;
import java.awt.Component;
+import java.awt.Dimension;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
list.setLayoutOrientation(
listMode ? JList.VERTICAL : JList.HORIZONTAL_WRAP);
+ StringBuilder longString = new StringBuilder();
+ for (int i = 0; i < 20; i++) {
+ longString.append(
+ "Some long string, which is 50 chars long itself...");
+ }
if (listMode) {
bookCoverUpdater.clear();
+ Dimension sz = new BookLine(
+ BookInfo.fromSource(null, longString.toString()), true)
+ .getPreferredSize();
+ list.setFixedCellHeight((int) sz.getHeight());
+ list.setFixedCellWidth(list.getWidth());
+ } else {
+ Dimension sz = new BookBlock(
+ BookInfo.fromSource(null, longString.toString()), true)
+ .getPreferredSize();
+ list.setFixedCellHeight((int) sz.getHeight());
+ list.setFixedCellWidth((int) sz.getWidth());
}
}
}
detailsPanel = true;
browser = new BrowserPanel();
+ books = new BooksPanel(true);
JComponent other = null;
boolean orientationH = true;
other = split(goBack, details, false, 0.5, 1);
}
- books = new BooksPanel(true);
-
browser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@Override
protected void updateMeta() {
- String main = getInfo().getMainInfo();
- String optSecondary = getInfo().getSecondaryInfo(isSeeWordCount());
+ String main = getMainInfoDisplay();
+ String optSecondary = getSecondaryInfoDisplay(isSeeWordCount());
String color = String.format("#%X%X%X", AUTHOR_COLOR.getRed(),
AUTHOR_COLOR.getGreen(), AUTHOR_COLOR.getBlue());
title.setText(String.format("<html>"
"source_" + (source == null ? "" : source), source);
int size = 0;
- try {
- size = lib.getList().filter(source, null, null).size();
- } catch (IOException e) {
+ if (lib != null) {
+ try {
+ size = lib.getList().filter(source, null, null).size();
+ } catch (IOException e) {
+ }
}
info.count = StringUtils.formatNumber(size);
"author_" + (author == null ? "" : author), author);
int size = 0;
- try {
- size = lib.getList().filter(null, author, null).size();
- } catch (IOException e) {
+ if (lib != null) {
+ try {
+ size = lib.getList().filter(null, author, null).size();
+ } catch (IOException e) {
+ }
}
info.count = StringUtils.formatNumber(size);
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);
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);
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 + " ");
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;
+ }
}