improve touch panel
authorNiki Roo <niki@nikiroo.be>
Thu, 7 May 2020 20:24:00 +0000 (22:24 +0200)
committerNiki Roo <niki@nikiroo.be>
Thu, 7 May 2020 20:24:00 +0000 (22:24 +0200)
src/be/nikiroo/fanfix_swing/gui/BooksPanel.java
src/be/nikiroo/fanfix_swing/gui/MainFrame.java
src/be/nikiroo/fanfix_swing/gui/TouchFrame.java
src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java
src/be/nikiroo/fanfix_swing/gui/book/BookLine.java

index 5311b7b13fb6a39dd84fd640fa7001dd6268c01a..76f188ca644b682a8eb3a63d7395422343648a42 100644 (file)
@@ -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<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();
@@ -419,7 +458,7 @@ public class BooksPanel extends ListenerPanel {
                        }
                };
        }
-       
+
        protected BooksPanelActions initActions() {
                return new BooksPanelActions(this, getInformer());
        }
index fb8e15eff933d8a4adfc6cea9a6e8c7cc672dc08..01d2237ee87535bb2ad0ba95de5f3c63f82adb18 100644 (file)
@@ -101,28 +101,9 @@ public class MainFrame extends JFrame {
                        @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) {
index 68407c32de01eb95c24e392d8dfe43782573a4e1..ea6ae009ea1d4f2ad89c5df97f241474c71e5a1b 100644 (file)
@@ -34,7 +34,7 @@ public class TouchFrame extends JFrame {
 
        private List<JComponent> 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();
        }
index e77219bdb9026c138f1fa99599620226782a48d9..4aa164ba79bbe5d1f5ecce6bb3aa8b1bafc92fdd 100644 (file)
@@ -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
index a1dadedcd003a53bde761c32e6511e1a88283c02..1ebf7710bd177e4df11bd1c7954c630ccdcfb296 100644 (file)
@@ -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);