Added book info edit option

This commit is contained in:
2018-10-06 21:30:58 +01:00
parent 7431550d61
commit ff08db3e44
3 changed files with 55 additions and 17 deletions

View File

@@ -1 +1 @@
version=0.1.1
version=0.1.2

View File

@@ -1054,6 +1054,40 @@ public class AudiobookRecorder extends JFrame {
menu.addSeparator();
menu.add(deleteChapter);
menu.show(bookTree, e.getX(), e.getY());
} else if (node instanceof Book) {
JPopupMenu menu = new JPopupMenu();
JMenuItem editData = new JMenuItem("Edit Data...");
editData.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookInfoPanel info = new BookInfoPanel(
book.getName(),
book.getAuthor(),
book.getGenre(),
book.getComment(),
book.getACX()
);
int r = JOptionPane.showConfirmDialog(AudiobookRecorder.this, info, "Edit Book", JOptionPane.OK_CANCEL_OPTION);
if (r != JOptionPane.OK_OPTION) return;
String tit = info.getTitle();
String aut = info.getAuthor();
String gen = info.getGenre();
String com = info.getComment();
String acx = info.getACX();
book.setAuthor(aut);
book.setGenre(gen);
book.setComment(com);
book.setACX(acx);
if (!(book.getName().equals(tit))) {
book.renameBook(tit);
}
}
});
menu.add(editData);
menu.show(bookTree, e.getX(), e.getY());
}

View File

@@ -44,7 +44,7 @@ public class Book extends DefaultMutableTreeNode {
public String getAuthor() { return author; }
public String getGenre() { return genre; }
public String getComment() { return comment; }
public String getACX() { return ACX; }
public String getACX() { if (ACX == null) return ""; return ACX; }
public Chapter getClosingCredits() {
return getChapterById("close");
@@ -112,24 +112,28 @@ public class Book extends DefaultMutableTreeNode {
public void setUserObject(Object o) {
if (o instanceof String) {
String newName = (String)o;
if (newName.equals(name)) return;
renameBook(newName);
}
}
File oldDir = new File(Options.get("path.storage"), name);
File newDir = new File(Options.get("path.storage"), newName);
public void renameBook(String newName) {
File oldDir = new File(Options.get("path.storage"), name);
File newDir = new File(Options.get("path.storage"), newName);
if (newDir.exists()) {
JOptionPane.showMessageDialog(AudiobookRecorder.window, "Book already exists", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (newDir.exists()) {
JOptionPane.showMessageDialog(AudiobookRecorder.window, "Book already exists", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (oldDir.exists() && oldDir.isDirectory()) {
oldDir.renameTo(newDir);
name = newName;
AudiobookRecorder.window.saveBookStructure();
AudiobookRecorder.window.bookTreeModel.reload(this);
Options.set("path.last-book", name);
Options.savePreferences();
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
}
if (oldDir.exists() && oldDir.isDirectory()) {
oldDir.renameTo(newDir);
name = newName;
AudiobookRecorder.window.saveBookStructure();
AudiobookRecorder.window.bookTreeModel.reload(this);
Options.set("path.last-book", name);
Options.savePreferences();
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
}
}