1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-07 22:37:40 +02:00

Pressing enter rips, better error messages

And the history pane isn't so ugly
This commit is contained in:
4pr0n
2014-04-04 01:08:04 -07:00
parent df3b6b6000
commit 04de8d7a09

View File

@@ -14,11 +14,8 @@ import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Observable;
import java.util.Observer;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JButton; import javax.swing.JButton;
@@ -102,6 +99,15 @@ public class MainWindow implements Runnable, RipStatusHandler {
} }
private void status(String text) { private void status(String text) {
statusWithColor(text, Color.BLACK);
}
private void error(String text) {
statusWithColor(text, Color.RED);
}
private void statusWithColor(String text, Color color) {
statusLabel.setForeground(color);
statusLabel.setText(text); statusLabel.setText(text);
mainFrame.pack(); mainFrame.pack();
} }
@@ -171,7 +177,9 @@ public class MainWindow implements Runnable, RipStatusHandler {
gbc.gridx = 0; gbc.gridx = 0;
JPanel historyListPanel = new JPanel(new GridBagLayout()); JPanel historyListPanel = new JPanel(new GridBagLayout());
historyListPanel.add(historyListScroll, gbc); historyListPanel.add(historyListScroll, gbc);
gbc.ipady = 150;
historyPanel.add(historyListPanel, gbc); historyPanel.add(historyListPanel, gbc);
gbc.ipady = 0;
historyButtonPanel = new JPanel(new GridBagLayout()); historyButtonPanel = new JPanel(new GridBagLayout());
historyButtonPanel.setPreferredSize(new Dimension(300, 10)); historyButtonPanel.setPreferredSize(new Dimension(300, 10));
historyButtonPanel.setBorder(emptyBorder); historyButtonPanel.setBorder(emptyBorder);
@@ -198,6 +206,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
private void setupHandlers() { private void setupHandlers() {
ripButton.addActionListener(new RipButtonHandler()); ripButton.addActionListener(new RipButtonHandler());
ripTextfield.addActionListener(new RipButtonHandler());
optionLog.addActionListener(new ActionListener() { optionLog.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
@@ -343,7 +352,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
url = new URL(urlString); url = new URL(urlString);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
logger.error("[!] Could not generate URL for '" + urlString + "'", e); logger.error("[!] Could not generate URL for '" + urlString + "'", e);
status("Error: " + e.getMessage()); error("Given URL is not valid, expecting http://website.com/page/...");
return null; return null;
} }
ripButton.setEnabled(false); ripButton.setEnabled(false);
@@ -355,13 +364,14 @@ public class MainWindow implements Runnable, RipStatusHandler {
try { try {
AbstractRipper ripper = AbstractRipper.getRipper(url); AbstractRipper ripper = AbstractRipper.getRipper(url);
ripTextfield.setText(ripper.getURL().toExternalForm()); ripTextfield.setText(ripper.getURL().toExternalForm());
status("Starting rip...");
ripper.setObserver((RipStatusHandler) this); ripper.setObserver((RipStatusHandler) this);
Thread t = new Thread(ripper); Thread t = new Thread(ripper);
t.start(); t.start();
return t; return t;
} catch (Exception e) { } catch (Exception e) {
logger.error("[!] Error while ripping: " + e.getMessage(), e); logger.error("[!] Error while ripping: " + e.getMessage(), e);
status("Error: " + e.getMessage()); error("Unable to rip this URL: " + e.getMessage());
ripButton.setEnabled(true); ripButton.setEnabled(true);
ripTextfield.setEnabled(true); ripTextfield.setEnabled(true);
statusProgress.setValue(0); statusProgress.setValue(0);