diff --git a/resources/uk/co/majenko/audiobookrecorder/icons/manuscript.png b/resources/uk/co/majenko/audiobookrecorder/icons/manuscript.png new file mode 100644 index 0000000..7f6d803 Binary files /dev/null and b/resources/uk/co/majenko/audiobookrecorder/icons/manuscript.png differ diff --git a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java index cc58cda..b856f49 100644 --- a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java +++ b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java @@ -78,6 +78,7 @@ public class AudiobookRecorder extends JFrame { JMenuItem toolsMerge; JMenuItem toolsArchive; JMenuItem toolsCoverArt; + JMenuItem toolsManuscript; JMenuItem toolsOptions; JMenuItem helpAbout; @@ -292,6 +293,13 @@ public class AudiobookRecorder extends JFrame { } }); + toolsManuscript = new JMenuItem("Import Manuscript..."); + toolsManuscript.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + loadManuscript(); + } + }); + toolsOptions = new JMenuItem("Options"); toolsOptions.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -302,6 +310,7 @@ public class AudiobookRecorder extends JFrame { toolsMenu.add(toolsMerge); toolsMenu.add(toolsArchive); toolsMenu.add(toolsCoverArt); + toolsMenu.add(toolsManuscript); toolsMenu.addSeparator(); toolsMenu.add(toolsOptions); @@ -3686,4 +3695,33 @@ public class AudiobookRecorder extends JFrame { return notesArea.getText(); } + public void openManuscript() { + if (book == null) return; + File ms = book.getManuscript(); + if (ms == null) return; + try { + Desktop.getDesktop().open(ms); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void loadManuscript() { + if (book == null) return; + + JFileChooser jc = new JFileChooser(); + FileNameExtensionFilter filter = new FileNameExtensionFilter("Document Files", "doc", "docx", "pdf", "odt"); + jc.addChoosableFileFilter(filter); + jc.setFileFilter(filter); + jc.setDialogTitle("Select manuscript"); + int r = jc.showOpenDialog(this); + + if (r == JFileChooser.APPROVE_OPTION) { + File src = jc.getSelectedFile(); + if (src.exists()) { + book.setManuscript(src); + } + } + } + } diff --git a/src/uk/co/majenko/audiobookrecorder/Book.java b/src/uk/co/majenko/audiobookrecorder/Book.java index bf8bc02..485cade 100644 --- a/src/uk/co/majenko/audiobookrecorder/Book.java +++ b/src/uk/co/majenko/audiobookrecorder/Book.java @@ -31,6 +31,7 @@ public class Book extends DefaultMutableTreeNode { String genre; String comment; String ACX; + String manuscript; String defaultEffect = "none"; @@ -63,6 +64,7 @@ public class Book extends DefaultMutableTreeNode { genre = getTextNode(root, "genre"); comment = getTextNode(root, "comment"); ACX = getTextNode(root, "acx"); + manuscript = getTextNode(root, "manuscript"); AudiobookRecorder.window.setNotes(getTextNode(root, "notes")); @@ -183,8 +185,12 @@ public class Book extends DefaultMutableTreeNode { } } + public File getBookPath() { + return new File(Options.get("path.storage"), name); + } + public void renameBook(String newName) { - File oldDir = new File(Options.get("path.storage"), name); + File oldDir = getBookPath(); File newDir = new File(Options.get("path.storage"), newName); if (newDir.exists()) { @@ -298,6 +304,7 @@ public class Book extends DefaultMutableTreeNode { root.appendChild(makeTextNode(doc, "comment", comment)); root.appendChild(makeTextNode(doc, "genre", genre)); root.appendChild(makeTextNode(doc, "acx", ACX)); + root.appendChild(makeTextNode(doc, "manuscript", manuscript)); root.appendChild(makeTextNode(doc, "notes", AudiobookRecorder.window.getNotes())); @@ -333,7 +340,7 @@ public class Book extends DefaultMutableTreeNode { public static Element makeTextNode(Document doc, String name, String text) { Element node = doc.createElement(name); - Text tnode = doc.createTextNode(text); + Text tnode = doc.createTextNode(text == null ? "" : text); node.appendChild(tnode); return node; } @@ -367,4 +374,24 @@ public class Book extends DefaultMutableTreeNode { defaultEffect = eff; } + public void setManuscript(File f) { + manuscript = f.getName(); + File dst = new File(getBookPath(), manuscript); + + try { + Files.copy(f.toPath(), dst.toPath()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public File getManuscript() { + if (manuscript == null) return null; + if (manuscript.equals("")) return null; + File f = new File(getBookPath(), manuscript); + if (f.exists()) { + return f; + } + return null; + } } diff --git a/src/uk/co/majenko/audiobookrecorder/BookTreeRenderer.java b/src/uk/co/majenko/audiobookrecorder/BookTreeRenderer.java index abd7a65..7eb47f2 100644 --- a/src/uk/co/majenko/audiobookrecorder/BookTreeRenderer.java +++ b/src/uk/co/majenko/audiobookrecorder/BookTreeRenderer.java @@ -26,7 +26,7 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer { } if (s.isLocked()) { - ret.setForeground(new Color(0x00, 0x80, 0xFF)); + ret.setForeground(new Color(0x30, 0xb0, 0xFF)); icn.add(Overlays.locked, OverlayIcon.BOTTOM_LEFT); } diff --git a/src/uk/co/majenko/audiobookrecorder/Icons.java b/src/uk/co/majenko/audiobookrecorder/Icons.java index 2ea0018..d06e9c8 100644 --- a/src/uk/co/majenko/audiobookrecorder/Icons.java +++ b/src/uk/co/majenko/audiobookrecorder/Icons.java @@ -38,4 +38,5 @@ public class Icons { static public final ImageIcon docut = new ImageIcon(Icons.class.getResource("icons/do-cut.png")); static public final ImageIcon playto = new ImageIcon(Icons.class.getResource("icons/play-to.png")); static public final ImageIcon disable = new ImageIcon(Icons.class.getResource("icons/disable-effects.png")); + static public final ImageIcon manuscript = new ImageIcon(Icons.class.getResource("icons/manuscript.png")); } diff --git a/src/uk/co/majenko/audiobookrecorder/MainToolBar.java b/src/uk/co/majenko/audiobookrecorder/MainToolBar.java index d08047b..e74cd75 100644 --- a/src/uk/co/majenko/audiobookrecorder/MainToolBar.java +++ b/src/uk/co/majenko/audiobookrecorder/MainToolBar.java @@ -17,6 +17,7 @@ public class MainToolBar extends JToolBar { JButtonSpacePlay playtoSentence; JButtonSpacePlay stopPlaying; JButtonSpacePlay eq; + JButtonSpacePlay openManuscript; JToggleButtonSpacePlay mic; JComboBox playbackSpeed; @@ -171,6 +172,15 @@ public class MainToolBar extends JToolBar { playbackSpeed.setSelectedIndex(1); add(playbackSpeed); + addSeparator(); + openManuscript = new JButtonSpacePlay(Icons.manuscript, "Open Manuscript", new ActionListener() { + public void actionPerformed(ActionEvent e) { + root.openManuscript(); + } + }); + add(openManuscript); + + setFloatable(false); }