From: Niki Roo Date: Tue, 16 Apr 2019 16:53:41 +0000 (+0200) Subject: GUI: search X-Git-Tag: fanfix-3.0.0~99 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=08e2185a6c13eb75e9b80e2523c0862959c88a13;p=fanfix.git GUI: search --- diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java index e7a1f2b..6bc5fc6 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java @@ -1,7 +1,6 @@ package be.nikiroo.fanfix.reader.ui; import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Component; import java.awt.EventQueue; import java.awt.event.ActionEvent; @@ -14,6 +13,7 @@ import java.util.List; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; @@ -46,12 +46,12 @@ public class GuiReaderSearch extends JFrame { private JComboBox comboSupportTypes; private JTabbedPane searchTabs; private JTextField keywordsField; + private JButton submitKeywords; private boolean seeWordcount; private GuiReaderGroup books; public GuiReaderSearch(final GuiReader reader) { - // TODO: i18n super("Browse stories"); setLayout(new BorderLayout()); setSize(800, 600); @@ -69,7 +69,6 @@ public class GuiReaderSearch extends JFrame { } supportType = supportTypes.isEmpty() ? null : supportTypes.get(0); - JPanel top = new JPanel(new BorderLayout()); comboSupportTypes = new JComboBox( supportTypes.toArray(new SupportType[] {})); comboSupportTypes.addActionListener(new ActionListener() { @@ -79,13 +78,16 @@ public class GuiReaderSearch extends JFrame { .getSelectedItem()); } }); - top.add(comboSupportTypes, BorderLayout.NORTH); + JPanel searchSites = new JPanel(new BorderLayout()); + searchSites.add(comboSupportTypes, BorderLayout.CENTER); + searchSites.add(new JLabel(" " + "Website : "), BorderLayout.WEST); - // TODO: i18n searchTabs = new JTabbedPane(); searchTabs.addTab("By name", createByNameSearchPanel()); searchTabs.addTab("By tags", createByTagSearchPanel()); + JPanel top = new JPanel(new BorderLayout()); + top.add(searchSites, BorderLayout.NORTH); top.add(searchTabs, BorderLayout.CENTER); add(top, BorderLayout.NORTH); @@ -118,13 +120,12 @@ public class GuiReaderSearch extends JFrame { keywordsField = new JTextField(); byName.add(keywordsField, BorderLayout.CENTER); - // TODO: i18n - JButton submit = new JButton("Search"); - byName.add(submit, BorderLayout.EAST); + submitKeywords = new JButton("Search"); + byName.add(submitKeywords, BorderLayout.EAST); // TODO: ENTER -> search - submit.addActionListener(new ActionListener() { + submitKeywords.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { search(supportType, keywordsField.getText(), page, 0); @@ -178,14 +179,17 @@ public class GuiReaderSearch extends JFrame { }); } + // cannot be NULL private void updateKeywords(final String keywords) { - inUi(new Runnable() { - @Override - public void run() { - GuiReaderSearch.this.keywords = keywords; - keywordsField.setText(keywords); - } - }); + if (!keywords.equals(this.keywords)) { + inUi(new Runnable() { + @Override + public void run() { + GuiReaderSearch.this.keywords = keywords; + keywordsField.setText(keywords); + } + }); + } } // can be NULL @@ -213,6 +217,8 @@ public class GuiReaderSearch extends JFrame { public void search(final SupportType searchOn, final String keywords, final int page, final int item) { + setWaitingScreen(true); + updateSupportType(searchOn); updateSearchBy(false); updateKeywords(keywords); @@ -251,6 +257,8 @@ public class GuiReaderSearch extends JFrame { // TODO: "click" on item ITEM } } + + setWaitingScreen(false); } }).start(); } @@ -348,12 +356,8 @@ public class GuiReaderSearch extends JFrame { @Override public void run() { GuiReaderSearch.this.setEnabled(!waiting); - // TODO: this is just an example of something to do - if (waiting) { - books.setBackground(Color.RED); - } else { - books.setBackground(null); - } + books.setEnabled(!waiting); + submitKeywords.setEnabled(!waiting); } }); } diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearchAction.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearchAction.java index dbce52f..b3c8f8b 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearchAction.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearchAction.java @@ -1,32 +1,91 @@ package be.nikiroo.fanfix.reader.ui; import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.net.URL; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; +import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.utils.Progress; +import be.nikiroo.utils.ui.ProgressBar; public class GuiReaderSearchAction extends JFrame { private static final long serialVersionUID = 1L; private GuiReaderBookInfo info; + private ProgressBar pgBar; public GuiReaderSearchAction(BasicLibrary lib, GuiReaderBookInfo info) { - // TODO i18n - super("TODO: " + info.getMainInfo()); + super(info.getMainInfo()); this.setSize(800, 600); this.info = info; setLayout(new BorderLayout()); + JPanel main = new JPanel(new BorderLayout()); JPanel props = new GuiReaderPropertiesPane(lib, info.getMeta()); - add(props, BorderLayout.NORTH); - add(new GuiReaderViewerPanel(info.getMeta(), info.getMeta() + main.add(props, BorderLayout.NORTH); + main.add(new GuiReaderViewerPanel(info.getMeta(), info.getMeta() .isImageDocument()), BorderLayout.CENTER); - add(new JButton("TODO: Download"), BorderLayout.SOUTH); - // TODO --^ + main.add(createImportButton(lib), BorderLayout.SOUTH); + + add(main, BorderLayout.CENTER); + + pgBar = new ProgressBar(); + pgBar.setVisible(false); + add(pgBar, BorderLayout.SOUTH); + + pgBar.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + pgBar.invalidate(); + pgBar.setProgress(null); + setEnabled(true); + validate(); + } + }); + + pgBar.addUpdateListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + pgBar.invalidate(); + validate(); + repaint(); + } + }); + } + + private Component createImportButton(final BasicLibrary lib) { + JButton imprt = new JButton("Import into library"); + imprt.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + final Progress pg = new Progress(); + pgBar.setProgress(pg); + + new Thread(new Runnable() { + @Override + public void run() { + try { + lib.imprt(new URL(info.getMeta().getUrl()), null); + } catch (IOException e) { + Instance.getTraceHandler().error(e); + } + + pg.done(); + } + }).start(); + } + }); + + return imprt; } }