Update MainWindow.java
This commit is contained in:
parent
6b4b4c0ac4
commit
981898dc2a
@ -74,7 +74,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
private static JFrame mainFrame;
|
private static JFrame mainFrame;
|
||||||
private static JTextField ripTextfield;
|
private static JTextField ripTextfield;
|
||||||
private static JButton ripButton,
|
private static JButton ripButton,
|
||||||
stopButton;
|
stopButton;
|
||||||
|
|
||||||
private static JLabel statusLabel;
|
private static JLabel statusLabel;
|
||||||
private static JButton openButton;
|
private static JButton openButton;
|
||||||
@ -96,8 +96,8 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
private static JTable historyTable;
|
private static JTable historyTable;
|
||||||
private static AbstractTableModel historyTableModel;
|
private static AbstractTableModel historyTableModel;
|
||||||
private static JButton historyButtonRemove,
|
private static JButton historyButtonRemove,
|
||||||
historyButtonClear,
|
historyButtonClear,
|
||||||
historyButtonRerip;
|
historyButtonRerip;
|
||||||
|
|
||||||
// Queue
|
// Queue
|
||||||
public static JButton optionQueue;
|
public static JButton optionQueue;
|
||||||
@ -388,15 +388,15 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
for (int i = 0; i < historyTable.getColumnModel().getColumnCount(); i++) {
|
for (int i = 0; i < historyTable.getColumnModel().getColumnCount(); i++) {
|
||||||
int width = 130; // Default
|
int width = 130; // Default
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0: // URL
|
case 0: // URL
|
||||||
width = 270;
|
width = 270;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
width = 40;
|
width = 40;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
width = 15;
|
width = 15;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
historyTable.getColumnModel().getColumn(i).setPreferredWidth(width);
|
historyTable.getColumnModel().getColumn(i).setPreferredWidth(width);
|
||||||
}
|
}
|
||||||
@ -494,29 +494,29 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT);
|
configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT);
|
||||||
configSaveDirButton = new JButton("Select Save Directory...");
|
configSaveDirButton = new JButton("Select Save Directory...");
|
||||||
gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc);
|
gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc);
|
gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc);
|
||||||
gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configAutoupdateCheckbox, gbc);
|
gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configAutoupdateCheckbox, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configLogLevelCombobox, gbc);
|
gbc.gridx = 1; configurationPanel.add(configLogLevelCombobox, gbc);
|
||||||
gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc);
|
gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc);
|
gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc);
|
||||||
gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc);
|
gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc);
|
gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc);
|
||||||
gbc.gridy = 4; gbc.gridx = 0; configurationPanel.add(configRetriesLabel, gbc);
|
gbc.gridy = 4; gbc.gridx = 0; configurationPanel.add(configRetriesLabel, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc);
|
gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc);
|
||||||
gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc);
|
gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configSaveOrderCheckbox, gbc);
|
gbc.gridx = 1; configurationPanel.add(configSaveOrderCheckbox, gbc);
|
||||||
gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc);
|
gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configSaveLogs, gbc);
|
gbc.gridx = 1; configurationPanel.add(configSaveLogs, gbc);
|
||||||
gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configShowPopup, gbc);
|
gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configShowPopup, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configSaveURLsOnly, gbc);
|
gbc.gridx = 1; configurationPanel.add(configSaveURLsOnly, gbc);
|
||||||
gbc.gridy = 8; gbc.gridx = 0; configurationPanel.add(configClipboardAutorip, gbc);
|
gbc.gridy = 8; gbc.gridx = 0; configurationPanel.add(configClipboardAutorip, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configSaveAlbumTitles, gbc);
|
gbc.gridx = 1; configurationPanel.add(configSaveAlbumTitles, gbc);
|
||||||
gbc.gridy = 9; gbc.gridx = 0; configurationPanel.add(configSaveDescriptions, gbc);
|
gbc.gridy = 9; gbc.gridx = 0; configurationPanel.add(configSaveDescriptions, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configPreferMp4, gbc);
|
gbc.gridx = 1; configurationPanel.add(configPreferMp4, gbc);
|
||||||
gbc.gridy = 10; gbc.gridx = 0; configurationPanel.add(configWindowPosition, gbc);
|
gbc.gridy = 10; gbc.gridx = 0; configurationPanel.add(configWindowPosition, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configURLHistoryCheckbox, gbc);
|
gbc.gridx = 1; configurationPanel.add(configURLHistoryCheckbox, gbc);
|
||||||
gbc.gridy = 11; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
|
gbc.gridy = 11; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
|
||||||
gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc);
|
gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc);
|
||||||
|
|
||||||
|
|
||||||
emptyPanel = new JPanel();
|
emptyPanel = new JPanel();
|
||||||
@ -661,33 +661,46 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
saveHistory();
|
saveHistory();
|
||||||
});
|
});
|
||||||
historyButtonClear.addActionListener(event -> {
|
historyButtonClear.addActionListener(event -> {
|
||||||
JPanel checkChoise = new JPanel();
|
if (Utils.getConfigBoolean("history.warn_before_delete", true)) {
|
||||||
checkChoise.setLayout(new FlowLayout());
|
|
||||||
JButton yesButton = new JButton("YES");
|
JPanel checkChoise = new JPanel();
|
||||||
JButton noButton = new JButton("NO");
|
checkChoise.setLayout(new FlowLayout());
|
||||||
yesButton.setPreferredSize(new Dimension(70,30));
|
JButton yesButton = new JButton("YES");
|
||||||
noButton.setPreferredSize(new Dimension(70,30));
|
JButton noButton = new JButton("NO");
|
||||||
checkChoise.add(yesButton);
|
yesButton.setPreferredSize(new Dimension(70, 30));
|
||||||
checkChoise.add(noButton);
|
noButton.setPreferredSize(new Dimension(70, 30));
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
checkChoise.add(yesButton);
|
||||||
JFrame frame = new JFrame("Are you sure?");
|
checkChoise.add(noButton);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||||
frame.add(checkChoise);
|
JFrame frame = new JFrame("Are you sure?");
|
||||||
frame.setSize(405, 70);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setVisible(true);
|
frame.add(checkChoise);
|
||||||
frame.setLocationRelativeTo(null);
|
frame.setSize(405, 70);
|
||||||
noButton.addActionListener(e -> {
|
frame.setVisible(true);
|
||||||
frame.setVisible(false);
|
frame.setLocationRelativeTo(null);
|
||||||
});
|
noButton.addActionListener(e -> {
|
||||||
yesButton.addActionListener(ed -> {
|
frame.setVisible(false);
|
||||||
frame.setVisible(false);
|
});
|
||||||
|
yesButton.addActionListener(ed -> {
|
||||||
|
frame.setVisible(false);
|
||||||
|
Utils.clearURLHistory();
|
||||||
|
HISTORY.clear();
|
||||||
|
try {
|
||||||
|
historyTableModel.fireTableDataChanged();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
saveHistory();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
Utils.clearURLHistory();
|
Utils.clearURLHistory();
|
||||||
HISTORY.clear();
|
HISTORY.clear();
|
||||||
try {
|
try {
|
||||||
historyTableModel.fireTableDataChanged();
|
historyTableModel.fireTableDataChanged();
|
||||||
} catch (Exception e) { }
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
saveHistory();
|
saveHistory();
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Re-rip all history
|
// Re-rip all history
|
||||||
@ -834,8 +847,8 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
trayMenuAbout.addActionListener(arg0 -> {
|
trayMenuAbout.addActionListener(arg0 -> {
|
||||||
StringBuilder about = new StringBuilder();
|
StringBuilder about = new StringBuilder();
|
||||||
about.append("<html><h1>")
|
about.append("<html><h1>")
|
||||||
.append(mainFrame.getTitle())
|
.append(mainFrame.getTitle())
|
||||||
.append("</h1>");
|
.append("</h1>");
|
||||||
about.append("Download albums from various websites:");
|
about.append("Download albums from various websites:");
|
||||||
try {
|
try {
|
||||||
List<String> rippers = Utils.getListOfAlbumRippers();
|
List<String> rippers = Utils.getListOfAlbumRippers();
|
||||||
@ -851,7 +864,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
}
|
}
|
||||||
about.append("</ul>");
|
about.append("</ul>");
|
||||||
} catch (Exception e) { }
|
} catch (Exception e) { }
|
||||||
about.append("<br>And download videos from video sites:");
|
about.append("<br>And download videos from video sites:");
|
||||||
try {
|
try {
|
||||||
List<String> rippers = Utils.getListOfVideoRippers();
|
List<String> rippers = Utils.getListOfVideoRippers();
|
||||||
about.append("<ul>");
|
about.append("<ul>");
|
||||||
@ -958,9 +971,9 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
logger.error("Failed to load history from file " + historyFile, e);
|
logger.error("Failed to load history from file " + historyFile, e);
|
||||||
JOptionPane.showMessageDialog(null,
|
JOptionPane.showMessageDialog(null,
|
||||||
"RipMe failed to load the history file at " + historyFile.getAbsolutePath() + "\n\n" +
|
"RipMe failed to load the history file at " + historyFile.getAbsolutePath() + "\n\n" +
|
||||||
"Error: " + e.getMessage() + "\n\n" +
|
"Error: " + e.getMessage() + "\n\n" +
|
||||||
"Closing RipMe will automatically overwrite the contents of this file,\n" +
|
"Closing RipMe will automatically overwrite the contents of this file,\n" +
|
||||||
"so you may want to back the file up before closing RipMe!",
|
"so you may want to back the file up before closing RipMe!",
|
||||||
"RipMe - history load failure",
|
"RipMe - history load failure",
|
||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
@ -1127,93 +1140,93 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
status( evt.ripper.getStatusText() );
|
status( evt.ripper.getStatusText() );
|
||||||
|
|
||||||
switch(msg.getStatus()) {
|
switch(msg.getStatus()) {
|
||||||
case LOADING_RESOURCE:
|
case LOADING_RESOURCE:
|
||||||
case DOWNLOAD_STARTED:
|
case DOWNLOAD_STARTED:
|
||||||
if (logger.isEnabledFor(Level.INFO)) {
|
if (logger.isEnabledFor(Level.INFO)) {
|
||||||
appendLog("Downloading " + msg.getObject(), Color.BLACK);
|
appendLog("Downloading " + msg.getObject(), Color.BLACK);
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DOWNLOAD_COMPLETE:
|
|
||||||
if (logger.isEnabledFor(Level.INFO)) {
|
|
||||||
appendLog("Downloaded " + msg.getObject(), Color.GREEN);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DOWNLOAD_ERRORED:
|
|
||||||
if (logger.isEnabledFor(Level.ERROR)) {
|
|
||||||
appendLog((String) msg.getObject(), Color.RED);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DOWNLOAD_WARN:
|
|
||||||
if (logger.isEnabledFor(Level.WARN)) {
|
|
||||||
appendLog((String) msg.getObject(), Color.ORANGE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RIP_ERRORED:
|
|
||||||
if (logger.isEnabledFor(Level.ERROR)) {
|
|
||||||
appendLog((String) msg.getObject(), Color.RED);
|
|
||||||
}
|
|
||||||
stopButton.setEnabled(false);
|
|
||||||
statusProgress.setValue(0);
|
|
||||||
statusProgress.setVisible(false);
|
|
||||||
openButton.setVisible(false);
|
|
||||||
pack();
|
|
||||||
statusWithColor("Error: " + msg.getObject(), Color.RED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RIP_COMPLETE:
|
|
||||||
RipStatusComplete rsc = (RipStatusComplete) msg.getObject();
|
|
||||||
String url = ripper.getURL().toExternalForm();
|
|
||||||
if (HISTORY.containsURL(url)) {
|
|
||||||
// TODO update "modifiedDate" of entry in HISTORY
|
|
||||||
HistoryEntry entry = HISTORY.getEntryByURL(url);
|
|
||||||
entry.count = rsc.count;
|
|
||||||
entry.modifiedDate = new Date();
|
|
||||||
} else {
|
|
||||||
HistoryEntry entry = new HistoryEntry();
|
|
||||||
entry.url = url;
|
|
||||||
entry.dir = rsc.getDir();
|
|
||||||
entry.count = rsc.count;
|
|
||||||
try {
|
|
||||||
entry.title = ripper.getAlbumTitle(ripper.getURL());
|
|
||||||
} catch (MalformedURLException e) { }
|
|
||||||
HISTORY.add(entry);
|
|
||||||
historyTableModel.fireTableDataChanged();
|
|
||||||
}
|
|
||||||
if (configPlaySound.isSelected()) {
|
|
||||||
Utils.playSound("camera.wav");
|
|
||||||
}
|
|
||||||
saveHistory();
|
|
||||||
stopButton.setEnabled(false);
|
|
||||||
statusProgress.setValue(0);
|
|
||||||
statusProgress.setVisible(false);
|
|
||||||
openButton.setVisible(true);
|
|
||||||
File f = rsc.dir;
|
|
||||||
String prettyFile = Utils.shortenPath(f);
|
|
||||||
openButton.setText("Open " + prettyFile);
|
|
||||||
mainFrame.setTitle("RipMe v" + UpdateUtils.getThisJarVersion());
|
|
||||||
try {
|
|
||||||
Image folderIcon = ImageIO.read(getClass().getClassLoader().getResource("folder.png"));
|
|
||||||
openButton.setIcon(new ImageIcon(folderIcon));
|
|
||||||
} catch (Exception e) { }
|
|
||||||
appendLog("Rip complete, saved to " + f.getAbsolutePath(), Color.GREEN);
|
|
||||||
openButton.setActionCommand(f.toString());
|
|
||||||
openButton.addActionListener(event -> {
|
|
||||||
try {
|
|
||||||
Desktop.getDesktop().open(new File(event.getActionCommand()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e);
|
|
||||||
}
|
}
|
||||||
});
|
break;
|
||||||
pack();
|
case DOWNLOAD_COMPLETE:
|
||||||
ripNextAlbum();
|
if (logger.isEnabledFor(Level.INFO)) {
|
||||||
break;
|
appendLog("Downloaded " + msg.getObject(), Color.GREEN);
|
||||||
case COMPLETED_BYTES:
|
}
|
||||||
// Update completed bytes
|
break;
|
||||||
break;
|
case DOWNLOAD_ERRORED:
|
||||||
case TOTAL_BYTES:
|
if (logger.isEnabledFor(Level.ERROR)) {
|
||||||
// Update total bytes
|
appendLog((String) msg.getObject(), Color.RED);
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
case DOWNLOAD_WARN:
|
||||||
|
if (logger.isEnabledFor(Level.WARN)) {
|
||||||
|
appendLog((String) msg.getObject(), Color.ORANGE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RIP_ERRORED:
|
||||||
|
if (logger.isEnabledFor(Level.ERROR)) {
|
||||||
|
appendLog((String) msg.getObject(), Color.RED);
|
||||||
|
}
|
||||||
|
stopButton.setEnabled(false);
|
||||||
|
statusProgress.setValue(0);
|
||||||
|
statusProgress.setVisible(false);
|
||||||
|
openButton.setVisible(false);
|
||||||
|
pack();
|
||||||
|
statusWithColor("Error: " + msg.getObject(), Color.RED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RIP_COMPLETE:
|
||||||
|
RipStatusComplete rsc = (RipStatusComplete) msg.getObject();
|
||||||
|
String url = ripper.getURL().toExternalForm();
|
||||||
|
if (HISTORY.containsURL(url)) {
|
||||||
|
// TODO update "modifiedDate" of entry in HISTORY
|
||||||
|
HistoryEntry entry = HISTORY.getEntryByURL(url);
|
||||||
|
entry.count = rsc.count;
|
||||||
|
entry.modifiedDate = new Date();
|
||||||
|
} else {
|
||||||
|
HistoryEntry entry = new HistoryEntry();
|
||||||
|
entry.url = url;
|
||||||
|
entry.dir = rsc.getDir();
|
||||||
|
entry.count = rsc.count;
|
||||||
|
try {
|
||||||
|
entry.title = ripper.getAlbumTitle(ripper.getURL());
|
||||||
|
} catch (MalformedURLException e) { }
|
||||||
|
HISTORY.add(entry);
|
||||||
|
historyTableModel.fireTableDataChanged();
|
||||||
|
}
|
||||||
|
if (configPlaySound.isSelected()) {
|
||||||
|
Utils.playSound("camera.wav");
|
||||||
|
}
|
||||||
|
saveHistory();
|
||||||
|
stopButton.setEnabled(false);
|
||||||
|
statusProgress.setValue(0);
|
||||||
|
statusProgress.setVisible(false);
|
||||||
|
openButton.setVisible(true);
|
||||||
|
File f = rsc.dir;
|
||||||
|
String prettyFile = Utils.shortenPath(f);
|
||||||
|
openButton.setText("Open " + prettyFile);
|
||||||
|
mainFrame.setTitle("RipMe v" + UpdateUtils.getThisJarVersion());
|
||||||
|
try {
|
||||||
|
Image folderIcon = ImageIO.read(getClass().getClassLoader().getResource("folder.png"));
|
||||||
|
openButton.setIcon(new ImageIcon(folderIcon));
|
||||||
|
} catch (Exception e) { }
|
||||||
|
appendLog("Rip complete, saved to " + f.getAbsolutePath(), Color.GREEN);
|
||||||
|
openButton.setActionCommand(f.toString());
|
||||||
|
openButton.addActionListener(event -> {
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().open(new File(event.getActionCommand()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pack();
|
||||||
|
ripNextAlbum();
|
||||||
|
break;
|
||||||
|
case COMPLETED_BYTES:
|
||||||
|
// Update completed bytes
|
||||||
|
break;
|
||||||
|
case TOTAL_BYTES:
|
||||||
|
// Update total bytes
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user