test: improve flag files
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / ui / GuiReaderSearchAction.java
CommitLineData
eb665fbd
NR
1package be.nikiroo.fanfix.reader.ui;
2
3import java.awt.BorderLayout;
08e2185a
NR
4import java.awt.Component;
5import java.awt.event.ActionEvent;
6import java.awt.event.ActionListener;
7import java.io.IOException;
8import java.net.URL;
eb665fbd
NR
9
10import javax.swing.JButton;
11import javax.swing.JFrame;
12import javax.swing.JPanel;
13
08e2185a 14import be.nikiroo.fanfix.Instance;
eb665fbd 15import be.nikiroo.fanfix.library.BasicLibrary;
08e2185a
NR
16import be.nikiroo.utils.Progress;
17import be.nikiroo.utils.ui.ProgressBar;
eb665fbd
NR
18
19public class GuiReaderSearchAction extends JFrame {
20 private static final long serialVersionUID = 1L;
21
22 private GuiReaderBookInfo info;
08e2185a 23 private ProgressBar pgBar;
eb665fbd
NR
24
25 public GuiReaderSearchAction(BasicLibrary lib, GuiReaderBookInfo info) {
08e2185a 26 super(info.getMainInfo());
eb665fbd
NR
27 this.setSize(800, 600);
28 this.info = info;
29
30 setLayout(new BorderLayout());
31
08e2185a 32 JPanel main = new JPanel(new BorderLayout());
eb665fbd
NR
33 JPanel props = new GuiReaderPropertiesPane(lib, info.getMeta());
34
08e2185a
NR
35 main.add(props, BorderLayout.NORTH);
36 main.add(new GuiReaderViewerPanel(info.getMeta(), info.getMeta()
eb665fbd 37 .isImageDocument()), BorderLayout.CENTER);
08e2185a
NR
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;
eb665fbd
NR
90 }
91}