+
+ private void outOfUi(final Progress pg, final Runnable run) {
+ pgBar.setProgress(pg);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ setAllEnabled(false);
+ pgBar.addActioListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ pgBar.setProgress(null);
+ setAllEnabled(true);
+ }
+ });
+ }
+ });
+
+ new Thread(new Runnable() {
+ public void run() {
+ run.run();
+ if (pg == null) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ setAllEnabled(true);
+ }
+ });
+ } else if (!pg.isDone()) {
+ pg.setProgress(pg.getMax());
+ }
+ }
+ }).start();
+ }
+
+ private void imprt(boolean askUrl) {
+ JFileChooser fc = new JFileChooser();
+
+ final String url;
+ if (askUrl) {
+ url = JOptionPane.showInputDialog(LocalReaderFrame.this,
+ "url of the story to import?", "Importing from URL",
+ JOptionPane.QUESTION_MESSAGE);
+ } else if (fc.showOpenDialog(this) != JFileChooser.CANCEL_OPTION) {
+ url = fc.getSelectedFile().getAbsolutePath();
+ } else {
+ url = null;
+ }
+
+ 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);
+ }
+ }
+ });
+ }
+ });
+ }
+ }
+
+ public void setAllEnabled(boolean enabled) {
+ for (LocalReaderBook book : books) {
+ book.setEnabled(enabled);
+ book.validate();
+ book.repaint();
+ }
+
+ bar.setEnabled(enabled);
+ bookPane.setEnabled(enabled);
+ bookPane.validate();
+ bookPane.repaint();
+
+ setEnabled(enabled);
+ validate();
+ repaint();
+ }