+ /**
+ * Create the "set author" menu item.
+ *
+ * @param libOk
+ * the library can be queried
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemSetAuthor(boolean libOk) {
+ JMenu changeTo = new JMenu(
+ GuiReader.trans(StringIdGui.MENU_FILE_SET_AUTHOR));
+ changeTo.setMnemonic(KeyEvent.VK_A);
+
+ // New author
+ JMenuItem newItem = new JMenuItem(
+ GuiReader.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR));
+ changeTo.add(newItem);
+ changeTo.addSeparator();
+ newItem.addActionListener(createMoveAction(ChangeAction.AUTHOR, null));
+
+ // Existing authors
+ if (libOk) {
+ Map<String, List<String>> groupedAuthors = reader.getLibrary()
+ .getAuthorsGrouped();
+
+ if (groupedAuthors.size() > 1) {
+ for (String key : groupedAuthors.keySet()) {
+ JMenu group = new JMenu(key);
+ for (String value : groupedAuthors.get(key)) {
+ JMenuItem item = new JMenuItem(
+ value.isEmpty() ? GuiReader
+ .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+ : value);
+ item.addActionListener(createMoveAction(
+ ChangeAction.AUTHOR, value));
+ group.add(item);
+ }
+ changeTo.add(group);
+ }
+ } else if (groupedAuthors.size() == 1) {
+ for (String value : groupedAuthors.values().iterator().next()) {
+ JMenuItem item = new JMenuItem(
+ value.isEmpty() ? GuiReader
+ .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+ : value);
+ item.addActionListener(createMoveAction(
+ ChangeAction.AUTHOR, value));
+ changeTo.add(item);
+ }
+ }
+ }
+
+ return changeTo;
+ }
+
+ /**
+ * Create the "rename" menu item.
+ *
+ * @param libOk
+ * the library can be queried
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemRename(
+ @SuppressWarnings("unused") boolean libOk) {
+ JMenuItem changeTo = new JMenuItem(
+ GuiReader.trans(StringIdGui.MENU_FILE_RENAME));
+ changeTo.setMnemonic(KeyEvent.VK_R);
+ changeTo.addActionListener(createMoveAction(ChangeAction.TITLE, null));
+ return changeTo;
+ }
+
+ private ActionListener createMoveAction(final ChangeAction what,
+ final String type) {
+ return new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
+ if (selectedBook != null) {
+ boolean refreshRequired = false;
+
+ if (what == ChangeAction.SOURCE) {
+ refreshRequired = mainPanel.getCurrentType();
+ } else if (what == ChangeAction.TITLE) {
+ refreshRequired = false;
+ } else if (what == ChangeAction.AUTHOR) {
+ refreshRequired = !mainPanel.getCurrentType();
+ }
+
+ String changeTo = type;
+ if (type == null) {
+ MetaData meta = selectedBook.getInfo().getMeta();
+ String init = "";
+ if (what == ChangeAction.SOURCE) {
+ init = meta.getSource();
+ } else if (what == ChangeAction.TITLE) {
+ init = meta.getTitle();
+ } else if (what == ChangeAction.AUTHOR) {
+ init = meta.getAuthor();