From: Niki Roo Date: Wed, 6 May 2020 21:34:48 +0000 (+0200) Subject: touch frame update X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=2132e8b0b53e9a02b3e2138dd9ee89fb0e40851c;p=fanfix-swing.git touch frame update --- diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java index a49c5b81..5311b7b1 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java @@ -338,7 +338,7 @@ public class BooksPanel extends ListenerPanel { private JList6 initList() { informer = initInformer(); - actions = new BooksPanelActions(this, informer); + actions = initActions(); // needs informer final JList6 list = new JList6(); data = new ListModel(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 generateRenderer() { return new ListCellRenderer6() { diff --git a/src/be/nikiroo/fanfix_swing/gui/TouchFrame.java b/src/be/nikiroo/fanfix_swing/gui/TouchFrame.java index 0bde0344..85730550 100644 --- a/src/be/nikiroo/fanfix_swing/gui/TouchFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/TouchFrame.java @@ -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 active; private JPanel wait; private BooksPanel books; public TouchFrame() { + active = new ArrayList(); + 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() { - 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() { + @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(); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java index 4cc9da3f..0a554f22 100644 --- a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java +++ b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java @@ -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); diff --git a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java index 08811146..c5a50919 100644 --- a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java +++ b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java @@ -81,6 +81,7 @@ public class ViewerNonImages extends JFrame { setChapter(0); UiHelper.setFrameIcon(this, lib, story.getMeta()); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } /**