+ bookPane.validate();
+ bookPane.repaint();
+ }
+
+ private JMenuBar createMenu() {
+ bar = new JMenuBar();
+
+ JMenu file = new JMenu("File");
+
+ JMenuItem imprt = new JMenuItem("Import", KeyEvent.VK_I);
+ imprt.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ 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);
+ }
+ }
+ });
+ }
+ });
+ }
+ }
+ });
+ JMenu types = new JMenu("Type");
+ List<String> tt = Instance.getLibrary().getTypes();
+ tt.add(0, null);
+ for (final String type : tt) {
+ JMenuItem item = new JMenuItem(type == null ? "[all]" : type);
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ refreshBooks(type);
+ }
+ });
+ types.add(item);
+ }
+ JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X);
+ exit.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ LocalReaderFrame.this.dispatchEvent(new WindowEvent(
+ LocalReaderFrame.this, WindowEvent.WINDOW_CLOSING));
+ }
+ });
+
+ file.add(imprt);
+ file.add(types);
+ file.addSeparator();
+ file.add(exit);
+
+ bar.add(file);
+
+ return bar;
+ }
+
+ 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.isDone()) {
+ pg.setProgress(pg.getMax());
+ }
+ }
+ }).start();
+ }
+
+ 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();