+ 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(createMenuItemOpenBook());
+ file.add(createMenuItemExport());
+ file.add(createMenuItemMove());
+ file.addSeparator();
+ file.add(imprt);
+ file.add(imprtF);
+ file.addSeparator();
+ file.add(exit);
+
+ bar.add(file);
+
+ JMenu edit = new JMenu("Edit");
+ edit.setMnemonic(KeyEvent.VK_E);
+
+ edit.add(createMenuItemClearCache());
+ edit.add(createMenuItemRedownload());
+ edit.addSeparator();
+ edit.add(createMenuItemDelete());
+
+ bar.add(edit);
+
+ JMenu view = new JMenu("View");
+ view.setMnemonic(KeyEvent.VK_V);
+ JMenuItem vauthors = new JMenuItem("Author");
+ vauthors.setMnemonic(KeyEvent.VK_A);
+ vauthors.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ words = false;
+ refreshBooks();
+ }
+ });
+ view.add(vauthors);
+ JMenuItem vwords = new JMenuItem("Word count");
+ vwords.setMnemonic(KeyEvent.VK_W);
+ vwords.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ words = true;
+ refreshBooks();
+ }
+ });
+ view.add(vwords);
+ bar.add(view);
+
+ JMenu sources = new JMenu("Sources");
+ sources.setMnemonic(KeyEvent.VK_S);
+
+ 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) {
+ removeBookPanes();
+ addBookPane(type, true);
+ refreshBooks();
+ }
+ });
+ sources.add(item);
+
+ if (type == null) {
+ sources.addSeparator();
+ }
+ }
+
+ bar.add(sources);
+
+ JMenu authors = new JMenu("Authors");
+ authors.setMnemonic(KeyEvent.VK_A);
+
+ List<String> aa = Instance.getLibrary().getAuthors();
+ aa.add(0, null);
+ for (final String author : aa) {
+ JMenuItem item = new JMenuItem(author == null ? "All"
+ : author.isEmpty() ? "[unknown]" : author);
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ removeBookPanes();
+ addBookPane(author, false);
+ refreshBooks();
+ }
+ });
+ authors.add(item);
+
+ if (author == null || author.isEmpty()) {
+ authors.addSeparator();
+ }
+ }
+
+ bar.add(authors);
+
+ JMenu options = new JMenu("Options");
+ options.setMnemonic(KeyEvent.VK_O);
+ options.add(createMenuItemConfig());
+ options.add(createMenuItemUiConfig());
+ bar.add(options);
+
+ return bar;
+ }
+
+ /**
+ * Create the Fanfix Configuration menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemConfig() {
+ final String title = "Fanfix Configuration";
+ JMenuItem item = new JMenuItem(title);
+ item.setMnemonic(KeyEvent.VK_F);
+
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ ConfigEditor<Config> ed = new ConfigEditor<Config>(
+ Config.class, Instance.getConfig(),
+ "This is where you configure the options of the program.");
+ JFrame frame = new JFrame(title);
+ frame.add(ed);
+ frame.setSize(800, 600);
+ frame.setVisible(true);
+ }
+ });
+
+ return item;
+ }
+
+ /**
+ * Create the UI Configuration menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemUiConfig() {
+ final String title = "UI Configuration";
+ JMenuItem item = new JMenuItem(title);
+ item.setMnemonic(KeyEvent.VK_U);
+
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ ConfigEditor<UiConfig> ed = new ConfigEditor<UiConfig>(
+ UiConfig.class, Instance.getUiConfig(),
+ "This is where you configure the graphical appearence of the program.");
+ JFrame frame = new JFrame(title);
+ frame.add(ed);
+ frame.setSize(800, 600);
+ frame.setVisible(true);
+ }
+ });
+
+ return item;
+ }
+
+ /**
+ * Create the export menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemExport() {
+ final JFileChooser fc = new JFileChooser();
+ fc.setAcceptAllFileFilterUsed(false);
+
+ final Map<FileFilter, OutputType> filters = new HashMap<FileFilter, OutputType>();
+ for (OutputType type : OutputType.values()) {
+ String ext = type.getDefaultExtension(false);
+ String desc = type.getDesc(false);
+
+ if (ext == null || ext.isEmpty()) {
+ filters.put(createAllFilter(desc), type);
+ } else {
+ filters.put(new FileNameExtensionFilter(desc, ext), type);
+ }
+ }
+
+ // First the "ALL" filters, then, the extension filters
+ for (Entry<FileFilter, OutputType> entry : filters.entrySet()) {
+ if (!(entry.getKey() instanceof FileNameExtensionFilter)) {
+ fc.addChoosableFileFilter(entry.getKey());
+ }
+ }
+ for (Entry<FileFilter, OutputType> entry : filters.entrySet()) {
+ if (entry.getKey() instanceof FileNameExtensionFilter) {
+ fc.addChoosableFileFilter(entry.getKey());
+ }
+ }
+ //
+
+ JMenuItem export = new JMenuItem("Save as...", KeyEvent.VK_S);
+ export.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ fc.showDialog(LocalReaderFrame.this, "Save");
+ if (fc.getSelectedFile() != null) {
+ final OutputType type = filters.get(fc.getFileFilter());
+ final String path = fc.getSelectedFile()
+ .getAbsolutePath()
+ + type.getDefaultExtension(false);
+ final Progress pg = new Progress();
+ outOfUi(pg, new Runnable() {
+ public void run() {
+ try {
+ Instance.getLibrary().export(
+ selectedBook.getMeta().getLuid(),
+ type, path, pg);
+ } catch (IOException e) {
+ Instance.syserr(e);
+ }