+ color = Instance.getUiConfig().getColor(UiConfig.BACKGROUND_COLOR);
+
+ if (color != null) {
+ setBackground(color);
+ bookPane.setBackground(color);
+ }
+
+ JScrollPane scroll = new JScrollPane(bookPane);
+ scroll.getVerticalScrollBar().setUnitIncrement(16);
+ add(scroll, BorderLayout.CENTER);
+
+ pgBar = new ProgressBar();
+ add(pgBar, BorderLayout.SOUTH);
+
+ refreshBooks(type);
+ setJMenuBar(createMenu());
+
+ setVisible(true);
+ }
+
+ private void refreshBooks(String type) {
+ this.type = type;
+ stories = Instance.getLibrary().getList(type);
+ books.clear();
+ bookPane.removeAll();
+ for (MetaData meta : stories) {
+ LocalReaderBook book = new LocalReaderBook(meta,
+ reader.isCached(meta.getLuid()));
+ if (color != null) {
+ book.setBackground(color);
+ }
+
+ books.add(book);
+ final String luid = meta.getLuid();
+ book.addActionListener(new BookActionListener() {
+ public void select(LocalReaderBook book) {
+ selectedBook = book;
+ for (LocalReaderBook abook : books) {
+ abook.setSelected(abook == book);
+ }
+ }
+
+ public void action(final LocalReaderBook book) {
+ final Progress pg = new Progress();
+ outOfUi(pg, new Runnable() {
+ public void run() {
+ try {
+ File target = LocalReaderFrame.this.reader
+ .getTarget(luid, pg);
+ book.setCached(true);
+ // TODO: allow custom programs, with
+ // Desktop/xdg-open fallback
+ try {
+ Desktop.getDesktop().browse(target.toURI());
+ } catch (UnsupportedOperationException e) {
+ String browsers[] = new String[] {
+ "xdg-open", "epiphany",
+ "konqueror", "firefox", "chrome",
+ "google-chrome", "mozilla" };
+
+ Runtime runtime = Runtime.getRuntime();
+ for (String browser : browsers) {
+ try {
+ runtime.exec(new String[] {
+ browser,
+ target.getAbsolutePath() });
+ runtime = null;
+ break;
+ } catch (IOException ioe) {
+ // continue, try next browser
+ }
+ }
+
+ if (runtime != null) {
+ throw new IOException(
+ "Cannot find a working GUI browser...");
+ }
+ }
+ } catch (IOException e) {
+ Instance.syserr(e);
+ }
+ }
+ });
+ }
+ });
+
+ bookPane.add(book);
+ }
+
+ bookPane.validate();
+ bookPane.repaint();
+ }
+
+ private JMenuBar createMenu() {
+ bar = new JMenuBar();
+
+ JMenu file = new JMenu("File");
+ file.setMnemonic(KeyEvent.VK_F);
+
+ JMenuItem imprt = new JMenuItem("Import URL", KeyEvent.VK_U);
+ imprt.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ imprt(true);
+ }
+ });
+ JMenuItem imprtF = new JMenuItem("Import File", KeyEvent.VK_F);
+ imprtF.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ imprt(false);
+ }
+ });
+ 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(imprtF);
+ file.addSeparator();
+ file.add(exit);
+
+ bar.add(file);
+
+ JMenu edit = new JMenu("Edit");
+ edit.setMnemonic(KeyEvent.VK_E);
+
+ final String notYet = "[TODO] Show not ready yet, but you can do it on command line, see: fanfix --help";
+
+ JMenuItem export = new JMenuItem("Export", KeyEvent.VK_E);
+ export.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ JOptionPane.showMessageDialog(LocalReaderFrame.this, notYet);
+ }
+ });
+
+ JMenuItem refresh = new JMenuItem("Refresh", KeyEvent.VK_R);
+ refresh.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ outOfUi(null, new Runnable() {
+ public void run() {
+ reader.refresh(selectedBook.getLuid());
+ selectedBook.setCached(false);
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ selectedBook.repaint();
+ }
+ });
+ }
+ });
+ }
+ }
+ });
+
+ JMenuItem delete = new JMenuItem("Delete", KeyEvent.VK_D);
+ delete.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ outOfUi(null, new Runnable() {
+ public void run() {
+ reader.delete(selectedBook.getLuid());
+ selectedBook = null;
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ refreshBooks(type);
+ }
+ });
+ }
+ });
+ }
+ }
+ });
+
+ edit.add(export);
+ edit.add(refresh);
+ edit.add(delete);
+
+ bar.add(edit);
+
+ JMenu view = new JMenu("View");
+ view.setMnemonic(KeyEvent.VK_V);
+
+ List<String> tt = Instance.getLibrary().getTypes();
+ tt.add(0, null);
+ for (final String type : tt) {
+
+ JMenuItem item = new JMenuItem(type == null ? "All books" : type);
+ item.addActionListener(new ActionListener() {