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;
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;
private JComboBox<SupportType> 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);
}
supportType = supportTypes.isEmpty() ? null : supportTypes.get(0);
- JPanel top = new JPanel(new BorderLayout());
comboSupportTypes = new JComboBox<SupportType>(
supportTypes.toArray(new SupportType[] {}));
comboSupportTypes.addActionListener(new ActionListener() {
.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);
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);
});
}
+ // 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
public void search(final SupportType searchOn, final String keywords,
final int page, final int item) {
+ setWaitingScreen(true);
+
updateSupportType(searchOn);
updateSearchBy(false);
updateKeywords(keywords);
// TODO: "click" on item ITEM
}
}
+
+ setWaitingScreen(false);
}
}).start();
}
@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);
}
});
}
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;
}
}