Added import / open manuscript file

This commit is contained in:
2020-01-12 22:46:15 +00:00
parent db7d297dbc
commit 3b5cacb8ad
6 changed files with 79 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -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);
}
}
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -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"));
}

View File

@@ -17,6 +17,7 @@ public class MainToolBar extends JToolBar {
JButtonSpacePlay playtoSentence;
JButtonSpacePlay stopPlaying;
JButtonSpacePlay eq;
JButtonSpacePlay openManuscript;
JToggleButtonSpacePlay mic;
JComboBox<String> 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);
}