- String url = JOptionPane.showInputDialog(LocalReaderFrame.this,
- "url?");
- if (Main.imprt(url) != 0) {
- JOptionPane.showMessageDialog(LocalReaderFrame.this,
- "Cannot import", "Imort error",
- JOptionPane.ERROR_MESSAGE);
- } else {
- refreshBooks(type);
+ final String url = JOptionPane.showInputDialog(
+ LocalReaderFrame.this, "url of the story to import?",
+ "Importing from URL", JOptionPane.QUESTION_MESSAGE);
+ if (url != null && !url.isEmpty()) {
+ final Progress pg = new Progress("Importing " + url);
+ outOfUi(pg, new Runnable() {
+ public void run() {
+ Exception ex = null;
+ try {
+ Instance.getLibrary().imprt(
+ BasicReader.getUrl(url), pg);
+ } catch (IOException e) {
+ ex = e;
+ }
+
+ final Exception e = ex;
+
+ final boolean ok = (e == null);
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ if (!ok) {
+ JOptionPane.showMessageDialog(
+ LocalReaderFrame.this,
+ "Cannot import: " + url,
+ e.getMessage(),
+ JOptionPane.ERROR_MESSAGE);
+
+ setAllEnabled(true);
+ } else {
+ refreshBooks(type);
+ }
+ }
+ });
+ }
+ });