touch frame update
authorNiki Roo <niki@nikiroo.be>
Wed, 6 May 2020 21:34:48 +0000 (23:34 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 6 May 2020 21:34:48 +0000 (23:34 +0200)
src/be/nikiroo/fanfix_swing/gui/BooksPanel.java
src/be/nikiroo/fanfix_swing/gui/TouchFrame.java
src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java
src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java

index a49c5b81c7cf63b1dac49b95748ec4d572ddf116..5311b7b13fb6a39dd84fd640fa7001dd6268c01a 100644 (file)
@@ -338,7 +338,7 @@ public class BooksPanel extends ListenerPanel {
 
        private JList6<BookInfo> initList() {
                informer = initInformer();
-               actions = new BooksPanelActions(this, informer);
+               actions = initActions(); // needs informer
                final JList6<BookInfo> list = new JList6<BookInfo>();
                data = new ListModel<BookInfo>(list);
                setPopup(new BookPopup(Instance.getInstance().getLibrary(), informer));
@@ -419,6 +419,10 @@ public class BooksPanel extends ListenerPanel {
                        }
                };
        }
+       
+       protected BooksPanelActions initActions() {
+               return new BooksPanelActions(this, getInformer());
+       }
 
        private ListCellRenderer6<BookInfo> generateRenderer() {
                return new ListCellRenderer6<BookInfo>() {
index 0bde03442af0a05308e82b3251f939746e020263..857305508b1c858b432c147e6c152e23152e06a4 100644 (file)
@@ -2,39 +2,58 @@ package be.nikiroo.fanfix_swing.gui;
 
 import java.awt.BorderLayout;
 import java.awt.Component;
-import java.awt.Window;
-import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
 
+import javax.swing.JComponent;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
+import javax.swing.JToolBar;
 import javax.swing.SwingWorker;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.library.BasicLibrary;
-import be.nikiroo.fanfix_swing.Actions;
 import be.nikiroo.fanfix_swing.gui.book.BookInfo;
 import be.nikiroo.fanfix_swing.gui.utils.UiHelper;
-import be.nikiroo.fanfix_swing.gui.utils.WaitingDialogMeta;
 import be.nikiroo.fanfix_swing.gui.viewer.ViewerImages;
 import be.nikiroo.fanfix_swing.gui.viewer.ViewerNonImages;
-import be.nikiroo.utils.ui.WaitingDialog;
 
 public class TouchFrame extends JFrame {
        private JPanel root;
 
+       private List<JComponent> active;
        private JPanel wait;
        private BooksPanel books;
 
        public TouchFrame() {
+               active = new ArrayList<JComponent>();
+               
                root = new JPanel(new BorderLayout());
 
                wait = new JPanel();
                wait.add(new JLabel("Waiting..."));
 
-               books = new BooksPanel(false, true);
+               books = new BooksPanel(false, true) {
+                       @Override
+                       protected BooksPanelActions initActions() {
+                               return new BooksPanelActions(books, getInformer()) {
+                                       @Override
+                                       public boolean openBook() {
+                                               BookInfo book = getInformer().getUniqueSelected();
+                                               if (book != null) {
+                                                       showWait(); // TODO: some details
+                                                       open(book);
+                                                       return true;
+                                               }
+                                               
+                                               return false;
+                                       }
+                               };
+                       }
+               };
                books.setTooltip(false);
                books.loadData(null, null, null);
                // We hijack the popup to generate an action on long-press.
@@ -50,46 +69,8 @@ public class TouchFrame extends JFrame {
                        public void show(Component invoker, int x, int y) {
                                final BookInfo book = books.getInformer().getUniqueSelected();
                                if (book != null && book.getMeta() != null) {
-                                       final BasicLibrary lib = Instance.getInstance()
-                                                       .getLibrary();
-
                                        showWait(); // TODO: some details
-
-                                       new SwingWorker<File, Void>() {
-                                               private Story story;
-
-                                               @Override
-                                               protected File doInBackground() throws Exception {
-                                                       story = lib.getStory(book.getMeta().getLuid(),
-                                                                       null);
-                                                       return null;
-                                               }
-
-                                               @Override
-                                               protected void done() {
-                                                       try {
-                                                               get();
-                                                               Actions.openInternal(story);
-                                                       } catch (Exception e) {
-                                                               // TODO: i18n
-                                                               UiHelper.error(TouchFrame.this,
-                                                                               e.getLocalizedMessage(),
-                                                                               "Cannot open the story", e);
-                                                       }
-
-                                                       // Integrate it with showViewer or something
-                                                       if (story.getMeta().isImageDocument()) {
-                                                               ViewerImages viewer = new ViewerImages(story);
-                                                               viewer.setVisible(true);
-                                                       } else {
-                                                               ViewerNonImages viewer = new ViewerNonImages(
-                                                                               Instance.getInstance().getLibrary(),
-                                                                               story);
-                                                               viewer.setVisible(true);
-                                                       }
-
-                                               }
-                                       }.execute();
+                                       open(book);
                                }
                        }
                });
@@ -98,21 +79,83 @@ public class TouchFrame extends JFrame {
                showBooks();
                setSize(355, 465);
        }
+       
+       private void open(final BookInfo book) {
+               new SwingWorker<Story, Void>() {
+                       @Override
+                       protected Story doInBackground() throws Exception {
+                               BasicLibrary lib = Instance.getInstance().getLibrary();
+                               return lib.getStory(book.getMeta().getLuid(), null);
+                       }
+
+                       @Override
+                       protected void done() {
+                               try {
+                                       open(get());
+                               } catch (Exception e) {
+                                       // TODO: i18n
+                                       UiHelper.error(TouchFrame.this,
+                                                       e.getLocalizedMessage(),
+                                                       "Cannot open the story", e);
+                               }
+                       }
+               }.execute();
+       }
+       
+       private void open(Story story) {
+               // Integrate it with showViewer or something
+               if (story.getMeta().isImageDocument()) {
+                       ViewerImages viewer = new ViewerImages(story) {
+                               @Override
+                               protected JToolBar createToolBar() {
+                                       JToolBar toolbar = super.createToolBar();
+                                       active.add(toolbar);
+                                       TouchFrame.this.add(toolbar, BorderLayout.NORTH);
+                                       return null;
+                               }
+                               
+                               @Override
+                               protected void initGui() {
+                                       super.initGui();
+                                       removeShows();
+                                       active.add(scroll);
+                                       root.add(scroll);
+                               }
+                       };
+                       
+                       revalidate();
+                       repaint();
+                       
+                       //TODO: dispose viewer when changed
+               } else {
+                       ViewerNonImages viewer = new ViewerNonImages(
+                                       Instance.getInstance().getLibrary(),
+                                       story);
+                       viewer.setVisible(true);
+               }               
+       }
 
        private void removeShows() {
-               root.remove(wait);
-               root.remove(books);
+               for (JComponent comp : active) {
+                       this.remove(comp);
+                       root.remove(comp);
+               }
+               active.clear();
        }
 
        private void showBooks() {
                removeShows();
+               active.add(books);
                root.add(books);
                revalidate();
+               repaint();
        }
 
        private void showWait() {
                removeShows();
+               active.add(wait);
                root.add(wait);
                revalidate();
+               repaint();
        }
 }
index 4cc9da3fb985494947b4abc92b0ec1b36037e15c..0a554f224a94b2eb6ce3c9a3d0c90de584fbeff5 100644 (file)
@@ -119,7 +119,7 @@ public class ViewerImages extends JFrame {
 
        private NavBar navbar;
        private JLabel area;
-       private JScrollPane scroll;
+       protected JScrollPane scroll;
 
        @SuppressWarnings("rawtypes") // JComboBox<?> not compatible java 1.6
        private DefaultComboBoxModel zoomBoxModel;
@@ -166,12 +166,17 @@ public class ViewerImages extends JFrame {
                });
 
                UiHelper.setFrameIcon(this, images.isEmpty() ? null : images.get(0));
+               setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }
 
-       private void initGui() {
+       protected void initGui() {
                this.setLayout(new BorderLayout());
-               this.add(createToolBar(), BorderLayout.NORTH);
-
+               
+               JToolBar toolbar = createToolBar();
+               if (toolbar != null) {
+                       this.add(toolbar, BorderLayout.NORTH);
+               }
+               
                area = new JLabel();
                area.setHorizontalAlignment(JLabel.CENTER);
                area.setOpaque(false);
@@ -187,7 +192,7 @@ public class ViewerImages extends JFrame {
 
        @SuppressWarnings({ "unchecked", "rawtypes" }) // JComboBox<?> not
                                                                                                        // compatible java 1.6
-       private JToolBar createToolBar() {
+       protected JToolBar createToolBar() {
                JToolBar toolBar = new JToolBar();
 
                // Page navigation
@@ -601,7 +606,7 @@ public class ViewerImages extends JFrame {
                                }
                        }
                });
-               this.addComponentListener(new ComponentAdapter() {
+               scroll.addComponentListener(new ComponentAdapter() {
                        @Override
                        public void componentResized(ComponentEvent e) {
                                display(index, rotation, false);
index 088111462ea35d4a516e8944b947d5244fe2358c..c5a5091965b38fc40adf0c34cf19246e5d8e3323 100644 (file)
@@ -81,6 +81,7 @@ public class ViewerNonImages extends JFrame {
                setChapter(0);
 
                UiHelper.setFrameIcon(this, lib, story.getMeta());
+               setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }
 
        /**