From: Niki Roo Date: Thu, 7 May 2020 20:24:00 +0000 (+0200) Subject: improve touch panel X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=04a6a146d3117aaff05d37456901b4f994f6995c;p=fanfix-swing.git improve touch panel --- diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java index 5311b7b1..76f188ca 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java @@ -154,7 +154,7 @@ public class BooksPanel extends ListenerPanel { @Override protected void done() { try { - loadData(get()); + doLoadData(get()); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { @@ -165,22 +165,61 @@ public class BooksPanel extends ListenerPanel { }.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 sources = new ArrayList(); + final List authors = new ArrayList(); + final List tags = new ArrayList(); + + 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 bookInfos) { - // synchronized (lastLoad) { - // lastLoad[0] = "bookInfos"; - // lastLoad[1] = bookInfos; - // } + new SwingWorker, Void>() { + @Override + protected List doInBackground() throws Exception { + List bookInfos = new ArrayList(); + 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 bookInfos) { data.clearItems(); data.addAllItems(bookInfos); bookCoverUpdater.clear(); @@ -419,7 +458,7 @@ public class BooksPanel extends ListenerPanel { } }; } - + protected BooksPanelActions initActions() { return new BooksPanelActions(this, getInformer()); } diff --git a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java index fb8e15ef..01d2237e 100644 --- a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java @@ -101,28 +101,9 @@ public class MainFrame extends JFrame { @Override public void actionPerformed(ActionEvent e) { BookInfo book = goBack.getHighlight(); - List sources = new ArrayList(); - List authors = new ArrayList(); - List tags = new ArrayList(); - - 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) { diff --git a/src/be/nikiroo/fanfix_swing/gui/TouchFrame.java b/src/be/nikiroo/fanfix_swing/gui/TouchFrame.java index 68407c32..ea6ae009 100644 --- a/src/be/nikiroo/fanfix_swing/gui/TouchFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/TouchFrame.java @@ -34,7 +34,7 @@ public class TouchFrame extends JFrame { private List active; private JPanel wait; - private BooksPanel books; + private JPanel booksPane; public TouchFrame() { setLayout(new BorderLayout()); @@ -46,10 +46,20 @@ public class TouchFrame extends JFrame { 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(); @@ -87,11 +97,21 @@ public class TouchFrame extends JFrame { } }); - 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) { @@ -187,7 +207,6 @@ public class TouchFrame extends JFrame { JPanel zoombox = new JPanel(); zoombox.add(exit); - zoombox.add(Box.createRigidArea(new Dimension(10, 10))); zoombox.add(comps[2]); active.add(scroll); @@ -212,8 +231,8 @@ public class TouchFrame extends JFrame { private void showBooks() { removeShows(); - active.add(books); - root.add(books); + active.add(booksPane); + root.add(booksPane); revalidate(); repaint(); } diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java b/src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java index e77219bd..4aa164ba 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java @@ -58,7 +58,7 @@ public class BookBlock extends BookLine { /** * the cover image to use a base (see - * {@link BookCoverImager#generateCoverImage(BasicLibrary, BookInfo)}) + * {@link BookBlock#generateCoverImage(BasicLibrary, BookInfo)}) * * @param coverImage * the image diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java index a1dadedc..1ebf7710 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java @@ -2,6 +2,7 @@ package be.nikiroo.fanfix_swing.gui.book; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JLabel; @@ -11,6 +12,7 @@ import javax.swing.SwingConstants; 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}. @@ -57,8 +59,38 @@ public class BookLine extends JPanel { * 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);