1 package be
.nikiroo
.fanfix_swing
.gui
;
3 import java
.awt
.Container
;
4 import java
.awt
.Toolkit
;
5 import java
.awt
.datatransfer
.DataFlavor
;
9 import javax
.swing
.JFileChooser
;
10 import javax
.swing
.JFrame
;
11 import javax
.swing
.JOptionPane
;
13 import be
.nikiroo
.fanfix
.Instance
;
14 import be
.nikiroo
.fanfix
.bundles
.StringIdGui
;
15 import be
.nikiroo
.fanfix
.library
.LocalLibrary
;
16 import be
.nikiroo
.fanfix_swing
.Actions
;
17 import be
.nikiroo
.utils
.Progress
;
19 public class ImporterFrame
extends JFrame
{
20 public ImporterFrame() {
25 * Ask for and import an {@link URL} into the main {@link LocalLibrary}.
27 * Should be called inside the UI thread.
30 * a container we can use to display the {@link URL} chooser and
31 * to show error messages if any
33 * Action to execute on success
35 public void imprtUrl(final Container parent
, final Runnable onSuccess
) {
36 String clipboard
= "";
38 clipboard
= ("" + Toolkit
.getDefaultToolkit().getSystemClipboard()
39 .getData(DataFlavor
.stringFlavor
)).trim();
40 } catch (Exception e
) {
41 // No data will be handled
44 if (clipboard
== null || !(clipboard
.startsWith("http://") || //
45 clipboard
.startsWith("https://"))) {
49 Object url
= JOptionPane
.showInputDialog(parent
,
50 Instance
.getInstance().getTransGui()
51 .getString(StringIdGui
.SUBTITLE_IMPORT_URL
),
52 Instance
.getInstance().getTransGui()
53 .getString(StringIdGui
.TITLE_IMPORT_URL
),
54 JOptionPane
.QUESTION_MESSAGE
, null, null, clipboard
);
57 if (url
!= null && !url
.toString().isEmpty()) {
58 Actions
.imprt(parent
, url
.toString(), pg
, onSuccess
);
63 * Ask for and import a {@link File} into the main {@link LocalLibrary}.
65 * Should be called inside the UI thread.
68 * a container we can use to display the {@link File} chooser and
69 * to show error messages if any
71 * Action to execute on success
74 public void imprtFile(final Container parent
, final Runnable onSuccess
) {
75 JFileChooser fc
= new JFileChooser();
78 if (fc
.showOpenDialog(parent
) != JFileChooser
.CANCEL_OPTION
) {
79 Object url
= fc
.getSelectedFile().getAbsolutePath();
80 if (url
!= null && !url
.toString().isEmpty()) {
81 Actions
.imprt(parent
, url
.toString(), pg
, onSuccess
);