Much nicer UI for rip progress.
Progress bar, percentage, counts of pending,completed,errored files. Also using GridBagLayout manager for placement of UI elements.
This commit is contained in:
parent
857b8a86b5
commit
a2a86960b0
@ -263,6 +263,24 @@ public abstract class AbstractRipper
|
|||||||
observer.notifyAll();
|
observer.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCompletionPercentage() {
|
||||||
|
double total = itemsPending.size() + itemsErrored.size() + itemsCompleted.size();
|
||||||
|
return (int) (100 * ( (total - itemsPending.size()) / total));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusText() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(getCompletionPercentage())
|
||||||
|
.append("% - ")
|
||||||
|
.append("Pending: ")
|
||||||
|
.append(itemsPending.size())
|
||||||
|
.append(", Completed: ")
|
||||||
|
.append(itemsCompleted.size())
|
||||||
|
.append(", Errored: ")
|
||||||
|
.append(itemsErrored.size());
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.rarchives.ripme.ui;
|
package com.rarchives.ripme.ui;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.Container;
|
||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -13,15 +15,17 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JProgressBar;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.JTextPane;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.rarchives.ripme.ripper.AbstractRipper;
|
import com.rarchives.ripme.ripper.AbstractRipper;
|
||||||
import com.rarchives.ripme.utils.Utils;
|
import com.rarchives.ripme.utils.Utils;
|
||||||
|
|
||||||
|
|
||||||
public class MainWindow implements Runnable {
|
public class MainWindow implements Runnable {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(MainWindow.class);
|
private static final Logger logger = Logger.getLogger(MainWindow.class);
|
||||||
@ -29,43 +33,26 @@ public class MainWindow implements Runnable {
|
|||||||
private static final String WINDOW_TITLE = "RipMe";
|
private static final String WINDOW_TITLE = "RipMe";
|
||||||
|
|
||||||
private static JFrame mainFrame;
|
private static JFrame mainFrame;
|
||||||
private static JPanel ripPanel;
|
|
||||||
private static JTextField ripTextfield;
|
private static JTextField ripTextfield;
|
||||||
private static JButton ripButton;
|
private static JButton ripButton;
|
||||||
|
|
||||||
private static JPanel statusPanel;
|
|
||||||
private static JLabel statusLabel;
|
private static JLabel statusLabel;
|
||||||
private static JButton statusButton;
|
private static JButton openButton;
|
||||||
|
private static JProgressBar statusProgress;
|
||||||
|
|
||||||
|
private static JTextPane textLog;
|
||||||
|
private static JScrollPane textLogScroll;
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
createUI();
|
mainFrame = new JFrame(WINDOW_TITLE);
|
||||||
|
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
mainFrame.setResizable(false);
|
||||||
|
mainFrame.setLayout(new GridBagLayout());
|
||||||
|
|
||||||
|
createUI(mainFrame.getContentPane());
|
||||||
setupHandlers();
|
setupHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createUI() {
|
|
||||||
mainFrame = new JFrame(WINDOW_TITLE);
|
|
||||||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
ripPanel = new JPanel();
|
|
||||||
ripTextfield = new JTextField("", 20);
|
|
||||||
ripButton = new JButton("rip");
|
|
||||||
ripPanel.add(ripTextfield, BorderLayout.WEST);
|
|
||||||
ripPanel.add(ripButton, BorderLayout.EAST);
|
|
||||||
mainFrame.getContentPane().add(ripPanel, BorderLayout.NORTH);
|
|
||||||
|
|
||||||
statusPanel = new JPanel();
|
|
||||||
statusLabel = new JLabel("inactive", SwingConstants.LEADING);
|
|
||||||
statusButton = new JButton("open dir");
|
|
||||||
statusButton.setVisible(false);
|
|
||||||
statusPanel.add(statusLabel, BorderLayout.WEST);
|
|
||||||
statusPanel.add(statusButton, BorderLayout.EAST);
|
|
||||||
mainFrame.getContentPane().add(statusPanel, BorderLayout.SOUTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupHandlers() {
|
|
||||||
ripButton.addActionListener(new RipButtonHandler());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
mainFrame.pack();
|
mainFrame.pack();
|
||||||
mainFrame.setLocationRelativeTo(null);
|
mainFrame.setLocationRelativeTo(null);
|
||||||
@ -74,11 +61,68 @@ public class MainWindow implements Runnable {
|
|||||||
|
|
||||||
public static void status(String text) {
|
public static void status(String text) {
|
||||||
statusLabel.setText(text);
|
statusLabel.setText(text);
|
||||||
|
mainFrame.pack();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUI(Container pane) {
|
||||||
|
EmptyBorder emptyBorder = new EmptyBorder(5, 5, 5, 5);
|
||||||
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
gbc.weightx = 9; gbc.ipadx = 5; gbc.gridx = 0;
|
||||||
|
gbc.weighty = 9; gbc.ipady = 5; gbc.gridy = 0;
|
||||||
|
|
||||||
|
ripTextfield = new JTextField("", 20);
|
||||||
|
ripButton = new JButton("rip");
|
||||||
|
JPanel ripPanel = new JPanel(new GridBagLayout());
|
||||||
|
ripPanel.setBorder(emptyBorder);
|
||||||
|
|
||||||
|
ripPanel.add(new JLabel("URL:"), gbc);
|
||||||
|
gbc.gridx = 1;
|
||||||
|
ripPanel.add(ripTextfield, gbc);
|
||||||
|
gbc.gridx = 2;
|
||||||
|
ripPanel.add(ripButton, gbc);
|
||||||
|
|
||||||
|
statusLabel = new JLabel("Inactive");
|
||||||
|
openButton = new JButton();
|
||||||
|
openButton.setVisible(false);
|
||||||
|
JPanel statusPanel = new JPanel(new GridBagLayout());
|
||||||
|
statusPanel.setBorder(emptyBorder);
|
||||||
|
|
||||||
|
gbc.gridx = 0; gbc.gridy = 1;
|
||||||
|
statusPanel.add(statusLabel, gbc);
|
||||||
|
gbc.gridx = 1;
|
||||||
|
statusPanel.add(openButton, gbc);
|
||||||
|
|
||||||
|
JPanel progressPanel = new JPanel(new GridBagLayout());
|
||||||
|
progressPanel.setBorder(emptyBorder);
|
||||||
|
statusProgress = new JProgressBar(0, 100);
|
||||||
|
progressPanel.add(statusProgress, gbc);
|
||||||
|
|
||||||
|
JPanel logPanel = new JPanel(new GridBagLayout());
|
||||||
|
logPanel.setBorder(emptyBorder);
|
||||||
|
textLog = new JTextPane();
|
||||||
|
textLogScroll = new JScrollPane(textLog);
|
||||||
|
logPanel.add(textLogScroll, gbc);
|
||||||
|
|
||||||
|
gbc.gridx = 0; gbc.gridy = 0;
|
||||||
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
|
pane.add(ripPanel, gbc);
|
||||||
|
gbc.gridy = 1;
|
||||||
|
pane.add(statusPanel, gbc);
|
||||||
|
gbc.gridy = 2;
|
||||||
|
pane.add(progressPanel, gbc);
|
||||||
|
gbc.gridy = 3;
|
||||||
|
pane.add(logPanel, gbc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupHandlers() {
|
||||||
|
ripButton.addActionListener(new RipButtonHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
class RipButtonHandler implements ActionListener {
|
class RipButtonHandler implements ActionListener {
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
statusButton.setVisible(false);
|
openButton.setVisible(false);
|
||||||
|
statusLabel.setVisible(true);
|
||||||
|
mainFrame.pack();
|
||||||
try {
|
try {
|
||||||
URL url = new URL(ripTextfield.getText());
|
URL url = new URL(ripTextfield.getText());
|
||||||
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
||||||
@ -101,12 +145,20 @@ public class MainWindow implements Runnable {
|
|||||||
case DOWNLOAD_STARTED:
|
case DOWNLOAD_STARTED:
|
||||||
case DOWNLOAD_COMPLETE:
|
case DOWNLOAD_COMPLETE:
|
||||||
case DOWNLOAD_ERRORED:
|
case DOWNLOAD_ERRORED:
|
||||||
status((String) msg.getObject());
|
//status((String) msg.getObject());
|
||||||
|
int completedPercent = ((AbstractRipper) observable).getCompletionPercentage();
|
||||||
|
statusProgress.setValue(completedPercent);
|
||||||
|
status( ((AbstractRipper)observable).getStatusText() );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RIP_COMPLETE:
|
case RIP_COMPLETE:
|
||||||
|
statusProgress.setValue(100);
|
||||||
|
statusLabel.setVisible(false);
|
||||||
|
openButton.setVisible(true);
|
||||||
File f = (File) msg.getObject();
|
File f = (File) msg.getObject();
|
||||||
statusButton.setActionCommand(f.toString());
|
openButton.setText("Open " + Utils.removeCWD(f));
|
||||||
statusButton.addActionListener(new ActionListener() {
|
openButton.setActionCommand(f.toString());
|
||||||
|
openButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
try {
|
try {
|
||||||
@ -116,8 +168,7 @@ public class MainWindow implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
statusButton.setVisible(true);
|
mainFrame.pack();
|
||||||
status("Finished: " + Utils.removeCWD(f));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user