From ff08db3e4400a9f315a7180f59b453c228462adf Mon Sep 17 00:00:00 2001 From: Matt Jenkins Date: Sat, 6 Oct 2018 21:30:58 +0100 Subject: [PATCH] Added book info edit option --- .../co/majenko/audiobookrecorder/config.txt | 2 +- .../audiobookrecorder/AudiobookRecorder.java | 34 ++++++++++++++++++ src/uk/co/majenko/audiobookrecorder/Book.java | 36 ++++++++++--------- 3 files changed, 55 insertions(+), 17 deletions(-) diff --git a/resources/uk/co/majenko/audiobookrecorder/config.txt b/resources/uk/co/majenko/audiobookrecorder/config.txt index a482420..33aa3f7 100644 --- a/resources/uk/co/majenko/audiobookrecorder/config.txt +++ b/resources/uk/co/majenko/audiobookrecorder/config.txt @@ -1 +1 @@ -version=0.1.1 +version=0.1.2 diff --git a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java index c5fde4f..df3ac5f 100644 --- a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java +++ b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java @@ -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()); } diff --git a/src/uk/co/majenko/audiobookrecorder/Book.java b/src/uk/co/majenko/audiobookrecorder/Book.java index 280743d..2b6265c 100644 --- a/src/uk/co/majenko/audiobookrecorder/Book.java +++ b/src/uk/co/majenko/audiobookrecorder/Book.java @@ -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); } }