private List<BookActionListener> listeners;
private GuiReaderBookInfo info;
private boolean cached;
+ private boolean seeWordCount;
/**
* Create a new {@link GuiReaderBook} item for the given {@link Story}.
*/
public GuiReaderBook(Reader reader, GuiReaderBookInfo info, boolean cached,
boolean seeWordCount) {
- this.cached = cached;
this.info = info;
-
- String optSecondary = info.getSecondaryInfo(seeWordCount);
+ this.cached = cached;
+ this.seeWordCount = seeWordCount;
icon = new JLabel(GuiReaderCoverImager.generateCoverIcon(
reader.getLibrary(), info));
- title = new JLabel(
- String.format(
- "<html>"
- + "<body style='width: %d px; height: %d px; text-align: center'>"
- + "%s" + "<br>" + "<span style='color: %s;'>"
- + "%s" + "</span>" + "</body>" + "</html>",
- GuiReaderCoverImager.TEXT_WIDTH,
- GuiReaderCoverImager.TEXT_HEIGHT, info.getMainInfo(),
- AUTHOR_COLOR, optSecondary));
+
+ title = new JLabel();
+ updateTitle();
setLayout(new BorderLayout(10, 10));
add(icon, BorderLayout.CENTER);
}
/**
- * Paint the item, then call {@link GuiReaderBook#paintOverlay(Graphics)}.
+ * Update the title, paint the item, then call
+ * {@link GuiReaderCoverImager#paintOverlay(Graphics, boolean, boolean, boolean, boolean)}
+ * .
*/
@Override
public void paint(Graphics g) {
+ updateTitle();
super.paint(g);
GuiReaderCoverImager.paintOverlay(g, isEnabled(), isSelected(),
isHovered(), isCached());
}
+
+ /**
+ * Update the title with the currently registered information.
+ */
+ private void updateTitle() {
+ String optSecondary = info.getSecondaryInfo(seeWordCount);
+ title.setText(String
+ .format("<html>"
+ + "<body style='width: %d px; height: %d px; text-align: center'>"
+ + "%s" + "<br>" + "<span style='color: %s;'>" + "%s"
+ + "</span>" + "</body>" + "</html>",
+ GuiReaderCoverImager.TEXT_WIDTH,
+ GuiReaderCoverImager.TEXT_HEIGHT, info.getMainInfo(),
+ AUTHOR_COLOR, optSecondary));
+ }
}
public void actionPerformed(ActionEvent e) {
final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
if (selectedBook != null) {
+ boolean refreshRequired = false;
+
+ if (what == ChangeAction.SOURCE) {
+ refreshRequired = mainPanel.getCurrentType();
+ } else if (what == ChangeAction.TITLE) {
+ refreshRequired = false;
+ } else if (what == ChangeAction.AUTHOR) {
+ refreshRequired = !mainPanel.getCurrentType();
+ }
+
String changeTo = type;
if (type == null) {
MetaData meta = selectedBook.getInfo().getMeta();
}
final String fChangeTo = changeTo;
- mainPanel.outOfUi(null, true, new Runnable() {
+ mainPanel.outOfUi(null, refreshRequired, new Runnable() {
@Override
public void run() {
String luid = selectedBook.getInfo().getMeta()
reader.changeAuthor(luid, fChangeTo);
}
+ mainPanel.getSelectedBook().repaint();
mainPanel.unsetSelectedBook();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void actionPerformed(ActionEvent e) {
final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
- if (selectedBook != null) {
- mainPanel.outOfUi(null, true, new Runnable() {
- @Override
- public void run() {
- reader.delete(selectedBook.getInfo().getMeta()
- .getLuid());
- mainPanel.unsetSelectedBook();
- }
- });
+ if (selectedBook != null
+ && selectedBook.getInfo().getMeta() != null) {
+
+ final MetaData meta = selectedBook.getInfo().getMeta();
+ int rep = JOptionPane.showConfirmDialog(
+ GuiReaderFrame.this,
+ String.format("Delete %s: %s", meta.getLuid(),
+ meta.getTitle()), "Delete story",
+ JOptionPane.OK_CANCEL_OPTION);
+
+ if (rep == JOptionPane.OK_OPTION) {
+ mainPanel.outOfUi(null, true, new Runnable() {
+ @Override
+ public void run() {
+ reader.delete(meta.getLuid());
+ mainPanel.unsetSelectedBook();
+ }
+ });
+ }
}
}
});