+ 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("Rename...");
+ changeTo.setMnemonic(KeyEvent.VK_R);
+ changeTo.addActionListener(createMoveAction("TITLE", null));
+ return changeTo;
+ }
+
+ private ActionListener createMoveAction(final String what, final String type) {
+ return new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ String changeTo = type;
+ if (type == null) {
+ String init = "";
+ if (what.equals("SOURCE")) {
+ init = selectedBook.getMeta().getSource();
+ } else if (what.equals("TITLE")) {
+ init = selectedBook.getMeta().getTitle();
+ } else if (what.equals("AUTHOR")) {
+ init = selectedBook.getMeta().getAuthor();
+ }
+
+ Object rep = JOptionPane.showInputDialog(
+ GuiReaderFrame.this, "Move to:",
+ "Moving story", JOptionPane.QUESTION_MESSAGE,
+ null, null, init);
+
+ if (rep == null) {
+ return;
+ }
+
+ changeTo = rep.toString();
+ }
+
+ final String fChangeTo = changeTo;
+ outOfUi(null, new Runnable() {
+ @Override
+ public void run() {
+ if (what.equals("SOURCE")) {
+ reader.changeSource(selectedBook.getMeta()
+ .getLuid(), fChangeTo);
+ } else if (what.equals("TITLE")) {
+ reader.changeTitle(selectedBook.getMeta()
+ .getLuid(), fChangeTo);
+ } else if (what.equals("AUTHOR")) {
+ reader.changeAuthor(selectedBook.getMeta()
+ .getLuid(), fChangeTo);
+ }
+
+ selectedBook = null;
+
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ setJMenuBar(createMenu(true));
+ }
+ });
+ }
+ });
+ }
+ }
+ };