@Override
protected void done() {
try {
- loadData(get());
+ doLoadData(get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
}.execute();
}
- // TODO loadData by Book.Type + value
- private void loadData(final Type type, final String value) {
+ // loadData by Book.Type + value
+ public void loadData(final Type type, final String value) {
synchronized (lastLoad) {
lastLoad = new ReloadData(type, value);
}
- // TODO loadData todo todo
- }
+ final List<String> sources = new ArrayList<String>();
+ final List<String> authors = new ArrayList<String>();
+ final List<String> tags = new ArrayList<String>();
+
+ if (type != null && value != null) {
+ switch (type) {
+ case SOURCE:
+ sources.add(value);
+ break;
+ case AUTHOR:
+ authors.add(value);
+ break;
+ case TAG:
+ tags.add(value);
+ break;
+
+ default:
+ break;
+ }
+ }
- // TODO loadData by Book.Type + value
- private void loadData(List<BookInfo> bookInfos) {
- // synchronized (lastLoad) {
- // lastLoad[0] = "bookInfos";
- // lastLoad[1] = bookInfos;
- // }
+ new SwingWorker<List<BookInfo>, Void>() {
+ @Override
+ protected List<BookInfo> doInBackground() throws Exception {
+ List<BookInfo> bookInfos = new ArrayList<BookInfo>();
+ BasicLibrary lib = Instance.getInstance().getLibrary();
+ for (MetaData meta : lib.getList().filter(sources, authors,
+ tags)) {
+ bookInfos.add(BookInfo.fromMeta(lib, meta));
+ }
+
+ return bookInfos;
+ }
+ @Override
+ protected void done() {
+ try {
+ doLoadData(get());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ // TODO: error
+ }
+ }.execute();
+ }
+
+ private void doLoadData(List<BookInfo> bookInfos) {
data.clearItems();
data.addAllItems(bookInfos);
bookCoverUpdater.clear();
}
};
}
-
+
protected BooksPanelActions initActions() {
return new BooksPanelActions(this, getInformer());
}
@Override
public void actionPerformed(ActionEvent e) {
BookInfo book = goBack.getHighlight();
- List<String> sources = new ArrayList<String>();
- List<String> authors = new ArrayList<String>();
- List<String> tags = new ArrayList<String>();
-
- if (book != null && book.getMainInfo() != null) {
- switch (book.getType()) {
- case SOURCE:
- sources.add(book.getMainInfo());
- break;
- case AUTHOR:
- authors.add(book.getMainInfo());
- break;
- case TAG:
- tags.add(book.getMainInfo());
- break;
-
- default:
- break;
- }
- }
- books.loadData(sources, authors, tags);
+ books.loadData(book == null ? null : book.getType(),
+ book == null ? null : book.getMainInfo());
details.setBook(book);
if (onCrumbsbreadChange != null) {
private List<JComponent> active;
private JPanel wait;
- private BooksPanel books;
+ private JPanel booksPane;
public TouchFrame() {
setLayout(new BorderLayout());
wait = new JPanel();
wait.add(new JLabel("Waiting..."));
- books = new BooksPanel(false, true) {
+ booksPane = createBooksPane();
+
+ this.add(root, BorderLayout.CENTER);
+ showBooks();
+
+ UiHelper.setFrameIcon(this);
+ setSize(355, 465);
+ }
+
+ private JPanel createBooksPane() {
+ final BooksPanel books = new BooksPanel(false, true) {
@Override
protected BooksPanelActions initActions() {
- return new BooksPanelActions(books, getInformer()) {
+ return new BooksPanelActions(null, getInformer()) {
@Override
public boolean openBook() {
BookInfo book = getInformer().getUniqueSelected();
}
});
- this.add(root, BorderLayout.CENTER);
- showBooks();
+ final BreadCrumbsPanel breadcrumbs = new BreadCrumbsPanel();
+ breadcrumbs.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ BookInfo book = breadcrumbs.getHighlight();
+ books.loadData(book == null ? null : book.getType(),
+ book == null ? null : book.getMainInfo());
+ }
+ });
- UiHelper.setFrameIcon(this);
- setSize(355, 465);
+ JPanel booksPane = new JPanel(new BorderLayout());
+ booksPane.add(breadcrumbs, BorderLayout.NORTH);
+ booksPane.add(books, BorderLayout.CENTER);
+
+ return booksPane;
}
private void open(final BookInfo book) {
JPanel zoombox = new JPanel();
zoombox.add(exit);
- zoombox.add(Box.createRigidArea(new Dimension(10, 10)));
zoombox.add(comps[2]);
active.add(scroll);
private void showBooks() {
removeShows();
- active.add(books);
- root.add(books);
+ active.add(booksPane);
+ root.add(booksPane);
revalidate();
repaint();
}
/**
* the cover image to use a base (see
- * {@link BookCoverImager#generateCoverImage(BasicLibrary, BookInfo)})
+ * {@link BookBlock#generateCoverImage(BasicLibrary, BookInfo)})
*
* @param coverImage
* the image
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JLabel;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix_swing.gui.BooksPanel;
import be.nikiroo.fanfix_swing.gui.utils.CoverImager;
+import be.nikiroo.utils.ui.UIUtils;
/**
* A book item presented in a {@link BooksPanel}.
* Initialise this {@link BookLine}.
*/
protected void init() {
- iconCached = new JLabel(" ◉ ");
- iconNotCached = new JLabel(" ○ ");
+ iconCached = new JLabel(" ") {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+
+ Dimension sz = iconCached.getSize();
+ int s = Math.min(sz.width, sz.height);
+ int x = Math.max(0, (sz.width - sz.height) / 2);
+ int y = Math.max(0, (sz.height - sz.width) / 2);
+
+ UIUtils.drawEllipse3D(g, BookCoverImager.CACHED_ICON_COLOR, x,
+ y, s, s, true);
+ }
+ };
+ iconNotCached = new JLabel(" ") {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+
+ Dimension sz = iconNotCached.getSize();
+ int s = Math.min(sz.width, sz.height);
+ int x = Math.max(0, (sz.width - sz.height) / 2);
+ int y = Math.max(0, (sz.height - sz.width) / 2);
+
+ UIUtils.drawEllipse3D(g, BookCoverImager.UNCACHED_ICON_COLOR, 2,
+ 6, 10, 10, false);
+ }
+ };
iconNotCached.setForeground(BookCoverImager.UNCACHED_ICON_COLOR);
iconCached.setForeground(BookCoverImager.CACHED_ICON_COLOR);