Added rename book

This commit is contained in:
2018-09-13 17:51:20 +01:00
parent aa9d7993d6
commit a8b8def6ca
5 changed files with 72 additions and 14 deletions

View File

@@ -1060,6 +1060,15 @@ public class AudiobookRecorder extends JFrame {
prefs.loadFromXML(fis); prefs.loadFromXML(fis);
buildBook(prefs); buildBook(prefs);
File r = f.getParentFile();
File cf = new File(r, "coverart.png");
if (cf.exists()) {
ImageIcon i = new ImageIcon(cf.getAbsolutePath());
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
book.setIcon(new ImageIcon(ri));
bookTreeModel.reload(book);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -1242,6 +1251,7 @@ public class AudiobookRecorder extends JFrame {
toolBar.enableBook(); toolBar.enableBook();
statusLabel.setText("Noise floor: " + getNoiseFloor()); statusLabel.setText("Noise floor: " + getNoiseFloor());
book.setIcon(Icons.book);
} }
public void openBook() { public void openBook() {

View File

@@ -16,6 +16,8 @@ public class Book extends DefaultMutableTreeNode {
String genre; String genre;
String comment; String comment;
ImageIcon icon;
public Book(String bookname) { public Book(String bookname) {
super(bookname); super(bookname);
name = bookname; name = bookname;
@@ -99,4 +101,39 @@ public class Book extends DefaultMutableTreeNode {
public String getName() { public String getName() {
return name; return name;
} }
public ImageIcon getIcon() {
return icon;
}
public void setIcon(ImageIcon i) {
icon = i;
}
public void setUserObject(Object o) {
if (o instanceof String) {
String newName = (String)o;
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 (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();
}
}
}
public String toString() {
return name;
}
} }

View File

@@ -40,7 +40,7 @@ public class BookPanel extends JPanel {
File icon = new File(root, "coverart.png"); File icon = new File(root, "coverart.png");
if (icon.exists()) { if (icon.exists()) {
cover = new ImageIcon(icon.getAbsolutePath()); cover = new ImageIcon(icon.getAbsolutePath());
resizedCover = getScaledImage(cover.getImage(), 75, 75); resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
iconLabel = new JLabel(new ImageIcon(resizedCover)); iconLabel = new JLabel(new ImageIcon(resizedCover));
} else { } else {
cover = null; cover = null;
@@ -80,18 +80,6 @@ public class BookPanel extends JPanel {
} }
} }
private Image getScaledImage(Image srcImg, int w, int h){
BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = resizedImg.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(srcImg, 0, 0, w, h, null);
g2.dispose();
return resizedImg;
}
public File getConfigFile() { public File getConfigFile() {
return new File(root, "audiobook.abk"); return new File(root, "audiobook.abk");
} }

View File

@@ -19,7 +19,7 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
} else if (value instanceof Chapter) { } else if (value instanceof Chapter) {
ret.setIcon(Icons.chapter); ret.setIcon(Icons.chapter);
} else if (value instanceof Book) { } else if (value instanceof Book) {
ret.setIcon(Icons.book); ret.setIcon(((Book)value).getIcon());
} }
return ret; return ret;
} }

View File

@@ -0,0 +1,23 @@
package uk.co.majenko.audiobookrecorder;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.border.*;
import java.util.*;
import java.io.*;
public class Utils {
public static Image getScaledImage(Image srcImg, int w, int h){
BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = resizedImg.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(srcImg, 0, 0, w, h, null);
g2.dispose();
return resizedImg;
}
}