+ 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.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);
+
+ 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() {
+ public void actionPerformed(ActionEvent e) {
+ refreshBooks(type);
+ }
+ });
+ view.add(item);
+
+ if (type == null) {
+ view.addSeparator();
+ }
+ }
+
+ bar.add(view);
+
+ return bar;
+ }
+
+ /**
+ * 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");
+ final OutputType type = filters.get(fc.getFileFilter());
+ final String path = fc.getSelectedFile().getAbsolutePath()
+ + type.getDefaultExtension(false);
+ final Progress pg = new Progress();