test: improve flag files
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / ui / GuiReaderSearchAction.java
1 package be.nikiroo.fanfix.reader.ui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.io.IOException;
8 import java.net.URL;
9
10 import javax.swing.JButton;
11 import javax.swing.JFrame;
12 import javax.swing.JPanel;
13
14 import be.nikiroo.fanfix.Instance;
15 import be.nikiroo.fanfix.library.BasicLibrary;
16 import be.nikiroo.utils.Progress;
17 import be.nikiroo.utils.ui.ProgressBar;
18
19 public class GuiReaderSearchAction extends JFrame {
20 private static final long serialVersionUID = 1L;
21
22 private GuiReaderBookInfo info;
23 private ProgressBar pgBar;
24
25 public GuiReaderSearchAction(BasicLibrary lib, GuiReaderBookInfo info) {
26 super(info.getMainInfo());
27 this.setSize(800, 600);
28 this.info = info;
29
30 setLayout(new BorderLayout());
31
32 JPanel main = new JPanel(new BorderLayout());
33 JPanel props = new GuiReaderPropertiesPane(lib, info.getMeta());
34
35 main.add(props, BorderLayout.NORTH);
36 main.add(new GuiReaderViewerPanel(info.getMeta(), info.getMeta()
37 .isImageDocument()), BorderLayout.CENTER);
38 main.add(createImportButton(lib), BorderLayout.SOUTH);
39
40 add(main, BorderLayout.CENTER);
41
42 pgBar = new ProgressBar();
43 pgBar.setVisible(false);
44 add(pgBar, BorderLayout.SOUTH);
45
46 pgBar.addActionListener(new ActionListener() {
47 @Override
48 public void actionPerformed(ActionEvent e) {
49 pgBar.invalidate();
50 pgBar.setProgress(null);
51 setEnabled(true);
52 validate();
53 }
54 });
55
56 pgBar.addUpdateListener(new ActionListener() {
57 @Override
58 public void actionPerformed(ActionEvent e) {
59 pgBar.invalidate();
60 validate();
61 repaint();
62 }
63 });
64 }
65
66 private Component createImportButton(final BasicLibrary lib) {
67 JButton imprt = new JButton("Import into library");
68 imprt.addActionListener(new ActionListener() {
69 @Override
70 public void actionPerformed(ActionEvent ae) {
71 final Progress pg = new Progress();
72 pgBar.setProgress(pg);
73
74 new Thread(new Runnable() {
75 @Override
76 public void run() {
77 try {
78 lib.imprt(new URL(info.getMeta().getUrl()), null);
79 } catch (IOException e) {
80 Instance.getTraceHandler().error(e);
81 }
82
83 pg.done();
84 }
85 }).start();
86 }
87 });
88
89 return imprt;
90 }
91 }