2014-03-01 11:13:32 +01:00
|
|
|
package com.rarchives.ripme.ui;
|
|
|
|
|
2017-10-25 22:31:02 +02:00
|
|
|
import java.awt.*;
|
2014-04-08 06:57:18 +02:00
|
|
|
import java.awt.TrayIcon.MessageType;
|
2014-03-01 11:13:32 +01:00
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
2014-04-08 06:57:18 +02:00
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
|
import java.awt.event.MouseEvent;
|
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
import java.awt.event.WindowEvent;
|
2014-03-01 11:13:32 +01:00
|
|
|
import java.io.File;
|
2014-04-27 19:09:52 +02:00
|
|
|
import java.io.IOException;
|
2014-03-09 08:59:36 +01:00
|
|
|
import java.net.MalformedURLException;
|
2014-04-27 19:09:52 +02:00
|
|
|
import java.net.URI;
|
2014-03-01 11:13:32 +01:00
|
|
|
import java.net.URL;
|
2017-10-15 14:21:58 +02:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
2015-02-10 07:18:09 +01:00
|
|
|
import java.util.Collections;
|
2015-01-11 09:23:43 +01:00
|
|
|
import java.util.Date;
|
2015-09-17 12:11:50 +02:00
|
|
|
import java.util.Enumeration;
|
2014-04-27 19:09:52 +02:00
|
|
|
import java.util.List;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-04-07 02:26:30 +02:00
|
|
|
import javax.imageio.ImageIO;
|
2014-03-08 21:22:49 +01:00
|
|
|
import javax.swing.DefaultListModel;
|
2014-04-07 02:26:30 +02:00
|
|
|
import javax.swing.ImageIcon;
|
2014-03-01 11:13:32 +01:00
|
|
|
import javax.swing.JButton;
|
2014-04-06 01:57:54 +02:00
|
|
|
import javax.swing.JCheckBox;
|
2015-02-10 08:29:29 +01:00
|
|
|
import javax.swing.JComboBox;
|
2014-04-06 11:41:04 +02:00
|
|
|
import javax.swing.JFileChooser;
|
2014-03-01 11:13:32 +01:00
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JLabel;
|
2014-03-02 10:12:20 +01:00
|
|
|
import javax.swing.JList;
|
2014-04-07 02:26:30 +02:00
|
|
|
import javax.swing.JOptionPane;
|
2014-03-02 03:08:16 +01:00
|
|
|
import javax.swing.JPanel;
|
2014-03-02 08:28:37 +01:00
|
|
|
import javax.swing.JProgressBar;
|
|
|
|
import javax.swing.JScrollPane;
|
2015-01-11 13:31:30 +01:00
|
|
|
import javax.swing.JTable;
|
2014-03-01 11:13:32 +01:00
|
|
|
import javax.swing.JTextField;
|
2014-03-02 08:28:37 +01:00
|
|
|
import javax.swing.JTextPane;
|
2014-03-09 08:59:36 +01:00
|
|
|
import javax.swing.ListSelectionModel;
|
2014-03-08 21:22:49 +01:00
|
|
|
import javax.swing.SwingUtilities;
|
2014-04-07 02:26:30 +02:00
|
|
|
import javax.swing.UIManager;
|
2014-03-02 08:28:37 +01:00
|
|
|
import javax.swing.border.EmptyBorder;
|
2014-06-08 04:54:36 +02:00
|
|
|
import javax.swing.event.DocumentEvent;
|
|
|
|
import javax.swing.event.DocumentListener;
|
2014-07-30 16:48:52 +02:00
|
|
|
import javax.swing.event.ListDataEvent;
|
|
|
|
import javax.swing.event.ListDataListener;
|
2015-01-11 13:31:30 +01:00
|
|
|
import javax.swing.table.AbstractTableModel;
|
2014-03-02 10:12:20 +01:00
|
|
|
import javax.swing.text.BadLocationException;
|
|
|
|
import javax.swing.text.SimpleAttributeSet;
|
|
|
|
import javax.swing.text.StyleConstants;
|
|
|
|
import javax.swing.text.StyledDocument;
|
2014-03-02 03:08:16 +01:00
|
|
|
|
2015-02-10 08:29:29 +01:00
|
|
|
import org.apache.log4j.ConsoleAppender;
|
|
|
|
import org.apache.log4j.FileAppender;
|
2015-01-11 14:11:10 +01:00
|
|
|
import org.apache.log4j.Level;
|
2014-03-02 03:08:16 +01:00
|
|
|
import org.apache.log4j.Logger;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
|
|
|
import com.rarchives.ripme.ripper.AbstractRipper;
|
2015-02-10 07:18:09 +01:00
|
|
|
import com.rarchives.ripme.utils.RipUtils;
|
2014-03-02 03:08:16 +01:00
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2017-10-25 22:31:02 +02:00
|
|
|
|
2017-05-09 23:02:24 +02:00
|
|
|
import javax.swing.UnsupportedLookAndFeelException;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-09 09:20:22 +01:00
|
|
|
/**
|
|
|
|
* Everything UI-related starts and ends here.
|
|
|
|
*/
|
2017-05-09 23:02:24 +02:00
|
|
|
public final class MainWindow implements Runnable, RipStatusHandler {
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-02 03:08:16 +01:00
|
|
|
private static final Logger logger = Logger.getLogger(MainWindow.class);
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-07-30 16:48:52 +02:00
|
|
|
private boolean isRipping = false; // Flag to indicate if we're ripping something
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
private static JFrame mainFrame;
|
|
|
|
private static JTextField ripTextfield;
|
2014-04-18 07:11:37 +02:00
|
|
|
private static JButton ripButton,
|
|
|
|
stopButton;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-02 03:08:16 +01:00
|
|
|
private static JLabel statusLabel;
|
2014-03-02 08:28:37 +01:00
|
|
|
private static JButton openButton;
|
|
|
|
private static JProgressBar statusProgress;
|
|
|
|
|
2017-10-31 00:47:58 +01:00
|
|
|
// Put an empty JPanel on the bottom of the window to keep components
|
|
|
|
// anchored to the top when there is no open lower panel
|
|
|
|
private static JPanel emptyPanel;
|
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
// Log
|
|
|
|
private static JButton optionLog;
|
|
|
|
private static JPanel logPanel;
|
|
|
|
private static JTextPane logText;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
// History
|
|
|
|
private static JButton optionHistory;
|
2015-01-11 13:31:30 +01:00
|
|
|
private static final History HISTORY = new History();
|
2014-03-02 10:12:20 +01:00
|
|
|
private static JPanel historyPanel;
|
2015-01-11 13:31:30 +01:00
|
|
|
private static JTable historyTable;
|
|
|
|
private static AbstractTableModel historyTableModel;
|
2014-03-08 21:22:49 +01:00
|
|
|
private static JButton historyButtonRemove,
|
|
|
|
historyButtonClear,
|
|
|
|
historyButtonRerip;
|
2014-03-02 10:12:20 +01:00
|
|
|
|
2014-07-30 16:48:52 +02:00
|
|
|
// Queue
|
2015-12-20 20:58:37 +01:00
|
|
|
public static JButton optionQueue;
|
2014-07-30 16:48:52 +02:00
|
|
|
private static JPanel queuePanel;
|
2015-09-17 12:30:33 +02:00
|
|
|
private static DefaultListModel queueListModel;
|
2014-07-30 16:48:52 +02:00
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
// Configuration
|
|
|
|
private static JButton optionConfiguration;
|
|
|
|
private static JPanel configurationPanel;
|
2014-04-05 10:39:10 +02:00
|
|
|
private static JButton configUpdateButton;
|
|
|
|
private static JLabel configUpdateLabel;
|
2014-04-06 01:57:54 +02:00
|
|
|
private static JTextField configTimeoutText;
|
|
|
|
private static JTextField configThreadsText;
|
|
|
|
private static JCheckBox configOverwriteCheckbox;
|
2014-04-06 11:41:04 +02:00
|
|
|
private static JLabel configSaveDirLabel;
|
|
|
|
private static JButton configSaveDirButton;
|
|
|
|
private static JTextField configRetriesText;
|
2014-04-07 08:11:37 +02:00
|
|
|
private static JCheckBox configAutoupdateCheckbox;
|
2015-09-17 12:30:33 +02:00
|
|
|
private static JComboBox configLogLevelCombobox;
|
2014-05-11 09:38:15 +02:00
|
|
|
private static JCheckBox configPlaySound;
|
2014-05-26 09:31:58 +02:00
|
|
|
private static JCheckBox configSaveOrderCheckbox;
|
2014-06-02 05:00:19 +02:00
|
|
|
private static JCheckBox configShowPopup;
|
2014-06-12 07:21:09 +02:00
|
|
|
private static JCheckBox configSaveLogs;
|
2014-06-28 18:47:46 +02:00
|
|
|
private static JCheckBox configSaveURLsOnly;
|
2014-07-25 09:48:52 +02:00
|
|
|
private static JCheckBox configSaveAlbumTitles;
|
2014-08-02 18:24:07 +02:00
|
|
|
private static JCheckBox configClipboardAutorip;
|
2015-12-21 16:36:56 +01:00
|
|
|
private static JCheckBox configSaveDescriptions;
|
2015-12-24 22:40:04 +01:00
|
|
|
private static JCheckBox configPreferMp4;
|
2016-10-01 22:20:55 +02:00
|
|
|
private static JCheckBox configWindowPosition;
|
2014-04-06 11:41:04 +02:00
|
|
|
|
2014-04-08 06:57:18 +02:00
|
|
|
private static TrayIcon trayIcon;
|
2014-04-07 08:11:37 +02:00
|
|
|
private static MenuItem trayMenuMain;
|
2014-04-07 02:26:30 +02:00
|
|
|
private static CheckboxMenuItem trayMenuAutorip;
|
|
|
|
|
|
|
|
private static Image mainIcon;
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-04-18 06:43:34 +02:00
|
|
|
private static AbstractRipper ripper;
|
2014-04-07 02:26:30 +02:00
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
public MainWindow() {
|
2014-04-06 12:27:30 +02:00
|
|
|
mainFrame = new JFrame("RipMe v" + UpdateUtils.getThisJarVersion());
|
2014-03-01 11:13:32 +01:00
|
|
|
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
2014-03-02 08:28:37 +01:00
|
|
|
mainFrame.setLayout(new GridBagLayout());
|
|
|
|
|
|
|
|
createUI(mainFrame.getContentPane());
|
2017-10-25 22:31:02 +02:00
|
|
|
pack();
|
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
loadHistory();
|
2014-03-02 08:28:37 +01:00
|
|
|
setupHandlers();
|
2016-10-01 22:20:55 +02:00
|
|
|
|
2017-10-25 22:31:02 +02:00
|
|
|
Thread shutdownThread = new Thread(this::shutdownCleanup);
|
2014-04-06 11:41:04 +02:00
|
|
|
Runtime.getRuntime().addShutdownHook(shutdownThread);
|
2014-04-07 08:11:37 +02:00
|
|
|
|
|
|
|
if (Utils.getConfigBoolean("auto.update", true)) {
|
|
|
|
upgradeProgram();
|
|
|
|
}
|
|
|
|
|
2014-08-01 19:31:23 +02:00
|
|
|
boolean autoripEnabled = Utils.getConfigBoolean("clipboard.autorip", false);
|
|
|
|
ClipboardUtils.setClipboardAutoRip(autoripEnabled);
|
|
|
|
trayMenuAutorip.setState(autoripEnabled);
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
private void upgradeProgram() {
|
2014-04-07 08:11:37 +02:00
|
|
|
if (!configurationPanel.isVisible()) {
|
|
|
|
optionConfiguration.doClick();
|
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
Runnable r = () -> UpdateUtils.updateProgram(configUpdateLabel);
|
2014-04-29 15:17:49 +02:00
|
|
|
new Thread(r).start();
|
2014-04-07 08:11:37 +02:00
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
public void run() {
|
2014-06-13 05:41:45 +02:00
|
|
|
pack();
|
2016-10-01 22:20:55 +02:00
|
|
|
restoreWindowPosition(mainFrame);
|
2014-03-01 11:13:32 +01:00
|
|
|
mainFrame.setVisible(true);
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
private void shutdownCleanup() {
|
2014-04-06 11:41:04 +02:00
|
|
|
Utils.setConfigBoolean("file.overwrite", configOverwriteCheckbox.isSelected());
|
|
|
|
Utils.setConfigInteger("threads.size", Integer.parseInt(configThreadsText.getText()));
|
|
|
|
Utils.setConfigInteger("download.retries", Integer.parseInt(configRetriesText.getText()));
|
|
|
|
Utils.setConfigInteger("download.timeout", Integer.parseInt(configTimeoutText.getText()));
|
2014-04-07 02:26:30 +02:00
|
|
|
Utils.setConfigBoolean("clipboard.autorip", ClipboardUtils.getClipboardAutoRip());
|
2014-04-07 08:11:37 +02:00
|
|
|
Utils.setConfigBoolean("auto.update", configAutoupdateCheckbox.isSelected());
|
2015-02-10 08:29:29 +01:00
|
|
|
Utils.setConfigString("log.level", configLogLevelCombobox.getSelectedItem().toString());
|
2014-05-11 09:38:15 +02:00
|
|
|
Utils.setConfigBoolean("play.sound", configPlaySound.isSelected());
|
2014-05-26 09:31:58 +02:00
|
|
|
Utils.setConfigBoolean("download.save_order", configSaveOrderCheckbox.isSelected());
|
2014-06-02 05:00:19 +02:00
|
|
|
Utils.setConfigBoolean("download.show_popup", configShowPopup.isSelected());
|
2014-06-12 07:21:09 +02:00
|
|
|
Utils.setConfigBoolean("log.save", configSaveLogs.isSelected());
|
2014-06-28 18:47:46 +02:00
|
|
|
Utils.setConfigBoolean("urls_only.save", configSaveURLsOnly.isSelected());
|
2014-07-25 09:48:52 +02:00
|
|
|
Utils.setConfigBoolean("album_titles.save", configSaveAlbumTitles.isSelected());
|
2014-08-02 18:24:07 +02:00
|
|
|
Utils.setConfigBoolean("clipboard.autorip", configClipboardAutorip.isSelected());
|
2015-12-21 16:36:56 +01:00
|
|
|
Utils.setConfigBoolean("descriptions.save", configSaveDescriptions.isSelected());
|
2015-12-24 22:40:04 +01:00
|
|
|
Utils.setConfigBoolean("prefer.mp4", configPreferMp4.isSelected());
|
2016-10-01 22:20:55 +02:00
|
|
|
saveWindowPosition(mainFrame);
|
2014-04-07 02:26:30 +02:00
|
|
|
saveHistory();
|
2014-04-06 11:41:04 +02:00
|
|
|
Utils.saveConfig();
|
|
|
|
}
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-13 20:38:11 +01:00
|
|
|
private void status(String text) {
|
2014-04-04 10:08:04 +02:00
|
|
|
statusWithColor(text, Color.BLACK);
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-04-04 10:08:04 +02:00
|
|
|
private void error(String text) {
|
|
|
|
statusWithColor(text, Color.RED);
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-04-04 10:08:04 +02:00
|
|
|
private void statusWithColor(String text, Color color) {
|
|
|
|
statusLabel.setForeground(color);
|
2014-03-02 03:08:16 +01:00
|
|
|
statusLabel.setText(text);
|
2014-06-13 05:41:45 +02:00
|
|
|
pack();
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-06-13 05:41:45 +02:00
|
|
|
private void pack() {
|
2017-10-25 22:31:02 +02:00
|
|
|
SwingUtilities.invokeLater(() -> {
|
|
|
|
Dimension preferredSize = mainFrame.getPreferredSize();
|
|
|
|
mainFrame.setMinimumSize(preferredSize);
|
2017-10-31 00:47:58 +01:00
|
|
|
if (isCollapsed()) {
|
2017-10-25 22:31:02 +02:00
|
|
|
mainFrame.setSize(preferredSize);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isCollapsed() {
|
|
|
|
return (!logPanel.isVisible() &&
|
|
|
|
!historyPanel.isVisible() &&
|
|
|
|
!queuePanel.isVisible() &&
|
|
|
|
!configurationPanel.isVisible()
|
|
|
|
);
|
2014-03-02 08:28:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void createUI(Container pane) {
|
2017-10-12 10:43:07 +02:00
|
|
|
//If creating the tray icon fails, ignore it.
|
|
|
|
try {
|
|
|
|
setupTrayIcon();
|
|
|
|
} catch (Exception e) { }
|
2014-04-07 02:26:30 +02:00
|
|
|
|
2014-03-02 08:28:37 +01:00
|
|
|
EmptyBorder emptyBorder = new EmptyBorder(5, 5, 5, 5);
|
|
|
|
GridBagConstraints gbc = new GridBagConstraints();
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
|
gbc.weightx = 1; gbc.ipadx = 2; gbc.gridx = 0;
|
|
|
|
gbc.weighty = 0; gbc.ipady = 2; gbc.gridy = 0;
|
|
|
|
gbc.anchor = GridBagConstraints.PAGE_START;
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-04-06 06:54:22 +02:00
|
|
|
try {
|
|
|
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
2017-10-24 16:33:28 +02:00
|
|
|
} catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) {
|
2014-04-06 06:54:22 +02:00
|
|
|
logger.error("[!] Exception setting system theme:", e);
|
|
|
|
}
|
2014-03-02 08:28:37 +01:00
|
|
|
|
|
|
|
ripTextfield = new JTextField("", 20);
|
2014-05-26 09:43:47 +02:00
|
|
|
ripTextfield.addMouseListener(new ContextMenuMouseListener());
|
2014-04-18 07:11:37 +02:00
|
|
|
ImageIcon ripIcon = new ImageIcon(mainIcon);
|
2014-04-07 08:11:37 +02:00
|
|
|
ripButton = new JButton("<html><font size=\"5\"><b>Rip</b></font></html>", ripIcon);
|
2014-04-18 07:11:37 +02:00
|
|
|
stopButton = new JButton("<html><font size=\"5\"><b>Stop</b></font></html>");
|
2014-07-30 16:48:52 +02:00
|
|
|
stopButton.setEnabled(false);
|
2014-04-18 07:11:37 +02:00
|
|
|
try {
|
|
|
|
Image stopIcon = ImageIO.read(getClass().getClassLoader().getResource("stop.png"));
|
|
|
|
stopButton.setIcon(new ImageIcon(stopIcon));
|
2017-10-24 16:33:28 +02:00
|
|
|
} catch (Exception ignored) { }
|
2014-03-02 08:28:37 +01:00
|
|
|
JPanel ripPanel = new JPanel(new GridBagLayout());
|
|
|
|
ripPanel.setBorder(emptyBorder);
|
2017-05-09 23:54:27 +02:00
|
|
|
|
2017-10-30 23:14:10 +01:00
|
|
|
gbc.fill = GridBagConstraints.BOTH;
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.weightx = 0;
|
2017-05-09 23:54:27 +02:00
|
|
|
gbc.gridx = 0; ripPanel.add(new JLabel("URL:", JLabel.RIGHT), gbc);
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.weightx = 1;
|
2017-10-30 23:14:10 +01:00
|
|
|
gbc.weighty = 1;
|
2017-05-09 23:54:27 +02:00
|
|
|
gbc.gridx = 1; ripPanel.add(ripTextfield, gbc);
|
2017-10-30 23:14:10 +01:00
|
|
|
gbc.weighty = 0;
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.weightx = 0;
|
2017-05-09 23:54:27 +02:00
|
|
|
gbc.gridx = 2; ripPanel.add(ripButton, gbc);
|
|
|
|
gbc.gridx = 3; ripPanel.add(stopButton, gbc);
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.weightx = 1;
|
2017-05-09 23:54:27 +02:00
|
|
|
|
2017-10-25 22:31:02 +02:00
|
|
|
statusLabel = new JLabel("Inactive");
|
2014-03-02 10:12:20 +01:00
|
|
|
statusLabel.setHorizontalAlignment(JLabel.CENTER);
|
2014-03-02 08:28:37 +01:00
|
|
|
openButton = new JButton();
|
|
|
|
openButton.setVisible(false);
|
|
|
|
JPanel statusPanel = new JPanel(new GridBagLayout());
|
|
|
|
statusPanel.setBorder(emptyBorder);
|
2014-03-02 10:12:20 +01:00
|
|
|
|
2014-04-08 04:48:53 +02:00
|
|
|
gbc.gridx = 0; statusPanel.add(statusLabel, gbc);
|
|
|
|
gbc.gridy = 1; statusPanel.add(openButton, gbc);
|
2014-04-08 06:57:18 +02:00
|
|
|
gbc.gridy = 0;
|
2014-03-02 08:28:37 +01:00
|
|
|
|
|
|
|
JPanel progressPanel = new JPanel(new GridBagLayout());
|
|
|
|
progressPanel.setBorder(emptyBorder);
|
2017-10-25 22:31:02 +02:00
|
|
|
statusProgress = new JProgressBar(0, 100);
|
2014-03-02 08:28:37 +01:00
|
|
|
progressPanel.add(statusProgress, gbc);
|
2014-03-02 10:12:20 +01:00
|
|
|
|
|
|
|
JPanel optionsPanel = new JPanel(new GridBagLayout());
|
|
|
|
optionsPanel.setBorder(emptyBorder);
|
|
|
|
optionLog = new JButton("Log");
|
|
|
|
optionHistory = new JButton("History");
|
2014-07-30 16:48:52 +02:00
|
|
|
optionQueue = new JButton("Queue");
|
2014-03-02 10:12:20 +01:00
|
|
|
optionConfiguration = new JButton("Configuration");
|
2017-10-25 22:31:02 +02:00
|
|
|
optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
2014-04-18 06:43:34 +02:00
|
|
|
try {
|
|
|
|
Image icon;
|
|
|
|
icon = ImageIO.read(getClass().getClassLoader().getResource("comment.png"));
|
|
|
|
optionLog.setIcon(new ImageIcon(icon));
|
|
|
|
icon = ImageIO.read(getClass().getClassLoader().getResource("time.png"));
|
|
|
|
optionHistory.setIcon(new ImageIcon(icon));
|
2014-07-30 16:48:52 +02:00
|
|
|
icon = ImageIO.read(getClass().getClassLoader().getResource("list.png"));
|
|
|
|
optionQueue.setIcon(new ImageIcon(icon));
|
2014-04-18 06:43:34 +02:00
|
|
|
icon = ImageIO.read(getClass().getClassLoader().getResource("gear.png"));
|
|
|
|
optionConfiguration.setIcon(new ImageIcon(icon));
|
|
|
|
} catch (Exception e) { }
|
2014-03-08 21:22:49 +01:00
|
|
|
gbc.gridx = 0; optionsPanel.add(optionLog, gbc);
|
|
|
|
gbc.gridx = 1; optionsPanel.add(optionHistory, gbc);
|
2014-07-30 16:48:52 +02:00
|
|
|
gbc.gridx = 2; optionsPanel.add(optionQueue, gbc);
|
|
|
|
gbc.gridx = 3; optionsPanel.add(optionConfiguration, gbc);
|
2014-03-02 10:12:20 +01:00
|
|
|
|
|
|
|
logPanel = new JPanel(new GridBagLayout());
|
2014-03-02 08:28:37 +01:00
|
|
|
logPanel.setBorder(emptyBorder);
|
2017-10-25 22:31:02 +02:00
|
|
|
logText = new JTextPane();
|
|
|
|
logText.setEditable(false);
|
2017-10-24 16:33:28 +02:00
|
|
|
JScrollPane logTextScroll = new JScrollPane(logText);
|
2017-10-25 22:31:02 +02:00
|
|
|
logTextScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
2014-03-02 10:12:20 +01:00
|
|
|
logPanel.setVisible(false);
|
2014-03-11 09:29:26 +01:00
|
|
|
logPanel.setPreferredSize(new Dimension(300, 250));
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.fill = GridBagConstraints.BOTH;
|
|
|
|
gbc.weighty = 1;
|
2014-03-02 10:12:20 +01:00
|
|
|
logPanel.add(logTextScroll, gbc);
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
|
gbc.weighty = 0;
|
2014-03-08 20:27:30 +01:00
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
historyPanel = new JPanel(new GridBagLayout());
|
|
|
|
historyPanel.setBorder(emptyBorder);
|
|
|
|
historyPanel.setVisible(false);
|
2014-03-11 09:29:26 +01:00
|
|
|
historyPanel.setPreferredSize(new Dimension(300, 250));
|
2015-01-11 13:31:30 +01:00
|
|
|
historyTableModel = new AbstractTableModel() {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
@Override
|
|
|
|
public String getColumnName(int col) {
|
|
|
|
return HISTORY.getColumnName(col);
|
|
|
|
}
|
2017-05-09 23:02:24 +02:00
|
|
|
@Override
|
2017-10-24 16:33:28 +02:00
|
|
|
public Class<?> getColumnClass(int c) {
|
2015-01-11 13:31:30 +01:00
|
|
|
return getValueAt(0, c).getClass();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public Object getValueAt(int row, int col) {
|
|
|
|
return HISTORY.getValueAt(row, col);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public int getRowCount() {
|
|
|
|
return HISTORY.toList().size();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public int getColumnCount() {
|
|
|
|
return HISTORY.getColumnCount();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public boolean isCellEditable(int row, int col) {
|
|
|
|
return (col == 0 || col == 4);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void setValueAt(Object value, int row, int col) {
|
|
|
|
if (col == 4) {
|
|
|
|
HISTORY.get(row).selected = (Boolean) value;
|
|
|
|
historyTableModel.fireTableDataChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
historyTable = new JTable(historyTableModel);
|
2015-01-13 10:23:16 +01:00
|
|
|
historyTable.addMouseListener(new HistoryMenuMouseListener());
|
2015-01-11 13:31:30 +01:00
|
|
|
historyTable.setAutoCreateRowSorter(true);
|
|
|
|
for (int i = 0; i < historyTable.getColumnModel().getColumnCount(); i++) {
|
|
|
|
int width = 130; // Default
|
|
|
|
switch (i) {
|
|
|
|
case 0: // URL
|
|
|
|
width = 270;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
width = 40;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
width = 15;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
historyTable.getColumnModel().getColumn(i).setPreferredWidth(width);
|
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
JScrollPane historyTableScrollPane = new JScrollPane(historyTable);
|
2014-03-08 21:22:49 +01:00
|
|
|
historyButtonRemove = new JButton("Remove");
|
|
|
|
historyButtonClear = new JButton("Clear");
|
2015-01-11 13:31:30 +01:00
|
|
|
historyButtonRerip = new JButton("Re-rip Checked");
|
2014-03-08 21:22:49 +01:00
|
|
|
gbc.gridx = 0;
|
2015-01-11 13:31:30 +01:00
|
|
|
// History List Panel
|
|
|
|
JPanel historyTablePanel = new JPanel(new GridBagLayout());
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.fill = GridBagConstraints.BOTH;
|
|
|
|
gbc.weighty = 1;
|
2015-01-11 13:31:30 +01:00
|
|
|
historyTablePanel.add(historyTableScrollPane, gbc);
|
2014-07-30 16:48:52 +02:00
|
|
|
gbc.ipady = 180;
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.gridy = 0;
|
2015-01-11 13:31:30 +01:00
|
|
|
historyPanel.add(historyTablePanel, gbc);
|
2014-04-04 10:08:04 +02:00
|
|
|
gbc.ipady = 0;
|
2017-10-24 16:33:28 +02:00
|
|
|
JPanel historyButtonPanel = new JPanel(new GridBagLayout());
|
2014-03-11 09:29:26 +01:00
|
|
|
historyButtonPanel.setPreferredSize(new Dimension(300, 10));
|
2014-03-08 21:22:49 +01:00
|
|
|
historyButtonPanel.setBorder(emptyBorder);
|
|
|
|
gbc.gridx = 0; historyButtonPanel.add(historyButtonRemove, gbc);
|
|
|
|
gbc.gridx = 1; historyButtonPanel.add(historyButtonClear, gbc);
|
|
|
|
gbc.gridx = 2; historyButtonPanel.add(historyButtonRerip, gbc);
|
|
|
|
gbc.gridy = 1; gbc.gridx = 0;
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.weighty = 0;
|
|
|
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
2014-03-08 21:22:49 +01:00
|
|
|
historyPanel.add(historyButtonPanel, gbc);
|
2014-04-05 10:39:10 +02:00
|
|
|
|
2014-07-30 16:48:52 +02:00
|
|
|
queuePanel = new JPanel(new GridBagLayout());
|
|
|
|
queuePanel.setBorder(emptyBorder);
|
|
|
|
queuePanel.setVisible(false);
|
|
|
|
queuePanel.setPreferredSize(new Dimension(300, 250));
|
2015-09-17 12:30:33 +02:00
|
|
|
queueListModel = new DefaultListModel();
|
2017-10-24 16:33:28 +02:00
|
|
|
JList queueList = new JList(queueListModel);
|
2014-07-30 16:48:52 +02:00
|
|
|
queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
2015-12-20 20:58:37 +01:00
|
|
|
queueList.addMouseListener(new QueueMenuMouseListener());
|
2017-10-24 16:33:28 +02:00
|
|
|
JScrollPane queueListScroll = new JScrollPane(queueList,
|
2014-07-30 16:48:52 +02:00
|
|
|
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
|
|
|
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
2015-09-17 12:11:50 +02:00
|
|
|
for (String item : Utils.getConfigList("queue")) {
|
|
|
|
queueListModel.addElement(item);
|
|
|
|
}
|
|
|
|
if (queueListModel.size() > 0) {
|
|
|
|
optionQueue.setText("Queue (" + queueListModel.size() + ")");
|
|
|
|
} else {
|
|
|
|
optionQueue.setText("Queue");
|
|
|
|
}
|
2014-07-30 16:48:52 +02:00
|
|
|
gbc.gridx = 0;
|
|
|
|
JPanel queueListPanel = new JPanel(new GridBagLayout());
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.fill = GridBagConstraints.BOTH;
|
|
|
|
gbc.weighty = 1;
|
2014-07-30 16:48:52 +02:00
|
|
|
queueListPanel.add(queueListScroll, gbc);
|
|
|
|
queuePanel.add(queueListPanel, gbc);
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
|
gbc.weighty = 0;
|
2014-07-30 16:48:52 +02:00
|
|
|
gbc.ipady = 0;
|
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
configurationPanel = new JPanel(new GridBagLayout());
|
|
|
|
configurationPanel.setBorder(emptyBorder);
|
|
|
|
configurationPanel.setVisible(false);
|
|
|
|
// TODO Configuration components
|
2014-04-05 10:39:10 +02:00
|
|
|
configUpdateButton = new JButton("Check for updates");
|
2014-04-06 01:57:54 +02:00
|
|
|
configUpdateLabel = new JLabel("Current version: " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT);
|
|
|
|
JLabel configThreadsLabel = new JLabel("Maximum download threads:", JLabel.RIGHT);
|
2014-04-06 11:41:04 +02:00
|
|
|
JLabel configTimeoutLabel = new JLabel("Timeout (in milliseconds):", JLabel.RIGHT);
|
|
|
|
JLabel configRetriesLabel = new JLabel("Retry download count:", JLabel.RIGHT);
|
2014-04-06 01:57:54 +02:00
|
|
|
configThreadsText = new JTextField(Integer.toString(Utils.getConfigInteger("threads.size", 3)));
|
2014-04-06 11:41:04 +02:00
|
|
|
configTimeoutText = new JTextField(Integer.toString(Utils.getConfigInteger("download.timeout", 60000)));
|
|
|
|
configRetriesText = new JTextField(Integer.toString(Utils.getConfigInteger("download.retries", 3)));
|
2014-04-06 01:57:54 +02:00
|
|
|
configOverwriteCheckbox = new JCheckBox("Overwrite existing files?", Utils.getConfigBoolean("file.overwrite", false));
|
|
|
|
configOverwriteCheckbox.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configOverwriteCheckbox.setHorizontalTextPosition(JCheckBox.LEFT);
|
2014-04-07 08:11:37 +02:00
|
|
|
configAutoupdateCheckbox = new JCheckBox("Auto-update?", Utils.getConfigBoolean("auto.update", true));
|
|
|
|
configAutoupdateCheckbox.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configAutoupdateCheckbox.setHorizontalTextPosition(JCheckBox.LEFT);
|
2015-09-17 12:30:33 +02:00
|
|
|
configLogLevelCombobox = new JComboBox(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"});
|
2015-02-10 08:29:29 +01:00
|
|
|
configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug"));
|
|
|
|
setLogLevel(configLogLevelCombobox.getSelectedItem().toString());
|
2014-05-11 09:38:15 +02:00
|
|
|
configPlaySound = new JCheckBox("Sound when rip completes", Utils.getConfigBoolean("play.sound", false));
|
|
|
|
configPlaySound.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configPlaySound.setHorizontalTextPosition(JCheckBox.LEFT);
|
2014-06-12 07:21:09 +02:00
|
|
|
configSaveOrderCheckbox = new JCheckBox("Preserve order", Utils.getConfigBoolean("download.save_order", true));
|
2014-05-26 09:31:58 +02:00
|
|
|
configSaveOrderCheckbox.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configSaveOrderCheckbox.setHorizontalTextPosition(JCheckBox.LEFT);
|
2014-06-02 05:00:19 +02:00
|
|
|
configShowPopup = new JCheckBox("Notification when rip starts", Utils.getConfigBoolean("download.show_popup", false));
|
|
|
|
configShowPopup.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configShowPopup.setHorizontalTextPosition(JCheckBox.LEFT);
|
2014-06-12 07:21:09 +02:00
|
|
|
configSaveLogs = new JCheckBox("Save logs", Utils.getConfigBoolean("log.save", false));
|
|
|
|
configSaveLogs.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configSaveLogs.setHorizontalTextPosition(JCheckBox.LEFT);
|
2014-06-28 18:47:46 +02:00
|
|
|
configSaveURLsOnly = new JCheckBox("Save URLs only", Utils.getConfigBoolean("urls_only.save", false));
|
|
|
|
configSaveURLsOnly.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configSaveURLsOnly.setHorizontalTextPosition(JCheckBox.LEFT);
|
2014-07-25 09:48:52 +02:00
|
|
|
configSaveAlbumTitles = new JCheckBox("Save album titles", Utils.getConfigBoolean("album_titles.save", true));
|
|
|
|
configSaveAlbumTitles.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configSaveAlbumTitles.setHorizontalTextPosition(JCheckBox.LEFT);
|
2014-08-02 18:24:07 +02:00
|
|
|
configClipboardAutorip = new JCheckBox("Autorip from Clipboard", Utils.getConfigBoolean("clipboard.autorip", false));
|
|
|
|
configClipboardAutorip.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configClipboardAutorip.setHorizontalTextPosition(JCheckBox.LEFT);
|
2015-12-21 16:36:56 +01:00
|
|
|
configSaveDescriptions = new JCheckBox("Save descriptions", Utils.getConfigBoolean("descriptions.save", true));
|
|
|
|
configSaveDescriptions.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configSaveDescriptions.setHorizontalTextPosition(JCheckBox.LEFT);
|
2015-12-24 22:40:04 +01:00
|
|
|
configPreferMp4 = new JCheckBox("Prefer MP4 over GIF", Utils.getConfigBoolean("prefer.mp4", false));
|
|
|
|
configPreferMp4.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configPreferMp4.setHorizontalTextPosition(JCheckBox.LEFT);
|
2016-10-01 22:20:55 +02:00
|
|
|
configWindowPosition = new JCheckBox("Restore window position", Utils.getConfigBoolean("window.position", true));
|
|
|
|
configWindowPosition.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configWindowPosition.setHorizontalTextPosition(JCheckBox.LEFT);
|
2014-04-06 11:41:04 +02:00
|
|
|
configSaveDirLabel = new JLabel();
|
|
|
|
try {
|
|
|
|
String workingDir = (Utils.shortenPath(Utils.getWorkingDirectory()));
|
|
|
|
configSaveDirLabel.setText(workingDir);
|
2016-12-21 04:46:42 +01:00
|
|
|
configSaveDirLabel.setForeground(Color.BLUE);
|
|
|
|
configSaveDirLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
2014-04-06 11:41:04 +02:00
|
|
|
} catch (Exception e) { }
|
|
|
|
configSaveDirLabel.setToolTipText(configSaveDirLabel.getText());
|
|
|
|
configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT);
|
2014-07-30 16:48:52 +02:00
|
|
|
configSaveDirButton = new JButton("Select Save Directory...");
|
2014-04-06 01:57:54 +02:00
|
|
|
gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc);
|
|
|
|
gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc);
|
2014-04-07 08:11:37 +02:00
|
|
|
gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configAutoupdateCheckbox, gbc);
|
2015-02-10 08:29:29 +01:00
|
|
|
gbc.gridx = 1; configurationPanel.add(configLogLevelCombobox, gbc);
|
2014-04-07 08:11:37 +02:00
|
|
|
gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc);
|
2014-04-06 01:57:54 +02:00
|
|
|
gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc);
|
2014-04-07 08:11:37 +02:00
|
|
|
gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc);
|
2014-04-06 11:41:04 +02:00
|
|
|
gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc);
|
2014-04-07 08:11:37 +02:00
|
|
|
gbc.gridy = 4; gbc.gridx = 0; configurationPanel.add(configRetriesLabel, gbc);
|
2014-04-06 11:41:04 +02:00
|
|
|
gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc);
|
2014-04-07 08:11:37 +02:00
|
|
|
gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc);
|
2014-06-12 07:21:09 +02:00
|
|
|
gbc.gridx = 1; configurationPanel.add(configSaveOrderCheckbox, gbc);
|
2014-05-11 09:38:15 +02:00
|
|
|
gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc);
|
2014-06-12 07:21:09 +02:00
|
|
|
gbc.gridx = 1; configurationPanel.add(configSaveLogs, gbc);
|
|
|
|
gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configShowPopup, gbc);
|
2014-06-28 18:47:46 +02:00
|
|
|
gbc.gridx = 1; configurationPanel.add(configSaveURLsOnly, gbc);
|
2014-08-02 18:24:07 +02:00
|
|
|
gbc.gridy = 8; gbc.gridx = 0; configurationPanel.add(configClipboardAutorip, gbc);
|
|
|
|
gbc.gridx = 1; configurationPanel.add(configSaveAlbumTitles, gbc);
|
2015-12-21 16:36:56 +01:00
|
|
|
gbc.gridy = 9; gbc.gridx = 0; configurationPanel.add(configSaveDescriptions, gbc);
|
2015-12-24 22:40:04 +01:00
|
|
|
gbc.gridx = 1; configurationPanel.add(configPreferMp4, gbc);
|
2016-10-01 22:20:55 +02:00
|
|
|
gbc.gridy = 10; gbc.gridx = 0; configurationPanel.add(configWindowPosition, gbc);
|
|
|
|
gbc.gridy = 11; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
|
|
|
|
gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc);
|
2014-04-06 01:57:54 +02:00
|
|
|
|
2017-10-31 00:47:58 +01:00
|
|
|
emptyPanel = new JPanel();
|
2017-10-30 23:26:34 +01:00
|
|
|
emptyPanel.setPreferredSize(new Dimension(0, 0));
|
|
|
|
emptyPanel.setSize(0, 0);
|
|
|
|
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.anchor = GridBagConstraints.PAGE_START;
|
2014-03-08 21:22:49 +01:00
|
|
|
gbc.gridy = 0; pane.add(ripPanel, gbc);
|
|
|
|
gbc.gridy = 1; pane.add(statusPanel, gbc);
|
|
|
|
gbc.gridy = 2; pane.add(progressPanel, gbc);
|
|
|
|
gbc.gridy = 3; pane.add(optionsPanel, gbc);
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.weighty = 1;
|
|
|
|
gbc.fill = GridBagConstraints.BOTH;
|
2014-03-08 21:22:49 +01:00
|
|
|
gbc.gridy = 4; pane.add(logPanel, gbc);
|
|
|
|
gbc.gridy = 5; pane.add(historyPanel, gbc);
|
2014-07-30 16:48:52 +02:00
|
|
|
gbc.gridy = 5; pane.add(queuePanel, gbc);
|
2014-03-08 21:22:49 +01:00
|
|
|
gbc.gridy = 5; pane.add(configurationPanel, gbc);
|
2017-10-31 00:47:58 +01:00
|
|
|
gbc.gridy = 5; pane.add(emptyPanel, gbc);
|
2017-10-25 22:31:02 +02:00
|
|
|
gbc.weighty = 0;
|
|
|
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
2014-03-02 08:28:37 +01:00
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-03-02 08:28:37 +01:00
|
|
|
private void setupHandlers() {
|
|
|
|
ripButton.addActionListener(new RipButtonHandler());
|
2014-04-04 10:08:04 +02:00
|
|
|
ripTextfield.addActionListener(new RipButtonHandler());
|
2014-06-08 04:54:36 +02:00
|
|
|
ripTextfield.getDocument().addDocumentListener(new DocumentListener() {
|
|
|
|
@Override
|
|
|
|
public void removeUpdate(DocumentEvent e) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void insertUpdate(DocumentEvent e) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void changedUpdate(DocumentEvent e) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
private void update() {
|
|
|
|
try {
|
2014-06-11 05:22:28 +02:00
|
|
|
String urlText = ripTextfield.getText().trim();
|
2014-10-21 12:03:29 +02:00
|
|
|
if (urlText.equals("")) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-12 08:01:16 +02:00
|
|
|
if (!urlText.startsWith("http")) {
|
2014-06-08 04:54:36 +02:00
|
|
|
urlText = "http://" + urlText;
|
|
|
|
}
|
|
|
|
URL url = new URL(urlText);
|
|
|
|
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
|
|
|
statusWithColor(ripper.getHost() + " album detected", Color.GREEN);
|
|
|
|
} catch (Exception e) {
|
2017-10-25 22:31:02 +02:00
|
|
|
statusWithColor("Can't rip this URL: " + e.getMessage(), Color.RED);
|
2014-06-08 04:54:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
stopButton.addActionListener(event -> {
|
|
|
|
if (ripper != null) {
|
|
|
|
ripper.stop();
|
|
|
|
isRipping = false;
|
|
|
|
stopButton.setEnabled(false);
|
|
|
|
statusProgress.setValue(0);
|
|
|
|
statusProgress.setVisible(false);
|
2014-06-13 05:41:45 +02:00
|
|
|
pack();
|
2017-10-24 16:33:28 +02:00
|
|
|
statusProgress.setValue(0);
|
|
|
|
status("Ripping interrupted");
|
|
|
|
appendLog("Ripper interrupted", Color.RED);
|
2014-03-02 10:12:20 +01:00
|
|
|
}
|
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
optionLog.addActionListener(event -> {
|
|
|
|
logPanel.setVisible(!logPanel.isVisible());
|
2017-10-31 00:47:58 +01:00
|
|
|
emptyPanel.setVisible(!logPanel.isVisible());
|
2017-10-24 16:33:28 +02:00
|
|
|
historyPanel.setVisible(false);
|
|
|
|
queuePanel.setVisible(false);
|
|
|
|
configurationPanel.setVisible(false);
|
2017-10-25 22:31:02 +02:00
|
|
|
if (logPanel.isVisible()) {
|
|
|
|
optionLog.setFont(optionLog.getFont().deriveFont(Font.BOLD));
|
|
|
|
} else {
|
|
|
|
optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
pack();
|
2014-07-30 16:48:52 +02:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
optionHistory.addActionListener(event -> {
|
|
|
|
logPanel.setVisible(false);
|
|
|
|
historyPanel.setVisible(!historyPanel.isVisible());
|
2017-10-31 00:47:58 +01:00
|
|
|
emptyPanel.setVisible(!historyPanel.isVisible());
|
2017-10-24 16:33:28 +02:00
|
|
|
queuePanel.setVisible(false);
|
|
|
|
configurationPanel.setVisible(false);
|
|
|
|
optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
2017-10-25 22:31:02 +02:00
|
|
|
if (historyPanel.isVisible()) {
|
|
|
|
optionHistory.setFont(optionLog.getFont().deriveFont(Font.BOLD));
|
|
|
|
} else {
|
|
|
|
optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
pack();
|
2014-03-02 10:12:20 +01:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
optionQueue.addActionListener(event -> {
|
|
|
|
logPanel.setVisible(false);
|
|
|
|
historyPanel.setVisible(false);
|
|
|
|
queuePanel.setVisible(!queuePanel.isVisible());
|
2017-10-31 00:47:58 +01:00
|
|
|
emptyPanel.setVisible(!queuePanel.isVisible());
|
2017-10-24 16:33:28 +02:00
|
|
|
configurationPanel.setVisible(false);
|
|
|
|
optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
2017-10-25 22:31:02 +02:00
|
|
|
if (queuePanel.isVisible()) {
|
|
|
|
optionQueue.setFont(optionLog.getFont().deriveFont(Font.BOLD));
|
|
|
|
} else {
|
|
|
|
optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
pack();
|
2014-03-02 10:12:20 +01:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
optionConfiguration.addActionListener(event -> {
|
|
|
|
logPanel.setVisible(false);
|
|
|
|
historyPanel.setVisible(false);
|
|
|
|
queuePanel.setVisible(false);
|
|
|
|
configurationPanel.setVisible(!configurationPanel.isVisible());
|
2017-10-31 00:47:58 +01:00
|
|
|
emptyPanel.setVisible(!configurationPanel.isVisible());
|
2017-10-24 16:33:28 +02:00
|
|
|
optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
2017-10-25 22:31:02 +02:00
|
|
|
if (configurationPanel.isVisible()) {
|
|
|
|
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.BOLD));
|
|
|
|
} else {
|
|
|
|
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
|
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
pack();
|
2014-03-09 08:59:36 +01:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
historyButtonRemove.addActionListener(event -> {
|
|
|
|
int[] indices = historyTable.getSelectedRows();
|
|
|
|
for (int i = indices.length - 1; i >= 0; i--) {
|
|
|
|
int modelIndex = historyTable.convertRowIndexToModel(indices[i]);
|
|
|
|
HISTORY.remove(modelIndex);
|
2014-03-09 08:59:36 +01:00
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
try {
|
|
|
|
historyTableModel.fireTableDataChanged();
|
|
|
|
} catch (Exception e) { }
|
|
|
|
saveHistory();
|
|
|
|
});
|
|
|
|
historyButtonClear.addActionListener(event -> {
|
|
|
|
HISTORY.clear();
|
|
|
|
try {
|
|
|
|
historyTableModel.fireTableDataChanged();
|
|
|
|
} catch (Exception e) { }
|
|
|
|
saveHistory();
|
2014-03-09 08:59:36 +01:00
|
|
|
});
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-03-09 08:59:36 +01:00
|
|
|
// Re-rip all history
|
2017-10-24 16:33:28 +02:00
|
|
|
historyButtonRerip.addActionListener(event -> {
|
|
|
|
if (HISTORY.isEmpty()) {
|
|
|
|
JOptionPane.showMessageDialog(null,
|
2017-10-25 22:31:02 +02:00
|
|
|
"There are no history entries to re-rip. Rip some albums first",
|
|
|
|
"RipMe Error",
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
2017-10-24 16:33:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int added = 0;
|
|
|
|
for (HistoryEntry entry : HISTORY.toList()) {
|
|
|
|
if (entry.selected) {
|
|
|
|
added++;
|
|
|
|
queueListModel.addElement(entry.url);
|
2014-08-01 19:20:42 +02:00
|
|
|
}
|
2014-03-09 08:59:36 +01:00
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
if (added == 0) {
|
|
|
|
JOptionPane.showMessageDialog(null,
|
2017-10-25 22:31:02 +02:00
|
|
|
"No history entries have been 'Checked'\n" +
|
|
|
|
"Check an entry by clicking the checkbox to the right of the URL or Right-click a URL to check/uncheck all items",
|
|
|
|
"RipMe Error",
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
2014-04-05 10:39:10 +02:00
|
|
|
}
|
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configUpdateButton.addActionListener(arg0 -> {
|
|
|
|
Thread t = new Thread(() -> UpdateUtils.updateProgram(configUpdateLabel));
|
|
|
|
t.start();
|
|
|
|
});
|
|
|
|
configLogLevelCombobox.addActionListener(arg0 -> {
|
|
|
|
String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString();
|
|
|
|
setLogLevel(level);
|
2015-02-10 08:29:29 +01:00
|
|
|
});
|
2016-12-21 04:46:42 +01:00
|
|
|
configSaveDirLabel.addMouseListener(new MouseAdapter() {
|
|
|
|
@Override
|
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
File file = new File(Utils.getWorkingDirectory().toString());
|
|
|
|
Desktop desktop = Desktop.getDesktop();
|
|
|
|
try {
|
|
|
|
desktop.open(file);
|
|
|
|
} catch (Exception e1) { }
|
|
|
|
}
|
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configSaveDirButton.addActionListener(arg0 -> {
|
|
|
|
UIManager.put("FileChooser.useSystemExtensionHiding", false);
|
|
|
|
JFileChooser jfc = new JFileChooser(Utils.getWorkingDirectory());
|
|
|
|
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
|
|
|
int returnVal = jfc.showDialog(null, "select directory");
|
|
|
|
if (returnVal != JFileChooser.APPROVE_OPTION) {
|
|
|
|
return;
|
2014-05-26 05:10:49 +02:00
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
File chosenFile = jfc.getSelectedFile();
|
|
|
|
String chosenPath = null;
|
|
|
|
try {
|
|
|
|
chosenPath = chosenFile.getCanonicalPath();
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error while getting selected path: ", e);
|
|
|
|
return;
|
2014-05-26 09:31:58 +02:00
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
configSaveDirLabel.setText(Utils.shortenPath(chosenPath));
|
|
|
|
Utils.setConfigString("rips.directory", chosenPath);
|
2014-05-26 09:31:58 +02:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configOverwriteCheckbox.addActionListener(arg0 -> Utils.setConfigBoolean("file.overwrite", configOverwriteCheckbox.isSelected()));
|
|
|
|
configSaveOrderCheckbox.addActionListener(arg0 -> Utils.setConfigBoolean("download.save_order", configSaveOrderCheckbox.isSelected()));
|
|
|
|
configSaveLogs.addActionListener(arg0 -> {
|
|
|
|
Utils.setConfigBoolean("log.save", configSaveLogs.isSelected());
|
|
|
|
Utils.configureLogger();
|
2014-06-12 07:21:09 +02:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configSaveURLsOnly.addActionListener(arg0 -> {
|
|
|
|
Utils.setConfigBoolean("urls_only.save", configSaveURLsOnly.isSelected());
|
|
|
|
Utils.configureLogger();
|
2014-06-28 18:47:46 +02:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configSaveAlbumTitles.addActionListener(arg0 -> {
|
|
|
|
Utils.setConfigBoolean("album_titles.save", configSaveAlbumTitles.isSelected());
|
|
|
|
Utils.configureLogger();
|
2014-07-25 09:48:52 +02:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configClipboardAutorip.addActionListener(arg0 -> {
|
|
|
|
Utils.setConfigBoolean("clipboard.autorip", configClipboardAutorip.isSelected());
|
|
|
|
ClipboardUtils.setClipboardAutoRip(configClipboardAutorip.isSelected());
|
|
|
|
trayMenuAutorip.setState(configClipboardAutorip.isSelected());
|
|
|
|
Utils.configureLogger();
|
2014-08-02 18:24:07 +02:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configSaveDescriptions.addActionListener(arg0 -> {
|
|
|
|
Utils.setConfigBoolean("descriptions.save", configSaveDescriptions.isSelected());
|
|
|
|
Utils.configureLogger();
|
2015-12-21 16:36:56 +01:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configPreferMp4.addActionListener(arg0 -> {
|
|
|
|
Utils.setConfigBoolean("prefer.mp4", configPreferMp4.isSelected());
|
|
|
|
Utils.configureLogger();
|
2015-12-24 22:40:04 +01:00
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
configWindowPosition.addActionListener(arg0 -> {
|
|
|
|
Utils.setConfigBoolean("window.position", configWindowPosition.isSelected());
|
|
|
|
Utils.configureLogger();
|
2016-10-01 22:20:55 +02:00
|
|
|
});
|
2014-07-30 16:48:52 +02:00
|
|
|
queueListModel.addListDataListener(new ListDataListener() {
|
|
|
|
@Override
|
|
|
|
public void intervalAdded(ListDataEvent arg0) {
|
|
|
|
if (queueListModel.size() > 0) {
|
|
|
|
optionQueue.setText("Queue (" + queueListModel.size() + ")");
|
|
|
|
} else {
|
|
|
|
optionQueue.setText("Queue");
|
|
|
|
}
|
|
|
|
if (!isRipping) {
|
|
|
|
ripNextAlbum();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void contentsChanged(ListDataEvent arg0) { }
|
|
|
|
@Override
|
|
|
|
public void intervalRemoved(ListDataEvent arg0) { }
|
|
|
|
});
|
2014-03-02 10:12:20 +01:00
|
|
|
}
|
2016-10-01 22:20:55 +02:00
|
|
|
|
2015-02-10 08:29:29 +01:00
|
|
|
private void setLogLevel(String level) {
|
|
|
|
Level newLevel = Level.ERROR;
|
|
|
|
level = level.substring(level.lastIndexOf(' ') + 1);
|
2017-10-24 16:33:28 +02:00
|
|
|
switch (level) {
|
|
|
|
case "Debug":
|
|
|
|
newLevel = Level.DEBUG;
|
|
|
|
break;
|
|
|
|
case "Info":
|
|
|
|
newLevel = Level.INFO;
|
|
|
|
break;
|
|
|
|
case "Warn":
|
|
|
|
newLevel = Level.WARN;
|
|
|
|
break;
|
|
|
|
case "Error":
|
|
|
|
newLevel = Level.ERROR;
|
|
|
|
break;
|
2015-02-10 08:29:29 +01:00
|
|
|
}
|
|
|
|
Logger.getRootLogger().setLevel(newLevel);
|
|
|
|
logger.setLevel(newLevel);
|
2015-02-20 16:36:12 +01:00
|
|
|
ConsoleAppender ca = (ConsoleAppender)Logger.getRootLogger().getAppender("stdout");
|
|
|
|
if (ca != null) {
|
|
|
|
ca.setThreshold(newLevel);
|
|
|
|
}
|
|
|
|
FileAppender fa = (FileAppender)Logger.getRootLogger().getAppender("FILE");
|
|
|
|
if (fa != null) {
|
|
|
|
fa.setThreshold(newLevel);
|
|
|
|
}
|
2015-02-10 08:29:29 +01:00
|
|
|
}
|
2014-04-08 06:57:18 +02:00
|
|
|
|
|
|
|
private void setupTrayIcon() {
|
|
|
|
mainFrame.addWindowListener(new WindowAdapter() {
|
2017-05-09 23:02:24 +02:00
|
|
|
@Override
|
2014-04-08 06:57:18 +02:00
|
|
|
public void windowActivated(WindowEvent e) { trayMenuMain.setLabel("Hide"); }
|
2017-05-09 23:02:24 +02:00
|
|
|
@Override
|
2014-04-08 06:57:18 +02:00
|
|
|
public void windowDeactivated(WindowEvent e) { trayMenuMain.setLabel("Show"); }
|
2017-05-09 23:02:24 +02:00
|
|
|
@Override
|
2014-04-08 06:57:18 +02:00
|
|
|
public void windowDeiconified(WindowEvent e) { trayMenuMain.setLabel("Hide"); }
|
2017-05-09 23:02:24 +02:00
|
|
|
@Override
|
2014-04-08 06:57:18 +02:00
|
|
|
public void windowIconified(WindowEvent e) { trayMenuMain.setLabel("Show"); }
|
|
|
|
});
|
|
|
|
PopupMenu trayMenu = new PopupMenu();
|
|
|
|
trayMenuMain = new MenuItem("Hide");
|
2017-10-24 16:33:28 +02:00
|
|
|
trayMenuMain.addActionListener(arg0 -> toggleTrayClick());
|
|
|
|
MenuItem trayMenuAbout = new MenuItem("About " + mainFrame.getTitle());
|
|
|
|
trayMenuAbout.addActionListener(arg0 -> {
|
|
|
|
StringBuilder about = new StringBuilder();
|
|
|
|
about.append("<html><h1>")
|
|
|
|
.append(mainFrame.getTitle())
|
|
|
|
.append("</h1>");
|
|
|
|
about.append("Download albums from various websites:");
|
|
|
|
try {
|
|
|
|
List<String> rippers = Utils.getListOfAlbumRippers();
|
|
|
|
about.append("<ul>");
|
|
|
|
for (String ripper : rippers) {
|
|
|
|
about.append("<li>");
|
|
|
|
ripper = ripper.substring(ripper.lastIndexOf('.') + 1);
|
|
|
|
if (ripper.contains("Ripper")) {
|
|
|
|
ripper = ripper.substring(0, ripper.indexOf("Ripper"));
|
2014-04-27 19:09:52 +02:00
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
about.append(ripper);
|
|
|
|
about.append("</li>");
|
|
|
|
}
|
|
|
|
about.append("</ul>");
|
|
|
|
} catch (Exception e) { }
|
|
|
|
about.append("<br>And download videos from video sites:");
|
|
|
|
try {
|
|
|
|
List<String> rippers = Utils.getListOfVideoRippers();
|
|
|
|
about.append("<ul>");
|
|
|
|
for (String ripper : rippers) {
|
|
|
|
about.append("<li>");
|
|
|
|
ripper = ripper.substring(ripper.lastIndexOf('.') + 1);
|
|
|
|
if (ripper.contains("Ripper")) {
|
|
|
|
ripper = ripper.substring(0, ripper.indexOf("Ripper"));
|
2014-04-27 19:09:52 +02:00
|
|
|
}
|
2017-10-24 16:33:28 +02:00
|
|
|
about.append(ripper);
|
|
|
|
about.append("</li>");
|
|
|
|
}
|
|
|
|
about.append("</ul>");
|
|
|
|
} catch (Exception e) { }
|
|
|
|
|
|
|
|
about.append("Do you want to visit the project homepage on Github?");
|
|
|
|
about.append("</html>");
|
|
|
|
int response = JOptionPane.showConfirmDialog(null,
|
|
|
|
about.toString(),
|
|
|
|
mainFrame.getTitle(),
|
|
|
|
JOptionPane.YES_NO_OPTION,
|
|
|
|
JOptionPane.PLAIN_MESSAGE,
|
|
|
|
new ImageIcon(mainIcon));
|
|
|
|
if (response == JOptionPane.YES_OPTION) {
|
|
|
|
try {
|
|
|
|
Desktop.getDesktop().browse(URI.create("http://github.com/4pr0n/ripme"));
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.error("Exception while opening project home page", e);
|
2014-04-27 19:09:52 +02:00
|
|
|
}
|
2014-04-08 06:57:18 +02:00
|
|
|
}
|
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
MenuItem trayMenuExit = new MenuItem("Exit");
|
|
|
|
trayMenuExit.addActionListener(arg0 -> System.exit(0));
|
2014-04-08 06:57:18 +02:00
|
|
|
trayMenuAutorip = new CheckboxMenuItem("Clipboard Autorip");
|
2017-10-24 16:33:28 +02:00
|
|
|
trayMenuAutorip.addItemListener(arg0 -> {
|
|
|
|
ClipboardUtils.setClipboardAutoRip(trayMenuAutorip.getState());
|
|
|
|
configClipboardAutorip.setSelected(trayMenuAutorip.getState());
|
2014-04-08 06:57:18 +02:00
|
|
|
});
|
|
|
|
trayMenu.add(trayMenuMain);
|
|
|
|
trayMenu.add(trayMenuAbout);
|
|
|
|
trayMenu.addSeparator();
|
|
|
|
trayMenu.add(trayMenuAutorip);
|
|
|
|
trayMenu.addSeparator();
|
|
|
|
trayMenu.add(trayMenuExit);
|
|
|
|
try {
|
|
|
|
mainIcon = ImageIO.read(getClass().getClassLoader().getResource("icon.png"));
|
|
|
|
trayIcon = new TrayIcon(mainIcon);
|
|
|
|
trayIcon.setToolTip(mainFrame.getTitle());
|
|
|
|
trayIcon.setImageAutoSize(true);
|
|
|
|
trayIcon.setPopupMenu(trayMenu);
|
|
|
|
SystemTray.getSystemTray().add(trayIcon);
|
|
|
|
trayIcon.addMouseListener(new MouseAdapter() {
|
|
|
|
@Override
|
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
toggleTrayClick();
|
|
|
|
if (mainFrame.getExtendedState() != JFrame.NORMAL) {
|
|
|
|
mainFrame.setExtendedState(JFrame.NORMAL);
|
|
|
|
}
|
|
|
|
mainFrame.setAlwaysOnTop(true);
|
|
|
|
mainFrame.setAlwaysOnTop(false);
|
|
|
|
}
|
|
|
|
});
|
2017-10-24 16:33:28 +02:00
|
|
|
} catch (IOException | AWTException e) {
|
2017-05-09 23:02:24 +02:00
|
|
|
//TODO implement proper stack trace handling this is really just intented as a placeholder until you implement proper error handling
|
2014-04-08 06:57:18 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-04-08 06:57:18 +02:00
|
|
|
private void toggleTrayClick() {
|
|
|
|
if (mainFrame.getExtendedState() == JFrame.ICONIFIED
|
|
|
|
|| !mainFrame.isActive()
|
2016-12-20 05:31:08 +01:00
|
|
|
|| !mainFrame.isVisible()) {
|
2014-04-08 06:57:18 +02:00
|
|
|
mainFrame.setVisible(true);
|
|
|
|
mainFrame.setAlwaysOnTop(true);
|
|
|
|
mainFrame.setAlwaysOnTop(false);
|
|
|
|
trayMenuMain.setLabel("Hide");
|
2017-10-25 22:31:02 +02:00
|
|
|
} else {
|
2014-04-08 06:57:18 +02:00
|
|
|
mainFrame.setVisible(false);
|
|
|
|
trayMenuMain.setLabel("Show");
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
private void appendLog(final String text, final Color color) {
|
2014-03-13 20:18:35 +01:00
|
|
|
SimpleAttributeSet sas = new SimpleAttributeSet();
|
|
|
|
StyleConstants.setForeground(sas, color);
|
|
|
|
StyledDocument sd = logText.getStyledDocument();
|
|
|
|
try {
|
2014-04-22 08:04:33 +02:00
|
|
|
synchronized (this) {
|
|
|
|
sd.insertString(sd.getLength(), text + "\n", sas);
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
} catch (BadLocationException e) { }
|
|
|
|
|
|
|
|
logText.setCaretPosition(sd.getLength());
|
2014-03-08 21:22:49 +01:00
|
|
|
}
|
2014-06-28 18:47:46 +02:00
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
private void loadHistory() {
|
2017-10-15 14:21:58 +02:00
|
|
|
File historyFile = new File(Utils.getConfigDir() + File.separator + "history.json");
|
2015-01-11 13:31:30 +01:00
|
|
|
HISTORY.clear();
|
2014-07-30 16:48:52 +02:00
|
|
|
if (historyFile.exists()) {
|
|
|
|
try {
|
2017-10-15 14:21:58 +02:00
|
|
|
logger.info("Loading history from " + historyFile.getCanonicalPath());
|
|
|
|
HISTORY.fromFile(historyFile.getCanonicalPath());
|
2014-07-30 16:48:52 +02:00
|
|
|
} catch (IOException e) {
|
2015-01-11 13:31:30 +01:00
|
|
|
logger.error("Failed to load history from file " + historyFile, e);
|
2015-02-08 08:39:27 +01:00
|
|
|
JOptionPane.showMessageDialog(null,
|
|
|
|
"RipMe failed to load the history file at " + historyFile.getAbsolutePath() + "\n\n" +
|
2016-12-20 05:31:08 +01:00
|
|
|
"Error: " + e.getMessage() + "\n\n" +
|
2015-02-08 08:39:27 +01:00
|
|
|
"Closing RipMe will automatically overwrite the contents of this file,\n" +
|
|
|
|
"so you may want to back the file up before closing RipMe!",
|
|
|
|
"RipMe - history load failure",
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
2014-07-30 16:48:52 +02:00
|
|
|
}
|
2017-10-25 22:31:02 +02:00
|
|
|
} else {
|
2014-07-30 16:48:52 +02:00
|
|
|
logger.info("Loading history from configuration");
|
2015-01-11 13:31:30 +01:00
|
|
|
HISTORY.fromList(Utils.getConfigList("download.history"));
|
2015-02-10 07:18:09 +01:00
|
|
|
if (HISTORY.toList().size() == 0) {
|
|
|
|
// Loaded from config, still no entries.
|
|
|
|
// Guess rip history based on rip folder
|
2017-10-24 16:33:28 +02:00
|
|
|
String[] dirs = Utils.getWorkingDirectory().list((dir, file) -> new File(dir.getAbsolutePath() + File.separator + file).isDirectory());
|
2015-02-10 07:18:09 +01:00
|
|
|
for (String dir : dirs) {
|
|
|
|
String url = RipUtils.urlFromDirectoryName(dir);
|
|
|
|
if (url != null) {
|
|
|
|
// We found one, add it to history
|
|
|
|
HistoryEntry entry = new HistoryEntry();
|
|
|
|
entry.url = url;
|
|
|
|
HISTORY.add(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 21:22:49 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-02 10:12:20 +01:00
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
private void saveHistory() {
|
2017-10-15 14:21:58 +02:00
|
|
|
Path historyFile = Paths.get(Utils.getConfigDir() + File.separator + "history.json");
|
2014-07-30 16:48:52 +02:00
|
|
|
try {
|
2017-10-15 14:21:58 +02:00
|
|
|
if (!Files.exists(historyFile)) {
|
|
|
|
Files.createDirectories(historyFile.getParent());
|
|
|
|
Files.createFile(historyFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
HISTORY.toFile(historyFile.toString());
|
2015-02-10 07:18:09 +01:00
|
|
|
Utils.setConfigList("download.history", Collections.emptyList());
|
2014-07-30 16:48:52 +02:00
|
|
|
} catch (IOException e) {
|
2017-10-15 14:21:58 +02:00
|
|
|
logger.error("Failed to save history to file " + historyFile, e);
|
2014-07-30 16:48:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 12:11:50 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2014-07-30 16:48:52 +02:00
|
|
|
private void ripNextAlbum() {
|
|
|
|
isRipping = true;
|
2015-09-17 12:11:50 +02:00
|
|
|
// Save current state of queue to configuration.
|
|
|
|
Utils.setConfigList("queue", (Enumeration<Object>) queueListModel.elements());
|
|
|
|
|
|
|
|
if (queueListModel.isEmpty()) {
|
2014-07-30 16:48:52 +02:00
|
|
|
// End of queue
|
|
|
|
isRipping = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String nextAlbum = (String) queueListModel.remove(0);
|
2017-05-09 23:02:24 +02:00
|
|
|
if (queueListModel.isEmpty()) {
|
2014-07-30 16:48:52 +02:00
|
|
|
optionQueue.setText("Queue");
|
2017-10-25 22:31:02 +02:00
|
|
|
} else {
|
2014-07-30 16:48:52 +02:00
|
|
|
optionQueue.setText("Queue (" + queueListModel.size() + ")");
|
|
|
|
}
|
|
|
|
Thread t = ripAlbum(nextAlbum);
|
|
|
|
if (t == null) {
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (InterruptedException ie) {
|
|
|
|
logger.error("Interrupted while waiting to rip next album", ie);
|
|
|
|
}
|
|
|
|
ripNextAlbum();
|
2017-10-25 22:31:02 +02:00
|
|
|
} else {
|
2014-07-30 16:48:52 +02:00
|
|
|
t.start();
|
|
|
|
}
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 08:59:36 +01:00
|
|
|
private Thread ripAlbum(String urlString) {
|
2014-04-22 08:04:33 +02:00
|
|
|
//shutdownCleanup();
|
2014-04-08 04:48:53 +02:00
|
|
|
if (!logPanel.isVisible()) {
|
|
|
|
optionLog.doClick();
|
|
|
|
}
|
2014-05-26 09:31:58 +02:00
|
|
|
urlString = urlString.trim();
|
2014-04-04 09:38:40 +02:00
|
|
|
if (urlString.toLowerCase().startsWith("gonewild:")) {
|
|
|
|
urlString = "http://gonewild.com/user/" + urlString.substring(urlString.indexOf(':') + 1);
|
|
|
|
}
|
|
|
|
if (!urlString.startsWith("http")) {
|
|
|
|
urlString = "http://" + urlString;
|
|
|
|
}
|
2014-03-09 08:59:36 +01:00
|
|
|
URL url = null;
|
|
|
|
try {
|
|
|
|
url = new URL(urlString);
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
logger.error("[!] Could not generate URL for '" + urlString + "'", e);
|
2014-04-04 10:08:04 +02:00
|
|
|
error("Given URL is not valid, expecting http://website.com/page/...");
|
2014-03-09 08:59:36 +01:00
|
|
|
return null;
|
|
|
|
}
|
2014-07-30 16:48:52 +02:00
|
|
|
stopButton.setEnabled(true);
|
2014-03-09 08:59:36 +01:00
|
|
|
statusProgress.setValue(100);
|
|
|
|
openButton.setVisible(false);
|
|
|
|
statusLabel.setVisible(true);
|
2014-06-13 05:41:45 +02:00
|
|
|
pack();
|
2014-04-07 02:26:30 +02:00
|
|
|
boolean failed = false;
|
2014-03-09 08:59:36 +01:00
|
|
|
try {
|
2014-04-07 02:26:30 +02:00
|
|
|
ripper = AbstractRipper.getRipper(url);
|
2014-06-11 05:22:28 +02:00
|
|
|
ripper.setup();
|
2014-03-09 08:59:36 +01:00
|
|
|
} catch (Exception e) {
|
2014-04-07 02:26:30 +02:00
|
|
|
failed = true;
|
2014-06-14 08:14:24 +02:00
|
|
|
logger.error("Could not find ripper for URL " + url, e);
|
2014-07-30 16:48:52 +02:00
|
|
|
error(e.getMessage());
|
2014-04-07 02:26:30 +02:00
|
|
|
}
|
|
|
|
if (!failed) {
|
|
|
|
try {
|
2014-07-20 09:59:22 +02:00
|
|
|
mainFrame.setTitle("Ripping - RipMe v" + UpdateUtils.getThisJarVersion());
|
2014-04-07 02:26:30 +02:00
|
|
|
status("Starting rip...");
|
2017-10-24 16:33:28 +02:00
|
|
|
ripper.setObserver(this);
|
2014-04-07 02:26:30 +02:00
|
|
|
Thread t = new Thread(ripper);
|
2014-06-02 05:00:19 +02:00
|
|
|
if (configShowPopup.isSelected() &&
|
|
|
|
(!mainFrame.isVisible() || !mainFrame.isActive())) {
|
2014-04-08 06:57:18 +02:00
|
|
|
mainFrame.toFront();
|
|
|
|
mainFrame.setAlwaysOnTop(true);
|
|
|
|
trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO);
|
|
|
|
mainFrame.setAlwaysOnTop(false);
|
|
|
|
}
|
2014-04-07 02:26:30 +02:00
|
|
|
return t;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("[!] Error while ripping: " + e.getMessage(), e);
|
|
|
|
error("Unable to rip this URL: " + e.getMessage());
|
|
|
|
}
|
2014-03-09 08:59:36 +01:00
|
|
|
}
|
2014-07-30 16:48:52 +02:00
|
|
|
stopButton.setEnabled(false);
|
2014-04-07 02:26:30 +02:00
|
|
|
statusProgress.setValue(0);
|
2014-06-13 05:41:45 +02:00
|
|
|
pack();
|
2014-04-07 02:26:30 +02:00
|
|
|
return null;
|
2014-03-09 08:59:36 +01:00
|
|
|
}
|
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
class RipButtonHandler implements ActionListener {
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
2015-09-17 12:11:50 +02:00
|
|
|
if (!queueListModel.contains(ripTextfield.getText()) && !ripTextfield.getText().equals("")) {
|
2014-07-30 16:48:52 +02:00
|
|
|
queueListModel.add(queueListModel.size(), ripTextfield.getText());
|
|
|
|
ripTextfield.setText("");
|
2017-10-25 22:31:02 +02:00
|
|
|
} else {
|
2014-07-30 16:48:52 +02:00
|
|
|
if (!isRipping) {
|
|
|
|
ripNextAlbum();
|
|
|
|
}
|
|
|
|
}
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-03-13 20:18:35 +01:00
|
|
|
private class StatusEvent implements Runnable {
|
|
|
|
private final AbstractRipper ripper;
|
|
|
|
private final RipStatusMessage msg;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
StatusEvent(AbstractRipper ripper, RipStatusMessage msg) {
|
2014-03-13 20:18:35 +01:00
|
|
|
this.ripper = ripper;
|
|
|
|
this.msg = msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
handleEvent(this);
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-04-22 08:04:33 +02:00
|
|
|
private synchronized void handleEvent(StatusEvent evt) {
|
2014-04-18 07:11:37 +02:00
|
|
|
if (ripper.isStopped()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
RipStatusMessage msg = evt.msg;
|
|
|
|
|
|
|
|
int completedPercent = evt.ripper.getCompletionPercentage();
|
|
|
|
statusProgress.setValue(completedPercent);
|
2014-04-20 09:12:48 +02:00
|
|
|
statusProgress.setVisible(true);
|
2014-03-13 20:18:35 +01:00
|
|
|
status( evt.ripper.getStatusText() );
|
|
|
|
|
|
|
|
switch(msg.getStatus()) {
|
|
|
|
case LOADING_RESOURCE:
|
|
|
|
case DOWNLOAD_STARTED:
|
2015-01-11 14:11:10 +01:00
|
|
|
if (logger.isEnabledFor(Level.INFO)) {
|
2017-10-25 22:31:02 +02:00
|
|
|
appendLog("Downloading " + msg.getObject(), Color.BLACK);
|
2015-01-11 14:11:10 +01:00
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
break;
|
|
|
|
case DOWNLOAD_COMPLETE:
|
2017-10-25 22:31:02 +02:00
|
|
|
if (logger.isEnabledFor(Level.INFO)) {
|
|
|
|
appendLog("Downloaded " + msg.getObject(), Color.GREEN);
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
break;
|
|
|
|
case DOWNLOAD_ERRORED:
|
2015-01-11 14:11:10 +01:00
|
|
|
if (logger.isEnabledFor(Level.ERROR)) {
|
|
|
|
appendLog((String) msg.getObject(), Color.RED);
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
break;
|
|
|
|
case DOWNLOAD_WARN:
|
2017-10-25 22:31:02 +02:00
|
|
|
if (logger.isEnabledFor(Level.WARN)) {
|
|
|
|
appendLog((String) msg.getObject(), Color.ORANGE);
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
break;
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-05-05 07:40:53 +02:00
|
|
|
case RIP_ERRORED:
|
2015-01-11 14:11:10 +01:00
|
|
|
if (logger.isEnabledFor(Level.ERROR)) {
|
|
|
|
appendLog((String) msg.getObject(), Color.RED);
|
|
|
|
}
|
2014-07-30 16:48:52 +02:00
|
|
|
stopButton.setEnabled(false);
|
2014-05-05 07:40:53 +02:00
|
|
|
statusProgress.setValue(0);
|
|
|
|
statusProgress.setVisible(false);
|
|
|
|
openButton.setVisible(false);
|
2014-06-13 05:41:45 +02:00
|
|
|
pack();
|
2017-10-24 16:33:28 +02:00
|
|
|
statusWithColor("Error: " + msg.getObject(), Color.RED);
|
2014-05-05 07:40:53 +02:00
|
|
|
break;
|
2014-03-13 20:18:35 +01:00
|
|
|
|
|
|
|
case RIP_COMPLETE:
|
2015-01-11 09:23:43 +01:00
|
|
|
RipStatusComplete rsc = (RipStatusComplete) msg.getObject();
|
2014-08-01 19:20:42 +02:00
|
|
|
String url = ripper.getURL().toExternalForm();
|
2015-01-11 13:31:30 +01:00
|
|
|
if (HISTORY.containsURL(url)) {
|
|
|
|
// TODO update "modifiedDate" of entry in HISTORY
|
|
|
|
HistoryEntry entry = HISTORY.getEntryByURL(url);
|
|
|
|
entry.count = rsc.count;
|
|
|
|
entry.modifiedDate = new Date();
|
2017-10-25 22:31:02 +02:00
|
|
|
} else {
|
2014-08-01 19:20:42 +02:00
|
|
|
HistoryEntry entry = new HistoryEntry();
|
|
|
|
entry.url = url;
|
2015-01-11 09:23:43 +01:00
|
|
|
entry.dir = rsc.getDir();
|
|
|
|
entry.count = rsc.count;
|
2014-08-01 19:20:42 +02:00
|
|
|
try {
|
|
|
|
entry.title = ripper.getAlbumTitle(ripper.getURL());
|
|
|
|
} catch (MalformedURLException e) { }
|
2015-01-11 13:31:30 +01:00
|
|
|
HISTORY.add(entry);
|
|
|
|
historyTableModel.fireTableDataChanged();
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
2014-05-11 09:38:15 +02:00
|
|
|
if (configPlaySound.isSelected()) {
|
|
|
|
Utils.playSound("camera.wav");
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
saveHistory();
|
2014-07-30 16:48:52 +02:00
|
|
|
stopButton.setEnabled(false);
|
2014-04-08 04:48:53 +02:00
|
|
|
statusProgress.setValue(0);
|
|
|
|
statusProgress.setVisible(false);
|
2014-03-13 20:18:35 +01:00
|
|
|
openButton.setVisible(true);
|
2015-01-11 09:23:43 +01:00
|
|
|
File f = rsc.dir;
|
2014-04-06 11:41:04 +02:00
|
|
|
String prettyFile = Utils.shortenPath(f);
|
2014-03-13 20:18:35 +01:00
|
|
|
openButton.setText("Open " + prettyFile);
|
2014-07-20 09:59:22 +02:00
|
|
|
mainFrame.setTitle("RipMe v" + UpdateUtils.getThisJarVersion());
|
2014-04-18 06:43:34 +02:00
|
|
|
try {
|
|
|
|
Image folderIcon = ImageIO.read(getClass().getClassLoader().getResource("folder.png"));
|
|
|
|
openButton.setIcon(new ImageIcon(folderIcon));
|
2014-04-18 07:11:37 +02:00
|
|
|
} catch (Exception e) { }
|
2017-10-25 22:31:02 +02:00
|
|
|
appendLog("Rip complete, saved to " + f.getAbsolutePath(), Color.GREEN);
|
2014-03-13 20:18:35 +01:00
|
|
|
openButton.setActionCommand(f.toString());
|
2017-10-24 16:33:28 +02:00
|
|
|
openButton.addActionListener(event -> {
|
|
|
|
try {
|
|
|
|
Desktop.getDesktop().open(new File(event.getActionCommand()));
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error(e);
|
2014-03-13 20:18:35 +01:00
|
|
|
}
|
|
|
|
});
|
2014-06-13 05:41:45 +02:00
|
|
|
pack();
|
2014-07-30 16:48:52 +02:00
|
|
|
ripNextAlbum();
|
2014-04-20 07:41:11 +02:00
|
|
|
break;
|
|
|
|
case COMPLETED_BYTES:
|
|
|
|
// Update completed bytes
|
|
|
|
break;
|
|
|
|
case TOTAL_BYTES:
|
|
|
|
// Update total bytes
|
|
|
|
break;
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
|
|
|
|
public void update(AbstractRipper ripper, RipStatusMessage message) {
|
|
|
|
StatusEvent event = new StatusEvent(ripper, message);
|
|
|
|
SwingUtilities.invokeLater(event);
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
|
2014-04-07 02:26:30 +02:00
|
|
|
public static void ripAlbumStatic(String url) {
|
2014-05-26 09:31:58 +02:00
|
|
|
ripTextfield.setText(url.trim());
|
2014-04-07 02:26:30 +02:00
|
|
|
ripButton.doClick();
|
|
|
|
}
|
2016-10-01 22:20:55 +02:00
|
|
|
|
|
|
|
public static void enableWindowPositioning() {
|
|
|
|
Utils.setConfigBoolean("window.position", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disableWindowPositioning() {
|
|
|
|
Utils.setConfigBoolean("window.position", false);
|
|
|
|
}
|
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
private static boolean hasWindowPositionBug() {
|
2017-10-12 11:13:22 +02:00
|
|
|
String osName = System.getProperty("os.name");
|
2017-10-24 16:33:28 +02:00
|
|
|
// Java on Windows has a bug where if we try to manually set the position of the Window,
|
|
|
|
// javaw.exe will not close itself down when the application is closed.
|
|
|
|
// Therefore, even if isWindowPositioningEnabled, if we are on Windows, we ignore it.
|
|
|
|
return osName == null || osName.startsWith("Windows");
|
2017-10-12 11:13:22 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
private static boolean isWindowPositioningEnabled() {
|
2016-10-01 22:20:55 +02:00
|
|
|
boolean isEnabled = Utils.getConfigBoolean("window.position", true);
|
2017-10-12 11:13:22 +02:00
|
|
|
return isEnabled && !hasWindowPositionBug();
|
2016-10-01 22:20:55 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
private static void saveWindowPosition(Frame frame) {
|
2016-10-01 22:20:55 +02:00
|
|
|
if (!isWindowPositioningEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-12 11:13:22 +02:00
|
|
|
|
2016-10-01 22:20:55 +02:00
|
|
|
Point point;
|
|
|
|
try {
|
|
|
|
point = frame.getLocationOnScreen();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
try {
|
|
|
|
point = frame.getLocation();
|
|
|
|
} catch (Exception e2) {
|
|
|
|
e2.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int x = (int)point.getX();
|
|
|
|
int y = (int)point.getY();
|
|
|
|
int w = frame.getWidth();
|
|
|
|
int h = frame.getHeight();
|
|
|
|
Utils.setConfigInteger("window.x", x);
|
|
|
|
Utils.setConfigInteger("window.y", y);
|
|
|
|
Utils.setConfigInteger("window.w", w);
|
|
|
|
Utils.setConfigInteger("window.h", h);
|
2016-12-20 05:31:08 +01:00
|
|
|
logger.debug("Saved window position (x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ")");
|
2016-10-01 22:20:55 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
private static void restoreWindowPosition(Frame frame) {
|
2017-10-12 11:13:22 +02:00
|
|
|
if (!isWindowPositioningEnabled()) {
|
2016-12-20 05:31:08 +01:00
|
|
|
mainFrame.setLocationRelativeTo(null); // default to middle of screen
|
2016-10-01 22:20:55 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-10-12 10:59:31 +02:00
|
|
|
|
2016-10-01 22:20:55 +02:00
|
|
|
try {
|
|
|
|
int x = Utils.getConfigInteger("window.x", -1);
|
|
|
|
int y = Utils.getConfigInteger("window.y", -1);
|
|
|
|
int w = Utils.getConfigInteger("window.w", -1);
|
|
|
|
int h = Utils.getConfigInteger("window.h", -1);
|
2016-12-20 05:31:08 +01:00
|
|
|
if (x < 0 || y < 0 || w <= 0 || h <= 0) {
|
2016-10-01 22:20:55 +02:00
|
|
|
logger.debug("UNUSUAL: One or more of: x, y, w, or h was still less than 0 after reading config");
|
2016-12-20 05:31:08 +01:00
|
|
|
mainFrame.setLocationRelativeTo(null); // default to middle of screen
|
2016-10-01 22:20:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
frame.setBounds(x, y, w, h);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 05:31:08 +01:00
|
|
|
}
|